N64 CPU

From en64 wiki
Jump to: navigation, search

Just putting shit here rn: In addition to the CPU core, the R4300i microprocessor includes a Control Processor (CP), which contains a Translation Lookaside Buffer and a Memory Management Unit (COP0). The CP works as a coprocessor. It's important to note, and somehow should be "bred into" the sea of information that will soon be here: The o32 ABI that all Nintendo 64 games use is for the R3000 processor! The CPU's MMU greatly reduces the speed at which a game runs when virtual mapping a lot of addresses. Thus, a lot of games directly use physical memory. The R4300i processor handles a slower memory bus better due to having more registers and less addressing modes. Another benefit is not having status/flag registers after ever instruction.

MIPS Language

Main article: MIPS

Opcodes

Main article: Opcodes

Todo: Short Description Here.

Registers

Main article: Registers

Todo: Short Description Here. MIPS has four sets of co-processor registers, each have 32 registers, and the General Purpose Registers (GPR) are not apart of the set.

  • Co-processor 0 (MMU) Memory management and exception processing
  • Co-processor 1 (FPU) Floating-point unit for IEEE 754 single-precision FP numbers (Does it's own exception handling)
  • Co-processor 2 (RCP) R4300i processor but with vector extensions (has it's own co-processors)
  • Co-processor 3 (FPU) 64-bit Floating-point unit for double-precision FP numbers

The Stack

Main article: The Stack

Subroutine
Calling Convention

Todo: Short Description Here.


Co-processor 0

The VR4300 processor provides a full-featured memory management unit (MMU) which uses an on-chip translation lookaside buffer (TLB) to translate virtual addresses into physical addresses.

Memory Management Unit (MMU)

Translation Lookaside Buffer (TLB)

Main Page!

CPU Addressing

CPUaddress32.png
The main R4300i processor has a huge role in deciding where memory is placed and how it is placed through the Control Processor (CP) which acts as a coprocessor. The CP is composed of the Translation Lookaside Buffer (TLB) and a Memory Management Unit (COP0). The Nintendo 64 is a single user system, meaning it normally just runs in one kernel mode. All addresses related to the CPU are NOT physical addresses, they're always virtual addresses. The kernel can be either in 32 or 64-bit addressing mode, but usually for performance reasons it's 32-bit. The manner in which memory addresses are translated or mapped depends on the operating mode of the CPU. The following is a table for virtual address translation in 32-bit kernel addressing mode (mapped meaning mapped through the MMU):
Address Range ID Comments
0x80000000 - 0x7FFFFFFF KUSEG, USEG, SUSEG TLB map (User Mode) Accessible in all modes
0x80000000 - 0x9FFFFFFF KSEG0 Direct map (Cached Memory) Accessible in kernel mode, not mapped
0xA0000000 - 0xBFFFFFFF KSEG1 Direct map (Non-cached Memory) Accessible in kernel mode, not mapped
0xC0000000 - 0xDFFFFFFF KSSEG, SSEG TLB mapping (Supervisor Mode) Accessible in kernel or supervisor mode
0xE0000000 - 0xFFFFFFFF KSEG3 TLB mapping (Kernel Mode) Accessible in kernel mode

Operating Modes

The only difference between KUSEG, KSSEG, and KSEG3 is the virtual address space. KUSEG is the "user" address space accessible from kernel mode (this is the same address space accessible from user mode). KSSEG is the "supervisor" address space (same address space as accessible in supervisor mode), and KSEG3 is one of the three address spaces accessible only from kernel mode (and the only segment of the three that is mappable via TLB).

  • User Mode: In the single-user mode, a virtual address space of 2 GB can be used in the 32-bit mode. (Will explain more.)
  • Supervisor Mode: Will explain.
  • Kernel Mode: Will explain.

Cached and Non-cached Memory

In the logical memory hierarchy, the caches lie between the CPU and main memory. They are designed to make the speedup of memory accesses transparent to the user. In attempt to create a proper frame of mind around cached and non-cached memory: Even if a game is allocated to the uncached memory of kernel mode KSEG1, data is still present in it's cached counterpart KSEG0. By that I mean, they point to the same physical address; all writes between locations are accessible by each other. You obtain performance gains by using non-cached memory, but only in tight loops (a loop that iterates many times/plays an important role in the games performance). Like not having to flush the CPU cache when running a lot of cycles in a short time. The only time you care about cache is when writing self-modifying code, or when doing silly interleaved access between each address space.

Note, if you're ever feeling froggy or get a wild hair caught up your ass and want to make a really big TLB page, be sure to keep your peripherals away from your cached address space by placing them near the top of your address space.


Exception and Interrupt Processing

Main article: Exceptions and Interrupts
The processor receives exceptions from a number of sources, including translation lookaside buffer (TLB) misses, arithmetic overflows, I/O interrupts, and system calls. When the CPU detects an exception, the normal sequence of instruction execution is suspended and the processor enters Kernel mode. The processor then disables interrupts and forces execution of a software exception process (called an exception handler) located at a fixed address. The handler saves the context of the processor, including the contents of the program counter, the current operating mode (User or Supervisor), and the status of the interrupts (enabled or disabled). This context is saved so it can be restored when the exception processing has been performed.


NEC VR4300 Pinout

The following is from the VR4300 manual.

V4300 pinout.
Name Description
ColdReset Cold Reset
DivMode (1:0)* Divide Mode
EOK External OK
EReq External Request
EValid External Valid
Int (4:0) Interrupt Request
JTCK JTAG Clock Input
JTDI JTAG Data In
JTDO JTAG Data Out
JTMS JTAG Command Signal
MasterClock Master Clock
NMI Non-maskable Interrupt Request
PLLCap (1:0) Phase Locked Loop Capacitance
PMaster Processor Master
PReq Processor Request
PValid Processor Valid
Reset Reset
Syncln Synchronization Clock Input
SyncOut Synchronization Clock Output
SysAD (31:0) System Address/Data Bus
SysCmd (4:0) System Command Data ID Bus
TClock Transmit Clock
VDD Power Supply
GND Ground
VDDP VDD for PLL
GNDP GND for PLL

* In the mPD30200- ́ ́ ́. DivMode (2:0) in the mPD30210- ́ ́ ́.

Pin Functions

Cpupin1.png Cpupin2.png Cpupin3.png Cpupin4.png Cpupin51.png Cpupin52.png