πΎ Archived View for thingvellir.net βΊ log βΊ 2023-06-16.gmi captured on 2024-12-17 at 10:17:40. Gemini links have been rewritten to link to archived content
β¬ οΈ Previous capture (2023-11-14)
-=-=-=-=-=-=-
As of 2023-07-05, this document is unfinished!
Support for unaligned loads and stores is implementation-defined.
The byte order is little-endian for the file format, instructions, and data values.
Instruction and data memory are in separate spaces. Only the data memory is read-write accessible to the ISA. Instruction space pointers are only word-addressable, data space is octet-addressable.
struct HeaderSymbol { offset: uint32, // the instruction word this symbol // points to, must not be zero name: [uint8; 60], // zero-padded string } struct Header { magic: [uint8; 4] = "Plg\x00", data_len: uint32, // must be a multiple of 16 bss_len: uint32, // ditto, bss space is appended to the end // of data space but is not stored in the file text_count: uint32, // length in 32 bit words, not bytes sym_count: uint32, // what pc will be set to at startup for in-vm initialization // if zero, the 0th instruction word must be 'eret' reset_vector: uint32, // 40 free bytes for implementations to use userdata: [uint8; 40], // symbols for the host to call plugin functions syms: [HeaderSymbol; sym_count], // these two sections are separate in the ISA, // data being general purpose read-write space, // and text being host-read-only instruction memory data: [uint8; data_len], text: [uint32; text_count], }
There are 32 general purpose 32-bit integer registers. Writes to the zero register are ignored, and reading from it always returns zero.
Floating-point operations share the 32 integer registers.
All instructions are a fixed 32 bits in length, with 128 available opcodes.
Immediate fields must be zero if an instruction does not use them.
31 22 17 12 07 04 00 Bit βββββββββΌββββββΌββββββΌββββββΌββββββββΌββββββββ€ β imm10 β rs2 β rs1 β rd β opc β opf β βββββββββ΄ββββββ΄ββββββ΄ββββββ΄ββββββββ΄ββββββββ
31 17 12 07 04 00 Bit βββββββββββββββΌββββββΌββββββΌββββββββΌββββββββ€ β imm15 β rs1 β rd β opc β opf β βββββββββββββββ΄ββββββ΄ββββββ΄ββββββββ΄ββββββββ
31 12 07 03 00 Bit βββββββββββββββββββββΌββββββΌββββββββΌββββββββ€ β imm20 β rd β opc β opf β βββββββββββββββββββββ΄ββββββ΄ββββββββ΄ββββββββ
Instructions either listed as 'reserved' or not listed at all should cause an invalid instruction exception.
An instruction field must be zero if the instruction does not use it.
ββββββ¬βββββ¬ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β opcβ opfβ Nameβ Descriptionβ ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 00 β 00 β break β Debugger breakpoint β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 00 β 01 β eret β Halt execution and return to host β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 00 β 02 β ecall β Call host function (imm15) β ββββββ΄βββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββ¬βββββ¬ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β opcβ opfβ Nameβ Descriptionβ ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 00 β β Reserved β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 01 β sw β Store 32b word (rd) to (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 02 β sh β Store 16b short (rd) to (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 03 β sb β Store 8b byte (rd) to (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 04 β β Reserved β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 05 β lw β Load s-ext 32b word (rd) from (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 06 β lh β Load s-ext 16b short (rd) from (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 07 β lb β Load s-ext 8b byte (rd) from (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 08 β β Reserved β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 09 β lhu β Load z-ext 16b short (rd) from (rs1 + imm15) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 01 β 0A β lbu β Load z-ext 8b byte (rd) from (rs1 + imm15) β ββββββ΄βββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββ¬βββββ¬ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β opcβ opfβ Nameβ Descriptionβ ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 00 β addi β rd := rs1 + (imm15 z-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 01 β subi β rd := rs1 - (imm15 z-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 02 β andi β rd := rs1 & (imm15 s-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 03 β xori β rd := rs1 ^ (imm15 s-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 04 β ori β rd := rs1 | (imm15 s-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 05 β slli β rd := rs1 << (imm15 z-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 06 β srli β rd := rs1 z-ext>> (imm15 z-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 07 β srai β rd := rs1 s-ext>> (imm15 z-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 08 β muli β rd := rs1 * (imm15 s-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 09 β divi β rd := rs1 /trunc (imm15 s-ext) (0 illegal) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 0A β remi β rd := rs1 %trunc (imm15 s-ext) (0 illegal) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 0B β icf β rd := (float)rs1 truncated to int32 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 0C β fci β rd := rs1 converted to float β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 0D βroundf β rd := round((float)rs1) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 0E β ceilf β rd := ceil((float)rs1) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 02 β 0F βfloorf β rd := floor((float)rs1) β ββββββ΄βββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββ¬βββββ¬ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β opcβ opfβ Nameβ Descriptionβ ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 00 β add β rd := rs1 + rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 01 β sub β rd := rs1 - rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 02 β and β rd := rs1 & rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 03 β xor β rd := rs1 ^ rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 04 β or β rd := rs1 | rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 05 β sll β rd := rs1 << rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 06 β srl β rd := rs1 z-ext>> rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 07 β sra β rd := rs1 s-ext>> rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 08 β mul β rd := rs1 * rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 09 β div β rd := rs1 /trunc rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 0A β rem β rd := rs1 %trunc rs2 β βββββοΏ½οΏ½οΏ½βββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 0B β addf β rd := (float)rs1 + (float)rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 0C β subf β rd := (float)rs1 - (float)rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 0D β mulf β rd := (float)rs1 * (float)rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 0E β divf β rd := (float)rs1 / (float)rs2 β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 03 β 0F β sqrtf β rd := sqrt((float)rs1) β ββββββ΄βββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββ¬βββββ¬ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β opcβ opfβ Nameβ Descriptionβ ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 00 β jalr β rd := pc + 1; pc := rs1 + (imm15 z-ext) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 01 β beq β if rs1 == rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 02 β bne β if rs1 != rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 03 β blt β if rs1 <s rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 04 β bge β if rs1 >=s rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 05 β bltu β if rs1 <u rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 06 β bgeu β if rs1 >=u rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 07 β bltf β if rs1 <f rs2 { pc += (imm15 s-ext) } β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 04 β 08 β bgef β if rs1 >=f rs2 { pc += (imm15 s-ext) } β ββββββ΄βββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββ¬βββββ¬ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β opcβ opfβ Nameβ Descriptionβ ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 05 β 00 β lui β rd := (imm20 << 12) β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 05 β 01 β lif β rd := (imm20 s-ext) converted to float β ββββββΌβββββΌββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β 05 β 02 β jal β rd := pc + 1; pc = (imm20 z-ext) β ββββββ΄βββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ β Exampleβ Descriptionβ βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β nop β addi zero zero 0 β βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β mv rd rs1 β addi rd rs1 0 β βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β not rd rs1 β xori rd rs1 -1 β βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€ β TODO β β βββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
This ABI is used both for function calls inside the VM and for host-VM syscalls.
ββββββ¬βββββ¬βββββββββββββββββββββββββββββββββββ¬βββββββββ β RnβNameβ Descriptionβ Saverβ ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 00 βzeroβ Always zero β ---- β ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 01 β ra β Return address β Caller β ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 02 β sp β Stack pointer β Callee β ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 03 β fp β Frame pointer β Callee β ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 04 β a0 β Function arguments/Return values β Caller β β 05 β a1 β β β β 06 β a2 β β β β 07 β a3 β β β β 08 β a4 β β β β 09 β a5 β β β β 0A β a6 β β β β 0B β a7 β β β ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 0C β t0 β Temporary registers β Caller β β 0D β t1 β β β β 0E β t2 β β β β 0F β t3 β β β β 10 β t4 β β β β 11 β t5 β β β β 12 β t6 β β β β 13 β t7 β β β β 14 β t8 β β β β 15 β t9 β β β ββββββΌβββββΌβββββββββββββββββββββββββββββββββββΌβββββββββ€ β 16 β s0 β Saved registers β Callee β β 17 β s1 β β β β 18 β s2 β β β β 19 β s3 β β β β 1A β s4 β β β β 1B β s5 β β β β 1C β s6 β β β β 1D β s7 β β β β 1E β s8 β β β β 1F β s9 β β β ββββββ΄βββββ΄βββββββββββββββββββββββββββββββββββ΄βββββββββ
βββββββββββββββ¬ββββββββ β C Type Name β Bytes β βββββββββββββββΌββββββββ€ β char β 1 β βββββββββββββββΌββββββββ€ β short β 2 β βββββββββββββββΌββββββββ€ β int β 4 β βββββββββββββββΌββββββββ€ β long β 4 β βββββββββββββββΌββββββββ€ β long long β 8 β βββββββββββββββΌββββββββ€ β void * β 4 β βββββββββββββββΌββββββββ€ β float β 4 β βββββββββββββββΌββββββββ€ β double β --- β The semantics of 'double' and βββββββββββββββΌββββββββ€ 'long double' are undefined by this spec. β long double β --- β βββββββββββββββ΄ββββββββ