Implement GET/SET_GLOBAL(...) instead of using GET/SET_VAR(CS, ...)
authorKevin O'Connor <kevin@koconnor.net>
Sat, 13 Dec 2008 16:10:37 +0000 (11:10 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 13 Dec 2008 16:10:37 +0000 (11:10 -0500)
src/apm.c
src/biosvar.h
src/cdrom.c
src/clock.c
src/kbd.c
src/mouse.c
src/output.c
src/system.c

index 20786c0259da2a605d80b785a873e73049100839..fbbd5116d479f9fd7ef00f4c13c6588ab634d425 100644 (file)
--- a/src/apm.c
+++ b/src/apm.c
@@ -11,6 +11,7 @@
 #include "ioport.h" // outb
 #include "util.h" // irq_enable
 #include "config.h" // CONFIG_*
+#include "biosvar.h" // GET_GLOBAL
 
 static void
 out_str(const char *str_cs)
@@ -22,7 +23,7 @@ out_str(const char *str_cs)
 
     u8 *s = (u8*)str_cs;
     for (;;) {
-        u8 c = GET_VAR(CS, *s);
+        u8 c = GET_GLOBAL(*s);
         if (!c)
             break;
         outb(c, PORT_BIOS_APM);
index 646bd51180189c23dea0293e11816e1096a1e90e..f2cb47f6238e686eef41d174b54b53582381844f 100644 (file)
@@ -304,6 +304,22 @@ struct extended_bios_data_area_s {
     SET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var, (val))
 
 
+/****************************************************************
+ * Global variables
+ ****************************************************************/
+
+#define GET_GLOBAL(var) \
+    GET_VAR(CS, (var))
+#if MODE16
+extern void __force_link_error__set_global_only_in_32bit();
+#define SET_GLOBAL(var, val)                            \
+    __force_link_error__set_global_only_in_32bit()
+#else
+#define SET_GLOBAL(var, val)                    \
+    do { (var) = (val); } while (0)
+#endif
+
+
 /****************************************************************
  * Bios Config Table
  ****************************************************************/
index 3690f677e54058079e34cc7eefdcae64b827eea8..65b5bbe384f3cd69845376199ef9b7cb02f3c268 100644 (file)
@@ -415,7 +415,7 @@ streq_cs(u8 *s1, char *cs_s2)
 {
     u8 *s2 = (u8*)cs_s2;
     for (;;) {
-        if (*s1 != GET_VAR(CS, *s2))
+        if (*s1 != GET_GLOBAL(*s2))
             return 0;
         if (! *s1)
             return 1;
index 5933ad3e9b82ad5eb1f73effaeb035d938ee3576..43b8379acc5aa36d8b4ff04be1805d13f1853540 100644 (file)
@@ -11,6 +11,7 @@
 #include "cmos.h" // inb_cmos
 #include "pic.h" // eoi_pic1
 #include "bregs.h" // struct bregs
+#include "biosvar.h" // GET_GLOBAL
 
 // RTC register flags
 #define RTC_A_UIP 0x80
@@ -81,7 +82,7 @@ calibrate_tsc()
     dprintf(6, "tsc calibrate start=%u end=%u diff=%u\n"
             , (u32)start, (u32)end, (u32)diff);
     u32 hz = diff * PIT_TICK_RATE / CALIBRATE_COUNT;
-    SET_VAR(CS, cpu_khz, hz / 1000);
+    SET_GLOBAL(cpu_khz, hz / 1000);
 
     dprintf(1, "CPU Mhz=%u\n", hz / 1000000);
 }
@@ -98,19 +99,19 @@ tscsleep(u64 diff)
 void
 ndelay(u32 count)
 {
-    u32 khz = GET_VAR(CS, cpu_khz);
+    u32 khz = GET_GLOBAL(cpu_khz);
     tscsleep(count * khz / 1000000);
 }
 void
 udelay(u32 count)
 {
-    u32 khz = GET_VAR(CS, cpu_khz);
+    u32 khz = GET_GLOBAL(cpu_khz);
     tscsleep(count * khz / 1000);
 }
 void
 mdelay(u32 count)
 {
-    u32 khz = GET_VAR(CS, cpu_khz);
+    u32 khz = GET_GLOBAL(cpu_khz);
     tscsleep(count * khz);
 }
 
@@ -118,7 +119,7 @@ mdelay(u32 count)
 u64
 calc_future_tsc(u32 msecs)
 {
-    u32 khz = GET_VAR(CS, cpu_khz);
+    u32 khz = GET_GLOBAL(cpu_khz);
     return rdtscll() + ((u64)khz * msecs);
 }
 
@@ -220,6 +221,7 @@ handle_1a01(struct bregs *regs)
     u32 ticks = (regs->cx << 16) | regs->dx;
     SET_BDA(timer_counter, ticks);
     SET_BDA(timer_rollover, 0); // reset flag
+    // XXX - should use set_code_success()?
     regs->ah = 0;
     set_success(regs);
 }
index 7563733706f1573d9c62f920fbc3cb0906504a84..190c9fedc1594f6e144befdece8ee61ad63ec9f2 100644 (file)
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -580,35 +580,35 @@ process_key(u8 scancode)
         u8 asciicode;
         struct scaninfo *info = &scan_to_scanascii[scancode];
         if (shift_flags & 0x08) { /* ALT */
-            asciicode = GET_VAR(CS, info->alt);
-            scancode = GET_VAR(CS, info->alt) >> 8;
+            asciicode = GET_GLOBAL(info->alt);
+            scancode = GET_GLOBAL(info->alt) >> 8;
         } else if (shift_flags & 0x04) { /* CONTROL */
-            asciicode = GET_VAR(CS, info->control);
-            scancode = GET_VAR(CS, info->control) >> 8;
+            asciicode = GET_GLOBAL(info->control);
+            scancode = GET_GLOBAL(info->control) >> 8;
         } else if ((mf2_state & 0x02) > 0
                    && scancode >= 0x47 && scancode <= 0x53) {
             /* extended keys handling */
             asciicode = 0xe0;
-            scancode = GET_VAR(CS, info->normal) >> 8;
+            scancode = GET_GLOBAL(info->normal) >> 8;
         } else if (shift_flags & 0x03) { /* LSHIFT + RSHIFT */
             /* check if lock state should be ignored
              * because a SHIFT key are pressed */
 
-            if (shift_flags & GET_VAR(CS, info->lock_flags)) {
-                asciicode = GET_VAR(CS, info->normal);
-                scancode = GET_VAR(CS, info->normal) >> 8;
+            if (shift_flags & GET_GLOBAL(info->lock_flags)) {
+                asciicode = GET_GLOBAL(info->normal);
+                scancode = GET_GLOBAL(info->normal) >> 8;
             } else {
-                asciicode = GET_VAR(CS, info->shift);
-                scancode = GET_VAR(CS, info->shift) >> 8;
+                asciicode = GET_GLOBAL(info->shift);
+                scancode = GET_GLOBAL(info->shift) >> 8;
             }
         } else {
             /* check if lock is on */
-            if (shift_flags & GET_VAR(CS, info->lock_flags)) {
-                asciicode = GET_VAR(CS, info->shift);
-                scancode = GET_VAR(CS, info->shift) >> 8;
+            if (shift_flags & GET_GLOBAL(info->lock_flags)) {
+                asciicode = GET_GLOBAL(info->shift);
+                scancode = GET_GLOBAL(info->shift) >> 8;
             } else {
-                asciicode = GET_VAR(CS, info->normal);
-                scancode = GET_VAR(CS, info->normal) >> 8;
+                asciicode = GET_GLOBAL(info->normal);
+                scancode = GET_GLOBAL(info->normal) >> 8;
             }
         }
         if (scancode==0 && asciicode==0) {
index 09631bd2e825a7ad5d04cfbd47488f0a5d7f9096..daac50542c3686028c38dd9a4275147a3601c836 100644 (file)
@@ -114,7 +114,7 @@ mouse_15c202(struct bregs *regs)
         set_code_fail(regs, RET_EINVINPUT);
         return;
     }
-    u8 mouse_data1 = GET_VAR(CS, sample_rates[regs->bh]);
+    u8 mouse_data1 = GET_GLOBAL(sample_rates[regs->bh]);
     int ret = aux_command(PSMOUSE_CMD_SETRATE, &mouse_data1);
     if (ret)
         set_code_fail(regs, RET_ENEEDRESEND);
index b09677e4b8a93e1a9db1364499ff5916fac458b1..6a56d456da52def6ab0cc12167555865fc966136 100644 (file)
@@ -10,6 +10,7 @@
 #include "util.h" // printf
 #include "bregs.h" // struct bregs
 #include "config.h" // CONFIG_*
+#include "biosvar.h" // GET_GLOBAL
 
 #define DEBUG_PORT 0x03f8
 #define DEBUG_TIMEOUT 100000
@@ -96,7 +97,7 @@ static void
 puts_cs(u16 action, const char *s)
 {
     for (;; s++) {
-        char c = GET_VAR(CS, *(u8*)s);
+        char c = GET_GLOBAL(*(u8*)s);
         if (!c)
             break;
         putc(action, c);
@@ -156,7 +157,7 @@ bvprintf(u16 action, const char *fmt, va_list args)
 {
     const char *s = fmt;
     for (;; s++) {
-        char c = GET_VAR(CS, *(u8*)s);
+        char c = GET_GLOBAL(*(u8*)s);
         if (!c)
             break;
         if (c != '%') {
@@ -165,7 +166,7 @@ bvprintf(u16 action, const char *fmt, va_list args)
         }
         const char *n = s+1;
         for (;;) {
-            c = GET_VAR(CS, *(u8*)n);
+            c = GET_GLOBAL(*(u8*)n);
             if (!isdigit(c))
                 break;
             n++;
@@ -173,7 +174,7 @@ bvprintf(u16 action, const char *fmt, va_list args)
         if (c == 'l') {
             // Ignore long format indicator
             n++;
-            c = GET_VAR(CS, *(u8*)n);
+            c = GET_GLOBAL(*(u8*)n);
         }
         s32 val;
         const char *sarg;
@@ -204,7 +205,7 @@ bvprintf(u16 action, const char *fmt, va_list args)
             break;
         case '.':
             // Hack to support "%.s" - meaning string on stack.
-            if (GET_VAR(CS, *(u8*)(n+1)) != 's')
+            if (GET_GLOBAL(*(u8*)(n+1)) != 's')
                 break;
             n++;
             sarg = va_arg(args, const char *);
index 7d2f2431a3eabf847bbbdc9f717e4933d1482977..6615b31c4eb05ff3080110e5cb36a69dda6f2e3c 100644 (file)
@@ -275,13 +275,13 @@ int e820_count VISIBLE16;
 static void
 handle_15e820(struct bregs *regs)
 {
-    int count = GET_VAR(CS, e820_count);
+    int count = GET_GLOBAL(e820_count);
     if (regs->edx != 0x534D4150 || regs->bx >= count) {
         set_code_fail(regs, RET_EUNSUPPORTED);
         return;
     }
 
-    struct e820entry *l = GET_VAR(CS, e820_list);
+    struct e820entry *l = GET_GLOBAL(e820_list);
     memcpy_far(MAKE_FARPTR(regs->es, regs->di), &l[regs->bx], sizeof(l[0]));
     if (regs->bx == count-1)
         regs->ebx = 0;