I want to replace debugger ICOUNT guard by existent cpu_loop funtionality, first step to do that ...

This commit is contained in:
Stanislav Shwartsman 2006-04-29 07:12:13 +00:00
parent 510cbe02e2
commit 1a0b7ee1e3
6 changed files with 96 additions and 106 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: dbg_main.cc,v 1.63 2006-03-08 20:10:29 sshwarts Exp $
// $Id: dbg_main.cc,v 1.64 2006-04-29 07:12:13 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -70,13 +70,6 @@ static struct {
char default_unit_size;
Bit32u default_addr;
unsigned next_bpoint_id;
// last icount known to be in sync
#if BX_DBG_ICOUNT_SIZE == 32
Bit32u last_sync_icount;
#else // BX_DBG_ICOUNT_SIZE == 64
Bit64u last_sync_icount;
#endif
} bx_debugger;
#define BX_DBG_DEFAULT_ICOUNT_QUANTUM 3 /* mch */
@ -113,7 +106,7 @@ static struct {
unsigned len; // number of bytes in op
unsigned what; // BX_READ or BX_WRITE
Bit32u val; // value of DMA op
bx_dbg_icount_t icount; // icount at this dma op
Bit32u icount; // icount at this dma op
} Q[BX_BATCH_DMA_BUFSIZE];
} bx_dbg_batch_dma;
@ -161,7 +154,6 @@ int bx_dbg_main(int argc, char *argv[])
bx_debugger.default_unit_size = 'w';
bx_debugger.default_addr = 0;
bx_debugger.next_bpoint_id = 1;
bx_debugger.last_sync_icount = 0;
argv0 = strdup(argv[0]);
@ -509,7 +501,7 @@ void bx_debug_ctrlc_handler(int signum)
bx_debug_break ();
}
void bx_debug_break ()
void bx_debug_break()
{
bx_guard.interrupt_requested = 1;
}
@ -1198,7 +1190,7 @@ one_more:
// I must guard for ICOUNT or one CPU could run forever without giving
// the others a chance.
bx_guard.guard_for |= BX_DBG_GUARD_ICOUNT;
bx_guard.guard_for |= BX_DBG_GUARD_CTRL_C; // stop on Ctrl-C
bx_guard.guard_for |= BX_DBG_GUARD_CTRL_C; // stop on Ctrl-C
// update gui (disable continue command, enable stop command, etc.)
sim_running->set (1);
@ -1226,7 +1218,7 @@ one_more:
BX_CPU(cpu)->guard_found.guard_found = 0;
BX_CPU(cpu)->guard_found.icount = 0;
bx_guard.icount = quantum;
BX_CPU(cpu)->cpu_loop (-1);
BX_CPU(cpu)->cpu_loop(0);
// set stop flag if a guard found other than icount or halted
unsigned long found = BX_CPU(cpu)->guard_found.guard_found;
stop_reason_t reason = (stop_reason_t) BX_CPU(cpu)->stop_reason;
@ -1281,7 +1273,7 @@ one_more:
goto one_more;
}
void bx_dbg_stepN_command(bx_dbg_icount_t count)
void bx_dbg_stepN_command(Bit32u count)
{
if (count == 0) {
dbg_printf("Error: stepN: count=0\n");
@ -1302,7 +1294,7 @@ void bx_dbg_stepN_command(bx_dbg_icount_t count)
bx_guard.interrupt_requested = 0;
BX_CPU(cpu)->guard_found.guard_found = 0;
BX_CPU(cpu)->guard_found.icount = 0;
BX_CPU(cpu)->cpu_loop(-1);
BX_CPU(cpu)->cpu_loop(0);
}
#if BX_SUPPORT_SMP == 0
// ticks are handled inside the cpu loop

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: debug.h,v 1.22 2006-02-13 21:32:21 sshwarts Exp $
// $Id: debug.h,v 1.23 2006-04-29 07:12:13 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -29,14 +29,6 @@
#include "config.h"
#include "osdep.h"
#if BX_DBG_ICOUNT_SIZE == 32
typedef Bit32u bx_dbg_icount_t;
#elif BX_DBG_ICOUNT_SIZE == 64
typedef Bit64u bx_dbg_icount_t;
#else
# error "BX_DBG_ICOUNT_SIZE incorrect."
#endif
#define BX_DBG_NO_HANDLE 1000
extern Bit32u dbg_cpu;
@ -252,7 +244,7 @@ void bx_dbg_print_stack_command(unsigned nwords);
void bx_dbg_watch(int read, Bit32u address);
void bx_dbg_unwatch(int read, Bit32u address);
void bx_dbg_continue_command(void);
void bx_dbg_stepN_command(bx_dbg_icount_t count);
void bx_dbg_stepN_command(Bit32u count);
void bx_dbg_set_auto_disassemble(bx_bool enable);
void bx_dbg_disassemble_switch_mode(void);
void bx_dbg_set_disassemble_size(unsigned size);
@ -327,9 +319,14 @@ extern int num_read_watchpoints;
extern Bit32u read_watchpoint[MAX_READ_WATCHPOINTS];
typedef enum {
STOP_NO_REASON = 0, STOP_TIME_BREAK_POINT, STOP_READ_WATCH_POINT,
STOP_WRITE_WATCH_POINT, STOP_MAGIC_BREAK_POINT,
STOP_MODE_BREAK_POINT, STOP_CPU_HALTED, STOP_CPU_PANIC
STOP_NO_REASON = 0,
STOP_TIME_BREAK_POINT,
STOP_READ_WATCH_POINT,
STOP_WRITE_WATCH_POINT,
STOP_MAGIC_BREAK_POINT,
STOP_MODE_BREAK_POINT,
STOP_CPU_HALTED,
STOP_CPU_PANIC
} stop_reason_t;
typedef enum {
@ -405,7 +402,7 @@ typedef struct {
#endif
} iaddr;
bx_dbg_icount_t icount; // stop after completing this many instructions
Bit32u icount; // stop after completing this many instructions
// user typed Ctrl-C, requesting simulator stop at next convient spot
volatile bx_bool interrupt_requested;
@ -460,7 +457,7 @@ typedef struct {
typedef struct bx_guard_found_t {
unsigned long guard_found;
unsigned iaddr_index;
bx_dbg_icount_t icount; // number of completed instructions
Bit32u icount; // number of completed instructions
Bit32u cs; // cs:eip and linear addr of instruction at guard point
bx_address eip;
bx_address laddr;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.cc,v 1.146 2006-04-28 16:45:29 sshwarts Exp $
// $Id: cpu.cc,v 1.147 2006-04-29 07:12:13 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -106,11 +106,12 @@ static unsigned iCacheMisses=0;
// instructions and then return so that the other processors have a chance to
// run. This is used only when simulating multiple processors.
//
// If maximum instructions have been executed, return. A count less
// than zero means run forever.
// If maximum instructions have been executed, return. The zero-count
// means run forever.
#define CHECK_MAX_INSTRUCTIONS(count) \
if (count >= 0) { \
count--; if (count == 0) return; \
if (count > 0) { \
count--; \
if (count == 0) return; \
}
#if BX_SUPPORT_SMP
@ -201,7 +202,7 @@ BX_CPP_INLINE bxInstruction_c* BX_CPU_C::fetchInstruction(bxInstruction_c *iStor
return i;
}
void BX_CPU_C::cpu_loop(Bit32s max_instr_count)
void BX_CPU_C::cpu_loop(Bit32u max_instr_count)
{
bxInstruction_c iStorage BX_CPP_AlignN(32);
@ -426,6 +427,69 @@ debugger_check:
// inform instrumentation about new instruction
BX_INSTR_NEW_INSTRUCTION(BX_CPU_ID);
#if BX_DEBUGGER
// Mode switch support is in dbg_is_begin_instr_bpoint
// note instr generating exceptions never reach this point.
// (mch) Read/write, time break point support
if (BX_CPU_THIS_PTR break_point) {
switch (BX_CPU_THIS_PTR break_point) {
case BREAK_POINT_TIME:
BX_INFO(("[" FMT_LL "d] Caught time breakpoint", bx_pc_system.time_ticks()));
BX_CPU_THIS_PTR stop_reason = STOP_TIME_BREAK_POINT;
return;
case BREAK_POINT_READ:
BX_INFO(("[" FMT_LL "d] Caught read watch point", bx_pc_system.time_ticks()));
BX_CPU_THIS_PTR stop_reason = STOP_READ_WATCH_POINT;
return;
case BREAK_POINT_WRITE:
BX_INFO(("[" FMT_LL "d] Caught write watch point", bx_pc_system.time_ticks()));
BX_CPU_THIS_PTR stop_reason = STOP_WRITE_WATCH_POINT;
return;
default:
BX_PANIC(("Weird break point condition"));
}
}
#if BX_MAGIC_BREAKPOINT
// (mch) Magic break point support
if (BX_CPU_THIS_PTR magic_break) {
if (bx_dbg.magic_break_enabled) {
BX_DEBUG(("Stopped on MAGIC BREAKPOINT"));
BX_CPU_THIS_PTR stop_reason = STOP_MAGIC_BREAK_POINT;
return;
}
else {
BX_CPU_THIS_PTR magic_break = 0;
BX_CPU_THIS_PTR stop_reason = STOP_NO_REASON;
BX_DEBUG(("Ignoring MAGIC BREAKPOINT"));
}
}
#endif
{
// check for icount or control-C. If found, set guard reg and return.
bx_address debug_eip = BX_CPU_THIS_PTR prev_eip;
if (dbg_is_end_instr_bpoint(
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value,
debug_eip,
BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS) + debug_eip,
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b,
Is64BitMode()))
{
return;
}
}
#endif // #if BX_DEBUGGER
#if BX_GDBSTUB
if (bx_dbg.gdbstub_enabled) {
unsigned int reason = bx_gdbstub_check(EIP);
if (reason != GDBSTUB_STOP_NO_REASON) {
return;
}
}
#endif
#if (BX_SUPPORT_SMP && BX_DEBUGGER==0)
// The CHECK_MAX_INSTRUCTIONS macro allows cpu_loop to execute a few
// instructions and then return so that the other processors have a chance
@ -436,69 +500,6 @@ debugger_check:
CHECK_MAX_INSTRUCTIONS(max_instr_count);
#endif
#if BX_DEBUGGER
// Mode switch support is in dbg_is_begin_instr_bpoint
// note instr generating exceptions never reach this point.
// (mch) Read/write, time break point support
if (BX_CPU_THIS_PTR break_point) {
switch (BX_CPU_THIS_PTR break_point) {
case BREAK_POINT_TIME:
BX_INFO(("[" FMT_LL "d] Caught time breakpoint", bx_pc_system.time_ticks()));
BX_CPU_THIS_PTR stop_reason = STOP_TIME_BREAK_POINT;
return;
case BREAK_POINT_READ:
BX_INFO(("[" FMT_LL "d] Caught read watch point", bx_pc_system.time_ticks()));
BX_CPU_THIS_PTR stop_reason = STOP_READ_WATCH_POINT;
return;
case BREAK_POINT_WRITE:
BX_INFO(("[" FMT_LL "d] Caught write watch point", bx_pc_system.time_ticks()));
BX_CPU_THIS_PTR stop_reason = STOP_WRITE_WATCH_POINT;
return;
default:
BX_PANIC(("Weird break point condition"));
}
}
#if BX_MAGIC_BREAKPOINT
// (mch) Magic break point support
if (BX_CPU_THIS_PTR magic_break) {
if (bx_dbg.magic_break_enabled) {
BX_DEBUG(("Stopped on MAGIC BREAKPOINT"));
BX_CPU_THIS_PTR stop_reason = STOP_MAGIC_BREAK_POINT;
return;
}
else {
BX_CPU_THIS_PTR magic_break = 0;
BX_CPU_THIS_PTR stop_reason = STOP_NO_REASON;
BX_DEBUG(("Ignoring MAGIC BREAKPOINT"));
}
}
#endif
{
// check for icount or control-C. If found, set guard reg and return.
bx_address debug_eip = BX_CPU_THIS_PTR prev_eip;
if (dbg_is_end_instr_bpoint(
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value,
debug_eip,
BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS) + debug_eip,
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b,
Is64BitMode()))
{
return;
}
}
#endif // #if BX_DEBUGGER
#if BX_GDBSTUB
if (bx_dbg.gdbstub_enabled) {
unsigned int reason = bx_gdbstub_check(EIP);
if (reason != GDBSTUB_STOP_NO_REASON) {
return;
}
}
#endif
} // while (1)
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.282 2006-04-25 15:35:26 sshwarts Exp $
// $Id: cpu.h,v 1.283 2006-04-29 07:12:13 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -2664,7 +2664,7 @@ public: // for now...
BX_SMF void atexit(void);
// now for some ancillary functions...
BX_SMF void cpu_loop(Bit32s max_instr_count);
BX_SMF void cpu_loop(Bit32u max_instr_count);
BX_SMF unsigned handleAsyncEvent(void);
BX_SMF void boundaryFetch(Bit8u *fetchPtr, unsigned remainingInPage, bxInstruction_c *i);
BX_SMF void prefetch(void);

View File

@ -432,7 +432,7 @@ static void debug_loop(void)
stub_trace_flag = 0;
bx_cpu.ispanic = 0;
bx_cpu.cpu_loop(-1);
bx_cpu.cpu_loop(0);
if (bx_cpu.ispanic)
{
last_stop_reason = GDBSTUB_EXECUTION_BREAKPOINT;
@ -468,7 +468,7 @@ static void debug_loop(void)
BX_INFO (("stepping"));
stub_trace_flag = 1;
bx_cpu.cpu_loop(-1);
bx_cpu.cpu_loop(0);
DEV_vga_refresh();
stub_trace_flag = 0;
BX_INFO (("stopped with %x", last_stop_reason));
@ -903,5 +903,5 @@ void bx_gdbstub_init(int argc, char* argv[])
debug_loop();
/* CPU loop */
bx_cpu.cpu_loop(-1);
bx_cpu.cpu_loop(0);
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.332 2006-04-16 09:29:02 vruppert Exp $
// $Id: main.cc,v 1.333 2006-04-29 07:12:13 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -857,7 +857,7 @@ int bx_begin_simulation (int argc, char *argv[])
#if BX_SUPPORT_SMP == 0
// only one processor, run as fast as possible by not messing with
// quantums and loops.
BX_CPU(0)->cpu_loop(1);
BX_CPU(0)->cpu_loop(0);
// for one processor, the only reason for cpu_loop to return is
// that kill_bochs_request was set by the GUI interface.
#else