coastline 0.0.4
Loading...
Searching...
No Matches
coastline::MipsCpu Class Reference

The VR4300 processor and the RDRAM it runs from. More...

#include <mipscpu.h>

Collaboration diagram for coastline::MipsCpu:

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.

Detailed Description

The VR4300 processor and the RDRAM it runs from.

Member Typedef Documentation

◆ Hook

A routine called before the instruction at the address it is set on.

◆ DeviceRead

A read of the registers of the console: the physical address and the size in bytes.

◆ DeviceWrite

A write to the registers of the console: the physical address, the size, and the value.

Member Enumeration Documentation

◆ HookResult

enum class coastline::MipsCpu::HookResult
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.

Constructor & Destructor Documentation

◆ MipsCpu()

coastline::MipsCpu::MipsCpu ( std::size_t ramSize)
explicit

Make a processor with zeroed RDRAM.

Parameters
ramSizeThe bytes of RDRAM, a multiple of 4.

Member Function Documentation

◆ SetRom()

void coastline::MipsCpu::SetRom ( std::span< const std::uint8_t > rom)

Set the cartridge image the physical addresses from 0x10000000 read.

Parameters
romThe image, in the byte order of the console. It must remain valid while the processor runs.

◆ SetHook()

void coastline::MipsCpu::SetHook ( std::uint32_t address,
Hook hook )

Set the routine called before the instruction at an address of RDRAM.

Parameters
addressThe virtual address, in KSEG0.
hookThe routine.

◆ SetDevices()

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.

Parameters
readThe routine of the reads.
writeThe routine of the writes.

◆ SetIdle()

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.

Parameters
idleThe routine.

◆ Run()

bool coastline::MipsCpu::Run ( std::uint64_t budget)

Run instructions until Stop() or a fault.

Parameters
budgetThe most instructions to run.
Returns
Whether the processor stopped by Stop(), rather than by a fault or the budget.

◆ Stop()

void coastline::MipsCpu::Stop ( )

Stop Run() before the next instruction.

◆ Return()

void coastline::MipsCpu::Return ( std::uint32_t value)

Return from the routine a hook is on, as its last instruction would.

Parameters
valueThe value in v0, sign-extended from 32 bits.

◆ Jump()

void coastline::MipsCpu::Jump ( std::uint32_t address)

Set the program counter, with no branch pending.

Parameters
addressThe address of the next instruction.

◆ Fault()

const std::string & coastline::MipsCpu::Fault ( ) const
inline
Returns
The fault that ended Run(), or empty text. Later faults replace the stored text.

◆ Read8()

std::uint8_t coastline::MipsCpu::Read8 ( std::uint32_t address)

Read a byte of memory, through the map of the console.

Parameters
addressThe virtual address.
Returns
The byte, or zero after a fault.

◆ Read16()

std::uint16_t coastline::MipsCpu::Read16 ( std::uint32_t address)

Read a big-endian half-word of memory.

Parameters
addressThe virtual address, a multiple of 2.
Returns
The half-word.

◆ Read32()

std::uint32_t coastline::MipsCpu::Read32 ( std::uint32_t address)

Read a big-endian word of memory.

Parameters
addressThe virtual address, a multiple of 4.
Returns
The word.

◆ Read64()

std::uint64_t coastline::MipsCpu::Read64 ( std::uint32_t address)

Read a big-endian double word of memory.

Parameters
addressThe virtual address, a multiple of 8.
Returns
The double word.

◆ Write8()

void coastline::MipsCpu::Write8 ( std::uint32_t address,
std::uint8_t value )

Write a byte of memory.

Parameters
addressThe virtual address.
valueThe byte.

◆ Write16()

void coastline::MipsCpu::Write16 ( std::uint32_t address,
std::uint16_t value )

Write a big-endian half-word of memory.

Parameters
addressThe virtual address, a multiple of 2.
valueThe half-word.

◆ Write32()

void coastline::MipsCpu::Write32 ( std::uint32_t address,
std::uint32_t value )

Write a big-endian word of memory.

Parameters
addressThe virtual address, a multiple of 4.
valueThe word.

◆ Write64()

void coastline::MipsCpu::Write64 ( std::uint32_t address,
std::uint64_t value )

Write a big-endian double word of memory.

Parameters
addressThe virtual address, a multiple of 8.
valueThe double word.

◆ ReadFloat()

float coastline::MipsCpu::ReadFloat ( std::uint32_t address)

Read a single-precision value of memory.

Parameters
addressThe virtual address, a multiple of 4.
Returns
The value.

◆ Argument()

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.

Parameters
indexThe argument, from 0.
Returns
The low word of the argument.

◆ Ticks()

std::uint64_t coastline::MipsCpu::Ticks ( ) const
inline
Returns
Count ticks since power on, one for two instructions plus accumulated idle ticks.

◆ Count()

std::uint32_t coastline::MipsCpu::Count ( ) const
inline
Returns
The value of Count, the low word of Ticks().

Member Data Documentation

◆ ram

std::vector<std::uint8_t> coastline::MipsCpu::ram

The RDRAM.

◆ gpr

std::uint64_t coastline::MipsCpu::gpr[32] = {}

The general registers.

◆ hi

std::uint64_t coastline::MipsCpu::hi = 0

The high word of a product or the remainder of a division.

◆ lo

std::uint64_t coastline::MipsCpu::lo = 0

The low word of a product or the quotient of a division.

◆ fpr

std::uint32_t coastline::MipsCpu::fpr[32] = {}

The floating-point registers, as 32-bit halves.

A double is the pair from an even one.

◆ fcr31

std::uint32_t coastline::MipsCpu::fcr31 = 0

The control and status register of the floating-point unit.

◆ cop0

std::uint32_t coastline::MipsCpu::cop0[32] = {}

The registers of the system control processor.

Count is computed from the instructions.

◆ pc

std::uint32_t coastline::MipsCpu::pc = 0

The address of the next instruction.

◆ npc

std::uint32_t coastline::MipsCpu::npc = 4

The address of the instruction after it, the target of a branch taken.

◆ instructions

std::uint64_t coastline::MipsCpu::instructions = 0

The instructions run.

◆ idleTicks

std::uint64_t coastline::MipsCpu::idleTicks = 0

The ticks of Count added to those of the instructions, as time spent idle.


The documentation for this class was generated from the following file: