]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
bios_emulator: Add an option to enable debugging
authorSimon Glass <sjg@chromium.org>
Sat, 15 Nov 2014 03:56:42 +0000 (20:56 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 25 Nov 2014 14:11:17 +0000 (07:11 -0700)
At present there are DEBUG options spread around the place. If you enable
one and not another you can end up with an emulator that does not work,
since each file can have a different view of what the registers look like.
To fix this, create a global CONFIG_X86EMU_DEBUG option that keeps
everything consistent.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/bios_emulator/besys.c
drivers/bios_emulator/bios.c
drivers/bios_emulator/biosemui.h
drivers/bios_emulator/include/x86emu.h
drivers/bios_emulator/include/x86emu/debug.h
drivers/bios_emulator/include/x86emu/regs.h
drivers/bios_emulator/x86emu/debug.c
drivers/bios_emulator/x86emu/decode.c
drivers/bios_emulator/x86emu/ops.c

index 8e29a9eafec6f1e7adf2096140da171bfe2eeec0..752a928f6602fb43ec07b93536a9620ef386ac68 100644 (file)
@@ -60,6 +60,14 @@ static u8 BE_model = 0xFC;
 static u8 BE_submodel = 0x00;
 #endif
 
+#undef DEBUG_IO_ACCESS
+
+#ifdef DEBUG_IO_ACCESS
+#define debug_io(fmt, ...)     printf(fmt, ##__VA_ARGS__)
+#else
+#define debug_io(x, b...)
+#endif
+
 /*----------------------------- Implementation ----------------------------*/
 
 /****************************************************************************
@@ -96,15 +104,15 @@ static u8 *BE_memaddr(u32 addr)
 #else
        else if (addr >= 0xFFFF5 && addr < 0xFFFFE) {
                /* Return a faked BIOS date string for non-x86 machines */
-               DB(printf("BE_memaddr - Returning BIOS date\n");)
+               debug_io("BE_memaddr - Returning BIOS date\n");
                return (u8 *)(BE_biosDate + addr - 0xFFFF5);
        } else if (addr == 0xFFFFE) {
                /* Return system model identifier for non-x86 machines */
-               DB(printf("BE_memaddr - Returning model\n");)
+               debug_io("BE_memaddr - Returning model\n");
                return &BE_model;
        } else if (addr == 0xFFFFF) {
                /* Return system submodel identifier for non-x86 machines */
-               DB(printf("BE_memaddr - Returning submodel\n");)
+               debug_io("BE_memaddr - Returning submodel\n");
                return &BE_submodel;
        }
 #endif
@@ -260,6 +268,7 @@ static u8 VGA_inpb (const int port)
 {
        u8 val = 0xff;
 
+       debug_io("vga_inb.%04X -> ", (u16) port);
        switch (port) {
        case 0x3C0:
                /* 3C0 has funky characteristics because it can act as either
@@ -583,7 +592,12 @@ u8 X86API BE_inb(X86EMU_pioAddr port)
                val = LOG_inpb(port);
        } else
 #endif
+       {
+               debug_io("inb.%04X -> ", (u16) port);
                val = LOG_inpb(port);
+               debug_io("%02X\n", val);
+       }
+
        return val;
 }
 
@@ -611,7 +625,12 @@ u16 X86API BE_inw(X86EMU_pioAddr port)
                val = LOG_inpw(port);
        } else
 #endif
+       {
+               debug_io("inw.%04X -> ", (u16) port);
                val = LOG_inpw(port);
+               debug_io("%04X\n", val);
+       }
+
        return val;
 }
 
@@ -638,7 +657,12 @@ u32 X86API BE_inl(X86EMU_pioAddr port)
                val = LOG_inpd(port);
        } else
 #endif
+       {
+               debug_io("inl.%04X -> ", (u16) port);
                val = LOG_inpd(port);
+               debug_io("%08X\n", val);
+       }
+
        return val;
 }
 
@@ -670,7 +694,11 @@ void X86API BE_outb(X86EMU_pioAddr port, u8 val)
                LOG_outpb(port, val);
        } else
 #endif
+       {
+               debug_io("outb.%04X <- %02X", (u16) port, val);
                LOG_outpb(port, val);
+               debug_io("\n");
+       }
 }
 
 /****************************************************************************
@@ -686,18 +714,22 @@ through to the real hardware if we don't need to special case it.
 void X86API BE_outw(X86EMU_pioAddr port, u16 val)
 {
 #if !defined(CONFIG_X86EMU_RAW_IO)
-               if (IS_VGA_PORT(port)) {
-                       VGA_outpb(port, val);
-                       VGA_outpb(port + 1, val >> 8);
-               } else if (IS_PCI_PORT(port))
-                       PCI_outp(port, val, REG_WRITE_WORD);
-               else if (port < 0x100) {
-                       DB(printf("WARN: MAybe INVALID outw.%04X <- %04X\n", (u16) port,
-                              val);)
-                       LOG_outpw(port, val);
-               } else
+       if (IS_VGA_PORT(port)) {
+               VGA_outpb(port, val);
+               VGA_outpb(port + 1, val >> 8);
+       } else if (IS_PCI_PORT(port)) {
+               PCI_outp(port, val, REG_WRITE_WORD);
+       } else if (port < 0x100) {
+               DB(printf("WARN: MAybe INVALID outw.%04X <- %04X\n", (u16)port,
+                         val);)
+               LOG_outpw(port, val);
+       } else
 #endif
-                       LOG_outpw(port, val);
+       {
+               debug_io("outw.%04X <- %04X", (u16) port, val);
+               LOG_outpw(port, val);
+               debug_io("\n");
+       }
 }
 
 /****************************************************************************
@@ -720,5 +752,9 @@ void X86API BE_outl(X86EMU_pioAddr port, u32 val)
                LOG_outpd(port, val);
        } else
 #endif
+       {
+               debug_io("outl.%04X <- %08X", (u16) port, val);
                LOG_outpd(port, val);
+               debug_io("\n");
+       }
 }
index bcc192fb2e3f1c7201c96d970b0daa00bd39fb21..152d70a778c452a697a6ebb83ff9c8d35b746a7e 100644 (file)
@@ -84,14 +84,14 @@ static void X86API int42(int intno)
                        PM_outpb(0x3c2, PM_inpb(0x3cc) & (u8) ~ 0x02);
                        return;
                }
-#ifdef  DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
                else {
                        printf("int42: unknown function AH=0x12, BL=0x32, AL=%#02x\n",
                             M.x86.R_AL);
                }
 #endif
        }
-#ifdef  DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
        else {
                printf("int42: unknown function AH=%#02x, AL=%#02x, BL=%#02x\n",
                     M.x86.R_AH, M.x86.R_AL, M.x86.R_BL);
index 8c1f111fc83cd809b0dc6da3f9dcb10be7d60164..7853015c1e2ef83b57b207299cdc603312e15ece 100644 (file)
@@ -48,7 +48,7 @@
 #include <asm/io.h>
 /*---------------------- Macros and type definitions ----------------------*/
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 #define DB(x)  x
 #else
 #define DB(x)  do{}while(0);
index 63febe0e2913d3b094a0b526fb21114e15924fff..b28cdc6b8cadcffd319ed5929313b5132419b978 100644 (file)
@@ -161,7 +161,7 @@ extern "C" {                        /* Use "C" linkage when in C++ mode */
        void X86EMU_exec(void);
        void X86EMU_halt_sys(void);
 
-#ifdef  DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 #define HALT_SYS()  \
     printf("halt_sys: file %s, line %d\n", __FILE__, __LINE__), \
     X86EMU_halt_sys()
index 268c9d391e239a1ebdc4a61d369fa287d9722d96..12d6c7ffd7f8275c58c16e212e41770a4cb27fb1 100644 (file)
@@ -48,7 +48,7 @@
 #define CHECK_MEM_ACCESS_F             0x4     /*using regular linear pointer */
 #define CHECK_DATA_ACCESS_F            0x8     /*using segment:offset */
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 # define CHECK_IP_FETCH()              (M.x86.check & CHECK_IP_FETCH_F)
 # define CHECK_SP_ACCESS()             (M.x86.check & CHECK_SP_ACCESS_F)
 # define CHECK_MEM_ACCESS()            (M.x86.check & CHECK_MEM_ACCESS_F)
@@ -60,7 +60,7 @@
 # define CHECK_DATA_ACCESS()
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 # define DEBUG_INSTRUMENT()    (M.x86.debug & DEBUG_INSTRUMENT_F)
 # define DEBUG_DECODE()                (M.x86.debug & DEBUG_DECODE_F)
 # define DEBUG_TRACE()         (M.x86.debug & DEBUG_TRACE_F)
@@ -99,7 +99,7 @@
 # define DEBUG_DECODE_NOPRINT() 0
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 
 # define DECODE_PRINTF(x)      if (DEBUG_DECODE()) \
                                    x86emu_decode_printf(x)
 # define SAVE_IP_CS(x,y)
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 #define TRACE_REGS()                                       \
     if (DEBUG_DISASSEMBLE()) {                             \
        x86emu_just_disassemble();                          \
 # define TRACE_REGS()
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 # define SINGLE_STEP()     if (DEBUG_STEP()) x86emu_single_step()
 #else
 # define SINGLE_STEP()
     TRACE_REGS();          \
     SINGLE_STEP()
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 # define START_OF_INSTR()
 # define END_OF_INSTR()            EndOfTheInstructionProcedure: x86emu_end_instr();
 # define END_OF_INSTR_NO_TRACE()    x86emu_end_instr();
 # define END_OF_INSTR_NO_TRACE()
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 # define  CALL_TRACE(u,v,w,x,s)                                        \
     if (DEBUG_TRACECALLREGS())                                 \
        x86emu_dump_regs();                                     \
 # define RETURN_TRACE(n,u,v)
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 #define DB(x)  x
 #else
 #define DB(x)
index a7fedd2f6ca1caa7d56de1cf54bec54300bdb872..29341297d96608e0a50fed2f00de9ce89a458a31 100644 (file)
@@ -282,7 +282,7 @@ typedef struct {
        u8 intno;
        volatile int intr;      /* mask of pending interrupts */
        int debug;
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
        int check;
        u16 saved_ip;
        u16 saved_cs;
index 2ec64c24ce794b4992c2435675bd47b23c9f8336..27e90e441aa44c710226695bbac7f4e9c9c4f9c1 100644 (file)
@@ -44,7 +44,7 @@
 
 /*----------------------------- Implementation ----------------------------*/
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 
 static void print_encoded_bytes(u16 s, u16 o);
 static void print_decoded_instruction(void);
index a782b817b707fe95c46dfac1d4e874c16db912b9..da44c3d8d9f53798d6554e302df4535852e31d97 100644 (file)
@@ -303,7 +303,7 @@ NOTE: Do not inline this function as (*sys_rdX) is already inline!
 u8 fetch_data_byte(
     uint offset)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access((u16)get_data_segment(), offset);
 #endif
@@ -322,7 +322,7 @@ NOTE: Do not inline this function as (*sys_rdX) is already inline!
 u16 fetch_data_word(
     uint offset)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access((u16)get_data_segment(), offset);
 #endif
@@ -341,7 +341,7 @@ NOTE: Do not inline this function as (*sys_rdX) is already inline!
 u32 fetch_data_long(
     uint offset)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access((u16)get_data_segment(), offset);
 #endif
@@ -362,7 +362,7 @@ u8 fetch_data_byte_abs(
     uint segment,
     uint offset)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access(segment, offset);
 #endif
@@ -383,7 +383,7 @@ u16 fetch_data_word_abs(
     uint segment,
     uint offset)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access(segment, offset);
 #endif
@@ -404,7 +404,7 @@ u32 fetch_data_long_abs(
     uint segment,
     uint offset)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access(segment, offset);
 #endif
@@ -426,7 +426,7 @@ void store_data_byte(
     uint offset,
     u8 val)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access((u16)get_data_segment(), offset);
 #endif
@@ -448,7 +448,7 @@ void store_data_word(
     uint offset,
     u16 val)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access((u16)get_data_segment(), offset);
 #endif
@@ -470,7 +470,7 @@ void store_data_long(
     uint offset,
     u32 val)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access((u16)get_data_segment(), offset);
 #endif
@@ -493,7 +493,7 @@ void store_data_byte_abs(
     uint offset,
     u8 val)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access(segment, offset);
 #endif
@@ -516,7 +516,7 @@ void store_data_word_abs(
     uint offset,
     u16 val)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access(segment, offset);
 #endif
@@ -539,7 +539,7 @@ void store_data_long_abs(
     uint offset,
     u32 val)
 {
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (CHECK_DATA_ACCESS())
        x86emu_check_data_access(segment, offset);
 #endif
index f8e093d751ae59adbeed9329b09cf9dc8ee1e2f5..c853260198e5cd2e24f5a511c5469d23f6ed4f90 100644 (file)
@@ -79,7 +79,7 @@
 
 /* constant arrays to do several instructions in just one function */
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 static char *x86emu_GenOpName[8] = {
     "ADD", "OR", "ADC", "SBB", "AND", "SUB", "XOR", "CMP"};
 #endif
@@ -160,7 +160,7 @@ static u32 (*opcD1_long_operation[])(u32 s, u8 d) =
     sar_long,
 };
 
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
 
 static char *opF6_names[8] =
   { "TEST\t", "", "NOT\t", "NEG\t", "MUL\t", "IMUL\t", "DIV\t", "IDIV\t" };
@@ -1281,7 +1281,7 @@ void x86emuOp_opc80_byte_RM_IMM(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -1359,7 +1359,7 @@ void x86emuOp_opc81_word_RM_IMM(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -1475,7 +1475,7 @@ void x86emuOp_opc82_byte_RM_IMM(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -1551,7 +1551,7 @@ void x86emuOp_opc83_word_RM_IMM(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -3083,7 +3083,7 @@ void x86emuOp_opcC0_byte_RM_MEM(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -3158,7 +3158,7 @@ void x86emuOp_opcC1_word_RM_MEM(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -3630,7 +3630,7 @@ void x86emuOp_opcD0_byte_RM_1(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -3701,7 +3701,7 @@ void x86emuOp_opcD1_word_RM_1(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -3803,7 +3803,7 @@ void x86emuOp_opcD2_byte_RM_CL(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -3876,7 +3876,7 @@ void x86emuOp_opcD3_word_RM_CL(u8 X86EMU_UNUSED(op1))
      */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -4859,7 +4859,7 @@ void x86emuOp_opcFE_byte_RM(u8 X86EMU_UNUSED(op1))
     /* Yet another special case instruction. */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings
@@ -4923,7 +4923,7 @@ void x86emuOp_opcFF_word_RM(u8 X86EMU_UNUSED(op1))
     /* Yet another special case instruction. */
     START_OF_INSTR();
     FETCH_DECODE_MODRM(mod, rh, rl);
-#ifdef DEBUG
+#ifdef CONFIG_X86EMU_DEBUG
     if (DEBUG_DECODE()) {
        /* XXX DECODE_PRINTF may be changed to something more
           general, so that it is important to leave the strings