|
coastline 0.0.4
|
The VR4300 processor and the RDRAM it runs from. More...
#include <mipscpu.h>

Public Types | |
| enum class | HookResult { Continue , Jumped } |
| What a hook did. More... | |
| using | Hook = std::function<HookResult(MipsCpu &)> |
| A routine called before the instruction at the address it is set on. | |
| using | DeviceRead = std::function<std::uint64_t(std::uint32_t address, int size)> |
| A read of the registers of the console: the physical address and the size in bytes. | |
| using | DeviceWrite = std::function<void(std::uint32_t address, int size, std::uint64_t value)> |
| A write to the registers of the console: the physical address, the size, and the value. | |
Public Member Functions | |
| MipsCpu (std::size_t ramSize) | |
| Make a processor with zeroed RDRAM. | |
| void | SetRom (std::span< const std::uint8_t > rom) |
| Set the cartridge image the physical addresses from 0x10000000 read. | |
| void | SetHook (std::uint32_t address, Hook hook) |
| Set the routine called before the instruction at an address of RDRAM. | |
| void | SetDevices (DeviceRead read, DeviceWrite write) |
| Set the routines the registers of the console are read and written through. | |
| void | SetIdle (std::function< void(MipsCpu &)> idle) |
| Set the routine called when the processor spins on a branch to itself, as an idle thread does. | |
| bool | Run (std::uint64_t budget) |
| Run instructions until Stop() or a fault. | |
| void | Stop () |
| Stop Run() before the next instruction. | |
| void | Return (std::uint32_t value) |
| Return from the routine a hook is on, as its last instruction would. | |
| void | Jump (std::uint32_t address) |
| Set the program counter, with no branch pending. | |
| const std::string & | Fault () const |
| std::uint8_t | Read8 (std::uint32_t address) |
| Read a byte of memory, through the map of the console. | |
| std::uint16_t | Read16 (std::uint32_t address) |
| Read a big-endian half-word of memory. | |
| std::uint32_t | Read32 (std::uint32_t address) |
| Read a big-endian word of memory. | |
| std::uint64_t | Read64 (std::uint32_t address) |
| Read a big-endian double word of memory. | |
| void | Write8 (std::uint32_t address, std::uint8_t value) |
| Write a byte of memory. | |
| void | Write16 (std::uint32_t address, std::uint16_t value) |
| Write a big-endian half-word of memory. | |
| void | Write32 (std::uint32_t address, std::uint32_t value) |
| Write a big-endian word of memory. | |
| void | Write64 (std::uint32_t address, std::uint64_t value) |
| Write a big-endian double word of memory. | |
| float | ReadFloat (std::uint32_t address) |
| Read a single-precision value of memory. | |
| std::uint32_t | Argument (int index) |
| Read an argument of the routine a hook is on, from a0 to a3 and then from the stack. | |
| std::uint64_t | Ticks () const |
| std::uint32_t | Count () const |
Public Attributes | |
| std::vector< std::uint8_t > | ram |
| The RDRAM. | |
| std::uint64_t | gpr [32] = {} |
| The general registers. | |
| std::uint64_t | hi = 0 |
| The high word of a product or the remainder of a division. | |
| std::uint64_t | lo = 0 |
| The low word of a product or the quotient of a division. | |
| std::uint32_t | fpr [32] = {} |
| The floating-point registers, as 32-bit halves. | |
| std::uint32_t | fcr31 = 0 |
| The control and status register of the floating-point unit. | |
| std::uint32_t | cop0 [32] = {} |
| The registers of the system control processor. | |
| std::uint32_t | pc = 0 |
| The address of the next instruction. | |
| std::uint32_t | npc = 4 |
| The address of the instruction after it, the target of a branch taken. | |
| std::uint64_t | instructions = 0 |
| The instructions run. | |
| std::uint64_t | idleTicks = 0 |
| The ticks of Count added to those of the instructions, as time spent idle. | |
The VR4300 processor and the RDRAM it runs from.
| using coastline::MipsCpu::Hook = std::function<HookResult(MipsCpu &)> |
A routine called before the instruction at the address it is set on.
| using coastline::MipsCpu::DeviceRead = std::function<std::uint64_t(std::uint32_t address, int size)> |
A read of the registers of the console: the physical address and the size in bytes.
| using coastline::MipsCpu::DeviceWrite = std::function<void(std::uint32_t address, int size, std::uint64_t value)> |
A write to the registers of the console: the physical address, the size, and the value.
|
strong |
What a hook did.
Run the instruction at the address of the hook, as if the hook were not there, or skip it because the hook moved the program counter, as Return() does.
| Enumerator | |
|---|---|
| Continue | Execute the hooked instruction normally. |
| Jumped | Skip the instruction after the hook changed the program counter. |
|
explicit |
Make a processor with zeroed RDRAM.
| ramSize | The bytes of RDRAM, a multiple of 4. |
| void coastline::MipsCpu::SetRom | ( | std::span< const std::uint8_t > | rom | ) |
Set the cartridge image the physical addresses from 0x10000000 read.
| rom | The image, in the byte order of the console. It must remain valid while the processor runs. |
| void coastline::MipsCpu::SetHook | ( | std::uint32_t | address, |
| Hook | hook ) |
Set the routine called before the instruction at an address of RDRAM.
| address | The virtual address, in KSEG0. |
| hook | The routine. |
| void coastline::MipsCpu::SetDevices | ( | DeviceRead | read, |
| DeviceWrite | write ) |
Set the routines the registers of the console are read and written through.
Without them, a read gives zero and a write is discarded.
| read | The routine of the reads. |
| write | The routine of the writes. |
| void coastline::MipsCpu::SetIdle | ( | std::function< void(MipsCpu &)> | idle | ) |
Set the routine called when the processor spins on a branch to itself, as an idle thread does.
| idle | The routine. |
| bool coastline::MipsCpu::Run | ( | std::uint64_t | budget | ) |
| void coastline::MipsCpu::Stop | ( | ) |
Stop Run() before the next instruction.
| void coastline::MipsCpu::Return | ( | std::uint32_t | value | ) |
Return from the routine a hook is on, as its last instruction would.
| value | The value in v0, sign-extended from 32 bits. |
| void coastline::MipsCpu::Jump | ( | std::uint32_t | address | ) |
Set the program counter, with no branch pending.
| address | The address of the next instruction. |
|
inline |
| std::uint8_t coastline::MipsCpu::Read8 | ( | std::uint32_t | address | ) |
Read a byte of memory, through the map of the console.
| address | The virtual address. |
| std::uint16_t coastline::MipsCpu::Read16 | ( | std::uint32_t | address | ) |
Read a big-endian half-word of memory.
| address | The virtual address, a multiple of 2. |
| std::uint32_t coastline::MipsCpu::Read32 | ( | std::uint32_t | address | ) |
Read a big-endian word of memory.
| address | The virtual address, a multiple of 4. |
| std::uint64_t coastline::MipsCpu::Read64 | ( | std::uint32_t | address | ) |
Read a big-endian double word of memory.
| address | The virtual address, a multiple of 8. |
| void coastline::MipsCpu::Write8 | ( | std::uint32_t | address, |
| std::uint8_t | value ) |
Write a byte of memory.
| address | The virtual address. |
| value | The byte. |
| void coastline::MipsCpu::Write16 | ( | std::uint32_t | address, |
| std::uint16_t | value ) |
Write a big-endian half-word of memory.
| address | The virtual address, a multiple of 2. |
| value | The half-word. |
| void coastline::MipsCpu::Write32 | ( | std::uint32_t | address, |
| std::uint32_t | value ) |
Write a big-endian word of memory.
| address | The virtual address, a multiple of 4. |
| value | The word. |
| void coastline::MipsCpu::Write64 | ( | std::uint32_t | address, |
| std::uint64_t | value ) |
Write a big-endian double word of memory.
| address | The virtual address, a multiple of 8. |
| value | The double word. |
| float coastline::MipsCpu::ReadFloat | ( | std::uint32_t | address | ) |
Read a single-precision value of memory.
| address | The virtual address, a multiple of 4. |
| std::uint32_t coastline::MipsCpu::Argument | ( | int | index | ) |
Read an argument of the routine a hook is on, from a0 to a3 and then from the stack.
| index | The argument, from 0. |
|
inline |
|
inline |
| std::vector<std::uint8_t> coastline::MipsCpu::ram |
The RDRAM.
| std::uint64_t coastline::MipsCpu::gpr[32] = {} |
The general registers.
| std::uint64_t coastline::MipsCpu::hi = 0 |
The high word of a product or the remainder of a division.
| std::uint64_t coastline::MipsCpu::lo = 0 |
The low word of a product or the quotient of a division.
| std::uint32_t coastline::MipsCpu::fpr[32] = {} |
The floating-point registers, as 32-bit halves.
A double is the pair from an even one.
| std::uint32_t coastline::MipsCpu::fcr31 = 0 |
The control and status register of the floating-point unit.
| std::uint32_t coastline::MipsCpu::cop0[32] = {} |
The registers of the system control processor.
Count is computed from the instructions.
| std::uint32_t coastline::MipsCpu::pc = 0 |
The address of the next instruction.
| std::uint32_t coastline::MipsCpu::npc = 4 |
The address of the instruction after it, the target of a branch taken.
| std::uint64_t coastline::MipsCpu::instructions = 0 |
The instructions run.
| std::uint64_t coastline::MipsCpu::idleTicks = 0 |
The ticks of Count added to those of the instructions, as time spent idle.