HarvOS ISA

ISA - Instruction Set Architecture

This page documents the instruction set currently implemented by the HarvOS core. It uses RV32I-like 32-bit encodings, but it is not claimed to be a complete standards-compliant RISC-V platform.

Encoding groups

GroupOpcodeDescription
LOAD0000011Byte, halfword and word loads.
FENCE0001111FENCE and FENCE.I; FENCE.I flushes the HarvOS TLBs.
OP-IMM0010011Integer immediate operations.
AUIPC0010111PC-relative U-type value construction.
STORE0100011Byte, halfword and word stores.
OP0110011Register-register ALU operations.
LUI0110111Upper immediate load.
BRANCH1100011Conditional branches.
JALR1100111Indirect jump with link.
JAL1101111PC-relative jump with link.
SYSTEM1110011ECALL, EBREAK and CSR operations.
CUSTOM-00001011HarvOS-specific runtime and security instructions.

RISC-V profile and deviations

AspectRISC-V-likeHarvOS-specific
Base encodingOpcode, rd, rs1, rs2, funct3 and immediate fields follow familiar layouts for listed instructions.Unlisted opcode/function combinations are illegal; there is no implicit support for the full RISC-V specification.
ExtensionsRV32I-like integer operations.No M, A, C, floating-point or standard privileged extensions beyond the local CSRs documented here.
Privileges and CSRsNames U, S and M are inspired by RISC-V.CSR addresses and semantics are local; the MPU is not PMP and satp is not full Sv32.
Memory protectionLoad, store and fetch can fault.Harvard rules, W^X checks, MMU region model and fixed MPU are HarvOS-specific.

Register model

The core has 32 integer registers x0..x31. x0 is permanently zero. The software ABI follows common RISC-V conventions: a0 is used for arguments/return values and a7 carries the syscall number.

ALU and immediate instructions

MnemonicFormatOperationNotes
ADDRrd = rs1 + rs2funct7=0000000.
SUBRrd = rs1 - rs2funct7=0100000.
SLLR/ILogical left shift.Shift amount is 5 bits.
SLT/SLTUR/ISigned or unsigned less-than.Result is 0 or 1.
XOR/OR/ANDR/IBitwise operations.
SRL/SRAR/ILogical or arithmetic right shift.SRA uses funct7=0100000.
ADDIIrd = rs1 + signext(imm12)Common pointer arithmetic.
LUIUrd = imm20 << 12Upper immediate.
AUIPCUrd = pc + (imm20 << 12)PC-relative address construction.

Load and store

MnemonicWidthSemanticsFault conditions
LB/LBU8 bitSigned or unsigned byte load.MMU/MPU fault.
LH/LHU16 bitSigned or unsigned halfword load.Address must be 2-byte aligned.
LW32 bitWord load.Address must be 4-byte aligned.
SB8 bitByte store.MMU/MPU fault.
SH16 bitHalfword store.Address must be 2-byte aligned.
SW32 bitWord store.Address must be 4-byte aligned.

Control flow

MnemonicSemanticsNotes
BEQ/BNEBranch on equality or inequality.Target must be 4-byte aligned.
BLT/BGESigned comparison branches.
BLTU/BGEUUnsigned comparison branches.
JALrd = pc + 4, pc = pc + imm.Target must be 4-byte aligned.
JALRrd = pc + 4, pc = (rs1 + imm) & ~1.Final target must be 4-byte aligned.

System, CSR and Custom-0

InstructionEncodingDescriptionPrivilege
ECALL0x00000073Trap to user or supervisor ecall cause.User/Supervisor.
EBREAK0x00100073Breakpoint trap.User/Supervisor.
CSRRW/CSRRS/CSRRCopcode=1110011Read/write, set or clear local CSRs.Supervisor only.
CLRREG rdCustom-0, funct3=000Writes zero to rd.User/Supervisor.
CLRMEM rs1, rs2Custom-0, funct3=001Clears rs2 32-bit words starting at rs1. Address must be aligned; MMIO is forbidden.Supervisor only.
ENTROPY rdCustom-0, funct3=010rd = entropy_i ^ csr_srandom.User/Supervisor.
SRET0x10200073HarvOS trap return: loads pc=sepc, flushes TLBs and returns to user mode.Supervisor only.

Custom-0 bit layout

word = (rs2 << 20) | (rs1 << 15) | (funct3 << 12) | (rd << 7) | 0x0b
BitsNameMeaning
6:0opcode0001011 / 0x0b.
11:7rdDestination for CLRREG and ENTROPY.
14:12funct3000 = CLRREG, 001 = CLRMEM, 010 = ENTROPY.
19:15rs1Base address for CLRMEM.
24:20rs2Word count for CLRMEM.
31:25ReservedSoftware should set these bits to zero for forward compatibility.

CSRs

CSRAddressMeaning
sstatus0x100Interrupt enable and fixed status bits; writable mask 0x00000003.
stvec0x101Trap vector, 4-byte aligned.
sepc0x102Trap PC, 4-byte aligned.
scause0x103Trap cause.
stval0x104Trap value, often an address or instruction word.
satp0x105Translation control; mode bit and ASID-style bits are used locally.
srandom0x120Software mixing value for ENTROPY.
smpuctl0x130MPU lock control.
scaps0x140Capability mask for runtime policy.

Trap codes

NameCodeTrigger
SCAUSE_INST_ADDR_MISALIGNED0x00000000PC or branch/jump target is not 4-byte aligned.
SCAUSE_INST_ACCESS_FAULT0x00000001Fetch MMU/MPU rejects access.
SCAUSE_ILLEGAL_INSTRUCTION0x00000002Unsupported opcode/function or illegal privilege access.
SCAUSE_BREAKPOINT0x00000003EBREAK.
SCAUSE_LOAD_ADDR_MISALIGNED0x00000004Misaligned LH/LHU/LW.
SCAUSE_LOAD_ACCESS_FAULT0x00000005Load denied.
SCAUSE_STORE_ADDR_MISALIGNED0x00000006Misaligned SH/SW or CLRMEM.
SCAUSE_STORE_ACCESS_FAULT0x00000007Store denied.
SCAUSE_ECALL_U0x00000008ECALL from user mode.
SCAUSE_ECALL_S0x00000009ECALL from supervisor mode.
SCAUSE_HARVARD_VIOLATION0x0000000aViolation of IMEM/DMEM separation.
SCAUSE_EXTERNAL_INTERRUPT0x8000000bExternal IRQ, for example USB or HNET.