371 definitions in 21 files, 371 with an encoding diagram. src/isa/mips
| File | Definitions | Other | What |
|---|---|---|---|
| package.lisp | 0 | 0 | the ISA.MIPS package: MIPS (the PS1's R3000A, the PS2's R5900) on one abstract machine; its state contract. |
| model.lisp | 0 | 6 | MIPS CPU models: several in one build, each instantiated from the one description. |
| state.lisp | 0 | 31 | the one MIPS state every model runs on, and the accessors every semantics body uses. |
| bus.lisp | 0 | 12 | a machine's memory map under the MIPS models' loads, stores and fetches (XSPE_MIPS_BUS). |
| defmips.lisp | 0 | 2 | MIPS encodings (generated, gen/opcodes.lisp) and DEFMIPS, an instruction's semantics instantiated per model. |
| gen/opcodes.lisp | 0 | 0 | the encodings table, shown with each instruction |
| mips1.lisp | 59 | 2 | MIPS I semantics, for every model (the R3000A runs them as they are, the R5900 as MIPS III does). |
| cop0r3k.lisp | 7 | 15 | the R3000A's coprocessor 0 (the PS1's): its registers, rfe, exception entry and interrupts. |
| gte.lisp | 31 | 40 | the PS1's coprocessor 2, the Geometry Transformation Engine: its registers, moves and commands. |
| mips3.lisp | 48 | 0 | MIPS II, III and IV instructions of the R5900: 64-bit arithmetic, doubleword memory, likely branches, traps. |
| ee.lisp | 22 | 15 | the R5900's own non-multimedia instructions: 3-operand multiply, multiply-add, pipeline 1, SA, 128-bit loads and stores. |
| cop0.lisp | 29 | 21 | the R5900's coprocessor 0: moves, ERET, EI/DI, BC0, the TLB instructions, the debug and performance registers, and its exception entry. |
| mmi.lisp | 91 | 13 | the R5900's multimedia instructions (MMI): parallel operations on its 128-bit GPRs, HI and LO. |
| eefloat.lisp | 0 | 27 | the Emotion Engine's single precision as rules around the IEEE primitives: the arithmetic of its FPU (COP1) and of the VUs. |
| fpu.lisp | 34 | 11 | the R5900's FPU (coprocessor 1): single precision only, not IEEE 754. |
| vu0.lisp | 50 | 37 | the R5900's coprocessor 2: VU0 in macro mode (its upper and lower instructions issued by the EE core), moves to and from it. |
| exec.lisp | 0 | 4 | MIPS as a guest: per model, the executor, decoder, step and run loop. |
| enc.lisp | 0 | 2 | MIPS as a host: run-time encoders per model, made from the DEFMIPS encodings, and the emitter. |
| asm.lisp | 0 | 0 | a compile-time MIPS assembler per model, built from the DEFMIPS records. |
| model/r3000a.lisp | 0 | 1 | the MIPS model of the PS1's CPU (and of the PS2's IOP): an LSI CW33300, an R3000A core. |
| model/r5900.lisp | 0 | 1 | the MIPS model of the PS2's Emotion Engine core, the R5900. |
Package ISA.MIPS. One description of MIPS, instantiated per CPU model
on one abstract machine (the mips state struct). Each model is an ISA of
its own to the rest of the kit (R3000A, R5900): its own executor,
decoder, step, run loop, encoders and isel tiles, all made from the same
defmips forms. Both CPUs are guests (the PS1, the PS2's EE and IOP) and
both can be hosts: the PS2 can run the PS1's code, as its IOP does.
See docs/isa.md for the general recipe.
tools/mipsgen into gen/opcodes.lisp (committed): 501 encodings,
152 of them the R3000A's (MIPS I), 439 the R5900's (MIPS III and the EE's
MMI, VU0 macro mode, its FPU), each tagged with its models (:in). The
same name can have different encodings in different models (mult, the
c.cond.s compares). The PS1 GTE's 22 command encodings, which binutils
lacks, are written by hand in gte.lisp from [PSXSPX].model.lisp, model/<name>.lisp): every model file the
build loads (XSPE_MIPS_MODELS, default r3000a;r5900) is a model of
the build, because the PS2 needs both at once. Model-dependent forms
(mips-model-case, mips-feature-case, mips-model-value, and helpers
defined with defmipsmacro) are resolved when defmips expands, so each
model's stored semantics are its own, and the generated C tests no model.state.lisp): the union of what the models architect: 64-bit
GPRs (a 32-bit model keeps them zero-extended; a 64-bit one sign-extends
32-bit results, so MIPS I code computes the same on both), the R5900's
upper GPR halves, HI/LO and HI1/LO1, SA, pc/npc/nnpc for delay slots,
the R3000A's load in flight, COP0, the R5900's FPU, COP2 data and control
(GTE or VU0) and VU0's vector registers.| File | What |
|---|---|
package.lisp | ISA.MIPS and its exports |
model.lisp | defmipsmodel, defmipsmacro, mips-resolve, with-mips-model |
state.lisp | the mips struct; (gpr n), set-gpr, set-gpr32, set-gprx, xgpr, sgpr, reg32, set-gpr-load; mips-load/mips-store (little-endian), vaddr; branch-to, branch-target, nullify, link-address; raise and the exception codes |
model/r3000a.lisp | the PS1's CPU: MIPS I, 32-bit, :load-delay, :gte |
model/r5900.lisp | the PS2's EE core: MIPS III, 64-bit, :mmi, :pipe1, :fpu-single, :vu0 |
defmips.lisp | defmipsenc (the table), defmips (semantics, per model) |
gen/opcodes.lisp | the encodings (generated, do not edit) |
mips1.lisp | MIPS I semantics, for every model, quoting [MIPSIV] and [PSXSPX] |
cop0r3k.lisp | the R3000A's coprocessor 0 (mfc0, mtc0, rfe, the absent coprocessors 1 and 3), r3000a-take-exception, r3000a-interrupt, r3000a-sys-step/-run, r3000a-reset (loaded when r3000a is a model) |
gte.lisp | the R3000A's coprocessor 2, the PS1's GTE: registers, moves, the 22 commands and their encodings (loaded when r3000a is a model) |
mips3.lisp | the R5900's MIPS II/III/IV: 64-bit arithmetic and shifts, ld/sd/lwu/ldl/ldr/sdl/sdr, branch likely, traps, movn/movz, sync, pref, cache [MIPSIV] |
ee.lisp | the R5900's own: 3-operand mult/multu, div/divu, madd/maddu, pipeline 1 (mult1 ... mtlo1 on hi1/lo1), SA (mfsa, mtsa, mtsab, mtsah), lq/sq; gprq/set-gprq (128-bit GPRs) [EECORE] [EEUM] |
cop0.lisp | the R5900's COP0: mfc0/mtc0, the debug and counter moves, eret, ei/di, bc0*, the TLB instructions; r5900-take-exception, r5900-take-level2, r5900-interrupt-p, r5900-take-interrupt, r5900-reset-cop0 [EEUM] |
mmi.lisp | the multimedia instructions (all of the table's) on 128-bit GPRs, HI and LO; lane order stated [EECORE] |
eefloat.lisp | the EE's single precision (no Inf/NaN/denormals, truncation, +-MAX) as rules around the IEEE primitives (an EE value is exactly a double; the double operation toward zero, then truncated to the EE's format), for the FPU and the VUs |
fpu.lisp | the R5900's FPU (COP1): moves, arithmetic, ACC, compares, conversions, bc1*, FCR31's flags |
vu0.lisp | VU0 in macro mode (COP2): every macro instruction of the table, the flags, VU0 data memory, the EE's moves [VUUM] |
exec.lisp | per model M-execute, M-decode, M-step, M-run (and M-execute-w for the load delay); mips-fetch, mips-reset |
enc.lisp | per model (M-enc/<name> field...) (fields MSB first), mips-emit32 |
asm.lisp | (mips-assemble model program origin), mips-load-program |
What is described, from [MIPSIV], [R3000] and [PSXSPX] (docs/refs.md):
mips1.lisp): every MIPS I instruction the PS1
has. One body per instruction for both models; written for the R3000A
only: mult/multu (the R5900's encodings have an rd) and lwr (a
64-bit CPU keeps the register's high half on a partial lwr), which the
R5900's description adds itself. Undefined results are the R3000A's
([PSXSPX]: division by zero, -2^31/-1). Address errors set BadVaddr.exec.lisp): the load in flight lands
after the next instruction unless that one writes the same register
(known statically: r3000a-execute-w's leaves return the register each
instruction's semantics write), a second load replaces the first,
lwl/lwr merge with the value in flight (gpr-inflight), and an
exception lets it land. mfc0/mfc2/cfc2 are delayed the same way. bd is
set for the slot of any branch, bt when it was taken (Cause.BD/BT).cop0r3k.lisp): SR, Cause, EPC, BadVaddr, PRId, TAR
and the debug registers (stored), mtc0's writable bits, rfe, the
coprocessor unusable cases, the exception entry and interrupts (with the
GTE-command quirk). A machine steps with r3000a-sys-step and drives
Cause.IP (bit 10: the interrupt controller); HLE uses r3000a-step and
mips-exc itself.gte.lisp): the 64 registers with their read/write
quirks, mfc2/cfc2/mtc2/ctc2/lwc2/swc2, bc2f/bc2t, SR.CU2, and RTPS RTPT
NCLIP OP DPCS INTPL MVMVA NCDS CDP NCDT NCCS CC NCS NCT SQR DCPL DPCT
AVSZ3 AVSZ4 GPF GPL NCCT with sf/lm/mx/v/cv, the 44-bit MAC checks,
saturation, FLAG, and the UNR division. The command encodings are
hand-written defmipsenc lines (:in (:r3000a)) beside them; the generic
c2 decodes only command numbers the GTE lacks. The commands are
functions, not covered by isel.Tests (tests/isa/mips): mips_enc1 (the new words against llvm-mc,
decoded back), mips_sem1 (sample values, both models), mips_delay and
lower_mips_delay (the load delay), mips_cop0, mips_gte (values from
[PSXSPX]'s formulas and tables), mips_gtediff and mips_cpudiff (with
their lower_ twins: random GTE commands and random programs against
xps1emu's gte.c and cpu.c built on the host from XSPE_XPS1EMU_DIR; the
differences found are psxe's, listed in cpudiff.c), mips_disc (a PS1
disc's boot executable decoded and run, XSPE_TEST_PS1_DISC).
Not described yet: the debug breakpoints (BPC/BDA/DCIC are stored, never raised), bus errors (the machine's memory map raises them), cache isolation (SR.Isc, the machine's stores), timing (the GTE's and the multiplier's cycles, the GTE's store delay, SR.CU2's 2-cycle delay), and unused instruction fields: the decoder takes binutils' encodings, which require them zero, while the R3000A ignores them ([PSXSPX] "Illegal Opcodes"; compiled code has them zero, the Vib-Ribbon executable has none set).
INSN_5900 set plus
MIPS III) has semantics (MIPS I from mips1.lisp, shared with the
R3000A; its own lwr, which keeps the high half on a partial load)
except what the EE does not implement
although binutils lists it for the R5900: the double and long FPU
formats (ceil/floor/round/trunc.l.*, cvt.d.l, cvt.l.*,
cvt.s.l), floor/round.w.s, wait, cfc0/ctc0, jalx, and the
generic c0/c1/c2 (PCSX2's tables [PCSX2] decode none of them: a
reserved instruction).tests/isa/mips/pcsx2.lisp), so not only against binutils.sqrt.s reads ft (bits
20..16), "SQRT.S fd, ft"; binutils 2.44 gives the R5900 MIPS II's form.
fpu.lisp replaces the R5900's entry with a defmipsenc citing the
manual and PCSX2's interpreter and disassembler. binutils' name for the
R5900's cvt.w.s is trunc.w.s (kept, assembled as cvt.w.s).vdiv/vrsqrt/vsqrt the field
called fsf (bits 24..23) is the manual's ftf (ft's lane) and bc (bits
22..21) the manual's fsf (fs's lane).vcallms/vcallmsr record TPC and VPU-STAT, a machine runs them);
Count/Compare, Random, the interrupt lines, CPCOND0, address
translation through the TLB, Coprocessor Unusable (not checked, as in
PCSX2's interpreter): the machine's.src/isel/mips.lisp makes tiles from any model's
semantics; src/isel/mipsmips.lisp pairs R5900 -> R5900 and R3000A ->
R5900 (docs/isel.md), test isel_mips.src/sys/ps2 (not written) would: map memory (kseg0/kseg1, the scratchpad,
VU0's data memory at #x11004000 and the registers) and the TLB's
translations; call r5900-take-exception when r5900-run stops on
mips-exc (with BadVAddr/EntryHi for address and TLB errors) and
r5900-take-interrupt when r5900-interrupt-p (Cause.IP2/IP3/IP7 from
the INTC, the DMAC and Count/Compare, which it advances per cycle); set
mips-cpcond0 from the DMAC; run VU0 micro programs (VPU-STAT, TPC) and
VU1; and run the IOP as an R3000A beside the EE.
gen/opcodes.lisp for the model (:in).
An instruction no machine-readable source has (the GTE's commands) gets
a hand-written defmipsenc beside its semantics, citing its source.(defmips name (:asm "mnemonic" operand...) (:doc "...") body),
quoting the manual. Use the model helpers of state.lisp for anything
whose meaning depends on the register width or the load delay, and
(:only :r5900) or mips-model-case where a model differs. Load the file
in files.cmake before exec.lisp.tests/isa/mips/sem.lisp (in every model that has
the instruction) and an independent assembler's word to enc.lisp.CPM_SOURCE_CACHE=$HOME/.cache/cpm cmake -S . -B build -DXSPE_REGEN=ON
cmake --build build --target mips-regen && git diff src/isa/mips/gen
A new model's target is added to XSPE_MIPSGEN_ARGS
(tools/mipsgen/CMakeLists.txt) as name:ISA-level[:binutils CPU flag].
The test mips_regen (REGEN mode only) requires the committed file to
match a fresh run.
Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.