Software APIs
rom_isrs.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include "sw/device/silicon_creator/rom/rom_isrs.h"
6 
9 #include "sw/device/silicon_creator/lib/error.h"
10 
13 static rom_error_t rom_irq_error(void) {
14  uint32_t mcause;
15  CSR_READ(CSR_REG_MCAUSE, &mcause);
16  // Shuffle the mcause bits into the uppermost byte of the word and report
17  // the cause as kErrorInterrupt.
18  // Based on the ibex verilog, it appears that the most significant bit
19  // indicates whether the cause is an exception (0) or external interrupt (1),
20  // and the 5 least significant bits indicate which exception/interrupt.
21  //
22  // Preserve the MSB and shift the 7 LSBs into the upper byte.
23  // (we preserve 7 instead of 5 because the verilog hardcodes the unused bits
24  // as zero and those would be the next bits used should the number of
25  // interrupt causes increase).
26  mcause = (mcause & 0x80000000) | ((mcause & 0x7f) << 24);
27  return kErrorInterrupt + mcause;
28 }
29 
30 void rom_interrupt_handler(void) {
31  register rom_error_t error asm("a0") = rom_irq_error();
32  asm volatile("tail shutdown_finalize;" ::"r"(error));
34 }
35 
36 // We only need a single handler for all ROM interrupts, but we want to
37 // keep distinct symbols to make writing tests easier. In the ROM,
38 // alias all interrupt handler symbols to the single handler.
39 OT_ALIAS("rom_interrupt_handler")
40 noreturn void rom_nmi_handler(void);