From cdcd7522aabe1320294edd43b7841b3648570d85 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Fri, 15 Feb 2008 19:03:54 +0000 Subject: [PATCH] Added RIP to the GPR register file as lst register This allowed to optimize (read - remove) two more BxResolve methods in 64-bit mode + Some white space cleanup --- bochs/bx_debug/dbg_main.cc | 49 ++++++------- bochs/config.cc | 14 ++-- bochs/cpu/apic.cc | 7 +- bochs/cpu/bcd.cc | 6 +- bochs/cpu/bit16.cc | 6 +- bochs/cpu/bit32.cc | 6 +- bochs/cpu/bit64.cc | 6 +- bochs/cpu/call_far.cc | 8 +-- bochs/cpu/cpu.h | 137 +++++++++++-------------------------- bochs/cpu/debugstuff.cc | 5 +- bochs/cpu/extdb.cc | 22 +++--- bochs/cpu/fetchdecode64.cc | 10 +-- bochs/cpu/instr.h | 19 ++--- bochs/cpu/iret.cc | 12 ++-- bochs/cpu/jmp_far.cc | 4 +- bochs/cpu/paging.cc | 14 ++-- bochs/cpu/proc_ctrl.cc | 18 ++--- bochs/cpu/resolve64.cc | 13 +--- bochs/cpu/soft_int.cc | 4 +- bochs/cpu/tasking.cc | 8 +-- bochs/cpu/vm8086.cc | 8 +-- bochs/gdbstub.cc | 11 ++- bochs/iodev/iodebug.cc | 28 +++++--- bochs/load32bitOShack.cc | 54 +++++++-------- bochs/logio.cc | 6 +- bochs/main.cc | 50 +++++++------- bochs/plex86-interface.cc | 28 ++++---- 27 files changed, 248 insertions(+), 305 deletions(-) diff --git a/bochs/bx_debug/dbg_main.cc b/bochs/bx_debug/dbg_main.cc index 2da57cc68..bb82c5e26 100644 --- a/bochs/bx_debug/dbg_main.cc +++ b/bochs/bx_debug/dbg_main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dbg_main.cc,v 1.111 2008-02-05 22:33:33 sshwarts Exp $ +// $Id: dbg_main.cc,v 1.112 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -483,7 +483,7 @@ void bx_dbg_interrupt(unsigned cpu, Bit8u vector, Bit16u error_code) void bx_dbg_exit(int code) { - BX_DEBUG(("dbg: before exit" )); + BX_DEBUG(("dbg: before exit")); for (int cpu=0; cpu < BX_SMP_PROCESSORS; cpu++) { if (BX_CPU(cpu)) BX_CPU(cpu)->atexit(); } @@ -995,7 +995,7 @@ void bx_dbg_where_command() return; } Bit32u bp = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EBP); - Bit32u ip = BX_CPU(dbg_cpu)->get_ip(); + Bit32u ip = BX_CPU(dbg_cpu)->get_instruction_pointer(); dbg_printf("(%d) 0x%08x\n", 0, ip); for (int i = 1; i < 50; i++) { // Up @@ -2361,31 +2361,31 @@ void bx_dbg_set_symbol_command(char *symbol, Bit32u val) bx_bool is_OK = false; symbol++; // get past '$' - if ( !strcmp(symbol, "eip") ) { + if (!strcmp(symbol, "eip")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_EIP, val); } - else if ( !strcmp(symbol, "eflags") ) { + else if (!strcmp(symbol, "eflags")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_EFLAGS, val); } - else if ( !strcmp(symbol, "cs") ) { + else if (!strcmp(symbol, "cs")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_CS, val); } - else if ( !strcmp(symbol, "ss") ) { + else if (!strcmp(symbol, "ss")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_SS, val); } - else if ( !strcmp(symbol, "ds") ) { + else if (!strcmp(symbol, "ds")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_DS, val); } - else if ( !strcmp(symbol, "es") ) { + else if (!strcmp(symbol, "es")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_ES, val); } - else if ( !strcmp(symbol, "fs") ) { + else if (!strcmp(symbol, "fs")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_FS, val); } - else if ( !strcmp(symbol, "gs") ) { + else if (!strcmp(symbol, "gs")) { is_OK = BX_CPU(dbg_cpu)->dbg_set_reg(BX_DBG_REG_GS, val); } - else if ( !strcmp(symbol, "cpu") ) { + else if (!strcmp(symbol, "cpu")) { if (val >= BX_SMP_PROCESSORS) { dbg_printf("invalid cpu id number %d\n", val); return; @@ -2396,15 +2396,15 @@ void bx_dbg_set_symbol_command(char *symbol, Bit32u val) dbg_cpu = val; return; } - else if ( !strcmp(symbol, "synchronous_dma") ) { + else if (!strcmp(symbol, "synchronous_dma")) { bx_guard.async.dma = !val; return; } - else if ( !strcmp(symbol, "synchronous_irq") ) { + else if (!strcmp(symbol, "synchronous_irq")) { bx_guard.async.irq = !val; return; } - else if ( !strcmp(symbol, "event_reports") ) { + else if (!strcmp(symbol, "event_reports")) { bx_guard.report.irq = val; bx_guard.report.a20 = val; bx_guard.report.io = val; @@ -2412,7 +2412,7 @@ void bx_dbg_set_symbol_command(char *symbol, Bit32u val) bx_guard.report.dma = val; return; } - else if ( !strcmp(symbol, "auto_disassemble") ) { + else if (!strcmp(symbol, "auto_disassemble")) { bx_dbg_set_auto_disassemble(val != 0); return; } @@ -2464,7 +2464,8 @@ void bx_dbg_restore_command(const char *param_name, const char *restore_path) void bx_dbg_disassemble_current(const char *format) { - Bit64u addr = bx_dbg_get_laddr(bx_dbg_get_selector_value(BX_DBG_SREG_CS), BX_CPU(dbg_cpu)->get_ip()); + Bit64u addr = bx_dbg_get_laddr(bx_dbg_get_selector_value(BX_DBG_SREG_CS), + BX_CPU(dbg_cpu)->get_instruction_pointer()); bx_dbg_disassemble_command(format, addr, addr); } @@ -2520,16 +2521,16 @@ void bx_dbg_disassemble_command(const char *format, Bit64u from, Bit64u to) void bx_dbg_instrument_command(const char *comm) { #if BX_INSTRUMENTATION - if ( !strcmp(comm, "start") ) { + if (!strcmp(comm, "start")) { BX_INSTR_START(); } - else if ( !strcmp(comm, "stop") ) { + else if (!strcmp(comm, "stop")) { BX_INSTR_STOP(); } - else if ( !strcmp(comm, "reset") ) { + else if (!strcmp(comm, "reset")) { BX_INSTR_RESET(dbg_cpu); } - else if ( !strcmp(comm, "print") ) { + else if (!strcmp(comm, "print")) { BX_INSTR_PRINT(); } else { @@ -3279,17 +3280,17 @@ Bit16u bx_dbg_get_selector_value(unsigned int seg_no) Bit16u bx_dbg_get_ip(void) { - return (BX_CPU(dbg_cpu)->get_ip() & 0xffff); + return BX_CPU(dbg_cpu)->get_ip(); } Bit32u bx_dbg_get_eip(void) { - return (BX_CPU(dbg_cpu)->get_ip() & 0xffffffff); + return BX_CPU(dbg_cpu)->get_eip(); } bx_address bx_dbg_get_instruction_pointer(void) { - return BX_CPU(dbg_cpu)->get_ip(); + return BX_CPU(dbg_cpu)->get_instruction_pointer(); } Bit32u bx_dbg_get_laddr(Bit16u sel, Bit32u ofs) diff --git a/bochs/config.cc b/bochs/config.cc index 9766e941f..769b008d9 100755 --- a/bochs/config.cc +++ b/bochs/config.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: config.cc,v 1.130 2008-02-05 22:57:39 sshwarts Exp $ +// $Id: config.cc,v 1.131 2008-02-15 19:03:52 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -1774,7 +1774,7 @@ static const char *get_builtin_variable(const char *varname) data[0] = 0; size = MAX_PATH; if (RegQueryValueEx(hkey, "", NULL, (LPDWORD)&type, (LPBYTE)data, - (LPDWORD)&size ) == ERROR_SUCCESS ) { + (LPDWORD)&size ) == ERROR_SUCCESS) { RegCloseKey(hkey); return data; } else { @@ -1882,7 +1882,7 @@ static Bit32s parse_line_unformatted(const char *context, char *line) Bit32s retval = parse_line_formatted(context, num_params, ¶ms[0]); for (i=0; i < MAX_PARAMS_LEN; i++) { - if ( params[i] != NULL ) + if (params[i] != NULL) { free(params[i]); params[i] = NULL; @@ -2259,7 +2259,7 @@ static Bit32s parse_line_formatted(const char *context, int num_params, char *pa if (SIM->get_param_bool("present", base)->get() == 1) { if (SIM->get_param_enum("type", base)->get() == BX_ATA_DEVICE_DISK) { if ((SIM->get_param_num("cylinders", base)->get() == 0) && - (SIM->get_param_num("heads", base)->get() ==0 ) && + (SIM->get_param_num("heads", base)->get() == 0) && (SIM->get_param_num("spt", base)->get() == 0)) { PARSE_WARN(("%s: ataX-master/slave CHS set to 0/0/0 - autodetection enabled", context)); // using heads = 16 and spt = 63 for autodetection (bximage defaults) @@ -2723,13 +2723,13 @@ static Bit32s parse_line_formatted(const char *context, int num_params, char *pa } for (i=1; iname, vector*0x100, cpu->eip_reg.dword.eip)); + BX_INFO(("%s started up at %04X:%08X by APIC", + cpu->name, vector*0x100, cpu->gen_reg[BX_32BIT_REG_EIP].dword.erx)); } else { BX_INFO(("%s started up by APIC, but was not halted at the time", cpu->name)); } diff --git a/bochs/cpu/bcd.cc b/bochs/cpu/bcd.cc index 2d6e2c601..4440d0cd5 100644 --- a/bochs/cpu/bcd.cc +++ b/bochs/cpu/bcd.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: bcd.cc,v 1.22 2008-02-02 21:46:49 sshwarts Exp $ +// $Id: bcd.cc,v 1.23 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -54,7 +54,7 @@ void BX_CPU_C::AAA(bxInstruction_c *) /* AAA affects the following flags: A,C */ - if ( ((AL & 0x0f) > 9) || get_AF() ) + if (((AL & 0x0f) > 9) || get_AF()) { AX = AX + 0x106; assert_AF(); @@ -82,7 +82,7 @@ void BX_CPU_C::AAS(bxInstruction_c *) { /* AAS affects the following flags: A,C */ - if ( ((AL & 0x0F) > 0x09) || get_AF() ) + if (((AL & 0x0F) > 0x09) || get_AF()) { AX = AX - 0x106; assert_AF(); diff --git a/bochs/cpu/bit16.cc b/bochs/cpu/bit16.cc index 32fec62d1..096e909ef 100755 --- a/bochs/cpu/bit16.cc +++ b/bochs/cpu/bit16.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: bit16.cc,v 1.6 2008-01-29 17:13:05 sshwarts Exp $ +// $Id: bit16.cc,v 1.7 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -53,7 +53,7 @@ void BX_CPU_C::BSF_GwEw(bxInstruction_c *i) } op1_16 = 0; - while ( (op2_16 & 0x01) == 0 ) { + while ((op2_16 & 0x01) == 0) { op1_16++; op2_16 >>= 1; } @@ -86,7 +86,7 @@ void BX_CPU_C::BSR_GwEw(bxInstruction_c *i) } op1_16 = 15; - while ( (op2_16 & 0x8000) == 0 ) { + while ((op2_16 & 0x8000) == 0) { op1_16--; op2_16 <<= 1; } diff --git a/bochs/cpu/bit32.cc b/bochs/cpu/bit32.cc index 317f0bebe..831f45fbf 100755 --- a/bochs/cpu/bit32.cc +++ b/bochs/cpu/bit32.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: bit32.cc,v 1.5 2008-01-29 17:13:05 sshwarts Exp $ +// $Id: bit32.cc,v 1.6 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -53,7 +53,7 @@ void BX_CPU_C::BSF_GdEd(bxInstruction_c *i) } op1_32 = 0; - while ( (op2_32 & 0x01) == 0 ) { + while ((op2_32 & 0x01) == 0) { op1_32++; op2_32 >>= 1; } @@ -86,7 +86,7 @@ void BX_CPU_C::BSR_GdEd(bxInstruction_c *i) } op1_32 = 31; - while ( (op2_32 & 0x80000000) == 0 ) { + while ((op2_32 & 0x80000000) == 0) { op1_32--; op2_32 <<= 1; } diff --git a/bochs/cpu/bit64.cc b/bochs/cpu/bit64.cc index d4ebdf8a6..f80e0b880 100755 --- a/bochs/cpu/bit64.cc +++ b/bochs/cpu/bit64.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: bit64.cc,v 1.8 2008-02-02 21:46:49 sshwarts Exp $ +// $Id: bit64.cc,v 1.9 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -53,7 +53,7 @@ void BX_CPU_C::BSF_GqEq(bxInstruction_c *i) } op1_64 = 0; - while ( (op2_64 & 0x01) == 0 ) { + while ((op2_64 & 0x01) == 0) { op1_64++; op2_64 >>= 1; } @@ -86,7 +86,7 @@ void BX_CPU_C::BSR_GqEq(bxInstruction_c *i) } op1_64 = 63; - while ( (op2_64 & BX_CONST64(0x8000000000000000)) == 0 ) { + while ((op2_64 & BX_CONST64(0x8000000000000000)) == 0) { op1_64--; op2_64 <<= 1; } diff --git a/bochs/cpu/call_far.cc b/bochs/cpu/call_far.cc index cccc891e5..598230e25 100755 --- a/bochs/cpu/call_far.cc +++ b/bochs/cpu/call_far.cc @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////// -// $Id: call_far.cc,v 1.26 2008-02-02 21:46:49 sshwarts Exp $ +// $Id: call_far.cc,v 1.27 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (c) 2005 Stanislav Shwartsman @@ -207,7 +207,7 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp) new_EIP = gate_descriptor.u.gate.dest_offset; // selector must not be null else #GP(0) - if ( (dest_selector & 0xfffc) == 0 ) { + if ((dest_selector & 0xfffc) == 0) { BX_ERROR(("call_protected: selector in gate null")); exception(BX_GP_EXCEPTION, 0, 0); } @@ -258,7 +258,7 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp) // check selector & descriptor for new SS: // selector must not be null, else #TS(0) - if ( (SS_for_cpl_x & 0xfffc) == 0 ) { + if ((SS_for_cpl_x & 0xfffc) == 0) { BX_ERROR(("call_protected: new SS null")); exception(BX_TS_EXCEPTION, 0, 0); } @@ -457,7 +457,7 @@ BX_CPU_C::call_gate64(bx_selector_t *gate_selector) Bit16u dest_selector = gate_descriptor.u.gate.dest_selector; // selector must not be null else #GP(0) - if ( (dest_selector & 0xfffc) == 0 ) { + if ((dest_selector & 0xfffc) == 0) { BX_ERROR(("call_gate64: selector in gate null")); exception(BX_GP_EXCEPTION, 0, 0); } diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index 8a8f3cdc8..55a8a194a 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.h,v 1.426 2008-02-14 18:59:40 sshwarts Exp $ +// $Id: cpu.h,v 1.427 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -83,6 +83,16 @@ #define BX_64BIT_REG_R14 14 #define BX_64BIT_REG_R15 15 +#if BX_SUPPORT_X86_64 +# define BX_GENERAL_REGISTERS 16 +#else +# define BX_GENERAL_REGISTERS 8 +#endif + +#define BX_16BIT_REG_IP BX_GENERAL_REGISTERS +#define BX_32BIT_REG_EIP BX_GENERAL_REGISTERS +#define BX_64BIT_REG_RIP BX_GENERAL_REGISTERS + #if defined(NEED_CPU_REG_SHORTCUTS) /* WARNING: @@ -113,7 +123,7 @@ #define DI (BX_CPU_THIS_PTR gen_reg[7].word.rx) // access to 16 bit instruction pointer -#define IP BX_CPU_THIS_PTR eip_reg.word.ip +#define IP (BX_CPU_THIS_PTR gen_reg[BX_16BIT_REG_IP].word.rx) // accesss to 32 bit general registers #define EAX BX_CPU_THIS_PTR gen_reg[0].dword.erx @@ -126,7 +136,7 @@ #define EDI BX_CPU_THIS_PTR gen_reg[7].dword.erx // access to 32 bit instruction pointer -#define EIP BX_CPU_THIS_PTR eip_reg.dword.eip +#define EIP BX_CPU_THIS_PTR gen_reg[BX_32BIT_REG_EIP].dword.erx #if BX_SUPPORT_X86_64 // accesss to 64 bit general registers @@ -148,7 +158,7 @@ #define R15 BX_CPU_THIS_PTR gen_reg[15].rrx // access to 64 bit instruction pointer -#define RIP BX_CPU_THIS_PTR eip_reg.rip +#define RIP BX_CPU_THIS_PTR gen_reg[BX_64BIT_REG_RIP].rrx // access to 64 bit MSR registers #define MSR_FSBASE (BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.u.segment.base) @@ -672,71 +682,6 @@ typedef struct { #endif // #if BX_SUPPORT_X86_64 -// instruction pointer register -#if BX_SUPPORT_X86_64 - -#ifdef BX_BIG_ENDIAN -typedef struct { - union { - struct { - Bit32u rip_upper; - Bit16u word_filler; - Bit16u ip; - } word; - Bit64u rip; - struct { - Bit32u rip_upper; // hi 32 bits - Bit32u eip; // lo 32 bits - } dword; - }; -} bx_eip_reg_t; -#else -typedef struct { - union { - struct { - Bit16u ip; - Bit16u word_filler; - Bit32u rip_upper; - } word; - Bit64u rip; - struct { - Bit32u eip; // lo 32 bits - Bit32u rip_upper; // hi 32 bits - } dword; - }; -} bx_eip_reg_t; -#endif - -#else // #if BX_SUPPORT_X86_64 - -#ifdef BX_BIG_ENDIAN -typedef struct { - union { - struct { - Bit32u eip; - } dword; - struct { - Bit16u word_filler; - Bit16u ip; - } word; - }; -} bx_eip_reg_t; -#else -typedef struct { - union { - struct { - Bit32u eip; - } dword; - struct { - Bit16u ip; - Bit16u word_filler; - } word; - }; -} bx_eip_reg_t; -#endif - -#endif // #if BX_SUPPORT_X86_64 - #if BX_SUPPORT_APIC #define BX_INCLUDE_LOCAL_APIC 1 #include "apic.h" @@ -744,12 +689,6 @@ typedef struct { class BX_MEM_C; -#if BX_SUPPORT_X86_64 -# define BX_GENERAL_REGISTERS 16 -#else -# define BX_GENERAL_REGISTERS 8 -#endif - #if BX_SUPPORT_FPU #include "cpu/i387.h" #include "cpu/xmm.h" @@ -789,11 +728,9 @@ public: // for now... // esi: source index // edi: destination index // esp: stack pointer + // eip: instruction pointer bx_gen_reg_t gen_reg[BX_GENERAL_REGISTERS+1]; - // instruction pointer - bx_eip_reg_t eip_reg; - /* 31|30|29|28| 27|26|25|24| 23|22|21|20| 19|18|17|16 * ==|==|=====| ==|==|==|==| ==|==|==|==| ==|==|==|== * 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|ID|VP| VF|AC|VM|RF @@ -2841,8 +2778,6 @@ public: // for now... BX_SMF void BxResolve32DispIndex(bxInstruction_c *) BX_CPP_AttrRegparmN(1); #if BX_SUPPORT_X86_64 - BX_SMF void BxResolve32Rip(bxInstruction_c *) BX_CPP_AttrRegparmN(1); - BX_SMF void BxResolve64Rip(bxInstruction_c *) BX_CPP_AttrRegparmN(1); BX_SMF void BxResolve64Disp(bxInstruction_c *) BX_CPP_AttrRegparmN(1); BX_SMF void BxResolve64Base(bxInstruction_c *) BX_CPP_AttrRegparmN(1); BX_SMF void BxResolve64BaseIndex(bxInstruction_c *) BX_CPP_AttrRegparmN(1); @@ -3140,14 +3075,19 @@ public: // for now... BX_CPP_INLINE Bit8u get_CPL(void) { return (BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.rpl); } + BX_CPP_INLINE bx_address get_instruction_pointer(void); + + BX_CPP_INLINE Bit32u get_eip(void); + BX_CPP_INLINE Bit16u get_ip(void); +#if BX_SUPPORT_X86_64 + BX_CPP_INLINE Bit64u get_rip(void); +#endif + BX_CPP_INLINE Bit8u get_reg8l(unsigned reg); BX_CPP_INLINE Bit8u get_reg8h(unsigned reg); BX_CPP_INLINE void set_reg8l(unsigned reg, Bit8u val); BX_CPP_INLINE void set_reg8h(unsigned reg, Bit8u val); - BX_CPP_INLINE bx_address get_ip(void); - BX_CPP_INLINE void set_ip(bx_address ip); - BX_CPP_INLINE Bit16u get_reg16(unsigned reg); BX_CPP_INLINE void set_reg16(unsigned reg, Bit16u val); BX_CPP_INLINE Bit32u get_reg32(unsigned reg); @@ -3267,8 +3207,6 @@ BX_CPP_INLINE Bit32u BX_CPU_C::read_eflags(void) return BX_CPU_THIS_PTR force_flags(); } -#include - BX_CPP_INLINE Bit8u BX_CPU_C::get_reg8l(unsigned reg) { assert(reg < BX_GENERAL_REGISTERS); @@ -3294,24 +3232,31 @@ BX_CPP_INLINE void BX_CPU_C::set_reg8h(unsigned reg, Bit8u val) } #if BX_SUPPORT_X86_64 -BX_CPP_INLINE bx_address BX_CPU_C::get_ip(void) +BX_CPP_INLINE bx_address BX_CPU_C::get_instruction_pointer(void) { - return (BX_CPU_THIS_PTR eip_reg.rip); -} - -BX_CPP_INLINE void BX_CPU_C::set_ip(bx_address ip) -{ - BX_CPU_THIS_PTR eip_reg.rip = ip; + return BX_CPU_THIS_PTR get_rip(); } #else -BX_CPP_INLINE bx_address BX_CPU_C::get_ip(void) +BX_CPP_INLINE bx_address BX_CPU_C::get_instruction_pointer(void) { - return (BX_CPU_THIS_PTR eip_reg.dword.eip); + return BX_CPU_THIS_PTR get_eip(); +} +#endif + +BX_CPP_INLINE Bit16u BX_CPU_C::get_ip(void) +{ + return (BX_CPU_THIS_PTR gen_reg[BX_16BIT_REG_IP].word.rx); } -BX_CPP_INLINE void BX_CPU_C::set_ip(bx_address ip) +BX_CPP_INLINE Bit32u BX_CPU_C::get_eip(void) { - BX_CPU_THIS_PTR eip_reg.dword.eip = ip; + return (BX_CPU_THIS_PTR gen_reg[BX_32BIT_REG_EIP].dword.erx); +} + +#if BX_SUPPORT_X86_64 +BX_CPP_INLINE Bit64u BX_CPU_C::get_rip(void) +{ + return (BX_CPU_THIS_PTR gen_reg[BX_64BIT_REG_RIP].rrx); } #endif diff --git a/bochs/cpu/debugstuff.cc b/bochs/cpu/debugstuff.cc index a62c9699d..663fbe55c 100644 --- a/bochs/cpu/debugstuff.cc +++ b/bochs/cpu/debugstuff.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: debugstuff.cc,v 1.92 2008-02-02 21:46:50 sshwarts Exp $ +// $Id: debugstuff.cc,v 1.93 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -240,7 +240,8 @@ void BX_CPU_C::debug(bx_address offset) #if BX_SUPPORT_X86_64 BX_INFO(("| RIP=%08x%08x (%08x%08x)", - (unsigned) BX_CPU_THIS_PTR eip_reg.dword.rip_upper, (unsigned) EIP, + (unsigned) (BX_CPU_THIS_PTR gen_reg[BX_64BIT_REG_RIP].dword.hrx), + (unsigned) (EIP), (unsigned) (BX_CPU_THIS_PTR prev_rip >> 32), (unsigned) (BX_CPU_THIS_PTR prev_rip & 0xffffffff))); BX_INFO(("| CR0=0x%08x CR1=0x%x CR2=0x%08x%08x", diff --git a/bochs/cpu/extdb.cc b/bochs/cpu/extdb.cc index 23bcb603b..5b9079293 100644 --- a/bochs/cpu/extdb.cc +++ b/bochs/cpu/extdb.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: extdb.cc,v 1.24 2008-01-29 17:13:06 sshwarts Exp $ +// $Id: extdb.cc,v 1.25 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// #include "bochs.h" @@ -30,8 +30,8 @@ void bx_external_debugger(BX_CPU_C *cpu) regs.debug_state = debug_step; break; case debug_skip: - if (cpu->eip_reg.dword.eip != regs.debug_eip || - cpu->sregs[1].selector.value != regs.debug_cs) return; + if (cpu->get_instruction_pointer() != regs.debug_eip || + cpu->sregs[BX_SEG_REG_CS].selector.value != regs.debug_cs) return; regs.debug_state = debug_step; break; } @@ -53,7 +53,7 @@ void bx_external_debugger(BX_CPU_C *cpu) regs.r13 = cpu->gen_reg[13].rrx; regs.r14 = cpu->gen_reg[14].rrx; regs.r15 = cpu->gen_reg[15].rrx; - regs.rip = cpu->rip; + regs.rip = cpu->get_instruction_pointer(); #else regs.rax = cpu->gen_reg[0].dword.erx; regs.rcx = cpu->gen_reg[1].dword.erx; @@ -71,15 +71,15 @@ void bx_external_debugger(BX_CPU_C *cpu) regs.r13 = 0; regs.r14 = 0; regs.r15 = 0; - regs.rip = cpu->eip_reg.dword.eip; + regs.rip = cpu->get_instruction_pointer(); #endif regs.rflags = cpu->read_eflags(); - regs.es = cpu->sregs[0].selector.value; - regs.cs = cpu->sregs[1].selector.value; - regs.ss = cpu->sregs[2].selector.value; - regs.ds = cpu->sregs[3].selector.value; - regs.fs = cpu->sregs[4].selector.value; - regs.gs = cpu->sregs[5].selector.value; + regs.es = cpu->sregs[BX_SEG_REG_ES].selector.value; + regs.cs = cpu->sregs[BX_SEG_REG_CS].selector.value; + regs.ss = cpu->sregs[BX_SEG_REG_SS].selector.value; + regs.ds = cpu->sregs[BX_SEG_REG_DS].selector.value; + regs.fs = cpu->sregs[BX_SEG_REG_FS].selector.value; + regs.gs = cpu->sregs[BX_SEG_REG_GS].selector.value; regs.gdt.base = cpu->gdtr.base; regs.gdt.limit = cpu->gdtr.limit; regs.idt.base = cpu->idtr.base; diff --git a/bochs/cpu/fetchdecode64.cc b/bochs/cpu/fetchdecode64.cc index 5cb0421f9..0e02ad2ed 100644 --- a/bochs/cpu/fetchdecode64.cc +++ b/bochs/cpu/fetchdecode64.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: fetchdecode64.cc,v 1.173 2008-02-15 12:23:49 sshwarts Exp $ +// $Id: fetchdecode64.cc,v 1.174 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -3553,7 +3553,7 @@ fetch_b1: if (BX_NULL_SEG_REG(i->seg())) i->setSeg(BX_SEG_REG_DS); if ((rm & 0x7) == 5) { - i->ResolveModrm = &BX_CPU_C::BxResolve64Rip; + i->setSibBase(BX_64BIT_REG_RIP); get_32bit_displ: if ((ilen+3) < remain) { i->modRMForm.displ32u = FetchDWORD(iptr); @@ -3629,7 +3629,7 @@ get_8bit_displ: if (BX_NULL_SEG_REG(i->seg())) i->setSeg(BX_SEG_REG_DS); if ((rm & 0x7) == 5) { - i->ResolveModrm = &BX_CPU_C::BxResolve32Rip; + i->setSibBase(BX_32BIT_REG_EIP); goto get_32bit_displ; } // mod==00b, rm!=4, rm!=5 @@ -3655,8 +3655,8 @@ get_8bit_displ: index = (sib & 0x7) | rex_x; sib >>= 3; scale = sib; i->setSibBase(base); - i->metaData.metaData2 |= (index); - i->metaData.metaData2 |= (scale<<4); + i->setSibIndex(index); + i->setSibScale(scale); if (index == 4) i->ResolveModrm = &BX_CPU_C::BxResolve32Base; else diff --git a/bochs/cpu/instr.h b/bochs/cpu/instr.h index 8756bcc6f..3c6e1fb19 100755 --- a/bochs/cpu/instr.h +++ b/bochs/cpu/instr.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: instr.h,v 1.4 2008-02-04 21:28:53 sshwarts Exp $ +// $Id: instr.h,v 1.5 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (c) 2008 Stanislav Shwartsman @@ -60,6 +60,7 @@ public: Bit8u metaInfo1; } metaInfo; + // using 5-bit index for registers (16 regs in 64-bit and RIP) struct { // (unused, keep for alignment) // (will be used for SSE5 destination override later) @@ -72,24 +73,24 @@ public: // 2...0 seg Bit8u metaData6; - // 7...4 (unused) - // 3...0 nnn (modrm) + // 7...5 (unused) + // 4...0 nnn (modrm) Bit8u metaData5; - // 7...4 (unused) - // 3...0 base (sib) + // 7...5 (unused) + // 4...0 base (sib) Bit8u metaData4; - // 7...4 (unused) - // 3...0 index (sib) + // 7...5 (unused) + // 4...0 index (sib) Bit8u metaData3; // 7...2 (unused) // 1...0 scale (sib) Bit8u metaData2; - // 7...4 (unused) - // 3...0 rm (modrm) // also used for opcodeReg() + // 7...5 (unused) + // 4...0 rm (modrm) // also used for opcodeReg() Bit8u metaData1; } metaData; diff --git a/bochs/cpu/iret.cc b/bochs/cpu/iret.cc index f5f92e8e7..6c4c9a839 100755 --- a/bochs/cpu/iret.cc +++ b/bochs/cpu/iret.cc @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////// -// $Id: iret.cc,v 1.27 2008-02-02 21:46:51 sshwarts Exp $ +// $Id: iret.cc,v 1.28 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (c) 2005 Stanislav Shwartsman @@ -137,7 +137,7 @@ BX_CPU_C::iret_protected(bxInstruction_c *i) } /* CS on stack must be within stack limits, else #SS(0) */ - if ( !can_pop(top_nbytes_same) ) { + if (!can_pop(top_nbytes_same)) { BX_ERROR(("iret: CS not within stack limits")); exception(BX_SS_EXCEPTION, 0, 0); } @@ -238,7 +238,7 @@ BX_CPU_C::iret_protected(bxInstruction_c *i) */ /* top 10/20 bytes on stack must be within limits else #SS(0) */ - if ( !can_pop(top_nbytes_outer) ) { + if (!can_pop(top_nbytes_outer)) { BX_ERROR(("iret: top 10/20 bytes not within stack limits")); exception(BX_SS_EXCEPTION, 0, 0); } @@ -247,7 +247,7 @@ BX_CPU_C::iret_protected(bxInstruction_c *i) raw_ss_selector = read_virtual_word(BX_SEG_REG_SS, temp_ESP + ss_offset); /* selector must be non-null, else #GP(0) */ - if ( (raw_ss_selector & 0xfffc) == 0 ) { + if ((raw_ss_selector & 0xfffc) == 0) { BX_ERROR(("iret: SS selector null")); exception(BX_GP_EXCEPTION, 0, 0); } @@ -386,7 +386,7 @@ BX_CPU_C::long_iret(bxInstruction_c *i) } else if (i->os32L()) { /* CS on stack must be within stack limits, else #SS(0) */ - if ( !can_pop(12) ) { + if (!can_pop(12)) { BX_ERROR(("iret64: CS not within stack limits")); exception(BX_SS_EXCEPTION, 0, 0); } @@ -401,7 +401,7 @@ BX_CPU_C::long_iret(bxInstruction_c *i) } else { /* CS on stack must be within stack limits, else #SS(0) */ - if ( !can_pop(6) ) { + if (!can_pop(6)) { BX_ERROR(("iret64: CS not within stack limits")); exception(BX_SS_EXCEPTION, 0, 0); } diff --git a/bochs/cpu/jmp_far.cc b/bochs/cpu/jmp_far.cc index b24a21cdd..6a918f325 100755 --- a/bochs/cpu/jmp_far.cc +++ b/bochs/cpu/jmp_far.cc @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////// -// $Id: jmp_far.cc,v 1.11 2008-01-29 17:13:07 sshwarts Exp $ +// $Id: jmp_far.cc,v 1.12 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (c) 2005 Stanislav Shwartsman @@ -262,7 +262,7 @@ BX_CPU_C::jmp_call_gate64(bx_selector_t *gate_selector) Bit16u dest_selector = gate_descriptor.u.gate.dest_selector; // selector must not be null else #GP(0) - if ( (dest_selector & 0xfffc) == 0 ) { + if ((dest_selector & 0xfffc) == 0) { BX_ERROR(("call_gate64: selector in gate null")); exception(BX_GP_EXCEPTION, 0, 0); } diff --git a/bochs/cpu/paging.cc b/bochs/cpu/paging.cc index c0182efc7..dd364cea9 100644 --- a/bochs/cpu/paging.cc +++ b/bochs/cpu/paging.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: paging.cc,v 1.109 2008-02-11 20:52:10 sshwarts Exp $ +// $Id: paging.cc,v 1.110 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -341,12 +341,12 @@ static unsigned priv_check[BX_PRIV_CHECK_SIZE]; // value, necessitating a TLB flush when CR0.WP changes. // // The test is: -// OK = 0x1 << ( (W<<2) | CPL ) [W:1=write, 0=read] +// OK = 0x01 << ( (W<<2) | CPL ) [W:1=write, 0=read] // // Thus for reads, it is: -// OK = 0x01 << ( CPL ) +// OK = 0x01 << ( CPL ) // And for writes: -// OK = 0x10 << ( CPL ) +// OK = 0x10 << ( CPL ) // // bit 15: a Write from CPL=3 is OK // bit 14: a Write from CPL=2 is OK @@ -431,7 +431,7 @@ BX_CPU_C::pagingCR0Changed(Bit32u oldCR0, Bit32u newCR0) // Modification of PG,PE flushes TLB cache according to docs. // Additionally, the TLB strategy is based on the current value of // WP, so if that changes we must also flush the TLB. - if ( (oldCR0 & 0x80010001) != (newCR0 & 0x80010001) ) + if ((oldCR0 & 0x80010001) != (newCR0 & 0x80010001)) TLB_flush(1); // 1 = Flush Global entries also. if (bx_dbg.paging) @@ -1119,7 +1119,7 @@ void BX_CPU_C::access_linear(bx_address laddr, unsigned len, unsigned curr_pl, u if (BX_CPU_THIS_PTR cr0.get_PG()) { /* check for reference across multiple pages */ - if ( (pageOffset + len) <= 4096 ) { + if ((pageOffset + len) <= 4096) { // Access within single page. BX_CPU_THIS_PTR address_xlation.paddress1 = dtranslate_linear(laddr, curr_pl, xlate_rw); @@ -1211,7 +1211,7 @@ void BX_CPU_C::access_linear(bx_address laddr, unsigned len, unsigned curr_pl, u } else { // Paging off. - if ( (pageOffset + len) <= 4096 ) { + if ((pageOffset + len) <= 4096) { // Access within single page. BX_CPU_THIS_PTR address_xlation.paddress1 = (bx_phy_address) laddr; BX_CPU_THIS_PTR address_xlation.pages = 1; diff --git a/bochs/cpu/proc_ctrl.cc b/bochs/cpu/proc_ctrl.cc index 69c436d38..b4b3204c1 100644 --- a/bochs/cpu/proc_ctrl.cc +++ b/bochs/cpu/proc_ctrl.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: proc_ctrl.cc,v 1.201 2008-02-12 22:41:39 sshwarts Exp $ +// $Id: proc_ctrl.cc,v 1.202 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -304,21 +304,21 @@ void BX_CPU_C::MOV_DdRd(bxInstruction_c *i) if ( (((val_32>>16) & 3)==2) || (((val_32>>20) & 3)==2) || (((val_32>>24) & 3)==2) || - (((val_32>>28) & 3)==2) ) { + (((val_32>>28) & 3)==2)) { // IO breakpoints (10b) are not yet supported. BX_PANIC(("MOV_DdRd: write of %08x contains IO breakpoint", val_32)); } if ( (((val_32>>18) & 3)==2) || (((val_32>>22) & 3)==2) || (((val_32>>26) & 3)==2) || - (((val_32>>30) & 3)==2) ) { + (((val_32>>30) & 3)==2)) { // LEN0..3 contains undefined length specifier (10b) BX_PANIC(("MOV_DdRd: write of %08x contains undefined LENx", val_32)); } if ( ((((val_32>>16) & 3)==0) && (((val_32>>18) & 3)!=0)) || ((((val_32>>20) & 3)==0) && (((val_32>>22) & 3)!=0)) || ((((val_32>>24) & 3)==0) && (((val_32>>26) & 3)!=0)) || - ((((val_32>>28) & 3)==0) && (((val_32>>30) & 3)!=0)) ) + ((((val_32>>28) & 3)==0) && (((val_32>>30) & 3)!=0))) { // Instruction breakpoint with LENx not 00b (1-byte length) BX_PANIC(("MOV_DdRd: write of %08x, R/W=00b LEN!=00b", val_32)); @@ -489,7 +489,7 @@ void BX_CPU_C::MOV_DqRq(bxInstruction_c *i) if ( (((val_64>>16) & 3)==2) || (((val_64>>20) & 3)==2) || (((val_64>>24) & 3)==2) || - (((val_64>>28) & 3)==2) ) + (((val_64>>28) & 3)==2)) { // IO breakpoints (10b) are not yet supported. BX_PANIC(("MOV_DqRq: write of %08x:%08x contains IO breakpoint", @@ -498,7 +498,7 @@ void BX_CPU_C::MOV_DqRq(bxInstruction_c *i) if ( (((val_64>>18) & 3)==2) || (((val_64>>22) & 3)==2) || (((val_64>>26) & 3)==2) || - (((val_64>>30) & 3)==2) ) + (((val_64>>30) & 3)==2)) { // LEN0..3 contains undefined length specifier (10b) BX_PANIC(("MOV_DqRq: write of %08x:%08x contains undefined LENx", @@ -507,7 +507,7 @@ void BX_CPU_C::MOV_DqRq(bxInstruction_c *i) if ( ((((val_64>>16) & 3)==0) && (((val_64>>18) & 3)!=0)) || ((((val_64>>20) & 3)==0) && (((val_64>>22) & 3)!=0)) || ((((val_64>>24) & 3)==0) && (((val_64>>26) & 3)!=0)) || - ((((val_64>>28) & 3)==0) && (((val_64>>30) & 3)!=0)) ) + ((((val_64>>28) & 3)==0) && (((val_64>>30) & 3)!=0))) { // Instruction breakpoint with LENx not 00b (1-byte length) BX_PANIC(("MOV_DqRq: write of %08x:%08x , R/W=00b LEN!=00b", @@ -1196,7 +1196,7 @@ void BX_CPU_C::handleCpuModeChange(void) } else { BX_CPU_THIS_PTR cpu_mode = BX_MODE_LONG_COMPAT; - if (BX_CPU_THIS_PTR eip_reg.dword.rip_upper != 0) { + if (BX_CPU_THIS_PTR gen_reg[BX_64BIT_REG_RIP].dword.hrx != 0) { BX_PANIC(("handleCpuModeChange: leaving long mode with RIP upper != 0 !")); } } @@ -1281,7 +1281,7 @@ void BX_CPU_C::SetCR0(Bit32u val_32) exception(BX_GP_EXCEPTION, 0, 0); } if (BX_CPU_THIS_PTR efer.lma) { - if (BX_CPU_THIS_PTR eip_reg.dword.rip_upper != 0) { + if (BX_CPU_THIS_PTR gen_reg[BX_64BIT_REG_RIP].dword.hrx != 0) { BX_PANIC(("SetCR0: attempt to leave x86-64 LONG mode with RIP upper != 0 !!!")); } BX_CPU_THIS_PTR efer.lma = 0; diff --git a/bochs/cpu/resolve64.cc b/bochs/cpu/resolve64.cc index 76823d7c8..03be51895 100644 --- a/bochs/cpu/resolve64.cc +++ b/bochs/cpu/resolve64.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: resolve64.cc,v 1.17 2008-01-29 17:13:09 sshwarts Exp $ +// $Id: resolve64.cc,v 1.18 2008-02-15 19:03:54 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -32,17 +32,6 @@ #if BX_SUPPORT_X86_64 - void BX_CPP_AttrRegparmN(1) -BX_CPU_C::BxResolve32Rip(bxInstruction_c *i) -{ - RMAddr(i) = EIP + i->displ32u(); -} - void BX_CPP_AttrRegparmN(1) -BX_CPU_C::BxResolve64Rip(bxInstruction_c *i) -{ - RMAddr(i) = RIP + (Bit32s) i->displ32u(); -} - void BX_CPP_AttrRegparmN(1) BX_CPU_C::BxResolve64DispIndex(bxInstruction_c *i) { diff --git a/bochs/cpu/soft_int.cc b/bochs/cpu/soft_int.cc index 74c507530..6c33f2ee6 100644 --- a/bochs/cpu/soft_int.cc +++ b/bochs/cpu/soft_int.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: soft_int.cc,v 1.39 2008-02-02 21:46:53 sshwarts Exp $ +// $Id: soft_int.cc,v 1.40 2008-02-15 19:03:54 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -159,7 +159,7 @@ void BX_CPU_C::INT_Ib(bxInstruction_c *i) } #ifdef SHOW_EXIT_STATUS - if ( (vector == 0x21) && (AH == 0x4c) ) { + if ((vector == 0x21) && (AH == 0x4c)) { BX_INFO(("INT 21/4C called AL=0x%02x, BX=0x%04x", (unsigned) AL, (unsigned) BX)); } #endif diff --git a/bochs/cpu/tasking.cc b/bochs/cpu/tasking.cc index e7454c9e0..007cc5359 100644 --- a/bochs/cpu/tasking.cc +++ b/bochs/cpu/tasking.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: tasking.cc,v 1.46 2008-02-02 21:46:54 sshwarts Exp $ +// $Id: tasking.cc,v 1.47 2008-02-15 19:03:54 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -475,7 +475,7 @@ void BX_CPU_C::task_switch(bx_selector_t *tss_selector, exception(BX_TS_EXCEPTION, raw_ldt_selector & 0xfffc, 0); } - if ( (raw_ldt_selector & 0xfffc) != 0 ) { + if ((raw_ldt_selector & 0xfffc) != 0) { bx_bool good = fetch_raw_descriptor2(&ldt_selector, &dword1, &dword2); if (!good) { BX_ERROR(("task_switch(exception after commit point): bad LDT fetch")); @@ -527,7 +527,7 @@ void BX_CPU_C::task_switch(bx_selector_t *tss_selector, // load cache with new segment descriptor and set valid bit // CS - if ( (raw_cs_selector & 0xfffc) != 0 ) { + if ((raw_cs_selector & 0xfffc) != 0) { bx_bool good = fetch_raw_descriptor2(&cs_selector, &dword1, &dword2); if (!good) { BX_ERROR(("task_switch(exception after commit point): bad CS fetch")); @@ -652,7 +652,7 @@ void BX_CPU_C::task_switch(bx_selector_t *tss_selector, // // Step 14: Begin execution of new task. // - BX_DEBUG(( "TASKING: LEAVE" )); + BX_DEBUG(("TASKING: LEAVE")); } void BX_CPU_C::task_switch_load_selector(bx_segment_reg_t *seg, diff --git a/bochs/cpu/vm8086.cc b/bochs/cpu/vm8086.cc index 5b739c719..ec7c63095 100644 --- a/bochs/cpu/vm8086.cc +++ b/bochs/cpu/vm8086.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: vm8086.cc,v 1.38 2008-02-02 21:46:54 sshwarts Exp $ +// $Id: vm8086.cc,v 1.39 2008-02-15 19:03:54 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -75,7 +75,7 @@ void BX_CPU_C::stack_return_to_v86(Bit32u new_eip, Bit32u raw_cs_selector, temp_ESP = SP; // top 36 bytes of stack must be within stack limits, else #SS(0) - if ( !can_pop(36) ) { + if (!can_pop(36)) { BX_ERROR(("stack_return_to_v86: top 36 bytes not within limits")); exception(BX_SS_EXCEPTION, 0, 0); } @@ -118,7 +118,7 @@ void BX_CPU_C::iret16_stack_return_from_v86(bxInstruction_c *i) Bit16u ip, cs_raw, flags16; - if( !can_pop(6) ) + if(!can_pop(6)) { BX_DEBUG(("iret16_stack_return_from_v86(): can't pop 6 bytes from the stack")); exception(BX_SS_EXCEPTION, 0, 0); @@ -175,7 +175,7 @@ void BX_CPU_C::iret32_stack_return_from_v86(bxInstruction_c *i) change_mask |= (EFlagsIDMask | EFlagsACMask); // ID/AC #endif - if( !can_pop(12) ) + if(!can_pop(12)) { BX_DEBUG(("iret32_stack_return_from_v86(): can't pop 12 bytes from the stack")); exception(BX_SS_EXCEPTION, 0, 0); diff --git a/bochs/gdbstub.cc b/bochs/gdbstub.cc index 6769fdd8b..df042f486 100644 --- a/bochs/gdbstub.cc +++ b/bochs/gdbstub.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: gdbstub.cc,v 1.31 2008-02-05 22:57:39 sshwarts Exp $ +// $Id: gdbstub.cc,v 1.32 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002-2006 The Bochs Project Team @@ -454,11 +454,11 @@ static void debug_loop(void) case 'c': { char buf[255]; - int new_eip; + Bit32u new_eip; if (buffer[1] != 0) { - new_eip = atoi(buffer + 1); + new_eip = (Bit32u) atoi(buffer + 1); BX_INFO(("continuing at %x", new_eip)); @@ -467,8 +467,7 @@ static void debug_loop(void) } saved_eip = EIP; - - BX_CPU(0)->eip_reg.dword.eip = new_eip; + BX_CPU_THIS_PTR gen_reg[BX_32BIT_REG_EIP].dword.erx = new_eip; } stub_trace_flag = 0; @@ -479,7 +478,7 @@ static void debug_loop(void) if (buffer[1] != 0) { bx_cpu.invalidate_prefetch_q(); - BX_CPU_THIS_PTR eip_reg.dword.eip = saved_eip; + BX_CPU_THIS_PTR gen_reg[BX_32BIT_REG_EIP].dword.erx = saved_eip; } BX_INFO(("stopped with %x", last_stop_reason)); diff --git a/bochs/iodev/iodebug.cc b/bochs/iodev/iodebug.cc index eccf73574..676ff6d14 100644 --- a/bochs/iodev/iodebug.cc +++ b/bochs/iodev/iodebug.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: iodebug.cc,v 1.23 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: iodebug.cc,v 1.24 2008-02-15 19:03:54 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// #include "bochs.h" @@ -152,18 +152,21 @@ void bx_iodebug_c::mem_write(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *dat area--; #if BX_DEBUGGER - if (cpu != NULL) - fprintf(stdout, "IODEBUG %s @ eip: " FMT_ADDRX " write at monitored memory location %8X\n", cpu->name, cpu->get_ip(), addr); - else + if (cpu != NULL) { + fprintf(stdout, "IODEBUG %s @ eip: " FMT_ADDRX " write at monitored memory location %8X\n", + cpu->name, cpu->get_instruction_pointer(), addr); + } + else { fprintf(stdout, "IODEBUG write at monitored memory location %8X\n", addr); + } bx_guard.interrupt_requested=1; #else fprintf(stderr, "IODEBUG write to monitored memory area: %2i\t", area); if (cpu != NULL) - fprintf(stderr, "by EIP:\t\t" FMT_ADDRX "\n\t", cpu->get_ip()); + fprintf(stderr, "by EIP:\t\t" FMT_ADDRX "\n\t", cpu->get_instruction_pointer()); else - fprintf(stderr, "(device origin)\t", cpu->get_ip()); + fprintf(stderr, "(device origin)\t", cpu->get_instruction_pointer()); fprintf(stderr, "range start: \t\t%08X\trange end:\t%08X\n\taddress accessed:\t%08X\tdata written:\t", bx_iodebug_s.monitored_mem_areas_start[area], @@ -212,18 +215,21 @@ void bx_iodebug_c::mem_read(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data area--; #if BX_DEBUGGER - if (cpu != NULL) - fprintf(stdout, "IODEBUG %s @ eip: " FMT_ADDRX " read at monitored memory location %8X\n", cpu->name, cpu->get_ip(), addr); - else + if (cpu != NULL) { + fprintf(stdout, "IODEBUG %s @ eip: " FMT_ADDRX " read at monitored memory location %8X\n", + cpu->name, cpu->get_instruction_pointer(), addr); + } + else { fprintf(stdout, "IODEBUG read at monitored memory location %8X\n", addr); + } bx_guard.interrupt_requested=1; #else fprintf(stderr, "IODEBUG read at monitored memory area: %2i\t", area); if (cpu != NULL) - fprintf(stderr, "by EIP:\t\t" FMT_ADDRX "\n\t", cpu->get_ip()); + fprintf(stderr, "by EIP:\t\t" FMT_ADDRX "\n\t", cpu->get_instruction_pointer()); else - fprintf(stderr, "(device origin)\t", cpu->get_ip()); + fprintf(stderr, "(device origin)\t", cpu->get_instruction_pointer()); fprintf(stderr, "range start: \t\t%08X\trange end:\t%08X\n\taddress accessed:\t%08X\tdata written:\t", bx_iodebug_s.monitored_mem_areas_start[area], diff --git a/bochs/load32bitOShack.cc b/bochs/load32bitOShack.cc index dad83bacb..7c8d74651 100644 --- a/bochs/load32bitOShack.cc +++ b/bochs/load32bitOShack.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: load32bitOShack.cc,v 1.25 2008-02-05 22:57:40 sshwarts Exp $ +// $Id: load32bitOShack.cc,v 1.26 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -138,7 +138,7 @@ static void bx_load_linux_setup_params(Bit32u initrd_start, Bit32u initrd_size) struct linux_setup_params *params = (struct linux_setup_params *) &mem->vector[0x00090000]; - memset( params, '\0', sizeof(*params) ); + memset(params, '\0', sizeof(*params)); /* Video settings (standard VGA) */ params->orig_x = 0; @@ -180,34 +180,34 @@ void bx_load_linux_hack(void) bx_load_kernel_image(SIM->get_param_string(BXPN_LOAD32BITOS_PATH)->getptr(), 0x100000); // Load initial ramdisk image if requested - char * tmpPtr = SIM->get_param_string(BXPN_LOAD32BITOS_INITRD)->getptr(); - if ( tmpPtr && tmpPtr[0] ) /* The initial value is "" and not NULL */ + char *tmpPtr = SIM->get_param_string(BXPN_LOAD32BITOS_INITRD)->getptr(); + if (tmpPtr && tmpPtr[0]) /* The initial value is "" and not NULL */ { initrd_start = 0x00800000; /* FIXME: load at top of memory */ - initrd_size = bx_load_kernel_image( tmpPtr, initrd_start ); + initrd_size = bx_load_kernel_image(tmpPtr, initrd_start); } // Setup Linux startup parameters buffer - bx_load_linux_setup_params( initrd_start, initrd_size ); + bx_load_linux_setup_params(initrd_start, initrd_size); // Enable A20 line - BX_SET_ENABLE_A20( 1 ); + BX_SET_ENABLE_A20(1); // Setup PICs the way Linux likes it - BX_OUTP( 0x20, 0x11, 1 ); - BX_OUTP( 0xA0, 0x11, 1 ); - BX_OUTP( 0x21, 0x20, 1 ); - BX_OUTP( 0xA1, 0x28, 1 ); - BX_OUTP( 0x21, 0x04, 1 ); - BX_OUTP( 0xA1, 0x02, 1 ); - BX_OUTP( 0x21, 0x01, 1 ); - BX_OUTP( 0xA1, 0x01, 1 ); - BX_OUTP( 0x21, 0xFF, 1 ); - BX_OUTP( 0xA1, 0xFB, 1 ); + BX_OUTP(0x20, 0x11, 1); + BX_OUTP(0xA0, 0x11, 1); + BX_OUTP(0x21, 0x20, 1); + BX_OUTP(0xA1, 0x28, 1); + BX_OUTP(0x21, 0x04, 1); + BX_OUTP(0xA1, 0x02, 1); + BX_OUTP(0x21, 0x01, 1); + BX_OUTP(0xA1, 0x01, 1); + BX_OUTP(0x21, 0xFF, 1); + BX_OUTP(0xA1, 0xFB, 1); // Disable interrupts and NMIs - BX_CPU(0)->clear_IF (); - BX_OUTP( 0x70, 0x80, 1 ); + BX_CPU(0)->clear_IF(); + BX_OUTP(0x70, 0x80, 1); // Enter protected mode // Fixed by george (kyriazis at nvidia.com) @@ -224,7 +224,7 @@ void bx_load_linux_hack(void) BX_CPU(0)->gdtr.base = 0x00090400; // Jump to protected mode entry point - BX_CPU(0)->jump_protected( NULL, 0x10, 0x00100000 ); + BX_CPU(0)->jump_protected(NULL, 0x10, 0x100000); } void bx_load_null_kernel_hack(void) @@ -235,7 +235,7 @@ void bx_load_null_kernel_hack(void) bx_load_kernel_image(SIM->get_param_string(BXPN_LOAD32BITOS_PATH)->getptr(), 0x100000); // EIP deltas - BX_CPU(0)->prev_rip = BX_CPU(0)->eip_reg.dword.eip = 0x00100000; + BX_CPU(0)->prev_rip = BX_CPU(0)->gen_reg[BX_32BIT_REG_EIP].dword.erx = 0x100000; // CS deltas BX_CPU(0)->sregs[BX_SEG_REG_CS].cache.u.segment.base = 0x00000000; @@ -274,21 +274,21 @@ bx_load_kernel_image(char *path, Bit32u paddr) #endif ); if (fd < 0) { - BX_INFO(( "load_kernel_image: couldn't open image file '%s'.", path )); + BX_INFO(("load_kernel_image: couldn't open image file '%s'.", path)); BX_EXIT(1); } ret = fstat(fd, &stat_buf); if (ret) { - BX_INFO(( "load_kernel_image: couldn't stat image file '%s'.", path )); + BX_INFO(("load_kernel_image: couldn't stat image file '%s'.", path)); BX_EXIT(1); } - size = (unsigned long)stat_buf.st_size; + size = (unsigned long) stat_buf.st_size; page_size = ((Bit32u)size + 0xfff) & ~0xfff; BX_MEM_C *mem = BX_MEM(0); - if ( (paddr + size) > mem->len ) { - BX_INFO(( "load_kernel_image: address range > physical memsize!" )); + if ((paddr + size) > mem->len) { + BX_INFO(("load_kernel_image: address range > physical memsize!")); BX_EXIT(1); } @@ -296,7 +296,7 @@ bx_load_kernel_image(char *path, Bit32u paddr) while (size > 0) { ret = read(fd, (bx_ptr_t) &mem->vector[paddr + offset], size); if (ret <= 0) { - BX_INFO(( "load_kernel_image: read failed on image" )); + BX_INFO(("load_kernel_image: read failed on image")); BX_EXIT(1); } size -= ret; diff --git a/bochs/logio.cc b/bochs/logio.cc index ee055bf4d..7c64805a7 100644 --- a/bochs/logio.cc +++ b/bochs/logio.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: logio.cc,v 1.65 2008-02-05 22:57:40 sshwarts Exp $ +// $Id: logio.cc,v 1.66 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -103,7 +103,7 @@ void iofunctions::init_log(const char *fn) newfd = fopen(fn, "w"); if(newfd != NULL) { newfn = strdup(fn); - log->ldebug("Opened log file '%s'.", fn ); + log->ldebug("Opened log file '%s'.", fn); } else { // in constructor, genlog might not exist yet, so do it the safe way. log->error("Couldn't open log file: %s, using stderr instead", fn); @@ -196,7 +196,7 @@ void iofunctions::out(int f, int l, const char *prefix, const char *fmt, va_list break; case 'i': #if BX_SUPPORT_SMP == 0 - fprintf(logfd, "%08x", BX_CPU(0)->eip_reg.dword.eip); + fprintf(logfd, "%08x", BX_CPU(0)->get_eip()); #endif break; case 'e': diff --git a/bochs/main.cc b/bochs/main.cc index 717fdaf61..ec8142fae 100644 --- a/bochs/main.cc +++ b/bochs/main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: main.cc,v 1.372 2008-02-05 22:57:40 sshwarts Exp $ +// $Id: main.cc,v 1.373 2008-02-15 19:03:53 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -91,7 +91,7 @@ Bit8u bx_cpu_count; #define LOG_THIS genlog-> -#if ( BX_PROVIDE_DEVICE_MODELS==1 ) +#if BX_PROVIDE_DEVICE_MODELS bx_pc_system_c bx_pc_system; #endif @@ -129,29 +129,29 @@ void bx_print_header () #if BX_WITH_CARBON /* Original code by Darrell Walisser - dwaliss1@purdue.edu */ -static void setupWorkingDirectory (char *path) +static void setupWorkingDirectory(char *path) { - char parentdir[MAXPATHLEN]; - char *c; + char parentdir[MAXPATHLEN]; + char *c; - strncpy ( parentdir, path, MAXPATHLEN ); - c = (char*) parentdir; + strncpy (parentdir, path, MAXPATHLEN); + c = (char*) parentdir; - while (*c != '\0') /* go to end */ - c++; + while (*c != '\0') /* go to end */ + c++; - while (*c != '/') /* back up to parent */ - c--; + while (*c != '/') /* back up to parent */ + c--; - *c = '\0'; /* cut off last part (binary name) */ + *c = '\0'; /* cut off last part (binary name) */ - /* chdir to the binary app's parent */ - int n; - n = chdir (parentdir); - if (n) BX_PANIC (("failed to change dir to parent")); - /* chdir to the .app's parent */ - n = chdir ("../../../"); - if (n) BX_PANIC (("failed to change to ../../..")); + /* chdir to the binary app's parent */ + int n; + n = chdir (parentdir); + if (n) BX_PANIC (("failed to change dir to parent")); + /* chdir to the .app's parent */ + n = chdir ("../../../"); + if (n) BX_PANIC (("failed to change to ../../..")); } /* Panic button to display fatal errors. @@ -187,8 +187,8 @@ static void carbonFatalDialog(const char *error, const char *exposition) &alertDialog); RunStandardAlert( alertDialog, NULL, &index); // Cleanup - CFRelease( cfError ); - if( cfExposition != NULL ) { CFRelease( cfExposition ); } + CFRelease(cfError); + if(cfExposition != NULL) { CFRelease(cfExposition); } } #endif @@ -419,13 +419,13 @@ int RedirectIOToConsole() hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen(hConHandle, "w"); *stdout = *fp; - setvbuf( stdout, NULL, _IONBF, 0 ); + setvbuf(stdout, NULL, _IONBF, 0); // redirect unbuffered STDIN to the console lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen(hConHandle, "r"); *stdin = *fp; - setvbuf( stdin, NULL, _IONBF, 0 ); + setvbuf(stdin, NULL, _IONBF, 0); // redirect unbuffered STDERR to the console lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); @@ -1115,7 +1115,7 @@ void bx_init_hardware() #if !defined(__MINGW32__) && !defined(_MSC_VER) signal(SIGALRM, bx_signal_handler); #endif - alarm( 1 ); + alarm(1); #endif } @@ -1241,7 +1241,7 @@ void bx_signal_handler(int signum) } #if !defined(__MINGW32__) && !defined(_MSC_VER) signal(SIGALRM, bx_signal_handler); - alarm( 1 ); + alarm(1); #endif return; } diff --git a/bochs/plex86-interface.cc b/bochs/plex86-interface.cc index 069e17815..b014073d6 100644 --- a/bochs/plex86-interface.cc +++ b/bochs/plex86-interface.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -//// $Id: plex86-interface.cc,v 1.11 2008-02-05 22:57:40 sshwarts Exp $ +//// $Id: plex86-interface.cc,v 1.12 2008-02-15 19:03:53 sshwarts Exp $ /////////////////////////////////////////////////////////////////////////// //// //// Copyright (C) 2002 Kevin P. Lawton @@ -84,7 +84,7 @@ unsigned plex86CpuInfo(BX_CPU_C *cpu) if (plex86FD < 0) { // If the plex86 File Descriptor has not been opened yet. - if ( !openFD() ) { + if (!openFD()) { return(0); // Error. } } @@ -96,7 +96,7 @@ unsigned plex86CpuInfo(BX_CPU_C *cpu) bochsCPUID.featureFlags.raw = cpu->cpuidInfo.featureFlags; fprintf(stderr, "plex86: passing guest CPUID to plex86.\n"); - if ( ioctl(plex86FD, PLEX86_CPUID, &bochsCPUID) ) { + if (ioctl(plex86FD, PLEX86_CPUID, &bochsCPUID)) { perror("ioctl CPUID: "); return(0); // Error. } @@ -114,12 +114,12 @@ unsigned plex86TearDown(void) fprintf(stderr, "plex86: FC[%u] = %u\n", f, faultCount[f]); } - if ( plex86FD < 0 ) { + if (plex86FD < 0) { fprintf(stderr, "plex86: plex86TearDown: FD not open.\n"); return(0); } - if ( plex86State & Plex86StateMMapPhyMem ) { + if (plex86State & Plex86StateMMapPhyMem) { fprintf(stderr, "plex86: unmapping guest physical memory.\n"); } plex86State &= ~Plex86StateMMapPhyMem; @@ -157,7 +157,7 @@ unsigned plex86ExecuteInVM(BX_CPU_C *cpu) plex86IoctlExecute_t executeMsg; int ret; - if ( plex86State != Plex86StateReady ) { + if (plex86State != Plex86StateReady) { fprintf(stderr, "plex86: plex86ExecuteInVM: not in ready state (0x%x)\n", plex86State); BX_PANIC(("plex86ExecuteInVM: bailing")); @@ -175,7 +175,7 @@ unsigned plex86ExecuteInVM(BX_CPU_C *cpu) plex86GuestCPU->eax = cpu->gen_reg[BX_32BIT_REG_EAX].dword.erx; plex86GuestCPU->eflags = cpu->eflags.val32; - plex86GuestCPU->eip = cpu->eip_reg.dword.eip; + plex86GuestCPU->eip = cpu->get_eip(); // ES/CS/SS/DS/FS/GS for (unsigned s=0; s<6; s++) { @@ -261,7 +261,7 @@ unsigned plex86ExecuteInVM(BX_CPU_C *cpu) } } else { - switch ( executeMsg.monitorState.request ) { + switch (executeMsg.monitorState.request) { case MonReqFlushPrintBuf: fprintf(stderr, "plex86: MonReqFlushPrintBuf:\n"); fprintf(stderr, "::%s\n", plex86PrintBuffer); @@ -302,7 +302,7 @@ void copyPlex86StateToBochs(BX_CPU_C *cpu) cpu->gen_reg[BX_32BIT_REG_EAX].dword.erx = plex86GuestCPU->eax; cpu->eflags.val32 = plex86GuestCPU->eflags; - cpu->eip_reg.dword.eip = plex86GuestCPU->eip; + cpu->gen_reg[BX_32BIT_REG_EIP].dword.erx = plex86GuestCPU->eip; // Set fields used for exception processing. cpu->prev_rip = plex86GuestCPU->eip; @@ -311,9 +311,9 @@ void copyPlex86StateToBochs(BX_CPU_C *cpu) for (unsigned s=0; s<6; s++) { cpu->sregs[s].selector.value = plex86GuestCPU->sreg[s].sel.raw; cpu->sregs[s].cache.valid = plex86GuestCPU->sreg[s].valid; - if ( (cpu->sregs[s].selector.value & 0xfffc) == 0 ) { + if ((cpu->sregs[s].selector.value & 0xfffc) == 0) { /* Null selector. */ - if ( cpu->sregs[s].cache.valid ) { + if (cpu->sregs[s].cache.valid) { plex86TearDown(); BX_PANIC(("copyPlex86StateToBochs: null descriptor [%u] " "with descriptor cache valid bit set.", s)); @@ -322,7 +322,7 @@ void copyPlex86StateToBochs(BX_CPU_C *cpu) } else { /* Non-null selector. */ - if ( cpu->sregs[s].cache.valid==0 ) { + if (cpu->sregs[s].cache.valid==0) { plex86TearDown(); BX_PANIC(("copyPlex86StateToBochs: non-null descriptor [%u] " "with descriptor cache valid bit clear.", s)); @@ -404,7 +404,7 @@ unsigned plex86RegisterGuestMemory(Bit8u *vector, unsigned bytes) if (plex86FD < 0) { // If the plex86 File Descriptor has not been opened yet. - if ( !openFD() ) { + if (!openFD()) { return(0); // Error. } } @@ -415,7 +415,7 @@ unsigned plex86RegisterGuestMemory(Bit8u *vector, unsigned bytes) "is not a 4Meg increment.\n", bytes); return(0); // Error. } - if ( ((unsigned)vector) & 0xfff ) { + if (((unsigned)vector) & 0xfff) { // Memory vector must be page aligned. fprintf(stderr, "plex86: RegisterGuestMemory: vector not page aligned."); return(0); // Error.