2003-11-28 18:07:29 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2003-11-28 18:07:29 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-03-19 23:09:34 +03:00
|
|
|
// Copyright (C) 2001-2011 The Bochs Project
|
2003-11-28 18:07:29 +03:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-01-15 20:55:25 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <signal.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2010-02-26 17:18:19 +03:00
|
|
|
#include "param_names.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu/cpu.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.h"
|
2009-01-19 22:01:03 +03:00
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
|
2009-01-19 22:01:03 +03:00
|
|
|
#include "disasm/disasm.h"
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
#define LOG_THIS genlog->
|
|
|
|
|
|
|
|
#if HAVE_LIBREADLINE
|
|
|
|
extern "C" {
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <readline/readline.h>
|
|
|
|
#if HAVE_READLINE_HISTORY_H
|
|
|
|
#include <readline/history.h>
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// default CPU in the debugger. For commands like "dump_cpu" it will
|
|
|
|
// use the default instead of always dumping all cpus.
|
2006-01-27 22:50:00 +03:00
|
|
|
unsigned dbg_cpu = 0;
|
2007-10-11 22:12:00 +04:00
|
|
|
bx_list_c *dbg_cpu_list = 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
extern const char* cpu_mode_string(unsigned cpu_mode);
|
2007-10-14 23:04:51 +04:00
|
|
|
extern void bx_sr_after_restore_state(void);
|
2006-02-03 01:33:32 +03:00
|
|
|
|
2009-10-02 14:16:04 +04:00
|
|
|
void bx_dbg_print_descriptor(Bit32u lo, Bit32u hi);
|
|
|
|
void bx_dbg_print_descriptor64(Bit32u lo1, Bit32u hi1, Bit32u lo2, Bit32u hi2);
|
|
|
|
|
2006-09-17 11:12:50 +04:00
|
|
|
static bx_param_bool_c *sim_running = NULL;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
static char tmp_buf[512];
|
|
|
|
static char tmp_buf_prev[512];
|
|
|
|
static char *tmp_buf_ptr;
|
|
|
|
static char *argv0 = NULL;
|
|
|
|
|
|
|
|
static FILE *debugger_log = NULL;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
// some fields used for single CPU debugger
|
|
|
|
bx_bool auto_disassemble;
|
|
|
|
unsigned disassemble_size;
|
|
|
|
char default_display_format;
|
|
|
|
char default_unit_size;
|
2009-04-07 20:12:19 +04:00
|
|
|
bx_address default_addr;
|
2003-11-28 18:07:29 +03:00
|
|
|
unsigned next_bpoint_id;
|
2008-08-08 01:09:30 +04:00
|
|
|
unsigned next_wpoint_id;
|
2005-04-10 22:03:16 +04:00
|
|
|
} bx_debugger;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2012-03-10 21:14:07 +04:00
|
|
|
typedef struct _debug_info_t {
|
|
|
|
const char *name;
|
|
|
|
bx_devmodel_c *device;
|
|
|
|
struct _debug_info_t *next;
|
|
|
|
} debug_info_t;
|
|
|
|
|
|
|
|
static debug_info_t *bx_debug_info_list = NULL;
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
typedef struct {
|
|
|
|
FILE *fp;
|
|
|
|
char fname[BX_MAX_PATH];
|
|
|
|
unsigned lineno;
|
2005-04-10 22:03:16 +04:00
|
|
|
} bx_infile_stack_entry_t;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_infile_stack_entry_t bx_infile_stack[BX_INFILE_DEPTH];
|
|
|
|
int bx_infile_stack_index = 0;
|
|
|
|
|
|
|
|
static int bx_nest_infile(char *path);
|
|
|
|
|
2009-04-14 13:45:22 +04:00
|
|
|
void CDECL bx_debug_ctrlc_handler(int signum);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
static void bx_unnest_infile(void);
|
|
|
|
static void bx_get_command(void);
|
|
|
|
static void bx_dbg_print_guard_results();
|
|
|
|
static void bx_dbg_breakpoint_changed(void);
|
2011-08-17 23:51:32 +04:00
|
|
|
static void bx_dbg_set_icount_guard(int which_cpu, Bit32u n);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2011-08-17 23:51:32 +04:00
|
|
|
bx_guard_t bx_guard;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// DMA stuff
|
|
|
|
void bx_dbg_post_dma_reports(void);
|
|
|
|
#define BX_BATCH_DMA_BUFSIZE 512
|
|
|
|
|
|
|
|
static struct {
|
2006-04-29 13:27:49 +04:00
|
|
|
unsigned this_many; // batch this many max before posting events
|
|
|
|
unsigned Qsize; // this many have been batched
|
2003-11-28 18:07:29 +03:00
|
|
|
struct {
|
2007-10-09 23:49:23 +04:00
|
|
|
bx_phy_address addr; // address of DMA op
|
|
|
|
unsigned len; // number of bytes in op
|
|
|
|
unsigned what; // BX_READ or BX_WRITE
|
|
|
|
Bit32u val; // value of DMA op
|
|
|
|
Bit64u time; // system time at this dma op
|
2005-04-08 22:30:34 +04:00
|
|
|
} Q[BX_BATCH_DMA_BUFSIZE];
|
|
|
|
} bx_dbg_batch_dma;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// some buffers for disassembly
|
2006-06-11 20:40:37 +04:00
|
|
|
static disassembler bx_disassemble;
|
2003-11-28 18:07:29 +03:00
|
|
|
static Bit8u bx_disasm_ibuf[32];
|
|
|
|
static char bx_disasm_tbuf[512];
|
|
|
|
|
2009-11-20 15:02:57 +03:00
|
|
|
static bx_bool watchpoint_continue = 0;
|
2008-10-08 21:13:35 +04:00
|
|
|
unsigned num_write_watchpoints = 0;
|
|
|
|
unsigned num_read_watchpoints = 0;
|
2009-11-20 00:28:25 +03:00
|
|
|
bx_watchpoint write_watchpoint[BX_DBG_MAX_WATCHPONTS];
|
|
|
|
bx_watchpoint read_watchpoint[BX_DBG_MAX_WATCHPONTS];
|
2008-06-01 00:59:38 +04:00
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
#define DBG_PRINTF_BUFFER_LEN 1024
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
void dbg_printf(const char *fmt, ...)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2009-02-08 21:52:06 +03:00
|
|
|
char buf[DBG_PRINTF_BUFFER_LEN+1];
|
2006-06-09 16:26:34 +04:00
|
|
|
vsnprintf(buf, DBG_PRINTF_BUFFER_LEN, fmt, ap);
|
2003-11-28 18:07:29 +03:00
|
|
|
va_end(ap);
|
|
|
|
if (debugger_log != NULL) {
|
|
|
|
fprintf(debugger_log,"%s", buf);
|
|
|
|
fflush(debugger_log);
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2006-04-29 13:27:49 +04:00
|
|
|
SIM->debug_puts(buf); // send to debugger, which will free buf when done.
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-10-24 21:53:47 +04:00
|
|
|
void bx_dbg_init_infile(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-10-24 21:53:47 +04:00
|
|
|
bx_infile_stack_index = 0;
|
|
|
|
bx_infile_stack[0].fp = stdin;
|
|
|
|
bx_infile_stack[0].lineno = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bx_dbg_set_rcfile(const char *rcfile)
|
|
|
|
{
|
|
|
|
strncpy(bx_infile_stack[0].fname, rcfile, BX_MAX_PATH);
|
|
|
|
bx_infile_stack[0].fname[BX_MAX_PATH-1] = 0;
|
|
|
|
BX_INFO(("debugger using rc file '%s'.", rcfile));
|
|
|
|
return bx_nest_infile((char*)rcfile);
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:14:07 +04:00
|
|
|
bx_bool bx_dbg_register_debug_info(const char *devname, void *dev)
|
|
|
|
{
|
|
|
|
debug_info_t *debug_info;
|
|
|
|
|
|
|
|
debug_info = (debug_info_t *)malloc(sizeof(debug_info_t));
|
|
|
|
if (debug_info == NULL) {
|
|
|
|
BX_PANIC(("can't allocate debug_info_t"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_info->name = devname;
|
|
|
|
debug_info->device = (bx_devmodel_c*)dev;
|
|
|
|
debug_info->next = NULL;
|
|
|
|
|
|
|
|
if (bx_debug_info_list == NULL) {
|
|
|
|
bx_debug_info_list = debug_info;
|
|
|
|
} else {
|
|
|
|
debug_info_t *temp = bx_debug_info_list;
|
|
|
|
|
|
|
|
while (temp->next) {
|
|
|
|
if (!strcmp(temp->name, devname)) {
|
|
|
|
free(debug_info);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
temp = temp->next;
|
|
|
|
}
|
|
|
|
temp->next = debug_info;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_info_cleanup(void)
|
|
|
|
{
|
|
|
|
debug_info_t *temp = bx_debug_info_list, *next;
|
|
|
|
while (temp != NULL) {
|
|
|
|
next = temp->next;
|
|
|
|
free(temp);
|
|
|
|
temp = next;
|
|
|
|
}
|
|
|
|
bx_debug_info_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bx_bool bx_dbg_info_find_device(const char *devname, debug_info_t **found_debug_info)
|
|
|
|
{
|
|
|
|
debug_info_t *debug_info;
|
|
|
|
|
|
|
|
for (debug_info = bx_debug_info_list; debug_info; debug_info = debug_info->next) {
|
|
|
|
if (!strcmp(debug_info->name, devname)) {
|
|
|
|
*found_debug_info = debug_info;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-24 21:53:47 +04:00
|
|
|
int bx_dbg_main(void)
|
|
|
|
{
|
2006-04-29 13:27:49 +04:00
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_dbg_batch_dma.this_many = 1;
|
|
|
|
bx_dbg_batch_dma.Qsize = 0;
|
|
|
|
|
|
|
|
memset(&bx_guard, 0, sizeof(bx_guard));
|
|
|
|
bx_guard.async.irq = 1;
|
|
|
|
bx_guard.async.dma = 1;
|
|
|
|
|
|
|
|
memset(&bx_debugger, 0, sizeof(bx_debugger));
|
|
|
|
bx_debugger.auto_disassemble = 1;
|
|
|
|
bx_debugger.disassemble_size = 0;
|
|
|
|
bx_debugger.default_display_format = 'x';
|
|
|
|
bx_debugger.default_unit_size = 'w';
|
|
|
|
bx_debugger.default_addr = 0;
|
|
|
|
bx_debugger.next_bpoint_id = 1;
|
2008-08-08 01:09:30 +04:00
|
|
|
bx_debugger.next_wpoint_id = 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2007-10-14 23:04:51 +04:00
|
|
|
dbg_cpu_list = (bx_list_c*) SIM->get_param("cpu0", SIM->get_bochs_root());
|
2008-03-23 20:59:44 +03:00
|
|
|
const char *debugger_log_filename = SIM->get_param_string(BXPN_DEBUGGER_LOG_FILENAME)->getptr();
|
2007-10-11 22:12:00 +04:00
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
// Open debugger log file if needed
|
2008-03-23 20:59:44 +03:00
|
|
|
if (strlen(debugger_log_filename) > 0 && (strcmp(debugger_log_filename, "-") != 0))
|
|
|
|
{
|
|
|
|
debugger_log = fopen(debugger_log_filename, "w");
|
2003-11-28 18:07:29 +03:00
|
|
|
if (!debugger_log) {
|
2008-03-23 20:59:44 +03:00
|
|
|
BX_PANIC(("Can not open debugger log file '%s'", debugger_log_filename));
|
2006-05-30 23:46:31 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
2008-03-23 20:59:44 +03:00
|
|
|
BX_INFO(("Using debugger log file %s", debugger_log_filename));
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2006-05-30 23:46:31 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
memset(bx_disasm_ibuf, 0, sizeof(bx_disasm_ibuf));
|
|
|
|
|
|
|
|
// create a boolean parameter that will tell if the simulation is
|
|
|
|
// running (continue command) or waiting for user response. This affects
|
|
|
|
// some parts of the GUI.
|
2006-09-17 11:12:50 +04:00
|
|
|
if (sim_running == NULL) {
|
|
|
|
bx_list_c *base = (bx_list_c*) SIM->get_param("general");
|
|
|
|
sim_running = new bx_param_bool_c(base,
|
|
|
|
"debug_running",
|
|
|
|
"Simulation is running", "", 0);
|
|
|
|
} else {
|
|
|
|
sim_running->set(0);
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
// setup Ctrl-C handler
|
2006-11-12 13:07:18 +03:00
|
|
|
if (!SIM->has_debug_gui()) {
|
2003-11-28 18:07:29 +03:00
|
|
|
signal(SIGINT, bx_debug_ctrlc_handler);
|
2006-04-29 13:27:49 +04:00
|
|
|
BX_INFO(("set SIGINT handler to bx_debug_ctrlc_handler"));
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print disassembly of the first instruction... you wouldn't think it
|
|
|
|
// would have to be so hard. First initialize guard_found, since it is used
|
|
|
|
// in the disassembly code to decide what instruction to print.
|
2007-10-11 22:12:00 +04:00
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS; i++) {
|
2006-01-15 20:55:25 +03:00
|
|
|
BX_CPU(i)->guard_found.cs = BX_CPU(i)->sregs[BX_SEG_REG_CS].selector.value;
|
2010-02-24 22:43:40 +03:00
|
|
|
BX_CPU(i)->guard_found.eip = BX_CPU(i)->get_instruction_pointer();
|
2003-11-28 18:07:29 +03:00
|
|
|
BX_CPU(i)->guard_found.laddr =
|
2010-02-24 22:41:32 +03:00
|
|
|
BX_CPU(i)->get_laddr(BX_SEG_REG_CS, BX_CPU(i)->guard_found.eip);
|
2012-06-04 22:46:07 +04:00
|
|
|
BX_CPU(i)->guard_found.code_32_64 = 0;
|
2009-03-10 19:28:01 +03:00
|
|
|
// 00 - 16 bit, 01 - 32 bit, 10 - 64-bit, 11 - illegal
|
|
|
|
if (BX_CPU(i)->sregs[BX_SEG_REG_CS].cache.u.segment.d_b)
|
|
|
|
BX_CPU(i)->guard_found.code_32_64 |= 0x1;
|
|
|
|
if (BX_CPU(i)->get_cpu_mode() == BX_MODE_LONG_64)
|
|
|
|
BX_CPU(i)->guard_found.code_32_64 |= 0x2;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
// finally, call the usual function to print the disassembly
|
2006-04-29 13:27:49 +04:00
|
|
|
dbg_printf("Next at t=" FMT_LL "d\n", bx_pc_system.time_ticks());
|
|
|
|
bx_dbg_disassemble_current(-1, 0); // all cpus, don't print time
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_dbg_user_input_loop();
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
if(debugger_log != NULL)
|
2003-11-28 18:07:29 +03:00
|
|
|
fclose(debugger_log);
|
|
|
|
|
|
|
|
bx_dbg_exit(0);
|
|
|
|
return(0); // keep compiler happy
|
|
|
|
}
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
void bx_dbg_interpret_line(char *cmd)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_add_lex_input(cmd);
|
|
|
|
bxparse();
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_user_input_loop(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
int reti;
|
|
|
|
unsigned include_cmd_len = strlen(BX_INCLUDE_CMD);
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
while(1) {
|
|
|
|
SIM->refresh_ci();
|
|
|
|
SIM->set_display_mode(DISP_MODE_CONFIG);
|
2011-11-20 20:21:53 +04:00
|
|
|
SIM->get_param_bool(BXPN_MOUSE_ENABLED)->set(0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_get_command();
|
|
|
|
reparse:
|
|
|
|
if ((*tmp_buf_ptr == '\n') || (*tmp_buf_ptr == 0))
|
2005-04-08 22:30:34 +04:00
|
|
|
{
|
2003-11-28 18:07:29 +03:00
|
|
|
if ((*tmp_buf_prev != '\n') && (*tmp_buf_prev != 0)) {
|
|
|
|
strncpy(tmp_buf, tmp_buf_prev, sizeof(tmp_buf_prev));
|
|
|
|
goto reparse;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
|
|
|
}
|
2006-04-29 13:27:49 +04:00
|
|
|
else if ((strncmp(tmp_buf_ptr, BX_INCLUDE_CMD, include_cmd_len) == 0) &&
|
2003-11-28 18:07:29 +03:00
|
|
|
(tmp_buf_ptr[include_cmd_len] == ' ' ||
|
2006-04-29 13:27:49 +04:00
|
|
|
tmp_buf_ptr[include_cmd_len] == '\t'))
|
2005-04-08 22:30:34 +04:00
|
|
|
{
|
2009-11-02 17:56:26 +03:00
|
|
|
char *ptr = tmp_buf_ptr + include_cmd_len + 1;
|
2006-04-29 13:27:49 +04:00
|
|
|
while(*ptr==' ' || *ptr=='\t')
|
2003-11-28 18:07:29 +03:00
|
|
|
ptr++;
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
int len = strlen(ptr);
|
2003-11-28 18:07:29 +03:00
|
|
|
if (len == 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: no filename given to 'source' command.\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bx_infile_stack_index > 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: ERROR in source file causes exit.\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
continue;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
ptr[len-1] = 0; // get rid of newline
|
|
|
|
reti = bx_nest_infile(ptr);
|
2009-11-02 17:56:26 +03:00
|
|
|
if (reti==0 && bx_infile_stack_index > 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: ERROR in source file causes exit.\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
|
|
|
// Give a chance to the command line extensions, to
|
|
|
|
// consume the command. If they return 0, then
|
|
|
|
// we need to process the command. A return of 1
|
|
|
|
// means, the extensions have handled the command
|
2006-04-29 13:27:49 +04:00
|
|
|
if (bx_dbg_extensions(tmp_buf_ptr)==0) {
|
2003-11-28 18:07:29 +03:00
|
|
|
// process command here
|
|
|
|
bx_add_lex_input(tmp_buf_ptr);
|
|
|
|
bxparse();
|
|
|
|
}
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_get_command(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
char *charptr_ret;
|
|
|
|
|
|
|
|
bx_infile_stack[bx_infile_stack_index].lineno++;
|
|
|
|
|
|
|
|
char prompt[256];
|
|
|
|
if (bx_infile_stack_index == 0) {
|
|
|
|
sprintf(prompt, "<bochs:%d> ", bx_infile_stack[bx_infile_stack_index].lineno);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2006-11-12 13:07:18 +03:00
|
|
|
if (SIM->has_debug_gui() && bx_infile_stack_index == 0) {
|
2012-07-01 18:37:13 +04:00
|
|
|
// wait for gui debugger to send another debugger command
|
2006-04-29 13:27:49 +04:00
|
|
|
charptr_ret = SIM->debug_get_next_command();
|
2003-11-28 18:07:29 +03:00
|
|
|
if (charptr_ret) {
|
2006-04-29 13:27:49 +04:00
|
|
|
strncpy(tmp_buf, charptr_ret, sizeof(tmp_buf));
|
|
|
|
strcat(tmp_buf, "\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
// The returned string was allocated in wxmain.cc by "new char[]".
|
|
|
|
// Free it with delete[].
|
|
|
|
delete [] charptr_ret;
|
|
|
|
charptr_ret = &tmp_buf[0];
|
|
|
|
} else {
|
|
|
|
// if debug_get_next_command returned NULL, probably the GUI is
|
|
|
|
// shutting down
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if HAVE_LIBREADLINE
|
|
|
|
else if (bx_infile_stack_index == 0) {
|
2006-04-29 13:27:49 +04:00
|
|
|
charptr_ret = readline(prompt);
|
2003-11-28 18:07:29 +03:00
|
|
|
// beware, returns NULL on end of file
|
|
|
|
if (charptr_ret && strlen(charptr_ret) > 0) {
|
2006-04-29 13:27:49 +04:00
|
|
|
add_history(charptr_ret);
|
|
|
|
strcpy(tmp_buf, charptr_ret);
|
|
|
|
strcat(tmp_buf, "\n");
|
|
|
|
free(charptr_ret);
|
2003-11-28 18:07:29 +03:00
|
|
|
charptr_ret = &tmp_buf[0];
|
|
|
|
}
|
|
|
|
} else {
|
2009-11-02 17:56:26 +03:00
|
|
|
charptr_ret = fgets(tmp_buf, sizeof(tmp_buf), bx_infile_stack[bx_infile_stack_index].fp);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
#else /* !HAVE_LIBREADLINE */
|
|
|
|
else {
|
|
|
|
if (bx_infile_stack_index == 0)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s", prompt);
|
2009-11-02 17:56:26 +03:00
|
|
|
strncpy(tmp_buf_prev, tmp_buf, sizeof(tmp_buf));
|
|
|
|
charptr_ret = fgets(tmp_buf, sizeof(tmp_buf), bx_infile_stack[bx_infile_stack_index].fp);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (charptr_ret == NULL) {
|
|
|
|
// see if error was due to EOF condition
|
|
|
|
if (feof(bx_infile_stack[bx_infile_stack_index].fp)) {
|
|
|
|
if (bx_infile_stack_index > 0) {
|
|
|
|
// nested level of include files, pop back to previous one
|
|
|
|
bx_unnest_infile();
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
|
|
|
// not nested, sitting at stdin prompt, user wants out
|
|
|
|
bx_dbg_quit_command();
|
2006-04-29 13:27:49 +04:00
|
|
|
BX_PANIC(("bx_dbg_quit_command should not return, but it did"));
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// call recursively
|
|
|
|
bx_get_command();
|
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// error was not EOF, see if it was from a Ctrl-C
|
|
|
|
if (bx_guard.interrupt_requested) {
|
|
|
|
tmp_buf[0] = '\n';
|
|
|
|
tmp_buf[1] = 0;
|
|
|
|
tmp_buf_ptr = &tmp_buf[0];
|
|
|
|
bx_guard.interrupt_requested = 0;
|
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("fgets() returned ERROR.\n");
|
2011-08-11 23:40:51 +04:00
|
|
|
dbg_printf("debugger interrupt request was %u\n", bx_guard.interrupt_requested);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
tmp_buf_ptr = &tmp_buf[0];
|
|
|
|
|
|
|
|
if (debugger_log != NULL) {
|
|
|
|
fprintf(debugger_log, "%s", tmp_buf);
|
|
|
|
fflush(debugger_log);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// look for first non-whitespace character
|
2008-02-16 01:05:43 +03:00
|
|
|
while (((*tmp_buf_ptr == ' ') || (*tmp_buf_ptr == '\t')) &&
|
|
|
|
(*tmp_buf_ptr != '\n') && (*tmp_buf_ptr != 0))
|
2005-04-08 22:30:34 +04:00
|
|
|
{
|
2003-11-28 18:07:29 +03:00
|
|
|
tmp_buf_ptr++;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
int bx_nest_infile(char *path)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
FILE *tmp_fp;
|
|
|
|
|
|
|
|
tmp_fp = fopen(path, "r");
|
|
|
|
if (!tmp_fp) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: can not open file '%s' for reading.\n", argv0, path);
|
2003-11-28 18:07:29 +03:00
|
|
|
return(0);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
if ((bx_infile_stack_index+1) >= BX_INFILE_DEPTH) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: source files nested too deeply\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
return(0);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_infile_stack_index++;
|
|
|
|
bx_infile_stack[bx_infile_stack_index].fp = tmp_fp;
|
|
|
|
strncpy(bx_infile_stack[bx_infile_stack_index].fname, path, BX_MAX_PATH);
|
|
|
|
bx_infile_stack[bx_infile_stack_index].fname[BX_MAX_PATH-1] = 0;
|
|
|
|
bx_infile_stack[bx_infile_stack_index].lineno = 0;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_unnest_infile(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (bx_infile_stack_index <= 0) {
|
2009-11-02 17:56:26 +03:00
|
|
|
dbg_printf("%s: ERROR: unnest_infile(): nesting level = 0\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
fclose(bx_infile_stack[bx_infile_stack_index].fp);
|
|
|
|
bx_infile_stack_index--;
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
int bxwrap(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-11-02 17:56:26 +03:00
|
|
|
dbg_printf("%s: ERROR: bxwrap() called\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
|
|
|
return(0); // keep compiler quiet
|
|
|
|
}
|
|
|
|
|
2008-10-07 11:47:56 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
char* bxtext;
|
|
|
|
#endif
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bxerror(char *s)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-11-02 17:56:26 +03:00
|
|
|
dbg_printf("%s:%d: %s at '%s'\n", bx_infile_stack[bx_infile_stack_index].fname,
|
|
|
|
bx_infile_stack[bx_infile_stack_index].lineno, s, bxtext);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (bx_infile_stack_index > 0) {
|
2009-11-02 17:56:26 +03:00
|
|
|
dbg_printf("%s: ERROR in source file causes exit\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2009-04-14 13:45:22 +04:00
|
|
|
void CDECL bx_debug_ctrlc_handler(int signum)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
UNUSED(signum);
|
2006-11-12 13:07:18 +03:00
|
|
|
if (SIM->has_debug_gui()) {
|
2003-11-28 18:07:29 +03:00
|
|
|
// in a multithreaded environment, a signal such as SIGINT can be sent to all
|
|
|
|
// threads. This function is only intended to handle signals in the
|
|
|
|
// simulator thread. It will simply return if called from any other thread.
|
|
|
|
// Otherwise the BX_PANIC() below can be called in multiple threads at
|
|
|
|
// once, leading to multiple threads trying to display a dialog box,
|
|
|
|
// leading to GUI deadlock.
|
2006-04-29 13:27:49 +04:00
|
|
|
if (!SIM->is_sim_thread()) {
|
2006-06-09 16:26:34 +04:00
|
|
|
BX_INFO(("bx_signal_handler: ignored sig %d because it wasn't called from the simulator thread", signum));
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BX_INFO(("Ctrl-C detected in signal handler."));
|
|
|
|
|
|
|
|
signal(SIGINT, bx_debug_ctrlc_handler);
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_debug_break();
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-04-29 11:12:13 +04:00
|
|
|
void bx_debug_break()
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
bx_guard.interrupt_requested = 1;
|
|
|
|
}
|
|
|
|
|
2006-06-22 23:53:58 +04:00
|
|
|
void bx_dbg_exception(unsigned cpu, Bit8u vector, Bit16u error_code)
|
|
|
|
{
|
2008-04-16 20:42:00 +04:00
|
|
|
static const char *exception[] = {
|
2008-04-17 02:28:07 +04:00
|
|
|
"(#DE) divide by zero",
|
2008-04-16 20:42:00 +04:00
|
|
|
"(#DB) debug break",
|
|
|
|
"(#NMI)",
|
|
|
|
"(#BP) breakpoint match",
|
|
|
|
"(#OF) overflow",
|
|
|
|
"(#BR) boundary check",
|
|
|
|
"(#UD) undefined opcode",
|
|
|
|
"(#NM) device not available",
|
|
|
|
"(#DF) double fault",
|
|
|
|
"(#CO) coprocessor overrun",
|
|
|
|
"(#TS) invalid TSS",
|
|
|
|
"(#NP) segment not present",
|
|
|
|
"(#SS) stack fault",
|
|
|
|
"(#GP) general protection fault",
|
2008-04-17 01:49:46 +04:00
|
|
|
"(#PF) page fault",
|
2008-04-16 20:42:00 +04:00
|
|
|
"(#RESERVED)",
|
|
|
|
"(#MF) floating point error",
|
|
|
|
"(#AC) alignment check",
|
|
|
|
"(#MC) machine check",
|
2008-05-04 01:32:02 +04:00
|
|
|
"(#XF) SIMD floating point exception",
|
2008-04-16 20:42:00 +04:00
|
|
|
};
|
|
|
|
|
2006-06-22 23:53:58 +04:00
|
|
|
if (BX_CPU(dbg_cpu)->trace || bx_dbg.exceptions)
|
|
|
|
{
|
2008-04-16 20:42:00 +04:00
|
|
|
if (vector <= BX_XM_EXCEPTION) {
|
|
|
|
dbg_printf("CPU %d: Exception 0x%02x - %s occured (error_code=0x%04x)\n",
|
|
|
|
cpu, vector, exception[vector], error_code);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("CPU %d: Exception 0x%02x occured (error_code=0x%04x)\n",
|
|
|
|
cpu, vector, error_code);
|
|
|
|
}
|
2006-06-22 23:53:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_interrupt(unsigned cpu, Bit8u vector, Bit16u error_code)
|
|
|
|
{
|
|
|
|
if (BX_CPU(dbg_cpu)->trace || bx_dbg.interrupts)
|
|
|
|
{
|
2008-02-06 01:33:35 +03:00
|
|
|
dbg_printf("CPU %d: Interrupt 0x%02x occured (error_code=0x%04x)\n",
|
2006-06-22 23:53:58 +04:00
|
|
|
cpu, vector, error_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-24 00:39:01 +03:00
|
|
|
void bx_dbg_halt(unsigned cpu)
|
|
|
|
{
|
2008-06-13 01:00:25 +04:00
|
|
|
if (BX_CPU(dbg_cpu)->trace)
|
|
|
|
{
|
|
|
|
dbg_printf("CPU %d: HALTED\n", cpu);
|
|
|
|
}
|
2008-03-24 00:39:01 +03:00
|
|
|
}
|
|
|
|
|
2009-11-20 15:02:57 +03:00
|
|
|
void bx_dbg_watchpoint_continue(bx_bool watch_continue)
|
|
|
|
{
|
|
|
|
watchpoint_continue = watch_continue;
|
|
|
|
if (watchpoint_continue) {
|
|
|
|
dbg_printf("Will stop on watch points\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("Will not stop on watch points (they will still be logged)\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-08 01:09:30 +04:00
|
|
|
void bx_dbg_check_memory_watchpoints(unsigned cpu, bx_phy_address phy, unsigned len, unsigned rw)
|
2008-06-01 00:59:38 +04:00
|
|
|
{
|
2009-11-20 15:02:57 +03:00
|
|
|
bx_phy_address phy_end = phy + len - 1;
|
|
|
|
|
2008-12-06 01:34:42 +03:00
|
|
|
if (rw & 1) {
|
2008-10-08 21:13:35 +04:00
|
|
|
// Check for physical write watch points
|
|
|
|
for (unsigned i = 0; i < num_write_watchpoints; i++) {
|
2009-11-20 15:02:57 +03:00
|
|
|
bx_phy_address watch_end = write_watchpoint[i].addr + write_watchpoint[i].len - 1;
|
|
|
|
if (watch_end < phy || phy_end < write_watchpoint[i].addr) continue;
|
|
|
|
BX_CPU(cpu)->watchpoint = phy;
|
|
|
|
BX_CPU(cpu)->break_point = BREAK_POINT_WRITE;
|
|
|
|
break;
|
2008-10-08 21:13:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Check for physical read watch points
|
|
|
|
for (unsigned i = 0; i < num_read_watchpoints; i++) {
|
2009-11-20 15:02:57 +03:00
|
|
|
bx_phy_address watch_end = read_watchpoint[i].addr + read_watchpoint[i].len - 1;
|
|
|
|
if (watch_end < phy || phy_end < read_watchpoint[i].addr) continue;
|
|
|
|
BX_CPU(cpu)->watchpoint = phy;
|
|
|
|
BX_CPU(cpu)->break_point = BREAK_POINT_READ;
|
|
|
|
break;
|
2008-06-01 00:59:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-19 17:21:23 +04:00
|
|
|
void bx_dbg_lin_memory_access(unsigned cpu, bx_address lin, bx_phy_address phy, unsigned len, unsigned pl, unsigned rw, Bit8u *data)
|
|
|
|
{
|
2008-08-08 01:09:30 +04:00
|
|
|
bx_dbg_check_memory_watchpoints(cpu, phy, len, rw);
|
2008-06-01 00:59:38 +04:00
|
|
|
|
|
|
|
if (! BX_CPU(cpu)->trace_mem)
|
2008-04-19 17:21:23 +04:00
|
|
|
return;
|
|
|
|
|
2008-12-06 01:34:42 +03:00
|
|
|
bx_bool write = rw & 1;
|
|
|
|
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("[CPU%d %s]: LIN 0x" FMT_ADDRX " PHY 0x" FMT_PHY_ADDRX " (len=%d, pl=%d)",
|
2008-04-19 17:21:23 +04:00
|
|
|
cpu,
|
2008-12-06 01:34:42 +03:00
|
|
|
(write) ? "WR" : "RD",
|
2008-04-19 17:21:23 +04:00
|
|
|
lin, phy,
|
|
|
|
len, pl);
|
|
|
|
|
|
|
|
if (len == 1) {
|
2008-04-20 00:01:09 +04:00
|
|
|
Bit8u val8 = *data;
|
|
|
|
dbg_printf(": 0x%02X", (unsigned) val8);
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
else if (len == 2) {
|
2008-04-20 00:01:09 +04:00
|
|
|
Bit16u val16 = *((Bit16u*) data);
|
|
|
|
dbg_printf(": 0x%04X", (unsigned) val16);
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
else if (len == 4) {
|
2008-04-20 00:01:09 +04:00
|
|
|
Bit32u val32 = *((Bit32u*) data);
|
|
|
|
dbg_printf(": 0x%08X", (unsigned) val32);
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
else if (len == 8) {
|
|
|
|
Bit64u data64 = * (Bit64u*)(data);
|
|
|
|
dbg_printf(": 0x%08X 0x%08X", GET32H(data64), GET32L(data64));
|
|
|
|
}
|
2008-12-08 23:20:30 +03:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2008-07-26 18:20:24 +04:00
|
|
|
else if (len == 16) {
|
|
|
|
const BxPackedXmmRegister *xmmdata = (const BxPackedXmmRegister*)(data);
|
|
|
|
dbg_printf(": 0x%08X 0x%08X 0x%08X 0x%08X",
|
|
|
|
xmmdata->xmm32u(3), xmmdata->xmm32u(2), xmmdata->xmm32u(1), xmmdata->xmm32u(0));
|
|
|
|
}
|
2011-03-19 23:09:34 +03:00
|
|
|
#if BX_SUPPORT_AVX
|
|
|
|
else if (len == 32) {
|
|
|
|
const BxPackedAvxRegister *xmmdata = (const BxPackedAvxRegister*)(data);
|
|
|
|
dbg_printf(": 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X",
|
|
|
|
xmmdata->avx32u(7), xmmdata->avx32u(6), xmmdata->avx32u(5), xmmdata->avx32u(4),
|
|
|
|
xmmdata->avx32u(3), xmmdata->avx32u(2), xmmdata->avx32u(1), xmmdata->avx32u(0));
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-08 23:20:30 +03:00
|
|
|
#endif
|
2011-02-24 22:50:24 +03:00
|
|
|
else {
|
|
|
|
for (int i=len-1;i >= 0;i--) {
|
|
|
|
dbg_printf(" %02x", data[i]);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 17:21:23 +04:00
|
|
|
|
|
|
|
dbg_printf("\n");
|
|
|
|
}
|
|
|
|
|
2012-01-18 02:02:19 +04:00
|
|
|
void bx_dbg_phy_memory_access(unsigned cpu, bx_phy_address phy, unsigned len, unsigned rw, unsigned access, Bit8u *data)
|
2008-04-19 17:21:23 +04:00
|
|
|
{
|
2008-08-08 01:09:30 +04:00
|
|
|
bx_dbg_check_memory_watchpoints(cpu, phy, len, rw);
|
2008-06-01 00:59:38 +04:00
|
|
|
|
|
|
|
if (! BX_CPU(cpu)->trace_mem)
|
2008-04-19 17:21:23 +04:00
|
|
|
return;
|
|
|
|
|
2010-04-13 21:56:50 +04:00
|
|
|
static const char *access_string[] = {
|
|
|
|
"",
|
|
|
|
"PDPTR0",
|
|
|
|
"PDPTR1",
|
|
|
|
"PDPTR2",
|
|
|
|
"PDPTR3",
|
|
|
|
"PTE",
|
|
|
|
"PDE",
|
|
|
|
"PDPTE",
|
|
|
|
"PML4E",
|
|
|
|
"EPT PTE",
|
|
|
|
"EPT PDE",
|
|
|
|
"EPT PDPTE",
|
|
|
|
"EPT PML4E",
|
|
|
|
"VMCS",
|
2011-12-26 02:09:31 +04:00
|
|
|
"MSR BITMAP",
|
|
|
|
"I/O BITMAP",
|
2010-04-13 21:56:50 +04:00
|
|
|
"VMX LDMSR",
|
|
|
|
"VMX STMSR",
|
2012-09-06 19:21:08 +04:00
|
|
|
"VAPIC",
|
2010-04-13 21:56:50 +04:00
|
|
|
"SMRAM"
|
|
|
|
};
|
|
|
|
|
2008-12-06 01:34:42 +03:00
|
|
|
bx_bool write = rw & 1;
|
|
|
|
|
2008-05-11 00:33:39 +04:00
|
|
|
dbg_printf("[CPU%d %s]: PHY 0x" FMT_PHY_ADDRX " (len=%d)",
|
2008-04-19 17:21:23 +04:00
|
|
|
cpu,
|
2008-12-06 01:34:42 +03:00
|
|
|
(write) ? "WR" : "RD",
|
2008-04-19 17:21:23 +04:00
|
|
|
phy,
|
|
|
|
len);
|
|
|
|
|
|
|
|
if (len == 1) {
|
2008-04-20 00:01:09 +04:00
|
|
|
Bit8u val8 = *data;
|
|
|
|
dbg_printf(": 0x%02X", (unsigned) val8);
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
else if (len == 2) {
|
2008-04-20 00:01:09 +04:00
|
|
|
Bit16u val16 = *((Bit16u*) data);
|
|
|
|
dbg_printf(": 0x%04X", (unsigned) val16);
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
else if (len == 4) {
|
2008-04-20 00:01:09 +04:00
|
|
|
Bit32u val32 = *((Bit32u*) data);
|
|
|
|
dbg_printf(": 0x%08X", (unsigned) val32);
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
else if (len == 8) {
|
|
|
|
Bit64u data64 = * (Bit64u*)(data);
|
|
|
|
dbg_printf(": 0x%08X 0x%08X", GET32H(data64), GET32L(data64));
|
|
|
|
}
|
2008-12-08 23:20:30 +03:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2008-07-26 18:20:24 +04:00
|
|
|
else if (len == 16) {
|
|
|
|
const BxPackedXmmRegister *xmmdata = (const BxPackedXmmRegister*)(data);
|
|
|
|
dbg_printf(": 0x%08X 0x%08X 0x%08X 0x%08X",
|
|
|
|
xmmdata->xmm32u(3), xmmdata->xmm32u(2), xmmdata->xmm32u(1), xmmdata->xmm32u(0));
|
|
|
|
}
|
2011-03-19 23:09:34 +03:00
|
|
|
#if BX_SUPPORT_AVX
|
|
|
|
else if (len == 32) {
|
|
|
|
const BxPackedAvxRegister *xmmdata = (const BxPackedAvxRegister*)(data);
|
|
|
|
dbg_printf(": 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X",
|
|
|
|
xmmdata->avx32u(7), xmmdata->avx32u(6), xmmdata->avx32u(5), xmmdata->avx32u(4),
|
|
|
|
xmmdata->avx32u(3), xmmdata->avx32u(2), xmmdata->avx32u(1), xmmdata->avx32u(0));
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-08 23:20:30 +03:00
|
|
|
#endif
|
2011-02-24 22:50:24 +03:00
|
|
|
else {
|
|
|
|
for (int i=len-1;i >= 0;i--) {
|
|
|
|
dbg_printf(" %02x", data[i]);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 17:21:23 +04:00
|
|
|
|
2010-04-13 21:56:50 +04:00
|
|
|
if (access != 0)
|
|
|
|
dbg_printf("\t; %s\n", access_string[access]);
|
|
|
|
else
|
|
|
|
dbg_printf("\n");
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_exit(int code)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2008-02-15 22:03:54 +03:00
|
|
|
BX_DEBUG(("dbg: before exit"));
|
2003-11-28 18:07:29 +03:00
|
|
|
for (int cpu=0; cpu < BX_SMP_PROCESSORS; cpu++) {
|
|
|
|
if (BX_CPU(cpu)) BX_CPU(cpu)->atexit();
|
|
|
|
}
|
|
|
|
|
|
|
|
bx_atexit();
|
|
|
|
BX_EXIT(code);
|
|
|
|
}
|
|
|
|
|
2007-10-11 22:12:00 +04:00
|
|
|
//
|
|
|
|
// functions for browsing of cpu state
|
|
|
|
//
|
|
|
|
|
2011-03-19 23:09:34 +03:00
|
|
|
void bx_dbg_print_mxcsr_state(void)
|
|
|
|
{
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
Bit32u mxcsr = SIM->get_param_num("SSE.mxcsr", dbg_cpu_list)->get();
|
2011-10-07 00:33:10 +04:00
|
|
|
|
|
|
|
static const char* round_control[] = {
|
|
|
|
"Nearest", "Down", "Up", "Chop"
|
|
|
|
};
|
|
|
|
|
|
|
|
dbg_printf("MXCSR: 0x%05x: %s %s RC:%s %s %s %s %s %s %s %s %s %s %s %s %s %s\n", mxcsr,
|
2011-03-19 23:09:34 +03:00
|
|
|
(mxcsr & (1<<17)) ? "ULE" : "ule",
|
|
|
|
(mxcsr & (1<<15)) ? "FUZ" : "fuz",
|
2011-10-07 00:33:10 +04:00
|
|
|
round_control[(mxcsr >> 13) & 3],
|
2011-03-19 23:09:34 +03:00
|
|
|
(mxcsr & (1<<12)) ? "PM" : "pm",
|
|
|
|
(mxcsr & (1<<11)) ? "UM" : "um",
|
|
|
|
(mxcsr & (1<<10)) ? "OM" : "om",
|
|
|
|
(mxcsr & (1<<9)) ? "ZM" : "zm",
|
|
|
|
(mxcsr & (1<<8)) ? "DM" : "dm",
|
|
|
|
(mxcsr & (1<<7)) ? "IM" : "im",
|
|
|
|
(mxcsr & (1<<6)) ? "DAZ" : "daz",
|
|
|
|
(mxcsr & (1<<5)) ? "PE" : "pe",
|
|
|
|
(mxcsr & (1<<4)) ? "UE" : "ue",
|
|
|
|
(mxcsr & (1<<3)) ? "OE" : "oe",
|
|
|
|
(mxcsr & (1<<2)) ? "ZE" : "ze",
|
|
|
|
(mxcsr & (1<<1)) ? "DE" : "de",
|
|
|
|
(mxcsr & (1<<0)) ? "IE" : "ie");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-10-11 22:12:00 +04:00
|
|
|
void bx_dbg_print_sse_state(void)
|
|
|
|
{
|
2010-02-26 15:10:17 +03:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2011-11-01 17:24:42 +04:00
|
|
|
Bit64u isa_extensions_bitmask = SIM->get_param_num("isa_extensions_bitmask", dbg_cpu_list)->get();
|
2007-10-11 22:12:00 +04:00
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if ((isa_extensions_bitmask & BX_ISA_SSE) != 0) {
|
2011-03-19 23:09:34 +03:00
|
|
|
bx_dbg_print_mxcsr_state();
|
2010-02-26 01:04:31 +03:00
|
|
|
|
|
|
|
char param_name[20];
|
|
|
|
for(unsigned i=0;i<BX_XMM_REGISTERS;i++) {
|
2010-12-07 00:52:41 +03:00
|
|
|
sprintf(param_name, "SSE.xmm%02d_1", i);
|
2010-02-26 01:04:31 +03:00
|
|
|
Bit64u hi = SIM->get_param_num(param_name, dbg_cpu_list)->get64();
|
2010-12-07 00:52:41 +03:00
|
|
|
sprintf(param_name, "SSE.xmm%02d_0", i);
|
2010-02-26 01:04:31 +03:00
|
|
|
Bit64u lo = SIM->get_param_num(param_name, dbg_cpu_list)->get64();
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("XMM[%02u]: %08x_%08x_%08x_%08x\n", i,
|
2010-02-26 01:04:31 +03:00
|
|
|
GET32H(hi), GET32L(hi), GET32H(lo), GET32L(lo));
|
|
|
|
}
|
2007-10-11 22:12:00 +04:00
|
|
|
}
|
2010-02-26 15:10:17 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
dbg_printf("The CPU doesn't support SSE state !\n");
|
|
|
|
}
|
2007-10-11 22:12:00 +04:00
|
|
|
}
|
|
|
|
|
2011-03-19 23:09:34 +03:00
|
|
|
void bx_dbg_print_avx_state(unsigned vlen)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_AVX
|
2011-11-01 17:24:42 +04:00
|
|
|
Bit64u isa_extensions_bitmask = SIM->get_param_num("isa_extensions_bitmask", dbg_cpu_list)->get();
|
2011-03-19 23:09:34 +03:00
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if ((isa_extensions_bitmask & BX_ISA_AVX) != 0) {
|
2011-03-19 23:09:34 +03:00
|
|
|
bx_dbg_print_mxcsr_state();
|
|
|
|
|
|
|
|
char param_name[20];
|
|
|
|
|
|
|
|
for(unsigned i=0;i<BX_XMM_REGISTERS;i++) {
|
|
|
|
dbg_printf("VMM[%02u]: ", i);
|
|
|
|
for (int j=vlen;j >= 0; j--) {
|
|
|
|
sprintf(param_name, "SSE.xmm%02d_%d", i, j*2+1);
|
|
|
|
Bit64u hi = SIM->get_param_num(param_name, dbg_cpu_list)->get64();
|
|
|
|
sprintf(param_name, "SSE.xmm%02d_%d", i, j*2);
|
|
|
|
Bit64u lo = SIM->get_param_num(param_name, dbg_cpu_list)->get64();
|
|
|
|
if (j!=(int)vlen) dbg_printf("_");
|
|
|
|
dbg_printf("%08x_%08x_%08x_%08x", GET32H(hi), GET32L(hi), GET32H(lo), GET32L(lo));
|
|
|
|
}
|
|
|
|
dbg_printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
dbg_printf("The CPU doesn't support AVX state !\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-11 22:12:00 +04:00
|
|
|
void bx_dbg_print_mmx_state(void)
|
|
|
|
{
|
2010-03-01 21:53:53 +03:00
|
|
|
#if BX_CPU_LEVEL >= 5
|
2011-11-01 17:24:42 +04:00
|
|
|
Bit64u isa_extensions_bitmask = SIM->get_param_num("isa_extensions_bitmask", dbg_cpu_list)->get();
|
2010-03-01 21:53:53 +03:00
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if ((isa_extensions_bitmask & BX_ISA_MMX) != 0) {
|
2010-03-01 21:53:53 +03:00
|
|
|
char param_name[20];
|
|
|
|
for(unsigned i=0;i<8;i++) {
|
|
|
|
sprintf(param_name, "FPU.st%d.fraction", i);
|
|
|
|
Bit64u mmreg = SIM->get_param_num(param_name, dbg_cpu_list)->get64();
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("MM[%d]: %08x_%08x\n", i, GET32H(mmreg), GET32L(mmreg));
|
2010-03-01 21:53:53 +03:00
|
|
|
}
|
2007-10-11 22:12:00 +04:00
|
|
|
}
|
2010-03-01 21:53:53 +03:00
|
|
|
else
|
2007-10-11 22:12:00 +04:00
|
|
|
#endif
|
2010-03-01 21:53:53 +03:00
|
|
|
{
|
|
|
|
dbg_printf("The CPU doesn't support MMX state !\n");
|
|
|
|
}
|
2007-10-11 22:12:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_print_fpu_state(void)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
BX_CPU(dbg_cpu)->print_state_FPU();
|
|
|
|
#else
|
2008-05-19 23:11:24 +04:00
|
|
|
dbg_printf("The CPU doesn't support FPU state !\n");
|
2007-10-11 22:12:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_info_flags(void)
|
|
|
|
{
|
2008-04-16 20:42:00 +04:00
|
|
|
dbg_printf("%s %s %s %s %s %s %s IOPL=%1u %s %s %s %s %s %s %s %s %s\n",
|
2007-10-11 22:12:00 +04:00
|
|
|
BX_CPU(dbg_cpu)->get_ID() ? "ID" : "id",
|
|
|
|
BX_CPU(dbg_cpu)->get_VIP() ? "VIP" : "vip",
|
|
|
|
BX_CPU(dbg_cpu)->get_VIF() ? "VIF" : "vif",
|
|
|
|
BX_CPU(dbg_cpu)->get_AC() ? "AC" : "ac",
|
|
|
|
BX_CPU(dbg_cpu)->get_VM() ? "VM" : "vm",
|
|
|
|
BX_CPU(dbg_cpu)->get_RF() ? "RF" : "rf",
|
|
|
|
BX_CPU(dbg_cpu)->get_NT() ? "NT" : "nt",
|
2008-04-16 20:42:00 +04:00
|
|
|
BX_CPU(dbg_cpu)->get_IOPL(),
|
2007-10-11 22:12:00 +04:00
|
|
|
BX_CPU(dbg_cpu)->get_OF() ? "OF" : "of",
|
|
|
|
BX_CPU(dbg_cpu)->get_DF() ? "DF" : "df",
|
|
|
|
BX_CPU(dbg_cpu)->get_IF() ? "IF" : "if",
|
|
|
|
BX_CPU(dbg_cpu)->get_TF() ? "TF" : "tf",
|
|
|
|
BX_CPU(dbg_cpu)->get_SF() ? "SF" : "sf",
|
|
|
|
BX_CPU(dbg_cpu)->get_ZF() ? "ZF" : "zf",
|
|
|
|
BX_CPU(dbg_cpu)->get_AF() ? "AF" : "af",
|
|
|
|
BX_CPU(dbg_cpu)->get_PF() ? "PF" : "pf",
|
|
|
|
BX_CPU(dbg_cpu)->get_CF() ? "CF" : "cf");
|
|
|
|
}
|
|
|
|
|
2009-08-07 12:26:41 +04:00
|
|
|
void bx_dbg_info_debug_regs_command(void)
|
|
|
|
{
|
|
|
|
bx_address dr0 = SIM->get_param_num("DR0", dbg_cpu_list)->get();
|
|
|
|
bx_address dr1 = SIM->get_param_num("DR1", dbg_cpu_list)->get();
|
2009-09-30 21:26:08 +04:00
|
|
|
bx_address dr2 = SIM->get_param_num("DR2", dbg_cpu_list)->get();
|
|
|
|
bx_address dr3 = SIM->get_param_num("DR3", dbg_cpu_list)->get();
|
2009-08-07 12:26:41 +04:00
|
|
|
Bit32u dr6 = SIM->get_param_num("DR6", dbg_cpu_list)->get();
|
|
|
|
Bit32u dr7 = SIM->get_param_num("DR7", dbg_cpu_list)->get();
|
|
|
|
|
|
|
|
dbg_printf("DR0=0x" FMT_ADDRX "\n", dr0);
|
|
|
|
dbg_printf("DR1=0x" FMT_ADDRX "\n", dr1);
|
|
|
|
dbg_printf("DR2=0x" FMT_ADDRX "\n", dr2);
|
|
|
|
dbg_printf("DR3=0x" FMT_ADDRX "\n", dr3);
|
2009-10-14 18:56:01 +04:00
|
|
|
|
2009-10-14 20:05:44 +04:00
|
|
|
static const char *dr_ln[4] = { "Byte", "Word", "QWord", "Dword" };
|
|
|
|
static const char *dr_rw[4] = { "Code", "DataW", "I/O", "DataRW" };
|
|
|
|
|
2009-10-14 18:56:01 +04:00
|
|
|
dbg_printf("DR6=0x%08x: %s %s %s %s %s %s %s\n", dr6,
|
|
|
|
(dr6 & (1<<15)) ? "BT" : "bt",
|
|
|
|
(dr6 & (1<<14)) ? "BS" : "bs",
|
|
|
|
(dr6 & (1<<13)) ? "BD" : "bd",
|
|
|
|
(dr6 & (1<<3)) ? "B3" : "b3",
|
|
|
|
(dr6 & (1<<2)) ? "B2" : "b2",
|
|
|
|
(dr6 & (1<<1)) ? "B1" : "b1",
|
|
|
|
(dr6 & (1<<0)) ? "B0" : "b0");
|
|
|
|
|
|
|
|
dbg_printf("DR7=0x%08x: DR3=%s-%s DR2=%s-%s DR1=%s-%s DR0=%s-%s %s | %s %s | %s %s %s %s %s %s %s %s\n", dr7,
|
|
|
|
dr_rw[(dr7 >> 28) & 3], dr_ln[(dr7 >> 30) & 3],
|
|
|
|
dr_rw[(dr7 >> 24) & 3], dr_ln[(dr7 >> 26) & 3],
|
|
|
|
dr_rw[(dr7 >> 20) & 3], dr_ln[(dr7 >> 22) & 3],
|
|
|
|
dr_rw[(dr7 >> 16) & 3], dr_ln[(dr7 >> 18) & 3],
|
|
|
|
(dr7 & (1<<13)) ? "GD" : "gd",
|
|
|
|
(dr7 & (1<<9)) ? "GE" : "ge",
|
|
|
|
(dr7 & (1<<8)) ? "LE" : "le",
|
|
|
|
(dr7 & (1<<7)) ? "G3" : "g3",
|
|
|
|
(dr7 & (1<<6)) ? "L3" : "l3",
|
|
|
|
(dr7 & (1<<5)) ? "G2" : "g2",
|
|
|
|
(dr7 & (1<<4)) ? "L2" : "l2",
|
|
|
|
(dr7 & (1<<3)) ? "G1" : "g1",
|
|
|
|
(dr7 & (1<<2)) ? "L1" : "l1",
|
|
|
|
(dr7 & (1<<1)) ? "G0" : "g0",
|
|
|
|
(dr7 & (1<<0)) ? "L0" : "l0");
|
2009-08-07 12:26:41 +04:00
|
|
|
}
|
|
|
|
|
2007-10-14 04:23:06 +04:00
|
|
|
void bx_dbg_info_control_regs_command(void)
|
|
|
|
{
|
2007-10-24 01:51:44 +04:00
|
|
|
Bit32u cr0 = SIM->get_param_num("CR0", dbg_cpu_list)->get();
|
2008-03-23 20:59:44 +03:00
|
|
|
bx_address cr2 = (bx_address) SIM->get_param_num("CR2", dbg_cpu_list)->get64();
|
2008-05-10 02:33:37 +04:00
|
|
|
bx_phy_address cr3 = (bx_phy_address) SIM->get_param_num("CR3", dbg_cpu_list)->get64();
|
2008-05-23 21:49:46 +04:00
|
|
|
dbg_printf("CR0=0x%08x: %s %s %s %s %s %s %s %s %s %s %s\n", cr0,
|
|
|
|
(cr0 & (1<<31)) ? "PG" : "pg",
|
|
|
|
(cr0 & (1<<30)) ? "CD" : "cd",
|
|
|
|
(cr0 & (1<<29)) ? "NW" : "nw",
|
|
|
|
(cr0 & (1<<18)) ? "AC" : "ac",
|
|
|
|
(cr0 & (1<<16)) ? "WP" : "wp",
|
|
|
|
(cr0 & (1<<5)) ? "NE" : "ne",
|
|
|
|
(cr0 & (1<<4)) ? "ET" : "et",
|
|
|
|
(cr0 & (1<<3)) ? "TS" : "ts",
|
|
|
|
(cr0 & (1<<2)) ? "EM" : "em",
|
|
|
|
(cr0 & (1<<1)) ? "MP" : "mp",
|
|
|
|
(cr0 & (1<<0)) ? "PE" : "pe");
|
|
|
|
dbg_printf("CR2=page fault laddr=0x" FMT_ADDRX "\n", cr2);
|
2008-05-11 00:33:39 +04:00
|
|
|
dbg_printf("CR3=0x" FMT_PHY_ADDRX "\n", cr3);
|
2007-10-14 04:23:06 +04:00
|
|
|
dbg_printf(" PCD=page-level cache disable=%d\n", (cr3>>4) & 1);
|
2009-09-25 14:07:26 +04:00
|
|
|
dbg_printf(" PWT=page-level write-through=%d\n", (cr3>>3) & 1);
|
2011-08-16 23:04:36 +04:00
|
|
|
#if BX_CPU_LEVEL >= 5
|
2007-10-24 01:51:44 +04:00
|
|
|
Bit32u cr4 = SIM->get_param_num("CR4", dbg_cpu_list)->get();
|
2012-09-10 19:22:26 +04:00
|
|
|
dbg_printf("CR4=0x%08x: %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n", cr4,
|
|
|
|
(cr4 & (1<<21)) ? "SMAP" : "smap",
|
2011-05-29 20:28:26 +04:00
|
|
|
(cr4 & (1<<20)) ? "SMEP" : "smep",
|
2009-01-19 00:25:49 +03:00
|
|
|
(cr4 & (1<<18)) ? "OSXSAVE" : "osxsave",
|
2010-03-31 18:00:46 +04:00
|
|
|
(cr4 & (1<<17)) ? "PCID" : "pcid",
|
2010-07-22 20:41:59 +04:00
|
|
|
(cr4 & (1<<16)) ? "FSGSBASE" : "fsgsbase",
|
2009-01-19 00:25:49 +03:00
|
|
|
(cr4 & (1<<14)) ? "SMX" : "smx",
|
|
|
|
(cr4 & (1<<13)) ? "VMX" : "vmx",
|
2008-05-23 21:49:46 +04:00
|
|
|
(cr4 & (1<<10)) ? "OSXMMEXCPT" : "osxmmexcpt",
|
|
|
|
(cr4 & (1<<9)) ? "OSFXSR" : "osfxsr",
|
|
|
|
(cr4 & (1<<8)) ? "PCE" : "pce",
|
|
|
|
(cr4 & (1<<7)) ? "PGE" : "pge",
|
|
|
|
(cr4 & (1<<6)) ? "MCE" : "mce",
|
|
|
|
(cr4 & (1<<5)) ? "PAE" : "pae",
|
|
|
|
(cr4 & (1<<4)) ? "PSE" : "pse",
|
|
|
|
(cr4 & (1<<3)) ? "DE" : "de",
|
|
|
|
(cr4 & (1<<2)) ? "TSD" : "tsd",
|
|
|
|
(cr4 & (1<<1)) ? "PVI" : "pvi",
|
|
|
|
(cr4 & (1<<0)) ? "VME" : "vme");
|
2012-06-28 22:27:26 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
Bit64u cpu_extensions_bitmask = SIM->get_param_num("cpu_extensions_bitmask", dbg_cpu_list)->get();
|
2012-06-28 22:34:28 +04:00
|
|
|
if ((cpu_extensions_bitmask & BX_CPU_LONG_MODE) != 0) {
|
|
|
|
dbg_printf("CR8: 0x%x\n", BX_CPU(dbg_cpu)->get_cr8());
|
2012-06-28 22:27:26 +04:00
|
|
|
}
|
|
|
|
#endif
|
2007-10-24 01:51:44 +04:00
|
|
|
Bit32u efer = SIM->get_param_num("MSR.EFER", dbg_cpu_list)->get();
|
2008-05-23 21:49:46 +04:00
|
|
|
dbg_printf("EFER=0x%08x: %s %s %s %s %s\n", efer,
|
|
|
|
(efer & (1<<14)) ? "FFXSR" : "ffxsr",
|
|
|
|
(efer & (1<<11)) ? "NXE" : "nxe",
|
|
|
|
(efer & (1<<10)) ? "LMA" : "lma",
|
|
|
|
(efer & (1<<8)) ? "LME" : "lme",
|
|
|
|
(efer & (1<<0)) ? "SCE" : "sce");
|
2007-10-14 04:23:06 +04:00
|
|
|
#endif
|
2011-10-09 01:58:17 +04:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2011-11-01 17:24:42 +04:00
|
|
|
Bit64u isa_extensions_bitmask = SIM->get_param_num("isa_extensions_bitmask", dbg_cpu_list)->get();
|
|
|
|
if ((isa_extensions_bitmask & BX_ISA_XSAVE) != 0) {
|
2011-11-18 16:56:33 +04:00
|
|
|
Bit32u xcr0 = SIM->get_param_num("XCR0", dbg_cpu_list)->get();
|
2011-11-01 17:24:42 +04:00
|
|
|
dbg_printf("XCR0=0x%08x: %s %s %s\n", xcr0,
|
|
|
|
(xcr0 & (1<<2)) ? "AVX" : "avx",
|
|
|
|
(xcr0 & (1<<1)) ? "SSE" : "sse",
|
|
|
|
(xcr0 & (1<<0)) ? "FPU" : "fpu");
|
|
|
|
}
|
2011-10-09 01:58:17 +04:00
|
|
|
#endif
|
2007-10-14 04:23:06 +04:00
|
|
|
}
|
|
|
|
|
2007-10-24 01:51:44 +04:00
|
|
|
void bx_dbg_info_segment_regs_command(void)
|
|
|
|
{
|
2009-10-02 14:16:04 +04:00
|
|
|
static const char *segname[] = { "es", "cs", "ss", "ds", "fs", "gs" };
|
|
|
|
|
2007-10-24 01:51:44 +04:00
|
|
|
bx_dbg_sreg_t sreg;
|
|
|
|
bx_dbg_global_sreg_t global_sreg;
|
|
|
|
|
2009-10-02 14:16:04 +04:00
|
|
|
for(int s=0;s<6;s++) {
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_sreg(&sreg, s);
|
|
|
|
dbg_printf("%s:0x%04x, dh=0x%08x, dl=0x%08x, valid=%u\n", segname[s],
|
|
|
|
(unsigned) sreg.sel, (unsigned) sreg.des_h,
|
|
|
|
(unsigned) sreg.des_l, (unsigned) sreg.valid);
|
|
|
|
if (sreg.valid) {
|
|
|
|
dbg_printf("\t");
|
|
|
|
bx_dbg_print_descriptor(sreg.des_l, sreg.des_h);
|
|
|
|
}
|
|
|
|
}
|
2007-10-24 01:51:44 +04:00
|
|
|
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_ldtr(&sreg);
|
2009-10-02 14:16:04 +04:00
|
|
|
dbg_printf("ldtr:0x%04x, dh=0x%08x, dl=0x%08x, valid=%u\n",
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) sreg.sel, (unsigned) sreg.des_h,
|
|
|
|
(unsigned) sreg.des_l, (unsigned) sreg.valid);
|
2007-10-24 01:51:44 +04:00
|
|
|
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_tr(&sreg);
|
2009-10-02 14:16:04 +04:00
|
|
|
dbg_printf("tr:0x%04x, dh=0x%08x, dl=0x%08x, valid=%u\n",
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) sreg.sel, (unsigned) sreg.des_h,
|
|
|
|
(unsigned) sreg.des_l, (unsigned) sreg.valid);
|
2007-10-24 01:51:44 +04:00
|
|
|
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_gdtr(&global_sreg);
|
2009-11-07 23:30:39 +03:00
|
|
|
dbg_printf("gdtr:base=0x"FMT_ADDRX", limit=0x%x\n",
|
|
|
|
global_sreg.base, (unsigned) global_sreg.limit);
|
2007-10-24 01:51:44 +04:00
|
|
|
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_idtr(&global_sreg);
|
2009-11-07 23:30:39 +03:00
|
|
|
dbg_printf("idtr:base=0x"FMT_ADDRX", limit=0x%x\n",
|
|
|
|
global_sreg.base, (unsigned) global_sreg.limit);
|
2007-10-24 01:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_info_registers_command(int which_regs_mask)
|
|
|
|
{
|
|
|
|
bx_address reg;
|
|
|
|
|
|
|
|
if (which_regs_mask & BX_INFO_GENERAL_PURPOSE_REGS) {
|
|
|
|
#if BX_SUPPORT_SMP
|
2009-03-27 16:20:23 +03:00
|
|
|
dbg_printf("CPU%d:\n", BX_CPU(dbg_cpu)->bx_cpuid);
|
2007-10-24 01:51:44 +04:00
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_X86_64 == 0
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EAX);
|
|
|
|
dbg_printf("eax: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_ECX);
|
|
|
|
dbg_printf("ecx: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EDX);
|
|
|
|
dbg_printf("edx: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EBX);
|
|
|
|
dbg_printf("ebx: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_ESP);
|
|
|
|
dbg_printf("esp: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EBP);
|
|
|
|
dbg_printf("ebp: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_ESI);
|
|
|
|
dbg_printf("esi: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EDI);
|
|
|
|
dbg_printf("edi: 0x%08x %d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = bx_dbg_get_eip();
|
|
|
|
dbg_printf("eip: 0x%08x\n", (unsigned) reg);
|
|
|
|
#else
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RAX);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rax: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RCX);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rcx: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RDX);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rdx: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RBX);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rbx: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RSP);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rsp: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RBP);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rbp: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RSI);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rsi: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RDI);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rdi: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R8);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r8 : 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R9);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r9 : 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R10);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r10: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R11);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r11: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R12);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r12: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R13);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r13: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R14);
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("r14: 0x%08x_%08x ", GET32H(reg), GET32L(reg));
|
2008-04-11 18:16:46 +04:00
|
|
|
reg = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_R15);
|
2011-03-19 23:09:34 +03:00
|
|
|
dbg_printf("r15: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2007-10-24 01:51:44 +04:00
|
|
|
reg = bx_dbg_get_instruction_pointer();
|
2011-03-19 20:19:41 +03:00
|
|
|
dbg_printf("rip: 0x%08x_%08x\n", GET32H(reg), GET32L(reg));
|
2007-10-24 01:51:44 +04:00
|
|
|
#endif
|
|
|
|
reg = BX_CPU(dbg_cpu)->read_eflags();
|
2009-10-29 18:49:50 +03:00
|
|
|
dbg_printf("eflags 0x%08x: ", (unsigned) reg);
|
2007-10-24 01:51:44 +04:00
|
|
|
bx_dbg_info_flags();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
if (which_regs_mask & BX_INFO_FPU_REGS) {
|
|
|
|
bx_dbg_print_fpu_state();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (which_regs_mask & BX_INFO_MMX_REGS) {
|
|
|
|
bx_dbg_print_mmx_state();
|
|
|
|
}
|
|
|
|
|
2011-03-19 23:09:34 +03:00
|
|
|
if (which_regs_mask & BX_INFO_AVX_REGS) {
|
|
|
|
bx_dbg_print_avx_state(BX_VLMAX-1);
|
|
|
|
}
|
|
|
|
else if (which_regs_mask & BX_INFO_SSE_REGS) {
|
2007-10-24 01:51:44 +04:00
|
|
|
bx_dbg_print_sse_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
//
|
2006-01-15 20:55:25 +03:00
|
|
|
// commands invoked from parser
|
2003-11-28 18:07:29 +03:00
|
|
|
//
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_quit_command(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
BX_INFO(("dbg: Quit"));
|
|
|
|
bx_dbg_exit(0);
|
|
|
|
}
|
|
|
|
|
2006-01-31 22:45:34 +03:00
|
|
|
void bx_dbg_trace_command(bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-01-31 22:45:34 +03:00
|
|
|
BX_CPU(dbg_cpu)->trace = enable;
|
2009-02-21 02:01:09 +03:00
|
|
|
dbg_printf("Tracing %s for CPU%d\n", enable ? "enabled" : "disabled",
|
|
|
|
BX_CPU(dbg_cpu)->which_cpu());
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-01-31 22:45:34 +03:00
|
|
|
void bx_dbg_trace_reg_command(bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-01-31 22:45:34 +03:00
|
|
|
BX_CPU(dbg_cpu)->trace_reg = enable;
|
2009-02-21 02:01:09 +03:00
|
|
|
dbg_printf("Register-Tracing %s for CPU%d\n", enable ? "enabled" : "disabled",
|
|
|
|
BX_CPU(dbg_cpu)->which_cpu());
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 17:21:23 +04:00
|
|
|
void bx_dbg_trace_mem_command(bx_bool enable)
|
|
|
|
{
|
|
|
|
BX_CPU(dbg_cpu)->trace_mem = enable;
|
2009-02-21 02:01:09 +03:00
|
|
|
dbg_printf("Memory-Tracing %s for CPU%d\n", enable ? "enabled" : "disabled",
|
|
|
|
BX_CPU(dbg_cpu)->which_cpu());
|
2008-04-19 17:21:23 +04:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_ptime_command(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("ptime: " FMT_LL "d\n", bx_pc_system.time_ticks());
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int timebp_timer = -1;
|
|
|
|
Bit64u timebp_queue[MAX_CONCURRENT_BPS];
|
|
|
|
int timebp_queue_size = 0;
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_timebp_command(bx_bool absolute, Bit64u time)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
Bit64u abs_time = (absolute) ? time : time + bx_pc_system.time_ticks();
|
|
|
|
|
2011-11-21 16:50:37 +04:00
|
|
|
if (abs_time <= bx_pc_system.time_ticks()) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Request for time break point in the past. I can't let you do that.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timebp_queue_size == MAX_CONCURRENT_BPS) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Too many time break points\n");
|
2005-03-26 22:41:59 +03:00
|
|
|
return;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2007-01-04 23:12:32 +03:00
|
|
|
|
|
|
|
Bit64u diff = (absolute) ? time - bx_pc_system.time_ticks() : time;
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
if (timebp_timer >= 0) {
|
2006-02-05 22:48:29 +03:00
|
|
|
if (timebp_queue_size == 0 || abs_time < timebp_queue[0]) {
|
|
|
|
/* first in queue */
|
|
|
|
for (int i = timebp_queue_size; i >= 0; i--)
|
2007-01-04 23:12:32 +03:00
|
|
|
timebp_queue[i+1] = timebp_queue[i];
|
2006-02-05 22:48:29 +03:00
|
|
|
timebp_queue[0] = abs_time;
|
|
|
|
timebp_queue_size++;
|
|
|
|
bx_pc_system.activate_timer_ticks(timebp_timer, diff, 1);
|
|
|
|
} else {
|
|
|
|
/* not first, insert at suitable place */
|
|
|
|
for (int i = 1; i < timebp_queue_size; i++) {
|
|
|
|
if (timebp_queue[i] == abs_time) {
|
|
|
|
dbg_printf("Time breakpoint not inserted (duplicate)\n");
|
|
|
|
return;
|
|
|
|
} else if (abs_time < timebp_queue[i]) {
|
2008-04-20 13:20:56 +04:00
|
|
|
for (int j = timebp_queue_size; j >= i; j--)
|
2006-06-11 20:40:37 +04:00
|
|
|
timebp_queue[j+1] = timebp_queue[j];
|
2006-02-05 22:48:29 +03:00
|
|
|
timebp_queue[i] = abs_time;
|
|
|
|
goto inserted;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2006-02-05 22:48:29 +03:00
|
|
|
/* last */
|
|
|
|
timebp_queue[timebp_queue_size] = abs_time;
|
2003-11-28 18:07:29 +03:00
|
|
|
inserted:
|
2006-02-05 22:48:29 +03:00
|
|
|
timebp_queue_size++;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
} else {
|
2005-03-26 22:41:59 +03:00
|
|
|
timebp_queue_size = 1;
|
|
|
|
timebp_queue[0] = abs_time;
|
|
|
|
timebp_timer = bx_pc_system.register_timer_ticks(&bx_pc_system, bx_pc_system_c::timebp_handler, diff, 0, 1, "debug.timebp");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Time breakpoint inserted. Delta = " FMT_LL "u\n", diff);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
Bit32u conv_4xBit8u_to_Bit32u(const Bit8u* buf)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
Bit32u ret = 0;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
ret |= (buf[i] << (8 * i));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-09 23:28:07 +03:00
|
|
|
Bit16u conv_2xBit8u_to_Bit16u(const Bit8u* buf)
|
|
|
|
{
|
|
|
|
Bit16u ret = 0;
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
ret |= (buf[i] << (8 * i));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-02-01 21:12:08 +03:00
|
|
|
// toggles mode switch breakpoint
|
2006-01-24 00:44:44 +03:00
|
|
|
void bx_dbg_modebp_command()
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
BX_CPU(dbg_cpu)->mode_break = !BX_CPU(dbg_cpu)->mode_break;
|
2008-04-07 23:59:53 +04:00
|
|
|
dbg_printf("mode switch break %s\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
BX_CPU(dbg_cpu)->mode_break ? "enabled" : "disabled");
|
|
|
|
}
|
|
|
|
|
2011-05-06 12:19:03 +04:00
|
|
|
// toggles vmexit switch breakpoint
|
|
|
|
void bx_dbg_vmexitbp_command()
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
BX_CPU(dbg_cpu)->vmexit_break = !BX_CPU(dbg_cpu)->vmexit_break;
|
|
|
|
dbg_printf("vmexit switch break %s\n",
|
|
|
|
BX_CPU(dbg_cpu)->vmexit_break ? "enabled" : "disabled");
|
|
|
|
#else
|
|
|
|
dbg_printf("VMX is not compiled in, cannot set vmexit breakpoint !");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-08-07 12:26:41 +04:00
|
|
|
bx_bool bx_dbg_read_linear(unsigned which_cpu, bx_address laddr, unsigned len, Bit8u *buf)
|
2006-02-03 01:33:32 +03:00
|
|
|
{
|
|
|
|
unsigned remainsInPage;
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_phy_address paddr;
|
2006-02-03 01:33:32 +03:00
|
|
|
unsigned read_len;
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_bool paddr_valid;
|
2006-02-03 01:33:32 +03:00
|
|
|
|
|
|
|
next_page:
|
2008-04-20 00:01:09 +04:00
|
|
|
remainsInPage = 0x1000 - PAGE_OFFSET(laddr);
|
2006-02-03 01:33:32 +03:00
|
|
|
read_len = (remainsInPage < len) ? remainsInPage : len;
|
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
paddr_valid = BX_CPU(which_cpu)->dbg_xlate_linear2phy(laddr, &paddr);
|
2006-02-03 01:33:32 +03:00
|
|
|
if (paddr_valid) {
|
2006-10-02 21:40:20 +04:00
|
|
|
if (! BX_MEM(0)->dbg_fetch_mem(BX_CPU(which_cpu), paddr, read_len, buf)) {
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("bx_dbg_read_linear: physical memory read error (phy=0x" FMT_PHY_ADDRX ", lin=0x" FMT_ADDRX ")\n", paddr, laddr);
|
2006-02-03 01:33:32 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-09-24 01:10:06 +04:00
|
|
|
dbg_printf("bx_dbg_read_linear: physical address not available for linear 0x" FMT_ADDRX "\n", laddr);
|
2006-02-03 01:33:32 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for access across multiple pages */
|
|
|
|
if (remainsInPage < len)
|
|
|
|
{
|
|
|
|
laddr += read_len;
|
|
|
|
len -= read_len;
|
|
|
|
buf += read_len;
|
|
|
|
goto next_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
// where
|
|
|
|
// stack trace: ebp -> old ebp
|
|
|
|
// return eip at ebp + 4
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_where_command()
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (!BX_CPU(dbg_cpu)->protected_mode()) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("'where' only supported in protected mode\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
if (BX_CPU(dbg_cpu)->get_segment_base(BX_SEG_REG_SS) != 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("non-zero stack base\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2005-11-27 21:25:57 +03:00
|
|
|
Bit32u bp = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_EBP);
|
2009-04-07 20:12:19 +04:00
|
|
|
bx_address ip = BX_CPU(dbg_cpu)->get_instruction_pointer();
|
2009-06-01 18:50:19 +04:00
|
|
|
dbg_printf("(%d) 0x%08x\n", dbg_cpu, ip);
|
2003-11-28 18:07:29 +03:00
|
|
|
for (int i = 1; i < 50; i++) {
|
|
|
|
// Up
|
2007-10-09 23:49:23 +04:00
|
|
|
bx_phy_address paddr;
|
2003-11-28 18:07:29 +03:00
|
|
|
Bit8u buf[4];
|
|
|
|
|
|
|
|
// bp = [bp];
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_bool paddr_valid = BX_CPU(dbg_cpu)->dbg_xlate_linear2phy(bp, &paddr);
|
2003-11-28 18:07:29 +03:00
|
|
|
if (paddr_valid) {
|
2006-10-02 21:40:20 +04:00
|
|
|
if (BX_MEM(0)->dbg_fetch_mem(BX_CPU(dbg_cpu), paddr, 4, buf)) {
|
2003-11-28 18:07:29 +03:00
|
|
|
bp = conv_4xBit8u_to_Bit32u(buf);
|
|
|
|
} else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%d) Physical memory read error (BP)\n", i);
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%d) Could not translate linear address (BP)\n", i);
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ip = [bp + 4];
|
2006-06-17 16:09:55 +04:00
|
|
|
paddr_valid = BX_CPU(dbg_cpu)->dbg_xlate_linear2phy(bp + 4, &paddr);
|
2003-11-28 18:07:29 +03:00
|
|
|
if (paddr_valid) {
|
2006-10-02 21:40:20 +04:00
|
|
|
if (BX_MEM(0)->dbg_fetch_mem(BX_CPU(dbg_cpu), paddr, 4, buf)) {
|
2003-11-28 18:07:29 +03:00
|
|
|
ip = conv_4xBit8u_to_Bit32u(buf);
|
|
|
|
} else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%d) Physical memory read error (IP)\n", i);
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%d) Could not translate linear address (IP)\n", i);
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%d) 0x%08x\n", i, ip);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
void bx_dbg_print_string_command(bx_address start_addr)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("0x%08x: ", start_addr);
|
2003-11-28 18:07:29 +03:00
|
|
|
for (int i = 0; ; i++) {
|
2006-02-03 01:33:32 +03:00
|
|
|
Bit8u buf = 0;
|
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, start_addr+i, 1, &buf)) break;
|
|
|
|
if (buf == 0) break;
|
|
|
|
if (isgraph(buf) || buf == 0x20)
|
|
|
|
dbg_printf("%c", buf);
|
|
|
|
else
|
|
|
|
dbg_printf("\\%d", buf);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-13 21:28:14 +03:00
|
|
|
static void dbg_print_guard_found(unsigned cpu_mode, Bit32u cs, bx_address eip, bx_address laddr)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (cpu_mode == BX_MODE_LONG_64) {
|
|
|
|
dbg_printf("0x%04x:" FMT_ADDRX " (0x" FMT_ADDRX ")", cs, eip, laddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (cpu_mode >= BX_MODE_IA32_PROTECTED)
|
|
|
|
dbg_printf("%04x:%08x (0x%08x)", cs, (unsigned) eip, (unsigned) laddr);
|
|
|
|
else // real or v8086 mode
|
|
|
|
dbg_printf("%04x:%04x (0x%08x)", cs, (unsigned) eip, (unsigned) laddr);
|
|
|
|
}
|
|
|
|
|
2007-09-24 01:10:06 +04:00
|
|
|
void bx_dbg_xlate_address(bx_lin_address laddr)
|
|
|
|
{
|
|
|
|
bx_phy_address paddr;
|
|
|
|
laddr &= BX_CONST64(0xfffffffffffff000);
|
|
|
|
|
2010-05-05 00:17:26 +04:00
|
|
|
bx_bool paddr_valid = BX_CPU(dbg_cpu)->dbg_xlate_linear2phy(laddr, &paddr, 1);
|
2007-09-24 01:10:06 +04:00
|
|
|
if (paddr_valid) {
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("linear page 0x" FMT_ADDRX " maps to physical page 0x" FMT_PHY_ADDRX "\n", laddr, paddr);
|
2007-09-24 01:10:06 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("physical address not available for linear 0x" FMT_ADDRX "\n", laddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-12 23:21:36 +03:00
|
|
|
unsigned dbg_show_mask = 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-12 23:21:36 +03:00
|
|
|
#define BX_DBG_SHOW_CALLRET (Flag_call|Flag_ret)
|
2006-02-12 23:43:01 +03:00
|
|
|
#define BX_DBG_SHOW_SOFTINT (Flag_softint)
|
|
|
|
#define BX_DBG_SHOW_EXTINT (Flag_intsig)
|
|
|
|
#define BX_DBG_SHOW_IRET (Flag_iret)
|
2006-02-12 23:21:36 +03:00
|
|
|
#define BX_DBG_SHOW_INT (Flag_softint|Flag_iret|Flag_intsig)
|
|
|
|
#define BX_DBG_SHOW_MODE (Flag_mode)
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-12 00:19:22 +03:00
|
|
|
void bx_dbg_show_command(const char* arg)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if(arg) {
|
2006-02-12 23:21:36 +03:00
|
|
|
if (!strcmp(arg, "mode")) {
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_MODE) {
|
|
|
|
dbg_show_mask &= ~BX_DBG_SHOW_MODE;
|
|
|
|
dbg_printf("show mode switch: OFF\n");
|
|
|
|
} else {
|
|
|
|
dbg_show_mask |= BX_DBG_SHOW_MODE;
|
|
|
|
dbg_printf("show mode switch: ON\n");
|
|
|
|
}
|
2006-02-12 23:43:01 +03:00
|
|
|
} else if (!strcmp(arg, "int")) {
|
2006-02-12 23:21:36 +03:00
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_INT) {
|
|
|
|
dbg_show_mask &= ~BX_DBG_SHOW_INT;
|
2006-02-12 23:43:01 +03:00
|
|
|
dbg_printf("show interrupts tracing (extint/softint/iret): OFF\n");
|
2006-02-12 23:21:36 +03:00
|
|
|
} else {
|
|
|
|
dbg_show_mask |= BX_DBG_SHOW_INT;
|
2006-02-12 23:43:01 +03:00
|
|
|
dbg_printf("show interrupts tracing (extint/softint/iret): ON\n");
|
|
|
|
}
|
|
|
|
} else if (!strcmp(arg, "extint")) {
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_EXTINT) {
|
|
|
|
dbg_show_mask &= ~BX_DBG_SHOW_EXTINT;
|
|
|
|
dbg_printf("show external interrupts: OFF\n");
|
|
|
|
} else {
|
|
|
|
dbg_show_mask |= BX_DBG_SHOW_EXTINT;
|
|
|
|
dbg_printf("show external interrupts: ON\n");
|
|
|
|
}
|
|
|
|
} else if (!strcmp(arg, "softint")) {
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_SOFTINT) {
|
|
|
|
dbg_show_mask &= ~BX_DBG_SHOW_SOFTINT;
|
|
|
|
dbg_printf("show software interrupts: OFF\n");
|
|
|
|
} else {
|
|
|
|
dbg_show_mask |= BX_DBG_SHOW_SOFTINT;
|
|
|
|
dbg_printf("show software interrupts: ON\n");
|
|
|
|
}
|
|
|
|
} else if (!strcmp(arg, "iret")) {
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_IRET) {
|
|
|
|
dbg_show_mask &= ~BX_DBG_SHOW_IRET;
|
|
|
|
dbg_printf("show iret: OFF\n");
|
|
|
|
} else {
|
|
|
|
dbg_show_mask |= BX_DBG_SHOW_IRET;
|
|
|
|
dbg_printf("show iret: ON\n");
|
2006-02-12 23:21:36 +03:00
|
|
|
}
|
|
|
|
} else if(!strcmp(arg,"call")) {
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_CALLRET) {
|
|
|
|
dbg_show_mask &= ~BX_DBG_SHOW_CALLRET;
|
|
|
|
dbg_printf("show calls/returns: OFF\n");
|
|
|
|
} else {
|
|
|
|
dbg_show_mask |= BX_DBG_SHOW_CALLRET;
|
|
|
|
dbg_printf("show calls/returns: ON\n");
|
|
|
|
}
|
2006-02-12 23:43:01 +03:00
|
|
|
} else if(!strcmp(arg,"off")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
dbg_show_mask = 0x0;
|
2006-02-12 23:21:36 +03:00
|
|
|
dbg_printf("Disable all show flags\n");
|
2006-02-12 23:43:01 +03:00
|
|
|
} else if(!strcmp(arg,"dbg-all")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg.interrupts = 1;
|
|
|
|
bx_dbg.exceptions = 1;
|
2006-02-12 23:21:36 +03:00
|
|
|
dbg_printf("Turned ON all bx_dbg flags\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2006-02-12 23:43:01 +03:00
|
|
|
} else if(!strcmp(arg,"dbg-none")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg.interrupts = 0;
|
|
|
|
bx_dbg.exceptions = 0;
|
2006-02-12 23:21:36 +03:00
|
|
|
dbg_printf("Turned OFF all bx_dbg flags\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2006-02-12 00:19:22 +03:00
|
|
|
} else if(!strcmp(arg,"vga")){
|
2012-10-28 12:23:39 +04:00
|
|
|
SIM->refresh_vga();
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
} else {
|
2006-05-30 23:46:31 +04:00
|
|
|
dbg_printf("Unrecognized arg: %s (only 'mode', 'int', 'softint', 'extint', 'iret', 'call', 'off', 'dbg-all' and 'dbg-none' are valid)\n", arg);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-12 23:21:36 +03:00
|
|
|
if (dbg_show_mask) {
|
|
|
|
dbg_printf("show mask is:");
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_CALLRET)
|
|
|
|
dbg_printf(" call");
|
2006-02-12 23:43:01 +03:00
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_SOFTINT)
|
|
|
|
dbg_printf(" softint");
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_EXTINT)
|
|
|
|
dbg_printf(" extint");
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_IRET)
|
|
|
|
dbg_printf(" iret");
|
2006-02-12 23:21:36 +03:00
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_MODE)
|
|
|
|
dbg_printf(" mode");
|
|
|
|
dbg_printf("\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("show mask is: 0\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 23:29:19 +04:00
|
|
|
void bx_dbg_show_param_command(const char *param)
|
2006-05-30 23:46:31 +04:00
|
|
|
{
|
|
|
|
dbg_printf("show param name: <%s>\n", param);
|
2008-03-28 15:51:02 +03:00
|
|
|
bx_param_c *node = SIM->get_param(param, SIM->get_bochs_root());
|
|
|
|
if (node) {
|
|
|
|
print_tree(node, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node = SIM->get_param(param, dbg_cpu_list);
|
|
|
|
if (node)
|
|
|
|
print_tree(node, 0);
|
|
|
|
else
|
|
|
|
dbg_printf("can't find param <%s> in global or default CPU tree\n", param);
|
|
|
|
}
|
2006-05-30 23:46:31 +04:00
|
|
|
}
|
2006-02-12 23:21:36 +03:00
|
|
|
|
|
|
|
// return non zero to cause a stop
|
2008-02-06 01:33:35 +03:00
|
|
|
int bx_dbg_show_symbolic(void)
|
2006-02-12 23:21:36 +03:00
|
|
|
{
|
2008-01-17 18:39:45 +03:00
|
|
|
static unsigned last_cpu_mode = 0;
|
2009-04-07 20:12:19 +04:00
|
|
|
static bx_address last_cr3 = 0;
|
2006-02-12 23:21:36 +03:00
|
|
|
|
|
|
|
/* modes & address spaces */
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_MODE) {
|
|
|
|
if(BX_CPU(dbg_cpu)->get_cpu_mode() != last_cpu_mode) {
|
2008-02-06 01:33:35 +03:00
|
|
|
dbg_printf (FMT_TICK ": switched from '%s' to '%s'\n",
|
2006-02-12 23:21:36 +03:00
|
|
|
bx_pc_system.time_ticks(),
|
|
|
|
cpu_mode_string(last_cpu_mode),
|
|
|
|
cpu_mode_string(BX_CPU(dbg_cpu)->get_cpu_mode()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(last_cr3 != BX_CPU(dbg_cpu)->cr3)
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf(FMT_TICK ": address space switched. CR3: 0x" FMT_PHY_ADDRX "\n",
|
2006-02-12 23:21:36 +03:00
|
|
|
bx_pc_system.time_ticks(), BX_CPU(dbg_cpu)->cr3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interrupts */
|
2006-02-12 23:43:01 +03:00
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_SOFTINT) {
|
2006-02-12 23:21:36 +03:00
|
|
|
if(BX_CPU(dbg_cpu)->show_flag & Flag_softint) {
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf(FMT_TICK ": softint ", bx_pc_system.time_ticks());
|
|
|
|
dbg_print_guard_found(BX_CPU(dbg_cpu)->get_cpu_mode(),
|
|
|
|
BX_CPU(dbg_cpu)->guard_found.cs, BX_CPU(dbg_cpu)->guard_found.eip,
|
2006-02-12 23:21:36 +03:00
|
|
|
BX_CPU(dbg_cpu)->guard_found.laddr);
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("\n");
|
2006-02-12 23:21:36 +03:00
|
|
|
}
|
2006-02-12 23:43:01 +03:00
|
|
|
}
|
2008-02-06 01:33:35 +03:00
|
|
|
|
2006-02-12 23:43:01 +03:00
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_EXTINT) {
|
2006-02-12 23:21:36 +03:00
|
|
|
if((BX_CPU(dbg_cpu)->show_flag & Flag_intsig) && !(BX_CPU(dbg_cpu)->show_flag & Flag_softint)) {
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf(FMT_TICK ": exception (not softint) ", bx_pc_system.time_ticks());
|
|
|
|
dbg_print_guard_found(BX_CPU(dbg_cpu)->get_cpu_mode(),
|
|
|
|
BX_CPU(dbg_cpu)->guard_found.cs, BX_CPU(dbg_cpu)->guard_found.eip,
|
2006-02-12 23:21:36 +03:00
|
|
|
BX_CPU(dbg_cpu)->guard_found.laddr);
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("\n");
|
2006-02-12 23:21:36 +03:00
|
|
|
}
|
2006-02-12 23:43:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_IRET) {
|
2006-02-12 23:21:36 +03:00
|
|
|
if(BX_CPU(dbg_cpu)->show_flag & Flag_iret) {
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf(FMT_TICK ": iret ", bx_pc_system.time_ticks());
|
|
|
|
dbg_print_guard_found(BX_CPU(dbg_cpu)->get_cpu_mode(),
|
|
|
|
BX_CPU(dbg_cpu)->guard_found.cs, BX_CPU(dbg_cpu)->guard_found.eip,
|
2006-02-12 23:21:36 +03:00
|
|
|
BX_CPU(dbg_cpu)->guard_found.laddr);
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("\n");
|
2006-02-12 23:21:36 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-13 21:28:14 +03:00
|
|
|
|
2006-02-12 23:21:36 +03:00
|
|
|
/* calls */
|
|
|
|
if (dbg_show_mask & BX_DBG_SHOW_CALLRET)
|
|
|
|
{
|
|
|
|
if(BX_CPU(dbg_cpu)->show_flag & Flag_call) {
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_phy_address phy = 0;
|
|
|
|
bx_bool valid = BX_CPU(dbg_cpu)->dbg_xlate_linear2phy(BX_CPU(dbg_cpu)->guard_found.laddr, &phy);
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf(FMT_TICK ": call ", bx_pc_system.time_ticks());
|
|
|
|
dbg_print_guard_found(BX_CPU(dbg_cpu)->get_cpu_mode(),
|
|
|
|
BX_CPU(dbg_cpu)->guard_found.cs, BX_CPU(dbg_cpu)->guard_found.eip,
|
|
|
|
BX_CPU(dbg_cpu)->guard_found.laddr);
|
|
|
|
if (!valid) dbg_printf(" phys not valid");
|
|
|
|
else {
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf(" (phy: 0x" FMT_PHY_ADDRX ") %s", phy,
|
2009-11-07 23:07:04 +03:00
|
|
|
bx_dbg_symbolic_address(BX_CPU(dbg_cpu)->cr3 >> 12,
|
2006-02-12 23:21:36 +03:00
|
|
|
BX_CPU(dbg_cpu)->guard_found.eip,
|
|
|
|
BX_CPU(dbg_cpu)->guard_found.laddr - BX_CPU(dbg_cpu)->guard_found.eip));
|
2006-02-13 21:28:14 +03:00
|
|
|
}
|
2006-02-12 23:21:36 +03:00
|
|
|
dbg_printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
last_cr3 = BX_CPU(dbg_cpu)->cr3;
|
2006-01-24 00:44:44 +03:00
|
|
|
last_cpu_mode = BX_CPU(dbg_cpu)->get_cpu_mode();
|
2006-02-12 23:21:36 +03:00
|
|
|
BX_CPU(dbg_cpu)->show_flag = 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-12 23:21:36 +03:00
|
|
|
return 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
void bx_dbg_print_stack_command(unsigned nwords)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-02-03 01:33:32 +03:00
|
|
|
bx_address linear_sp;
|
|
|
|
unsigned len;
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (BX_CPU(dbg_cpu)->get_cpu_mode() == BX_MODE_LONG_64) {
|
2007-11-01 23:53:20 +03:00
|
|
|
linear_sp = BX_CPU(dbg_cpu)->get_reg64(BX_64BIT_REG_RSP);
|
2006-02-03 01:33:32 +03:00
|
|
|
len = 8;
|
|
|
|
}
|
2008-02-06 01:33:35 +03:00
|
|
|
else
|
2006-02-03 01:33:32 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (BX_CPU(dbg_cpu)->sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
linear_sp = BX_CPU(dbg_cpu)->get_reg32(BX_32BIT_REG_ESP);
|
|
|
|
len = 4;
|
|
|
|
}
|
|
|
|
else {
|
2007-11-01 23:53:20 +03:00
|
|
|
linear_sp = BX_CPU(dbg_cpu)->get_reg16(BX_16BIT_REG_SP);
|
2006-02-03 01:33:32 +03:00
|
|
|
len = 2;
|
|
|
|
}
|
2010-01-10 17:11:53 +03:00
|
|
|
|
|
|
|
linear_sp = BX_CPU(dbg_cpu)->get_laddr(BX_SEG_REG_SS, linear_sp);
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
Bit8u buf[8];
|
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
dbg_printf("Stack address size %d\n", len);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < nwords; i++) {
|
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, linear_sp, len, buf)) break;
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (len == 8) {
|
2008-02-06 01:33:35 +03:00
|
|
|
dbg_printf(" | STACK 0x%08x%08x [0x%08x:0x%08x]\n",
|
2007-01-25 22:21:20 +03:00
|
|
|
GET32H(linear_sp), GET32L(linear_sp),
|
2008-02-06 01:33:35 +03:00
|
|
|
(unsigned) conv_4xBit8u_to_Bit32u(buf+4),
|
2006-02-03 01:33:32 +03:00
|
|
|
(unsigned) conv_4xBit8u_to_Bit32u(buf));
|
|
|
|
}
|
2006-02-05 23:03:24 +03:00
|
|
|
else
|
2006-02-03 01:33:32 +03:00
|
|
|
#endif
|
2006-02-05 23:03:24 +03:00
|
|
|
{
|
2006-02-03 01:33:32 +03:00
|
|
|
if (len == 4) {
|
2008-02-06 01:33:35 +03:00
|
|
|
dbg_printf(" | STACK 0x%08x [0x%08x]\n",
|
2006-02-03 01:33:32 +03:00
|
|
|
(unsigned) linear_sp, (unsigned) conv_4xBit8u_to_Bit32u(buf));
|
|
|
|
}
|
|
|
|
else {
|
2008-02-06 01:33:35 +03:00
|
|
|
dbg_printf(" | STACK 0x%04x [0x%04x]\n",
|
2010-01-09 23:28:07 +03:00
|
|
|
(unsigned) linear_sp, (unsigned) conv_2xBit8u_to_Bit16u(buf));
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2006-02-03 01:33:32 +03:00
|
|
|
|
|
|
|
linear_sp += len;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-03 21:36:24 +04:00
|
|
|
void bx_dbg_print_watchpoints(void)
|
2009-10-02 19:11:23 +04:00
|
|
|
{ unsigned i;
|
2009-04-03 21:36:24 +04:00
|
|
|
Bit8u buf[2];
|
|
|
|
|
|
|
|
// print watch point info
|
2009-10-02 19:11:23 +04:00
|
|
|
for (i = 0; i < num_read_watchpoints; i++) {
|
2009-11-20 00:28:25 +03:00
|
|
|
if (BX_MEM(0)->dbg_fetch_mem(BX_CPU(dbg_cpu), read_watchpoint[i].addr, 2, buf))
|
2009-11-20 15:02:57 +03:00
|
|
|
dbg_printf("rd 0x"FMT_PHY_ADDRX" len=%d\t\t(%04x)\n",
|
|
|
|
read_watchpoint[i].addr, read_watchpoint[i].len, (int)buf[0] | ((int)buf[1] << 8));
|
2009-04-03 21:36:24 +04:00
|
|
|
else
|
2009-11-20 15:02:57 +03:00
|
|
|
dbg_printf("rd 0x"FMT_PHY_ADDRX" len=%d\t\t(read error)\n",
|
|
|
|
read_watchpoint[i].addr, read_watchpoint[i].len);
|
2009-04-03 21:36:24 +04:00
|
|
|
}
|
2009-10-02 19:11:23 +04:00
|
|
|
for (i = 0; i < num_write_watchpoints; i++) {
|
2009-11-20 00:28:25 +03:00
|
|
|
if (BX_MEM(0)->dbg_fetch_mem(BX_CPU(dbg_cpu), write_watchpoint[i].addr, 2, buf))
|
2009-11-20 15:02:57 +03:00
|
|
|
dbg_printf("wr 0x"FMT_PHY_ADDRX" len=%d\t\t(%04x)\n",
|
|
|
|
write_watchpoint[i].addr, write_watchpoint[i].len, (int)buf[0] | ((int)buf[1] << 8));
|
2009-04-03 21:36:24 +04:00
|
|
|
else
|
2009-11-20 15:02:57 +03:00
|
|
|
dbg_printf("rd 0x"FMT_PHY_ADDRX" len=%d\t\t(read error)\n",
|
|
|
|
write_watchpoint[i].addr, write_watchpoint[i].len);
|
2009-04-03 21:36:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 15:02:57 +03:00
|
|
|
void bx_dbg_watch(int type, bx_phy_address address, Bit32u len)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-04-03 21:36:24 +04:00
|
|
|
if (type == BX_READ) {
|
|
|
|
if (num_read_watchpoints == BX_DBG_MAX_WATCHPONTS) {
|
|
|
|
dbg_printf("Too many read watchpoints (%d)\n", BX_DBG_MAX_WATCHPONTS);
|
|
|
|
return;
|
2008-10-08 21:13:35 +04:00
|
|
|
}
|
2009-11-20 15:02:57 +03:00
|
|
|
read_watchpoint[num_read_watchpoints].addr = address;
|
|
|
|
read_watchpoint[num_read_watchpoints].len = len;
|
|
|
|
num_read_watchpoints++;
|
|
|
|
dbg_printf("read watchpoint at 0x" FMT_PHY_ADDRX " len=%d inserted\n", address, len);
|
2009-04-03 21:36:24 +04:00
|
|
|
}
|
|
|
|
else if (type == BX_WRITE) {
|
|
|
|
if (num_write_watchpoints == BX_DBG_MAX_WATCHPONTS) {
|
|
|
|
dbg_printf("Too many write watchpoints (%d)\n", BX_DBG_MAX_WATCHPONTS);
|
|
|
|
return;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2009-11-20 15:02:57 +03:00
|
|
|
write_watchpoint[num_write_watchpoints].addr = address;
|
|
|
|
write_watchpoint[num_write_watchpoints].len = len;
|
|
|
|
num_write_watchpoints++;
|
|
|
|
dbg_printf("write watchpoint at 0x" FMT_PHY_ADDRX " len=%d inserted\n", address, len);
|
2009-04-03 21:36:24 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("bx_dbg_watch: broken watchpoint type");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-03 21:36:24 +04:00
|
|
|
void bx_dbg_unwatch_all()
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-04-03 21:36:24 +04:00
|
|
|
num_read_watchpoints = num_write_watchpoints = 0;
|
|
|
|
dbg_printf("All watchpoints removed\n");
|
|
|
|
}
|
2008-08-08 01:09:30 +04:00
|
|
|
|
2009-04-03 21:36:24 +04:00
|
|
|
void bx_dbg_unwatch(bx_phy_address address)
|
2009-10-02 19:11:23 +04:00
|
|
|
{ unsigned i;
|
|
|
|
for (i=0; i<num_read_watchpoints; i++) {
|
2009-11-20 00:28:25 +03:00
|
|
|
if (read_watchpoint[i].addr == address) {
|
2008-10-08 21:13:35 +04:00
|
|
|
dbg_printf("read watchpoint at 0x" FMT_PHY_ADDRX " removed\n", address);
|
|
|
|
// found watchpoint, delete it by shifting remaining entries left
|
|
|
|
for (unsigned j=i; j<(num_read_watchpoints-1); j++) {
|
|
|
|
read_watchpoint[j] = read_watchpoint[j+1];
|
|
|
|
}
|
|
|
|
num_read_watchpoints--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 19:11:23 +04:00
|
|
|
for (i=0; i<num_write_watchpoints; i++) {
|
2009-11-20 00:28:25 +03:00
|
|
|
if (write_watchpoint[i].addr == address) {
|
2008-10-08 21:13:35 +04:00
|
|
|
dbg_printf("write watchpoint at 0x" FMT_PHY_ADDRX " removed\n", address);
|
2008-08-08 01:09:30 +04:00
|
|
|
// found watchpoint, delete it by shifting remaining entries left
|
2008-10-08 21:13:35 +04:00
|
|
|
for (unsigned j=i; j<(num_write_watchpoints-1); j++) {
|
|
|
|
write_watchpoint[j] = write_watchpoint[j+1];
|
2008-08-08 01:09:30 +04:00
|
|
|
}
|
2008-10-08 21:13:35 +04:00
|
|
|
num_write_watchpoints--;
|
2008-08-08 01:09:30 +04:00
|
|
|
break;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_continue_command(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
// continue executing, until a guard found
|
|
|
|
|
2005-04-10 22:03:16 +04:00
|
|
|
one_more:
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// update gui (disable continue command, enable stop command, etc.)
|
2006-04-29 13:27:49 +04:00
|
|
|
sim_running->set(1);
|
|
|
|
SIM->refresh_ci();
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// use simulation mode while executing instructions. When the prompt
|
|
|
|
// is printed, we will return to config mode.
|
2006-04-29 13:27:49 +04:00
|
|
|
SIM->set_display_mode(DISP_MODE_SIM);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_guard.interrupt_requested = 0;
|
|
|
|
int stop = 0;
|
|
|
|
int which = -1;
|
2005-11-10 21:14:18 +03:00
|
|
|
while (!stop && !bx_guard.interrupt_requested) {
|
2003-11-28 18:07:29 +03:00
|
|
|
// the quantum is an arbitrary number of cycles to run in each
|
|
|
|
// processor. In SMP mode, when this limit is reached, the
|
|
|
|
// cpu_loop exits so that another processor can be simulated
|
|
|
|
// for a few cycles. With a single processor, the quantum
|
|
|
|
// setting should have no effect, although a low setting does
|
2008-02-06 01:33:35 +03:00
|
|
|
// lead to poor performance because cpu_loop is returning and
|
2003-11-28 18:07:29 +03:00
|
|
|
// getting called again, over and over.
|
2007-12-14 01:56:35 +03:00
|
|
|
|
|
|
|
#define BX_DBG_DEFAULT_ICOUNT_QUANTUM 5
|
|
|
|
|
2011-08-11 23:40:51 +04:00
|
|
|
if (BX_SMP_PROCESSORS == 1) {
|
2011-08-17 23:51:32 +04:00
|
|
|
bx_dbg_set_icount_guard(0, 0); // run to next breakpoint
|
2011-09-22 23:38:52 +04:00
|
|
|
BX_CPU(0)->cpu_loop();
|
2003-11-28 18:07:29 +03:00
|
|
|
// set stop flag if a guard found other than icount or halted
|
2011-08-11 23:40:51 +04:00
|
|
|
unsigned found = BX_CPU(0)->guard_found.guard_found;
|
|
|
|
stop_reason_t reason = (stop_reason_t) BX_CPU(0)->stop_reason;
|
2008-08-01 12:36:04 +04:00
|
|
|
if (found || (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED)) {
|
2003-11-28 18:07:29 +03:00
|
|
|
stop = 1;
|
2012-01-23 20:51:00 +04:00
|
|
|
which = 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-14 01:56:35 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2011-08-11 23:40:51 +04:00
|
|
|
else {
|
|
|
|
Bit32u max_executed = 0;
|
2012-01-23 20:51:00 +04:00
|
|
|
for (int cpu=0; cpu < BX_SMP_PROCESSORS; cpu++) {
|
2011-08-17 23:51:32 +04:00
|
|
|
Bit64u cpu_icount = BX_CPU(cpu)->get_icount();
|
|
|
|
bx_dbg_set_icount_guard(cpu, BX_DBG_DEFAULT_ICOUNT_QUANTUM);
|
2011-09-22 23:38:52 +04:00
|
|
|
BX_CPU(cpu)->cpu_loop();
|
2011-08-17 23:51:32 +04:00
|
|
|
Bit32u executed = BX_CPU(cpu)->get_icount() - cpu_icount;
|
2011-08-11 23:40:51 +04:00
|
|
|
if (executed > max_executed) max_executed = executed;
|
|
|
|
// set stop flag if a guard found other than icount or halted
|
|
|
|
unsigned found = BX_CPU(cpu)->guard_found.guard_found;
|
|
|
|
stop_reason_t reason = (stop_reason_t) BX_CPU(cpu)->stop_reason;
|
|
|
|
if (found || (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED)) {
|
|
|
|
stop = 1;
|
|
|
|
which = cpu;
|
|
|
|
}
|
|
|
|
// even if stop==1, finish cycling through all processors.
|
|
|
|
// "which" remembers which cpu set the stop flag. If multiple
|
|
|
|
// cpus set stop, too bad.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Potential deadlock if all processors are halted. Then
|
2007-03-07 00:18:00 +03:00
|
|
|
// max_executed will be 0, tick will be incremented by zero, and
|
2011-08-11 23:40:51 +04:00
|
|
|
// there will never be a timed event to wake them up.
|
|
|
|
// To avoid this, always tick by a minimum of 1.
|
2007-03-07 00:18:00 +03:00
|
|
|
if (max_executed < 1) max_executed=1;
|
|
|
|
|
2011-08-11 23:40:51 +04:00
|
|
|
// increment time tick only after all processors have had their chance.
|
2007-03-07 00:18:00 +03:00
|
|
|
BX_TICKN(max_executed);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2007-12-14 01:56:35 +03:00
|
|
|
#endif
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
sim_running->set(0);
|
|
|
|
SIM->refresh_ci();
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// (mch) hack
|
2012-10-28 12:23:39 +04:00
|
|
|
SIM->refresh_vga();
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
BX_INSTR_DEBUG_PROMPT();
|
|
|
|
bx_dbg_print_guard_results();
|
|
|
|
|
|
|
|
if (watchpoint_continue && (BX_CPU(which)->stop_reason == STOP_READ_WATCH_POINT ||
|
|
|
|
BX_CPU(which)->stop_reason == STOP_WRITE_WATCH_POINT))
|
|
|
|
goto one_more;
|
|
|
|
}
|
|
|
|
|
2009-10-29 18:49:50 +03:00
|
|
|
void bx_dbg_stepN_command(int cpu, Bit32u count)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-10-29 18:49:50 +03:00
|
|
|
if (cpu != -1 && cpu >= BX_SMP_PROCESSORS) {
|
|
|
|
dbg_printf("Error: stepN: unknown cpu=%d\n", cpu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
if (count == 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: stepN: count=0\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// use simulation mode while executing instructions. When the prompt
|
|
|
|
// is printed, we will return to config mode.
|
2006-04-29 13:27:49 +04:00
|
|
|
SIM->set_display_mode(DISP_MODE_SIM);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2011-08-11 23:40:51 +04:00
|
|
|
if (cpu >= 0 || BX_SMP_PROCESSORS == 1) {
|
2009-02-02 01:20:04 +03:00
|
|
|
bx_guard.interrupt_requested = 0;
|
2011-08-17 23:51:32 +04:00
|
|
|
bx_dbg_set_icount_guard(cpu, count);
|
2011-09-22 23:38:52 +04:00
|
|
|
BX_CPU(cpu)->cpu_loop();
|
2009-02-02 01:20:04 +03:00
|
|
|
}
|
2008-11-19 00:03:04 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2009-02-02 01:20:04 +03:00
|
|
|
else {
|
|
|
|
int stop = 0;
|
|
|
|
// for now, step each CPU one instruction at a time
|
|
|
|
for (unsigned cycle=0; !stop && cycle < count; cycle++) {
|
2009-10-29 18:49:50 +03:00
|
|
|
for (unsigned ncpu=0; ncpu < BX_SMP_PROCESSORS; ncpu++) {
|
2009-02-02 01:20:04 +03:00
|
|
|
bx_guard.interrupt_requested = 0;
|
2011-12-17 17:32:08 +04:00
|
|
|
bx_dbg_set_icount_guard(ncpu, 1);
|
2011-09-22 23:38:52 +04:00
|
|
|
BX_CPU(ncpu)->cpu_loop();
|
2009-02-02 01:20:04 +03:00
|
|
|
// set stop flag if a guard found other than icount or halted
|
2009-10-29 18:49:50 +03:00
|
|
|
unsigned found = BX_CPU(ncpu)->guard_found.guard_found;
|
|
|
|
stop_reason_t reason = (stop_reason_t) BX_CPU(ncpu)->stop_reason;
|
2009-02-02 01:20:04 +03:00
|
|
|
if (found || (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED))
|
|
|
|
stop = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// when (BX_SMP_PROCESSORS == 1) ticks are handled inside the cpu loop
|
2011-08-11 23:40:51 +04:00
|
|
|
BX_TICK1();
|
2009-02-02 01:20:04 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2009-02-02 01:20:04 +03:00
|
|
|
#endif
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
BX_INSTR_DEBUG_PROMPT();
|
|
|
|
bx_dbg_print_guard_results();
|
|
|
|
}
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
void bx_dbg_disassemble_current(int which_cpu, int print_time)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_phy_address phy;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (which_cpu < 0) {
|
|
|
|
// iterate over all of them.
|
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS; i++)
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_dbg_disassemble_current(i, print_time);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_bool phy_valid = BX_CPU(which_cpu)->dbg_xlate_linear2phy(BX_CPU(which_cpu)->guard_found.laddr, &phy);
|
2006-02-03 01:33:32 +03:00
|
|
|
if (! phy_valid) {
|
|
|
|
dbg_printf("(%u).[" FMT_LL "d] ??? (physical address not available)\n", which_cpu, bx_pc_system.time_ticks());
|
|
|
|
return;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
if (bx_dbg_read_linear(which_cpu, BX_CPU(which_cpu)->guard_found.laddr, 16, bx_disasm_ibuf))
|
|
|
|
{
|
2009-03-10 20:02:03 +03:00
|
|
|
unsigned ilen = bx_disassemble.disasm(IS_CODE_32(BX_CPU(which_cpu)->guard_found.code_32_64),
|
|
|
|
IS_CODE_64(BX_CPU(which_cpu)->guard_found.code_32_64),
|
2008-02-06 01:33:35 +03:00
|
|
|
BX_CPU(which_cpu)->get_segment_base(BX_SEG_REG_CS),
|
2005-12-14 23:05:40 +03:00
|
|
|
BX_CPU(which_cpu)->guard_found.eip, bx_disasm_ibuf, bx_disasm_tbuf);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// Note: it would be nice to display only the modified registers here, the easy
|
|
|
|
// way out I have thought of would be to keep a prev_eax, prev_ebx, etc copies
|
|
|
|
// in each cpu description (see cpu/cpu.h) and update/compare those "prev" values
|
|
|
|
// from here. (eks)
|
2009-06-01 18:50:19 +04:00
|
|
|
if(BX_CPU(which_cpu)->trace_reg)
|
2007-10-24 01:51:44 +04:00
|
|
|
bx_dbg_info_registers_command(BX_INFO_GENERAL_PURPOSE_REGS);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (print_time)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%u).[" FMT_LL "d] ", which_cpu, bx_pc_system.time_ticks());
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("(%u) ", which_cpu);
|
2006-02-01 21:12:08 +03:00
|
|
|
|
|
|
|
if (BX_CPU(which_cpu)->protected_mode()) {
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("[0x"FMT_PHY_ADDRX"] %04x:" FMT_ADDRX " (%s): ",
|
2006-02-03 01:33:32 +03:00
|
|
|
phy, BX_CPU(which_cpu)->guard_found.cs,
|
2006-01-19 21:32:39 +03:00
|
|
|
BX_CPU(which_cpu)->guard_found.eip,
|
2009-11-07 23:07:04 +03:00
|
|
|
bx_dbg_symbolic_address(BX_CPU(which_cpu)->cr3 >> 12,
|
2008-02-06 01:33:35 +03:00
|
|
|
BX_CPU(which_cpu)->guard_found.eip,
|
2006-02-01 21:12:08 +03:00
|
|
|
BX_CPU(which_cpu)->get_segment_base(BX_SEG_REG_CS)));
|
2006-01-19 21:32:39 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else { // Real & V86 mode
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("[0x"FMT_PHY_ADDRX"] %04x:%04x (%s): ",
|
2006-02-03 01:33:32 +03:00
|
|
|
phy, BX_CPU(which_cpu)->guard_found.cs,
|
2003-11-28 18:07:29 +03:00
|
|
|
(unsigned) BX_CPU(which_cpu)->guard_found.eip,
|
2008-02-06 01:33:35 +03:00
|
|
|
bx_dbg_symbolic_address_16bit(BX_CPU(which_cpu)->guard_found.eip,
|
2006-02-01 21:12:08 +03:00
|
|
|
BX_CPU(which_cpu)->sregs[BX_SEG_REG_CS].selector.value));
|
2006-01-19 21:32:39 +03:00
|
|
|
}
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%-25s ; ", bx_disasm_tbuf);
|
2008-04-20 00:01:09 +04:00
|
|
|
for (unsigned j=0; j<ilen; j++) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%02x", (unsigned) bx_disasm_ibuf[j]);
|
2008-04-20 00:01:09 +04:00
|
|
|
}
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_print_guard_results(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-02-03 01:33:32 +03:00
|
|
|
unsigned cpu, i;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
for (cpu=0; cpu<BX_SMP_PROCESSORS; cpu++) {
|
2009-03-10 19:28:01 +03:00
|
|
|
unsigned found = BX_CPU(cpu)->guard_found.guard_found;
|
2008-10-09 00:15:37 +04:00
|
|
|
if (! found) { /* ... */ }
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2006-02-03 01:33:32 +03:00
|
|
|
else if (found & BX_DBG_GUARD_IADDR_VIR) {
|
|
|
|
i = BX_CPU(cpu)->guard_found.iaddr_index;
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("(%u) Breakpoint %u, in ");
|
|
|
|
dbg_print_guard_found(BX_CPU(dbg_cpu)->get_cpu_mode(),
|
|
|
|
BX_CPU(cpu)->guard_found.cs, BX_CPU(cpu)->guard_found.eip,
|
|
|
|
BX_CPU(cpu)->guard_found.laddr);
|
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2006-02-03 01:33:32 +03:00
|
|
|
else if (found & BX_DBG_GUARD_IADDR_LIN) {
|
|
|
|
i = BX_CPU(cpu)->guard_found.iaddr_index;
|
|
|
|
if (bx_guard.iaddr.lin[i].bpoint_id != 0)
|
|
|
|
dbg_printf("(%u) Breakpoint %u, 0x" FMT_ADDRX " in ?? ()\n",
|
|
|
|
cpu,
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_guard.iaddr.lin[i].bpoint_id,
|
2006-02-03 01:33:32 +03:00
|
|
|
BX_CPU(cpu)->guard_found.laddr);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2006-02-03 01:33:32 +03:00
|
|
|
else if (found & BX_DBG_GUARD_IADDR_PHY) {
|
|
|
|
i = BX_CPU(cpu)->guard_found.iaddr_index;
|
|
|
|
dbg_printf("(%u) Breakpoint %u, 0x" FMT_ADDRX " in ?? ()\n",
|
|
|
|
cpu,
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_guard.iaddr.phy[i].bpoint_id,
|
2006-02-03 01:33:32 +03:00
|
|
|
BX_CPU(cpu)->guard_found.laddr);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
2006-04-29 13:27:49 +04:00
|
|
|
switch(BX_CPU(cpu)->stop_reason) {
|
|
|
|
case STOP_NO_REASON:
|
|
|
|
case STOP_CPU_HALTED:
|
|
|
|
break;
|
|
|
|
case STOP_TIME_BREAK_POINT:
|
|
|
|
dbg_printf("(%u) Caught time breakpoint\n", cpu);
|
|
|
|
break;
|
|
|
|
case STOP_READ_WATCH_POINT:
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("(%u) Caught read watch point at 0x" FMT_PHY_ADDRX "\n", cpu, BX_CPU(cpu)->watchpoint);
|
2006-04-29 13:27:49 +04:00
|
|
|
break;
|
|
|
|
case STOP_WRITE_WATCH_POINT:
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("(%u) Caught write watch point at 0x" FMT_PHY_ADDRX "\n", cpu, BX_CPU(cpu)->watchpoint);
|
2006-04-29 13:27:49 +04:00
|
|
|
break;
|
|
|
|
case STOP_MAGIC_BREAK_POINT:
|
|
|
|
dbg_printf("(%u) Magic breakpoint\n", cpu);
|
|
|
|
break;
|
|
|
|
case STOP_MODE_BREAK_POINT:
|
|
|
|
dbg_printf("(%u) Caught mode switch breakpoint switching to '%s'\n",
|
|
|
|
cpu, cpu_mode_string(BX_CPU(cpu)->get_cpu_mode()));
|
|
|
|
break;
|
2011-05-06 12:19:03 +04:00
|
|
|
case STOP_VMEXIT_BREAK_POINT:
|
|
|
|
dbg_printf("(%u) Caught VMEXIT breakpoint\n", cpu);
|
|
|
|
break;
|
2006-04-29 13:27:49 +04:00
|
|
|
default:
|
|
|
|
dbg_printf("Error: (%u) print_guard_results: guard_found ? (stop reason %u)\n",
|
|
|
|
cpu, BX_CPU(cpu)->stop_reason);
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
if (bx_debugger.auto_disassemble) {
|
|
|
|
if (cpu==0) {
|
|
|
|
// print this only once
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("Next at t=" FMT_LL "d\n", bx_pc_system.time_ticks());
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_dbg_disassemble_current(cpu, 0); // one cpu, don't print time
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
2011-08-17 23:51:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_icount_guard(int which_cpu, Bit32u n)
|
|
|
|
{
|
|
|
|
if (n == 0) {
|
|
|
|
bx_guard.guard_for &= ~BX_DBG_GUARD_ICOUNT;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2011-08-17 23:51:32 +04:00
|
|
|
else {
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_ICOUNT;
|
|
|
|
BX_CPU(which_cpu)->guard_found.icount_max = BX_CPU(which_cpu)->get_icount() + n;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPU(which_cpu)->guard_found.guard_found = 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_breakpoint_changed(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bx_guard.iaddr.num_virtual)
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_IADDR_VIR;
|
|
|
|
else
|
|
|
|
bx_guard.guard_for &= ~BX_DBG_GUARD_IADDR_VIR;
|
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bx_guard.iaddr.num_linear)
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_IADDR_LIN;
|
|
|
|
else
|
|
|
|
bx_guard.guard_for &= ~BX_DBG_GUARD_IADDR_LIN;
|
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bx_guard.iaddr.num_physical)
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_IADDR_PHY;
|
|
|
|
else
|
|
|
|
bx_guard.guard_for &= ~BX_DBG_GUARD_IADDR_PHY;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_en_dis_breakpoint_command(unsigned handle, bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2006-04-29 13:27:49 +04:00
|
|
|
if (bx_dbg_en_dis_vbreak(handle, enable))
|
2007-10-13 02:11:25 +04:00
|
|
|
goto done;
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2006-04-29 13:27:49 +04:00
|
|
|
if (bx_dbg_en_dis_lbreak(handle, enable))
|
2007-10-13 02:11:25 +04:00
|
|
|
goto done;
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2006-04-29 13:27:49 +04:00
|
|
|
if (bx_dbg_en_dis_pbreak(handle, enable))
|
2007-10-13 02:11:25 +04:00
|
|
|
goto done;
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: breakpoint %u not found.\n", handle);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
bx_dbg_breakpoint_changed();
|
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_bool bx_dbg_en_dis_pbreak(unsigned handle, bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
// see if breakpoint is a physical breakpoint
|
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_physical; i++) {
|
|
|
|
if (bx_guard.iaddr.phy[i].bpoint_id == handle) {
|
|
|
|
bx_guard.iaddr.phy[i].enabled=enable;
|
2008-08-08 01:09:30 +04:00
|
|
|
return 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
2007-10-13 02:11:25 +04:00
|
|
|
return 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_bool bx_dbg_en_dis_lbreak(unsigned handle, bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
// see if breakpoint is a linear breakpoint
|
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_linear; i++) {
|
|
|
|
if (bx_guard.iaddr.lin[i].bpoint_id == handle) {
|
|
|
|
bx_guard.iaddr.lin[i].enabled=enable;
|
2006-04-29 13:27:49 +04:00
|
|
|
return 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-29 13:27:49 +04:00
|
|
|
return 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_bool bx_dbg_en_dis_vbreak(unsigned handle, bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
// see if breakpoint is a virtual breakpoint
|
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_virtual; i++) {
|
|
|
|
if (bx_guard.iaddr.vir[i].bpoint_id == handle) {
|
|
|
|
bx_guard.iaddr.vir[i].enabled=enable;
|
2006-04-29 13:27:49 +04:00
|
|
|
return 1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
2006-04-29 13:27:49 +04:00
|
|
|
return 0;
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_del_breakpoint_command(unsigned handle)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2006-06-11 20:40:37 +04:00
|
|
|
if (bx_dbg_del_vbreak(handle))
|
2003-11-28 18:07:29 +03:00
|
|
|
goto done;
|
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2006-06-11 20:40:37 +04:00
|
|
|
if (bx_dbg_del_lbreak(handle))
|
2003-11-28 18:07:29 +03:00
|
|
|
goto done;
|
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2006-06-11 20:40:37 +04:00
|
|
|
if (bx_dbg_del_pbreak(handle))
|
2003-11-28 18:07:29 +03:00
|
|
|
goto done;
|
|
|
|
#endif
|
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: breakpoint %u not found.\n", handle);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
bx_dbg_breakpoint_changed();
|
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_bool bx_dbg_del_pbreak(unsigned handle)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
// see if breakpoint is a physical breakpoint
|
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_physical; i++) {
|
|
|
|
if (bx_guard.iaddr.phy[i].bpoint_id == handle) {
|
|
|
|
// found breakpoint, delete it by shifting remaining entries left
|
|
|
|
for (unsigned j=i; j<(bx_guard.iaddr.num_physical-1); j++) {
|
|
|
|
bx_guard.iaddr.phy[j] = bx_guard.iaddr.phy[j+1];
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
bx_guard.iaddr.num_physical--;
|
|
|
|
return 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
2005-04-08 22:30:34 +04:00
|
|
|
return 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_bool bx_dbg_del_lbreak(unsigned handle)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
// see if breakpoint is a linear breakpoint
|
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_linear; i++) {
|
|
|
|
if (bx_guard.iaddr.lin[i].bpoint_id == handle) {
|
|
|
|
// found breakpoint, delete it by shifting remaining entries left
|
|
|
|
for (unsigned j=i; j<(bx_guard.iaddr.num_linear-1); j++) {
|
|
|
|
bx_guard.iaddr.lin[j] = bx_guard.iaddr.lin[j+1];
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
bx_guard.iaddr.num_linear--;
|
|
|
|
return 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
2005-04-08 22:30:34 +04:00
|
|
|
return 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_bool bx_dbg_del_vbreak(unsigned handle)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
// see if breakpoint is a virtual breakpoint
|
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_virtual; i++) {
|
|
|
|
if (bx_guard.iaddr.vir[i].bpoint_id == handle) {
|
|
|
|
// found breakpoint, delete it by shifting remaining entries left
|
|
|
|
for (unsigned j=i; j<(bx_guard.iaddr.num_virtual-1); j++) {
|
|
|
|
bx_guard.iaddr.vir[j] = bx_guard.iaddr.vir[j+1];
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
bx_guard.iaddr.num_virtual--;
|
|
|
|
return 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
2005-04-08 22:30:34 +04:00
|
|
|
return 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-01 21:12:08 +03:00
|
|
|
int bx_dbg_vbreakpoint_command(BreakpointKind bk, Bit32u cs, bx_address eip)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bk != bkRegular) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: vbreak of this kind not implemented yet.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (bx_guard.iaddr.num_virtual >= BX_DBG_MAX_VIR_BPOINTS) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: no more virtual breakpoint slots left.\n");
|
|
|
|
dbg_printf("Error: see BX_DBG_MAX_VIR_BPOINTS.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_guard.iaddr.vir[bx_guard.iaddr.num_virtual].cs = cs;
|
|
|
|
bx_guard.iaddr.vir[bx_guard.iaddr.num_virtual].eip = eip;
|
|
|
|
bx_guard.iaddr.vir[bx_guard.iaddr.num_virtual].bpoint_id = bx_debugger.next_bpoint_id++;
|
|
|
|
int BpId = (int)bx_guard.iaddr.vir[bx_guard.iaddr.num_virtual].bpoint_id;
|
|
|
|
bx_guard.iaddr.vir[bx_guard.iaddr.num_virtual].enabled=1;
|
|
|
|
bx_guard.iaddr.num_virtual++;
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_IADDR_VIR;
|
|
|
|
return BpId;
|
|
|
|
|
|
|
|
#else
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: virtual breakpoint support not compiled in.\n");
|
2007-10-13 02:11:25 +04:00
|
|
|
dbg_printf("Error: make sure BX_DBG_MAX_VIR_BPOINTS > 0\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-02-01 21:12:08 +03:00
|
|
|
int bx_dbg_lbreakpoint_command(BreakpointKind bk, bx_address laddress)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bk == bkAtIP) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: lbreak of this kind not implemented yet.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (bx_guard.iaddr.num_linear >= BX_DBG_MAX_LIN_BPOINTS) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: no more linear breakpoint slots left.\n");
|
|
|
|
dbg_printf("Error: see BX_DBG_MAX_LIN_BPOINTS.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_guard.iaddr.lin[bx_guard.iaddr.num_linear].addr = laddress;
|
|
|
|
int BpId = (bk == bkStepOver) ? 0 : bx_debugger.next_bpoint_id++;
|
|
|
|
bx_guard.iaddr.lin[bx_guard.iaddr.num_linear].bpoint_id = BpId;
|
|
|
|
bx_guard.iaddr.lin[bx_guard.iaddr.num_linear].enabled=1;
|
|
|
|
bx_guard.iaddr.num_linear++;
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_IADDR_LIN;
|
|
|
|
return BpId;
|
|
|
|
|
|
|
|
#else
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: linear breakpoint support not compiled in.\n");
|
2007-10-13 02:11:25 +04:00
|
|
|
dbg_printf("Error: make sure BX_DBG_MAX_LIN_BPOINTS > 0\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-10-09 23:49:23 +04:00
|
|
|
int bx_dbg_pbreakpoint_command(BreakpointKind bk, bx_phy_address paddress)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bk != bkRegular) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: pbreak of this kind not implemented yet.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (bx_guard.iaddr.num_physical >= BX_DBG_MAX_PHY_BPOINTS) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: no more physical breakpoint slots left.\n");
|
|
|
|
dbg_printf("Error: see BX_DBG_MAX_PHY_BPOINTS.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_guard.iaddr.phy[bx_guard.iaddr.num_physical].addr = paddress;
|
|
|
|
bx_guard.iaddr.phy[bx_guard.iaddr.num_physical].bpoint_id = bx_debugger.next_bpoint_id++;
|
|
|
|
int BpId = (int)bx_guard.iaddr.phy[bx_guard.iaddr.num_physical].bpoint_id;
|
|
|
|
bx_guard.iaddr.phy[bx_guard.iaddr.num_physical].enabled=1;
|
|
|
|
bx_guard.iaddr.num_physical++;
|
|
|
|
bx_guard.guard_for |= BX_DBG_GUARD_IADDR_PHY;
|
|
|
|
return BpId;
|
|
|
|
#else
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: physical breakpoint support not compiled in.\n");
|
2007-10-13 02:11:25 +04:00
|
|
|
dbg_printf("Error: make sure BX_DBG_MAX_PHY_BPOINTS > 0\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_info_bpoints_command(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
// Num Type Disp Enb Address What
|
|
|
|
// 1 breakpoint keep y 0x00010664 in main at temp.c:7
|
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Num Type Disp Enb Address\n");
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
for (i=0; i<bx_guard.iaddr.num_virtual; i++) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%3u ", bx_guard.iaddr.vir[i].bpoint_id);
|
|
|
|
dbg_printf("vbreakpoint ");
|
|
|
|
dbg_printf("keep ");
|
2006-06-09 16:26:34 +04:00
|
|
|
dbg_printf(bx_guard.iaddr.vir[i].enabled?"y ":"n ");
|
2006-02-01 21:12:08 +03:00
|
|
|
dbg_printf("0x%04x:" FMT_ADDRX "\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_guard.iaddr.vir[i].cs,
|
|
|
|
bx_guard.iaddr.vir[i].eip);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
for (i=0; i<bx_guard.iaddr.num_linear; i++) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%3u ", bx_guard.iaddr.lin[i].bpoint_id);
|
|
|
|
dbg_printf("lbreakpoint ");
|
|
|
|
dbg_printf("keep ");
|
2006-02-01 21:12:08 +03:00
|
|
|
dbg_printf(bx_guard.iaddr.lin[i].enabled?"y ":"n ");
|
|
|
|
dbg_printf("0x" FMT_ADDRX "\n", bx_guard.iaddr.lin[i].addr);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
|
2007-10-13 02:11:25 +04:00
|
|
|
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
|
2003-11-28 18:07:29 +03:00
|
|
|
for (i=0; i<bx_guard.iaddr.num_physical; i++) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%3u ", bx_guard.iaddr.phy[i].bpoint_id);
|
|
|
|
dbg_printf("pbreakpoint ");
|
|
|
|
dbg_printf("keep ");
|
2006-06-09 16:26:34 +04:00
|
|
|
dbg_printf(bx_guard.iaddr.phy[i].enabled?"y ":"n ");
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("0x"FMT_PHY_ADDRX"\n", bx_guard.iaddr.phy[i].addr);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-01-25 00:37:37 +03:00
|
|
|
void bx_dbg_set_auto_disassemble(bx_bool enable)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-01-25 00:37:37 +03:00
|
|
|
bx_debugger.auto_disassemble = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_disassemble_size(unsigned size)
|
|
|
|
{
|
2006-02-01 21:12:08 +03:00
|
|
|
if ((size!=16) && (size!=32) && (size!=64) && (size!=0))
|
|
|
|
{
|
2006-01-25 00:37:37 +03:00
|
|
|
dbg_printf("Error: disassemble size must be 16/32 or 64.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bx_debugger.disassemble_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_disassemble_switch_mode()
|
|
|
|
{
|
|
|
|
bx_disassemble.toggle_syntax_mode();
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2009-12-28 16:44:32 +03:00
|
|
|
void bx_dbg_disassemble_hex_mode_switch(int mode)
|
|
|
|
{
|
|
|
|
bx_disassemble.set_offset_mode_hex(mode);
|
|
|
|
}
|
|
|
|
|
2006-02-12 00:19:22 +03:00
|
|
|
void bx_dbg_take_command(const char *what, unsigned n)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-06-09 16:26:34 +04:00
|
|
|
if (! strcmp(what, "dma")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
if (n == 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: take what n=0.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_post_dma_reports(); // in case there's some pending reports
|
|
|
|
bx_dbg_batch_dma.this_many = n;
|
|
|
|
|
2006-02-01 21:12:08 +03:00
|
|
|
for (unsigned i=0; i<n; i++) {
|
2003-11-28 18:07:29 +03:00
|
|
|
BX_CPU(0)->dbg_take_dma();
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_dbg_batch_dma.this_many = 1; // reset to normal
|
|
|
|
bx_dbg_post_dma_reports(); // print reports and flush
|
|
|
|
if (bx_guard.report.dma)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("done\n");
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: Take '%s' not understood.\n", what);
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
static void bx_print_char(Bit8u ch)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (ch < 10)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf(" \\%d ", ch);
|
2003-11-28 18:07:29 +03:00
|
|
|
else if (isprint(ch))
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf(" %c ", ch);
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf(" \\x%02X", ch);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2009-01-31 00:47:42 +03:00
|
|
|
void dbg_printf_binary(const char *format, Bit32u data, int bits)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2011-02-11 12:56:23 +03:00
|
|
|
int len = 0;
|
2003-11-28 18:07:29 +03:00
|
|
|
char num[33];
|
|
|
|
|
2011-02-11 12:56:23 +03:00
|
|
|
for (unsigned b = 1 << (bits - 1); b; b >>= 1)
|
2003-11-28 18:07:29 +03:00
|
|
|
num [len++] = (data & b) ? '1' : '0';
|
2011-02-11 12:56:23 +03:00
|
|
|
num[len] = 0;
|
|
|
|
dbg_printf(format, num);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2011-02-11 12:56:23 +03:00
|
|
|
void bx_dbg_examine_command(const char *command, const char *format, bx_bool format_passed,
|
2007-10-09 23:49:23 +04:00
|
|
|
bx_address addr, bx_bool addr_passed)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
unsigned repeat_count, i;
|
|
|
|
char ch, display_format, unit_size;
|
|
|
|
bx_bool iteration, memory_dump = false;
|
|
|
|
unsigned data_size;
|
|
|
|
Bit8u data8;
|
|
|
|
Bit16u data16;
|
|
|
|
Bit32u data32;
|
|
|
|
unsigned columns, per_line, offset;
|
|
|
|
bx_bool is_linear;
|
2009-11-20 15:02:57 +03:00
|
|
|
Bit8u databuf[8];
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
dbg_printf("[bochs]:\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// If command was the extended "xp" command, meaning eXamine Physical memory,
|
|
|
|
// then flag memory address as physical, rather than linear.
|
|
|
|
if (strcmp(command, "xp") == 0) {
|
|
|
|
is_linear = 0;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
|
|
|
is_linear = 1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (addr_passed==0)
|
|
|
|
addr = bx_debugger.default_addr;
|
|
|
|
|
|
|
|
if (format_passed==0) {
|
|
|
|
display_format = bx_debugger.default_display_format;
|
|
|
|
unit_size = bx_debugger.default_unit_size;
|
|
|
|
repeat_count = 1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
|
|
|
if (format==NULL) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("dbg_examine: format NULL\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (strlen(format) < 2) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("dbg_examine: invalid format passed.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (format[0] != '/') {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("dbg_examine: '/' is not first char of format.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
format++;
|
|
|
|
repeat_count = 0;
|
|
|
|
ch = *format;
|
|
|
|
iteration = 0;
|
|
|
|
|
2011-02-11 12:56:23 +03:00
|
|
|
while (ch>='0' && ch<='9') {
|
2003-11-28 18:07:29 +03:00
|
|
|
iteration = 1;
|
|
|
|
repeat_count = 10*repeat_count + (ch-'0');
|
|
|
|
format++;
|
|
|
|
ch = *format;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (iteration==0) {
|
|
|
|
// if no count given, use default
|
|
|
|
repeat_count = 1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else if (repeat_count==0) {
|
|
|
|
// count give, but zero is an error
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("dbg_examine: repeat count given but is zero.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// set up the default display format and unit size parameters
|
|
|
|
display_format = bx_debugger.default_display_format;
|
|
|
|
unit_size = bx_debugger.default_unit_size;
|
|
|
|
|
2011-02-11 12:56:23 +03:00
|
|
|
for (i = 0; format[i]; i++) {
|
|
|
|
switch (ch = format[i]) {
|
2003-11-28 18:07:29 +03:00
|
|
|
case 'x': // hex
|
|
|
|
case 'd': // signed decimal
|
|
|
|
case 'u': // unsigned decimal
|
|
|
|
case 'o': // octal
|
|
|
|
case 't': // binary
|
|
|
|
case 'c': // chars
|
|
|
|
case 's': // null terminated string
|
|
|
|
case 'i': // machine instruction
|
|
|
|
display_format = ch;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b': // bytes
|
|
|
|
case 'h': // halfwords (two bytes)
|
|
|
|
case 'w': // words (4 bytes)
|
|
|
|
case 'g': // giant words (8 bytes)
|
|
|
|
unit_size = ch;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm': // memory dump
|
|
|
|
memory_dump = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("dbg_examine: invalid format passed. \'%c\'\n", ch);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
if ((display_format == 'i') || (display_format == 's')) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("error: dbg_examine: 'i' and 's' formats not supported.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (unit_size == 'g') {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("error: dbg_examine: 'g' (8-byte) unit size not supported.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2008-07-11 21:31:30 +04:00
|
|
|
if (format_passed) {
|
|
|
|
// store current options as default
|
|
|
|
bx_debugger.default_display_format = display_format;
|
|
|
|
bx_debugger.default_unit_size = unit_size;
|
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
data_size = 0;
|
|
|
|
per_line = 0;
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
if (memory_dump) {
|
|
|
|
if (display_format == 'c') {
|
|
|
|
// Display character dump in lines of 64 characters
|
|
|
|
unit_size = 'b';
|
|
|
|
data_size = 1;
|
|
|
|
per_line = 64;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
|
|
|
switch (unit_size) {
|
|
|
|
case 'b': data_size = 1; per_line = 16; break;
|
|
|
|
case 'h': data_size = 2; per_line = 8; break;
|
|
|
|
case 'w': data_size = 4; per_line = 4; break;
|
|
|
|
//case 'g': data_size = 8; per_line = 2; break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
|
|
|
// binary format is quite large
|
|
|
|
if (display_format == 't')
|
|
|
|
per_line /= 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (unit_size) {
|
|
|
|
case 'b': data_size = 1; per_line = 8; break;
|
|
|
|
case 'h': data_size = 2; per_line = 8; break;
|
|
|
|
case 'w': data_size = 4; per_line = 4; break;
|
2003-11-28 18:07:29 +03:00
|
|
|
//case 'g': data_size = 8; per_line = 2; break;
|
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
columns = per_line + 1; // set current number columns past limit
|
|
|
|
|
|
|
|
for (i=1; i<=repeat_count; i++) {
|
|
|
|
if (columns > per_line) {
|
|
|
|
// if not 1st run, need a newline from last line
|
|
|
|
if (i!=1)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
if (memory_dump)
|
2007-10-09 23:49:23 +04:00
|
|
|
dbg_printf("0x" FMT_ADDRX ":", addr);
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
2007-10-09 23:49:23 +04:00
|
|
|
dbg_printf("0x" FMT_ADDRX " <bogus+%8u>:", addr, offset);
|
2003-11-28 18:07:29 +03:00
|
|
|
columns = 1;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
/* Put a space in the middle of dump, for readability */
|
|
|
|
if ((columns - 1) == per_line / 2
|
2005-04-08 22:30:34 +04:00
|
|
|
&& memory_dump && display_format != 'c')
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf(" ");
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (is_linear) {
|
2006-06-09 16:26:34 +04:00
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, addr, data_size, databuf)) return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
2006-06-09 16:26:34 +04:00
|
|
|
// address is already physical address
|
2009-04-07 20:12:19 +04:00
|
|
|
BX_MEM(0)->dbg_fetch_mem(BX_CPU(dbg_cpu), (bx_phy_address) addr, data_size, databuf);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
//FIXME HanishKVC The char display for data to be properly integrated
|
|
|
|
// so that repeat_count, columns, etc. can be set or used properly.
|
|
|
|
// Also for data_size of 2 and 4 how to display the individual
|
|
|
|
// characters i.e in which order to be decided.
|
|
|
|
switch (data_size) {
|
|
|
|
case 1:
|
|
|
|
data8 = databuf[0];
|
|
|
|
if (memory_dump)
|
|
|
|
switch (display_format) {
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'd': dbg_printf("%03d ", data8); break;
|
|
|
|
case 'u': dbg_printf("%03u ", data8); break;
|
|
|
|
case 'o': dbg_printf("%03o ", data8); break;
|
2011-02-11 12:56:23 +03:00
|
|
|
case 't': dbg_printf_binary("%s ", data8, 8); break;
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'c': dbg_printf("%c", isprint(data8) ? data8 : '.'); break;
|
|
|
|
default : dbg_printf("%02X ", data8); break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
|
|
|
switch (display_format) {
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'x': dbg_printf("\t0x%02x", (unsigned) data8); break;
|
|
|
|
case 'd': dbg_printf("\t%d", (int) (Bit8s) data8); break;
|
|
|
|
case 'u': dbg_printf("\t%u", (unsigned) data8); break;
|
|
|
|
case 'o': dbg_printf("\t%o", (unsigned) data8); break;
|
2006-04-29 13:27:49 +04:00
|
|
|
case 't': dbg_printf_binary("\t%s", data8, 8); break;
|
|
|
|
case 'c': bx_print_char(data8); break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2009-11-20 15:02:57 +03:00
|
|
|
ReadHostWordFromLittleEndian(databuf, data16);
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
if (memory_dump)
|
|
|
|
switch (display_format) {
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'd': dbg_printf("%05d ", data16); break;
|
|
|
|
case 'u': dbg_printf("%05u ", data16); break;
|
|
|
|
case 'o': dbg_printf("%06o ", data16); break;
|
2011-02-11 12:56:23 +03:00
|
|
|
case 't': dbg_printf_binary("%s ", data16, 16); break;
|
2006-01-24 22:23:42 +03:00
|
|
|
default : dbg_printf("%04X ", data16); break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
|
|
|
switch (display_format) {
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'x': dbg_printf("\t0x%04x", (unsigned) data16); break;
|
|
|
|
case 'd': dbg_printf("\t%d", (int) (Bit16s) data16); break;
|
|
|
|
case 'u': dbg_printf("\t%u", (unsigned) data16); break;
|
|
|
|
case 'o': dbg_printf("\t%o", (unsigned) data16); break;
|
2006-04-29 13:27:49 +04:00
|
|
|
case 't': dbg_printf_binary("\t%s", data16, 16); break;
|
2008-02-06 01:33:35 +03:00
|
|
|
case 'c':
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_print_char(data16>>8);
|
|
|
|
bx_print_char(data16 & 0xff);
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2009-11-20 15:02:57 +03:00
|
|
|
ReadHostDWordFromLittleEndian(databuf, data32);
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
if (memory_dump)
|
|
|
|
switch (display_format) {
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'd': dbg_printf("%10d ", data32); break;
|
|
|
|
case 'u': dbg_printf("%10u ", data32); break;
|
|
|
|
case 'o': dbg_printf("%12o ", data32); break;
|
2011-02-11 12:56:23 +03:00
|
|
|
case 't': dbg_printf_binary("%s ", data32, 32); break;
|
2006-01-24 22:23:42 +03:00
|
|
|
default : dbg_printf("%08X ", data32); break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
|
|
|
switch (display_format) {
|
2006-01-24 22:23:42 +03:00
|
|
|
case 'x': dbg_printf("\t0x%08x", (unsigned) data32); break;
|
|
|
|
case 'd': dbg_printf("\t%d", (int) (Bit32s) data32); break;
|
|
|
|
case 'u': dbg_printf("\t%u", (unsigned) data32); break;
|
|
|
|
case 'o': dbg_printf("\t%o", (unsigned) data32); break;
|
2006-04-29 13:27:49 +04:00
|
|
|
case 't': dbg_printf_binary("\t%s", data32, 32); break;
|
2008-02-06 01:33:35 +03:00
|
|
|
case 'c':
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_print_char(0xff & (data32>>24));
|
|
|
|
bx_print_char(0xff & (data32>>16));
|
|
|
|
bx_print_char(0xff & (data32>> 8));
|
|
|
|
bx_print_char(0xff & (data32>> 0));
|
2005-04-08 22:30:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
addr += data_size;
|
|
|
|
bx_debugger.default_addr = addr;
|
|
|
|
columns++;
|
|
|
|
offset += data_size;
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2010-01-05 16:59:08 +03:00
|
|
|
Bit32u bx_dbg_lin_indirect(bx_address addr)
|
|
|
|
{
|
|
|
|
Bit8u databuf[4];
|
|
|
|
Bit32u result;
|
|
|
|
|
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, addr, 4, databuf)) {
|
2012-04-24 15:01:59 +04:00
|
|
|
/* bx_dbg_read_linear already printed an error message if failed */
|
2010-01-05 16:59:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadHostDWordFromLittleEndian(databuf, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u bx_dbg_phy_indirect(bx_phy_address paddr)
|
|
|
|
{
|
|
|
|
Bit8u databuf[4];
|
|
|
|
Bit32u result;
|
|
|
|
|
|
|
|
if (! BX_MEM(0)->dbg_fetch_mem(BX_CPU(dbg_cpu), paddr, 4, databuf)) {
|
2012-04-24 15:01:59 +04:00
|
|
|
/* dbg_fetch_mem already printed an error message if failed */
|
2010-01-05 16:59:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadHostDWordFromLittleEndian(databuf, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:01:59 +04:00
|
|
|
void bx_dbg_writemem_command(const char *filename, bx_address laddr, unsigned len)
|
|
|
|
{
|
|
|
|
if (len == 0) {
|
|
|
|
dbg_printf("writemem: required length in bytes\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *f = fopen(filename, "wb");
|
|
|
|
if (!f) {
|
|
|
|
dbg_printf("Can not open file '%s' for writemem log!\n", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit8u databuf[4096];
|
|
|
|
|
|
|
|
while(len > 0) {
|
|
|
|
unsigned bytes = len;
|
|
|
|
if (len > 4096) bytes = 4096;
|
|
|
|
|
|
|
|
// I hope laddr is 4KB aligned so read_linear will be done efficiently
|
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, laddr, bytes, databuf)) {
|
|
|
|
/* bx_dbg_read_linear already printed an error message if failed */
|
|
|
|
len = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fwrite(databuf, 1, bytes, f) < bytes) {
|
|
|
|
dbg_printf("Write error to file '%s'\n", filename);
|
|
|
|
len = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len -= bytes;
|
|
|
|
laddr += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2007-10-09 23:49:23 +04:00
|
|
|
void bx_dbg_setpmem_command(bx_phy_address paddr, unsigned len, Bit32u val)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-02-03 01:33:32 +03:00
|
|
|
Bit8u buf[4];
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
switch (len) {
|
2003-11-28 18:07:29 +03:00
|
|
|
case 1:
|
|
|
|
buf[0] = (Bit8u) val;
|
|
|
|
break;
|
|
|
|
case 2:
|
2006-01-27 22:50:00 +03:00
|
|
|
buf[0] = val & 0xff; val >>= 8;
|
|
|
|
buf[1] = val & 0xff;
|
2003-11-28 18:07:29 +03:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
buf[0] = val & 0xff; val >>= 8;
|
|
|
|
buf[1] = val & 0xff; val >>= 8;
|
|
|
|
buf[2] = val & 0xff; val >>= 8;
|
|
|
|
buf[3] = val & 0xff;
|
|
|
|
break;
|
|
|
|
default:
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: setpmem: bad length value = %u\n", len);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
if (! BX_MEM(0)->dbg_set_mem(paddr, len, buf)) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: setpmem: could not set memory, out of physical bounds?\n");
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2009-05-03 23:29:19 +04:00
|
|
|
void bx_dbg_set_symbol_command(const char *symbol, Bit32u val)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
bx_bool is_OK = false;
|
|
|
|
symbol++; // get past '$'
|
|
|
|
|
2012-11-07 00:01:02 +04:00
|
|
|
if (!strcmp(symbol, "eflags")) {
|
|
|
|
is_OK = BX_CPU(dbg_cpu)->dbg_set_eflags(val);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2008-02-15 22:03:54 +03:00
|
|
|
else if (!strcmp(symbol, "cpu")) {
|
2007-09-27 11:03:11 +04:00
|
|
|
if (val >= BX_SMP_PROCESSORS) {
|
2006-01-27 22:50:00 +03:00
|
|
|
dbg_printf("invalid cpu id number %d\n", val);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-11 22:12:00 +04:00
|
|
|
char cpu_param_name[10];
|
2007-10-14 23:04:51 +04:00
|
|
|
sprintf(cpu_param_name, "cpu%d", val);
|
2007-10-11 22:12:00 +04:00
|
|
|
dbg_cpu_list = (bx_list_c*) SIM->get_param(cpu_param_name, SIM->get_bochs_root());
|
2006-01-27 22:50:00 +03:00
|
|
|
dbg_cpu = val;
|
2007-09-27 11:03:11 +04:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2008-02-15 22:03:54 +03:00
|
|
|
else if (!strcmp(symbol, "synchronous_dma")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_guard.async.dma = !val;
|
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2008-02-15 22:03:54 +03:00
|
|
|
else if (!strcmp(symbol, "synchronous_irq")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_guard.async.irq = !val;
|
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2008-02-15 22:03:54 +03:00
|
|
|
else if (!strcmp(symbol, "event_reports")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_guard.report.irq = val;
|
|
|
|
bx_guard.report.a20 = val;
|
|
|
|
bx_guard.report.io = val;
|
|
|
|
bx_guard.report.dma = val;
|
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2008-02-15 22:03:54 +03:00
|
|
|
else if (!strcmp(symbol, "auto_disassemble")) {
|
2006-01-25 00:37:37 +03:00
|
|
|
bx_dbg_set_auto_disassemble(val != 0);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: set: unrecognized symbol.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (!is_OK) {
|
2012-11-07 00:01:02 +04:00
|
|
|
dbg_printf("Error: could not set register '%s'\n", symbol);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-12 00:19:22 +03:00
|
|
|
void bx_dbg_query_command(const char *what)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
unsigned pending;
|
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
if (! strcmp(what, "pending")) {
|
2003-11-28 18:07:29 +03:00
|
|
|
pending = BX_CPU(0)->dbg_query_pending();
|
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
if (pending & BX_DBG_PENDING_DMA)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("pending DMA\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
if (pending & BX_DBG_PENDING_IRQ)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("pending IRQ\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
if (!pending)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("pending none\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("done\n");
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: Query '%s' not understood.\n", what);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2007-10-14 23:04:51 +04:00
|
|
|
void bx_dbg_restore_command(const char *param_name, const char *restore_path)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-14 23:04:51 +04:00
|
|
|
const char *path = (restore_path == NULL) ? "." : restore_path;
|
2008-02-06 01:33:35 +03:00
|
|
|
dbg_printf("restoring param (%s) state from file (%s/%s)\n",
|
2007-10-14 23:04:51 +04:00
|
|
|
param_name, path, param_name);
|
|
|
|
if (! SIM->restore_bochs_param(SIM->get_bochs_root(), path, param_name)) {
|
|
|
|
dbg_printf("Error: error occured during restore\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bx_sr_after_restore_state();
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-10-22 01:28:20 +04:00
|
|
|
void bx_dbg_disassemble_current(const char *format)
|
|
|
|
{
|
2008-02-15 22:03:54 +03:00
|
|
|
Bit64u addr = bx_dbg_get_laddr(bx_dbg_get_selector_value(BX_DBG_SREG_CS),
|
|
|
|
BX_CPU(dbg_cpu)->get_instruction_pointer());
|
2006-10-22 01:28:20 +04:00
|
|
|
bx_dbg_disassemble_command(format, addr, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_disassemble_command(const char *format, Bit64u from, Bit64u to)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
int numlines = INT_MAX;
|
|
|
|
|
2006-10-22 01:28:20 +04:00
|
|
|
if (from > to) {
|
2009-04-07 20:12:19 +04:00
|
|
|
Bit64u temp = from;
|
2006-10-22 01:28:20 +04:00
|
|
|
from = to;
|
|
|
|
to = temp;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (format) {
|
|
|
|
// format always begins with '/' (checked in lexer)
|
|
|
|
// so we won't bother checking it here second time.
|
|
|
|
numlines = atoi(format + 1);
|
2006-10-22 01:28:20 +04:00
|
|
|
if (to == from)
|
|
|
|
to = BX_MAX_BIT64U; // Disassemble just X lines
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned dis_size = bx_debugger.disassemble_size;
|
|
|
|
if (dis_size == 0) {
|
|
|
|
dis_size = 16; // until otherwise proven
|
|
|
|
if (BX_CPU(dbg_cpu)->sregs[BX_SEG_REG_CS].cache.u.segment.d_b)
|
|
|
|
dis_size = 32;
|
|
|
|
if (BX_CPU(dbg_cpu)->get_cpu_mode() == BX_MODE_LONG_64)
|
|
|
|
dis_size = 64;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
do {
|
|
|
|
numlines--;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-10-22 01:28:20 +04:00
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, from, 16, bx_disasm_ibuf)) break;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-03 01:33:32 +03:00
|
|
|
unsigned ilen = bx_disassemble.disasm(dis_size==32, dis_size==64,
|
2006-02-11 22:46:03 +03:00
|
|
|
(bx_address)(-1), (bx_address)(-1), bx_disasm_ibuf, bx_disasm_tbuf);
|
2005-12-14 23:05:40 +03:00
|
|
|
|
2009-05-03 23:21:38 +04:00
|
|
|
const char *Sym=bx_dbg_disasm_symbolic_address((Bit32u)from, 0);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-10-22 01:28:20 +04:00
|
|
|
dbg_printf("%08x: ", (unsigned) from);
|
2006-02-03 01:33:32 +03:00
|
|
|
dbg_printf("(%20s): ", Sym?Sym:"");
|
|
|
|
dbg_printf("%-25s ; ", bx_disasm_tbuf);
|
|
|
|
|
|
|
|
for (unsigned j=0; j<ilen; j++)
|
|
|
|
dbg_printf("%02x", (unsigned) bx_disasm_ibuf[j]);
|
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-10-22 01:28:20 +04:00
|
|
|
from += ilen;
|
|
|
|
} while ((from < to) && numlines > 0);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-04-08 22:30:34 +04:00
|
|
|
void bx_dbg_instrument_command(const char *comm)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
#if BX_INSTRUMENTATION
|
2009-07-03 19:05:44 +04:00
|
|
|
dbg_printf("Command '%s' passed to instrumentation module\n", comm);
|
2009-07-07 08:56:07 +04:00
|
|
|
BX_INSTR_DEBUG_CMD(comm);
|
2003-11-28 18:07:29 +03:00
|
|
|
#else
|
2005-04-08 22:30:34 +04:00
|
|
|
UNUSED(comm);
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: instrumentation not enabled.\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_doit_command(unsigned n)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
// generic command to add temporary hacks to
|
|
|
|
// for debugging purposes
|
|
|
|
bx_dbg.interrupts = n;
|
|
|
|
bx_dbg.exceptions = n;
|
|
|
|
}
|
|
|
|
|
2007-10-09 23:49:23 +04:00
|
|
|
void bx_dbg_crc_command(bx_phy_address addr1, bx_phy_address addr2)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
Bit32u crc1;
|
|
|
|
|
|
|
|
if (addr1 >= addr2) {
|
2006-10-22 01:28:20 +04:00
|
|
|
dbg_printf("Error: crc32: invalid range\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-01-28 19:16:03 +03:00
|
|
|
if (!BX_MEM(0)->dbg_crc32(addr1, addr2, &crc1)) {
|
2006-10-22 01:28:20 +04:00
|
|
|
dbg_printf("Error: could not crc32 memory\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("0x%lx\n", crc1);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2009-10-02 14:16:04 +04:00
|
|
|
void bx_dbg_print_descriptor(Bit32u lo, Bit32u hi)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-06-22 20:44:37 +04:00
|
|
|
Bit32u base = ((lo >> 16) & 0xffff)
|
2003-11-28 18:07:29 +03:00
|
|
|
| ((hi << 16) & 0xff0000)
|
|
|
|
| (hi & 0xff000000);
|
2006-06-22 20:44:37 +04:00
|
|
|
Bit32u limit = (hi & 0x000f0000) | (lo & 0xffff);
|
|
|
|
Bit32u segment = (lo >> 16) & 0xffff;
|
|
|
|
Bit32u offset = (lo & 0xffff) | (hi & 0xffff0000);
|
2008-12-16 22:26:57 +03:00
|
|
|
unsigned type = (hi >> 8) & 0xf;
|
|
|
|
unsigned dpl = (hi >> 13) & 0x3;
|
|
|
|
unsigned s = (hi >> 12) & 0x1;
|
|
|
|
unsigned d_b = (hi >> 22) & 0x1;
|
|
|
|
unsigned g = (hi >> 23) & 0x1;
|
2012-06-14 22:56:47 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
unsigned l = (hi >> 21) & 0x1;
|
|
|
|
#endif
|
2008-12-16 22:26:57 +03:00
|
|
|
|
2006-02-05 22:48:29 +03:00
|
|
|
// 32-bit trap gate, target=0010:c0108ec4, DPL=0, present=1
|
|
|
|
// code segment, base=0000:00cfffff, length=0xffff
|
2003-11-28 18:07:29 +03:00
|
|
|
if (s) {
|
2008-02-06 01:33:35 +03:00
|
|
|
// either a code or a data segment. bit 11 (type file MSB) then says
|
2003-11-28 18:07:29 +03:00
|
|
|
// 0=data segment, 1=code seg
|
2012-06-14 22:56:47 +04:00
|
|
|
if (IS_CODE_SEGMENT(type)) {
|
2012-06-15 18:17:17 +04:00
|
|
|
dbg_printf("Code segment, base=0x%08x, limit=0x%08x, %s, %s%s",
|
2009-08-07 12:26:41 +04:00
|
|
|
base, g ? (limit * 4096 + 4095) : limit,
|
2012-06-14 22:56:47 +04:00
|
|
|
IS_CODE_SEGMENT_READABLE(type) ? "Execute/Read" : "Execute-Only",
|
2012-06-15 18:17:17 +04:00
|
|
|
IS_CODE_SEGMENT_CONFORMING(type)? "Conforming" : "Non-Conforming",
|
2012-06-14 22:56:47 +04:00
|
|
|
IS_SEGMENT_ACCESSED(type)? ", Accessed" : "");
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (l && !d_b)
|
|
|
|
dbg_printf(", 64-bit\n");
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
dbg_printf(", %d-bit\n", d_b ? 32 : 16);
|
2003-11-28 18:07:29 +03:00
|
|
|
} else {
|
2009-10-02 14:16:04 +04:00
|
|
|
dbg_printf("Data segment, base=0x%08x, limit=0x%08x, %s%s%s\n",
|
2009-08-07 12:26:41 +04:00
|
|
|
base, g ? (limit * 4096 + 4095) : limit,
|
2012-06-14 22:56:47 +04:00
|
|
|
IS_DATA_SEGMENT_WRITEABLE(type)? "Read/Write" : "Read-Only",
|
|
|
|
IS_DATA_SEGMENT_EXPAND_DOWN(type)? ", Expand-down" : "",
|
|
|
|
IS_SEGMENT_ACCESSED(type)? ", Accessed" : "");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// types from IA32-devel-guide-3, page 3-15.
|
2009-01-31 00:47:42 +03:00
|
|
|
static const char *undef = "???";
|
|
|
|
static const char *type_names[16] = {
|
2008-12-16 22:26:57 +03:00
|
|
|
undef,
|
|
|
|
"16-Bit TSS (available)",
|
|
|
|
"LDT",
|
|
|
|
"16-Bit TSS (Busy)",
|
|
|
|
"16-Bit Call Gate",
|
|
|
|
"Task Gate",
|
|
|
|
"16-Bit Interrupt Gate",
|
|
|
|
"16-Bit Trap Gate",
|
|
|
|
undef,
|
|
|
|
"32-Bit TSS (Available)",
|
|
|
|
undef,
|
|
|
|
"32-Bit TSS (Busy)",
|
|
|
|
"32-Bit Call Gate",
|
|
|
|
undef,
|
|
|
|
"32-Bit Interrupt Gate",
|
|
|
|
"32-Bit Trap Gate"
|
|
|
|
};
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s ", type_names[type]);
|
2003-11-28 18:07:29 +03:00
|
|
|
// only print more if type is valid
|
|
|
|
if (type_names[type] == undef) {
|
2006-06-22 20:44:37 +04:00
|
|
|
dbg_printf("descriptor hi=0x%08x, lo=0x%08x", hi, lo);
|
2003-11-28 18:07:29 +03:00
|
|
|
} else {
|
|
|
|
// for call gates, print segment:offset and parameter count p.4-15
|
|
|
|
// for task gate, only present,dpl,TSS segment selector exist. p.5-13
|
|
|
|
// for interrupt gate, segment:offset,p,dpl
|
|
|
|
// for trap gate, segment:offset,p,dpl
|
|
|
|
// for TSS, base address and segment limit
|
|
|
|
switch (type) {
|
2006-06-22 20:44:37 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
2008-12-16 22:26:57 +03:00
|
|
|
dbg_printf("at 0x%08x, length 0x%05x", base, limit);
|
2005-04-08 22:30:34 +04:00
|
|
|
break;
|
2006-06-22 20:44:37 +04:00
|
|
|
case BX_SYS_SEGMENT_LDT:
|
2005-04-08 22:30:34 +04:00
|
|
|
// it's an LDT. not much to print.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// task, int, trap, or call gate.
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("target=0x%04x:0x%08x, DPL=%d", segment, offset, dpl);
|
2008-12-16 22:26:57 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbg_printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2009-10-02 14:16:04 +04:00
|
|
|
void bx_dbg_print_descriptor64(Bit32u lo1, Bit32u hi1, Bit32u lo2, Bit32u hi2)
|
2008-12-16 22:26:57 +03:00
|
|
|
{
|
|
|
|
Bit32u segment = (lo1 >> 16) & 0xffff;
|
|
|
|
Bit64u offset = (lo1 & 0xffff) | (hi1 & 0xffff0000) | ((Bit64u)(lo2) << 32);
|
|
|
|
unsigned type = (hi1 >> 8) & 0xf;
|
|
|
|
unsigned dpl = (hi1 >> 13) & 0x3;
|
|
|
|
unsigned s = (hi1 >> 12) & 0x1;
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
dbg_printf("bx_dbg_print_descriptor64: only system entries displayed in 64bit mode\n");
|
|
|
|
}
|
|
|
|
else {
|
2009-01-31 00:47:42 +03:00
|
|
|
static const char *undef = "???";
|
|
|
|
static const char *type_names[16] = {
|
2008-12-16 22:26:57 +03:00
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
"LDT",
|
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
"64-Bit TSS (Available)",
|
|
|
|
undef,
|
|
|
|
"64-Bit TSS (Busy)",
|
|
|
|
"64-Bit Call Gate",
|
|
|
|
undef,
|
|
|
|
"64-Bit Interrupt Gate",
|
|
|
|
"64-Bit Trap Gate"
|
|
|
|
};
|
|
|
|
dbg_printf("%s ", type_names[type]);
|
|
|
|
// only print more if type is valid
|
|
|
|
if (type_names[type] == undef) {
|
|
|
|
dbg_printf("\ndescriptor dword2 hi=0x%08x, lo=0x%08x", hi2, lo2);
|
|
|
|
dbg_printf("\n dword1 hi=0x%08x, lo=0x%08x", hi1, lo1);
|
|
|
|
} else {
|
|
|
|
// for call gates, print segment:offset and parameter count p.4-15
|
|
|
|
// for task gate, only present,dpl,TSS segment selector exist. p.5-13
|
|
|
|
// for interrupt gate, segment:offset,p,dpl
|
|
|
|
// for trap gate, segment:offset,p,dpl
|
|
|
|
// for TSS, base address and segment limit
|
|
|
|
switch (type) {
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
|
|
|
// don't print nothing about 64-bit TSS
|
|
|
|
break;
|
|
|
|
case BX_SYS_SEGMENT_LDT:
|
|
|
|
// it's an LDT. not much to print.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// task, int, trap, or call gate.
|
|
|
|
dbg_printf("target=0x%04x:"FMT_ADDRX", DPL=%d", segment, offset, dpl);
|
|
|
|
break;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-16 22:26:57 +03:00
|
|
|
#endif
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-14 00:32:21 +03:00
|
|
|
void bx_dbg_info_idt_command(unsigned from, unsigned to)
|
2005-03-26 22:41:59 +03:00
|
|
|
{
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_dbg_global_sreg_t idtr;
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_idtr(&idtr);
|
2006-02-14 00:32:21 +03:00
|
|
|
bx_bool all = 0;
|
|
|
|
|
|
|
|
if (to == (unsigned) EMPTY_ARG) {
|
|
|
|
to = from;
|
|
|
|
if(from == (unsigned) EMPTY_ARG) { from = 0; to = 255; all = 1; }
|
|
|
|
}
|
|
|
|
if (from > 255 || to > 255) {
|
|
|
|
dbg_printf("IDT entry should be [0-255], 'info idt' command malformed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from > to) {
|
|
|
|
unsigned temp = from;
|
|
|
|
from = to;
|
|
|
|
to = temp;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:26:57 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-12-16 22:28:19 +03:00
|
|
|
if (BX_CPU(dbg_cpu)->long_mode()) {
|
2008-12-16 22:26:57 +03:00
|
|
|
dbg_printf("Interrupt Descriptor Table (base=0x" FMT_ADDRX ", limit=%d):\n", idtr.base, idtr.limit);
|
|
|
|
for (unsigned n = from; n<=to; n++) {
|
|
|
|
Bit8u entry[16];
|
|
|
|
if (16*n + 15 > idtr.limit) break;
|
|
|
|
if (bx_dbg_read_linear(dbg_cpu, idtr.base + 16*n, 16, entry)) {
|
|
|
|
dbg_printf("IDT[0x%02x]=", n);
|
2009-10-02 14:16:04 +04:00
|
|
|
|
|
|
|
Bit32u lo1 = (entry[3] << 24) | (entry[2] << 16) | (entry[1] << 8) | (entry[0]);
|
|
|
|
Bit32u hi1 = (entry[7] << 24) | (entry[6] << 16) | (entry[5] << 8) | (entry[4]);
|
|
|
|
Bit32u lo2 = (entry[11] << 24) | (entry[10] << 16) | (entry[9] << 8) | (entry[8]);
|
|
|
|
Bit32u hi2 = (entry[15] << 24) | (entry[14] << 16) | (entry[13] << 8) | (entry[12]);
|
|
|
|
|
|
|
|
bx_dbg_print_descriptor64(lo1, hi1, lo2, hi2);
|
2008-12-16 22:26:57 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("error: IDTR+16*%d points to invalid linear address 0x" FMT_ADDRX "\n", n, idtr.base);
|
|
|
|
}
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
2008-12-16 22:26:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
dbg_printf("Interrupt Descriptor Table (base=0x" FMT_ADDRX ", limit=%d):\n", idtr.base, idtr.limit);
|
|
|
|
for (unsigned n = from; n<=to; n++) {
|
|
|
|
Bit8u entry[8];
|
|
|
|
if (8*n + 7 > idtr.limit) break;
|
|
|
|
if (bx_dbg_read_linear(dbg_cpu, idtr.base + 8*n, 8, entry)) {
|
|
|
|
dbg_printf("IDT[0x%02x]=", n);
|
2009-10-02 14:16:04 +04:00
|
|
|
|
|
|
|
Bit32u lo = (entry[3] << 24) | (entry[2] << 16) | (entry[1] << 8) | (entry[0]);
|
|
|
|
Bit32u hi = (entry[7] << 24) | (entry[6] << 16) | (entry[5] << 8) | (entry[4]);
|
|
|
|
|
|
|
|
bx_dbg_print_descriptor(lo, hi);
|
2008-12-16 22:26:57 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("error: IDTR+8*%d points to invalid linear address 0x" FMT_ADDRX "\n", n, idtr.base);
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-16 22:26:57 +03:00
|
|
|
|
2006-02-14 00:32:21 +03:00
|
|
|
if (all)
|
|
|
|
dbg_printf("You can list individual entries with 'info idt [NUM]' or groups with 'info idt [NUM] [NUM]'\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-14 00:32:21 +03:00
|
|
|
void bx_dbg_info_gdt_command(unsigned from, unsigned to)
|
2005-03-26 22:41:59 +03:00
|
|
|
{
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_dbg_global_sreg_t gdtr;
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_gdtr(&gdtr);
|
2006-02-14 00:32:21 +03:00
|
|
|
bx_bool all = 0;
|
|
|
|
|
|
|
|
if (to == (unsigned) EMPTY_ARG) {
|
|
|
|
to = from;
|
|
|
|
if(from == (unsigned) EMPTY_ARG) { from = 0; to = 0xffff; all = 1; }
|
|
|
|
}
|
|
|
|
if (from > 0xffff || to > 0xffff) {
|
2008-04-26 01:08:58 +04:00
|
|
|
dbg_printf("GDT entry should be [0-65535], 'info gdt' command malformed\n");
|
2006-02-14 00:32:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from > to) {
|
|
|
|
unsigned temp = from;
|
|
|
|
from = to;
|
|
|
|
to = temp;
|
|
|
|
}
|
|
|
|
|
2007-05-12 23:19:15 +04:00
|
|
|
dbg_printf("Global Descriptor Table (base=0x" FMT_ADDRX ", limit=%d):\n", gdtr.base, gdtr.limit);
|
2006-02-14 00:32:21 +03:00
|
|
|
for (unsigned n = from; n<=to; n++) {
|
|
|
|
Bit8u entry[8];
|
2007-05-12 23:19:15 +04:00
|
|
|
if (8*n + 7 > gdtr.limit) break;
|
2006-06-11 20:40:37 +04:00
|
|
|
if (bx_dbg_read_linear(dbg_cpu, gdtr.base + 8*n, 8, entry)) {
|
2006-02-03 01:33:32 +03:00
|
|
|
dbg_printf("GDT[0x%02x]=", n);
|
2009-10-02 14:16:04 +04:00
|
|
|
|
|
|
|
Bit32u lo = (entry[3] << 24) | (entry[2] << 16) | (entry[1] << 8) | (entry[0]);
|
|
|
|
Bit32u hi = (entry[7] << 24) | (entry[6] << 16) | (entry[5] << 8) | (entry[4]);
|
|
|
|
|
|
|
|
bx_dbg_print_descriptor(lo, hi);
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-05-11 00:33:39 +04:00
|
|
|
dbg_printf("error: GDTR+8*%d points to invalid linear address 0x" FMT_ADDRX "\n",
|
2006-06-11 20:40:37 +04:00
|
|
|
n, gdtr.base);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-14 00:32:21 +03:00
|
|
|
if (all)
|
|
|
|
dbg_printf("You can list individual entries with 'info gdt [NUM]' or groups with 'info gdt [NUM] [NUM]'\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-14 00:32:21 +03:00
|
|
|
void bx_dbg_info_ldt_command(unsigned from, unsigned to)
|
2005-03-26 22:41:59 +03:00
|
|
|
{
|
2008-04-26 01:08:58 +04:00
|
|
|
bx_address ldtr_base = SIM->get_param_num("LDTR.base", dbg_cpu_list)->get64();
|
2009-04-30 22:58:44 +04:00
|
|
|
Bit32u ldtr_limit = SIM->get_param_num("LDTR.limit_scaled", dbg_cpu_list)->get();
|
2008-04-26 01:08:58 +04:00
|
|
|
|
|
|
|
bx_bool all = 0;
|
|
|
|
|
|
|
|
if (to == (unsigned) EMPTY_ARG) {
|
|
|
|
to = from;
|
|
|
|
if(from == (unsigned) EMPTY_ARG) { from = 0; to = 0xffff; all = 1; }
|
|
|
|
}
|
|
|
|
if (from > 0xffff || to > 0xffff) {
|
|
|
|
dbg_printf("LDT entry should be [0-65535], 'info ldt' command malformed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from > to) {
|
|
|
|
unsigned temp = from;
|
|
|
|
from = to;
|
|
|
|
to = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbg_printf("Local Descriptor Table (base=0x" FMT_ADDRX ", limit=%d):\n", ldtr_base, ldtr_limit);
|
|
|
|
for (unsigned n = from; n<=to; n++) {
|
|
|
|
Bit8u entry[8];
|
|
|
|
if (8*n + 7 > ldtr_limit) break;
|
|
|
|
if (bx_dbg_read_linear(dbg_cpu, ldtr_base + 8*n, 8, entry)) {
|
|
|
|
dbg_printf("LDT[0x%02x]=", n);
|
2009-10-02 14:16:04 +04:00
|
|
|
|
|
|
|
Bit32u lo = (entry[3] << 24) | (entry[2] << 16) | (entry[1] << 8) | (entry[0]);
|
|
|
|
Bit32u hi = (entry[7] << 24) | (entry[6] << 16) | (entry[5] << 8) | (entry[4]);
|
|
|
|
|
|
|
|
bx_dbg_print_descriptor(lo, hi);
|
2008-04-26 01:08:58 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-05-11 00:33:39 +04:00
|
|
|
dbg_printf("error: LDTR+8*%d points to invalid linear address 0x" FMT_ADDRX "\n",
|
2008-04-26 01:08:58 +04:00
|
|
|
n, ldtr_base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (all)
|
|
|
|
dbg_printf("You can list individual entries with 'info ldt [NUM]' or groups with 'info ldt [NUM] [NUM]'\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-14 00:32:21 +03:00
|
|
|
/*form RB list*/
|
2008-06-12 00:29:30 +04:00
|
|
|
static const char* bx_dbg_ivt_desc(int intnum)
|
2008-02-06 01:33:35 +03:00
|
|
|
{
|
2008-06-10 03:00:43 +04:00
|
|
|
const char* ret;
|
|
|
|
switch (intnum) {
|
|
|
|
case 0x00: ret = "DIVIDE ERROR" ; break;
|
|
|
|
case 0x01: ret = "SINGLE STEP" ; break;
|
|
|
|
case 0x02: ret = "NON-MASKABLE INTERRUPT" ; break;
|
|
|
|
case 0x03: ret = "BREAKPOINT" ; break;
|
|
|
|
case 0x04: ret = "INT0 DETECTED OVERFLOW" ; break;
|
|
|
|
case 0x05: ret = "BOUND RANGE EXCEED" ; break;
|
|
|
|
case 0x06: ret = "INVALID OPCODE" ; break;
|
|
|
|
case 0x07: ret = "PROCESSOR EXTENSION NOT AVAILABLE" ; break;
|
|
|
|
case 0x08: ret = "IRQ0 - SYSTEM TIMER" ; break;
|
|
|
|
case 0x09: ret = "IRQ1 - KEYBOARD DATA READY" ; break;
|
|
|
|
case 0x0a: ret = "IRQ2 - LPT2" ; break;
|
|
|
|
case 0x0b: ret = "IRQ3 - COM2" ; break;
|
|
|
|
case 0x0c: ret = "IRQ4 - COM1" ; break;
|
|
|
|
case 0x0d: ret = "IRQ5 - FIXED DISK" ; break;
|
|
|
|
case 0x0e: ret = "IRQ6 - DISKETTE CONTROLLER" ; break;
|
|
|
|
case 0x0f: ret = "IRQ7 - PARALLEL PRINTER" ; break;
|
|
|
|
case 0x10: ret = "VIDEO" ; break;
|
|
|
|
case 0x11: ret = "GET EQUIPMENT LIST" ; break;
|
|
|
|
case 0x12: ret = "GET MEMORY SIZE" ; break;
|
|
|
|
case 0x13: ret = "DISK" ; break;
|
|
|
|
case 0x14: ret = "SERIAL" ; break;
|
|
|
|
case 0x15: ret = "SYSTEM" ; break;
|
|
|
|
case 0x16: ret = "KEYBOARD" ; break;
|
|
|
|
case 0x17: ret = "PRINTER" ; break;
|
|
|
|
case 0x18: ret = "CASETTE BASIC" ; break;
|
|
|
|
case 0x19: ret = "BOOTSTRAP LOADER" ; break;
|
|
|
|
case 0x1a: ret = "TIME" ; break;
|
|
|
|
case 0x1b: ret = "KEYBOARD - CONTROL-BREAK HANDLER" ; break;
|
|
|
|
case 0x1c: ret = "TIME - SYSTEM TIMER TICK" ; break;
|
|
|
|
case 0x1d: ret = "SYSTEM DATA - VIDEO PARAMETER TABLES"; break;
|
|
|
|
case 0x1e: ret = "SYSTEM DATA - DISKETTE PARAMETERS" ; break;
|
|
|
|
case 0x1f: ret = "SYSTEM DATA - 8x8 GRAPHICS FONT" ; break;
|
|
|
|
case 0x70: ret = "IRQ8 - CMOS REAL-TIME CLOCK" ; break;
|
|
|
|
case 0x71: ret = "IRQ9 - REDIRECTED TO INT 0A BY BIOS" ; break;
|
|
|
|
case 0x72: ret = "IRQ10 - RESERVED" ; break;
|
|
|
|
case 0x73: ret = "IRQ11 - RESERVED" ; break;
|
|
|
|
case 0x74: ret = "IRQ12 - POINTING DEVICE" ; break;
|
|
|
|
case 0x75: ret = "IRQ13 - MATH COPROCESSOR EXCEPTION" ; break;
|
|
|
|
case 0x76: ret = "IRQ14 - HARD DISK CONTROLLER OPERATION COMPLETE"; break;
|
|
|
|
case 0x77: ret = "IRQ15 - SECONDARY IDE CONTROLLER OPERATION COMPLETE"; break;
|
|
|
|
default : ret = "" ; break;
|
2006-02-14 00:32:21 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_info_ivt_command(unsigned from, unsigned to)
|
2008-02-06 01:33:35 +03:00
|
|
|
{
|
2006-02-14 00:32:21 +03:00
|
|
|
unsigned char buff[4];
|
2009-11-20 15:02:57 +03:00
|
|
|
unsigned seg, off;
|
2006-02-14 00:32:21 +03:00
|
|
|
bx_bool all = 0;
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_dbg_global_sreg_t idtr;
|
2006-02-14 00:32:21 +03:00
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
BX_CPU(dbg_cpu)->dbg_get_idtr(&idtr);
|
2008-02-06 01:33:35 +03:00
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
if (! BX_CPU(dbg_cpu)->protected_mode())
|
2008-02-06 01:33:35 +03:00
|
|
|
{
|
2006-02-14 00:32:21 +03:00
|
|
|
if (to == (unsigned) EMPTY_ARG) {
|
|
|
|
to = from;
|
|
|
|
if(from == (unsigned) EMPTY_ARG) { from = 0; to = 255; all = 1; }
|
|
|
|
}
|
|
|
|
if (from > 255 || to > 255) {
|
|
|
|
dbg_printf("IVT entry should be [0-255], 'info ivt' command malformed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from > to) {
|
|
|
|
unsigned temp = from;
|
|
|
|
from = to;
|
|
|
|
to = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = from; i <= to; i++)
|
2008-02-06 01:33:35 +03:00
|
|
|
{
|
2009-11-20 15:02:57 +03:00
|
|
|
bx_dbg_read_linear(dbg_cpu, idtr.base + i*4, 4, buff);
|
|
|
|
seg = ((Bit32u) buff[3] << 8) | buff[2];
|
|
|
|
off = ((Bit32u) buff[1] << 8) | buff[0];
|
|
|
|
bx_dbg_read_linear(dbg_cpu, (seg << 4) + off, 1, buff);
|
|
|
|
dbg_printf("INT# %02x > %04X:%04X (0x%08x) %s%s\n", i, seg, off,
|
|
|
|
(unsigned) ((seg << 4) + off), bx_dbg_ivt_desc(i),
|
2006-02-14 00:32:21 +03:00
|
|
|
(buff[0] == 0xcf) ? " ; dummy iret" : "");
|
|
|
|
}
|
|
|
|
if (all) dbg_printf("You can list individual entries with 'info ivt [NUM]' or groups with 'info ivt [NUM] [NUM]'\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dbg_printf("cpu in protected mode, use info idt\n");
|
|
|
|
}
|
|
|
|
|
2008-04-20 00:01:09 +04:00
|
|
|
static void bx_dbg_print_tss(Bit8u *tss, int len)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (len<104) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Invalid tss length (limit must be greater then 103)\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("ss:esp(0): 0x%04x:0x%08x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit16u*)(tss+8), *(Bit32u*)(tss+4));
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("ss:esp(1): 0x%04x:0x%08x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit16u*)(tss+0x10), *(Bit32u*)(tss+0xc));
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("ss:esp(2): 0x%04x:0x%08x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit16u*)(tss+0x18), *(Bit32u*)(tss+0x14));
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("cr3: 0x%08x\n", *(Bit32u*)(tss+0x1c));
|
|
|
|
dbg_printf("eip: 0x%08x\n", *(Bit32u*)(tss+0x20));
|
|
|
|
dbg_printf("eflags: 0x%08x\n", *(Bit32u*)(tss+0x24));
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("cs: 0x%04x ds: 0x%04x ss: 0x%04x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit16u*)(tss+76), *(Bit16u*)(tss+84), *(Bit16u*)(tss+80));
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("es: 0x%04x fs: 0x%04x gs: 0x%04x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit16u*)(tss+72), *(Bit16u*)(tss+88), *(Bit16u*)(tss+92));
|
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("eax: 0x%08x ebx: 0x%08x ecx: 0x%08x edx: 0x%08x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit32u*)(tss+0x28), *(Bit32u*)(tss+0x34), *(Bit32u*)(tss+0x2c), *(Bit32u*)(tss+0x30));
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("esi: 0x%08x edi: 0x%08x ebp: 0x%08x esp: 0x%08x\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
*(Bit32u*)(tss+0x40), *(Bit32u*)(tss+0x44), *(Bit32u*)(tss+0x3c), *(Bit32u*)(tss+0x38));
|
|
|
|
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("ldt: 0x%04x\n", *(Bit16u*)(tss+0x60));
|
|
|
|
dbg_printf("i/o map: 0x%04x\n", *(Bit16u*)(tss+0x66));
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-02-14 00:32:21 +03:00
|
|
|
void bx_dbg_info_tss_command(void)
|
2006-01-27 22:50:00 +03:00
|
|
|
{
|
2006-06-11 20:40:37 +04:00
|
|
|
bx_dbg_sreg_t tr;
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_tr(&tr);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-10-29 18:49:50 +03:00
|
|
|
bx_address base = (tr.des_l>>16) |
|
|
|
|
((tr.des_h<<16)&0x00ff0000) | (tr.des_h & 0xff000000);
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
base |= (Bit64u)(tr.dword3) << 32;
|
|
|
|
#endif
|
2006-06-11 20:40:37 +04:00
|
|
|
Bit32u len = (tr.des_l & 0xffff) + 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-10-29 18:49:50 +03:00
|
|
|
dbg_printf("tr:s=0x%x, base=0x" FMT_ADDRX ", valid=%u\n",
|
|
|
|
(unsigned) tr.sel, base, (unsigned) tr.valid);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_phy_address paddr = 0;
|
2009-10-29 18:49:50 +03:00
|
|
|
if (BX_CPU(dbg_cpu)->dbg_xlate_linear2phy(base, &paddr)) {
|
2009-10-16 01:24:22 +04:00
|
|
|
bx_dbg_print_tss(BX_MEM(0)->get_vector(paddr), len);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dbg_printf("bx_dbg_info_tss_command: failed to get physical address for TSS.BASE !");
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-10 21:14:07 +04:00
|
|
|
* this implements the info device command in the debugger.
|
|
|
|
* info device - list devices supported by this command
|
|
|
|
* info device [string] - shows the state of device specified in string
|
2012-04-23 21:06:19 +04:00
|
|
|
* info device [string] [string] - shows the state of device with options
|
2003-11-28 18:07:29 +03:00
|
|
|
*/
|
2012-04-23 21:06:19 +04:00
|
|
|
void bx_dbg_info_device(const char *dev, const char *args)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2012-03-10 21:14:07 +04:00
|
|
|
debug_info_t *temp = NULL;
|
2012-04-23 21:06:19 +04:00
|
|
|
unsigned i, string_i;
|
|
|
|
int argc = 0;
|
|
|
|
char *argv[16];
|
|
|
|
char *ptr;
|
|
|
|
char string[512];
|
|
|
|
size_t len;
|
2004-08-24 14:15:56 +04:00
|
|
|
|
2012-03-10 21:14:07 +04:00
|
|
|
if (strlen(dev) == 0) {
|
|
|
|
if (bx_debug_info_list == NULL) {
|
|
|
|
dbg_printf("info device list: no device registered\n");
|
|
|
|
} else {
|
|
|
|
dbg_printf("devices supported by 'info device':\n\n");
|
|
|
|
temp = bx_debug_info_list;
|
|
|
|
while (temp) {
|
|
|
|
dbg_printf("%s\n", temp->name);
|
|
|
|
temp = temp->next;
|
|
|
|
}
|
|
|
|
dbg_printf("\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bx_dbg_info_find_device(dev, &temp)) {
|
|
|
|
if (temp->device != NULL) {
|
2012-04-23 21:06:19 +04:00
|
|
|
len = strlen(args);
|
|
|
|
memset(argv, 0, sizeof(argv));
|
|
|
|
if (len > 0) {
|
|
|
|
char *options = new char[len + 1];
|
|
|
|
strcpy(options, args);
|
|
|
|
ptr = strtok(options, ",");
|
|
|
|
while (ptr) {
|
|
|
|
string_i = 0;
|
|
|
|
for (i=0; i<strlen(ptr); i++) {
|
|
|
|
if (!isspace(ptr[i])) string[string_i++] = ptr[i];
|
|
|
|
}
|
|
|
|
string[string_i] = '\0';
|
|
|
|
if (argc < 16) {
|
|
|
|
argv[argc++] = strdup(string);
|
|
|
|
} else {
|
|
|
|
BX_PANIC (("too many parameters, max is 16\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
delete [] options;
|
|
|
|
}
|
|
|
|
temp->device->debug_dump(argc, argv);
|
|
|
|
for (i = 0; i < (unsigned)argc; i++) {
|
|
|
|
if (argv[i] != NULL) {
|
|
|
|
free(argv[i]);
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 21:14:07 +04:00
|
|
|
} else {
|
|
|
|
BX_PANIC(("info device: device pointer is NULL"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dbg_printf("info device: '%s' not found\n", dev);
|
|
|
|
}
|
2007-10-24 01:51:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
//
|
|
|
|
// Reports from various events
|
|
|
|
//
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_iac_report(unsigned vector, unsigned irq)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (bx_guard.report.irq) {
|
2006-04-29 13:27:49 +04:00
|
|
|
dbg_printf("event at t=" FMT_LL "d IRQ irq=%u vec=%x\n",
|
|
|
|
bx_pc_system.time_ticks(), irq, vector);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_a20_report(unsigned val)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (bx_guard.report.a20) {
|
2006-04-29 13:27:49 +04:00
|
|
|
dbg_printf("event at t=" FMT_LL "d A20 val=%u\n",
|
|
|
|
bx_pc_system.time_ticks(), val);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2007-10-09 23:49:23 +04:00
|
|
|
void bx_dbg_io_report(Bit32u port, unsigned size, unsigned op, Bit32u val)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (bx_guard.report.io) {
|
2006-04-29 13:27:49 +04:00
|
|
|
dbg_printf("event at t=" FMT_LL "d IO addr=0x%x size=%u op=%s val=0x%x\n",
|
|
|
|
bx_pc_system.time_ticks(),
|
2007-10-09 23:49:23 +04:00
|
|
|
port,
|
2003-11-28 18:07:29 +03:00
|
|
|
size,
|
|
|
|
(op==BX_READ) ? "read" : "write",
|
|
|
|
(unsigned) val);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2007-10-09 23:49:23 +04:00
|
|
|
void bx_dbg_dma_report(bx_phy_address addr, unsigned len, unsigned what, Bit32u val)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
if (bx_dbg_batch_dma.this_many == 0) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: DMA batch this_many=0.\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// if Q is full, post events (and flush)
|
|
|
|
if (bx_dbg_batch_dma.Qsize >= bx_dbg_batch_dma.this_many) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: DMA batch Q was not flushed.\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// if Q already has MAX elements in it
|
|
|
|
if (bx_dbg_batch_dma.Qsize >= BX_BATCH_DMA_BUFSIZE) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("%s: DMA batch buffer overrun.\n", argv0);
|
2003-11-28 18:07:29 +03:00
|
|
|
bx_dbg_exit(1);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
bx_dbg_batch_dma.Qsize++;
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_dbg_batch_dma.Q[bx_dbg_batch_dma.Qsize-1].addr = addr;
|
|
|
|
bx_dbg_batch_dma.Q[bx_dbg_batch_dma.Qsize-1].len = len;
|
|
|
|
bx_dbg_batch_dma.Q[bx_dbg_batch_dma.Qsize-1].what = what;
|
|
|
|
bx_dbg_batch_dma.Q[bx_dbg_batch_dma.Qsize-1].val = val;
|
|
|
|
bx_dbg_batch_dma.Q[bx_dbg_batch_dma.Qsize-1].time = bx_pc_system.time_ticks();
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// if Q is full, post events (and flush)
|
|
|
|
if (bx_dbg_batch_dma.Qsize >= bx_dbg_batch_dma.this_many)
|
|
|
|
bx_dbg_post_dma_reports();
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_post_dma_reports(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned addr, len, what, val;
|
|
|
|
unsigned last_addr, last_len, last_what;
|
|
|
|
unsigned print_header;
|
|
|
|
unsigned first_iteration;
|
|
|
|
|
|
|
|
if (bx_guard.report.dma) {
|
|
|
|
if (bx_dbg_batch_dma.Qsize == 0) return; // nothing batched to print
|
|
|
|
|
|
|
|
// compress output so all contiguous DMA ops of the same type and size
|
|
|
|
// are printed on the same line
|
|
|
|
last_addr = bx_dbg_batch_dma.Q[0].addr;
|
|
|
|
last_len = bx_dbg_batch_dma.Q[0].len;
|
|
|
|
last_what = bx_dbg_batch_dma.Q[0].what;
|
|
|
|
first_iteration = 1;
|
|
|
|
|
|
|
|
for (i=0; i<bx_dbg_batch_dma.Qsize; i++) {
|
|
|
|
addr = bx_dbg_batch_dma.Q[i].addr;
|
|
|
|
len = bx_dbg_batch_dma.Q[i].len;
|
|
|
|
what = bx_dbg_batch_dma.Q[i].what;
|
|
|
|
val = bx_dbg_batch_dma.Q[i].val;
|
|
|
|
|
|
|
|
if (len != last_len)
|
|
|
|
print_header = 1;
|
|
|
|
else if (what != last_what)
|
|
|
|
print_header = 1;
|
|
|
|
else if (addr != (last_addr + last_len))
|
|
|
|
print_header = 1;
|
|
|
|
else
|
|
|
|
print_header = 0;
|
|
|
|
|
|
|
|
// now store current values for next iteration
|
|
|
|
last_addr = addr;
|
|
|
|
last_len = len;
|
|
|
|
last_what = what;
|
|
|
|
|
|
|
|
if (print_header) {
|
|
|
|
if (!first_iteration) // need return from previous line
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
else
|
|
|
|
first_iteration = 0;
|
|
|
|
// need to output the event header
|
2006-04-29 13:27:49 +04:00
|
|
|
dbg_printf("event at t=" FMT_LL "d DMA addr=0x%x size=%u op=%s val=0x%x",
|
|
|
|
bx_pc_system.time_ticks(),
|
2006-01-24 22:03:55 +03:00
|
|
|
addr, len, (what==BX_READ) ? "read" : "write", val);
|
2003-11-28 18:07:29 +03:00
|
|
|
print_header = 0;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
|
|
|
// *no* need to output the event header
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf(" 0x%x", val);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
if (bx_dbg_batch_dma.Qsize)
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("\n");
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
// empty Q, regardless of whether reports are printed
|
|
|
|
bx_dbg_batch_dma.Qsize = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-11 23:47:22 +03:00
|
|
|
void bx_dbg_dump_table(void)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2007-10-09 23:49:23 +04:00
|
|
|
Bit32u lin, start_lin; // show only low 32 bit
|
|
|
|
bx_phy_address phy, start_phy; // start of a valid translation interval
|
2006-02-11 23:47:22 +03:00
|
|
|
bx_bool valid;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2007-07-09 18:57:33 +04:00
|
|
|
if (! BX_CPU(dbg_cpu)->cr0.get_PG()) {
|
2003-11-28 18:07:29 +03:00
|
|
|
printf("paging off\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-10 02:33:37 +04:00
|
|
|
printf("cr3: 0x"FMT_PHY_ADDRX"\n", BX_CPU(dbg_cpu)->cr3);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2008-02-06 01:33:35 +03:00
|
|
|
lin = 0;
|
|
|
|
phy = 0;
|
2006-02-11 23:47:22 +03:00
|
|
|
|
2006-01-28 18:10:33 +03:00
|
|
|
start_lin = 1;
|
2003-11-28 18:07:29 +03:00
|
|
|
start_phy = 2;
|
|
|
|
while(1) {
|
2006-06-17 16:09:55 +04:00
|
|
|
valid = BX_CPU(dbg_cpu)->dbg_xlate_linear2phy(lin, &phy);
|
2006-01-28 18:10:33 +03:00
|
|
|
if(valid) {
|
|
|
|
if((lin - start_lin) != (phy - start_phy)) {
|
2006-02-11 23:47:22 +03:00
|
|
|
if(start_lin != 1)
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("0x%08x-0x%08x -> 0x"FMT_PHY_ADDRX"-0x"FMT_PHY_ADDRX"\n",
|
2006-02-11 23:47:22 +03:00
|
|
|
start_lin, lin - 1, start_phy, start_phy + (lin-1-start_lin));
|
2006-01-28 18:10:33 +03:00
|
|
|
start_lin = lin;
|
2003-11-28 18:07:29 +03:00
|
|
|
start_phy = phy;
|
2005-03-26 22:41:59 +03:00
|
|
|
}
|
2006-01-28 18:10:33 +03:00
|
|
|
} else {
|
2006-02-11 23:47:22 +03:00
|
|
|
if(start_lin != 1)
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("0x%08x-0x%08x -> 0x"FMT_PHY_ADDRX"-0x"FMT_PHY_ADDRX"\n",
|
2006-02-11 23:47:22 +03:00
|
|
|
start_lin, lin - 1, start_phy, start_phy + (lin-1-start_lin));
|
2006-01-28 18:10:33 +03:00
|
|
|
start_lin = 1;
|
2005-03-26 22:41:59 +03:00
|
|
|
start_phy = 2;
|
2006-01-28 18:10:33 +03:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-01-28 18:10:33 +03:00
|
|
|
if(lin == 0xfffff000) break;
|
|
|
|
lin += 0x1000;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
2006-02-11 23:47:22 +03:00
|
|
|
if(start_lin != 1)
|
2008-05-10 02:33:37 +04:00
|
|
|
dbg_printf("0x%08x-0x%08x -> 0x"FMT_PHY_ADDRX"-0x"FMT_PHY_ADDRX"\n",
|
2006-02-11 23:47:22 +03:00
|
|
|
start_lin, 0xffffffff, start_phy, start_phy + (0xffffffff-start_lin));
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-01-24 22:03:55 +03:00
|
|
|
void bx_dbg_print_help(void)
|
2008-02-06 01:33:35 +03:00
|
|
|
{
|
2006-01-25 00:37:37 +03:00
|
|
|
dbg_printf("h|help - show list of debugger commands\n");
|
|
|
|
dbg_printf("h|help command - show short command description\n");
|
2006-01-24 22:03:55 +03:00
|
|
|
dbg_printf("-*- Debugger control -*-\n");
|
2006-01-31 22:45:34 +03:00
|
|
|
dbg_printf(" help, q|quit|exit, set, instrument, show, trace, trace-reg,\n");
|
2011-10-09 23:26:30 +04:00
|
|
|
dbg_printf(" trace-mem, u|disasm, ldsym, slist\n");
|
2006-01-24 22:03:55 +03:00
|
|
|
dbg_printf("-*- Execution control -*-\n");
|
2011-05-06 12:19:03 +04:00
|
|
|
dbg_printf(" c|cont|continue, s|step, p|n|next, modebp, vmexitbp\n");
|
2006-01-24 22:03:55 +03:00
|
|
|
dbg_printf("-*- Breakpoint management -*-\n");
|
|
|
|
dbg_printf(" vb|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,\n");
|
2009-11-20 15:02:57 +03:00
|
|
|
dbg_printf(" bpe, bpd, d|del|delete, watch, unwatch\n");
|
2006-01-24 22:03:55 +03:00
|
|
|
dbg_printf("-*- CPU and memory contents -*-\n");
|
2012-04-24 15:01:59 +04:00
|
|
|
dbg_printf(" x, xp, setpmem, writemem, crc, info,\n");
|
2009-12-28 16:44:32 +03:00
|
|
|
dbg_printf(" r|reg|regs|registers, fp|fpu, mmx, sse, sreg, dreg, creg,\n");
|
2009-11-20 15:02:57 +03:00
|
|
|
dbg_printf(" page, set, ptime, print-stack, ?|calc\n");
|
2007-10-14 23:04:51 +04:00
|
|
|
dbg_printf("-*- Working with bochs param tree -*-\n");
|
|
|
|
dbg_printf(" show \"param\", restore\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
void bx_dbg_calc_command(Bit64u value)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("0x" FMT_LL "x " FMT_LL "d\n", value, value);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-01-25 21:13:44 +03:00
|
|
|
Bit8u bx_dbg_get_reg8l_value(unsigned reg)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_reg8l(reg);
|
|
|
|
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 8BL register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit8u bx_dbg_get_reg8h_value(unsigned reg)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_reg8h(reg);
|
|
|
|
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 8BH register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit16u bx_dbg_get_reg16_value(unsigned reg)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_reg16(reg);
|
|
|
|
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 16B register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u bx_dbg_get_reg32_value(unsigned reg)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_reg32(reg);
|
|
|
|
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 32B register [%d] !!!\n", reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u bx_dbg_get_reg64_value(unsigned reg)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_X86_64
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS)
|
2006-02-13 21:28:14 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_reg64(reg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dbg_printf("Unknown 64B register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_reg8l_value(unsigned reg, Bit8u value)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
BX_CPU(dbg_cpu)->set_reg8l(reg, value);
|
|
|
|
else
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 8BL register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_reg8h_value(unsigned reg, Bit8u value)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
BX_CPU(dbg_cpu)->set_reg8h(reg, value);
|
|
|
|
else
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 8BH register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_reg16_value(unsigned reg, Bit16u value)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
BX_CPU(dbg_cpu)->set_reg16(reg, value);
|
|
|
|
else
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 16B register [%d] !!!\n", reg);
|
2006-01-25 21:13:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_reg32_value(unsigned reg, Bit32u value)
|
|
|
|
{
|
2011-09-25 21:36:20 +04:00
|
|
|
if (reg < 8 || (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS))
|
2006-01-25 21:13:44 +03:00
|
|
|
BX_CPU(dbg_cpu)->set_reg32(reg, value);
|
|
|
|
else
|
2006-02-13 21:28:14 +03:00
|
|
|
dbg_printf("Unknown 32B register [%d] !!!\n", reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_set_reg64_value(unsigned reg, Bit64u value)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_X86_64
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPU(dbg_cpu)->long64_mode() && reg < BX_GENERAL_REGISTERS)
|
2006-02-13 21:28:14 +03:00
|
|
|
BX_CPU(dbg_cpu)->set_reg64(reg, value);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
dbg_printf("Unknown 64B register [%d] !!!\n", reg);
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2012-11-07 00:01:02 +04:00
|
|
|
void bx_dbg_set_rip_value(bx_address value)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if ((value >> 32) != 0 && ! BX_CPU(dbg_cpu)->long64_mode()) {
|
|
|
|
dbg_printf("Cannot set EIP to 64-bit value hen not in long64 mode !\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
BX_CPU(dbg_cpu)->dbg_set_eip(value);
|
|
|
|
}
|
|
|
|
|
2005-03-26 22:41:59 +03:00
|
|
|
Bit16u bx_dbg_get_selector_value(unsigned int seg_no)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
|
|
|
bx_dbg_sreg_t sreg;
|
|
|
|
|
|
|
|
if (seg_no > 5) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: seg_no out of bounds\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BX_CPU(dbg_cpu)->dbg_get_sreg(&sreg, seg_no);
|
|
|
|
if (!sreg.valid) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("Error: segment valid bit cleared\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sreg.sel;
|
|
|
|
}
|
|
|
|
|
2006-01-31 22:45:34 +03:00
|
|
|
Bit16u bx_dbg_get_ip(void)
|
|
|
|
{
|
2008-02-15 22:03:54 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_ip();
|
2006-01-31 22:45:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u bx_dbg_get_eip(void)
|
|
|
|
{
|
2008-02-15 22:03:54 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_eip();
|
2006-01-31 22:45:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bx_address bx_dbg_get_instruction_pointer(void)
|
|
|
|
{
|
2008-02-15 22:03:54 +03:00
|
|
|
return BX_CPU(dbg_cpu)->get_instruction_pointer();
|
2006-01-31 22:45:34 +03:00
|
|
|
}
|
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
bx_bool bx_dbg_read_pmode_descriptor(Bit16u sel, bx_descriptor_t *descriptor)
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-12-27 19:38:09 +03:00
|
|
|
bx_selector_t selector;
|
|
|
|
Bit32u dword1, dword2;
|
|
|
|
bx_address desc_base;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
/* if selector is NULL, error */
|
|
|
|
if ((sel & 0xfffc) == 0) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: Dereferencing a NULL selector!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
/* parse fields in selector */
|
|
|
|
parse_selector(sel, &selector);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
if (selector.ti) {
|
|
|
|
// LDT
|
|
|
|
if (((Bit32u)selector.index*8 + 7) > BX_CPU(dbg_cpu)->ldtr.cache.u.segment.limit_scaled) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: selector (0x%04x) > LDT size limit\n", selector.index*8);
|
2008-04-12 01:59:47 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-12-27 19:38:09 +03:00
|
|
|
desc_base = BX_CPU(dbg_cpu)->ldtr.cache.u.segment.base;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// GDT
|
|
|
|
if (((Bit32u)selector.index*8 + 7) > BX_CPU(dbg_cpu)->gdtr.limit) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: selector (0x%04x) > GDT size limit\n", selector.index*8);
|
2008-04-12 01:59:47 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-12-27 19:38:09 +03:00
|
|
|
desc_base = BX_CPU(dbg_cpu)->gdtr.base;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, desc_base + selector.index * 8, 4, (Bit8u*) &dword1)) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: cannot read selector 0x%04x (index=0x%04x)\n", sel, selector.index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, desc_base + selector.index * 8 + 4, 4, (Bit8u*) &dword2)) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: cannot read selector 0x%04x (index=0x%04x)\n", sel, selector.index);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
memset (descriptor, 0, sizeof (descriptor));
|
2009-12-28 12:26:22 +03:00
|
|
|
parse_descriptor(dword1, dword2, descriptor);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
if (!descriptor->segment) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: selector 0x%04x points to a system descriptor and is not supported!\n", sel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* #NP(selector) if descriptor is not present */
|
|
|
|
if (descriptor->p==0) {
|
|
|
|
dbg_printf("bx_dbg_read_pmode_descriptor: descriptor 0x%04x not present!\n", sel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_dbg_load_segreg(unsigned seg_no, unsigned value)
|
|
|
|
{
|
|
|
|
bx_segment_reg_t sreg;
|
|
|
|
|
|
|
|
if (seg_no > 6) {
|
|
|
|
dbg_printf("bx_dbg_load_segreg: unknown segment register !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value > 0xffff) {
|
|
|
|
dbg_printf("bx_dbg_load_segreg: segment selector out of limits !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned cpu_mode = BX_CPU(dbg_cpu)->get_cpu_mode();
|
|
|
|
if (cpu_mode == BX_MODE_LONG_64) {
|
|
|
|
dbg_printf("bx_dbg_load_segreg: not supported in long64 mode !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! BX_CPU(dbg_cpu)->protected_mode()) {
|
|
|
|
parse_selector(value, &sreg.selector);
|
|
|
|
|
|
|
|
sreg.cache.valid = SegValidCache;
|
|
|
|
sreg.cache.p = 1;
|
|
|
|
sreg.cache.dpl = (cpu_mode == BX_MODE_IA32_V8086);
|
|
|
|
sreg.cache.segment = 1;
|
|
|
|
sreg.cache.type = BX_DATA_READ_WRITE_ACCESSED;
|
|
|
|
|
|
|
|
sreg.cache.u.segment.base = sreg.selector.value << 4;
|
|
|
|
sreg.cache.u.segment.limit_scaled = 0xffff;
|
|
|
|
sreg.cache.u.segment.g = 0;
|
|
|
|
sreg.cache.u.segment.d_b = 0;
|
|
|
|
sreg.cache.u.segment.avl = 0;
|
|
|
|
sreg.selector.rpl = (cpu_mode == BX_MODE_IA32_V8086);
|
|
|
|
|
|
|
|
BX_CPU(dbg_cpu)->dbg_set_sreg(seg_no, &sreg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parse_selector(value, &sreg.selector);
|
|
|
|
if (bx_dbg_read_pmode_descriptor(value, &sreg.cache)) {
|
|
|
|
BX_CPU(dbg_cpu)->dbg_set_sreg(seg_no, &sreg);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2009-12-27 19:38:09 +03:00
|
|
|
}
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
bx_address bx_dbg_get_laddr(Bit16u sel, bx_address ofs)
|
|
|
|
{
|
|
|
|
bx_address laddr;
|
|
|
|
|
|
|
|
if (BX_CPU(dbg_cpu)->protected_mode()) {
|
|
|
|
bx_descriptor_t descriptor;
|
2003-11-28 18:07:29 +03:00
|
|
|
Bit32u lowaddr, highaddr;
|
2006-06-12 20:58:27 +04:00
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
if (! bx_dbg_read_pmode_descriptor(sel, &descriptor))
|
|
|
|
return 0;
|
|
|
|
|
2006-06-12 20:58:27 +04:00
|
|
|
// expand-down
|
|
|
|
if (IS_DATA_SEGMENT(descriptor.type) && IS_DATA_SEGMENT_EXPAND_DOWN(descriptor.type)) {
|
|
|
|
lowaddr = descriptor.u.segment.limit_scaled;
|
2003-11-28 18:07:29 +03:00
|
|
|
highaddr = descriptor.u.segment.g ? 0xffffffff : 0xffff;
|
2006-06-12 20:58:27 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lowaddr = 0;
|
|
|
|
highaddr = descriptor.u.segment.limit_scaled;
|
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-10-16 00:50:33 +04:00
|
|
|
if (ofs < lowaddr || ofs > highaddr) {
|
2006-01-24 22:23:42 +03:00
|
|
|
dbg_printf("WARNING: Offset %08X is out of selector %04x limit (%08x...%08x)!\n",
|
2003-11-28 18:07:29 +03:00
|
|
|
ofs, sel, lowaddr, highaddr);
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2008-04-07 22:39:17 +04:00
|
|
|
laddr = descriptor.u.segment.base + ofs;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2003-11-28 18:07:29 +03:00
|
|
|
else {
|
2008-04-07 22:39:17 +04:00
|
|
|
laddr = sel * 16 + ofs;
|
2005-04-08 22:30:34 +04:00
|
|
|
}
|
2008-04-07 22:39:17 +04:00
|
|
|
|
|
|
|
return laddr;
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-06-09 16:26:34 +04:00
|
|
|
void bx_dbg_step_over_command()
|
2003-11-28 18:07:29 +03:00
|
|
|
{
|
2009-04-05 22:16:29 +04:00
|
|
|
bx_address laddr = BX_CPU(dbg_cpu)->guard_found.laddr;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2009-04-05 22:16:29 +04:00
|
|
|
if (! bx_dbg_read_linear(dbg_cpu, laddr, 16, bx_disasm_ibuf))
|
2006-02-05 22:48:29 +03:00
|
|
|
{
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-10 20:02:03 +03:00
|
|
|
x86_insn insn = bx_disassemble.decode(IS_CODE_32(BX_CPU(dbg_cpu)->guard_found.code_32_64),
|
|
|
|
IS_CODE_64(BX_CPU(dbg_cpu)->guard_found.code_32_64),
|
2008-02-06 01:33:35 +03:00
|
|
|
BX_CPU(dbg_cpu)->get_segment_base(BX_SEG_REG_CS),
|
2006-03-07 01:03:16 +03:00
|
|
|
BX_CPU(dbg_cpu)->guard_found.eip, bx_disasm_ibuf, bx_disasm_tbuf);
|
2003-11-28 18:07:29 +03:00
|
|
|
|
2006-02-05 22:48:29 +03:00
|
|
|
unsigned b1 = insn.b1;
|
2003-11-28 18:07:29 +03:00
|
|
|
|
|
|
|
switch(b1) {
|
|
|
|
// Jcc short
|
|
|
|
case 0x70:
|
|
|
|
case 0x71:
|
|
|
|
case 0x72:
|
|
|
|
case 0x73:
|
|
|
|
case 0x74:
|
|
|
|
case 0x75:
|
|
|
|
case 0x76:
|
|
|
|
case 0x77:
|
|
|
|
case 0x78:
|
|
|
|
case 0x79:
|
|
|
|
case 0x7A:
|
|
|
|
case 0x7B:
|
|
|
|
case 0x7C:
|
|
|
|
case 0x7D:
|
|
|
|
case 0x7E:
|
|
|
|
case 0x7F:
|
2008-02-06 01:33:35 +03:00
|
|
|
|
2003-11-28 18:07:29 +03:00
|
|
|
// Jcc near
|
|
|
|
case 0x180:
|
|
|
|
case 0x181:
|
|
|
|
case 0x182:
|
|
|
|
case 0x183:
|
|
|
|
case 0x184:
|
|
|
|
case 0x185:
|
|
|
|
case 0x186:
|
|
|
|
case 0x187:
|
|
|
|
case 0x188:
|
|
|
|
case 0x189:
|
|
|
|
case 0x18A:
|
|
|
|
case 0x18B:
|
|
|
|
case 0x18C:
|
|
|
|
case 0x18D:
|
|
|
|
case 0x18E:
|
|
|
|
case 0x18F:
|
|
|
|
|
|
|
|
// jcxz
|
|
|
|
case 0xE3:
|
|
|
|
|
|
|
|
// retn n
|
|
|
|
case 0xC2:
|
|
|
|
// retn
|
|
|
|
case 0xC3:
|
|
|
|
// retf n
|
|
|
|
case 0xCA:
|
|
|
|
// retf
|
|
|
|
case 0xCB:
|
|
|
|
// iret
|
|
|
|
case 0xCF:
|
|
|
|
|
|
|
|
// jmp near
|
|
|
|
case 0xE9:
|
|
|
|
// jmp far
|
|
|
|
case 0xEA:
|
|
|
|
// jmp short
|
|
|
|
case 0xEB:
|
2009-10-29 18:49:50 +03:00
|
|
|
bx_dbg_stepN_command(dbg_cpu, 1);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
// jmp absolute indirect
|
|
|
|
case 0xFF:
|
2006-02-05 22:48:29 +03:00
|
|
|
switch (insn.nnn) {
|
2003-11-28 18:07:29 +03:00
|
|
|
// near
|
|
|
|
case 4:
|
|
|
|
// far
|
|
|
|
case 5:
|
2009-10-29 18:49:50 +03:00
|
|
|
bx_dbg_stepN_command(dbg_cpu, 1);
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calls, ints, loops and so on
|
2009-04-05 22:16:29 +04:00
|
|
|
int BpId = bx_dbg_lbreakpoint_command(bkStepOver, laddr + insn.ilen);
|
2006-02-03 01:33:32 +03:00
|
|
|
if (BpId == -1) {
|
|
|
|
dbg_printf("bx_dbg_step_over_command:: Failed to set lbreakpoint !\n");
|
2003-11-28 18:07:29 +03:00
|
|
|
return;
|
2006-02-03 01:33:32 +03:00
|
|
|
}
|
2008-02-06 01:33:35 +03:00
|
|
|
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_dbg_continue_command();
|
2008-02-06 01:33:35 +03:00
|
|
|
|
2009-04-05 22:16:29 +04:00
|
|
|
if (bx_dbg_del_lbreak(BpId))
|
2006-04-29 13:27:49 +04:00
|
|
|
bx_dbg_breakpoint_changed();
|
2003-11-28 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2005-02-02 00:17:57 +03:00
|
|
|
#endif /* if BX_DEBUGGER */
|