Skip to main content

Module decode

Module decode 

Source
Expand description

MIPS III instruction decode (T-11-002).

Word in, Decoded out. Pure and total: every 32-bit pattern decodes to something, with anything unrecognized becoming Op::Reserved rather than a panic or a silent no-op. A guest can execute arbitrary bytes, so decode must not be able to fail.

§Encoding

Three formats, distinguished by the primary opcode in bits 31..26:

 31    26 25  21 20  16 15  11 10   6 5    0
┌────────┬──────┬──────┬──────┬──────┬──────┐
│ opcode │  rs  │  rt  │  rd  │  sa  │ funct│  R-type (opcode == 0, SPECIAL)
├────────┼──────┼──────┼──────┴──────┴──────┤
│ opcode │  rs  │  rt  │       immediate    │  I-type
├────────┼──────┴──────┴──────┴──────┴──────┤
│ opcode │              target              │  J-type
└────────┴──────────────────────────────────┘

This module covers the integer subset that crate::alu implements. Loads, stores, branches, jumps, COP0, COP1 and the trap family decode to Op::Reserved for now — they arrive with T-11-003 and T-11-004. That is deliberate: an unimplemented opcode that decodes to Reserved raises a reserved-instruction exception, which is visible, rather than executing as a NOP, which silently produces wrong results.

Structs§

Decoded
A decoded instruction: the operation plus its raw encoded fields.

Enums§

Op
The decoded operation. Only the integer subset so far; see the module docs.

Functions§

decode
Decode one instruction word. Total — never fails, never panics.