Introduce GET/SET_EBDA2() macros - they take a cached ebda seg.

For those places that repeatedly read/write to the ebda, caching the
    ebda segment improves code generation.
diff --git a/src/biosvar.h b/src/biosvar.h
index 1a6da34..c8a1cce 100644
--- a/src/biosvar.h
+++ b/src/biosvar.h
@@ -200,18 +200,25 @@
 } PACKED;
 
 // Accessor functions
-#define GET_EBDA(var) \
-    GET_FARVAR(GET_BDA(ebda_seg), ((struct extended_bios_data_area_s *)0)->var)
-#define SET_EBDA(var, val) \
-    SET_FARVAR(GET_BDA(ebda_seg), ((struct extended_bios_data_area_s *)0)->var, (val))
+static inline u16 get_ebda_seg() {
+    return GET_BDA(ebda_seg);
+}
 static inline struct extended_bios_data_area_s *
 get_ebda_ptr()
 {
     extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
     if (MODE16)
         return __force_link_error__get_ebda_ptr_only_in_32bit();
-    return (void*)MAKE_FARPTR(GET_BDA(ebda_seg), 0);
+    return (void*)MAKE_FARPTR(get_ebda_seg(), 0);
 }
+#define GET_EBDA2(eseg, var)                                            \
+    GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
+#define SET_EBDA2(eseg, var, val)                                       \
+    SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
+#define GET_EBDA(var)                                            \
+    GET_EBDA2(get_ebda_seg(), var)
+#define SET_EBDA(var, val)                                       \
+    SET_EBDA2(get_ebda_seg(), var, (val))
 
 
 /****************************************************************
diff --git a/src/boot.c b/src/boot.c
index b8104a5..7b64e86 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -83,8 +83,6 @@
     if (! CONFIG_BOOT)
         BX_PANIC("Boot support not compiled in.\n");
 
-    SET_EBDA(boot_sequence, seq_nr);
-
     u32 bootdev = IPL.bootorder;
     bootdev >>= 4 * seq_nr;
     bootdev &= 0xf;
@@ -202,7 +200,9 @@
 {
     debug_serial_setup();
     debug_enter(NULL, DEBUG_HDL_18);
-    u16 seq = GET_EBDA(boot_sequence) + 1;
+    u16 ebda_seg = get_ebda_seg();
+    u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1;
+    SET_EBDA2(ebda_seg, boot_sequence, seq);
     do_boot(seq);
 }
 
@@ -212,6 +212,7 @@
 {
     debug_serial_setup();
     debug_enter(NULL, DEBUG_HDL_19);
+    SET_EBDA(boot_sequence, 0);
     do_boot(0);
 }
 
diff --git a/src/cdrom.c b/src/cdrom.c
index 7ce7da7..1fe2ebc 100644
--- a/src/cdrom.c
+++ b/src/cdrom.c
@@ -29,13 +29,14 @@
 static void
 cdrom_134500(struct bregs *regs, u8 device)
 {
-    u8 locks = GET_EBDA(cdrom_locks[device]);
+    u16 ebda_seg = get_ebda_seg();
+    u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[device]);
     if (locks == 0xff) {
         regs->al = 1;
         disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
         return;
     }
-    SET_EBDA(cdrom_locks[device], locks + 1);
+    SET_EBDA2(ebda_seg, cdrom_locks[device], locks + 1);
     regs->al = 1;
     disk_ret(regs, DISK_RET_SUCCESS);
 }
@@ -44,14 +45,15 @@
 static void
 cdrom_134501(struct bregs *regs, u8 device)
 {
-    u8 locks = GET_EBDA(cdrom_locks[device]);
+    u16 ebda_seg = get_ebda_seg();
+    u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[device]);
     if (locks == 0x00) {
         regs->al = 0;
         disk_ret(regs, DISK_RET_ENOTLOCKED);
         return;
     }
     locks--;
-    SET_EBDA(cdrom_locks[device], locks);
+    SET_EBDA2(ebda_seg, cdrom_locks[device], locks);
     regs->al = (locks ? 1 : 0);
     disk_ret(regs, DISK_RET_SUCCESS);
 }
diff --git a/src/disk.c b/src/disk.c
index 533c254..2b40b2f 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -407,9 +407,10 @@
 
     // EDD 2.x
 
+    u16 ebda_seg = get_ebda_seg();
     SET_INT13DPT(regs, size, 30);
 
-    SET_INT13DPT(regs, dpte_segment, GET_BDA(ebda_seg));
+    SET_INT13DPT(regs, dpte_segment, ebda_seg);
     SET_INT13DPT(regs, dpte_offset
                  , offsetof(struct extended_bios_data_area_s, dpte));
 
@@ -440,22 +441,22 @@
     if (mode == ATA_MODE_PIO32)
         options |= 1<<7;
 
-    SET_EBDA(dpte.iobase1, iobase1);
-    SET_EBDA(dpte.iobase2, iobase2 + ATA_CB_DC);
-    SET_EBDA(dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
-                               | ATA_CB_DH_LBA));
-    SET_EBDA(dpte.unused, 0xcb);
-    SET_EBDA(dpte.irq, irq);
-    SET_EBDA(dpte.blkcount, 1);
-    SET_EBDA(dpte.dma, 0);
-    SET_EBDA(dpte.pio, 0);
-    SET_EBDA(dpte.options, options);
-    SET_EBDA(dpte.reserved, 0);
-    SET_EBDA(dpte.revision, 0x11);
+    SET_EBDA2(ebda_seg, dpte.iobase1, iobase1);
+    SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC);
+    SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
+                                      | ATA_CB_DH_LBA));
+    SET_EBDA2(ebda_seg, dpte.unused, 0xcb);
+    SET_EBDA2(ebda_seg, dpte.irq, irq);
+    SET_EBDA2(ebda_seg, dpte.blkcount, 1);
+    SET_EBDA2(ebda_seg, dpte.dma, 0);
+    SET_EBDA2(ebda_seg, dpte.pio, 0);
+    SET_EBDA2(ebda_seg, dpte.options, options);
+    SET_EBDA2(ebda_seg, dpte.reserved, 0);
+    SET_EBDA2(ebda_seg, dpte.revision, 0x11);
 
-    u8 *p = MAKE_FARPTR(GET_BDA(ebda_seg)
+    u8 *p = MAKE_FARPTR(ebda_seg
                         , offsetof(struct extended_bios_data_area_s, dpte));
-    SET_EBDA(dpte.checksum, -checksum(p, 15));
+    SET_EBDA2(ebda_seg, dpte.checksum, -checksum(p, 15));
 
     if (size < 66) {
         disk_ret(regs, DISK_RET_SUCCESS);
diff --git a/src/mouse.c b/src/mouse.c
index daac505..6c74fc1 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -30,12 +30,12 @@
 #define RET_ENOHANDLER   0x05
 
 static int
-disable_mouse()
+disable_mouse(u16 ebda_seg)
 {
-    u8 ps2ctr = GET_EBDA(ps2ctr);
+    u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr);
     ps2ctr |= I8042_CTR_AUXDIS;
     ps2ctr &= ~I8042_CTR_AUXINT;
-    SET_EBDA(ps2ctr, ps2ctr);
+    SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
 
     return aux_command(PSMOUSE_CMD_DISABLE, NULL);
 }
@@ -44,7 +44,8 @@
 static void
 mouse_15c20000(struct bregs *regs)
 {
-    int ret = disable_mouse();
+    u16 ebda_seg = get_ebda_seg();
+    int ret = disable_mouse(ebda_seg);
     if (ret)
         set_code_fail(regs, RET_ENEEDRESEND);
     else
@@ -55,16 +56,17 @@
 static void
 mouse_15c20001(struct bregs *regs)
 {
-    u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
+    u16 ebda_seg = get_ebda_seg();
+    u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2);
     if ((mouse_flags_2 & 0x80) == 0) {
         set_code_fail(regs, RET_ENOHANDLER);
         return;
     }
 
-    u8 ps2ctr = GET_EBDA(ps2ctr);
+    u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr);
     ps2ctr &= ~I8042_CTR_AUXDIS;
     ps2ctr |= I8042_CTR_AUXINT;
-    SET_EBDA(ps2ctr, ps2ctr);
+    SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
 
     int ret = aux_command(PSMOUSE_CMD_ENABLE, NULL);
     if (ret)
@@ -165,8 +167,9 @@
         set_code_fail(regs, RET_EINTERFACE);
         return;
     }
-    SET_EBDA(mouse_flag1, 0x00);
-    SET_EBDA(mouse_flag2, regs->bh);
+    u16 ebda_seg = get_ebda_seg();
+    SET_EBDA2(ebda_seg, mouse_flag1, 0x00);
+    SET_EBDA2(ebda_seg, mouse_flag2, regs->bh);
 
     // Reset Mouse
     mouse_15c201(regs);
@@ -233,19 +236,20 @@
 mouse_15c207(struct bregs *regs)
 {
     u32 farptr = (regs->es << 16) | regs->bx;
-    u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
+    u16 ebda_seg = get_ebda_seg();
+    u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2);
     if (! farptr) {
         /* remove handler */
         if ((mouse_flags_2 & 0x80) != 0) {
             mouse_flags_2 &= ~0x80;
-            disable_mouse();
+            disable_mouse(ebda_seg);
         }
     } else {
         /* install handler */
         mouse_flags_2 |= 0x80;
     }
-    SET_EBDA(mouse_flag2, mouse_flags_2);
-    SET_EBDA(far_call_pointer, farptr);
+    SET_EBDA2(ebda_seg, mouse_flag2, mouse_flags_2);
+    SET_EBDA2(ebda_seg, far_call_pointer, farptr);
     set_code_success(regs);
 }
 
@@ -290,8 +294,9 @@
     }
     v = inb(PORT_PS2_DATA);
 
-    u8 mouse_flags_1 = GET_EBDA(mouse_flag1);
-    u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
+    u16 ebda_seg = get_ebda_seg();
+    u8 mouse_flags_1 = GET_EBDA2(ebda_seg, mouse_flag1);
+    u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2);
 
     if (! (mouse_flags_2 & 0x80))
         // far call handler not installed
@@ -299,21 +304,21 @@
 
     u8 package_count = mouse_flags_2 & 0x07;
     u8 index = mouse_flags_1 & 0x07;
-    SET_EBDA(mouse_data[index], v);
+    SET_EBDA2(ebda_seg, mouse_data[index], v);
 
     if ((index+1) < package_count) {
         mouse_flags_1++;
-        SET_EBDA(mouse_flag1, mouse_flags_1);
+        SET_EBDA2(ebda_seg, mouse_flag1, mouse_flags_1);
         return;
     }
 
     //BX_DEBUG_INT74("int74_function: make_farcall=1\n");
-    u16 status = GET_EBDA(mouse_data[0]);
-    u16 X      = GET_EBDA(mouse_data[1]);
-    u16 Y      = GET_EBDA(mouse_data[2]);
-    SET_EBDA(mouse_flag1, 0);
+    u16 status = GET_EBDA2(ebda_seg, mouse_data[0]);
+    u16 X      = GET_EBDA2(ebda_seg, mouse_data[1]);
+    u16 Y      = GET_EBDA2(ebda_seg, mouse_data[2]);
+    SET_EBDA2(ebda_seg, mouse_flag1, 0);
 
-    u32 func = GET_EBDA(far_call_pointer);
+    u32 func = GET_EBDA2(ebda_seg, far_call_pointer);
     asm volatile(
         "pushl %0\n"
         "pushw %w1\n"  // status
diff --git a/src/post.c b/src/post.c
index cc86abf..c2a9b62 100644
--- a/src/post.c
+++ b/src/post.c
@@ -126,7 +126,8 @@
     add_e820(0xa0000, 0x50000, E820_HOLE);
 
     // Mark known areas as reserved.
-    add_e820((u32)MAKE_FARPTR(GET_BDA(ebda_seg), 0), GET_EBDA(size) * 1024
+    u16 ebda_seg = get_ebda_seg();
+    add_e820((u32)MAKE_FARPTR(ebda_seg, 0), GET_EBDA2(ebda_seg, size) * 1024
              , E820_RESERVED);
     add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
diff --git a/src/system.c b/src/system.c
index 7a0d20c..235e88c 100644
--- a/src/system.c
+++ b/src/system.c
@@ -232,7 +232,7 @@
 static void
 handle_15c1(struct bregs *regs)
 {
-    regs->es = GET_BDA(ebda_seg);
+    regs->es = get_ebda_seg();
     set_success(regs);
 }