MIPS I semantics, for every model (the R3000A runs them as they are, the R5900 as MIPS III does).
0/1 a fixed bit, name a field, a bit the decoder ignores
lwr rt (simm imm) rs
Load Word Right
LWR on a 64-bit CPU ([MIPSIV] LWR, PCSX2's interpreter [PCSX2]): the merged word is sign-extended when the whole word was loaded (byte 0); otherwise only the low 32 bits change and the high 32 keep their value.
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | rs | rt | imm | |||||||||||||||||||||||
(defmips lwr (:only :r5900) (:asm "lwr" rt (simm imm) rs) (:doc "Load Word Right")
(let* ((a (vaddr rs imm)) (b (wrap 2 a)) (m (mips-load 32 (wrap 32 (- a b))))
(w (logior (ash m (- (* 8 b))) (logand (gpr rt) (wrap 32 (ash #xFFFFFF00 (- 24 (* 8 b))))))))
(if (= b 0)
(set-gpr rt (wrap 64 (sext 32 w)))
(set-gpr rt (logior (logand (gpr rt) #xFFFFFFFF00000000) (wrap 32 w))))))
sb rt (simm imm) rs
Store Byte
SB: "memory[vAddr] <- GPR[rt]7..0"
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | rs | rt | imm | |||||||||||||||||||||||
(defmips sb (:asm "sb" rt (simm imm) rs) (:doc "Store Byte")
(mips-store 8 (vaddr rs imm) (wrap 8 (gpr rt))))
sh rt (simm imm) rs
Store Halfword
SH: "if vAddr0 /= 0 then SignalException(AddressError) ... memory[vAddr] <- GPR[rt]15..0"
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 1 | rs | rt | imm | |||||||||||||||||||||||
(defmips sh (:asm "sh" rt (simm imm) rs) (:doc "Store Halfword")
(let ((a (vaddr rs imm)))
(if (/= (wrap 1 a) 0)
(raise-address +exc-ades+ a)
(mips-store 16 a (wrap 16 (gpr rt))))))
sw rt (simm imm) rs
Store Word
SW: "memory[vAddr] <- GPR[rt]31..0"
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 | 1 | rs | rt | imm | |||||||||||||||||||||||
(defmips sw (:asm "sw" rt (simm imm) rs) (:doc "Store Word")
(let ((a (vaddr rs imm)))
(if (/= (wrap 2 a) 0)
(raise-address +exc-ades+ a)
(mips-store 32 a (gpr rt)))))
swl rt (simm imm) rs
Store Word Left
SWL, little-endian: the register's high 8 * (byte + 1) bits to the bytes
of the word from its start up to vAddr ("swl [N*4+0] transfer upper
8bit of Rt to [N*4+0] ... swl [N*4+3] whole 32bit"); the word's other
bytes are left. Written as a read-modify-write of the aligned word,
which is the same for memory (not for a device register with side
effects on reads, which the machine's memory map handles).
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 | rs | rt | imm | |||||||||||||||||||||||
(defmips swl (:asm "swl" rt (simm imm) rs) (:doc "Store Word Left")
(let* ((a (vaddr rs imm)) (b (wrap 2 a)) (w (wrap 32 (- a b))) (m (mips-load 32 w)))
(mips-store 32 w (logior (logand m (wrap 32 (ash #xFFFFFF00 (* 8 b))))
(ash (wrap 32 (gpr rt)) (- (* 8 b) 24))))))
swr rt (simm imm) rs
Store Word Right
SWR, little-endian: the register's low 8 * (4 - byte) bits to the bytes
of the word from vAddr to its end ("swr [N*4+0] transfer whole 32bit ...
swr [N*4+3] lower 8bit")
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 1 | 1 | 1 | 0 | rs | rt | imm | |||||||||||||||||||||||
(defmips swr (:asm "swr" rt (simm imm) rs) (:doc "Store Word Right")
(let* ((a (vaddr rs imm)) (b (wrap 2 a)) (w (wrap 32 (- a b))) (m (mips-load 32 w)))
(mips-store 32 w (logior (logand m (ash #x00FFFFFF (- (* 8 b) 24)))
(wrap 32 (ash (gpr rt) (* 8 b)))))))
beq rs rt (b-rel offset)
Branch on Equal
BEQ: "target <- sign_extend(offset || 0^2); condition <- GPR[rs] = GPR[rt]; if condition then PC <- PC + target" (PC the delay slot's address)
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | rs | rt | offset | |||||||||||||||||||||||
(defmips beq (:asm "beq" rs rt (b-rel offset)) (:doc "Branch on Equal")
(when (= (gpr rs) (gpr rt))
(branch-to (branch-target offset))))
bne rs rt (b-rel offset)
Branch on Not Equal
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 1 | 0 | 1 | rs | rt | offset | |||||||||||||||||||||||
(defmips bne (:asm "bne" rs rt (b-rel offset)) (:doc "Branch on Not Equal")
(when (/= (gpr rs) (gpr rt))
(branch-to (branch-target offset))))
blez rs (b-rel offset)
Branch on Less Than or Equal to Zero
BLEZ: "condition <- GPR[rs] <= 0", BGTZ "> 0", BLTZ "< 0", BGEZ ">= 0", GPR[rs] signed
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 | rs | 0 | 0 | 0 | 0 | 0 | offset | |||||||||||||||||||
(defmips blez (:asm "blez" rs (b-rel offset)) (:doc "Branch on Less Than or Equal to Zero")
(when (<= (sgpr rs) 0)
(branch-to (branch-target offset))))
bgtz rs (b-rel offset)
Branch on Greater Than Zero
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | rs | 0 | 0 | 0 | 0 | 0 | offset | |||||||||||||||||||
(defmips bgtz (:asm "bgtz" rs (b-rel offset)) (:doc "Branch on Greater Than Zero")
(when (> (sgpr rs) 0)
(branch-to (branch-target offset))))
bltz rs (b-rel offset)
Branch on Less Than Zero
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | rs | 0 | 0 | 0 | 0 | 0 | offset | |||||||||||||||||||
(defmips bltz (:asm "bltz" rs (b-rel offset)) (:doc "Branch on Less Than Zero")
(when (< (sgpr rs) 0)
(branch-to (branch-target offset))))
bgez rs (b-rel offset)
Branch on Greater Than or Equal to Zero
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | rs | 0 | 0 | 0 | 0 | 1 | offset | |||||||||||||||||||
(defmips bgez (:asm "bgez" rs (b-rel offset)) (:doc "Branch on Greater Than or Equal to Zero")
(when (>= (sgpr rs) 0)
(branch-to (branch-target offset))))
bltzal rs (b-rel offset)
Branch on Less Than Zero and Link
BLTZAL: "condition <- GPR[rs] < 0; GPR[31] <- PC + 8; if condition then PC <- PC + target": the link is written whether or not the branch is taken, and the condition reads rs before it ([PSXSPX] "jumps and branches": "if rs is $ra, then the value used for the comparison is $ra's value before linking")
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | rs | 1 | 0 | 0 | 0 | 0 | offset | |||||||||||||||||||
(defmips bltzal (:asm "bltzal" rs (b-rel offset)) (:doc "Branch on Less Than Zero and Link")
(let ((c (< (sgpr rs) 0)))
(set-gpr 31 (reg32 (link-address)))
(when c (branch-to (branch-target offset)))))
bgezal rs (b-rel offset)
Branch on Greater Than or Equal to Zero and Link
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | rs | 1 | 0 | 0 | 0 | 1 | offset | |||||||||||||||||||
(defmips bgezal (:asm "bgezal" rs (b-rel offset)) (:doc "Branch on Greater Than or Equal to Zero and Link")
(let ((c (>= (sgpr rs) 0)))
(set-gpr 31 (reg32 (link-address)))
(when c (branch-to (branch-target offset)))))
j (j-abs target)
Jump
J: "PC <- PC(GPRLEN-1)..28 || instr_index || 0^2", PC the delay slot's
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 0 | target | |||||||||||||||||||||||||
(defmips j (:asm "j" (j-abs target)) (:doc "Jump")
(branch-to (logior (logand (+ (mips-pc cpu) 4) #xF0000000) (ash target 2))))
jal (j-abs target)
Jump and Link
JAL: as J, and "GPR[31] <- PC + 8"
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | target | |||||||||||||||||||||||||
(defmips jal (:asm "jal" (j-abs target)) (:doc "Jump and Link")
(set-gpr 31 (reg32 (link-address)))
(branch-to (logior (logand (+ (mips-pc cpu) 4) #xF0000000) (ash target 2))))
jr rs
Jump Register
JR: "temp <- GPR[rs]; PC <- temp" (an address with its low two bits set raises an address error at the fetch, exec.lisp)
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | rs | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | ||||
(defmips jr (:asm "jr" rs) (:doc "Jump Register")
(branch-to (gpr rs)))
jalr rd rs
Jump and Link Register
JALR: "temp <- GPR[rs]; GPR[rd] <- PC + 8; PC <- temp": rs is read before rd is written
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | rs | 0 | 0 | 0 | 0 | 0 | rd | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | ||||||||
(defmips jalr (:asm "jalr" rd rs) (:doc "Jump and Link Register")
(let ((target (gpr rs)))
(set-gpr rd (reg32 (link-address)))
(branch-to target)))
syscall code
System Call
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | code | 0 | 0 | 1 | 1 | 0 | 0 | |||||||||||||||||||
(defmips syscall (:asm "syscall" code) (:doc "System Call")
(raise +exc-syscall+))
break code code2
Breakpoint
r3000a, r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | code | code2 | 0 | 0 | 1 | 1 | 0 | 1 | ||||||||||||||||||
(defmips break (:asm "break" code code2) (:doc "Breakpoint")
(raise +exc-break+))
(defmipsmacro gpr-inflight) source(defmipsmacro gpr-inflight (n)
(if (member :load-delay (mips-model-features))
`(if (= (mips-lfr cpu) ,n) (mips-lfv cpu) (gpr ,n))
`(gpr ,n)))(defmacro raise-address) source(defmacro raise-address (code a)
`(progn (setf (aref (mips-cop0 cpu) 8) (wrap 32 ,a))
(raise ,code)))Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.