summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Iorga <cristian.iorga@intel.com>2014-05-30 20:11:11 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-06-02 22:41:59 +0100
commit3e890dd00ed27cc30800caefa85827cb16da5a3a (patch)
tree58f53e9d9592fac04c83ebf77c3efe70a6492841
parent6433f5d68eba1ce7306fbfb19265ea6786715d7c (diff)
downloadopenembedded-core-3e890dd00ed27cc30800caefa85827cb16da5a3a.tar.gz
openembedded-core-3e890dd00ed27cc30800caefa85827cb16da5a3a.tar.bz2
openembedded-core-3e890dd00ed27cc30800caefa85827cb16da5a3a.zip
v86d: fix for SeaBIOS VGA BIOS compatibility
This fixes a compatibility issue between v86d and SeaBIOS VGA BIOS where the leal instruction is not decoded properly. Read the http://thread.gmane.org/gmane.comp.emulators.qemu/271806 thread for more details. Patch taken from upstream. Signed-off-by: Cristian Iorga <cristian.iorga@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-bsp/v86d/v86d/Update-x86emu-from-X.org.patch21766
-rw-r--r--meta/recipes-bsp/v86d/v86d_0.1.10.bb3
2 files changed, 21768 insertions, 1 deletions
diff --git a/meta/recipes-bsp/v86d/v86d/Update-x86emu-from-X.org.patch b/meta/recipes-bsp/v86d/v86d/Update-x86emu-from-X.org.patch
new file mode 100644
index 0000000000..a09e2a257e
--- /dev/null
+++ b/meta/recipes-bsp/v86d/v86d/Update-x86emu-from-X.org.patch
@@ -0,0 +1,21766 @@
+From 1a410ae58f28eeab32fa87626cfd5a663ba33c51 Mon Sep 17 00:00:00 2001
+From: Bernhard Walle <bernhard@bwalle.de>
+Date: Tue, 13 May 2014 23:40:56 +0200
+Subject: [PATCH 2/2] Update x86emu from X.org
+
+This commit updates the x86emu copy from X.org tarball
+(ftp://mirror.csclub.uwaterloo.ca/x.org/current/src/xserver/xorg-server-1.12.2.tar.bz2).
+
+This fixes a compatibility issue between v86d and SeaBIOS VGA BIOS where
+the leal instruction is not decoded properly. Read the
+http://thread.gmane.org/gmane.comp.emulators.qemu/271806 thread for more
+details.
+
+Upstream-Status: Backport
+
+Signed-off-by: Bernhard Walle <bernhard@bwalle.de>
+---
+ libs/x86emu/LICENSE | 17 -
+ libs/x86emu/debug.c | 509 +++---
+ libs/x86emu/decode.c | 1069 ++++++------
+ libs/x86emu/fpu.c | 463 +++---
+ libs/x86emu/ops.c | 2940 +++++++++++++++++++--------------
+ libs/x86emu/ops2.c | 1929 +++++++++++-----------
+ libs/x86emu/prim_ops.c | 3219 +++++++++++++++++++------------------
+ libs/x86emu/sys.c | 583 +++----
+ libs/x86emu/validate.c | 52 +-
+ libs/x86emu/x86emu.h | 75 +-
+ libs/x86emu/x86emu/debug.h | 163 +-
+ libs/x86emu/x86emu/decode.h | 57 +-
+ libs/x86emu/x86emu/fpu.h | 23 +-
+ libs/x86emu/x86emu/fpu_regs.h | 44 +-
+ libs/x86emu/x86emu/ops.h | 6 +-
+ libs/x86emu/x86emu/prim_asm.h | 251 ++-
+ libs/x86emu/x86emu/prim_ops.h | 188 +--
+ libs/x86emu/x86emu/prim_x86_gcc.h | 77 +
+ libs/x86emu/x86emu/regs.h | 101 +-
+ libs/x86emu/x86emu/types.h | 50 +-
+ libs/x86emu/x86emu/x86emui.h | 34 +-
+ 21 files changed, 6379 insertions(+), 5471 deletions(-)
+ delete mode 100644 libs/x86emu/LICENSE
+ create mode 100644 libs/x86emu/x86emu/prim_x86_gcc.h
+
+diff --git a/libs/x86emu/LICENSE b/libs/x86emu/LICENSE
+deleted file mode 100644
+index a3ede4a..0000000
+--- a/libs/x86emu/LICENSE
++++ /dev/null
+@@ -1,17 +0,0 @@
+- License information
+- -------------------
+-
+-The x86emu library is under a BSD style license, comaptible
+-with the XFree86 and X licenses used by XFree86. The
+-original x86emu libraries were under the GNU General Public
+-License. Due to license incompatibilities between the GPL
+-and the XFree86 license, the original authors of the code
+-decided to allow a license change. If you have submitted
+-code to the original x86emu project, and you don't agree
+-with the license change, please contact us and let you
+-know. Your code will be removed to comply with your wishes.
+-
+-If you have any questions about this, please send email to
+-x86emu@linuxlabs.com or KendallB@scitechsoft.com for
+-clarification.
+-
+diff --git a/libs/x86emu/debug.c b/libs/x86emu/debug.c
+index 6fd7f11..1a8d1d6 100644
+--- a/libs/x86emu/debug.c
++++ b/libs/x86emu/debug.c
+@@ -38,6 +38,8 @@
+ ****************************************************************************/
+
+ #include "x86emu/x86emui.h"
++#include <stdio.h>
++#include <string.h>
+ #ifndef NO_SYS_HEADERS
+ #include <stdarg.h>
+ #include <stdlib.h>
+@@ -47,46 +49,51 @@
+
+ #ifdef DEBUG
+
+-static void print_encoded_bytes (u16 s, u16 o);
+-static void print_decoded_instruction (void);
+-static int parse_line (char *s, int *ps, int *n);
+-
++static void print_encoded_bytes(u16 s, u16 o);
++static void print_decoded_instruction(void);
++static int parse_line(char *s, int *ps, int *n);
++
+ /* should look something like debug's output. */
+-void X86EMU_trace_regs (void)
++void
++X86EMU_trace_regs(void)
+ {
+- if (DEBUG_TRACE()) {
+- x86emu_dump_regs();
++ if (DEBUG_TRACE()) {
++ x86emu_dump_regs();
+ }
+- if (DEBUG_DECODE() && ! DEBUG_DECODE_NOPRINT()) {
+- printk("%04x:%04x ",M.x86.saved_cs, M.x86.saved_ip);
+- print_encoded_bytes( M.x86.saved_cs, M.x86.saved_ip);
+- print_decoded_instruction();
++ if (DEBUG_DECODE() && !DEBUG_DECODE_NOPRINT()) {
++ printk("%04x:%04x ", M.x86.saved_cs, M.x86.saved_ip);
++ print_encoded_bytes(M.x86.saved_cs, M.x86.saved_ip);
++ print_decoded_instruction();
+ }
+ }
+
+-void X86EMU_trace_xregs (void)
++void
++X86EMU_trace_xregs(void)
+ {
+- if (DEBUG_TRACE()) {
+- x86emu_dump_xregs();
++ if (DEBUG_TRACE()) {
++ x86emu_dump_xregs();
+ }
+ }
+
+-void x86emu_just_disassemble (void)
++void
++x86emu_just_disassemble(void)
+ {
+ /*
+ * This routine called if the flag DEBUG_DISASSEMBLE is set kind
+ * of a hack!
+ */
+- printk("%04x:%04x ",M.x86.saved_cs, M.x86.saved_ip);
+- print_encoded_bytes( M.x86.saved_cs, M.x86.saved_ip);
+- print_decoded_instruction();
++ printk("%04x:%04x ", M.x86.saved_cs, M.x86.saved_ip);
++ print_encoded_bytes(M.x86.saved_cs, M.x86.saved_ip);
++ print_decoded_instruction();
+ }
+
+-static void disassemble_forward (u16 seg, u16 off, int n)
++static void
++disassemble_forward(u16 seg, u16 off, int n)
+ {
+- X86EMU_sysEnv tregs;
+- int i;
+- u8 op1;
++ X86EMU_sysEnv tregs;
++ int i;
++ u8 op1;
++
+ /*
+ * hack, hack, hack. What we do is use the exact machinery set up
+ * for execution, except that now there is an additional state
+@@ -111,17 +118,17 @@ static void disassemble_forward (u16 seg, u16 off, int n)
+ * This was done for an entirely different reason, but makes a
+ * nice way to get the system to help debug codes.
+ */
+- tregs = M;
++ tregs = M;
+ tregs.x86.R_IP = off;
+ tregs.x86.R_CS = seg;
+-
++
+ /* reset the decoding buffers */
+ tregs.x86.enc_str_pos = 0;
+ tregs.x86.enc_pos = 0;
+-
++
+ /* turn on the "disassemble only, no execute" flag */
+ tregs.x86.debug |= DEBUG_DISASSEMBLE_F;
+-
++
+ /* DUMP NEXT n instructions to screen in straight_line fashion */
+ /*
+ * This looks like the regular instruction fetch stream, except
+@@ -130,299 +137,359 @@ static void disassemble_forward (u16 seg, u16 off, int n)
+ * the instruction. XXX --- CHECK THAT MEM IS NOT AFFECTED!!!
+ * Note the use of a copy of the register structure...
+ */
+- for (i=0; i<n; i++) {
+- op1 = (*sys_rdb)(((u32)M.x86.R_CS<<4) + (M.x86.R_IP++));
+- (x86emu_optab[op1])(op1);
++ for (i = 0; i < n; i++) {
++ op1 = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++));
++ (x86emu_optab[op1]) (op1);
+ }
+ /* end major hack mode. */
+ }
+
+-void x86emu_check_ip_access (void)
++void
++x86emu_check_ip_access(void)
+ {
+ /* NULL as of now */
+ }
+
+-void x86emu_check_sp_access (void)
++void
++x86emu_check_sp_access(void)
+ {
+ }
+
+-void x86emu_check_mem_access (u32 dummy)
++void
++x86emu_check_mem_access(u32 dummy)
+ {
+- /* check bounds, etc */
++ /* check bounds, etc */
+ }
+
+-void x86emu_check_data_access (uint dummy1, uint dummy2)
++void
++x86emu_check_data_access(uint dummy1, uint dummy2)
+ {
+- /* check bounds, etc */
++ /* check bounds, etc */
+ }
+
+-void x86emu_inc_decoded_inst_len (int x)
++void
++x86emu_inc_decoded_inst_len(int x)
+ {
+- M.x86.enc_pos += x;
++ M.x86.enc_pos += x;
+ }
+
+-void x86emu_decode_printf (char *x)
++void
++x86emu_decode_printf(const char *x)
+ {
+- sprintf(M.x86.decoded_buf+M.x86.enc_str_pos,"%s",x);
+- M.x86.enc_str_pos += strlen(x);
++ sprintf(M.x86.decoded_buf + M.x86.enc_str_pos, "%s", x);
++ M.x86.enc_str_pos += strlen(x);
+ }
+
+-void x86emu_decode_printf2 (char *x, int y)
++void
++x86emu_decode_printf2(const char *x, int y)
+ {
+- char temp[100];
+- sprintf(temp,x,y);
+- sprintf(M.x86.decoded_buf+M.x86.enc_str_pos,"%s",temp);
+- M.x86.enc_str_pos += strlen(temp);
++ char temp[100];
++
++ snprintf(temp, sizeof(temp), x, y);
++ sprintf(M.x86.decoded_buf + M.x86.enc_str_pos, "%s", temp);
++ M.x86.enc_str_pos += strlen(temp);
+ }
+
+-void x86emu_end_instr (void)
++void
++x86emu_end_instr(void)
+ {
+- M.x86.enc_str_pos = 0;
+- M.x86.enc_pos = 0;
++ M.x86.enc_str_pos = 0;
++ M.x86.enc_pos = 0;
+ }
+
+-static void print_encoded_bytes (u16 s, u16 o)
++static void
++print_encoded_bytes(u16 s, u16 o)
+ {
+ int i;
+ char buf1[64];
+- for (i=0; i< M.x86.enc_pos; i++) {
+- sprintf(buf1+2*i,"%02x", fetch_data_byte_abs(s,o+i));
++
++ for (i = 0; i < M.x86.enc_pos; i++) {
++ sprintf(buf1 + 2 * i, "%02x", fetch_data_byte_abs(s, o + i));
+ }
+- printk("%-20s",buf1);
++ printk("%-20s", buf1);
+ }
+
+-static void print_decoded_instruction (void)
++static void
++print_decoded_instruction(void)
+ {
+- printk("%s", M.x86.decoded_buf);
++ printk("%s", M.x86.decoded_buf);
+ }
+
+-void x86emu_print_int_vect (u16 iv)
++void
++x86emu_print_int_vect(u16 iv)
+ {
+- u16 seg,off;
++ u16 seg, off;
+
+- if (iv > 256) return;
+- seg = fetch_data_word_abs(0,iv*4);
+- off = fetch_data_word_abs(0,iv*4+2);
+- printk("%04x:%04x ", seg, off);
++ if (iv > 256)
++ return;
++ seg = fetch_data_word_abs(0, iv * 4);
++ off = fetch_data_word_abs(0, iv * 4 + 2);
++ printk("%04x:%04x ", seg, off);
+ }
+
+-void X86EMU_dump_memory (u16 seg, u16 off, u32 amt)
++void
++X86EMU_dump_memory(u16 seg, u16 off, u32 amt)
+ {
+- u32 start = off & 0xfffffff0;
+- u32 end = (off+16) & 0xfffffff0;
+- u32 i;
+- u32 current;
+-
+- current = start;
+- while (end <= off + amt) {
+- printk("%04x:%04x ", seg, start);
+- for (i=start; i< off; i++)
+- printk(" ");
+- for ( ; i< end; i++)
+- printk("%02x ", fetch_data_byte_abs(seg,i));
+- printk("\n");
+- start = end;
+- end = start + 16;
+- }
++ u32 start = off & 0xfffffff0;
++ u32 end = (off + 16) & 0xfffffff0;
++ u32 i;
++ u32 current;
++
++ current = start;
++ while (end <= off + amt) {
++ printk("%04x:%04x ", seg, start);
++ for (i = start; i < off; i++)
++ printk(" ");
++ for (; i < end; i++)
++ printk("%02x ", fetch_data_byte_abs(seg, i));
++ printk("\n");
++ start = end;
++ end = start + 16;
++ }
+ }
+
+-void x86emu_single_step (void)
++void
++x86emu_single_step(void)
+ {
+ char s[1024];
+ int ps[10];
+ int ntok;
+ int cmd;
+ int done;
+- int segment;
++ int segment;
+ int offset;
+ static int breakpoint;
+ static int noDecode = 1;
+-
++
+ char *p;
+
+- if (DEBUG_BREAK()) {
+- if (M.x86.saved_ip != breakpoint) {
+- return;
+- } else {
+- M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F;
+- M.x86.debug |= DEBUG_TRACE_F;
+- M.x86.debug &= ~DEBUG_BREAK_F;
+- print_decoded_instruction ();
+- X86EMU_trace_regs();
+- }
+- }
+- done=0;
+- offset = M.x86.saved_ip;
++ if (DEBUG_BREAK()) {
++ if (M.x86.saved_ip != breakpoint) {
++ return;
++ }
++ else {
++ M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F;
++ M.x86.debug |= DEBUG_TRACE_F;
++ M.x86.debug &= ~DEBUG_BREAK_F;
++ print_decoded_instruction();
++ X86EMU_trace_regs();
++ }
++ }
++ done = 0;
++ offset = M.x86.saved_ip;
+ while (!done) {
+ printk("-");
+ p = fgets(s, 1023, stdin);
+ cmd = parse_line(s, ps, &ntok);
+- switch(cmd) {
+- case 'u':
+- disassemble_forward(M.x86.saved_cs,(u16)offset,10);
++ switch (cmd) {
++ case 'u':
++ disassemble_forward(M.x86.saved_cs, (u16) offset, 10);
+ break;
+- case 'd':
+- if (ntok == 2) {
+- segment = M.x86.saved_cs;
+- offset = ps[1];
+- X86EMU_dump_memory(segment,(u16)offset,16);
+- offset += 16;
+- } else if (ntok == 3) {
+- segment = ps[1];
+- offset = ps[2];
+- X86EMU_dump_memory(segment,(u16)offset,16);
+- offset += 16;
+- } else {
+- segment = M.x86.saved_cs;
+- X86EMU_dump_memory(segment,(u16)offset,16);
+- offset += 16;
+- }
++ case 'd':
++ if (ntok == 2) {
++ segment = M.x86.saved_cs;
++ offset = ps[1];
++ X86EMU_dump_memory(segment, (u16) offset, 16);
++ offset += 16;
++ }
++ else if (ntok == 3) {
++ segment = ps[1];
++ offset = ps[2];
++ X86EMU_dump_memory(segment, (u16) offset, 16);
++ offset += 16;
++ }
++ else {
++ segment = M.x86.saved_cs;
++ X86EMU_dump_memory(segment, (u16) offset, 16);
++ offset += 16;
++ }
+ break;
+- case 'c':
+- M.x86.debug ^= DEBUG_TRACECALL_F;
++ case 'c':
++ M.x86.debug ^= DEBUG_TRACECALL_F;
+ break;
+- case 's':
+- M.x86.debug ^= DEBUG_SVC_F | DEBUG_SYS_F | DEBUG_SYSINT_F;
++ case 's':
++ M.x86.debug ^= DEBUG_SVC_F | DEBUG_SYS_F | DEBUG_SYSINT_F;
+ break;
+- case 'r':
+- X86EMU_trace_regs();
++ case 'r':
++ X86EMU_trace_regs();
+ break;
+- case 'x':
+- X86EMU_trace_xregs();
++ case 'x':
++ X86EMU_trace_xregs();
+ break;
+- case 'g':
++ case 'g':
+ if (ntok == 2) {
+ breakpoint = ps[1];
+- if (noDecode) {
+- M.x86.debug |= DEBUG_DECODE_NOPRINT_F;
+- } else {
+- M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F;
+- }
+- M.x86.debug &= ~DEBUG_TRACE_F;
+- M.x86.debug |= DEBUG_BREAK_F;
+- done = 1;
++ if (noDecode) {
++ M.x86.debug |= DEBUG_DECODE_NOPRINT_F;
++ }
++ else {
++ M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F;
++ }
++ M.x86.debug &= ~DEBUG_TRACE_F;
++ M.x86.debug |= DEBUG_BREAK_F;
++ done = 1;
+ }
+ break;
+- case 'q':
+- M.x86.debug |= DEBUG_EXIT;
+- return;
+- case 'P':
+- noDecode = (noDecode)?0:1;
+- printk("Toggled decoding to %s\n",(noDecode)?"FALSE":"TRUE");
+- break;
+- case 't':
+- case 0:
++ case 'q':
++ M.x86.debug |= DEBUG_EXIT;
++ return;
++ case 'P':
++ noDecode = (noDecode) ? 0 : 1;
++ printk("Toggled decoding to %s\n", (noDecode) ? "FALSE" : "TRUE");
++ break;
++ case 't':
++ case 0:
+ done = 1;
+ break;
+- }
++ }
+ }
+ }
+
+-int X86EMU_trace_on(void)
++int
++X86EMU_trace_on(void)
+ {
+- return M.x86.debug |= DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F;
++ return M.x86.debug |= DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F;
+ }
+
+-int X86EMU_trace_off(void)
++int
++X86EMU_trace_off(void)
+ {
+- return M.x86.debug &= ~(DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F);
++ return M.x86.debug &= ~(DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F);
+ }
+
+-static int parse_line (char *s, int *ps, int *n)
++static int
++parse_line(char *s, int *ps, int *n)
+ {
+ int cmd;
+
+ *n = 0;
+- while(*s == ' ' || *s == '\t') s++;
++ while (*s == ' ' || *s == '\t')
++ s++;
+ ps[*n] = *s;
+ switch (*s) {
+- case '\n':
++ case '\n':
+ *n += 1;
+ return 0;
+- default:
++ default:
+ cmd = *s;
+ *n += 1;
+ }
+
+- while (1) {
+- while (*s != ' ' && *s != '\t' && *s != '\n') s++;
+-
+- if (*s == '\n')
+- return cmd;
+-
+- while(*s == ' ' || *s == '\t') s++;
+-
+- sscanf(s,"%x",&ps[*n]);
+- *n += 1;
+- }
++ while (1) {
++ while (*s != ' ' && *s != '\t' && *s != '\n')
++ s++;
++
++ if (*s == '\n')
++ return cmd;
++
++ while (*s == ' ' || *s == '\t')
++ s++;
++
++ sscanf(s, "%x", &ps[*n]);
++ *n += 1;
++ }
+ }
+
+-#endif /* DEBUG */
++#endif /* DEBUG */
+
+-void x86emu_dump_regs (void)
++void
++x86emu_dump_regs(void)
+ {
+- printk("\tAX=%04x ", M.x86.R_AX );
+- printk("BX=%04x ", M.x86.R_BX );
+- printk("CX=%04x ", M.x86.R_CX );
+- printk("DX=%04x ", M.x86.R_DX );
+- printk("SP=%04x ", M.x86.R_SP );
+- printk("BP=%04x ", M.x86.R_BP );
+- printk("SI=%04x ", M.x86.R_SI );
+- printk("DI=%04x\n", M.x86.R_DI );
+- printk("\tDS=%04x ", M.x86.R_DS );
+- printk("ES=%04x ", M.x86.R_ES );
+- printk("SS=%04x ", M.x86.R_SS );
+- printk("CS=%04x ", M.x86.R_CS );
+- printk("IP=%04x ", M.x86.R_IP );
+- if (ACCESS_FLAG(F_OF)) printk("OV "); /* CHECKED... */
+- else printk("NV ");
+- if (ACCESS_FLAG(F_DF)) printk("DN ");
+- else printk("UP ");
+- if (ACCESS_FLAG(F_IF)) printk("EI ");
+- else printk("DI ");
+- if (ACCESS_FLAG(F_SF)) printk("NG ");
+- else printk("PL ");
+- if (ACCESS_FLAG(F_ZF)) printk("ZR ");
+- else printk("NZ ");
+- if (ACCESS_FLAG(F_AF)) printk("AC ");
+- else printk("NA ");
+- if (ACCESS_FLAG(F_PF)) printk("PE ");
+- else printk("PO ");
+- if (ACCESS_FLAG(F_CF)) printk("CY ");
+- else printk("NC ");
+- printk("\n");
++ printk("\tAX=%04x ", M.x86.R_AX);
++ printk("BX=%04x ", M.x86.R_BX);
++ printk("CX=%04x ", M.x86.R_CX);
++ printk("DX=%04x ", M.x86.R_DX);
++ printk("SP=%04x ", M.x86.R_SP);
++ printk("BP=%04x ", M.x86.R_BP);
++ printk("SI=%04x ", M.x86.R_SI);
++ printk("DI=%04x\n", M.x86.R_DI);
++ printk("\tDS=%04x ", M.x86.R_DS);
++ printk("ES=%04x ", M.x86.R_ES);
++ printk("SS=%04x ", M.x86.R_SS);
++ printk("CS=%04x ", M.x86.R_CS);
++ printk("IP=%04x ", M.x86.R_IP);
++ if (ACCESS_FLAG(F_OF))
++ printk("OV "); /* CHECKED... */
++ else
++ printk("NV ");
++ if (ACCESS_FLAG(F_DF))
++ printk("DN ");
++ else
++ printk("UP ");
++ if (ACCESS_FLAG(F_IF))
++ printk("EI ");
++ else
++ printk("DI ");
++ if (ACCESS_FLAG(F_SF))
++ printk("NG ");
++ else
++ printk("PL ");
++ if (ACCESS_FLAG(F_ZF))
++ printk("ZR ");
++ else
++ printk("NZ ");
++ if (ACCESS_FLAG(F_AF))
++ printk("AC ");
++ else
++ printk("NA ");
++ if (ACCESS_FLAG(F_PF))
++ printk("PE ");
++ else
++ printk("PO ");
++ if (ACCESS_FLAG(F_CF))
++ printk("CY ");
++ else
++ printk("NC ");
++ printk("\n");
+ }
+
+-void x86emu_dump_xregs (void)
++void
++x86emu_dump_xregs(void)
+ {
+- printk("\tEAX=%08x ", M.x86.R_EAX );
+- printk("EBX=%08x ", M.x86.R_EBX );
+- printk("ECX=%08x ", M.x86.R_ECX );
+- printk("EDX=%08x \n", M.x86.R_EDX );
+- printk("\tESP=%08x ", M.x86.R_ESP );
+- printk("EBP=%08x ", M.x86.R_EBP );
+- printk("ESI=%08x ", M.x86.R_ESI );
+- printk("EDI=%08x\n", M.x86.R_EDI );
+- printk("\tDS=%04x ", M.x86.R_DS );
+- printk("ES=%04x ", M.x86.R_ES );
+- printk("SS=%04x ", M.x86.R_SS );
+- printk("CS=%04x ", M.x86.R_CS );
+- printk("EIP=%08x\n\t", M.x86.R_EIP );
+- if (ACCESS_FLAG(F_OF)) printk("OV "); /* CHECKED... */
+- else printk("NV ");
+- if (ACCESS_FLAG(F_DF)) printk("DN ");
+- else printk("UP ");
+- if (ACCESS_FLAG(F_IF)) printk("EI ");
+- else printk("DI ");
+- if (ACCESS_FLAG(F_SF)) printk("NG ");
+- else printk("PL ");
+- if (ACCESS_FLAG(F_ZF)) printk("ZR ");
+- else printk("NZ ");
+- if (ACCESS_FLAG(F_AF)) printk("AC ");
+- else printk("NA ");
+- if (ACCESS_FLAG(F_PF)) printk("PE ");
+- else printk("PO ");
+- if (ACCESS_FLAG(F_CF)) printk("CY ");
+- else printk("NC ");
+- printk("\n");
++ printk("\tEAX=%08x ", M.x86.R_EAX);
++ printk("EBX=%08x ", M.x86.R_EBX);
++ printk("ECX=%08x ", M.x86.R_ECX);
++ printk("EDX=%08x \n", M.x86.R_EDX);
++ printk("\tESP=%08x ", M.x86.R_ESP);
++ printk("EBP=%08x ", M.x86.R_EBP);
++ printk("ESI=%08x ", M.x86.R_ESI);
++ printk("EDI=%08x\n", M.x86.R_EDI);
++ printk("\tDS=%04x ", M.x86.R_DS);
++ printk("ES=%04x ", M.x86.R_ES);
++ printk("SS=%04x ", M.x86.R_SS);
++ printk("CS=%04x ", M.x86.R_CS);
++ printk("EIP=%08x\n\t", M.x86.R_EIP);
++ if (ACCESS_FLAG(F_OF))
++ printk("OV "); /* CHECKED... */
++ else
++ printk("NV ");
++ if (ACCESS_FLAG(F_DF))
++ printk("DN ");
++ else
++ printk("UP ");
++ if (ACCESS_FLAG(F_IF))
++ printk("EI ");
++ else
++ printk("DI ");
++ if (ACCESS_FLAG(F_SF))
++ printk("NG ");
++ else
++ printk("PL ");
++ if (ACCESS_FLAG(F_ZF))
++ printk("ZR ");
++ else
++ printk("NZ ");
++ if (ACCESS_FLAG(F_AF))
++ printk("AC ");
++ else
++ printk("NA ");
++ if (ACCESS_FLAG(F_PF))
++ printk("PE ");
++ else
++ printk("PO ");
++ if (ACCESS_FLAG(F_CF))
++ printk("CY ");
++ else
++ printk("NC ");
++ printk("\n");
+ }
+diff --git a/libs/x86emu/decode.c b/libs/x86emu/decode.c
+index 7d9a34a..12f8fb8 100644
+--- a/libs/x86emu/decode.c
++++ b/libs/x86emu/decode.c
+@@ -46,25 +46,27 @@
+ REMARKS:
+ Handles any pending asychronous interrupts.
+ ****************************************************************************/
+-static void x86emu_intr_handle(void)
++static void
++x86emu_intr_handle(void)
+ {
+- u8 intno;
+-
+- if (M.x86.intr & INTR_SYNCH) {
+- intno = M.x86.intno;
+- if (_X86EMU_intrTab[intno]) {
+- (*_X86EMU_intrTab[intno])(intno);
+- } else {
+- push_word((u16)M.x86.R_FLG);
+- CLEAR_FLAG(F_IF);
+- CLEAR_FLAG(F_TF);
+- push_word(M.x86.R_CS);
+- M.x86.R_CS = mem_access_word(intno * 4 + 2);
+- push_word(M.x86.R_IP);
+- M.x86.R_IP = mem_access_word(intno * 4);
+- M.x86.intr = 0;
+- }
+- }
++ u8 intno;
++
++ if (M.x86.intr & INTR_SYNCH) {
++ intno = M.x86.intno;
++ if (_X86EMU_intrTab[intno]) {
++ (*_X86EMU_intrTab[intno]) (intno);
++ }
++ else {
++ push_word((u16) M.x86.R_FLG);
++ CLEAR_FLAG(F_IF);
++ CLEAR_FLAG(F_TF);
++ push_word(M.x86.R_CS);
++ M.x86.R_CS = mem_access_word(intno * 4 + 2);
++ push_word(M.x86.R_IP);
++ M.x86.R_IP = mem_access_word(intno * 4);
++ M.x86.intr = 0;
++ }
++ }
+ }
+
+ /****************************************************************************
+@@ -75,11 +77,11 @@ REMARKS:
+ Raise the specified interrupt to be handled before the execution of the
+ next instruction.
+ ****************************************************************************/
+-void x86emu_intr_raise(
+- u8 intrnum)
++void
++x86emu_intr_raise(u8 intrnum)
+ {
+- M.x86.intno = intrnum;
+- M.x86.intr |= INTR_SYNCH;
++ M.x86.intno = intrnum;
++ M.x86.intr |= INTR_SYNCH;
+ }
+
+ /****************************************************************************
+@@ -88,39 +90,39 @@ Main execution loop for the emulator. We return from here when the system
+ halts, which is normally caused by a stack fault when we return from the
+ original real mode call.
+ ****************************************************************************/
+-void X86EMU_exec(void)
++void
++X86EMU_exec(void)
+ {
+- u8 op1;
+-
+- M.x86.intr = 0;
+- DB(x86emu_end_instr();)
+-
+- for (;;) {
+-DB( if (CHECK_IP_FETCH())
+- x86emu_check_ip_access();)
+- /* If debugging, save the IP and CS values. */
+- SAVE_IP_CS(M.x86.R_CS, M.x86.R_IP);
+- INC_DECODED_INST_LEN(1);
+- if (M.x86.intr) {
+- if (M.x86.intr & INTR_HALTED) {
+-DB( if (M.x86.R_SP != 0) {
+- printk("halted\n");
+- X86EMU_trace_regs();
+- }
+- else {
+- if (M.x86.debug)
+- printk("Service completed successfully\n");
+- })
+- return;
++ u8 op1;
++
++ M.x86.intr = 0;
++ DB(x86emu_end_instr();
++ )
++
++ for (;;) {
++ DB(if (CHECK_IP_FETCH())
++ x86emu_check_ip_access();)
++ /* If debugging, save the IP and CS values. */
++ SAVE_IP_CS(M.x86.R_CS, M.x86.R_IP);
++ INC_DECODED_INST_LEN(1);
++ if (M.x86.intr) {
++ if (M.x86.intr & INTR_HALTED) {
++ DB(if (M.x86.R_SP != 0) {
++ printk("halted\n"); X86EMU_trace_regs();}
++ else {
++ if (M.x86.debug)
++ printk("Service completed successfully\n");}
++ )
++ return;
+ }
+- if (((M.x86.intr & INTR_SYNCH) && (M.x86.intno == 0 || M.x86.intno == 2)) ||
+- !ACCESS_FLAG(F_IF)) {
+- x86emu_intr_handle();
+- }
+- }
+-
+- op1 = (*sys_rdb)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP++));
+- (*x86emu_optab[op1])(op1);
++ if (((M.x86.intr & INTR_SYNCH) &&
++ (M.x86.intno == 0 || M.x86.intno == 2)) ||
++ !ACCESS_FLAG(F_IF)) {
++ x86emu_intr_handle();
++ }
++ }
++ op1 = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++));
++ (*x86emu_optab[op1]) (op1);
+ if (M.x86.debug & DEBUG_EXIT) {
+ M.x86.debug &= ~DEBUG_EXIT;
+ return;
+@@ -132,9 +134,10 @@ DB( if (M.x86.R_SP != 0) {
+ REMARKS:
+ Halts the system by setting the halted system flag.
+ ****************************************************************************/
+-void X86EMU_halt_sys(void)
++void
++X86EMU_halt_sys(void)
+ {
+- M.x86.intr |= INTR_HALTED;
++ M.x86.intr |= INTR_HALTED;
+ }
+
+ /****************************************************************************
+@@ -149,19 +152,17 @@ next instruction.
+
+ NOTE: Do not inline this function, as (*sys_rdb) is already inline!
+ ****************************************************************************/
+-void fetch_decode_modrm(
+- int *mod,
+- int *regh,
+- int *regl)
++void
++fetch_decode_modrm(int *mod, int *regh, int *regl)
+ {
+- int fetched;
+-
+-DB( if (CHECK_IP_FETCH())
+- x86emu_check_ip_access();)
+- fetched = (*sys_rdb)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP++));
+- INC_DECODED_INST_LEN(1);
+- *mod = (fetched >> 6) & 0x03;
+- *regh = (fetched >> 3) & 0x07;
++ int fetched;
++
++ DB(if (CHECK_IP_FETCH())
++ x86emu_check_ip_access();)
++ fetched = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++));
++ INC_DECODED_INST_LEN(1);
++ *mod = (fetched >> 6) & 0x03;
++ *regh = (fetched >> 3) & 0x07;
+ *regl = (fetched >> 0) & 0x07;
+ }
+
+@@ -175,15 +176,16 @@ moves the instruction pointer to the next value.
+
+ NOTE: Do not inline this function, as (*sys_rdb) is already inline!
+ ****************************************************************************/
+-u8 fetch_byte_imm(void)
++u8
++fetch_byte_imm(void)
+ {
+- u8 fetched;
++ u8 fetched;
+
+-DB( if (CHECK_IP_FETCH())
+- x86emu_check_ip_access();)
+- fetched = (*sys_rdb)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP++));
+- INC_DECODED_INST_LEN(1);
+- return fetched;
++ DB(if (CHECK_IP_FETCH())
++ x86emu_check_ip_access();)
++ fetched = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++));
++ INC_DECODED_INST_LEN(1);
++ return fetched;
+ }
+
+ /****************************************************************************
+@@ -196,16 +198,17 @@ moves the instruction pointer to the next value.
+
+ NOTE: Do not inline this function, as (*sys_rdw) is already inline!
+ ****************************************************************************/
+-u16 fetch_word_imm(void)
++u16
++fetch_word_imm(void)
+ {
+- u16 fetched;
+-
+-DB( if (CHECK_IP_FETCH())
+- x86emu_check_ip_access();)
+- fetched = (*sys_rdw)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP));
+- M.x86.R_IP += 2;
+- INC_DECODED_INST_LEN(2);
+- return fetched;
++ u16 fetched;
++
++ DB(if (CHECK_IP_FETCH())
++ x86emu_check_ip_access();)
++ fetched = (*sys_rdw) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP));
++ M.x86.R_IP += 2;
++ INC_DECODED_INST_LEN(2);
++ return fetched;
+ }
+
+ /****************************************************************************
+@@ -218,16 +221,17 @@ moves the instruction pointer to the next value.
+
+ NOTE: Do not inline this function, as (*sys_rdw) is already inline!
+ ****************************************************************************/
+-u32 fetch_long_imm(void)
++u32
++fetch_long_imm(void)
+ {
+- u32 fetched;
+-
+-DB( if (CHECK_IP_FETCH())
+- x86emu_check_ip_access();)
+- fetched = (*sys_rdl)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP));
+- M.x86.R_IP += 4;
+- INC_DECODED_INST_LEN(4);
+- return fetched;
++ u32 fetched;
++
++ DB(if (CHECK_IP_FETCH())
++ x86emu_check_ip_access();)
++ fetched = (*sys_rdl) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP));
++ M.x86.R_IP += 4;
++ INC_DECODED_INST_LEN(4);
++ return fetched;
+ }
+
+ /****************************************************************************
+@@ -259,38 +263,39 @@ cpu-state-varible M.x86.mode. There are several potential states:
+
+ Each of the above 7 items are handled with a bit in the mode field.
+ ****************************************************************************/
+-_INLINE u32 get_data_segment(void)
++_INLINE u32
++get_data_segment(void)
+ {
+ #define GET_SEGMENT(segment)
+- switch (M.x86.mode & SYSMODE_SEGMASK) {
+- case 0: /* default case: use ds register */
+- case SYSMODE_SEGOVR_DS:
+- case SYSMODE_SEGOVR_DS | SYSMODE_SEG_DS_SS:
+- return M.x86.R_DS;
+- case SYSMODE_SEG_DS_SS: /* non-overridden, use ss register */
+- return M.x86.R_SS;
+- case SYSMODE_SEGOVR_CS:
+- case SYSMODE_SEGOVR_CS | SYSMODE_SEG_DS_SS:
+- return M.x86.R_CS;
+- case SYSMODE_SEGOVR_ES:
+- case SYSMODE_SEGOVR_ES | SYSMODE_SEG_DS_SS:
+- return M.x86.R_ES;
+- case SYSMODE_SEGOVR_FS:
+- case SYSMODE_SEGOVR_FS | SYSMODE_SEG_DS_SS:
+- return M.x86.R_FS;
+- case SYSMODE_SEGOVR_GS:
+- case SYSMODE_SEGOVR_GS | SYSMODE_SEG_DS_SS:
+- return M.x86.R_GS;
+- case SYSMODE_SEGOVR_SS:
+- case SYSMODE_SEGOVR_SS | SYSMODE_SEG_DS_SS:
+- return M.x86.R_SS;
+- default:
++ switch (M.x86.mode & SYSMODE_SEGMASK) {
++ case 0: /* default case: use ds register */
++ case SYSMODE_SEGOVR_DS:
++ case SYSMODE_SEGOVR_DS | SYSMODE_SEG_DS_SS:
++ return M.x86.R_DS;
++ case SYSMODE_SEG_DS_SS: /* non-overridden, use ss register */
++ return M.x86.R_SS;
++ case SYSMODE_SEGOVR_CS:
++ case SYSMODE_SEGOVR_CS | SYSMODE_SEG_DS_SS:
++ return M.x86.R_CS;
++ case SYSMODE_SEGOVR_ES:
++ case SYSMODE_SEGOVR_ES | SYSMODE_SEG_DS_SS:
++ return M.x86.R_ES;
++ case SYSMODE_SEGOVR_FS:
++ case SYSMODE_SEGOVR_FS | SYSMODE_SEG_DS_SS:
++ return M.x86.R_FS;
++ case SYSMODE_SEGOVR_GS:
++ case SYSMODE_SEGOVR_GS | SYSMODE_SEG_DS_SS:
++ return M.x86.R_GS;
++ case SYSMODE_SEGOVR_SS:
++ case SYSMODE_SEGOVR_SS | SYSMODE_SEG_DS_SS:
++ return M.x86.R_SS;
++ default:
+ #ifdef DEBUG
+- printk("error: should not happen: multiple overrides.\n");
++ printk("error: should not happen: multiple overrides.\n");
+ #endif
+- HALT_SYS();
+- return 0;
+- }
++ HALT_SYS();
++ return 0;
++ }
+ }
+
+ /****************************************************************************
+@@ -302,14 +307,14 @@ Byte value read from the absolute memory location.
+
+ NOTE: Do not inline this function as (*sys_rdX) is already inline!
+ ****************************************************************************/
+-u8 fetch_data_byte(
+- uint offset)
++u8
++fetch_data_byte(uint offset)
+ {
+ #ifdef DEBUG
+- if (CHECK_DATA_ACCESS())
+- x86emu_check_data_access((u16)get_data_segment(), offset);
++ if (CHECK_DATA_ACCESS())
++ x86emu_check_data_access((u16) get_data_segment(), offset);
+ #endif
+- return (*sys_rdb)((get_data_segment() << 4) + offset);
++ return (*sys_rdb) ((get_data_segment() << 4) + offset);
+ }
+
+ /****************************************************************************
+@@ -321,14 +326,14 @@ Word value read from the absolute memory location.
+
+ NOTE: Do not inline this function as (*sys_rdX) is already inline!
+ ****************************************************************************/
+-u16 fetch_data_word(
+- uint offset)
++u16
++fetch_data_word(uint offset)
+ {
+ #ifdef DEBUG
+- if (CHECK_DATA_ACCESS())