]> xenbits.xensource.com Git - seabios.git/commitdiff
Add more linker protections around variables accessed from 16bit mode.
authorKevin O'Connor <kevin@koconnor.net>
Tue, 30 Dec 2008 01:42:40 +0000 (20:42 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 30 Dec 2008 01:42:40 +0000 (20:42 -0500)
Rename VAR16 to VAR16_32 -- that macro supports accesses from both
    16bit and 32bit mode.
Introduce a new macro VAR16 that must be present on all global
    variables accessed from 16bit mode.

16 files changed:
Makefile
src/ata.c
src/cbt.c
src/cdrom.c
src/clock.c
src/floppy.c
src/floppy_dbt.c
src/font.c
src/kbd.c
src/pirtable.c
src/pnpbios.c
src/rombios16.lds.S
src/smpdetect.c
src/system.c
src/types.h
src/vgahooks.c

index 24c67c2ef07a77823783d65098ab03a35f6e0418..3a24433fe1ff23cf7d1fbdab9a3f6fc927a86ad9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,7 @@ endif
 
 $(OUT)%.proc.16.s: $(OUT)%.16.s
        @echo "  Moving data sections to text in $@"
-       $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
+       $(Q)sed 's/^\t\.section\t\.\(ro\)\?data.*// ; s/^\t\.data$$//' < $< > $@
 
 $(OUT)%.16.s: %.c
        @echo "  Compiling to assembler $@"
index c1982642e41647d8d6ba825e23aa339d55b13e60..7e31002b5d342cda900f709e707e4a57916a52f5 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -29,7 +29,7 @@
 
 #define IDE_TIMEOUT 32000u //32 seconds max for IDE ops
 
-struct ata_s ATA VAR16;
+struct ata_s ATA VAR16_32;
 
 
 /****************************************************************
index 8a2a11a01a204007e8c6c6ca612d891aae959c68..5554fdaecb201d55e50b199ee9d02f160cd80567 100644 (file)
--- a/src/cbt.c
+++ b/src/cbt.c
@@ -27,7 +27,7 @@
 // INT 16/AH=09h (keyboard functionality) supported
 #define CBT_F2_INT1609  (1<<6)
 
-struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1) = {
+struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1) VAR16 = {
     .size     = sizeof(BIOS_CONFIG_TABLE) - 2,
     .model    = CONFIG_MODEL_ID,
     .submodel = CONFIG_SUBMODEL_ID,
index f955f18e8d1dbaf1bd8d6832fa29fee5e1f096b7..7ce7da754595b4e476a61b3b948e2f0b87324c74 100644 (file)
@@ -11,7 +11,7 @@
 #include "bregs.h" // struct bregs
 #include "biosvar.h" // GET_EBDA
 
-struct cdemu_s CDEMU VAR16;
+struct cdemu_s CDEMU VAR16_32;
 
 
 /****************************************************************
index 4590adc75efbeb4e9853f37484d9207b6109101f..c76ea75a41c5865665e7bd3c02b8b3ba8dafb96a 100644 (file)
@@ -51,7 +51,7 @@
 #define PIT_TICK_RATE 1193182 // Underlying HZ of PIT
 #define CALIBRATE_COUNT 0x800 // Approx 1.7ms
 
-u32 cpu_khz VAR16;
+u32 cpu_khz VAR16_32;
 
 static void
 calibrate_tsc()
index 6354bd8bd37e6e62381354884036b56170b7d7f1..da812ba6441c4a67b99efb706f3b22386859c4cc 100644 (file)
@@ -20,7 +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
-struct floppy_ext_dbt_s diskette_param_table2 VAR16 = {
+struct floppy_ext_dbt_s diskette_param_table2 VAR16_32 = {
     .dbt = {
         .specify1       = 0xAF,
         .specify2       = 0x02, // head load time 0000001, DMA used
index c391d9e48aeaf2021645422315bf03e83dd50a02..2a686dc49eb5019ed2ff8354b29c79e4f3fd8903 100644 (file)
@@ -4,7 +4,7 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "disk.h" // diskette_param_table
+#include "disk.h" // struct floppy_dbt_s
 
 // Since no provisions are made for multiple drive types, most
 // values in this table are ignored.  I set parameters for 1.44M
index 17f06907cab7b8143c644b16fe2f073c46497a06..99c7f435ff91d4e821857112fe7005de2ca88d1d 100644 (file)
@@ -7,7 +7,7 @@
  * found at ftp://ftp.simtel.net/pub/simtelnet/msdos/screen/fntcol16.zip
  * This font is public domain
  */
-const u8 vgafont8[128*8] __aligned(1) = {
+const u8 vgafont8[128*8] __aligned(1) VAR16 = {
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e,
     0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e,
index 702a03202ec4ab04e688249e7f4b5f016e9fc20e..9c59005661ba70dc8195e7ae0be3eb0f6883ee46 100644 (file)
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -148,17 +148,17 @@ dequeue_key(struct bregs *regs, int incr, int extended)
         ascii_code = 0;
     regs->ax = (scan_code << 8) | ascii_code;
 
-    if (incr) {
-        u16 buffer_start = GET_BDA(kbd_buf_start_offset);
-        u16 buffer_end   = GET_BDA(kbd_buf_end_offset);
-
-        buffer_head += 2;
-        if (buffer_head >= buffer_end)
-            buffer_head = buffer_start;
-        SET_BDA(kbd_buf_head, buffer_head);
-    } else {
+    if (!incr) {
         regs->flags &= ~F_ZF;
+        return;
     }
+    u16 buffer_start = GET_BDA(kbd_buf_start_offset);
+    u16 buffer_end   = GET_BDA(kbd_buf_end_offset);
+
+    buffer_head += 2;
+    if (buffer_head >= buffer_end)
+        buffer_head = buffer_start;
+    SET_BDA(kbd_buf_head, buffer_head);
 }
 
 // read keyboard input
@@ -326,7 +326,7 @@ static struct scaninfo {
     u16 control;
     u16 alt;
     u8 lock_flags;
-} scan_to_scanascii[MAX_SCAN_CODE + 1] = {
+} scan_to_scanascii[MAX_SCAN_CODE + 1] VAR16 = {
     {   none,   none,   none,   none, none },
     { 0x011b, 0x011b, 0x011b, 0x0100, none }, /* escape */
     { 0x0231, 0x0221,   none, 0x7800, none }, /* 1! */
index f776ee93ae740bcb85073fa9e04d49f59046863d..ba141a5af1b00692220a278e91e7caac773d8acb 100644 (file)
@@ -9,7 +9,7 @@
 #include "util.h" // checksum
 #include "biosvar.h" // SET_EBDA
 
-u16 PirOffset VAR16;
+u16 PirOffset VAR16_32;
 
 struct pir_table {
     struct pir_header pir;
@@ -18,7 +18,7 @@ struct pir_table {
 
 extern struct pir_table PIR_TABLE;
 #if CONFIG_PIRTABLE && !CONFIG_COREBOOT
-struct pir_table PIR_TABLE __aligned(16) VAR16 = {
+struct pir_table PIR_TABLE __aligned(16) VAR16_32 = {
     .pir = {
         .version = 0x0100,
         .size = sizeof(struct pir_table),
index 21d140a7eff2bdd9ee760cc68944030ff3d2a0f0..8bf71dcb13f605086e43fead568fc091c2ec2afa 100644 (file)
@@ -28,7 +28,7 @@ extern struct pnpheader PNPHEADER;
 extern const char pnp_string[];
 
 #if CONFIG_PNPBIOS
-struct pnpheader PNPHEADER __aligned(16) VAR16 = {
+struct pnpheader PNPHEADER __aligned(16) VAR16_32 = {
     .signature = PNP_SIGNATURE,
     .version = 0x10,
     .length = sizeof(PNPHEADER),
@@ -41,7 +41,7 @@ struct pnpheader PNPHEADER __aligned(16) VAR16 = {
 // 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) VAR16 = " $PnP";
+const char pnp_string[] __aligned(2) VAR16_32 = " $PnP";
 #endif
 
 #define FUNCTION_NOT_SUPPORTED 0x82
index 009eb8993bb97851fe8b882aa36687a290cfd0da..2966ce62385ba52ce2796d5411ea8273395682e5 100644 (file)
@@ -16,10 +16,7 @@ SECTIONS
                 *(.text)
                 code16_rodata = . ;
                 *(.rodata*)
-                *(.data)
-                code16_bss = . ;
-                *(.bss)
-                *(COMMON)
+                *(.data.var16)
                 }
         freespace1_start = . ;
         code16_end = . ;
@@ -31,4 +28,8 @@ SECTIONS
                 *(.text.fixed.addr)
                 }
         code16_fixed_end = . ;
+
+        // Discard regular data sections to force a link error if
+        // 16bit code attempts to access data not marked with VAR16.
+        /DISCARD/ : { *(.data) *(.bss) *(COMMON) }
 }
index 202a82a7e344072566d0086f572171e59379275b..b33464930aaabf883ba6f43c2f712aa279906873 100644 (file)
@@ -46,7 +46,7 @@ static inline u8 readb(const void *addr)
     return *(volatile const u8 *)addr;
 }
 
-u32 smp_cpus VAR16;
+u32 smp_cpus VAR16_32;
 extern void smp_ap_boot_code();
 ASM16(
     "  .global smp_ap_boot_code\n"
index abbfbbf82ad6fa96404d35c0c25c09b742b54302..7a0d20c4a9b3ad53fdd3a62a371d58a5fc0e4e62 100644 (file)
@@ -267,12 +267,12 @@ handle_15e801(struct bregs *regs)
 }
 
 // Info on e820 map location and size.
-struct e820entry *e820_list VAR16;
-int e820_count VAR16;
+struct e820entry *e820_list VAR16_32;
+int e820_count VAR16_32;
 // Amount of continuous ram under 4Gig
-u32 RamSize VAR16;
+u32 RamSize VAR16_32;
 // Amount of continuous ram >4Gig
-u64 RamSizeOver4G VAR16;
+u64 RamSizeOver4G;
 
 static void
 handle_15e820(struct bregs *regs)
index f7a0e9a6b72830a555d3e5ca7cd0d51ae004fdc7..587cb4199801b417142262b2d88652bba8602326 100644 (file)
@@ -28,14 +28,17 @@ union u64_u32_u {
 # define VISIBLE16 __VISIBLE
 // Notes a function as externally visible in the 32bit code chunk.
 # define VISIBLE32
+// Designate a variable as (only) visible to 16bit code.
+# define VAR16 __attribute__((section(".data.var16")))
 // Designate a variable as visible to both 32bit and 16bit code.
-# define VAR16 __VISIBLE
+# define VAR16_32 VAR16 __VISIBLE
 // Designate top-level assembler as 16bit only.
 # define ASM16(code) asm(code)
 #else
 # define VISIBLE16
 # define VISIBLE32 __VISIBLE
-# define VAR16 __VISIBLE __attribute__((section(".discard.var16"))) __attribute__((weak))
+# define VAR16 __attribute__((section(".discard.var16")))
+# define VAR16_32 VAR16 __VISIBLE __attribute__((weak))
 # define ASM16(code)
 #endif
 
index 8f55c49c669057c70176c2a284e99a481d2c0fa9..7cacbdfbd752c790c2bba404480df23434eba423 100644 (file)
@@ -46,7 +46,7 @@ getFBSize()
     if (!(reg & 0x80))
         goto err;
 
-    static u8 mem_power[] = {0, 3, 4, 5, 6, 7, 8, 9};
+    static u8 mem_power[] VAR16 = {0, 3, 4, 5, 6, 7, 8, 9};
     return GET_GLOBAL(mem_power[(reg >> 4) & 0x7]);
 err:
     dprintf(1, "Warning: VGA memory size is hardcoded\n");