Files
Odin/core/rexcode/isa/mips/reloc.odin
Brendan Punsky 95df04fbe1 rexcode: re-house ISA packages under core:rexcode/isa/<arch>
Move all ten ISA packages (x86, arm32, arm64, mips, riscv, ppc, ppc_vle,
rsp, mos6502, mos65816) from core/rexcode/<arch> to core/rexcode/isa/<arch>,
so the import pattern is now `import "core:rexcode/isa/x86"`. The shared
core stays at core:rexcode/isa.

Mechanical: relative `import "../isa"` / "../../isa" -> absolute
"core:rexcode/isa" (the only path that survives the move; the "../" and
"../.." self/generated imports move with their packages). build.lua now
builds paths as <root>/isa/<name>; stale `cd <arch>` hints in the verify
tools and the doc.odin paths updated.

WASM stays at core/rexcode/wasm for now -- it is an IR, not an ISA, and
will move under the forthcoming core:rexcode/ir once that layer lands.

All 10 arches gen/builders/check/test green; import core:rexcode/isa/x86
verified working; wasm still compiles.
2026-06-18 19:03:27 -04:00

36 lines
1.3 KiB
Odin

// rexcode · Brendan Punsky (dotbmp@github), original author
package rexcode_mips
// =============================================================================
// MIPS RELOCATIONS
// =============================================================================
//
// Per the cross-arch design (§2.4): each arch owns its own Relocation_Type
// enum and Relocation struct. The struct shape mirrors ELF rela so an
// object emitter can consume it unchanged; the resolution semantics for
// each `type` value are MIPS-specific and live in encoder.odin's pass-2
// resolver.
Relocation_Type :: enum u8 {
NONE = 0,
REL16, // 16-bit signed PC-rel branch offset (BEQ/BNE/BLEZ/BGTZ/...)
REL21, // 21-bit signed PC-rel compact branch (R6 BEQZC/BNEZC)
REL26, // 26-bit signed PC-rel compact branch (R6 BC/BALC)
REL_PC19, // 19-bit R6 PC-relative load offset ((target - PC) >> 2) (LWPC/LWUPC)
REL_PC18, // 18-bit R6 PC-relative load offset ((target - (PC & ~7)) >> 3) (LDPC)
J26, // 26-bit J-type region target ((target_addr >> 2) & 0x3FFFFFF)
HI16, // upper 16 of 32-bit absolute (LUI rt, %hi(sym)+0x8000 if LO16 paired)
LO16, // lower 16 of 32-bit absolute (ADDIU rt, rt, %lo(sym))
}
Relocation :: struct #packed {
offset: u32,
label_id: u32,
addend: i32,
type: Relocation_Type,
size: u8,
inst_idx: u16,
}
#assert(size_of(Relocation) == 16)