Started work on CPU class
This commit is contained in:
parent
dba1241f2d
commit
2c93d6e2f2
2 changed files with 41 additions and 3 deletions
|
|
@ -24,8 +24,35 @@ namespace dragon
|
|||
{
|
||||
namespace hw
|
||||
{
|
||||
CPU::CPU(void)
|
||||
CPU::CPU(BUS& bus) : m_bus(bus), m_mmu(m_bus, &m_accessMode)
|
||||
{
|
||||
}
|
||||
|
||||
bool CPU::run(void)
|
||||
{
|
||||
while (!m_halted)
|
||||
{
|
||||
try
|
||||
{
|
||||
step(); // fetch + decode + execute one instruction
|
||||
}
|
||||
catch (const GuestException& e)
|
||||
{
|
||||
take_exception(e.cause, e.fault_addr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPU::take_exception(ExceptionCause cause, VirtualAddress fault_addr)
|
||||
{
|
||||
// m_epc = m_faulting_pc; // saved before/during the faulting instr
|
||||
// m_cause = static_cast<u32>(cause);
|
||||
// m_badaddr = fault_addr;
|
||||
// m_estatus = pack_mode_and_ie(); // save mode/IE
|
||||
// set_mode_supervisor();
|
||||
// set_interrupts_enabled(false);
|
||||
// m_pc = m_iv; // jump to single entry point
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,18 +20,29 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// #include "../common/Data.hpp"
|
||||
#include "../common/Data.hpp"
|
||||
#include "MMU.hpp"
|
||||
|
||||
namespace dragon
|
||||
{
|
||||
namespace hw
|
||||
{
|
||||
class BUS;
|
||||
class CPU
|
||||
{
|
||||
public:
|
||||
CPU(void);
|
||||
CPU(BUS& bus);
|
||||
bool run(void);
|
||||
|
||||
private:
|
||||
void take_exception(ExceptionCause cause, VirtualAddress fault_addr);
|
||||
void step(void);
|
||||
|
||||
private:
|
||||
bool m_halted { true };
|
||||
MMUAccessMode m_accessMode { MMUAccessMode::Privileged };
|
||||
BUS& m_bus;
|
||||
MMU m_mmu;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue