Sm Extension

Versions

Version 1.11.0

State

ratified

Ratification date

2019-12

Changes

  • Moved Machine spec to Ratified status.

  • Improvements to the description and commentary.

  • Specified which interrupt sources are reserved for standard use.

  • Allocated some synchronous exception causes for custom use.

  • Specified the priority ordering of synchronous exceptions.

  • Added specification that xRET instructions may, but are not required to, clear LR reservations if A extension present.

  • Made the mstatus.MPP field WARL, rather than WLRL.

  • Made the unused xip fields WPRI, rather than WIRI.

  • Made the unused misa fields WARL, rather than WIRI.

  • Rectified an editing error that misdescribed the mechanism by which mstatus is written upon an exception.

  • Described scheme for emulating misaligned AMOs.

  • Specified the behavior of the misa and xepc registers in systems with variable IALIGN.

  • Specified the behavior of writing self-contradictory values to the misa register.

  • Specified contents of CSRs across XLEN modification.

  • Moved PLIC chapter into its own document.

Version 1.12.0

State

ratified

Ratification date

2021-12

Changes

  • Changed MRET to clear mstatus.MPRV when leaving M-mode.

  • Relaxed I/O regions have been specified to follow RVWMO. The previous specification implied that PPO rules other than fences and acquire/release annotations did not apply.

  • Constrained the LR/SC reservation set size and shape when using page-based virtual memory.

  • PMP changes require an SFENCE.VMA on any hart that implements page-based virtual memory, even if VM is not currently enabled.

  • Removed the N extension.

  • Defined the mandatory RV32-only CSR mstatush, which contains most of the same fields as the upper 32 bits of RV64’s mstatus.

  • Defined the mandatory CSR mconfigptr, which if nonzero contains the address of a configuration data structure.

  • Defined optional mseccfg and mseccfgh CSRs, which control the machine’s security configuration.

  • Defined menvcfg CSR (and RV32-only menvcfgh), which control various characteristics of the execution environment.

  • Designated part of SYSTEM major opcode for custom use.

  • Permitted the unconditional delegation of less-privileged interrupts.

  • Added optional big-endian and bi-endian support.

  • Made priority of load/store/AMO address-misaligned exceptions implementation-defined relative to load/store/AMO page-fault and access-fault exceptions.

  • Software breakpoint exceptions are permitted to write either 0 or the pc to xtval.

  • Specified relaxed constraints for implicit reads of non-idempotent regions.

Version 1.13.0

State

frozen

Changes

  • Redefined misa.MXL to be read-only, making MXLEN a constant.

  • Defined the misa.B field to reflect that the B extension has been implemented.

  • Defined the misa.V field to reflect that the V extension has been implemented.

  • Defined the RV32-only medelegh CSR.

  • Defined the misaligned atomicity granule PMA, superseding the proposed Zam extension.

  • Defined hardware error and software check exception codes.

  • Specified synchronization requirements when changing the PBMTE fields in menvcfg and henvcfg.

  • Exposed count-overflow interrupts to VS-mode via the Shlcofideleg extension.

  • Relaxed behavior of some HINTs when MXLEN > XLEN.

  • Transliterated the document from LaTeX into AsciiDoc.

  • Included all ratified extensions through March 2024.

  • Clarified that "platform- or custom-use" interrupts are actually "platform-use interrupts", where the platform can choose to make some custom.

  • Clarified semantics of explicit accesses to CSRs wider than XLEN bits.

  • Clarified that MXLEN≥SXLEN.

  • Clarified that WFI is not a HINT instruction.

  • Clarified that, for a given exception cause, xtval might sometimes be set to a nonzero value but sometimes not.

  • Clarified exception behavior of unimplemented or inaccessible CSRs.

  • Replaced the concept of vacant memory regions with inaccessible memory or I/O regions.

  • Clarified that timer and count-overflow interrupts' arrival in interrupt-pending registers is not immediate.

  • Clarified that MXR affects only explicit memory accesses.

Synopsis

This chapter describes the machine-level operations available in machine-mode (M-mode), which is the highest privilege mode in a RISC-V hart. M-mode is used for low-level access to a hardware platform and is the first mode entered at reset. M-mode can also be used to implement features that are too difficult or expensive to implement in hardware directly. The RISC-V machine-level ISA contains a common core that is extended depending on which other privilege levels are supported and other details of the hardware implementation. This chapter describes the RISC-V machine-level architecture, which contains a common core that is used with various supervisor-level address translation and protection schemes.

Instructions

The following instructions are affected by this extension:

mret

Machine-mode Return from Trap

wfi

Wait for interrupt

Parameters

This extension has the following implementation options (AKA parameters):

COUNTINHIBIT_EN

Type

array

Valid Values

32-element array where:
  [0] is boolean
  [1] is false
  [2] is boolean
additional items are:
  boolean

Description

Indicates which hardware performance monitor counters can be disabled from mcountinhibit.

An unimplemented counter cannot be specified, i.e., if HPM_COUNTER_EN[3] is false, it would be illegal to set COUNTINHIBIT_EN[3] to true.

COUNTINHIBIT_EN[1] can never be true, since it corresponds to mcountinhibit, which is always read-only-0.

COUNTINHIBIT_EN[3:31] must all be false if Zihpm is not implemented.

MARCHID_IMPLEMENTED

Type

boolean

Valid Values

boolean

Description

  • false: marchid is not implemented, and must be read-only-0

  • true: marchid is implemented, and the value is determined by ARCH_ID_VALUE

MIMPID_IMPLEMENTED

Type

boolean

Valid Values

boolean

Description

  • false: mimpid is not implemented, and must be read-only-0

  • true: mimpid is implemented, and the value is determined by IMP_ID_VALUE

MISALIGNED_LDST

Type

boolean

Valid Values

boolean

Description

Does the implementation perform non-atomic misaligned loads and stores to main memory (does not affect misaligned support to device memory)? If not, the implementation always throws a misaligned exception.

MISALIGNED_LDST_EXCEPTION_PRIORITY

Type

string

Valid Values

[low, high]

Description

The relative priority of a load/store/AMO exception vs. load/store/AMO page-fault or access-fault exceptions.

May be one of:

low

Misaligned load/store/AMO exceptions are always lower priority than load/store/AMO page-fault and access-fault exceptions.

high

Misaligned load/store/AMO exceptions are always higher priority than load/store/AMO page-fault and access-fault exceptions.

MISALIGNED_LDST_EXCEPTION_PRIORITY cannot be "high" when MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE is non-zero, since the atomicity of an access cannot be determined in that case until after address translation.

MISA_CSR_IMPLEMENTED

Type

boolean

Valid Values

boolean

Description

Options:

true

The misa CSR returns a non-zero value.

false

The misa CSR is read-only-0.

MTVAL_WIDTH

Type

integer when MXLEN == 32 integer when MXLEN == 64

Valid Values

0 to 32 when MXLEN == 32 0 to 64 when MXLEN == 64

Description

The number of implemented bits in the mtval CSR. This is the CSR that may be written when a trap is taken into M-mode with exception-specific information to assist software in handling the trap (e.g., address associated with exception).

Must be greater than or equal to max(PHYS_ADDR_WIDTH, VA_SIZE)

MTVEC_ACCESS

Type

string

Valid Values

[ro, rw]

Description

Options:

ro

mtvec is read-only.

rw

mtvec is read-write, but may not accept all values.

MTVEC_ILLEGAL_WRITE_BEHAVIOR

Type

string

Valid Values

[retain, custom]

Description

Options:

retain

When either mtvec.MODE or mtvec.BASE is illegal, mtvec will retain its curent value

custom

When either mtvec.MODE or mtvec.BASE is illegal, mtvec will obtain an unpredictable value

Other values may be added over time once other common behaviors are identified.

MTVEC_MODES

Type

array

Valid Values

1-element to 2-element array of [0, 1]

Description

Options:

0

Direct; All traps set pc to mtvec.BASE

1

Vectored; Asynchronous interrupts set pc to mtvec.BASE + 4 x cause.

If only one mode is given, mtvec.MODE is assumed to be read-only with that value. Otherwise, mtvec.MODE is read-write.

MXLEN

Type

integer

Valid Values

[32, 64]

Description

XLEN in machine mode, specified in bits

M_MODE_ENDIANNESS

Type

string

Valid Values

[little, big, dynamic]

Description

Options:

little

M-mode data is always little endian

big

M-mode data is always big endian

dynamic

M-mode data can be either little or big endian, depending on the CSR field mstatus.MBE

PHYS_ADDR_WIDTH

Type

integer when MXLEN == 32 integer when MXLEN == 64

Valid Values

1 to 34 when MXLEN == 32 1 to 64 when MXLEN == 64

Description

Implementation-defined size of the physical address space.

PMA_GRANULARITY

Type

integer

Valid Values

2 to 66

Description

Generally, for systems with an MMU, should not be smaller than 12, as that would preclude caching PMA results in the TLB along with virtual memory translations

PRECISE_SYNCHRONOUS_EXCEPTIONS

Type

boolean

Valid Values

boolean

Description

If false, any exception not otherwise mandated to precise (e.g., PMP violation) will cause execution to enter an unpredictable state.

REPORT_ENCODING_IN_MTVAL_ON_ILLEGAL_INSTRUCTION

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the encoding of an instruction causing an IllegalInstruction exception

  • false: mtval is written with 0 when an instruction causes an IllegalInstruction exception.

REPORT_VA_IN_MTVAL_ON_BREAKPOINT

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual PC of an EBREAK instruction (same information as mepc).

  • false: mtval is written with 0 on an EBREAK instruction.

Regardless, mtval is always written with a virtual PC when an external breakpoint is generated

REPORT_VA_IN_MTVAL_ON_INSTRUCTION_ACCESS_FAULT

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual address of a fetch causing the access fault

  • false: mtval is written with 0 when a fetch causes an access fault

REPORT_VA_IN_MTVAL_ON_INSTRUCTION_MISALIGNED

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual address of a trapping misaligned fetch

  • false: mtval is written with 0 when a misaligned fetch traps

REPORT_VA_IN_MTVAL_ON_LOAD_ACCESS_FAULT

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual address of a load causing the access fault

  • false: mtval is written with 0 when a load causes an access fault

REPORT_VA_IN_MTVAL_ON_LOAD_MISALIGNED

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual address of a trapping misaligned load.

  • false: mtval is written with 0 when a misaligned load traps.

REPORT_VA_IN_MTVAL_ON_STORE_AMO_ACCESS_FAULT

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual address of a store or AMO causing the access fault

  • false: mtval is written with 0 when a store or AMO causes an access fault

REPORT_VA_IN_MTVAL_ON_STORE_AMO_MISALIGNED

Type

boolean

Valid Values

boolean

Description

Options:

  • true: mtval is written with the virtual address of a trapping misaligned store or AMO.

  • false: mtval is written with 0 when a misaligned store or AMO traps.

TRAP_ON_EBREAK

Type

boolean

Valid Values

boolean

Description

The spec states that implementations may handle EBREAKs transparently without raising a trap, in which case the EEI must provide a builtin.

TRAP_ON_ECALL_FROM_M

Type

boolean

Valid Values

boolean

Description

The spec states that implementations may handle ECALLs transparently without raising a trap, in which case the EEI must provide a builtin.

TRAP_ON_ILLEGAL_WLRL

Type

boolean

Valid Values

boolean

Description

Options:

  • true: Writing an illegal value to a WLRL CSR field will cause an IllegalInstruction exception.

  • false: Writing an illegal value to a WLRL CSR field causes unpredictable behavior.

TRAP_ON_RESERVED_INSTRUCTION

Type

boolean

Valid Values

boolean

Description

Options:

  • true: Fetching an unimplemented and/or undefined instruction from the standard/reserved opcode space will cause an IllegalInstruction exception.

  • false: Fetching an unimplemented and/or undefined instruction from the standard/reserved opcose space causes unpredictable behavior.

TRAP_ON_RESERVED_INSTRUCTION may be false while TRAP_ON_UNIMPLEMENTED_INSTRUCTION is true when a custom instruction is implemented in the standard/reserved opcode space.

TRAP_ON_UNIMPLEMENTED_CSR

Type

boolean

Valid Values

boolean

Description

Options:

  • true: Accessing an unimplemented CSR (via a Zicsr instruction) will cause an IllegalInstruction exception.

  • false: Accessing an unimplemented CSR (via a Zicsr instruction) will cause unpredictable behavior.

TRAP_ON_UNIMPLEMENTED_INSTRUCTION

Type

boolean

Valid Values

boolean

Description

Options:

  • true: Fetching an unimplemented instruction will cause an IllegalInstruction exception.

  • false: Fetching an unimplemented instruction causes unpredictable behavior.

An unimplemented instruction is any instruction encoding that is not defined by the implementation. Custom instructions are considered implemented.

VENDOR_ID_BANK

Type

integer

Valid Values

25-bit integer

Description

Encodes the number of one-byte continuation codes in the Bank field of mvendorid.

iN JEDEC’s parlance, the bank number is one greater than the number of continuation codes; hence, the mvendorid Bank field encodes a value that is one less than the JEDEC bank number.

VENDOR_ID_OFFSET

Type

integer

Valid Values

7-bit integer

Description

Encodes the final byte of a JEDEC manufactor ID, discarding the parity bit.