2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2008-02-16 01:05:43 +03:00
|
|
|
// $Id: iodebug.cc,v 1.25 2008-02-15 22:05:42 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-06-19 19:20:15 +04:00
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "bochs.h"
|
|
|
|
#include "cpu/cpu.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2001-09-14 18:29:21 +04:00
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
#define BX_IODEBUG_THIS this->
|
2001-09-15 04:12:40 +04:00
|
|
|
|
2001-09-14 18:29:21 +04:00
|
|
|
bx_iodebug_c bx_iodebug;
|
2001-09-15 02:38:06 +04:00
|
|
|
|
|
|
|
struct bx_iodebug_s_type {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool enabled;
|
2006-03-03 15:55:37 +03:00
|
|
|
unsigned register_select;
|
2001-09-15 02:38:06 +04:00
|
|
|
Bit32u registers[2];
|
|
|
|
Bit32u monitored_mem_areas_start[BX_IODEBUG_MAX_AREAS];
|
|
|
|
Bit32u monitored_mem_areas_end[BX_IODEBUG_MAX_AREAS];
|
|
|
|
} bx_iodebug_s;
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
bx_iodebug_c::bx_iodebug_c()
|
2001-09-14 18:29:21 +04:00
|
|
|
{
|
2006-11-01 18:44:38 +03:00
|
|
|
put("IODBG");
|
2001-09-14 18:29:21 +04:00
|
|
|
settype(IODEBUGLOG);
|
|
|
|
}
|
|
|
|
|
2002-10-26 07:53:22 +04:00
|
|
|
void bx_iodebug_c::init(void)
|
2001-09-14 18:29:21 +04:00
|
|
|
{
|
2006-11-01 18:44:38 +03:00
|
|
|
DEV_register_ioread_handler(this, read_handler, 0x8A00,"BOCHS IODEBUG", 2);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, 0x8A00,"BOCHS IODEBUG", 2);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, 0x8A01,"BOCHS IODEBUG", 2);
|
2001-09-14 18:29:21 +04:00
|
|
|
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.enabled = 0;
|
|
|
|
bx_iodebug_s.register_select = 0;
|
2006-03-03 15:55:37 +03:00
|
|
|
|
|
|
|
for(int i=0;i<BX_IODEBUG_MAX_AREAS;i++) {
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.monitored_mem_areas_start[i] = 0;
|
|
|
|
bx_iodebug_s.monitored_mem_areas_end[i] = 0;
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
2001-09-14 18:29:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u bx_iodebug_c::read_handler(void *this_ptr, Bit32u addr, unsigned io_len)
|
|
|
|
{
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_iodebug_c *bx_iodebug_ptr = (bx_iodebug_c *) this_ptr;
|
2006-03-03 15:55:37 +03:00
|
|
|
return bx_iodebug_ptr->read(addr, io_len);
|
2001-09-14 18:29:21 +04:00
|
|
|
}
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
Bit32u bx_iodebug_c::read(Bit32u addr, unsigned io_len)
|
2001-09-14 18:29:21 +04:00
|
|
|
{
|
2006-11-01 18:44:38 +03:00
|
|
|
if (bx_iodebug_s.enabled) return 0x8A00;
|
2001-09-14 20:21:02 +04:00
|
|
|
return(0);
|
2001-09-14 18:29:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_iodebug_c::write_handler(void *this_ptr, Bit32u addr, Bit32u dvalue, unsigned io_len)
|
|
|
|
{
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_iodebug_c *bx_iodebug_ptr = (bx_iodebug_c *) this_ptr;
|
2006-03-03 15:55:37 +03:00
|
|
|
bx_iodebug_ptr->write(addr, dvalue, io_len);
|
2001-09-14 18:29:21 +04:00
|
|
|
}
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
void bx_iodebug_c::write(Bit32u addr, Bit32u dvalue, unsigned io_len)
|
2001-09-14 18:29:21 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
// fprintf(stderr, "IODEBUG addr: %4x\tdvalue: %8x\tio_len: %8x\n", (unsigned) addr, (unsigned) dvalue, io_len);
|
2001-09-14 20:21:02 +04:00
|
|
|
|
2006-11-01 18:44:38 +03:00
|
|
|
if (addr == 0x8A01)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.registers[bx_iodebug_s.register_select] =
|
|
|
|
(bx_iodebug_s.registers[bx_iodebug_s.register_select] << 16) +
|
2006-03-03 15:55:37 +03:00
|
|
|
(dvalue & 0xFFFF);
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
|
|
|
|
2006-11-01 18:44:38 +03:00
|
|
|
if (addr != 0x8A00) return;
|
2001-09-14 20:21:02 +04:00
|
|
|
|
2006-11-01 18:44:38 +03:00
|
|
|
if (!bx_iodebug_s.enabled)
|
2001-09-15 02:38:06 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if(dvalue == 0x8A00)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.enabled = 1;
|
2006-03-07 01:03:16 +03:00
|
|
|
// fprintf(stderr, "IODEBUG enabled\n");
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.registers[0] = 0;
|
|
|
|
bx_iodebug_s.registers[1] = 0;
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
2001-09-15 02:38:06 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-09-14 20:21:02 +04:00
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
switch(dvalue)
|
2001-09-15 02:38:06 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8A01:
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.register_select = 0;
|
2006-03-07 01:03:16 +03:00
|
|
|
// fprintf(stderr, "IODEBUG register 0 selected\n");
|
2001-09-15 02:38:06 +04:00
|
|
|
break;
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8A02:
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.register_select = 1;
|
2006-03-07 01:03:16 +03:00
|
|
|
// fprintf(stderr, "IODEBUG register 1 selected\n");
|
2001-09-15 02:38:06 +04:00
|
|
|
break;
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8A80:
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.register_select = 0;
|
2006-03-03 15:55:37 +03:00
|
|
|
bx_iodebug_c::add_range(bx_iodebug_s.registers[0],
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.registers[1]);
|
|
|
|
bx_iodebug_s.registers[0] = 0;
|
|
|
|
bx_iodebug_s.registers[1] = 0;
|
|
|
|
break;
|
|
|
|
|
2001-09-26 06:52:03 +04:00
|
|
|
#if BX_DEBUGGER
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8AE0:
|
|
|
|
fprintf(stderr, "request return to dbg prompt received, 0x8AE0 command (iodebug)\n");
|
2001-09-26 06:52:03 +04:00
|
|
|
bx_guard.interrupt_requested=1;
|
|
|
|
break;
|
2001-10-03 23:06:17 +04:00
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8AE2:
|
|
|
|
fprintf(stderr, "request made by the guest os to disable tracing, iodebug port 0x8A00->0x8AE2\n");
|
2001-10-03 23:06:17 +04:00
|
|
|
BX_CPU(dbg_cpu)->trace = 0;
|
|
|
|
break;
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8AE3:
|
|
|
|
fprintf(stderr, "request made by the guest os to enable tracing, iodebug port 0x8A00->0x8AE3\n");
|
2001-10-03 23:06:17 +04:00
|
|
|
BX_CPU(dbg_cpu)->trace = 1;
|
|
|
|
break;
|
2001-10-03 23:54:29 +04:00
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8AE4:
|
|
|
|
fprintf(stderr, "request made by the guest os to disable register tracing, iodebug port 0x8A00->0x8AE4\n");
|
2001-10-03 23:54:29 +04:00
|
|
|
BX_CPU(dbg_cpu)->trace_reg = 0;
|
|
|
|
break;
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8AE5:
|
|
|
|
fprintf(stderr, "request made by the guest os to enable register tracing, iodebug port 0x8A00->0x8AE5\n");
|
2001-10-03 23:54:29 +04:00
|
|
|
BX_CPU(dbg_cpu)->trace_reg = 1;
|
|
|
|
break;
|
2001-09-26 06:52:03 +04:00
|
|
|
#endif
|
2006-03-03 15:55:37 +03:00
|
|
|
case 0x8AFF:
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.enabled = 0;
|
2006-03-03 15:55:37 +03:00
|
|
|
// fprintf(stderr, "IODEBUG device deactivated\n");
|
2001-09-15 04:12:40 +04:00
|
|
|
// break;
|
2001-09-15 02:38:06 +04:00
|
|
|
|
2001-09-15 04:12:40 +04:00
|
|
|
// default:
|
|
|
|
// fprintf(stderr,"IODEBUG unsupported register code\n");
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-15 02:38:06 +04:00
|
|
|
// Static function
|
2006-03-03 15:55:37 +03:00
|
|
|
void bx_iodebug_c::mem_write(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if(! bx_iodebug_s.enabled) return;
|
2001-09-14 20:21:02 +04:00
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
unsigned area = bx_iodebug_c::range_test(addr, len);
|
2001-09-14 20:21:02 +04:00
|
|
|
// Device is enabled, testing address ranges
|
2006-03-03 15:55:37 +03:00
|
|
|
if(area)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
|
|
|
area--;
|
2006-03-07 01:03:16 +03:00
|
|
|
|
2001-09-15 04:12:40 +04:00
|
|
|
#if BX_DEBUGGER
|
2008-02-15 22:03:54 +03:00
|
|
|
if (cpu != NULL) {
|
|
|
|
fprintf(stdout, "IODEBUG %s @ eip: " FMT_ADDRX " write at monitored memory location %8X\n",
|
|
|
|
cpu->name, cpu->get_instruction_pointer(), addr);
|
|
|
|
}
|
|
|
|
else {
|
2006-03-07 01:03:16 +03:00
|
|
|
fprintf(stdout, "IODEBUG write at monitored memory location %8X\n", addr);
|
2008-02-15 22:03:54 +03:00
|
|
|
}
|
2005-11-14 22:03:12 +03:00
|
|
|
bx_guard.interrupt_requested=1;
|
2001-09-15 04:12:40 +04:00
|
|
|
#else
|
2006-03-07 01:03:16 +03:00
|
|
|
fprintf(stderr, "IODEBUG write to monitored memory area: %2i\t", area);
|
|
|
|
|
|
|
|
if (cpu != NULL)
|
2008-02-15 22:03:54 +03:00
|
|
|
fprintf(stderr, "by EIP:\t\t" FMT_ADDRX "\n\t", cpu->get_instruction_pointer());
|
2006-03-07 01:03:16 +03:00
|
|
|
else
|
2008-02-15 22:03:54 +03:00
|
|
|
fprintf(stderr, "(device origin)\t", cpu->get_instruction_pointer());
|
2006-03-07 01:03:16 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "range start: \t\t%08X\trange end:\t%08X\n\taddress accessed:\t%08X\tdata written:\t",
|
2001-09-15 02:38:06 +04:00
|
|
|
bx_iodebug_s.monitored_mem_areas_start[area],
|
|
|
|
bx_iodebug_s.monitored_mem_areas_end[area],
|
2006-03-03 15:55:37 +03:00
|
|
|
(unsigned) addr);
|
2001-09-14 20:21:02 +04:00
|
|
|
|
|
|
|
switch(len)
|
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
case 1: {
|
|
|
|
Bit8u data8 = * ((Bit8u *) data);
|
|
|
|
fprintf(stderr,"%02X\n", (unsigned) data8);
|
2001-09-14 20:21:02 +04:00
|
|
|
break;
|
2006-03-03 15:55:37 +03:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
Bit16u data16 = * ((Bit16u *) data);
|
|
|
|
fprintf(stderr,"%04X\n", (unsigned) data16);
|
2001-09-14 20:21:02 +04:00
|
|
|
break;
|
2006-03-03 15:55:37 +03:00
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
Bit32u data32 = * ((Bit32u *) data);
|
|
|
|
fprintf(stderr,"%08X\n", (unsigned) data32);
|
2001-09-14 20:21:02 +04:00
|
|
|
break;
|
2006-03-03 15:55:37 +03:00
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
Bit64u data64 = * ((Bit64u *) data);
|
2008-01-27 01:24:03 +03:00
|
|
|
fprintf(stderr,"%08X%08x\n",
|
2006-03-03 15:55:37 +03:00
|
|
|
(unsigned) (data64 >> 32),
|
|
|
|
(unsigned) (data64 & 0xffffffff));
|
|
|
|
break;
|
|
|
|
}
|
2001-09-14 20:21:02 +04:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "unsupported write size\n");
|
|
|
|
}
|
2001-09-15 04:12:40 +04:00
|
|
|
#endif
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
void bx_iodebug_c::mem_read(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if(! bx_iodebug_s.enabled) return;
|
2001-09-14 20:21:02 +04:00
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
unsigned area = bx_iodebug_c::range_test(addr, len);
|
2001-09-15 04:12:40 +04:00
|
|
|
// Device is enabled, testing address ranges
|
2006-03-03 15:55:37 +03:00
|
|
|
if(area)
|
2001-09-15 04:12:40 +04:00
|
|
|
{
|
|
|
|
area--;
|
2006-03-07 01:03:16 +03:00
|
|
|
|
2001-09-15 04:12:40 +04:00
|
|
|
#if BX_DEBUGGER
|
2008-02-15 22:03:54 +03:00
|
|
|
if (cpu != NULL) {
|
|
|
|
fprintf(stdout, "IODEBUG %s @ eip: " FMT_ADDRX " read at monitored memory location %8X\n",
|
|
|
|
cpu->name, cpu->get_instruction_pointer(), addr);
|
|
|
|
}
|
|
|
|
else {
|
2006-03-07 01:03:16 +03:00
|
|
|
fprintf(stdout, "IODEBUG read at monitored memory location %8X\n", addr);
|
2008-02-15 22:03:54 +03:00
|
|
|
}
|
2005-11-14 22:03:12 +03:00
|
|
|
bx_guard.interrupt_requested=1;
|
2001-09-15 04:12:40 +04:00
|
|
|
#else
|
2006-03-07 01:03:16 +03:00
|
|
|
fprintf(stderr, "IODEBUG read at monitored memory area: %2i\t", area);
|
|
|
|
|
|
|
|
if (cpu != NULL)
|
2008-02-15 22:03:54 +03:00
|
|
|
fprintf(stderr, "by EIP:\t\t" FMT_ADDRX "\n\t", cpu->get_instruction_pointer());
|
2006-03-07 01:03:16 +03:00
|
|
|
else
|
2008-02-15 22:03:54 +03:00
|
|
|
fprintf(stderr, "(device origin)\t", cpu->get_instruction_pointer());
|
2006-03-07 01:03:16 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "range start: \t\t%08X\trange end:\t%08X\n\taddress accessed:\t%08X\tdata written:\t",
|
2001-09-15 04:12:40 +04:00
|
|
|
bx_iodebug_s.monitored_mem_areas_start[area],
|
|
|
|
bx_iodebug_s.monitored_mem_areas_end[area],
|
2006-03-03 15:55:37 +03:00
|
|
|
(unsigned) addr);
|
2001-09-15 04:12:40 +04:00
|
|
|
|
|
|
|
switch(len)
|
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
case 1: {
|
|
|
|
Bit8u data8 = * ((Bit8u *) data);
|
|
|
|
fprintf(stderr,"%02X\n", (unsigned) data8);
|
2001-09-15 04:12:40 +04:00
|
|
|
break;
|
2006-03-03 15:55:37 +03:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
Bit16u data16 = * ((Bit16u *) data);
|
|
|
|
fprintf(stderr,"%04X\n", (unsigned) data16);
|
2001-09-15 04:12:40 +04:00
|
|
|
break;
|
2006-03-03 15:55:37 +03:00
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
Bit32u data32 = * ((Bit32u *) data);
|
|
|
|
fprintf(stderr,"%08X\n", (unsigned) data32);
|
2001-09-15 04:12:40 +04:00
|
|
|
break;
|
2006-03-03 15:55:37 +03:00
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
Bit64u data64 = * ((Bit64u *) data);
|
2008-01-27 01:24:03 +03:00
|
|
|
fprintf(stderr,"%08X%08x\n",
|
2006-03-03 15:55:37 +03:00
|
|
|
(unsigned) (data64 >> 32),
|
|
|
|
(unsigned) (data64 & 0xffffffff));
|
|
|
|
break;
|
|
|
|
}
|
2001-09-15 04:12:40 +04:00
|
|
|
default:
|
2006-03-03 15:55:37 +03:00
|
|
|
fprintf(stderr, "unsupported read size\n");
|
2001-09-15 04:12:40 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
unsigned bx_iodebug_c::range_test(Bit32u addr, unsigned len)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
for(unsigned i=0;i<BX_IODEBUG_MAX_AREAS;i++)
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if((bx_iodebug_s.monitored_mem_areas_start[i]!=0) ||
|
|
|
|
(bx_iodebug_s.monitored_mem_areas_end[i]!=0))
|
2001-09-14 20:21:02 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if((Bit32u)(addr+len-1) < bx_iodebug_s.monitored_mem_areas_start[i])
|
2001-09-14 20:21:02 +04:00
|
|
|
continue;
|
2006-03-03 15:55:37 +03:00
|
|
|
|
|
|
|
if(addr < bx_iodebug_s.monitored_mem_areas_end[i])
|
2001-09-15 02:38:06 +04:00
|
|
|
{
|
2001-09-14 20:21:02 +04:00
|
|
|
return(++i);
|
2001-09-15 02:38:06 +04:00
|
|
|
}
|
2001-09-14 20:21:02 +04:00
|
|
|
}
|
|
|
|
}
|
2006-03-03 15:55:37 +03:00
|
|
|
|
2001-09-15 02:38:06 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-03 15:55:37 +03:00
|
|
|
void bx_iodebug_c::add_range(Bit32u addr_start, Bit32u addr_end)
|
2001-09-15 02:38:06 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
for(unsigned i=0;i<BX_IODEBUG_MAX_AREAS;i++)
|
2001-09-15 02:38:06 +04:00
|
|
|
{
|
2008-02-16 01:05:43 +03:00
|
|
|
if(!bx_iodebug_s.monitored_mem_areas_start[i] &&
|
|
|
|
!bx_iodebug_s.monitored_mem_areas_end[i])
|
2001-09-15 02:38:06 +04:00
|
|
|
{
|
|
|
|
bx_iodebug_s.monitored_mem_areas_start[i] = addr_start;
|
|
|
|
bx_iodebug_s.monitored_mem_areas_end[i] = addr_end;
|
2001-09-15 04:12:40 +04:00
|
|
|
// fprintf(stderr, "IODEBUG added range successfully in slot: %i\n",i);
|
2001-09-15 02:38:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-09-15 04:12:40 +04:00
|
|
|
// fprintf(stderr, "IODEBUG unable to register memory range, all slots taken\n");
|
2001-09-14 18:29:21 +04:00
|
|
|
}
|
2004-06-19 19:20:15 +04:00
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#endif /* if BX_SUPPORT_IODEBUG */
|