2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-04-05 22:16:29 +04:00
|
|
|
// $Id: debugstuff.cc,v 1.104 2009-04-05 18:16:29 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// 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-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2008-01-29 20:13:10 +03:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-24 22:46:34 +04:00
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-12-19 20:58:08 +03:00
|
|
|
#if BX_DISASM
|
2007-12-26 00:42:38 +03:00
|
|
|
|
2009-01-19 22:01:03 +03:00
|
|
|
#include "disasm/disasm.h"
|
|
|
|
|
2005-12-19 20:58:08 +03:00
|
|
|
void BX_CPU_C::debug_disasm_instruction(bx_address offset)
|
|
|
|
{
|
2007-12-26 00:42:38 +03:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
bx_dbg_disassemble_current(BX_CPU_ID, 1); // only one cpu, print time stamp
|
|
|
|
#else
|
2006-04-08 00:47:32 +04:00
|
|
|
bx_phy_address phy_addr;
|
2007-12-30 20:53:12 +03:00
|
|
|
Bit8u instr_buf[16];
|
|
|
|
char char_buf[512];
|
|
|
|
size_t i=0;
|
2005-12-19 20:58:08 +03:00
|
|
|
|
2006-04-08 00:47:32 +04:00
|
|
|
static char letters[] = "0123456789ABCDEF";
|
2005-12-19 20:58:08 +03:00
|
|
|
static disassembler bx_disassemble;
|
2007-12-27 02:07:44 +03:00
|
|
|
unsigned remainsInPage = 0x1000 - PAGE_OFFSET(offset);
|
2005-12-19 20:58:08 +03:00
|
|
|
|
2008-04-07 22:39:17 +04:00
|
|
|
bx_bool valid = dbg_xlate_linear2phy(BX_CPU_THIS_PTR get_laddr(BX_SEG_REG_CS, offset), &phy_addr);
|
2008-04-27 23:49:02 +04:00
|
|
|
if (valid) {
|
|
|
|
BX_MEM(0)->dbg_fetch_mem(BX_CPU_THIS, phy_addr, 16, instr_buf);
|
2006-04-08 00:47:32 +04:00
|
|
|
unsigned isize = bx_disassemble.disasm(
|
2005-12-19 20:58:08 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b,
|
|
|
|
BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64,
|
|
|
|
BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS), offset,
|
2006-04-05 21:31:35 +04:00
|
|
|
instr_buf, char_buf+i);
|
2006-04-08 00:47:32 +04:00
|
|
|
if (isize <= remainsInPage) {
|
|
|
|
i=strlen(char_buf);
|
|
|
|
char_buf[i++] = ' ';
|
|
|
|
char_buf[i++] = ':';
|
|
|
|
char_buf[i++] = ' ';
|
|
|
|
for (unsigned j=0; j<isize; j++) {
|
|
|
|
char_buf[i++] = letters[(instr_buf[j] >> 4) & 0xf];
|
|
|
|
char_buf[i++] = letters[(instr_buf[j] >> 0) & 0xf];
|
|
|
|
}
|
|
|
|
char_buf[i] = 0;
|
2009-03-23 00:12:35 +03:00
|
|
|
BX_INFO(("0x" FMT_ADDRX ">> %s", offset, char_buf));
|
2006-04-08 00:47:32 +04:00
|
|
|
}
|
|
|
|
else {
|
2009-03-23 00:12:35 +03:00
|
|
|
BX_INFO(("0x" FMT_ADDRX ": (instruction unavailable) page split instruction", offset));
|
2006-04-05 21:31:35 +04:00
|
|
|
}
|
2005-12-19 20:58:08 +03:00
|
|
|
}
|
|
|
|
else {
|
2009-03-23 00:12:35 +03:00
|
|
|
BX_INFO(("0x" FMT_ADDRX ": (instruction unavailable) page not present", offset));
|
2005-12-19 20:58:08 +03:00
|
|
|
}
|
2007-12-26 00:42:38 +03:00
|
|
|
#endif // #if BX_DEBUGGER
|
2005-12-19 20:58:08 +03:00
|
|
|
}
|
2007-12-26 00:42:38 +03:00
|
|
|
|
2005-12-19 20:58:08 +03:00
|
|
|
#endif // #if BX_DISASM
|
|
|
|
|
2006-01-24 00:44:44 +03:00
|
|
|
const char* cpu_mode_string(unsigned cpu_mode)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-03-30 23:56:02 +04:00
|
|
|
static const char *cpu_mode_name[] = {
|
|
|
|
"real mode",
|
|
|
|
"v8086 mode",
|
|
|
|
"protected mode",
|
|
|
|
"compatibility mode",
|
2006-01-24 00:44:44 +03:00
|
|
|
"long mode",
|
|
|
|
"unknown mode"
|
2005-03-30 23:56:02 +04:00
|
|
|
};
|
|
|
|
|
2006-02-14 23:14:18 +03:00
|
|
|
if(cpu_mode >= 5) cpu_mode = 5;
|
2006-01-24 00:44:44 +03:00
|
|
|
return cpu_mode_name[cpu_mode];
|
|
|
|
}
|
|
|
|
|
2009-01-29 23:27:57 +03:00
|
|
|
const char* cpu_state_string(unsigned state)
|
2007-10-11 22:12:00 +04:00
|
|
|
{
|
|
|
|
static const char *cpu_state_name[] = {
|
|
|
|
"active",
|
2007-11-01 21:03:48 +03:00
|
|
|
"halted",
|
2009-01-29 23:27:57 +03:00
|
|
|
"in shutdown",
|
|
|
|
"waiting for SIPI",
|
|
|
|
"executing mwait",
|
|
|
|
"executing mwait inhibit interrups",
|
2007-10-11 22:12:00 +04:00
|
|
|
"unknown state"
|
|
|
|
};
|
|
|
|
|
2009-01-29 23:27:57 +03:00
|
|
|
if(state >= 6) state = 6;
|
|
|
|
return cpu_state_name[state];
|
2007-10-11 22:12:00 +04:00
|
|
|
}
|
|
|
|
|
2006-01-24 00:44:44 +03:00
|
|
|
void BX_CPU_C::debug(bx_address offset)
|
|
|
|
{
|
2008-02-03 00:46:54 +03:00
|
|
|
BX_INFO(("CPU is in %s (%s)", cpu_mode_string(BX_CPU_THIS_PTR get_cpu_mode()),
|
2009-01-29 23:27:57 +03:00
|
|
|
cpu_state_string(BX_CPU_THIS_PTR activity_state)));
|
2005-03-30 23:56:02 +04:00
|
|
|
BX_INFO(("CS.d_b = %u bit",
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b ? 32 : 16));
|
|
|
|
BX_INFO(("SS.d_b = %u bit",
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b ? 32 : 16));
|
|
|
|
#if BX_SUPPORT_X86_64
|
2008-12-06 13:21:55 +03:00
|
|
|
BX_INFO(("EFER = 0x%08x", BX_CPU_THIS_PTR efer.get32()));
|
2005-03-30 23:56:02 +04:00
|
|
|
BX_INFO(("| RAX=%08x%08x RBX=%08x%08x",
|
|
|
|
(unsigned) (RAX >> 32), (unsigned) EAX,
|
|
|
|
(unsigned) (RBX >> 32), (unsigned) EBX));
|
|
|
|
BX_INFO(("| RCX=%08x%08x RDX=%08x%08x",
|
|
|
|
(unsigned) (RCX >> 32), (unsigned) ECX,
|
|
|
|
(unsigned) (RDX >> 32), (unsigned) EDX));
|
|
|
|
BX_INFO(("| RSP=%08x%08x RBP=%08x%08x",
|
|
|
|
(unsigned) (RSP >> 32), (unsigned) ESP,
|
|
|
|
(unsigned) (RBP >> 32), (unsigned) EBP));
|
|
|
|
BX_INFO(("| RSI=%08x%08x RDI=%08x%08x",
|
|
|
|
(unsigned) (RSI >> 32), (unsigned) ESI,
|
|
|
|
(unsigned) (RDI >> 32), (unsigned) EDI));
|
2006-01-15 21:14:16 +03:00
|
|
|
BX_INFO(("| R8=%08x%08x R9=%08x%08x",
|
|
|
|
(unsigned) (R8 >> 32), (unsigned) (R8 & 0xFFFFFFFF),
|
|
|
|
(unsigned) (R9 >> 32), (unsigned) (R9 & 0xFFFFFFFF)));
|
|
|
|
BX_INFO(("| R10=%08x%08x R11=%08x%08x",
|
|
|
|
(unsigned) (R10 >> 32), (unsigned) (R10 & 0xFFFFFFFF),
|
|
|
|
(unsigned) (R11 >> 32), (unsigned) (R11 & 0xFFFFFFFF)));
|
|
|
|
BX_INFO(("| R12=%08x%08x R13=%08x%08x",
|
|
|
|
(unsigned) (R12 >> 32), (unsigned) (R12 & 0xFFFFFFFF),
|
|
|
|
(unsigned) (R13 >> 32), (unsigned) (R13 & 0xFFFFFFFF)));
|
|
|
|
BX_INFO(("| R14=%08x%08x R15=%08x%08x",
|
|
|
|
(unsigned) (R14 >> 32), (unsigned) (R14 & 0xFFFFFFFF),
|
|
|
|
(unsigned) (R15 >> 32), (unsigned) (R15 & 0xFFFFFFFF)));
|
2005-03-30 23:56:02 +04:00
|
|
|
#else
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| EAX=%08x EBX=%08x ECX=%08x EDX=%08x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) EAX, (unsigned) EBX, (unsigned) ECX, (unsigned) EDX));
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| ESP=%08x EBP=%08x ESI=%08x EDI=%08x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) ESP, (unsigned) EBP, (unsigned) ESI, (unsigned) EDI));
|
2005-03-30 23:56:02 +04:00
|
|
|
#endif
|
2006-01-25 21:13:44 +03:00
|
|
|
BX_INFO(("| IOPL=%1u %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
|
2005-12-12 00:58:53 +03:00
|
|
|
BX_CPU_THIS_PTR get_IOPL(),
|
2006-01-25 21:13:44 +03:00
|
|
|
BX_CPU_THIS_PTR get_ID() ? "ID" : "id",
|
|
|
|
BX_CPU_THIS_PTR get_VIP() ? "VIP" : "vip",
|
|
|
|
BX_CPU_THIS_PTR get_VIF() ? "VIF" : "vif",
|
|
|
|
BX_CPU_THIS_PTR get_AC() ? "AC" : "ac",
|
2005-12-14 23:05:40 +03:00
|
|
|
BX_CPU_THIS_PTR get_VM() ? "VM" : "vm",
|
|
|
|
BX_CPU_THIS_PTR get_RF() ? "RF" : "rf",
|
|
|
|
BX_CPU_THIS_PTR get_NT() ? "NT" : "nt",
|
2005-12-12 00:58:53 +03:00
|
|
|
BX_CPU_THIS_PTR get_OF() ? "OF" : "of",
|
|
|
|
BX_CPU_THIS_PTR get_DF() ? "DF" : "df",
|
|
|
|
BX_CPU_THIS_PTR get_IF() ? "IF" : "if",
|
2005-12-14 23:05:40 +03:00
|
|
|
BX_CPU_THIS_PTR get_TF() ? "TF" : "tf",
|
2005-12-12 00:58:53 +03:00
|
|
|
BX_CPU_THIS_PTR get_SF() ? "SF" : "sf",
|
|
|
|
BX_CPU_THIS_PTR get_ZF() ? "ZF" : "zf",
|
|
|
|
BX_CPU_THIS_PTR get_AF() ? "AF" : "af",
|
|
|
|
BX_CPU_THIS_PTR get_PF() ? "PF" : "pf",
|
|
|
|
BX_CPU_THIS_PTR get_CF() ? "CF" : "cf"));
|
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| SEG selector base limit G D"));
|
|
|
|
BX_INFO(("| SEG sltr(index|ti|rpl) base limit G D"));
|
2005-03-30 23:56:02 +04:00
|
|
|
BX_INFO(("| CS:%04x( %04x| %01u| %1u) %08x %08x %1u %1u",
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.index,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.ti,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.rpl,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.base,
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled,
|
2005-03-30 23:56:02 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.g,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b));
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| DS:%04x( %04x| %01u| %1u) %08x %08x %1u %1u",
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.index,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.ti,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.rpl,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].cache.u.segment.base,
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].cache.u.segment.limit_scaled,
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].cache.u.segment.g,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].cache.u.segment.d_b));
|
2005-03-30 23:56:02 +04:00
|
|
|
BX_INFO(("| SS:%04x( %04x| %01u| %1u) %08x %08x %1u %1u",
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.index,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.ti,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.rpl,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.base,
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.limit_scaled,
|
2005-03-30 23:56:02 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.g,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b));
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| ES:%04x( %04x| %01u| %1u) %08x %08x %1u %1u",
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.index,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.ti,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.rpl,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].cache.u.segment.base,
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].cache.u.segment.limit_scaled,
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].cache.u.segment.g,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].cache.u.segment.d_b));
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| FS:%04x( %04x| %01u| %1u) %08x %08x %1u %1u",
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.index,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.ti,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.rpl,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.u.segment.base,
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.u.segment.limit_scaled,
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.u.segment.g,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.u.segment.d_b));
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("| GS:%04x( %04x| %01u| %1u) %08x %08x %1u %1u",
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.index,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.ti,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.rpl,
|
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].cache.u.segment.base,
|
2009-04-05 22:16:29 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].cache.u.segment.limit_scaled,
|
2001-04-10 05:04:59 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].cache.u.segment.g,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].cache.u.segment.d_b));
|
2006-01-16 22:22:28 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
BX_INFO(("| MSR_FS_BASE:%08x%08x",
|
|
|
|
(unsigned) (MSR_FSBASE >> 32), (unsigned) (MSR_FSBASE & 0xFFFFFFFF)));
|
|
|
|
BX_INFO(("| MSR_GS_BASE:%08x%08x",
|
|
|
|
(unsigned) (MSR_GSBASE >> 32), (unsigned) (MSR_GSBASE & 0xFFFFFFFF)));
|
|
|
|
#endif
|
2005-03-30 23:56:02 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2008-02-03 00:46:54 +03:00
|
|
|
BX_INFO(("| RIP=%08x%08x (%08x%08x)",
|
2008-02-15 22:03:54 +03:00
|
|
|
(unsigned) (BX_CPU_THIS_PTR gen_reg[BX_64BIT_REG_RIP].dword.hrx),
|
|
|
|
(unsigned) (EIP),
|
2008-02-03 00:46:54 +03:00
|
|
|
(unsigned) (BX_CPU_THIS_PTR prev_rip >> 32),
|
2007-11-24 17:22:34 +03:00
|
|
|
(unsigned) (BX_CPU_THIS_PTR prev_rip & 0xffffffff)));
|
2008-10-02 22:14:52 +04:00
|
|
|
BX_INFO(("| CR0=0x%08x CR2=0x%08x%08x",
|
2008-12-06 13:21:55 +03:00
|
|
|
(unsigned) (BX_CPU_THIS_PTR cr0.get32()),
|
2005-03-30 23:56:02 +04:00
|
|
|
(unsigned) (BX_CPU_THIS_PTR cr2 >> 32),
|
|
|
|
(unsigned) (BX_CPU_THIS_PTR cr2 & 0xffffffff)));
|
2006-04-05 21:31:35 +04:00
|
|
|
BX_INFO(("| CR3=0x%08x CR4=0x%08x",
|
2008-12-06 13:21:55 +03:00
|
|
|
(unsigned) BX_CPU_THIS_PTR cr3, BX_CPU_THIS_PTR cr4.get32()));
|
2005-03-30 23:56:02 +04:00
|
|
|
#else
|
2002-09-13 04:15:23 +04:00
|
|
|
BX_INFO(("| EIP=%08x (%08x)", (unsigned) EIP,
|
2007-11-24 17:22:34 +03:00
|
|
|
(unsigned) BX_CPU_THIS_PTR prev_rip));
|
2005-03-30 23:56:02 +04:00
|
|
|
|
2002-09-24 02:10:00 +04:00
|
|
|
#if BX_CPU_LEVEL >= 2 && BX_CPU_LEVEL < 4
|
2008-10-02 22:14:52 +04:00
|
|
|
BX_INFO(("| CR0=0x%08x CR2=0x%08x CR3=0x%08x",
|
2008-12-06 13:21:55 +03:00
|
|
|
BX_CPU_THIS_PTR cr0.get32(),
|
2002-09-24 02:10:00 +04:00
|
|
|
BX_CPU_THIS_PTR cr2,
|
|
|
|
BX_CPU_THIS_PTR cr3));
|
|
|
|
#elif BX_CPU_LEVEL >= 4
|
2008-10-02 22:14:52 +04:00
|
|
|
BX_INFO(("| CR0=0x%08x CR2=0x%08x",
|
2008-12-06 13:21:55 +03:00
|
|
|
BX_CPU_THIS_PTR cr0.get32(),
|
2002-09-24 02:10:00 +04:00
|
|
|
BX_CPU_THIS_PTR cr2));
|
|
|
|
BX_INFO(("| CR3=0x%08x CR4=0x%08x",
|
|
|
|
BX_CPU_THIS_PTR cr3,
|
2008-12-06 13:21:55 +03:00
|
|
|
BX_CPU_THIS_PTR cr4.get32()));
|
2002-09-24 02:10:00 +04:00
|
|
|
#endif
|
2002-10-04 21:04:33 +04:00
|
|
|
|
2005-03-30 23:56:02 +04:00
|
|
|
#endif // BX_SUPPORT_X86_64
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_DISASM
|
2005-12-19 20:58:08 +03:00
|
|
|
debug_disasm_instruction(offset);
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif // #if BX_DISASM
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
2005-03-28 22:19:02 +04:00
|
|
|
Bit32u BX_CPU_C::dbg_get_reg(unsigned reg)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit32u return_val32;
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case BX_DBG_REG_EIP: return(EIP);
|
|
|
|
case BX_DBG_REG_EFLAGS:
|
2006-04-05 21:31:35 +04:00
|
|
|
return_val32 = BX_CPU_THIS_PTR read_eflags();
|
2001-04-10 05:04:59 +04:00
|
|
|
return(return_val32);
|
|
|
|
case BX_DBG_REG_CS: return(BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value);
|
|
|
|
case BX_DBG_REG_SS: return(BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value);
|
|
|
|
case BX_DBG_REG_DS: return(BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value);
|
|
|
|
case BX_DBG_REG_ES: return(BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value);
|
|
|
|
case BX_DBG_REG_FS: return(BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value);
|
|
|
|
case BX_DBG_REG_GS: return(BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value);
|
2006-06-11 20:40:37 +04:00
|
|
|
case BX_DBG_REG_CR0:
|
2008-12-06 13:21:55 +03:00
|
|
|
return BX_CPU_THIS_PTR cr0.get32();
|
2006-06-11 20:40:37 +04:00
|
|
|
case BX_DBG_REG_CR2:
|
|
|
|
return BX_CPU_THIS_PTR cr2;
|
|
|
|
case BX_DBG_REG_CR3:
|
|
|
|
return BX_CPU_THIS_PTR cr3;
|
|
|
|
#if BX_CPU_LEVEL >= 4
|
|
|
|
case BX_DBG_REG_CR4:
|
2008-12-06 13:21:55 +03:00
|
|
|
return BX_CPU_THIS_PTR cr4.get32();
|
2006-06-11 20:40:37 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("get_reg: request for unknown register"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-03-28 22:19:02 +04:00
|
|
|
bx_bool BX_CPU_C::dbg_set_reg(unsigned reg, Bit32u val)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// returns 1=OK, 0=can't change
|
|
|
|
bx_segment_reg_t *seg;
|
|
|
|
Bit32u current_sys_bits;
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case BX_DBG_REG_EIP: EIP = val; return(1);
|
|
|
|
case BX_DBG_REG_EFLAGS:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("dbg_set_reg: can not handle eflags yet."));
|
2006-04-05 21:31:35 +04:00
|
|
|
if (val & 0xffff0000) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("dbg_set_reg: can not set upper 16 bits of eflags."));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
// make sure none of the system bits are being changed
|
2002-09-24 22:33:38 +04:00
|
|
|
current_sys_bits = ((BX_CPU_THIS_PTR getB_NT()) << 14) |
|
2002-09-12 22:10:46 +04:00
|
|
|
(BX_CPU_THIS_PTR get_IOPL () << 12) |
|
2002-09-24 22:33:38 +04:00
|
|
|
((BX_CPU_THIS_PTR getB_TF()) << 8);
|
2006-04-23 21:16:27 +04:00
|
|
|
if (current_sys_bits != (val & 0x0000f100)) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("dbg_set_reg: can not modify NT, IOPL, or TF."));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR set_CF(val & 0x01); val >>= 2;
|
|
|
|
BX_CPU_THIS_PTR set_PF(val & 0x01); val >>= 2;
|
|
|
|
BX_CPU_THIS_PTR set_AF(val & 0x01); val >>= 2;
|
|
|
|
BX_CPU_THIS_PTR set_ZF(val & 0x01); val >>= 1;
|
|
|
|
BX_CPU_THIS_PTR set_SF(val & 0x01); val >>= 2;
|
2006-01-25 00:37:37 +03:00
|
|
|
BX_CPU_THIS_PTR set_IF(val & 0x01); val >>= 1;
|
|
|
|
BX_CPU_THIS_PTR set_DF(val & 0x01); val >>= 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR set_OF(val & 0x01);
|
2006-06-11 20:40:37 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_IF())
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR async_event = 1;
|
|
|
|
return(1);
|
|
|
|
case BX_DBG_REG_CS:
|
|
|
|
seg = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS];
|
|
|
|
break;
|
|
|
|
case BX_DBG_REG_SS:
|
|
|
|
seg = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS];
|
|
|
|
break;
|
|
|
|
case BX_DBG_REG_DS:
|
|
|
|
seg = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
|
|
|
|
break;
|
|
|
|
case BX_DBG_REG_ES:
|
|
|
|
seg = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES];
|
|
|
|
break;
|
|
|
|
case BX_DBG_REG_FS:
|
|
|
|
seg = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS];
|
|
|
|
break;
|
|
|
|
case BX_DBG_REG_GS:
|
|
|
|
seg = &BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS];
|
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("dbg_set_reg: unrecognized register ID (%u)", reg));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
if (real_mode()) {
|
2001-04-10 05:04:59 +04:00
|
|
|
seg->selector.value = val;
|
|
|
|
seg->cache.valid = 1;
|
|
|
|
seg->cache.p = 1;
|
|
|
|
seg->cache.dpl = 0;
|
|
|
|
seg->cache.segment = 1; // regular segment
|
2008-05-27 01:46:39 +04:00
|
|
|
seg->cache.type = BX_DATA_READ_WRITE_ACCESSED;
|
2001-04-10 05:04:59 +04:00
|
|
|
seg->cache.u.segment.base = val << 4;
|
|
|
|
seg->cache.u.segment.limit_scaled = 0xffff;
|
|
|
|
seg->cache.u.segment.g = 0; // byte granular
|
|
|
|
seg->cache.u.segment.d_b = 0; // default 16bit size
|
|
|
|
seg->cache.u.segment.avl = 0;
|
|
|
|
return(1); // ok
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
return(0); // can't change when not in real mode
|
|
|
|
}
|
|
|
|
|
2005-03-28 22:19:02 +04:00
|
|
|
unsigned BX_CPU_C::dbg_query_pending(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
unsigned ret = 0;
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
if (BX_HRQ) { // DMA Hold Request
|
2001-04-10 05:04:59 +04:00
|
|
|
ret |= BX_DBG_PENDING_DMA;
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
if (BX_CPU_THIS_PTR INTR && BX_CPU_THIS_PTR get_IF()) {
|
2001-04-10 05:04:59 +04:00
|
|
|
ret |= BX_DBG_PENDING_IRQ;
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2005-03-28 22:19:02 +04:00
|
|
|
bx_bool BX_CPU_C::dbg_get_sreg(bx_dbg_sreg_t *sreg, unsigned sreg_no)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
if (sreg_no > 5)
|
|
|
|
return(0);
|
|
|
|
sreg->sel = BX_CPU_THIS_PTR sregs[sreg_no].selector.value;
|
2006-04-23 21:16:27 +04:00
|
|
|
sreg->des_l = get_descriptor_l(&BX_CPU_THIS_PTR sregs[sreg_no].cache);
|
|
|
|
sreg->des_h = get_descriptor_h(&BX_CPU_THIS_PTR sregs[sreg_no].cache);
|
2001-04-10 05:04:59 +04:00
|
|
|
sreg->valid = BX_CPU_THIS_PTR sregs[sreg_no].cache.valid;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2006-06-11 20:40:37 +04:00
|
|
|
void BX_CPU_C::dbg_get_tr(bx_dbg_sreg_t *sreg)
|
|
|
|
{
|
|
|
|
sreg->sel = BX_CPU_THIS_PTR tr.selector.value;
|
|
|
|
sreg->des_l = get_descriptor_l(&BX_CPU_THIS_PTR tr.cache);
|
|
|
|
sreg->des_h = get_descriptor_h(&BX_CPU_THIS_PTR tr.cache);
|
|
|
|
sreg->valid = BX_CPU_THIS_PTR tr.cache.valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPU_C::dbg_get_ldtr(bx_dbg_sreg_t *sreg)
|
|
|
|
{
|
|
|
|
sreg->sel = BX_CPU_THIS_PTR ldtr.selector.value;
|
|
|
|
sreg->des_l = get_descriptor_l(&BX_CPU_THIS_PTR ldtr.cache);
|
|
|
|
sreg->des_h = get_descriptor_h(&BX_CPU_THIS_PTR ldtr.cache);
|
|
|
|
sreg->valid = BX_CPU_THIS_PTR ldtr.cache.valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPU_C::dbg_get_gdtr(bx_dbg_global_sreg_t *sreg)
|
|
|
|
{
|
|
|
|
sreg->base = BX_CPU_THIS_PTR gdtr.base;
|
|
|
|
sreg->limit = BX_CPU_THIS_PTR gdtr.limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPU_C::dbg_get_idtr(bx_dbg_global_sreg_t *sreg)
|
|
|
|
{
|
|
|
|
sreg->base = BX_CPU_THIS_PTR idtr.base;
|
|
|
|
sreg->limit = BX_CPU_THIS_PTR idtr.limit;
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif // #if BX_DEBUGGER
|
|
|
|
|
2005-03-28 22:19:02 +04:00
|
|
|
void BX_CPU_C::atexit(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-11-24 17:22:34 +03:00
|
|
|
debug(BX_CPU_THIS_PTR prev_rip);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|