mtvec

Machine Trap Vector Control

Controls where traps jump.

Attributes

Requirement

Sm

Defining extensions

Sm

Machine mode

CSR Address

0x305

Length

* 32 when CSR[misa].MXL == 0 * 64 when CSR[misa].MXL == 1

Privilege Mode

M

Format

This CSR format changes dynamically.

mtvec Format when CSR[misa].MXL == 0
Figure 1. mtvec Format when CSR[misa].MXL == 0
mtvec Format when CSR[misa].MXL == 1
Figure 2. mtvec Format when CSR[misa].MXL == 1

Field Summary

Name Location Type Reset Value

mtvec.BASE

* 31:2 when CSR[misa].MXL == 0 * 63:2 when CSR[misa].MXL == 1

[when,"MTVEC_ACCESS == "ro""] RO

[when,"MTVEC_ACCESS != "ro""] RW-R

0

mtvec.MODE

1:0

[when,"(MTVEC_ACCESS == "ro")"] RO [when,"(MTVEC_ACCESS != "ro")"]

[when,"$array_size(MTVEC_MODES) == 1"] RO

[when,"$array_size(MTVEC_MODES) != 1"] RW-R

UNDEFINED_LEGAL

Fields

BASE

Location
  • 31:2 when CSR[misa].MXL == 0

  • 63:2 when CSR[misa].MXL == 1

Description

Bits [MXLEN-1:2] of the exception vector physical address for any trap taken in M-mode.

The implementation physical memory map may resitrict which values are legal in this field.

The address must be aligned to MTVEC_BASE_ALIGNMENT_DIRECT bytes when mtvec.MODE is Direct, and to MTVEC_BASE_ALIGNMENT_VECTORED bytes when mtvec.MODE is Vectored. A write that does not meet the alignment for the new mode is illegal, and follows MTVEC_ILLEGAL_WRITE_BEHAVIOR.

Type

RO

RW-R

Reset value

0

MODE

Location

1:0

Description

Vectoring mode for asynchronous interrupts.

0 - Direct, 1 - Vectored

When Direct, all synchronous exceptions and asynchronous interrupts jump to (mtvec.BASE << 2).

When Vectored, asynchronous interrupts jump to (mtvec.BASE << 2 + mcause.CODE*4) while synchronous exceptions continue to jump to (mtvec.BASE << 2).

Type

RO

RO

RW-R

Reset value

UNDEFINED_LEGAL

Software write

This CSR may store a value that is different from what software attempts to write.

When a software write occurs (e.g., through csrrw), the following determines the written value:

BASE = # BASE always holds a 4-byte aligned address. The alignment parameter of
# the new MODE can require more.
Bits<64> alignment = 4;
if (MTVEC_ACCESS == "rw") {
  # The alignment parameters are only defined when mtvec is writable
  if ($array_includes?(MTVEC_MODES, 0)) {
    if (csr_value.MODE == 0) {
      alignment = MTVEC_BASE_ALIGNMENT_DIRECT;
    }
  }
  if ($array_includes?(MTVEC_MODES, 1)) {
    if (csr_value.MODE == 1) {
      alignment = MTVEC_BASE_ALIGNMENT_VECTORED;
    }
  }
}
if ($array_includes?(MTVEC_MODES, csr_value.MODE) && (({csr_value.BASE, 2'b00} & (alignment - 1)) == 0)) {
  return csr_value.BASE;
}
if (MTVEC_ILLEGAL_WRITE_BEHAVIOR == "retain") {
  return CSR[mtvec].BASE;
} else if (MTVEC_ILLEGAL_WRITE_BEHAVIOR == "custom") {
  return UNDEFINED_LEGAL_DETERMINISTIC;
}
unreachable();

MODE = # The write is illegal as a whole if BASE does not meet the alignment of
# the new MODE, so MODE is only updated when BASE is also legal.
Bits<64> alignment = 4;
if (MTVEC_ACCESS == "rw") {
  # The alignment parameters are only defined when mtvec is writable
  if ($array_includes?(MTVEC_MODES, 0)) {
    if (csr_value.MODE == 0) {
      alignment = MTVEC_BASE_ALIGNMENT_DIRECT;
    }
  }
  if ($array_includes?(MTVEC_MODES, 1)) {
    if (csr_value.MODE == 1) {
      alignment = MTVEC_BASE_ALIGNMENT_VECTORED;
    }
  }
}
if ($array_includes?(MTVEC_MODES, csr_value.MODE) && (({csr_value.BASE, 2'b00} & (alignment - 1)) == 0)) {
  return csr_value.MODE;
}
if (MTVEC_ILLEGAL_WRITE_BEHAVIOR == "retain") {
  return CSR[mtvec].MODE;
} else if (MTVEC_ILLEGAL_WRITE_BEHAVIOR == "custom") {
  return UNDEFINED_LEGAL_DETERMINISTIC;
}
unreachable();