boot.S and vectors.S — Assembly

The reset code and the exception page are per GPU: each BVNC has its own boot.S and vectors.S in src/bvnc/<b.v.n.c>/, next to its bvnc.h (which also holds the wired TLB layout they use).

BXE-2-32 (36.29.52.182)

boot.S

Reset / NMI entry (0xBFC00000, KSEG1, microMIPS).

Brings the MIPS core to a state where C code can run from the mapped firmware heap:

  • CP0 setup (exception base, vectored interrupts, uncached KSEG0);

  • TLB cleared, then wired entries for the register bank, the host page table and the stack, with the matching wrapper remap entries;

  • .bss cleared, stack pointer set, jump to fw_main() through ERET.

This is also the warm-boot path: every boot re-initialises everything.

REMAP(entry, va, hi, tmp, regs)

Program a MIPS wrapper address-remap entry.

The order follows docsClean memory-model.md: low word (entry, input address, enable), high word (output address), then a read-back of the high word that flushes the posted writes.

Parameters:
  • entry – Register holding the remap entry index.

  • va – Register holding the input virtual address.

  • hi – Register holding the high (output) word.

  • tmp – Scratch register.

  • regs – Register holding the register-bank address.

PHYS_TO_HI(out, lo32, hi32, tmp)

Build a remap entry’s high word from a 64-bit physical address.

Parameters:
  • out – Destination register.

  • lo32 – Register holding the address’s low 32 bits.

  • hi32 – Register holding the address’s high 32 bits.

  • tmp – Scratch register.

PTE_TO_HI(out, pte, tmp)

Build a remap entry’s high word from a host MIPS page-table entry.

Parameters:
  • out – Destination register.

  • pte – Register holding the PTE.

  • tmp – Scratch register.

MARK(v)

Write a progress marker to the boot-stage word of the boot-data page.

The page is reached through KSEG1, so this works before the TLB is set up. Expects $25 to hold the boot-data address; clobbers $26.

Parameters:
  • v – The marker (0xA0nn during CP0 setup, 0xB007n afterwards).

void _reset(void)

Reset entry point, at 0xBFC00000.

  • Sets Status (CU0, BEV, ERL; interrupts off), makes KSEG0 uncached (the firmware never uses the caches), makes exception handlers microMIPS, selects dedicated interrupt vectors 256 bytes apart and sets EBase to the exception page.

  • Invalidates every TLB entry, then wires the register bank and the XPU broadcast bank (1 MiB identity pages), the four host page-table pages (TLB slots 0 and 1, remap entries 0, 16, 1, 17) and the two stack pages, with their wrapper remap entries.

  • Sets Wired, the next dynamic TLB slot and the stack pointer, then leaves reset mode with ERET to fw_entry().

Progress is written to the boot-stage word and CR_DBG_STAGE.

vectors.S

Exception page (EBase = 0x9FC02000, KSEG0) and C runtime entry.

Offset

Vector

Handler

+0x000

TLB refill

dynamic mapping of the firmware heap

+0x180

general

fatal exception report

+0x400

HW0 timer

irq_dispatch(0)

+0x500

HW1 BG task

irq_dispatch(1)

+0x600

HW2 IRQ task

irq_dispatch(2)

The software interrupts (+0x200, +0x300) and HW3-HW5 also reach irq_dispatch, with source ids 8, 9 and 3-5, which count as spurious.

void _exc_base(void)

Start of the exception page: a branch per vector to the handlers below. Each interrupt vector loads its source id into $26 first.

void refill_main(void)

TLB refill handler: map a page pair of the firmware heap on demand.

Runs with EXL=1; registers it uses are saved in the boot-data page. The TLB is always identity (PFN = VA >> 12); the real 36-bit address goes to the wrapper remap entry of the chosen slot (entry slot for the even page, slot + 16 for the odd one), taken from the host’s MIPS page table. Pages without a valid host PTE, or outside the heap window, are sent to the host fault page and counted. Slots are used round-robin after the wired ones.

void general_main(void)

General exception handler.

Saves Cause, EPC and BadVAddr in the boot-data page and in the debug registers, switches to the stack with EXL cleared (so that TLB refills work in C), calls fatal_exception() and stops. A nested fault stops at once.

void int_common(void)

Common interrupt entry.

Saves the caller-saved registers, HI/LO, EPC and Status on the wired stack, then calls irq_dispatch($26) with EXL=0 and IE=0, so that a TLB miss in C takes the normal refill vector and EPC stays meaningful. Restores everything and returns with ERET.

void tlb_flush_dynamic(void)

void tlb_flush_dynamic(void): drop every dynamic mapping.

Invalidates every non-wired TLB entry (a distinct KSEG0 VPN with EntryLo = 0), disables its two remap entries and resets the next dynamic slot. Lives in the unmapped exception page, so that it never invalidates the page it is executing from. Interrupts are masked while it runs.

void fw_entry(void)

C runtime entry, reached from _reset through ERET.

Clears .bss, sets the stack pointer and calls fw_main(), which never returns.

BXM-4-64 (36.56.104.183)

Same entry-point names as the BXE-2-32 files, documented under the bxm C namespace.

boot.S

Reset entry of the BXM-4-64 (0xBFC00000, KSEG1, microMIPS).

docsClean/BXM-4-64 execution-environment.md sections 2.2-2.4:

  • CP0 setup with the spec’s values (Status = 0x1C00, Compare never, cacheable KSEG0 K0 = 3, exception base, vectored interrupts 256 bytes apart);

  • index initialisation of the 2 KiB I-cache and D-cache;

  • every remap entry and TLB entry cleared, then the wired entries: the register and broadcast banks (one 4 MiB page pair), the four host page-table pages and the stack, with their wrapper remap entries;

  • D-cache invalidated, stack pointer set, jump to fw_entry().

This is also the warm-boot path: every boot re-initialises everything. An NMI enters at the same vector with Status.NMI set: it writes the state dump for the host (mips_state_dump()) and returns to the interrupted code (section 2.1).

Caches: only KSEG0 is cacheable (the exception code at 0x9FC02000). The firmware reaches the boot-data page through its KSEG1 alias and maps the heap uncached (vectors.S), so the C code needs no D-cache maintenance; write_barrier() already drains the wrapper through 0xBFC01800 (section 5).

Boot-data offset of pt_log2_page_size (memory-model.md section 2.3).

Boot-data offset of pt_num_pages.

I-cache and D-cache size (execution-environment.md section 1).

Cache line size.

cache operation: Index Store Tag, I-cache.

cache operation: Index Store Tag, D-cache.

cache operation: Index Writeback Invalidate, D-cache.

EntryLo flags of the register banks: XI, uncached, D, V, G (section 2.3).

EntryLo flags of the other wired pages: uncached, D, V, G.

PageMask of a 4 MiB page (mask field [28:13] = 0x3FF).

REMAP(entry, va, hi, tmp, regs)

Program a MIPS wrapper address-remap entry.

Low word (entry, input address, enable), high word (output address phys >> 8), then a read-back of the high word that flushes the posted writes (memory-model.md section 4.5).

Parameters:
  • entry – Register holding the remap entry index.

  • va – Register holding the input virtual address.

  • hi – Register holding the high (output) word.

  • tmp – Scratch register.

  • regs – Register holding the register-bank address.

PHYS_TO_HI(out, lo32, hi32, tmp)

Build a remap entry’s high word from a 64-bit physical address.

Parameters:
  • out – Destination register.

  • lo32 – Register holding the address’s low 32 bits.

  • hi32 – Register holding the address’s high 32 bits.

  • tmp – Scratch register.

PTE_TO_HI(out, pte, tmp)

Build a remap entry’s high word from a host MIPS page-table entry.

Parameters:
  • out – Destination register.

  • pte – Register holding the PTE.

  • tmp – Scratch register.

MARK(v)

Write a progress marker to the boot-stage word of the boot-data page.

The page is reached through KSEG1, so this works before the TLB is set up. Expects $25 to hold the boot-data address; clobbers $26.

Parameters:
  • v – The marker (0xA0nn during CP0 setup, 0xB007n afterwards).

CACHE_ALL(op)

Apply a cache index operation to every line of a 2 KiB cache.

Uses the KSEG0 index addresses 0x80000000-0x800007F0 (memory-model.md section 2.1). Clobbers $8 and $9.

Parameters:
  • op – The cache operation.

void _reset(void)

Reset entry point, at 0xBFC00000.

  • CP0 in the order of execution-environment.md section 2.2: Status = 0x1C00 (IE, EXL, ERL and BEV clear, IM2-IM4 set), Cause = 0, Count = 0, Compare = 0xFFFFFFFF, Config.K0 = 3, EBase, Cause.IV, IntCtl.VS = 8, TagLo = 0; Config3.ISAOnExc makes the exception handlers microMIPS.

  • Index Store Tag over the I-cache and the D-cache (TagLo = 0: every line invalid).

  • Checks the host’s page-table geometry (4 KiB pages, four of them; the only one this file maps) and halts otherwise.

  • Clears the 32 remap entries and the 16 TLB entries, then wires the banks, the page table (TLB entries 1 and 2, remap entries 1, 17, 2, 18) and the two stack pages (TLB entry 3, remap entries 3 and 19).

  • Sets Wired and the next dynamic TLB slot, invalidates the D-cache, sets the stack pointer and jumps to fw_entry().

Progress is written to the boot-stage word and CR_DBG_STAGE.

void mips_state_dump(void)

void mips_state_dump(void): write struct rogue_mips_state for the host (execution-environment.md section 4.4, pvr_rogue_mips.h).

In the NMI shared area of the boot-data page (BD_NMI_STATE, through KSEG1): error_state = ROGUE_MIPSFW_NMI_ERROR_STATE_SET, ErrorEPC, Status, Cause, BadVAddr, EPC, $sp; debug, depc, bad_instr and unmapped_address are written 0 (the EJTAG and BadInstr registers are not guaranteed outside debug mode). Then the 16 TLB entries (tlbr: PageMask, EntryHi, EntryLo0/1) and the 32 remap entries (REMAP_RANGE_READ / _DATA: input page, output page (low 32 bits), region-size encoding). The TLB registers it uses are restored. Ends with the wrapper drain and a CR[0x0020] read.

Clobbers $1, $8-$15, $24; returns with jr $31. Needs wired TLB entry 0 (the register bank).

vectors.S

Exception page of the BXM-4-64 (EBase = 0x9FC02000, KSEG0, cached with K0 = 3) and C runtime entry: docsClean/BXM-4-64 execution-environment.md section 4.

Offset

Vector

Handler

+0x000

TLB refill

dynamic mapping of the firmware heap

+0x180

general

fatal exception report

+0x400

HW0 timer

irq_dispatch(0)

+0x500

HW1 BG task

irq_dispatch(1)

+0x600

HW2 IRQ task

irq_dispatch(2)

The software interrupts (+0x200, +0x300) and HW3-HW5 also reach irq_dispatch, with source ids 8, 9 and 3-5, which count as spurious.

Differences from the specification, both firmware-internal: the refill handler maps every heap page uncached (C = 2, whatever C the host PTE carries; memory-model.md section 2.2 allows write-through everywhere, uncached is stricter still), so no D-cache maintenance is needed in C; and invalid PTEs go to the host fault page instead of taking a TLB Invalid exception, so the general exception handler only reports fatal exceptions (section 4.2 handles ExcCode 1-3 by remapping the page); it publishes the state dump (mips_state_dump, section 4.4) before stopping.

void _exc_base(void)

Start of the exception page: a branch per vector to the handlers below. Each interrupt vector loads its source id into $26 first.

void refill_main(void)

TLB refill handler: map a page pair of the firmware heap on demand.

Runs with EXL=1; registers it uses are saved in the boot-data page. The TLB is always identity (PFN = VA >> 12); the real 36-bit address goes to the wrapper remap entry of the chosen slot (entry slot for the even page, slot + 16 for the odd one), taken from the host’s MIPS page table. Pages without a valid host PTE, or outside the heap window, are sent to the host fault page and counted. Slots are used round-robin after the wired ones.

void general_main(void)

General exception handler.

Saves Cause, EPC and BadVAddr in the boot-data page and in the debug registers, switches to the stack with EXL cleared (so that TLB refills work in C), calls fatal_exception() and stops. A nested fault stops at once.

void int_common(void)

Common interrupt entry.

Saves the caller-saved registers, HI/LO, EPC and Status on the wired stack, then calls irq_dispatch($26) with EXL=0 and IE=0, so that a TLB miss in C takes the normal refill vector and EPC stays meaningful. Restores everything and returns with ERET.

void tlb_flush_dynamic(void)

void tlb_flush_dynamic(void): drop every dynamic mapping.

Invalidates every non-wired TLB entry (a distinct KSEG0 VPN with EntryLo = 0), disables its two remap entries and resets the next dynamic slot. Lives in the unmapped exception page, so that it never invalidates the page it is executing from. Interrupts are masked while it runs.

void fw_entry(void)

C runtime entry, reached from _reset through ERET.

Clears .bss, sets the stack pointer and calls fw_main(), which never returns.