small fixups, code cleanup and reorganization

This commit is contained in:
Stanislav Shwartsman 2011-09-05 17:14:49 +00:00
parent 41f9b25777
commit c67338203c
5 changed files with 50 additions and 38 deletions

View File

@ -193,11 +193,6 @@ void print_tree(bx_param_c *node, int level = 0);
# define A20ADDR(x) ((bx_phy_address)(x))
#endif
#define BX_TICK1_IF_SINGLE_PROCESSOR() \
if (BX_SMP_PROCESSORS == 1) BX_TICK1()
#define BX_TICKN_IF_SINGLE_PROCESSOR(n) \
if (BX_SMP_PROCESSORS == 1) BX_TICKN(n)
// you can't use static member functions on the CPU, if there are going
// to be 2 cpus. Check this early on.
#if BX_SUPPORT_SMP

View File

@ -75,7 +75,7 @@ void BX_CPU_C::cpu_loop(Bit32u max_instr_count)
#endif
if (setjmp(BX_CPU_THIS_PTR jmp_buf_env)) {
// only from exception function we can get here ...
// can get here only from exception function or VMEXIT
BX_TICK1_IF_SINGLE_PROCESSOR();
#if BX_DEBUGGER || BX_GDBSTUB
if (dbg_instruction_epilog()) return;
@ -115,20 +115,36 @@ void BX_CPU_C::cpu_loop(Bit32u max_instr_count)
bxICacheEntry_c *entry = getICacheEntry();
bxInstruction_c *i = entry->i;
#if BX_SUPPORT_HANDLERS_CHAINING_SPEEDUPS == 0
bxInstruction_c *last = i + (entry->tlen);
#endif
#if BX_SUPPORT_HANDLERS_CHAINING_SPEEDUPS
for(;;) {
BX_DEBUG_DISASM_INSTRUCTION();
// want to allow changing of the instruction inside instrumentation callback
BX_INSTR_BEFORE_EXECUTION(BX_CPU_ID, i);
RIP += i->ilen();
// when handlers chaining is enabled this single call will execute entire trace
BX_CPU_CALL_METHOD(i->execute, (i)); // might iterate repeat instruction
if (BX_CPU_THIS_PTR async_event) {
// clear stop trace magic indication that probably was set by repeat or branch32/64
BX_CPU_THIS_PTR async_event &= ~BX_ASYNC_EVENT_STOP_TRACE;
break;
}
i = getICacheEntry()->i;
}
#else // BX_SUPPORT_HANDLERS_CHAINING_SPEEDUPS == 0
bxInstruction_c *last = i + (entry->tlen);
for(;;) {
if (BX_CPU_THIS_PTR trace)
debug_disasm_instruction(BX_CPU_THIS_PTR prev_rip);
// want to allow changing of the instruction inside instrumentation callback
BX_INSTR_BEFORE_EXECUTION(BX_CPU_ID, i);
RIP += i->ilen();
BX_CPU_CALL_METHOD(i->execute, (i)); // might iterate repeat instruction
BX_CPU_THIS_PTR prev_rip = RIP; // commit new RIP
BX_INSTR_AFTER_EXECUTION(BX_CPU_ID, i);
BX_TICK1_IF_SINGLE_PROCESSOR();
@ -146,17 +162,13 @@ void BX_CPU_C::cpu_loop(Bit32u max_instr_count)
break;
}
#if BX_SUPPORT_HANDLERS_CHAINING_SPEEDUPS
entry = getICacheEntry();
i = entry->i;
#else
if (++i == last) {
entry = getICacheEntry();
i = entry->i;
last = i + (entry->tlen);
}
#endif
}
#endif
} // while (1)
}
@ -725,7 +737,9 @@ void BX_CPU_C::prefetch(void)
// The next instruction could already hit a code breakpoint but
// async_event won't take effect immediatelly.
// Check if the next executing instruction hits code breakpoint
if (code_breakpoint_match(laddr)) exception(BX_DB_EXCEPTION, 0);
if (RIP == BX_CPU_THIS_PTR prev_rip) { // if not fetching page cross instruction
if (code_breakpoint_match(laddr)) exception(BX_DB_EXCEPTION, 0);
}
}
}
else {

View File

@ -28,31 +28,38 @@ class bxInstruction_c;
typedef void BX_INSF_TYPE;
#if BX_DEBUGGER && BX_DISASM
// print the instruction that is about to be executed
#define BX_DEBUG_DISASM_INSTRUCTION() \
if (BX_CPU_THIS_PTR trace) { debug_disasm_instruction(BX_CPU_THIS_PTR prev_rip); }
#else
#define BX_DEBUG_DISASM_INSTRUCTION() /* do nothing */
#endif
#define BX_NEXT_TRACE(i) { return; }
#define BX_TICK1_IF_SINGLE_PROCESSOR() \
if (BX_SMP_PROCESSORS == 1) BX_TICK1()
#if BX_SUPPORT_HANDLERS_CHAINING_SPEEDUPS
#define BX_NEXT_INSTR(i) { \
#define BX_COMMIT_INSTRUCTION(i) { \
BX_CPU_THIS_PTR prev_rip = RIP; /* commit new RIP */ \
BX_INSTR_AFTER_EXECUTION(BX_CPU_ID, i); \
BX_INSTR_AFTER_EXECUTION(BX_CPU_ID, (i)); \
BX_TICK1_IF_SINGLE_PROCESSOR(); \
}
#define BX_EXECUTE_INSTRUCTION(i) { \
BX_INSTR_BEFORE_EXECUTION(BX_CPU_ID, (i)); \
RIP += (i)->ilen(); \
return BX_CPU_CALL_METHOD(i->execute, (i)); \
}
#define BX_NEXT_TRACE(i) { \
BX_COMMIT_INSTRUCTION(i); \
return; \
}
#define BX_NEXT_INSTR(i) { \
BX_COMMIT_INSTRUCTION(i); \
if (BX_CPU_THIS_PTR async_event) return; \
++i; \
BX_INSTR_BEFORE_EXECUTION(BX_CPU_ID, i); \
RIP += i->ilen(); \
return BX_CPU_CALL_METHOD(i->execute, (i)); \
BX_EXECUTE_INSTRUCTION(i); \
}
#else
#define BX_NEXT_TRACE(i) { return; }
#define BX_NEXT_INSTR(i) { return; }
#endif

View File

@ -249,6 +249,4 @@ typedef struct {
SET_FLAGS_OSZAP_RESULT_SIZE(64, (result), BX_LF_INSTR_DEC64)
#endif
BOCHSAPI extern const Bit8u bx_parity_lookup[256];
#endif // BX_LAZY_FLAGS_DEF

View File

@ -287,8 +287,7 @@ int bx_pc_system_c::register_timer_ticks(void* this_ptr, bx_timer_handler_t func
timer[i].inUse = 1;
timer[i].period = ticks;
timer[i].timeToFire = (ticksTotal + Bit64u(currCountdownPeriod-currCountdown)) +
ticks;
timer[i].timeToFire = (ticksTotal + Bit64u(currCountdownPeriod-currCountdown)) + ticks;
timer[i].active = active;
timer[i].continuous = continuous;
timer[i].funct = funct;
@ -474,8 +473,7 @@ void bx_pc_system_c::activate_timer_ticks(unsigned i, Bit64u ticks, bx_bool cont
}
timer[i].period = ticks;
timer[i].timeToFire = (ticksTotal + Bit64u(currCountdownPeriod-currCountdown)) +
ticks;
timer[i].timeToFire = (ticksTotal + Bit64u(currCountdownPeriod-currCountdown)) + ticks;
timer[i].active = 1;
timer[i].continuous = continuous;