Documentation
¶
Index ¶
- Constants
- type AddressBus
- type AddressError
- type AddressRange
- type AddressRangeDevice
- type Breakpoint
- type BreakpointEvent
- type BreakpointHit
- type BreakpointType
- type Bus
- type BusAccessCallback
- type BusAccessInfo
- type BusError
- type CPU
- type ContainsDevice
- type CycleListener
- type CycleScheduler
- func (s *CycleScheduler) AddListener(listener CycleListener)
- func (s *CycleScheduler) Advance(cpuDelta uint64)
- func (s *CycleScheduler) Now() uint64
- func (s *CycleScheduler) Reset(now uint64)
- func (s *CycleScheduler) Schedule(at uint64, fn func(now uint64))
- func (s *CycleScheduler) ScheduleAfter(delta uint64, fn func(now uint64))
- func (s *CycleScheduler) SetClockRatio(deviceHz, cpuHz uint64)
- type DebugFaultInfo
- type DebugState
- type Device
- type DisassemblyLine
- type ExceptionCallback
- type ExceptionInfo
- type ExceptionStackFrame
- type ExceptionStackFrameFormat
- type FastRegion
- type HistoryEntry
- type HistoryKind
- type Hooks
- type IRQSource
- type InterruptCallback
- type InterruptInfo
- type MemoryRange
- type Option
- type PeekDevice
- type PreTraceCallback
- type PreTraceInfo
- type RAM
- func (ram *RAM) AddressRange() (uint32, uint32)
- func (ram *RAM) Contains(address uint32) bool
- func (ram *RAM) Peek(s Size, address uint32) (uint32, error)
- func (ram *RAM) Read(s Size, address uint32) (uint32, error)
- func (ram *RAM) Reset()
- func (ram *RAM) Write(s Size, address uint32, value uint32) error
- type Registers
- type RunPredicateInfo
- type RunResult
- type RunStopReason
- type RunUntilOptions
- type Size
- type TraceCallback
- type TraceInfo
- type VerboseLogger
- type VerboseLoggerOptions
- type WaitStateDevice
Constants ¶
const ( Version = "1.5.0" XBusError = 2 XAddressError = 3 XIllegal = 4 XDivByZero = 5 XPrivViolation = 8 XLineA = 10 XLineF = 11 XUninitializedInt = 15 XTrap = 32 )
const AutoVector uint8 = 0
AutoVector is the vector value that asks the CPU to auto-vector an interrupt request (using vector 24+level) instead of taking a device-supplied vector. It is the zero value, so a request with no explicit vector auto-vectors.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressBus ¶
type AddressBus interface {
Read(s Size, address uint32) (uint32, error)
Write(s Size, address uint32, value uint32) error
Reset()
}
AddressBus for accessing address areas
type AddressError ¶
type AddressError uint32
func (AddressError) Error ¶
func (ae AddressError) Error() string
type AddressRange ¶ added in v1.2.0
func (AddressRange) Contains ¶ added in v1.2.0
func (r AddressRange) Contains(address uint32) bool
type AddressRangeDevice ¶ added in v1.1.0
AddressRangeDevice exposes a fixed, inclusive address range [start, end].
type Breakpoint ¶
type BreakpointEvent ¶
type BreakpointEvent struct {
Type BreakpointType
Address uint32
Registers Registers
}
type BreakpointHit ¶
type BreakpointHit struct {
Address uint32
Type BreakpointType
}
func (BreakpointHit) Error ¶
func (bh BreakpointHit) Error() string
type BreakpointType ¶
type BreakpointType int
const ( BreakpointExecute BreakpointType = iota BreakpointRead BreakpointWrite )
func (BreakpointType) String ¶
func (bt BreakpointType) String() string
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus multiplexes memory access between attached devices and performs common checks such as alignment and bus error handling.
func (*Bus) Peek ¶ added in v1.1.0
Peek reads from the mapped device without charging wait states. Devices may use this for debugger-friendly, side-effect-free inspection.
func (*Bus) Read ¶
Read forwards a read to the mapped device after performing alignment and mapping checks.
func (*Bus) SetWaitStates ¶
SetWaitStates sets the base wait-state count charged to the CPU for every bus transaction. A device may add to it by implementing WaitStateDevice.
type BusAccessCallback ¶ added in v1.2.0
type BusAccessCallback func(BusAccessInfo)
type BusAccessInfo ¶ added in v1.2.0
type BusAccessInfo struct {
Address uint32
Size Size
Value uint32
Write bool
InstructionFetch bool
PC uint32
}
BusAccessInfo describes one memory transaction observed by the CPU core.
type CPU ¶
type CPU interface {
// Execution.
Reset() error
Step() error
RunCycles(budget uint64) error
RunInstructions(count uint64) error
RunUntil(options RunUntilOptions) (RunResult, error)
Cycles() uint64
// State inspection.
Registers() Registers
DebugState() DebugState
CurrentExceptionFrame() (ExceptionStackFrame, bool, error)
// External wiring.
RequestInterrupt(level, vector uint8) error
SetIRQSource(IRQSource)
SetScheduler(*CycleScheduler)
Scheduler() *CycleScheduler
SetFastMemory(...FastRegion)
// Observation and debugging.
SetHooks(Hooks)
Hooks() Hooks
SetTracer(TraceCallback)
SetBusTracer(BusAccessCallback)
SetExceptionTracer(ExceptionCallback)
AddBreakpoint(Breakpoint)
SetHistoryLimit(limit int)
History() []HistoryEntry
}
CPU is the interface returned by NewCPU for driving the emulator core.
type ContainsDevice ¶ added in v1.5.0
ContainsDevice decides, per address, whether the device answers for it.
type CycleListener ¶ added in v1.1.0
type CycleScheduler ¶ added in v1.1.0
type CycleScheduler struct {
// contains filtered or unexported fields
}
func NewCycleScheduler ¶ added in v1.2.0
func NewCycleScheduler() *CycleScheduler
func (*CycleScheduler) AddListener ¶ added in v1.2.0
func (s *CycleScheduler) AddListener(listener CycleListener)
func (*CycleScheduler) Advance ¶ added in v1.2.0
func (s *CycleScheduler) Advance(cpuDelta uint64)
func (*CycleScheduler) Now ¶ added in v1.2.0
func (s *CycleScheduler) Now() uint64
func (*CycleScheduler) Reset ¶ added in v1.2.0
func (s *CycleScheduler) Reset(now uint64)
func (*CycleScheduler) Schedule ¶ added in v1.2.0
func (s *CycleScheduler) Schedule(at uint64, fn func(now uint64))
func (*CycleScheduler) ScheduleAfter ¶ added in v1.2.0
func (s *CycleScheduler) ScheduleAfter(delta uint64, fn func(now uint64))
func (*CycleScheduler) SetClockRatio ¶ added in v1.5.0
func (s *CycleScheduler) SetClockRatio(deviceHz, cpuHz uint64)
SetClockRatio makes scheduler time (Now, listener deltas, and event "at" values) run in device cycles rather than CPU cycles: an Advance of n CPU cycles then moves scheduler time by n*deviceHz/cpuHz, carrying the sub-cycle remainder. Passing 0 for either argument, or never calling this, keeps the default 1:1 ratio.
type DebugFaultInfo ¶ added in v1.2.0
type DebugState ¶ added in v1.2.0
type DebugState struct {
Registers Registers
InException bool
InterruptMask uint8
LastFault DebugFaultInfo
LastException ExceptionInfo
HasException bool
LastInterrupt InterruptInfo
HasInterrupt bool
}
type Device ¶
type Device interface {
Read(Size, uint32) (uint32, error)
Write(Size, uint32, uint32) error
Reset()
}
Device represents a memory-mapped peripheral on the address bus. Implementations must be safe for repeated Reset calls.
A device must also be locatable: implement AddressRangeDevice for a single contiguous span, or ContainsDevice for a non-contiguous or state-dependent decode (a device may implement both, in which case Contains decides membership and AddressRange only bounds it).
type DisassemblyLine ¶ added in v1.2.0
DisassemblyLine captures one decoded instruction plus the backing bytes.
func DisassembleInstruction ¶ added in v1.2.0
func DisassembleInstruction(bus AddressBus, address uint32) (DisassemblyLine, error)
DisassembleInstruction decodes one instruction at the given bus address.
func DisassembleMemoryRange ¶ added in v1.2.0
func DisassembleMemoryRange(bus AddressBus, start uint32, length uint32) ([]DisassemblyLine, error)
DisassembleMemoryRange decodes instructions sequentially until the range is covered.
func (DisassemblyLine) String ¶ added in v1.2.0
func (line DisassemblyLine) String() string
String renders a disassembly line with its bytes for human-readable logs.
type ExceptionCallback ¶ added in v1.2.0
type ExceptionCallback func(ExceptionInfo)
type ExceptionInfo ¶ added in v1.2.0
type ExceptionInfo struct {
Vector uint32
PC uint32
NewPC uint32
Opcode uint16
OpcodeAddress uint32
FaultAddress uint32
FaultValid bool
SR uint16
NewSR uint16
StackPointer uint32
Frame ExceptionStackFrame
FrameValid bool
InterruptMask uint8
Group0 bool
}
ExceptionInfo describes one taken exception after vectoring has completed.
type ExceptionStackFrame ¶ added in v1.2.3
type ExceptionStackFrame struct {
Format ExceptionStackFrameFormat
StackPointer uint32
StatusWord uint16
FaultAddress uint32
InstructionRegister uint16
SR uint16
PC uint32
}
ExceptionStackFrame mirrors the exception frame currently stored on the supervisor stack.
func ReadExceptionStackFrame ¶ added in v1.2.3
func ReadExceptionStackFrame(bus AddressBus, sp uint32, format ExceptionStackFrameFormat) (ExceptionStackFrame, error)
ReadExceptionStackFrame decodes a 68000 exception frame directly from memory without requiring the caller to know the byte layout.
type ExceptionStackFrameFormat ¶ added in v1.2.3
type ExceptionStackFrameFormat int
ExceptionStackFrameFormat identifies the 68000 frame layout captured for an exception.
const ( ExceptionStackFrameGroup12 ExceptionStackFrameFormat = iota ExceptionStackFrameGroup0 )
type FastRegion ¶ added in v1.5.0
FastRegion describes one flat, directly-addressable span of guest memory the interpreter may service without going through the bus, for data reads, data writes (unless ReadOnly), and instruction/operand fetches whose whole access falls inside [Base, Base+len(Mem)).
The caller guarantees that, while the region is installed, it behaves as plain memory: accesses have no side effects, the address is not remapped (no MMU banking, no overlay), and Mem is the live backing store (the core reads and, when not ReadOnly, writes it in place). Accesses not fully contained in any region fall through to the bus unchanged, and a write to a ReadOnly region also falls through, so it is safe to map only the sub-range that currently satisfies these guarantees and to re-install the set whenever that changes.
WaitStates is the per-word-transfer penalty the bus would otherwise charge for this region (bus wait states plus the device's fixed contribution). It is added to the cycle counter on every access, doubled for a long access to match the bus running that as two word cycles. Address-dependent penalties (e.g. video bus contention) are not modelled on a fast region; leave such ranges on the bus if they must stay cycle-exact.
Regions are bypassed automatically whenever a breakpoint or bus/instruction tracer is active, so debugging still observes every access.
type HistoryEntry ¶ added in v1.2.3
type HistoryEntry struct {
Kind HistoryKind
Trace TraceInfo
Exception ExceptionInfo
Interrupt InterruptInfo
BusAccess BusAccessInfo
}
HistoryEntry stores one recent debug event in the optional rolling history buffer.
type HistoryKind ¶ added in v1.2.3
type HistoryKind int
const ( HistoryInstruction HistoryKind = iota HistoryException HistoryInterrupt HistoryBusAccess )
type Hooks ¶ added in v1.5.0
type Hooks struct {
Trace TraceCallback
PreTrace PreTraceCallback
Exception ExceptionCallback
Bus BusAccessCallback
Interrupt InterruptCallback
}
Hooks bundles every observation callback the core supports. A nil field means "no callback". SetHooks installs all of them in one call and runs the internal trace/run-mode refresh exactly once, which lets a caller swap a whole tracing configuration atomically instead of touching five setters.
type IRQSource ¶ added in v1.5.0
type IRQSource interface {
// PendingIRQ reports the highest interrupt level currently asserted (0 for
// none) and the vector to take (AutoVector to auto-vector). It is called
// once per instruction, so it must be cheap.
PendingIRQ() (level, vector uint8)
// AckIRQ is called with the level the CPU has just accepted, so the source
// can lower that line. A source with edge/pulse semantics uses this to clear
// the request it just delivered.
AckIRQ(level uint8)
}
IRQSource is a level-sensitive interrupt line the CPU samples at every instruction boundary. It suits a machine whose peripherals hold an interrupt asserted until it is serviced, rather than posting one-shot requests through RequestInterrupt.
type InterruptCallback ¶ added in v1.2.3
type InterruptCallback func(InterruptInfo)
type InterruptInfo ¶ added in v1.2.3
type InterruptInfo struct {
Level uint8
Vector uint32
AutoVector bool
PC uint32
NewPC uint32
SR uint16
NewSR uint16
}
InterruptInfo describes an interrupt that was accepted by the CPU.
type MemoryRange ¶ added in v1.2.0
MemoryRange describes a region of memory to disassemble for debug output.
type Option ¶ added in v1.5.0
type Option func(*cpuConfig)
Option configures CPU construction. Pass options to NewCPU.
func WithDeferredReset ¶ added in v1.5.0
func WithDeferredReset() Option
WithDeferredReset skips the implicit Reset performed by NewCPU. The caller must invoke Reset explicitly once the bus and every device on it are fully wired. Use this when the reset vector is not readable at construction time, for example when the ROM that supplies it is attached to the bus after the CPU is created.
type PeekDevice ¶ added in v1.1.0
PeekDevice exposes a side-effect-free read path for debugging and disassembly.
type PreTraceCallback ¶ added in v1.2.3
type PreTraceCallback func(PreTraceInfo)
type PreTraceInfo ¶ added in v1.2.3
type PreTraceInfo struct {
PC uint32
SR uint16
Registers Registers
Opcode uint16
Bytes []byte
Mnemonic string
Cycles uint64
}
PreTraceInfo reports an instruction just before execution.
type RAM ¶
type RAM struct {
// contains filtered or unexported fields
}
simple flat memory structure
func (*RAM) AddressRange ¶ added in v1.2.0
type Registers ¶
type Registers struct {
D [8]int32
A [8]uint32
PC uint32
SR uint16
SSP uint32
USP uint32
IR uint16 // instruction register
}
Registers represents the programmer visible registers of the 68000 CPU.
type RunPredicateInfo ¶ added in v1.2.3
type RunPredicateInfo struct {
Registers Registers
Instructions uint64
Cycles uint64
LastException ExceptionInfo
HasException bool
LastBusAccess BusAccessInfo
HasBusAccess bool
LastInterrupt InterruptInfo
HasInterrupt bool
}
RunPredicateInfo is passed to StopPredicate after each completed instruction.
type RunResult ¶ added in v1.2.0
type RunResult struct {
Reason RunStopReason
Instructions uint64
Cycles uint64
PC uint32
Exception ExceptionInfo
HasException bool
BusAccess BusAccessInfo
HasBusAccess bool
Interrupt InterruptInfo
HasInterrupt bool
}
RunResult reports why RunUntil stopped and what the CPU observed while stopping.
type RunStopReason ¶ added in v1.2.0
type RunStopReason int
const ( RunStopNone RunStopReason = iota RunStopInstructionLimit RunStopPC RunStopPCInRange RunStopPCOutsideRange RunStopBusAccess RunStopPredicate RunStopException RunStopIllegalOpcode )
func (RunStopReason) String ¶ added in v1.2.0
func (reason RunStopReason) String() string
type RunUntilOptions ¶ added in v1.2.0
type RunUntilOptions struct {
MaxInstructions uint64
StopOnException bool
StopOnIllegal bool
StopAtPC []uint32
StopOnPCRange *AddressRange
StopWhenPCOutside *AddressRange
StopOnBusAccess func(BusAccessInfo) bool
StopPredicate func(RunPredicateInfo) bool
}
RunUntilOptions controls which conditions stop the instruction runner.
type TraceCallback ¶
type TraceCallback func(TraceInfo)
type TraceInfo ¶
type TraceInfo struct {
PC uint32
SR uint16
Registers Registers
BeforeRegisters Registers
Opcode uint16
Bytes []byte
Mnemonic string
CycleDelta uint32
Cycles uint64
}
TraceInfo reports the outcome of a single executed instruction.
type VerboseLogger ¶ added in v1.2.0
type VerboseLogger struct {
// contains filtered or unexported fields
}
VerboseLogger formats trace callbacks with disassembly and optional state dumps.
func NewVerboseLogger ¶ added in v1.2.0
func NewVerboseLogger(cpu CPU, bus AddressBus, writer io.Writer, options VerboseLoggerOptions) *VerboseLogger
NewVerboseLogger builds a trace callback helper that writes detailed execution logs.
func (*VerboseLogger) Trace ¶ added in v1.2.0
func (logger *VerboseLogger) Trace(info TraceInfo)
Trace implements TraceCallback for use with CPU.SetTracer.
type VerboseLoggerOptions ¶ added in v1.2.0
type VerboseLoggerOptions struct {
IncludeRegisters bool
IncludeCycles bool
MemoryRanges []MemoryRange
}
VerboseLoggerOptions controls how much detail a VerboseLogger emits.
type WaitStateDevice ¶
WaitStateDevice optionally advertises additional wait states a device imposes per transaction. Implementations may vary their contribution based on access size and address.