main.c — Entry point and interrupt dispatch
Firmware initialisation and interrupt dispatch.
After boot the firmware has no main loop of its own: it sleeps in
WAIT and every piece of work runs from one of three interrupt sources
(timer, MTS background task, MTS interrupt task). As a safety net the timer
tick also polls the Kernel CCB, so a missed MTS wake-up only costs latency.
-
TICK_MS
Timer period in milliseconds, used as a polling backstop.
-
static void clocks_update(uint32_t hz)
Derive the clock-dependent rates from the core clock.
Sets
core_clock_hz, the GPU timer ticks per millisecond (clock / 256) and the CP0Countticks per millisecond (clock / 2). Neither rate is ever left at zero.- Parameters:
hz – Core clock in Hz; 0 selects 307.2 MHz.
Find the host-shared structures.
Reads
sysinitandosinitat their fixed addresses and takes from them the addresses ofsysdata,osdata, the runtime configuration, the trace control and both CCBs. Also stores the remap word for the fault page (used by the TLB refill handler), sets the clocks from the runtime configuration (or the initial clock) and reports the hardware as healthy.
-
void fw_main(void)
Firmware entry point, called by
boot.Sonce the stack and caches are up.Initialises the shared structures, the trace and statistics, powers the GPU on, initialises the units, the scheduler and the kick state, enables the host interrupt, reports
firmware_startedto the host and unmasks the three interrupt lines (HW0 timer, HW1 MTS background task, HW2 MTS interrupt task). It then handles any KCCB command queued before it was ready and sleeps inWAITforever; all later work runs fromirq_dispatch().Boot-stage words 4, 5 and 6 (and the
0xC0DE000ndebug register) mark its progress.
-
static void mts_task_end(uint32_t v)
Tell the MTS that the current task has finished.
- Parameters:
v – The task type: 0 for the background task, 2 for the interrupt task.
-
void irq_dispatch(uint32_t source)
Handle one interrupt, called by the exception vector in
vectors.S.Timer: re-arms the tick, then (unless powered off) processes the KCCB, polls the scheduler events, runs the HWR watchdog and the scheduler.
MTS background task: processes the KCCB, polls the events and runs the scheduler, then ends the task.
MTS interrupt task: reads and clears the GPU event status, passes the events to
sched_irq()and ends the task.
Each source also updates its debug counters.
- Parameters:
source – 0 timer, 1 MTS background task, 2 MTS interrupt task; anything else counts as spurious.
-
void fatal_exception(void)
Report an unexpected exception, called by
vectors.S.The vector has saved
Cause,EPCandBadVAddrin the boot data page. SetsHWR_FW_FAULTand counts the fault insysdata, writes a trace entry (0xDEAD00xxwith the exception code) and interrupts the host.