Webcentive RISC-V Reference

sinval.vma

Invalidate cached address translations

Extension
Svinval
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
sinval.vma xs1, xs2
Length
32-bit

Encoding

31252420191514121176210
0001011rs2rs1000000001110011

Match 0x16000073, mask 0xfe007fff. Source: sinval.vma 11..7=0 rs1 rs2 31..25=0x0b 14..12=0 6..2=0x1C 1..0=3 in riscv-opcodes/extensions/rv_svinval.

FieldBitsriscv-opcodes name
rs224:20rs2
rs119:15rs1

Description

The sinval.vma instruction invalidates any address-translation cache entries that an sfence.vma instruction with the same values of xs1 and xs2 would invalidate. However, unlike sfence.vma, sinval.vma instructions are only ordered with respect to sfence.vma, sfence.w.inval, and sfence.inval.ir instructions as defined below.

Description from riscv-unified-db, reformatted.

Operation

XReg vaddr = X[xs1];
Bits<ASID_WIDTH> asid = X[xs2][ASID_WIDTH-1:0];

if (CSR[mstatus].TVM == 1 &&
    ((mode() == PrivilegeMode::S) || (mode() == PrivilegeMode::VS))) {
  raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
}

if (CSR[misa].H == 1 && CSR[hstatus].VTVM == 1 && mode() == PrivilegeMode::VS) {
  raise (ExceptionCode::VirtualInstruction, mode(), $encoding);
}

if (mode() == PrivilegeMode::U) {
  raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

if (CSR[misa].H == 1 && mode() == PrivilegeMode::VU) {
  raise (ExceptionCode::VirtualInstruction, mode(), $encoding);
}

# note: this will default to "all"
VmaOrderType vma_type;
if (CSR[misa].H == 1 && mode() == PrivilegeMode::VS) {
  vma_type.vsmode = true;
  vma_type.single_vmid = true;
  vma_type.vmid = CSR[hgatp].VMID;
} else {
  vma_type.smode = true;
}

if ((xs1 == 0) && (xs2 == 0)) {
  # invalidate all translations, from all addresses and all ASIDs
  # includes global mappings
  vma_type.global = true;

  invalidate_translations(vma_type);

} else if ((xs1 == 0) && (xs2 != 0)) {
  # invalidates all translations from ASID 'asid'
  # does not affect global mappings
  vma_type.single_asid = true;
  vma_type.asid = asid;

  invalidate_translations(vma_type);

} else if ((xs1 != 0) && (xs2 == 0)) {
  # invalidate all translations from leaf page tables containing 'vaddr'
  # does not affect global mappings
  if (canonical_vaddr?(vaddr)) {
    vma_type.single_vaddr = true;
    vma_type.vaddr = vaddr;

    invalidate_translations(vma_type);

  }
  # else, silently do nothing

} else {
  # invalidate all translations from leaf page tables for address space 'asid' containing 'vaddr'
  # does not affect global mappings
  if (canonical_vaddr?(vaddr)) {
    vma_type.single_asid = true;
    vma_type.asid = asid;
    vma_type.single_vaddr = true;
    vma_type.vaddr = vaddr;

    invalidate_translations(vma_type);

  }
  # else, silently do nothing
}

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages