# The PIF, the CIC and the boot Sources: n64brew: PIF-NUS, CIC-NUS, Initial Program Load, ROM Header (CC BY-SA 4.0, facts only, tier 3; the PIF and CIC pages rest on decapped firmware dumps and logic-analyser captures: DIE-derived and MEASURED by their authors, not by us). **The firmware rule.** The PIF's boot ROM (IPL1 + IPL2, 1984 bytes), the PIF's own SM5 firmware, the CIC's SM5 firmware and Nintendo's IPL3s (in 1,093+ cartridge headers) are Nintendo's. None is committed, copied, disassembled or read here. The wiki's pages include an IPL1 disassembly listing (with a copyright warning) and the firmware projects (GenericHeroGuy/pif-sm5-rom, UltraCIC_C, UltraPIF_MCU, PifChecksum) are transcriptions of Nintendo code: **those parts and projects are excluded** (sources-n64.md). ## What the board must do at power-on The real sequence (PIF-NUS > Console startup; Initial Program Load): 1. The VR4300 starts at 0xBFC00000 (the PIF ROM). The CIC sends the PIF its region nibble, two seeds (identical in every known CIC) and a 6-byte checksum, scrambled. 2. IPL1 (in the PIF ROM) does basic RCP init (it stops the RSP, clears PI, VI and AI state) and copies IPL2 into IMEM; IPL2 reads the boot information the PIF wrote at PIF RAM 0x24-0x27, sets PI domain 1 from the header, loads IPL3 (ROM 0x40-0xFFF) into DMEM, has the PIF compare its checksum (PIF command 0x20/0x40: a mismatch halts the CPU), and jumps to DMEM. 3. IPL3 (the cartridge's) initialises RDRAM, copies 1 MiB from ROM 0x1000 to the header's entry point (adjusted by -0x100000 for 6103, -0x200000 for 6106; 7102's is fixed), checks the header's 64-bit check code, resets the RSP, clears interrupts, wipes DMEM/IMEM, and jumps. 4. The game must send PIF command 0x08 ("terminate boot") within about 5 s or the PIF freezes the console. Two ways the board can do this, without Nintendo code in the repository: - **A: a player-supplied PIF ROM**, read in place by path (`N64_PIF_ROM`, like pcengine-python's `PCE_SYSCARD`), run on the VR4300 core; IPL3 from the cartridge. Every cycle as the hardware, but needs the PIF's checksum and CIC behaviour modelled from the wiki's description (the seeds and checksums are tabulated per CIC on PIF-NUS: facts). - **B: a functional boot (HLE)**: the board performs IPL1-IPL2's observable effects directly (register and RCP state, IPL3 copied to DMEM, PC = 0xA4000040) and then runs the cartridge's IPL3 on the core; or, further, performs IPL3's effects too (RDRAM sized, 1 MiB copied, the registers IPL3 leaves, then PC = entry). Charter axis B: a functional model of firmware, judged against a run of the real firmware (A) where a player has it. - With a homebrew ROM built on libdragon, IPL3 is libdragon's open IPL3 (Unlicense): A with that IPL3, or B for IPL1-2 only, involves no Nintendo code at all. nemu64-test boots this way. What IPL3 leaves for the game (registers s3-s7, sp, and the boot variables at 0x80000300: osTvType, osRomType, osResetType, osCicId, osVersion, osMemSize) is only partly on the pinned pages (osMemSize at 0x80000318, or 0x800003F0 for 6105). MAME's trace at the entry point shows `s4` = 1 (TV type), `s6` = 0x3F (the seed), `sp` = 0xA4001FF0 (vr4300-python mame-oracle.md; tier 5 OBSERVED). The full list for option B is U9. ## PIF RAM and the joybus frame (PIF-NUS > RAM-based communication protocol) - 64 bytes at 0x1FC007C0; byte 0x3F is the command byte (a bitmask the PIF clears when done): boot mode 0x08 terminate boot, 0x10 ROM lockout, 0x20 acquire checksum, 0x40 run checksum; run mode 0x01 configure joybus frame, 0x02 the CIC-6105 challenge (15 bytes at 0x30), bits 0x04/0x08 joybus timing flags. - The frame is **parsed** when 0x01 is seen (by DMA or a direct write) and **executed only on an SI RD64B**, channels in reverse order 4 down to 0, replies written in place; channels 0-3 are the controller ports, 4 is the cartridge (EEPROM, RTC). - Per channel: TX length, RX length, TX bytes, RX bytes; escape bytes 0x00 skip channel, 0xFD reset pulse, 0xFE end of frame, 0xFF padding; at execute time RX gets 0x80 (no device) or 0x40 (timeout) in its top bits. ## The CIC A Sharp SM5 on every cartridge. After boot it runs a loop of 2-bit commands from the PIF; only 6105/7105 implement the real challenge/response, the others return the bit-inverted challenge (CIC-NUS). The CIC needs no firmware in an emulator: its observable behaviour is the seed, the checksum value and (6105) the challenge algorithm, all described as facts on the wiki; the challenge's algorithm itself is known only through UltraCIC_C (a transcription of Nintendo firmware: excluded). **U10: how to answer the 6105 challenge without that transcription** (Zelda OoT/MM, Banjo-Tooie, Perfect Dark use 6105: 56 images in the census). Candidates: a clean-room description from the wiki's prose if it is complete enough; else the player-supplied PIF/CIC path; else a concession. ## CIC identification for the census The census (census.md) groups IPL3s by CRC-32 and names each group by an anchor title from the CIC-NUS table. This is identification, not emulation; the board needs the seed (from the CIC type) only for options A and B above. ## Reset The reset button: the PIF raises pre-NMI (INT2 on the VR4300), about 500 ms later NMI; **the RCP is not reset**, so software must quiesce it (PIF-NUS > Console Reset). The PIF must be told 0x08 again after every soft reset.