Imagination_BXM-4-64

Execution Environment — Firmware MIPS Core

The PowerVR BXM-4-64 (36.56.104.183) GPU firmware executes on an embedded MIPS32 Release 2 core supporting compact microMIPS encoding, operating in little-endian mode, single-threaded, inside the GPU’s MIPS_WRAPPER subsystem.


1. MIPS Core Characteristics ([P][O])

Property Value Source
ISA Architecture MIPS32 Release 2 + microMIPS (little-endian) [P]
Hardware Threads 1 (ROGUE_FW_THREAD_MAX = 1 for MIPS) [P]
Instruction Cache (L1 I$) 2 KiB, 16-byte lines (128 lines) [P][D]
Data Cache (L1 D$) 2 KiB, 16-byte lines (128 lines), Write-Through policy [P][D]
TLB 16 paired entries (32 mappable pages; ROGUE_MIPSFW_NUMBER_OF_TLB_ENTRIES = 16) [P]
Fixed Entries (Wired) Wired = 4 (K3 vendor: 0 = CR/BCAST 4 MiB, 1 = PT 16 KiB, 2 = stack, 3 = private data) or Wired = 5 (mainline, pt_num_pages = 4). Entries Wired..15 are dynamic (TLB Refill). Details in memory-model.md §2.2 [O]
Stack Budget 4 KiB (ROGUE_MIPSFW_STACK_SIZE = 0x1000, 1 page); top 0xCF600FF8 [P]
$gp Base of firmware private data (MIPS_PRIVATE_DATA, $gp-relative access, ±32 KiB window) [P][O]
EBase 0x9FC02000 (ROGUE_MIPSFW_EXCEPTIONS_VIRTUAL_BASE); Cause.IV = 1 [P][O]
Config.K0 3 = cacheable (write-back) for kseg0 — MIPS32 encoding is 2 = uncached, 3 = cacheable (also confirmed by consistency with the firmware’s own cache maintenance, which invalidates/primes the I$ for the exception code at 0x9FC02xxx) [P][O]
Exception Vectors EBase+0x000 TLB Refill, EBase+0x180 general exception, EBase+0x200 interrupt (IV=1) [P][O]

2. Reset, Boot, and NMI Sequence ([P][O])

The host configures REMAP1/2/3 and MIPS_WRAPPER_CONFIG (REGBANK_ADDR_ALIGN = 16, BOOT_ISA_MODE = microMIPS) before releasing reset. The core PC starts at 0xBFC00000 (kseg1 → physical 0x1FC00000, redirected by REMAP1 to the boot buffer).

2.1 Reset Vector (0xBFC00000)

Per the MIPS32r2 architecture, the reset vector (0xBFC00000) distinguishes cold initialization from NMI via the CP0.Status.NMI (bit 19) bit (temporarily preserving a scratch register in CP0.DESAVE for the eret return case):

2.2 CP0 Initialization (Exact Values)

Executed before any access to kseg2; all values below were observed in the boot vector:

Order Register Value Effect
1 Status 0x00001C00 IE=0, EXL=0, ERL=0, BEV=0; IM2/IM3/IM4 enabled
2 Cause 0 clears pending flags
3 Count 0  
4 Compare 0xFFFFFFFF timer “never” fires before being armed
5 Config (Config & ~7) \| 3 K0 = 3 → kseg0 cacheable (write-back); kseg1 remains uncached
6 EBase 0x9FC02000 exception vector base ([31:12])
7 Cause (Cause \| 0x00800000) IV = 1 → interrupt vector at EBase+0x200
8 IntCtl (IntCtl & ~0x3E0) \| 0x100 VS = 8 (bits [9:5] = vector spacing: 256 B per IP line); not IPTI (which is in [31:29])
9 TagLo 0  
10 — — index-based cache maintenance: cache 8 + cache 9 over all 128 lines (0x80000000–0x800007FF) and boot code prime
11 PageMask + Index/EntryHi/EntryLo0/1 see §2.3 wired entries loading
12 Wired 4 (K3 vendor) / 5 (mainline, pt_num_pages = 4) see §2.3
13 Status Status & ~1 … \| (Status & 1) IE disabled during TLB load and restored at the end
14 — — invalidates D$ (2 KiB)

Context is not used: the firmware does not use “Context”-mode page walking; the table index is derived from EntryHi (§4 of memory-model.md).

2.3 Loading Wired Entries (Exact Order)

  1. PageMask = 0x1800 (4 KiB), followed by 0x7FF800 (4 MiB).
  2. Index 0 ← 0xCF800000, EntryHi = 0xCF800000, EntryLo0/1 derived from 0xCF800000/0xCFC00000, flags 0x40000017 (XI, C=2 uncached, D|V|G), 4 MiB page → covers 0xCF800000–0xCFFFFFFF (CR and BCAST).
  3. Reads MIPS_BOOT_DATA (0x9FC01000 window) and validates pt_log2_page_size (12..18) and pt_num_pages (< 5). Outside this range → break (fatal trap).
  4. PageMask = ((page_KiB << 11) - 1) & ~0x7FF (with page = 1 << pt_log2_page_size); Index 1 ← 0xCF000000, flags 0x1F (C=3 write-back, D|V|G), phys = pt_phys_addr[0] / pt_phys_addr[1] (page pair).
  5. If pt_num_pages = 2 (K3 vendor): Index 2 ← stack 0xCF600000, phys = stack_phys_addr; Index 3 ← first page of MIPS_PRIVATE_DATA (.bss+.data); Wired = 4. If pt_num_pages = 4 (mainline): Index 2 ← 0xCF000000 + 2 × page (second half of PT, phys = pt_phys_addr[1]); Index 3 ← stack; Index 4 ← private data; Wired = 5.
  6. Entries Wired..15 are invalidated (synthetic EntryHi/EntryLo, tlbwi) and remap entries 0..31 are cleared.

Each tlbwi is accompanied by programming the corresponding range-remap entry (16 + index for wired entries), as described in memory-model.md §4.5.

2.4 Handoff to Main Code

Upon returning from initialization: $sp = 0xCF600FF8 (top of stack − 8), $gp = base of MIPS_PRIVATE_DATA, $a0..$a3 = 0, sync, and jump to the firmware code entry point (MIPS_CODE). The initial sequence at that entry point is:

  1. locates the pointer to the struct rogue_fwif_sysinit block (mainline 1.1 ABI, sizeof = 0x220, see data-structures.md);
  2. CR[0x0890] = 1 (broadcast core selection);
  3. reads CR[0x0890] back (confirming the write landed);
  4. optionally configures PerfCtl0/PerfCnt0/PerfCtl1/PerfCnt1 according to sysinit.hw_perf_filter (+0x30);
  5. CR[0x08A0] = 1 (MIPS_WRAPPER_IRQ_ENABLE) — enables the wrapper interrupt line;
  6. runs main firmware initialization (publishing firmware_started = 1 with visibility barrier), enables Status.IE, and enters the idle loop (wait).

ABI Scope (sysinit): an implementation compatible with the Linux mainline 1.1 driver must use only the fields defined in struct rogue_fwif_sysinit (sizeof = 0x220, data-structures.md). Additional fields present in the larger DDK 24.2 block fall outside the mainline structure.


3. Interrupt Model and Execution Contexts ([P][D])

The firmware operates under an event-driven model controlled by the MTS (Meta/MIPS Task Scheduler) and the internal CP0 timer. The hardware interrupt lines in CP0.Cause / CP0.Status map directly to three logical contexts:

CP0 Line Cause.IP Mask Hardware Source Role in Firmware
HW0 (IP2) Bit 10 Timer (CP0.Count/Compare) Vector EBase+0x400: saves sp/Status/EPC, executes the timer ISR, and rewrites Compare (ack). Basis for the HWR deadline and APM latency timer (active_pm_latency_ms)
HW1 (IP3) Bit 11 MTS Background Task (BG) Vector EBase+0x500: same frame, calls the BG task (KCCB, cCCB scheduling, UFOs/fences, MemCtx, DM2/DM3/DM4 kicks). Runs with ei in the call’s delay slot, allowing IP4 to preempt it
HW2 (IP4) Bit 12 MTS Interrupt Task (IRQ) Vector EBase+0x600: saves the full context (all GPRs + Status/EPC) and calls the IRQ task (EVENT_STATUS: TA/3D/CDM completion, PM OOM, MMU fault, CSW store, HWR, APM/Idle)

Correction (2026-11-28): the IP ↔ task mapping was inverted in earlier versions (IP2 = BG was incorrect). The actual order, confirmed in the vector code, is IP2 = timer, IP3 = BG, IP4 = IRQ. The Status saved by the BG vector masks IM2|IM3 (bits 10–11), leaving only IM4 enabled, which confirms BG preemption by IRQ.

Priority Discipline and Internal Preemption ([D])


4. Exception Handling and TLB Refill ([P][O])

EBase = 0x9FC02000 with Cause.IV = 1:

Offset Vector Contents on K3
+0x000 TLB Refill Missing-page resolution (§4.1)
+0x180 General Exception Dispatch by Cause.ExcCode (§4.2)
+0x200 vector 0 (software interrupt) Not used by the firmware
+0x400 vector 2 = IP2 (timer) Frame + timer ISR call + Compare ack (§4.3)
+0x500 vector 3 = IP3 (BG) Frame + BG task call, with ei/di (§4.3)
+0x600 vector 4 = IP4 (IRQ) Full context save + IRQ task call (§4.3)

The +0x000, +0x180, and +0x200..+0x600 vectors all reside in the MIPS_EXCEPTIONS_CODE section (EBase = 0x9FC02000, maximum budget 8 KiB).

4.1 TLB Refill Vector (EBase+0x000)

The FW Heap (16 MiB) exceeds the 16 TLB entries, so every page outside the wired entries triggers a refill. Functional sequence:

  1. Saves the required scratch registers and executes sync.
  2. VPN2 = EntryHi[31:13]; Index = Random (free entry between Wired..15).
  3. Programs the range-remap entry at index Random & 0x1F with the missing virtual page (BASE_ADDR_IN = EntryHi[31:12]) and MODE_ENABLE = 1.
  4. Reads the PTE pair from the page table window: PTE0 = *(u32 *)(0xCF000000 + (EntryHi >> 10 & 0x3FFFF)), PTE1 = PTE0 + 4; writes ADDR_OUT = PTE[29:6] << 12 (actual physical address) to the remap entry.
  5. Builds EntryLo0 = (PTE0 & 0xC000003F) | ((EntryHi >> 12) << 6) and EntryLo1 with PFN+1 (see memory-model.md §4.4). The PFN comes from the VPN, not from the PTE.
  6. Index = Random, PageMask = 0x1800, tlbwi, ehb, and eret.

There is no “unmapped page” path in this vector: if PTE = 0, the resulting EntryLo has V = 0 and the faulting instruction triggers a new exception (now TLB Invalid, ExcCode = 2/3), handled by the general exception vector.

4.2 General Exception Vector (EBase+0x180)

  1. Reads Cause and extracts ExcCode = Cause[6:2].
  2. ExcCode ∈ {1, 2, 3} (TLB Modified / TLB Load / TLB Store — entry present but V/D insufficient):
    • scans Index = Wired .. 15 with tlbr until EntryHi[31:13] == BadVAddr[31:13];
    • if ExcCode = 1 (TLB Modified), tests D; if ExcCode = 2/3 (TLB Invalid), tests V; if the bit is missing, rewrites EntryLo0/1 = (EntryHi >> 6) | 0x3F (PFN from VPN, C = 7, D|V|G) and executes tlbwi;
    • re-arms the MMU_PAGE_FAULT event in software (CR[0x0130] |= 0x200 — EVENT_STATUS accepts software set, even though the header describes it as RO/W1C);
    • restores Status and returns via eret, re-executing the instruction.
  3. Any other ExcCode (Address Error, Reserved Instruction, Trap, Machine Check, …) → publishes the state dump (struct rogue_mips_state, §4.4) and enters a permanent halt: di; wait; in an infinite loop. There is no software recovery; the host detects the halt via timeout/MIPS_WRAPPER_STATUS.
  4. If Index reaches 15 without matching the VPN → also permanent halt (di; wait;).

4.3 Interrupt Vectors (Vectored, EBase+0x200+n*0x100)

Boot writes Cause.IV = 1 and IntCtl with VS = 8 (IntCtl = (IntCtl & ~0x3E0) | 0x100), enabling vectored interrupts. The resulting architectural layout is EBase + 0x200 + (n << 8), i.e., 256 bytes (0x100) per IP line — with three distinct vectors:

Vector Address Behavior
IP2 (timer) EBase+0x400 Saves sp/Status/EPC on the stack (8-byte aligned), clears IE\|EXL, runs the timer ISR, rewrites Compare (ack), restores Status/EPC, and returns via eret
IP3 (BG) EBase+0x500 Saves Status & ~0xC03 (masks IM2\|IM3, leaving IM4 active), calls the BG task (KCCB/CCCB) with ei enabled (and di on return) to allow preemption by IP4; restores and returns via eret
IP4 (IRQ) EBase+0x600 Saves all GPRs + sp/gp/Status/EPC, calls the IRQ task (EVENT_STATUS/HWR/CSW), and restores full context before eret

Implementation consequences:

4.4 State Dump for the Host

The dump (executed in the NMI path and the general exception vector) writes EntryHi/EntryLo0/EntryLo1/Index/PageMask and all 16 TLB entries (tlbr) into shared boot RAM, as well as publishing the state of all 32 remap entries — the layout consumed by the driver is in data-structures.md (struct rogue_mips_state). After the dump, the code performs a D-cache flush, drains the wrapper (0xBFC01800 = 1, ehb, sync), and performs a confirming CR read (0xCF800020) before returning.


5. Cache Maintenance and Visibility Barriers ([P][D])

The MIPS core uses a 2 KiB Write-Through D-cache with 16-byte lines, but there are write buffers in the MIPS wrapper and explicit coherency is required between the MIPS core, the GPU (BIF/SLC), and the host (RISC-V CPU):

Mandatory Operations

Operation Mechanism on K3 When to Use
Full D-cache Flush/Invalidate cache loop from 0x80000000 to 0x800007F0, stride 0x10 (16 B) (128 lines = 2 KiB) Before final shutdown (POW_OFF), during HWR reset sequence, and before global MMU/TLB invalidations
Range D-cache Flush/Invalidate cache Hit_Writeback_Invalidate_D loop aligned to 16 B over [addr, addr + len) After updating sysinit (firmware_started), FWCCB headers, UFOs, or structures read by the host
MIPS Wrapper Write Barrier (Fence Flush) Write 1 to uncached register 0xBFC01800 + ehb + sync Mandatory after D-cache flush to drain the MIPS wrapper write buffer to DRAM before signaling the host (boot handshake, KCCB MMU inval, HWR, power-off)
CR Register Synchronization Dummy read of a safe register (e.g., ROGUE_CR_CORE_ID__PBVNC at 0x0020) after an MMIO write sequence Guarantees previous CR writes have reached their destination before exposing status to the host
Dynamic TLB Invalidation Sweep entries Wired .. 15 invalidating EntryHi/EntryLo via tlbwi Upon receiving KCCB_CMD_MMUCACHE (MMU/FW cache invalidation)

Critical K3 note: Writing sysinit.firmware_started = 1 without first executing the D-cache flush, the write to 0xBFC01800 = 1, ehb + sync, and a confirming CR read can cause the RISC-V host to observe firmware_started = 0 until the boot timeout expires (or read partial sysinit data).


6. Stack Budget and Code Constraints ([P][D])