2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2006-01-24 22:03:55 +03:00
|
|
|
// $Id: cpu.cc,v 1.124 2006-01-24 19:03:54 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
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.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
|
|
|
|
2006-01-17 10:58:11 +03:00
|
|
|
#if BX_PROVIDE_CPU_MEMORY==1
|
|
|
|
|
|
|
|
#if BX_ADDRESS_SPACES==1
|
|
|
|
BOCHSAPI BX_MEM_C bx_mem;
|
|
|
|
#else
|
|
|
|
BOCHSAPI BX_MEM_C bx_mem_array[BX_ADDRESS_SPACES];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-03-11 00:22:15 +03:00
|
|
|
#if BX_SUPPORT_ICACHE
|
|
|
|
|
2005-04-10 23:42:48 +04:00
|
|
|
bxPageWriteStampTable pageWriteStampTable;
|
|
|
|
|
2005-10-18 22:07:52 +04:00
|
|
|
void purgeICaches(void)
|
2005-04-10 23:42:48 +04:00
|
|
|
{
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2005-04-10 23:42:48 +04:00
|
|
|
for (unsigned i=0; i<BX_SMP_PROCESSORS; i++)
|
2005-06-17 00:28:27 +04:00
|
|
|
BX_CPU(i)->iCache.purgeICacheEntries();
|
2006-01-18 21:35:38 +03:00
|
|
|
#else
|
|
|
|
BX_CPU(0)->iCache.purgeICacheEntries();
|
2005-04-10 23:42:48 +04:00
|
|
|
#endif
|
2005-06-17 00:28:27 +04:00
|
|
|
|
|
|
|
pageWriteStampTable.resetWriteStamps();
|
2005-04-10 23:42:48 +04:00
|
|
|
}
|
|
|
|
|
2005-10-18 22:07:52 +04:00
|
|
|
void flushICaches(void)
|
|
|
|
{
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2005-10-18 22:07:52 +04:00
|
|
|
for (unsigned i=0; i<BX_SMP_PROCESSORS; i++)
|
|
|
|
BX_CPU(i)->iCache.flushICacheEntries();
|
2006-01-18 21:35:38 +03:00
|
|
|
#else
|
|
|
|
BX_CPU(0)->iCache.flushICacheEntries();
|
2005-10-18 22:07:52 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pageWriteStampTable.resetWriteStamps();
|
|
|
|
}
|
|
|
|
|
2005-03-11 00:22:15 +03:00
|
|
|
#define InstrumentICACHE 0
|
|
|
|
|
|
|
|
#if InstrumentICACHE
|
|
|
|
static unsigned iCacheLookups=0;
|
|
|
|
static unsigned iCacheMisses=0;
|
|
|
|
|
|
|
|
#define InstrICache_StatsMask 0xffffff
|
|
|
|
|
|
|
|
#define InstrICache_Stats() {\
|
|
|
|
if ((iCacheLookups & InstrICache_StatsMask) == 0) { \
|
|
|
|
BX_INFO(("ICACHE lookups: %u, misses: %u, hit rate = %6.2f%% ", \
|
|
|
|
iCacheLookups, \
|
|
|
|
iCacheMisses, \
|
|
|
|
(iCacheLookups-iCacheMisses) * 100.0 / iCacheLookups)); \
|
|
|
|
iCacheLookups = iCacheMisses = 0; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define InstrICache_Increment(v) (v)++
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define InstrICache_Stats()
|
|
|
|
#define InstrICache_Increment(v)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// notes:
|
|
|
|
|
2001-06-05 19:56:19 +04:00
|
|
|
// The CHECK_MAX_INSTRUCTIONS macro allows cpu_loop to execute a few
|
|
|
|
// instructions and then return so that the other processors have a chance to
|
|
|
|
// run. This is used only when simulating multiple processors.
|
2001-05-23 12:16:07 +04:00
|
|
|
//
|
|
|
|
// If maximum instructions have been executed, return. A count less
|
|
|
|
// than zero means run forever.
|
|
|
|
#define CHECK_MAX_INSTRUCTIONS(count) \
|
|
|
|
if (count >= 0) { \
|
|
|
|
count--; if (count == 0) return; \
|
|
|
|
}
|
2001-06-05 19:56:19 +04:00
|
|
|
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2001-06-05 19:56:19 +04:00
|
|
|
# define BX_TICK1_IF_SINGLE_PROCESSOR()
|
2006-01-18 21:35:38 +03:00
|
|
|
#else
|
|
|
|
# define BX_TICK1_IF_SINGLE_PROCESSOR() BX_TICK1()
|
2001-05-23 12:16:07 +04:00
|
|
|
#endif
|
|
|
|
|
2002-09-14 07:01:05 +04:00
|
|
|
// Make code more tidy with a few macros.
|
|
|
|
#if BX_SUPPORT_X86_64==0
|
|
|
|
#define RIP EIP
|
|
|
|
#define RSP ESP
|
|
|
|
#endif
|
|
|
|
|
2005-06-17 00:28:27 +04:00
|
|
|
void BX_CPU_C::cpu_loop(Bit32s max_instr_count)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
unsigned ret;
|
2002-09-19 23:17:20 +04:00
|
|
|
bxInstruction_c iStorage BX_CPP_AlignN(32);
|
2002-09-28 13:38:58 +04:00
|
|
|
bxInstruction_c *i = &iStorage;
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
BX_CPU_THIS_PTR break_point = 0;
|
2004-01-29 20:49:03 +03:00
|
|
|
#if BX_MAGIC_BREAKPOINT
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR magic_break = 0;
|
|
|
|
#endif
|
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_NO_REASON;
|
|
|
|
#endif
|
|
|
|
|
2002-09-29 18:16:30 +04:00
|
|
|
if (setjmp( BX_CPU_THIS_PTR jmp_buf_env ))
|
|
|
|
{
|
|
|
|
// only from exception function can we get here ...
|
2003-02-13 18:04:11 +03:00
|
|
|
BX_INSTR_NEW_INSTRUCTION(BX_CPU_ID);
|
2005-04-12 22:08:10 +04:00
|
|
|
|
|
|
|
#if BX_GDBSTUB
|
|
|
|
if (bx_dbg.gdbstub_enabled) {
|
2004-11-06 13:50:03 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-09-29 18:16:30 +04:00
|
|
|
#endif
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-07 02:08:18 +04:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
// If the exception() routine has encountered a nasty fault scenario,
|
|
|
|
// the debugger may request that control is returned to it so that
|
|
|
|
// the situation may be examined.
|
|
|
|
if (bx_guard.special_unwind_stack) {
|
2005-03-11 00:22:15 +03:00
|
|
|
printf("CPU_LOOP %d\n", bx_guard.special_unwind_stack);
|
2002-10-07 02:08:18 +04:00
|
|
|
return;
|
2005-03-11 00:22:15 +03:00
|
|
|
}
|
2002-10-07 02:08:18 +04:00
|
|
|
#endif
|
|
|
|
|
2002-09-02 22:44:35 +04:00
|
|
|
// We get here either by a normal function call, or by a longjmp
|
|
|
|
// back from an exception() call. In either case, commit the
|
|
|
|
// new EIP/ESP, and set up other environmental fields. This code
|
|
|
|
// mirrors similar code below, after the interrupt() call.
|
2002-09-14 07:01:05 +04:00
|
|
|
BX_CPU_THIS_PTR prev_eip = RIP; // commit new EIP
|
|
|
|
BX_CPU_THIS_PTR prev_esp = RSP; // commit new ESP
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR EXT = 0;
|
|
|
|
BX_CPU_THIS_PTR errorno = 0;
|
|
|
|
|
2002-10-04 20:26:10 +04:00
|
|
|
while (1) {
|
2002-09-02 22:44:35 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// First check on events which occurred for previous instructions
|
|
|
|
// (traps) and ones which are asynchronous to the CPU
|
|
|
|
// (hardware interrupts).
|
2002-10-04 20:26:10 +04:00
|
|
|
if (BX_CPU_THIS_PTR async_event) {
|
2002-10-05 18:51:25 +04:00
|
|
|
if (handleAsyncEvent()) {
|
|
|
|
// If request to return to caller ASAP.
|
|
|
|
return;
|
2002-10-04 20:26:10 +04:00
|
|
|
}
|
2005-02-05 23:56:44 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
{
|
2006-01-19 21:32:39 +03:00
|
|
|
bx_address debug_eip = BX_CPU_THIS_PTR prev_eip;
|
|
|
|
if (dbg_is_begin_instr_bpoint(
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value,
|
|
|
|
debug_eip,
|
2005-02-28 21:56:05 +03:00
|
|
|
BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS) + debug_eip,
|
2006-01-19 21:32:39 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b,
|
|
|
|
Is64BitMode()))
|
2005-06-17 00:28:27 +04:00
|
|
|
{
|
2006-01-24 22:03:55 +03:00
|
|
|
fprintf(stderr, "back to debugger !!!\n");
|
2005-06-17 00:28:27 +04:00
|
|
|
return;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // #if BX_DEBUGGER
|
2002-09-12 11:16:37 +04:00
|
|
|
|
|
|
|
#if BX_EXTERNAL_DEBUGGER
|
|
|
|
if (regs.debug_state != debug_run) {
|
2004-11-05 13:13:15 +03:00
|
|
|
bx_external_debugger(BX_CPU_THIS);
|
2002-09-12 11:16:37 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-07-30 00:15:19 +04:00
|
|
|
bx_address eipBiased = RIP + BX_CPU_THIS_PTR eipPageBias;
|
2002-09-02 22:44:35 +04:00
|
|
|
|
2004-07-30 00:15:19 +04:00
|
|
|
if (eipBiased >= BX_CPU_THIS_PTR eipPageWindowSize) {
|
2001-04-10 05:04:59 +04:00
|
|
|
prefetch();
|
2002-09-14 07:01:05 +04:00
|
|
|
eipBiased = RIP + BX_CPU_THIS_PTR eipPageBias;
|
2004-07-30 00:15:19 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-07-30 00:15:19 +04:00
|
|
|
#if BX_SUPPORT_ICACHE
|
2004-10-16 23:34:17 +04:00
|
|
|
Bit32u pAddr = BX_CPU_THIS_PTR pAddrA20Page + eipBiased;
|
2004-09-14 00:48:11 +04:00
|
|
|
unsigned iCacheHash = BX_CPU_THIS_PTR iCache.hash(pAddr);
|
2004-10-16 23:34:17 +04:00
|
|
|
bxICacheEntry_c *cache_entry = &(BX_CPU_THIS_PTR iCache.entry[iCacheHash]);
|
|
|
|
i = &(cache_entry->i);
|
2002-09-19 23:17:20 +04:00
|
|
|
|
2005-08-10 22:18:57 +04:00
|
|
|
Bit32u pageWriteStamp = *(BX_CPU_THIS_PTR currPageWriteStampPtr);
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2005-03-11 00:22:15 +03:00
|
|
|
#if BX_SUPPORT_ICACHE
|
|
|
|
InstrICache_Increment(iCacheLookups);
|
|
|
|
InstrICache_Stats();
|
|
|
|
#endif
|
|
|
|
|
2004-10-16 23:34:17 +04:00
|
|
|
if ((cache_entry->pAddr == pAddr) &&
|
|
|
|
(cache_entry->writeStamp == pageWriteStamp))
|
2004-07-30 00:15:19 +04:00
|
|
|
{
|
2005-02-05 23:56:44 +03:00
|
|
|
// iCache hit. Instruction is already decoded and stored in the
|
|
|
|
// instruction cache.
|
2004-10-16 23:34:17 +04:00
|
|
|
|
2002-12-26 23:22:35 +03:00
|
|
|
#if BX_INSTRUMENTATION
|
|
|
|
// An instruction was found in the iCache.
|
2003-03-17 03:41:01 +03:00
|
|
|
BX_INSTR_OPCODE(BX_CPU_ID, BX_CPU_THIS_PTR eipFetchPtr + eipBiased,
|
2005-11-14 21:25:41 +03:00
|
|
|
i->ilen(), BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b, Is64BitMode());
|
2002-12-26 23:22:35 +03:00
|
|
|
#endif
|
2004-09-14 00:48:11 +04:00
|
|
|
}
|
2002-09-14 07:01:05 +04:00
|
|
|
else
|
|
|
|
#endif
|
2004-09-14 00:48:11 +04:00
|
|
|
{
|
2004-07-30 00:15:19 +04:00
|
|
|
// iCache miss. No validated instruction with matching fetch parameters
|
|
|
|
// is in the iCache. Or we're not compiling iCache support in, in which
|
2002-09-19 23:17:20 +04:00
|
|
|
// case we always have an iCache miss. :^)
|
|
|
|
bx_address remainingInPage;
|
|
|
|
remainingInPage = (BX_CPU_THIS_PTR eipPageWindowSize - eipBiased);
|
2004-07-30 00:15:19 +04:00
|
|
|
unsigned maxFetch = 15;
|
|
|
|
if (remainingInPage < 15) maxFetch = remainingInPage;
|
2004-10-16 23:34:17 +04:00
|
|
|
Bit8u *fetchPtr = BX_CPU_THIS_PTR eipFetchPtr + eipBiased;
|
2002-09-19 23:17:20 +04:00
|
|
|
|
2004-07-30 00:15:19 +04:00
|
|
|
#if BX_SUPPORT_ICACHE
|
|
|
|
// The entry will be marked valid if fetchdecode will succeed
|
2004-10-16 23:34:17 +04:00
|
|
|
cache_entry->writeStamp = ICacheWriteStampInvalid;
|
2005-03-11 00:22:15 +03:00
|
|
|
InstrICache_Increment(iCacheMisses);
|
2002-09-22 05:52:21 +04:00
|
|
|
#endif
|
|
|
|
|
2002-09-19 23:17:20 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2004-07-30 00:15:19 +04:00
|
|
|
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64)
|
2002-09-19 23:17:20 +04:00
|
|
|
ret = fetchDecode64(fetchPtr, i, maxFetch);
|
|
|
|
else
|
|
|
|
#endif
|
2002-09-22 05:52:21 +04:00
|
|
|
ret = fetchDecode(fetchPtr, i, maxFetch);
|
|
|
|
|
2002-09-19 23:17:20 +04:00
|
|
|
if (ret==0) {
|
2004-07-30 00:15:19 +04:00
|
|
|
#if BX_SUPPORT_ICACHE
|
|
|
|
i = &iStorage; // Leave entry invalid
|
2002-09-23 03:42:01 +04:00
|
|
|
#endif
|
2005-02-12 17:00:13 +03:00
|
|
|
boundaryFetch(fetchPtr, remainingInPage, i);
|
2002-09-29 19:06:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-30 00:15:19 +04:00
|
|
|
#if BX_SUPPORT_ICACHE
|
|
|
|
// In the case where the page is marked ICacheWriteStampInvalid, all
|
|
|
|
// counter bits will be high, being eqivalent to ICacheWriteStampMax.
|
|
|
|
// In the case where the page is marked as possibly having associated
|
|
|
|
// iCache entries, we need to leave the counter as-is, unless we're
|
|
|
|
// willing to dump all iCache entries which can hash to this page.
|
|
|
|
// Therefore, in either case, we can keep the counter as-is and
|
|
|
|
// replace the fetch mode bits.
|
2004-10-16 23:34:17 +04:00
|
|
|
Bit32u fetchModeMask = BX_CPU_THIS_PTR iCache.fetchModeMask;
|
2004-11-19 02:16:36 +03:00
|
|
|
pageWriteStamp &= ICacheWriteStampMask; // Clear out old fetch mode bits.
|
|
|
|
pageWriteStamp |= fetchModeMask; // Add in new ones.
|
2005-04-10 23:42:48 +04:00
|
|
|
pageWriteStampTable.setPageWriteStamp(pAddr, pageWriteStamp);
|
2004-10-16 23:34:17 +04:00
|
|
|
cache_entry->pAddr = pAddr;
|
|
|
|
cache_entry->writeStamp = pageWriteStamp;
|
2004-07-30 00:15:19 +04:00
|
|
|
#endif
|
|
|
|
#if BX_INSTRUMENTATION
|
2002-09-29 19:06:58 +04:00
|
|
|
// An instruction was either fetched, or found in the iCache.
|
2003-02-13 18:04:11 +03:00
|
|
|
BX_INSTR_OPCODE(BX_CPU_ID, fetchPtr, i->ilen(),
|
2005-11-14 21:25:41 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b, Is64BitMode());
|
2002-09-29 19:06:58 +04:00
|
|
|
#endif
|
2004-07-30 00:15:19 +04:00
|
|
|
}
|
2002-09-02 22:44:35 +04:00
|
|
|
}
|
2002-06-04 02:39:11 +04:00
|
|
|
|
2005-12-10 00:21:29 +03:00
|
|
|
bx_address next_RIP = RIP + i->ilen();
|
|
|
|
if (! Is64BitMode()) {
|
2005-12-28 22:18:50 +03:00
|
|
|
if (((Bit32u) next_RIP - 1) > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled) {
|
2005-12-10 00:21:29 +03:00
|
|
|
BX_ERROR(("GP(0): instruction cross segment boundary !"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-05 23:56:44 +03:00
|
|
|
BxExecutePtr_tR resolveModRM = i->ResolveModrm; // Get as soon as possible for speculation
|
|
|
|
BxExecutePtr_t execute = i->execute; // fetch as soon as possible for speculation
|
|
|
|
if (resolveModRM)
|
|
|
|
BX_CPU_CALL_METHODR(resolveModRM, (i));
|
|
|
|
|
2004-10-16 23:34:17 +04:00
|
|
|
// An instruction will have been fetched using either the normal case,
|
|
|
|
// or the boundary fetch (across pages), by this point.
|
|
|
|
BX_INSTR_FETCH_DECODE_COMPLETED(BX_CPU_ID, i);
|
2002-12-20 16:36:50 +03:00
|
|
|
|
2005-12-12 22:54:48 +03:00
|
|
|
#if BX_DEBUGGER
|
2004-10-16 23:34:17 +04:00
|
|
|
if (BX_CPU_THIS_PTR trace) {
|
|
|
|
// print the instruction that is about to be executed.
|
2005-12-12 22:54:48 +03:00
|
|
|
bx_dbg_disassemble_current (BX_CPU_ID, 1); // only one cpu, print time stamp
|
2004-10-16 23:34:17 +04:00
|
|
|
}
|
2005-12-12 22:54:48 +03:00
|
|
|
#endif
|
2002-02-16 01:58:06 +03:00
|
|
|
|
2004-10-16 23:34:17 +04:00
|
|
|
// decoding instruction compeleted -> continue with execution
|
2005-03-17 23:50:57 +03:00
|
|
|
BX_INSTR_BEFORE_EXECUTION(BX_CPU_ID, i);
|
2004-09-14 00:48:11 +04:00
|
|
|
|
2005-12-10 00:21:29 +03:00
|
|
|
if ( !(i->repUsedL() && i->repeatableL()) ) {
|
|
|
|
// non repeating instruction
|
|
|
|
RIP = next_RIP;
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
BX_CPU_THIS_PTR prev_eip = RIP; // commit new EIP
|
|
|
|
BX_CPU_THIS_PTR prev_esp = RSP; // commit new ESP
|
2002-09-02 22:44:35 +04:00
|
|
|
|
2005-12-10 00:21:29 +03:00
|
|
|
BX_INSTR_AFTER_EXECUTION(BX_CPU_ID, i);
|
|
|
|
BX_TICK1_IF_SINGLE_PROCESSOR();
|
|
|
|
}
|
|
|
|
else {
|
2003-10-09 23:05:13 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
repeat_loop:
|
2005-12-10 00:21:29 +03:00
|
|
|
|
|
|
|
if (i->repeatableZFL()) {
|
2002-09-14 07:01:05 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2005-12-10 00:21:29 +03:00
|
|
|
if (i->as64L()) {
|
|
|
|
if (RCX != 0) {
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
RCX --;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
if ((i->repUsedValue()==3) && (get_ZF()==0)) goto repeat_done;
|
|
|
|
if ((i->repUsedValue()==2) && (get_ZF()!=0)) goto repeat_done;
|
|
|
|
if (RCX == 0) goto repeat_done;
|
|
|
|
goto repeat_not_done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (i->as32L()) {
|
|
|
|
if (ECX != 0) {
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
ECX --;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
if ((i->repUsedValue()==3) && (get_ZF()==0)) goto repeat_done;
|
|
|
|
if ((i->repUsedValue()==2) && (get_ZF()!=0)) goto repeat_done;
|
|
|
|
if (ECX == 0) goto repeat_done;
|
|
|
|
goto repeat_not_done;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (CX != 0) {
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
CX --;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
if ((i->repUsedValue()==3) && (get_ZF()==0)) goto repeat_done;
|
|
|
|
if ((i->repUsedValue()==2) && (get_ZF()!=0)) goto repeat_done;
|
|
|
|
if (CX == 0) goto repeat_done;
|
|
|
|
goto repeat_not_done;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
}
|
|
|
|
else { // normal repeat, no concern for ZF
|
2002-09-14 07:01:05 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2005-12-10 00:21:29 +03:00
|
|
|
if (i->as64L()) {
|
|
|
|
if (RCX != 0) {
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
RCX --;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
if (RCX == 0) goto repeat_done;
|
|
|
|
goto repeat_not_done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (i->as32L()) {
|
|
|
|
if (ECX != 0) {
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
ECX --;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
if (ECX == 0) goto repeat_done;
|
|
|
|
goto repeat_not_done;
|
|
|
|
}
|
|
|
|
else { // 16bit addrsize
|
|
|
|
if (CX != 0) {
|
|
|
|
BX_CPU_CALL_METHOD(execute, (i));
|
|
|
|
CX --;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
if (CX == 0) goto repeat_done;
|
|
|
|
goto repeat_not_done;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2005-12-10 00:21:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// shouldn't get here from above
|
2001-04-10 05:04:59 +04:00
|
|
|
repeat_not_done:
|
2005-12-10 00:21:29 +03:00
|
|
|
BX_INSTR_REPEAT_ITERATION(BX_CPU_ID, i);
|
|
|
|
BX_TICK1_IF_SINGLE_PROCESSOR();
|
2001-05-23 12:16:07 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_DEBUGGER == 0
|
2005-12-10 00:21:29 +03:00
|
|
|
if (BX_CPU_THIS_PTR async_event) {
|
2001-05-23 12:16:07 +04:00
|
|
|
invalidate_prefetch_q();
|
|
|
|
goto debugger_check;
|
2005-12-10 00:21:29 +03:00
|
|
|
}
|
|
|
|
goto repeat_loop;
|
|
|
|
#else /* if BX_DEBUGGER == 1 */
|
|
|
|
invalidate_prefetch_q();
|
|
|
|
goto debugger_check;
|
2001-05-23 12:16:07 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
repeat_done:
|
2005-12-10 00:21:29 +03:00
|
|
|
RIP = next_RIP;
|
|
|
|
BX_CPU_THIS_PTR prev_eip = RIP; // commit new EIP
|
|
|
|
BX_CPU_THIS_PTR prev_esp = RSP; // commit new ESP
|
|
|
|
BX_INSTR_REPEAT_ITERATION(BX_CPU_ID, i);
|
|
|
|
BX_INSTR_AFTER_EXECUTION(BX_CPU_ID, i);
|
|
|
|
BX_TICK1_IF_SINGLE_PROCESSOR();
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
debugger_check:
|
2005-12-10 00:21:29 +03:00
|
|
|
// inform instrumentation about new instruction
|
|
|
|
BX_INSTR_NEW_INSTRUCTION(BX_CPU_ID);
|
2002-09-28 04:54:05 +04:00
|
|
|
|
2006-01-18 21:35:38 +03:00
|
|
|
#if (BX_SUPPORT_SMP && BX_DEBUGGER==0)
|
2005-12-10 00:21:29 +03:00
|
|
|
// The CHECK_MAX_INSTRUCTIONS macro allows cpu_loop to execute a few
|
|
|
|
// instructions and then return so that the other processors have a chance
|
|
|
|
// to run. This is used only when simulating multiple processors. If only
|
|
|
|
// one processor, don't waste any cycles on it! Also, it is not needed
|
|
|
|
// with the debugger because its guard mechanism provides the same
|
|
|
|
// functionality.
|
|
|
|
CHECK_MAX_INSTRUCTIONS(max_instr_count);
|
2001-06-05 19:56:19 +04:00
|
|
|
#endif
|
2001-05-23 12:16:07 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
// BW vm mode switch support is in dbg_is_begin_instr_bpoint
|
|
|
|
// note instr generating exceptions never reach this point.
|
|
|
|
|
|
|
|
// (mch) Read/write, time break point support
|
|
|
|
if (BX_CPU_THIS_PTR break_point) {
|
2002-10-04 21:04:33 +04:00
|
|
|
switch (BX_CPU_THIS_PTR break_point) {
|
|
|
|
case BREAK_POINT_TIME:
|
2003-06-07 23:16:55 +04:00
|
|
|
BX_INFO(("[" FMT_LL "d] Caught time breakpoint", bx_pc_system.time_ticks()));
|
2002-10-04 21:04:33 +04:00
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_TIME_BREAK_POINT;
|
|
|
|
return;
|
|
|
|
case BREAK_POINT_READ:
|
2003-06-07 23:16:55 +04:00
|
|
|
BX_INFO(("[" FMT_LL "d] Caught read watch point", bx_pc_system.time_ticks()));
|
2002-10-04 21:04:33 +04:00
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_READ_WATCH_POINT;
|
|
|
|
return;
|
|
|
|
case BREAK_POINT_WRITE:
|
2003-06-07 23:16:55 +04:00
|
|
|
BX_INFO(("[" FMT_LL "d] Caught write watch point", bx_pc_system.time_ticks()));
|
2002-10-04 21:04:33 +04:00
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_WRITE_WATCH_POINT;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
BX_PANIC(("Weird break point condition"));
|
|
|
|
}
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2004-01-29 20:49:03 +03:00
|
|
|
#if BX_MAGIC_BREAKPOINT
|
2001-04-10 05:04:59 +04:00
|
|
|
// (mch) Magic break point support
|
|
|
|
if (BX_CPU_THIS_PTR magic_break) {
|
2002-10-04 21:04:33 +04:00
|
|
|
if (bx_dbg.magic_break_enabled) {
|
|
|
|
BX_DEBUG(("Stopped on MAGIC BREAKPOINT"));
|
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_MAGIC_BREAK_POINT;
|
|
|
|
return;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2002-10-04 21:04:33 +04:00
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR magic_break = 0;
|
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_NO_REASON;
|
|
|
|
BX_DEBUG(("Ignoring MAGIC BREAKPOINT"));
|
|
|
|
}
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
2001-09-27 18:19:38 +04:00
|
|
|
// check for icount or control-C. If found, set guard reg and return.
|
2006-01-19 21:32:39 +03:00
|
|
|
bx_address debug_eip = BX_CPU_THIS_PTR prev_eip;
|
|
|
|
if (dbg_is_end_instr_bpoint(
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value,
|
|
|
|
debug_eip,
|
2005-02-28 21:56:05 +03:00
|
|
|
BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS) + debug_eip,
|
2006-01-19 21:32:39 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b,
|
|
|
|
Is64BitMode()))
|
|
|
|
{
|
2005-08-05 22:23:36 +04:00
|
|
|
return;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // #if BX_DEBUGGER
|
2004-10-16 23:34:17 +04:00
|
|
|
|
2002-10-03 09:14:50 +04:00
|
|
|
#if BX_GDBSTUB
|
2004-11-06 13:50:03 +03:00
|
|
|
if (bx_dbg.gdbstub_enabled) {
|
2005-04-12 22:08:10 +04:00
|
|
|
unsigned int reason = bx_gdbstub_check(EIP);
|
|
|
|
if (reason != GDBSTUB_STOP_NO_REASON) {
|
2004-11-06 13:50:03 +03:00
|
|
|
return;
|
2002-10-04 21:04:33 +04:00
|
|
|
}
|
2002-10-03 09:14:50 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-04 20:26:10 +04:00
|
|
|
} // while (1)
|
|
|
|
}
|
2002-09-19 23:17:20 +04:00
|
|
|
|
2005-02-12 17:00:13 +03:00
|
|
|
unsigned BX_CPU_C::handleAsyncEvent(void)
|
2002-10-04 20:26:10 +04:00
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This area is where we process special conditions and events.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR debug_trap & 0x80000000) {
|
|
|
|
// I made up the bitmask above to mean HALT state.
|
2006-01-18 21:35:38 +03:00
|
|
|
#if BX_SUPPORT_SMP == 0
|
2001-07-08 18:36:36 +04:00
|
|
|
BX_CPU_THIS_PTR debug_trap = 0; // clear traps for after resume
|
|
|
|
BX_CPU_THIS_PTR inhibit_mask = 0; // clear inhibits for after resume
|
2001-06-05 19:56:19 +04:00
|
|
|
// for one processor, pass the time as quickly as possible until
|
|
|
|
// an interrupt wakes up the CPU.
|
2002-04-01 17:14:37 +04:00
|
|
|
#if BX_DEBUGGER
|
2002-09-14 07:01:05 +04:00
|
|
|
while (bx_guard.interrupt_requested != 1)
|
2002-04-01 17:14:37 +04:00
|
|
|
#else
|
2002-09-14 07:01:05 +04:00
|
|
|
while (1)
|
2002-04-01 17:14:37 +04:00
|
|
|
#endif
|
2005-02-12 17:00:13 +03:00
|
|
|
{
|
2002-10-05 14:25:31 +04:00
|
|
|
if (BX_CPU_INTR && BX_CPU_THIS_PTR get_IF ()) {
|
2001-06-05 19:56:19 +04:00
|
|
|
break;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2002-11-21 11:08:29 +03:00
|
|
|
if (BX_CPU_THIS_PTR async_event == 2) {
|
2002-09-12 11:16:37 +04:00
|
|
|
BX_INFO(("decode: reset detected in halt state"));
|
|
|
|
break;
|
2002-09-14 07:01:05 +04:00
|
|
|
}
|
2005-02-12 17:00:13 +03:00
|
|
|
BX_TICK1();
|
|
|
|
}
|
2006-01-18 21:35:38 +03:00
|
|
|
#else /* BX_SUPPORT_SMP */
|
2001-06-05 19:56:19 +04:00
|
|
|
// for multiprocessor simulation, even if this CPU is halted we still
|
|
|
|
// must give the others a chance to simulate. If an interrupt has
|
|
|
|
// arrived, then clear the HALT condition; otherwise just return from
|
|
|
|
// the CPU loop with stop_reason STOP_CPU_HALTED.
|
2002-10-05 14:25:31 +04:00
|
|
|
if (BX_CPU_INTR && BX_CPU_THIS_PTR get_IF ()) {
|
2001-05-23 12:16:07 +04:00
|
|
|
// interrupt ends the HALT condition
|
|
|
|
BX_CPU_THIS_PTR debug_trap = 0; // clear traps for after resume
|
|
|
|
BX_CPU_THIS_PTR inhibit_mask = 0; // clear inhibits for after resume
|
2001-05-30 22:56:02 +04:00
|
|
|
//bx_printf ("halt condition has been cleared in %s", name);
|
2001-05-23 12:16:07 +04:00
|
|
|
} else {
|
|
|
|
// HALT condition remains, return so other CPUs have a chance
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_CPU_HALTED;
|
|
|
|
#endif
|
2002-10-05 18:51:25 +04:00
|
|
|
return 1; // Return to caller of cpu_loop.
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-06-05 19:56:19 +04:00
|
|
|
#endif
|
2002-04-18 04:22:20 +04:00
|
|
|
} else if (BX_CPU_THIS_PTR kill_bochs_request) {
|
|
|
|
// setting kill_bochs_request causes the cpu loop to return ASAP.
|
2002-10-05 18:51:25 +04:00
|
|
|
return 1; // Return to caller of cpu_loop.
|
2001-05-23 12:16:07 +04:00
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Priority 1: Hardware Reset and Machine Checks
|
|
|
|
// RESET
|
|
|
|
// Machine Check
|
|
|
|
// (bochs doesn't support these)
|
|
|
|
|
|
|
|
// Priority 2: Trap on Task Switch
|
|
|
|
// T flag in TSS is set
|
|
|
|
if (BX_CPU_THIS_PTR debug_trap & 0x00008000) {
|
|
|
|
BX_CPU_THIS_PTR dr6 |= BX_CPU_THIS_PTR debug_trap;
|
|
|
|
exception(BX_DB_EXCEPTION, 0, 0); // no error, not interrupt
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Priority 3: External Hardware Interventions
|
|
|
|
// FLUSH
|
|
|
|
// STOPCLK
|
|
|
|
// SMI
|
|
|
|
// INIT
|
|
|
|
// (bochs doesn't support these)
|
|
|
|
|
|
|
|
// Priority 4: Traps on Previous Instruction
|
|
|
|
// Breakpoints
|
|
|
|
// Debug Trap Exceptions (TF flag set or data/IO breakpoint)
|
|
|
|
if ( BX_CPU_THIS_PTR debug_trap &&
|
2005-02-12 17:00:13 +03:00
|
|
|
!(BX_CPU_THIS_PTR inhibit_mask & BX_INHIBIT_DEBUG) )
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
// A trap may be inhibited on this boundary due to an instruction
|
|
|
|
// which loaded SS. If so we clear the inhibit_mask below
|
|
|
|
// and don't execute this code until the next boundary.
|
|
|
|
// Commit debug events to DR6
|
|
|
|
BX_CPU_THIS_PTR dr6 |= BX_CPU_THIS_PTR debug_trap;
|
|
|
|
exception(BX_DB_EXCEPTION, 0, 0); // no error, not interrupt
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Priority 5: External Interrupts
|
|
|
|
// NMI Interrupts
|
|
|
|
// Maskable Hardware Interrupts
|
|
|
|
if (BX_CPU_THIS_PTR inhibit_mask & BX_INHIBIT_INTERRUPTS) {
|
|
|
|
// Processing external interrupts is inhibited on this
|
|
|
|
// boundary because of certain instructions like STI.
|
|
|
|
// inhibit_mask is cleared below, in which case we will have
|
|
|
|
// an opportunity to check interrupts on the next instruction
|
|
|
|
// boundary.
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2002-10-05 14:25:31 +04:00
|
|
|
else if (BX_CPU_INTR && BX_CPU_THIS_PTR get_IF () &&
|
2005-02-12 17:00:13 +03:00
|
|
|
BX_DBG_ASYNC_INTR)
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u vector;
|
|
|
|
|
|
|
|
// NOTE: similar code in ::take_irq()
|
2001-06-12 17:07:43 +04:00
|
|
|
#if BX_SUPPORT_APIC
|
2002-10-05 14:25:31 +04:00
|
|
|
if (BX_CPU_THIS_PTR local_apic.INTR)
|
2001-05-23 23:36:55 +04:00
|
|
|
vector = BX_CPU_THIS_PTR local_apic.acknowledge_int ();
|
2001-05-23 12:16:07 +04:00
|
|
|
else
|
2002-10-25 01:07:56 +04:00
|
|
|
vector = DEV_pic_iac(); // may set INTR with next interrupt
|
2001-05-23 12:16:07 +04:00
|
|
|
#else
|
|
|
|
// if no local APIC, always acknowledge the PIC.
|
2002-10-25 01:07:56 +04:00
|
|
|
vector = DEV_pic_iac(); // may set INTR with next interrupt
|
2001-05-23 12:16:07 +04:00
|
|
|
#endif
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_DEBUG(("decode: interrupt %u",
|
2001-05-23 12:16:07 +04:00
|
|
|
// (unsigned) vector));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR errorno = 0;
|
|
|
|
BX_CPU_THIS_PTR EXT = 1; /* external event */
|
|
|
|
interrupt(vector, 0, 0, 0);
|
2003-02-13 18:04:11 +03:00
|
|
|
BX_INSTR_HWINTERRUPT(BX_CPU_ID, vector,
|
2002-09-20 07:52:59 +04:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value, EIP);
|
2002-09-02 22:44:35 +04:00
|
|
|
// Set up environment, as would be when this main cpu loop gets
|
|
|
|
// invoked. At the end of normal instructions, we always commmit
|
|
|
|
// the new EIP/ESP values. But here, we call interrupt() much like
|
|
|
|
// it was a sofware interrupt instruction, and need to effect the
|
|
|
|
// commit here. This code mirrors similar code above.
|
2002-09-14 07:01:05 +04:00
|
|
|
BX_CPU_THIS_PTR prev_eip = RIP; // commit new RIP
|
|
|
|
BX_CPU_THIS_PTR prev_esp = RSP; // commit new RSP
|
2002-09-02 22:44:35 +04:00
|
|
|
BX_CPU_THIS_PTR EXT = 0;
|
|
|
|
BX_CPU_THIS_PTR errorno = 0;
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else if (BX_HRQ && BX_DBG_ASYNC_DMA) {
|
|
|
|
// NOTE: similar code in ::take_dma()
|
|
|
|
// assert Hold Acknowledge (HLDA) and go into a bus hold state
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_dma_raise_hlda();
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Priority 6: Faults from fetching next instruction
|
|
|
|
// Code breakpoint fault
|
|
|
|
// Code segment limit violation (priority 7 on 486/Pentium)
|
|
|
|
// Code page fault (priority 7 on 486/Pentium)
|
|
|
|
// (handled in main decode loop)
|
|
|
|
|
|
|
|
// Priority 7: Faults from decoding next instruction
|
|
|
|
// Instruction length > 15 bytes
|
|
|
|
// Illegal opcode
|
|
|
|
// Coprocessor not available
|
|
|
|
// (handled in main decode loop etc)
|
|
|
|
|
|
|
|
// Priority 8: Faults on executing an instruction
|
|
|
|
// Floating point execution
|
|
|
|
// Overflow
|
|
|
|
// Bound error
|
|
|
|
// Invalid TSS
|
|
|
|
// Segment not present
|
|
|
|
// Stack fault
|
|
|
|
// General protection
|
|
|
|
// Data page fault
|
|
|
|
// Alignment check
|
|
|
|
// (handled by rest of the code)
|
|
|
|
|
|
|
|
|
2005-02-12 17:00:13 +03:00
|
|
|
if (BX_CPU_THIS_PTR get_TF ())
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
// TF is set before execution of next instruction. Schedule
|
|
|
|
// a debug trap (#DB) after execution. After completion of
|
|
|
|
// next instruction, the code above will invoke the trap.
|
|
|
|
BX_CPU_THIS_PTR debug_trap |= 0x00004000; // BS flag in DR6
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-09-20 07:52:59 +04:00
|
|
|
// Now we can handle things which are synchronous to instruction
|
|
|
|
// execution.
|
2002-09-22 22:22:24 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_RF ()) {
|
2002-09-20 07:52:59 +04:00
|
|
|
BX_CPU_THIS_PTR clear_RF ();
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2002-09-20 07:52:59 +04:00
|
|
|
#if BX_X86_DEBUGGER
|
|
|
|
else {
|
|
|
|
// only bother comparing if any breakpoints enabled
|
|
|
|
if ( BX_CPU_THIS_PTR dr7 & 0x000000ff ) {
|
|
|
|
Bit32u iaddr =
|
2005-02-28 21:56:05 +03:00
|
|
|
BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS) +
|
2002-09-20 07:52:59 +04:00
|
|
|
BX_CPU_THIS_PTR prev_eip;
|
|
|
|
Bit32u dr6_bits;
|
|
|
|
if ( (dr6_bits = hwdebug_compare(iaddr, 1, BX_HWDebugInstruction,
|
2005-02-12 17:00:13 +03:00
|
|
|
BX_HWDebugInstruction)) )
|
|
|
|
{
|
2002-09-20 07:52:59 +04:00
|
|
|
// Add to the list of debug events thus far.
|
|
|
|
BX_CPU_THIS_PTR async_event = 1;
|
2003-08-04 20:03:09 +04:00
|
|
|
BX_CPU_THIS_PTR debug_trap |= dr6_bits;
|
2002-09-20 07:52:59 +04:00
|
|
|
// If debug events are not inhibited on this boundary,
|
|
|
|
// fire off a debug fault. Otherwise handle it on the next
|
|
|
|
// boundary. (becomes a trap)
|
|
|
|
if ( !(BX_CPU_THIS_PTR inhibit_mask & BX_INHIBIT_DEBUG) ) {
|
|
|
|
// Commit debug events to DR6
|
|
|
|
BX_CPU_THIS_PTR dr6 = BX_CPU_THIS_PTR debug_trap;
|
|
|
|
exception(BX_DB_EXCEPTION, 0, 0); // no error, not interrupt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-12 17:00:13 +03:00
|
|
|
}
|
2002-09-20 07:52:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// We have ignored processing of external interrupts and
|
|
|
|
// debug events on this boundary. Reset the mask so they
|
|
|
|
// will be processed on the next boundary.
|
|
|
|
BX_CPU_THIS_PTR inhibit_mask = 0;
|
|
|
|
|
2002-10-05 14:25:31 +04:00
|
|
|
if ( !(BX_CPU_INTR ||
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR debug_trap ||
|
|
|
|
BX_HRQ ||
|
2003-08-04 20:03:09 +04:00
|
|
|
BX_CPU_THIS_PTR get_TF ()
|
|
|
|
#if BX_X86_DEBUGGER
|
|
|
|
|| (BX_CPU_THIS_PTR dr7 & 0xff)
|
|
|
|
#endif
|
|
|
|
))
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR async_event = 0;
|
2002-10-05 18:51:25 +04:00
|
|
|
|
|
|
|
return 0; // Continue executing cpu_loop.
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// boundaries of consideration:
|
|
|
|
//
|
|
|
|
// * physical memory boundary: 1024k (1Megabyte) (increments of...)
|
|
|
|
// * A20 boundary: 1024k (1Megabyte)
|
|
|
|
// * page boundary: 4k
|
|
|
|
// * ROM boundary: 2k (dont care since we are only reading)
|
|
|
|
// * segment boundary: any
|
|
|
|
|
|
|
|
|
2005-02-12 17:00:13 +03:00
|
|
|
void BX_CPU_C::prefetch(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// prefetch QSIZE byte quantity aligned on corresponding boundary
|
2002-09-19 23:17:20 +04:00
|
|
|
Bit32u pAddr;
|
2002-09-14 07:01:05 +04:00
|
|
|
bx_address laddrPageOffset0, eipPageOffset0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-08-05 22:23:36 +04:00
|
|
|
bx_address temp_rip = RIP;
|
|
|
|
bx_address laddr = BX_CPU_THIS_PTR get_segment_base(BX_SEG_REG_CS) + temp_rip;
|
|
|
|
|
2005-12-10 00:21:29 +03:00
|
|
|
if (! Is64BitMode()) {
|
2005-08-05 22:23:36 +04:00
|
|
|
Bit32u temp_limit = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled;
|
2002-09-02 22:44:35 +04:00
|
|
|
|
2005-08-05 22:23:36 +04:00
|
|
|
if (((Bit32u) temp_rip) > temp_limit) {
|
|
|
|
BX_PANIC(("prefetch: RIP > CS.limit"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
2005-02-05 23:56:44 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-08-10 22:42:24 +04:00
|
|
|
#if BX_SUPPORT_PAGING
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_CPU_THIS_PTR cr0.pg) {
|
|
|
|
// aligned block guaranteed to be all in one page, same A20 address
|
2002-09-19 23:17:20 +04:00
|
|
|
pAddr = itranslate_linear(laddr, CPL==3);
|
|
|
|
pAddr = A20ADDR(pAddr);
|
2005-02-05 23:56:44 +03:00
|
|
|
}
|
2001-08-10 22:42:24 +04:00
|
|
|
else
|
|
|
|
#endif // BX_SUPPORT_PAGING
|
2005-02-05 23:56:44 +03:00
|
|
|
{
|
2002-09-19 23:17:20 +04:00
|
|
|
pAddr = A20ADDR(laddr);
|
2005-02-05 23:56:44 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-09-02 22:44:35 +04:00
|
|
|
// Linear address at the beginning of the page.
|
2003-02-28 05:37:18 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
laddrPageOffset0 = laddr & BX_CONST64(0xfffffffffffff000);
|
|
|
|
#else
|
2002-09-02 22:44:35 +04:00
|
|
|
laddrPageOffset0 = laddr & 0xfffff000;
|
2003-02-28 05:37:18 +03:00
|
|
|
#endif
|
2002-09-14 07:01:05 +04:00
|
|
|
// Calculate RIP at the beginning of the page.
|
|
|
|
eipPageOffset0 = RIP - (laddr - laddrPageOffset0);
|
2002-09-02 22:44:35 +04:00
|
|
|
BX_CPU_THIS_PTR eipPageBias = - eipPageOffset0;
|
|
|
|
BX_CPU_THIS_PTR eipPageWindowSize = 4096; // FIXME:
|
2002-09-19 23:17:20 +04:00
|
|
|
BX_CPU_THIS_PTR pAddrA20Page = pAddr & 0xfffff000;
|
2004-11-05 13:13:15 +03:00
|
|
|
BX_CPU_THIS_PTR eipFetchPtr =
|
|
|
|
BX_CPU_THIS_PTR mem->getHostMemAddr(BX_CPU_THIS, BX_CPU_THIS_PTR pAddrA20Page, BX_READ);
|
2002-09-02 22:44:35 +04:00
|
|
|
|
|
|
|
// Sanity checks
|
|
|
|
if ( !BX_CPU_THIS_PTR eipFetchPtr ) {
|
2002-09-19 23:17:20 +04:00
|
|
|
if ( pAddr >= BX_CPU_THIS_PTR mem->len ) {
|
2005-01-13 22:03:40 +03:00
|
|
|
BX_PANIC(("prefetch : running in bogus memory, pAddr=0x%08x", pAddr));
|
|
|
|
}
|
2002-09-02 22:44:35 +04:00
|
|
|
else {
|
2005-01-13 22:03:40 +03:00
|
|
|
BX_PANIC(("prefetch: getHostMemAddr vetoed direct read, pAddr=0x%08x", pAddr));
|
2002-09-02 22:44:35 +04:00
|
|
|
}
|
2005-01-13 22:03:40 +03:00
|
|
|
}
|
2003-05-11 02:25:55 +04:00
|
|
|
|
2004-07-30 00:15:19 +04:00
|
|
|
#if BX_SUPPORT_ICACHE
|
2005-08-13 18:10:22 +04:00
|
|
|
BX_CPU_THIS_PTR currPageWriteStampPtr = pageWriteStampTable.getPageWriteStampPtr(pAddr);
|
|
|
|
Bit32u pageWriteStamp = *(BX_CPU_THIS_PTR currPageWriteStampPtr);
|
2004-11-19 02:16:36 +03:00
|
|
|
Bit32u fetchModeMask = BX_CPU_THIS_PTR iCache.fetchModeMask;
|
|
|
|
if ((pageWriteStamp & ICacheFetchModeMask) != fetchModeMask)
|
|
|
|
{
|
2003-05-11 02:25:55 +04:00
|
|
|
// The current CPU mode does not match iCache entries for this
|
|
|
|
// physical page.
|
|
|
|
pageWriteStamp &= ICacheWriteStampMask; // Clear out old fetch mode bits.
|
2004-11-19 02:16:36 +03:00
|
|
|
pageWriteStamp |= fetchModeMask; // Add in new ones.
|
2005-04-10 23:42:48 +04:00
|
|
|
pageWriteStampTable.setPageWriteStamp(pAddr, pageWriteStamp);
|
2004-11-19 02:16:36 +03:00
|
|
|
}
|
2003-05-21 19:48:55 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-02-12 17:00:13 +03:00
|
|
|
void BX_CPU_C::boundaryFetch(Bit8u *fetchPtr, unsigned remainingInPage, bxInstruction_c *i)
|
2002-09-22 05:52:21 +04:00
|
|
|
{
|
2005-11-27 00:36:51 +03:00
|
|
|
unsigned j;
|
|
|
|
Bit8u fetchBuffer[16]; // Really only need 15
|
|
|
|
unsigned ret;
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
if (remainingInPage >= 15) {
|
|
|
|
BX_INFO(("fetchDecode #GP(0): too many instruction prefixes"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
// Read all leftover bytes in current page up to boundary.
|
|
|
|
for (j=0; j<remainingInPage; j++) {
|
|
|
|
fetchBuffer[j] = *fetchPtr++;
|
|
|
|
}
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
// The 2nd chunk of the instruction is on the next page.
|
|
|
|
// Set RIP to the 0th byte of the 2nd page, and force a
|
|
|
|
// prefetch so direct access of that physical page is possible, and
|
|
|
|
// all the associated info is updated.
|
|
|
|
RIP += remainingInPage;
|
|
|
|
prefetch();
|
|
|
|
if (BX_CPU_THIS_PTR eipPageWindowSize < 15) {
|
|
|
|
BX_PANIC(("fetch_decode: small window size after prefetch"));
|
|
|
|
}
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
// We can fetch straight from the 0th byte, which is eipFetchPtr;
|
|
|
|
fetchPtr = BX_CPU_THIS_PTR eipFetchPtr;
|
2002-09-22 05:52:21 +04:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
// read leftover bytes in next page
|
|
|
|
for (; j<15; j++) {
|
|
|
|
fetchBuffer[j] = *fetchPtr++;
|
|
|
|
}
|
2002-09-22 05:52:21 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2005-11-27 00:36:51 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
|
|
|
|
ret = fetchDecode64(fetchBuffer, i, 15);
|
|
|
|
}
|
|
|
|
else
|
2002-09-22 05:52:21 +04:00
|
|
|
#endif
|
2005-11-27 00:36:51 +03:00
|
|
|
{
|
|
|
|
ret = fetchDecode(fetchBuffer, i, 15);
|
|
|
|
}
|
2005-02-05 23:56:44 +03:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
if (ret==0) {
|
|
|
|
BX_INFO(("fetchDecode #GP(0): cross boundary"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0, 0);
|
|
|
|
}
|
2005-02-05 23:56:44 +03:00
|
|
|
|
2005-11-27 00:36:51 +03:00
|
|
|
// Restore EIP since we fudged it to start at the 2nd page boundary.
|
|
|
|
RIP = BX_CPU_THIS_PTR prev_eip;
|
2002-09-22 05:52:21 +04:00
|
|
|
|
|
|
|
// Since we cross an instruction boundary, note that we need a prefetch()
|
|
|
|
// again on the next instruction. Perhaps we can optimize this to
|
|
|
|
// eliminate the extra prefetch() since we do it above, but have to
|
|
|
|
// think about repeated instructions, etc.
|
|
|
|
BX_CPU_THIS_PTR eipPageWindowSize = 0; // Fixme
|
2002-09-28 04:54:05 +04:00
|
|
|
|
2003-02-13 18:04:11 +03:00
|
|
|
BX_INSTR_OPCODE(BX_CPU_ID, fetchBuffer, i->ilen(),
|
2005-11-14 21:25:41 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b, Is64BitMode());
|
2002-09-22 05:52:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-04 08:27:26 +03:00
|
|
|
#if BX_EXTERNAL_DEBUGGER
|
|
|
|
|
2005-08-28 21:37:37 +04:00
|
|
|
void BX_CPU_C::ask (int level, const char *prefix, const char *fmt, va_list ap)
|
2002-09-14 07:01:05 +04:00
|
|
|
{
|
|
|
|
char buf1[1024];
|
|
|
|
vsprintf (buf1, fmt, ap);
|
|
|
|
printf ("%s %s\n", prefix, buf1);
|
|
|
|
trap_debugger(1);
|
|
|
|
}
|
|
|
|
|
2005-08-28 21:37:37 +04:00
|
|
|
void BX_CPU_C::trap_debugger (bx_bool callnow)
|
2002-09-14 07:01:05 +04:00
|
|
|
{
|
|
|
|
regs.debug_state = debug_step;
|
|
|
|
if (callnow) {
|
2004-11-05 13:13:15 +03:00
|
|
|
bx_external_debugger(BX_CPU_THIS);
|
2002-09-14 07:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-04 08:27:26 +03:00
|
|
|
#endif // #if BX_EXTERNAL_DEBUGGER
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
extern unsigned int dbg_show_mask;
|
|
|
|
|
2006-01-19 21:32:39 +03:00
|
|
|
bx_bool BX_CPU_C::dbg_is_begin_instr_bpoint(Bit16u cs, bx_address eip, bx_address laddr, bx_bool is_32, bx_bool is_64)
|
2005-08-28 21:37:37 +04:00
|
|
|
{
|
|
|
|
Bit64u tt = bx_pc_system.time_ticks();
|
2005-08-15 09:32:36 +04:00
|
|
|
|
2001-05-24 22:46:34 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.cs = cs;
|
|
|
|
BX_CPU_THIS_PTR guard_found.eip = eip;
|
|
|
|
BX_CPU_THIS_PTR guard_found.laddr = laddr;
|
|
|
|
BX_CPU_THIS_PTR guard_found.is_32bit_code = is_32;
|
2006-01-19 21:32:39 +03:00
|
|
|
BX_CPU_THIS_PTR guard_found.is_64bit_code = is_64;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-01-24 22:03:55 +03:00
|
|
|
// mode switch breakpoint
|
2001-04-10 05:04:59 +04:00
|
|
|
// instruction which generate exceptions never reach the end of the
|
2001-05-23 12:16:07 +04:00
|
|
|
// loop due to a long jump. Thats why we check at start of instr.
|
2001-04-10 05:04:59 +04:00
|
|
|
// Downside is that we show the instruction about to be executed
|
|
|
|
// (not the one generating the mode switch).
|
|
|
|
if (BX_CPU_THIS_PTR mode_break &&
|
2006-01-24 22:03:55 +03:00
|
|
|
(BX_CPU_THIS_PTR dbg_cpu_mode != BX_CPU_THIS_PTR get_cpu_mode()))
|
|
|
|
{
|
|
|
|
BX_INFO(("[" FMT_LL "d] Caught mode switch breakpoint, switching from '%s' to '%s'",
|
|
|
|
bx_pc_system.time_ticks(), cpu_mode_string(BX_CPU_THIS_PTR dbg_cpu_mode),
|
|
|
|
cpu_mode_string(BX_CPU_THIS_PTR get_cpu_mode())));
|
|
|
|
BX_CPU_THIS_PTR dbg_cpu_mode = BX_CPU_THIS_PTR get_cpu_mode();
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_MODE_BREAK_POINT;
|
2006-01-24 22:03:55 +03:00
|
|
|
return(1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if( (BX_CPU_THIS_PTR show_flag) & (dbg_show_mask)) {
|
|
|
|
int rv;
|
|
|
|
if((rv = bx_dbg_symbolic_output()))
|
2006-01-24 22:03:55 +03:00
|
|
|
return(rv);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// see if debugger is looking for iaddr breakpoint of any type
|
|
|
|
if (bx_guard.guard_for & BX_DBG_GUARD_IADDR_ALL) {
|
|
|
|
#if BX_DBG_SUPPORT_VIR_BPOINT
|
|
|
|
if (bx_guard.guard_for & BX_DBG_GUARD_IADDR_VIR) {
|
2005-08-15 09:32:36 +04:00
|
|
|
if ((BX_CPU_THIS_PTR guard_found.icount!=0) ||
|
2005-08-28 21:37:37 +04:00
|
|
|
(tt != BX_CPU_THIS_PTR guard_found.time_tick))
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_virtual; i++) {
|
2003-08-04 20:03:09 +04:00
|
|
|
if ( bx_guard.iaddr.vir[i].enabled &&
|
|
|
|
(bx_guard.iaddr.vir[i].cs == cs) &&
|
2006-01-19 21:32:39 +03:00
|
|
|
(bx_guard.iaddr.vir[i].eip == eip) )
|
|
|
|
{
|
2001-05-24 22:46:34 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.guard_found = BX_DBG_GUARD_IADDR_VIR;
|
|
|
|
BX_CPU_THIS_PTR guard_found.iaddr_index = i;
|
2005-08-15 19:43:04 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.time_tick = tt;
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1); // on a breakpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
#if BX_DBG_SUPPORT_LIN_BPOINT
|
|
|
|
if (bx_guard.guard_for & BX_DBG_GUARD_IADDR_LIN) {
|
2005-08-15 09:32:36 +04:00
|
|
|
if ((BX_CPU_THIS_PTR guard_found.icount!=0) ||
|
2005-08-28 21:37:37 +04:00
|
|
|
(tt != BX_CPU_THIS_PTR guard_found.time_tick))
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_linear; i++) {
|
2003-08-04 20:03:09 +04:00
|
|
|
if (bx_guard.iaddr.lin[i].enabled &&
|
2006-01-19 21:32:39 +03:00
|
|
|
(bx_guard.iaddr.lin[i].addr == BX_CPU_THIS_PTR guard_found.laddr) )
|
|
|
|
{
|
2001-05-24 22:46:34 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.guard_found = BX_DBG_GUARD_IADDR_LIN;
|
|
|
|
BX_CPU_THIS_PTR guard_found.iaddr_index = i;
|
2005-08-15 19:43:04 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.time_tick = tt;
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1); // on a breakpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
#if BX_DBG_SUPPORT_PHY_BPOINT
|
|
|
|
if (bx_guard.guard_for & BX_DBG_GUARD_IADDR_PHY) {
|
|
|
|
Bit32u phy;
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool valid;
|
2001-05-24 22:46:34 +04:00
|
|
|
dbg_xlate_linear2phy(BX_CPU_THIS_PTR guard_found.laddr,
|
2001-04-10 05:04:59 +04:00
|
|
|
&phy, &valid);
|
2001-09-28 03:41:18 +04:00
|
|
|
// The "guard_found.icount!=0" condition allows you to step or
|
|
|
|
// continue beyond a breakpoint. Bryce tried removing it once,
|
|
|
|
// and once you get to a breakpoint you are stuck there forever.
|
|
|
|
// Not pretty.
|
2005-08-15 09:32:36 +04:00
|
|
|
if (valid && ((BX_CPU_THIS_PTR guard_found.icount!=0) ||
|
2005-08-28 21:37:37 +04:00
|
|
|
(tt != BX_CPU_THIS_PTR guard_found.time_tick)))
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
for (unsigned i=0; i<bx_guard.iaddr.num_physical; i++) {
|
2005-08-28 21:37:37 +04:00
|
|
|
if (bx_guard.iaddr.phy[i].enabled && (bx_guard.iaddr.phy[i].addr == phy))
|
|
|
|
{
|
2001-05-24 22:46:34 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.guard_found = BX_DBG_GUARD_IADDR_PHY;
|
|
|
|
BX_CPU_THIS_PTR guard_found.iaddr_index = i;
|
2005-08-15 09:32:36 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.time_tick = tt;
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1); // on a breakpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-12 22:08:10 +04:00
|
|
|
#endif
|
|
|
|
}
|
2005-08-28 21:37:37 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // not on a breakpoint
|
|
|
|
}
|
|
|
|
|
2006-01-19 21:32:39 +03:00
|
|
|
bx_bool BX_CPU_C::dbg_is_end_instr_bpoint(Bit16u cs, bx_address eip, bx_address laddr, bx_bool is_32, bx_bool is_64)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-09-27 18:19:38 +04:00
|
|
|
//fprintf (stderr, "end_instr_bp: checking for icount or ^C\n");
|
2001-05-24 22:46:34 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.icount++;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-09-27 18:19:38 +04:00
|
|
|
// convenient point to see if user typed Ctrl-C
|
|
|
|
if (bx_guard.interrupt_requested &&
|
2005-04-12 22:08:10 +04:00
|
|
|
(bx_guard.guard_for & BX_DBG_GUARD_CTRL_C))
|
|
|
|
{
|
2001-09-27 18:19:38 +04:00
|
|
|
BX_CPU_THIS_PTR guard_found.guard_found = BX_DBG_GUARD_CTRL_C;
|
|
|
|
return(1);
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-09-27 18:19:38 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// see if debugger requesting icount guard
|
|
|
|
if (bx_guard.guard_for & BX_DBG_GUARD_ICOUNT) {
|
2001-05-24 22:46:34 +04:00
|
|
|
if (BX_CPU_THIS_PTR guard_found.icount >= bx_guard.icount) {
|
|
|
|
BX_CPU_THIS_PTR guard_found.cs = cs;
|
|
|
|
BX_CPU_THIS_PTR guard_found.eip = eip;
|
|
|
|
BX_CPU_THIS_PTR guard_found.laddr = laddr;
|
|
|
|
BX_CPU_THIS_PTR guard_found.is_32bit_code = is_32;
|
|
|
|
BX_CPU_THIS_PTR guard_found.guard_found = BX_DBG_GUARD_ICOUNT;
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1);
|
|
|
|
}
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if (BX_NUM_SIMULATORS >= 2)
|
|
|
|
// if async event pending, acknowlege them
|
|
|
|
if (bx_guard.async_changes_pending.which) {
|
|
|
|
if (bx_guard.async_changes_pending.which & BX_DBG_ASYNC_PENDING_A20)
|
|
|
|
bx_dbg_async_pin_ack(BX_DBG_ASYNC_PENDING_A20,
|
|
|
|
bx_guard.async_changes_pending.a20);
|
|
|
|
if (bx_guard.async_changes_pending.which) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("decode: async pending unrecognized."));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
return(0); // no breakpoint
|
|
|
|
}
|
|
|
|
|
2005-08-28 21:37:37 +04:00
|
|
|
void BX_CPU_C::dbg_take_irq(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
unsigned vector;
|
|
|
|
|
|
|
|
// NOTE: similar code in ::cpu_loop()
|
|
|
|
|
2002-10-05 14:25:31 +04:00
|
|
|
if ( BX_CPU_INTR && BX_CPU_THIS_PTR get_IF () ) {
|
2001-04-10 05:04:59 +04:00
|
|
|
if ( setjmp(BX_CPU_THIS_PTR jmp_buf_env) == 0 ) {
|
|
|
|
// normal return from setjmp setup
|
2002-10-25 01:07:56 +04:00
|
|
|
vector = DEV_pic_iac(); // may set INTR with next interrupt
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR errorno = 0;
|
|
|
|
BX_CPU_THIS_PTR EXT = 1; // external event
|
|
|
|
BX_CPU_THIS_PTR async_event = 1; // set in case INTR is triggered
|
|
|
|
interrupt(vector, 0, 0, 0);
|
|
|
|
}
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-08-28 21:37:37 +04:00
|
|
|
void BX_CPU_C::dbg_force_interrupt(unsigned vector)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// Used to force slave simulator to take an interrupt, without
|
|
|
|
// regard to IF
|
|
|
|
|
|
|
|
if ( setjmp(BX_CPU_THIS_PTR jmp_buf_env) == 0 ) {
|
|
|
|
// normal return from setjmp setup
|
|
|
|
BX_CPU_THIS_PTR errorno = 0;
|
|
|
|
BX_CPU_THIS_PTR EXT = 1; // external event
|
|
|
|
BX_CPU_THIS_PTR async_event = 1; // probably don't need this
|
|
|
|
interrupt(vector, 0, 0, 0);
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-08-28 21:37:37 +04:00
|
|
|
void BX_CPU_C::dbg_take_dma(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// NOTE: similar code in ::cpu_loop()
|
|
|
|
if ( BX_HRQ ) {
|
|
|
|
BX_CPU_THIS_PTR async_event = 1; // set in case INTR is triggered
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_dma_raise_hlda();
|
2005-04-12 22:08:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-04-12 22:08:10 +04:00
|
|
|
#endif // #if BX_DEBUGGER
|