mcause

Machine Cause

Reports the cause of the latest exception.

Attributes

CSR Address

0x342

Defining extension

Sm

Length

64-bit

Privilege Mode

M

Format

mcause format
Figure 1. mcause format

Field Summary

Name Location Type Reset Value

INT

63

RW-RH

0

CODE

62:0

RW-RH

0

Fields

INT

Location

mcause[63]

Description

Written by hardware when a trap is taken into M-mode.

When set, the last exception was caused by an asynchronous Interrupt.

mcause.INT is writable.

If mcause is written with an undefined cause (combination of mcause.INT and mcause.CODE), an Illegal Instruction exception occurs.

If mcause is written with an undefined cause (combination of mcause.INT and mcause.CODE), neither mcause.INT nor mcause.CODE are modified.

Type

RW-RH

Read-Write Restricted with Hardware update

Field is writable by software. Only certain values are legal. Writing an illegal value into the field is ignored, such that the field retains its prior state. Hardware also updates the field without an explicit software write.)

Reset value

0

Software write

This field has special behavior when written by software (e.g., through csrrw).

When software tries to write csr_value, the field will be written with the return value of the function below.

if (csr_value.INT == 1) {
  if (valid_interrupt_code?(csr_value.CODE)) {
    return 1;
  }
  return ILLEGAL_WLRL;
} else {
  if (valid_exception_code?(csr_value.CODE)) {
    return 1;
  }
  return ILLEGAL_WLRL;
}

CODE

Location

mcause[62:0]

Description

Written by hardware when a trap is taken into M-mode.

Holds the interrupt or exception code for the last taken trap.

mcause.CODE is writable.

If mcause is written with an undefined cause (combination of mcause.INT and mcause.CODE), an Illegal Instruction exception occurs.

If mcause is written with an undefined cause (combination of mcause.INT and mcause.CODE), neither mcause.INT nor mcause.CODE are modified.

Valid interrupt codes are:

0

InstructionAddressMisaligned

1

InstructionAccessFault

2

IllegalInstruction

3

Breakpoint

4

LoadAddressMisaligned

5

LoadAccessFault

6

StoreAmoAddressMisaligned

7

StoreAmoAccessFault

8

Ucall

9

Scall

10

VScall

11

Mcall

12

InstructionPageFault

13

LoadPageFault

15

StoreAmoPageFault

16

DoubleTrap

18

SoftwareCheck

19

HardwareError

20

InstructionGuestPageFault

21

LoadGuestPageFault

22

VirtualInstruction

23

StoreAmoGuestPageFault

+ Valid exception codes are:

0

InstructionAddressMisaligned

1

InstructionAccessFault

2

IllegalInstruction

3

Breakpoint

4

LoadAddressMisaligned

5

LoadAccessFault

6

StoreAmoAddressMisaligned

7

StoreAmoAccessFault

8

Ucall

9

Scall

10

VScall

11

Mcall

12

InstructionPageFault

13

LoadPageFault

15

StoreAmoPageFault

16

DoubleTrap

18

SoftwareCheck

19

HardwareError

20

InstructionGuestPageFault

21

LoadGuestPageFault

22

VirtualInstruction

23

StoreAmoGuestPageFault

Type

RW-RH

Read-Write Restricted with Hardware update

Field is writable by software. Only certain values are legal. Writing an illegal value into the field is ignored, such that the field retains its prior state. Hardware also updates the field without an explicit software write.)

Reset value

0

Software write

This field has special behavior when written by software (e.g., through csrrw).

When software tries to write csr_value, the field will be written with the return value of the function below.

if (csr_value.INT == 1) {
  if (valid_interrupt_code?(csr_value.CODE)) {
    return csr_value.CODE;
  }
  return ILLEGAL_WLRL;
} else {
  if (valid_exception_code?(csr_value.CODE)) {
    return csr_value.CODE;
  }
  return ILLEGAL_WLRL;
}