Implement GET/SET_GLOBAL(...) instead of using GET/SET_VAR(CS, ...)
diff --git a/src/apm.c b/src/apm.c
index 20786c0..fbbd511 100644
--- 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 @@
 
     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);
diff --git a/src/biosvar.h b/src/biosvar.h
index 646bd51..f2cb47f 100644
--- a/src/biosvar.h
+++ b/src/biosvar.h
@@ -305,6 +305,22 @@
 
 
 /****************************************************************
+ * 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
  ****************************************************************/
 
diff --git a/src/cdrom.c b/src/cdrom.c
index 3690f67..65b5bbe 100644
--- a/src/cdrom.c
+++ b/src/cdrom.c
@@ -415,7 +415,7 @@
 {
     u8 *s2 = (u8*)cs_s2;
     for (;;) {
-        if (*s1 != GET_VAR(CS, *s2))
+        if (*s1 != GET_GLOBAL(*s2))
             return 0;
         if (! *s1)
             return 1;
diff --git a/src/clock.c b/src/clock.c
index 5933ad3..43b8379 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -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 @@
     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 @@
 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 @@
 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 @@
     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);
 }
diff --git a/src/kbd.c b/src/kbd.c
index 7563733..190c9fe 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -580,35 +580,35 @@
         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) {
diff --git a/src/mouse.c b/src/mouse.c
index 09631bd..daac505 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -114,7 +114,7 @@
         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);
diff --git a/src/output.c b/src/output.c
index b09677e..6a56d45 100644
--- a/src/output.c
+++ b/src/output.c
@@ -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 @@
 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 @@
 {
     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 @@
         }
         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 @@
         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 @@
             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 *);
diff --git a/src/system.c b/src/system.c
index 7d2f243..6615b31 100644
--- a/src/system.c
+++ b/src/system.c
@@ -275,13 +275,13 @@
 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;