7.5 FaultDispatcher

<< Click to Display Table of Contents >>

Navigation:  ASA-EMulatR Reference Guide > Introduction > Architecture Overview > Chapter 7 - Exceptions, Faults, and Interrupts >

7.5 FaultDispatcher

7.5.1 Role

 

The FaultDispatcher is the central authority for managing exceptional events. There is one FaultDispatcher per CPU, accessed via globalFaultDispatcher(cpuId). It decouples detection from delivery: faults are queued when detected and delivered when the pipeline reaches a safe state.

 

Responsibilities: queue faults and traps, track pending interrupts, enforce priority ordering, control delivery timing, and prevent imprecise state exposure.

 


 

7.5.2 Event Queueing

 

When a fault is detected, the detector creates a PendingEvent and passes it to FaultDispatcher::setPendingEvent(). The event is classified by kind, exception class, priority, and associated data (faultVA, faultPC, trapCode, etc.). Instruction execution halts and pipeline advancement is constrained until the event is delivered.

 


 

7.5.3 Fast-Path Query Interface

 

The FaultDispatcher's eventPending() method is the hottest path in the emulator — it is called every cycle by the run loop. The implementation uses a simple bitfield check with no atomics (per-CPU only):

 

bool eventPending() const noexcept {

 return m_pendingFlags != 0; // ~1 cycle, no atomic

}

 

The pending flags are a bitmask tracking event categories:

 

FLAG_NONE = 0x00

FLAG_EXCEPTION = 0x01 // Generic exception

FLAG_ARITHMETIC_TRAP = 0x02 // Arithmetic trap (for TRAPB)

FLAG_DTB_MISS = 0x04 // Data TLB miss

FLAG_ITB_MISS = 0x08 // Instruction TLB miss

FLAG_INTERRUPT = 0x10 // Interrupt pending

FLAG_MACHINE_CHECK = 0x20 // Machine check (highest priority)

 

Specialized query methods test individual flags: hasPendingArithmeticTraps() (for TRAPB release), hasPendingTLBFaults() (DTB/ITB), hasPendingInterrupt(), hasPendingMachineCheck().

 


 

7.5.4 Event Clearing

 

clearPendingEvents() resets both the PendingEvent structure and the flag bitmask to zero. clearArithmeticTrap() clears only the arithmetic trap flag and, if the pending event is an Arithmetic class, clears the event as well. This allows TRAPB to selectively clear arithmetic traps while leaving other events pending.

 

Implementation: FaultDispatcher.h, 449 lines.

 

See Also: faultLib/FaultDispatcher.h; faultLib/PendingEvent_Refined.h.