Additionally passing the current Bochs CPU context and instruction cache entry to BochsController (enables detailed instruction analysis and modification)
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1361 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -19,7 +19,8 @@ bx_bool interrupt_injection_request = false;
|
||||
int interrupt_to_fire = -1;
|
||||
|
||||
BochsController::BochsController()
|
||||
: SimulatorController(new BochsRegisterManager(), new BochsMemoryManager())
|
||||
: SimulatorController(new BochsRegisterManager(), new BochsMemoryManager()),
|
||||
m_CPUContext(NULL), m_CacheEntry(NULL)
|
||||
{
|
||||
// -------------------------------------
|
||||
// Add the general purpose register:
|
||||
@ -89,12 +90,15 @@ void BochsController::dbgEnableInstrPtrOutput(unsigned regularity, std::ostream*
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
void BochsController::onInstrPtrChanged(address_t instrPtr, address_t address_space)
|
||||
void BochsController::onInstrPtrChanged(address_t instrPtr, address_t address_space,
|
||||
BX_CPU_C *context, bxICacheEntry_c *cache_entry)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if(m_Regularity != 0 && ++m_Counter % m_Regularity == 0)
|
||||
(*m_pDest) << "0x" << std::hex << instrPtr;
|
||||
#endif
|
||||
m_CPUContext = context;
|
||||
m_CacheEntry = cache_entry;
|
||||
bool do_fire = false;
|
||||
// Check for active breakpoint-events:
|
||||
bp_cache_t &buffer_cache = m_EvList.getBPBuffer();
|
||||
@ -117,31 +121,6 @@ void BochsController::onInstrPtrChanged(address_t instrPtr, address_t address_sp
|
||||
m_EvList.fireActiveEvents();
|
||||
// Note: SimulatorController::onBreakpointEvent will not be invoked in this
|
||||
// implementation.
|
||||
#if 0
|
||||
//deprecated - this code is ugly
|
||||
bool do_fire = false;
|
||||
int i = 0;
|
||||
BufferCache<BPEvent*> *buffer_cache = m_EvList.getBPBuffer();
|
||||
while(i < buffer_cache->getCount()) {
|
||||
BPEvent *pEvBreakpt = buffer_cache->get(i);
|
||||
if(pEvBreakpt->isMatching(instrPtr, address_space)) {
|
||||
pEvBreakpt->setTriggerInstructionPointer(instrPtr);
|
||||
|
||||
i = buffer_cache->makeActive(m_EvList, i);
|
||||
assert(i >= 0 &&
|
||||
"FATAL ERROR: Could not erase BPEvent from cache");
|
||||
|
||||
// we now know we need to fire the active events - usually we do not have to
|
||||
do_fire = true;
|
||||
// "i" has already been set to the next element (by calling
|
||||
// makeActive()):
|
||||
continue; // -> skip loop increment
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(do_fire)
|
||||
m_EvList.fireActiveEvents();
|
||||
#endif
|
||||
}
|
||||
|
||||
void BochsController::onIOPortEvent(unsigned char data, unsigned port, bool out) {
|
||||
@ -300,11 +279,13 @@ void BochsController::onEventTrigger(BaseEvent* pev)
|
||||
const std::string& BochsController::getMnemonic() const
|
||||
{
|
||||
static std::string str;
|
||||
#if 0
|
||||
bxICacheEntry_c* pEntry = BX_CPU(0)->getICacheEntry();
|
||||
assert(pEntry != NULL && "FATAL ERROR: Bochs internal function returned NULL (not expected)!");
|
||||
bxInstruction_c* pInstr = pEntry->i;
|
||||
assert(pInstr != NULL && "FATAL ERROR: Bochs internal member was NULL (not expected)!");
|
||||
const char* pszName = get_bx_opcode_name(pInstr->getIaOpcode());
|
||||
#endif
|
||||
const char* pszName = get_bx_opcode_name(getICacheEntry()->i->getIaOpcode());
|
||||
if (pszName != NULL)
|
||||
str = pszName;
|
||||
else
|
||||
|
||||
@ -81,7 +81,7 @@ public:
|
||||
* @param instrPtr the new instruction pointer
|
||||
* @param address_space the address space the CPU is currently in
|
||||
*/
|
||||
void onInstrPtrChanged(address_t instrPtr, address_t address_space);
|
||||
void onInstrPtrChanged(address_t instrPtr, address_t address_space, BX_CPU_C *context, bxICacheEntry_c *cache_entry);
|
||||
/**
|
||||
* I/O port communication handler. This method is called (from
|
||||
* the IOPortCom aspect) every time when Bochs performs a port I/O operation.
|
||||
@ -174,6 +174,19 @@ public:
|
||||
* the returned string is empty
|
||||
*/
|
||||
const std::string& getMnemonic() const;
|
||||
/**
|
||||
* Retrieves the current Bochs instruction cache entry
|
||||
* @returns a pointer to a bxICacheEntry_c object
|
||||
*/
|
||||
inline bxICacheEntry_c *getICacheEntry() const { return m_CacheEntry; }
|
||||
/**
|
||||
* Retrieves the current CPU context
|
||||
* @return a pointer to a BX_CPU_C object
|
||||
*/
|
||||
inline BX_CPU_C *getCPUContext() const { return m_CPUContext; }
|
||||
private:
|
||||
BX_CPU_C *m_CPUContext;
|
||||
bxICacheEntry_c *m_CacheEntry;
|
||||
};
|
||||
|
||||
} // end-of-namespace: fail
|
||||
|
||||
@ -19,10 +19,10 @@ aspect Breakpoints {
|
||||
// BX_CPU(0) otherwise
|
||||
BX_CPU_C* pThis = *(tjp->arg<0>());
|
||||
// Points to the *current* bxInstruction-object
|
||||
//bxInstruction_c* pInstr = *(tjp->arg<1>());
|
||||
bxICacheEntry_c* pEntry = *(tjp->arg<1>());
|
||||
|
||||
// report this event to the Bochs controller:
|
||||
fail::simulator.onInstrPtrChanged(pThis->get_instruction_pointer(), pThis->cr3);
|
||||
fail::simulator.onInstrPtrChanged(pThis->get_instruction_pointer(), pThis->cr3, pThis, pEntry);
|
||||
// Note: get_bx_opcode_name(pInstr->getIaOpcode()) retrieves the mnemonics.
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user