Add linker magic to ensure 16bit variables aren't repeated in 32bit code.
authorKevin O'Connor <kevin@koconnor.net>
Mon, 29 Dec 2008 02:37:27 +0000 (21:37 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Mon, 29 Dec 2008 02:37:27 +0000 (21:37 -0500)
Add VAR16 macro to enable a variable to be available in both 32bit and
    16bit code.  This reduces the occurrences of "#if MODE16".
Also add ASM16 macro to reduce occurrences of "#if MODE16".

src/clock.c
src/floppy.c
src/floppy_dbt.c
src/pnpbios.c
src/rombios.lds.S
src/smpdetect.c
src/system.c
src/types.h

index 43b8379acc5aa36d8b4ff04be1805d13f1853540..4590adc75efbeb4e9853f37484d9207b6109101f 100644 (file)
 #define PIT_TICK_RATE 1193182 // Underlying HZ of PIT
 #define CALIBRATE_COUNT 0x800 // Approx 1.7ms
 
-extern u32 cpu_khz;
-#if MODE16
-u32 cpu_khz VISIBLE16;
-#endif
+u32 cpu_khz VAR16;
 
 static void
 calibrate_tsc()
index c880478938136341b0e48a7bf49dcf2da320f48a..6354bd8bd37e6e62381354884036b56170b7d7f1 100644 (file)
@@ -20,8 +20,7 @@
 // Since no provisions are made for multiple drive types, most
 // values in this table are ignored.  I set parameters for 1.44M
 // floppy here
-#if MODE16 == 1
-struct floppy_ext_dbt_s diskette_param_table2 VISIBLE16 = {
+struct floppy_ext_dbt_s diskette_param_table2 VAR16 = {
     .dbt = {
         .specify1       = 0xAF,
         .specify2       = 0x02, // head load time 0000001, DMA used
@@ -39,7 +38,6 @@ struct floppy_ext_dbt_s diskette_param_table2 VISIBLE16 = {
     .data_rate      = 0,    // data transfer rate
     .drive_type     = 4,    // drive type in cmos
 };
-#endif
 
 void
 floppy_drive_setup()
index c04d2229e66a300d6db9ddebab9f987703b8f258..c391d9e48aeaf2021645422315bf03e83dd50a02 100644 (file)
@@ -9,7 +9,7 @@
 // Since no provisions are made for multiple drive types, most
 // values in this table are ignored.  I set parameters for 1.44M
 // floppy here
-struct floppy_dbt_s diskette_param_table __aligned(1) VISIBLE16 = {
+struct floppy_dbt_s diskette_param_table __aligned(1) VAR16 = {
     .specify1       = 0xAF,
     .specify2       = 0x02, // head load time 0000001, DMA used
     .shutoff_ticks  = 0x25,
index 6f36a4a7345b2365ef1b7a8512f33c06e02cb2d9..21d140a7eff2bdd9ee760cc68944030ff3d2a0f0 100644 (file)
@@ -27,9 +27,8 @@ struct pnpheader {
 extern struct pnpheader PNPHEADER;
 extern const char pnp_string[];
 
-#if MODE16
-# if CONFIG_PNPBIOS
-struct pnpheader PNPHEADER __aligned(16) VISIBLE16 = {
+#if CONFIG_PNPBIOS
+struct pnpheader PNPHEADER __aligned(16) VAR16 = {
     .signature = PNP_SIGNATURE,
     .version = 0x10,
     .length = sizeof(PNPHEADER),
@@ -38,12 +37,11 @@ struct pnpheader PNPHEADER __aligned(16) VISIBLE16 = {
     .real_ds = SEG_BIOS,
     .prot_database = BUILD_BIOS_ADDR,
 };
-# else
+#else
 // We need a copy of this string in the 0xf000 segment, but we are not
 // actually a PnP BIOS, so make sure it is *not* aligned, so OSes will
 // not see it if they scan.
-const char pnp_string[] __aligned(2) VISIBLE16 = " $PnP";
-# endif
+const char pnp_string[] __aligned(2) VAR16 = " $PnP";
 #endif
 
 #define FUNCTION_NOT_SUPPORTED 0x82
index e3527ac1c62534f1c32ac472e4e52b09a629a60c..1305c40357a8e840892fa712eec070e9b4376f5f 100644 (file)
@@ -22,4 +22,5 @@ SECTIONS
                 final_code16_fixed_start = . ;
                 *(.text16.fixed.addr)
                 }
+        /DISCARD/ : { *(.discard.var16) }
 }
index 027402637b17cb6591dbd3b960875ed628e3e5f5..202a82a7e344072566d0086f572171e59379275b 100644 (file)
@@ -46,11 +46,9 @@ static inline u8 readb(const void *addr)
     return *(volatile const u8 *)addr;
 }
 
+u32 smp_cpus VAR16;
 extern void smp_ap_boot_code();
-extern u32 smp_cpus;
-#if MODE16
-u32 smp_cpus VISIBLE16;
-asm(
+ASM16(
     "  .global smp_ap_boot_code\n"
     "smp_ap_boot_code:\n"
     // Increment the cpu counter
@@ -60,7 +58,6 @@ asm(
     // Halt the processor.
     "  jmp permanent_halt\n"
     );
-#endif
 
 /* find the number of CPUs by launching a SIPI to them */
 int
index 6615b31c4eb05ff3080110e5cb36a69dda6f2e3c..fcbbaf67a50e8201aa610ea8652d7c1772fc077f 100644 (file)
@@ -266,11 +266,9 @@ handle_15e801(struct bregs *regs)
     set_success(regs);
 }
 
-#if MODE16
 // Info on e820 map location and size.
-struct e820entry *e820_list VISIBLE16;
-int e820_count VISIBLE16;
-#endif
+struct e820entry *e820_list VAR16;
+int e820_count VAR16;
 
 static void
 handle_15e820(struct bregs *regs)
index 8dd1a3b1c0d03fcc1d945ceb5e081e0d13188754..f7a0e9a6b72830a555d3e5ca7cd0d51ae004fdc7 100644 (file)
@@ -22,14 +22,21 @@ union u64_u32_u {
 };
 
 #define __VISIBLE __attribute__((externally_visible))
+
 #if MODE16 == 1
 // Notes a function as externally visible in the 16bit code chunk.
-#define VISIBLE16 __VISIBLE
+# define VISIBLE16 __VISIBLE
 // Notes a function as externally visible in the 32bit code chunk.
-#define VISIBLE32
+# define VISIBLE32
+// Designate a variable as visible to both 32bit and 16bit code.
+# define VAR16 __VISIBLE
+// Designate top-level assembler as 16bit only.
+# define ASM16(code) asm(code)
 #else
-#define VISIBLE16
-#define VISIBLE32 __VISIBLE
+# define VISIBLE16
+# define VISIBLE32 __VISIBLE
+# define VAR16 __VISIBLE __attribute__((section(".discard.var16"))) __attribute__((weak))
+# define ASM16(code)
 #endif
 
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)