blob: 014b4d39c9d377478d557faff0ef5f65b254b293 [file] [log] [blame]
Tobias Wölfeld839d812019-10-04 12:50:12 +02001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
Miguel Young de la Sota960fd8e2020-01-14 13:52:13 -05005#ifndef OPENTITAN_SW_DEVICE_LIB_HANDLER_H_
6#define OPENTITAN_SW_DEVICE_LIB_HANDLER_H_
Timothy Chen25eb4802019-09-20 17:23:26 -07007
8typedef enum exc_id {
9 kInstMisa = 0,
10 kInstAccFault = 1,
11 kInstIllegalFault = 2,
12 kBkpt = 3,
13 kLoadAccFault = 5,
14 kStrAccFault = 7,
15 kECall = 11,
16 kIdMax = 31
17} exc_id_t;
18
Sam Elliott2463e2d2019-12-11 17:52:23 +000019// The RISC-V interrupt vector will not include the addresses of the handlers,
20// instead, it includes (uncompressed) instructions. Thus the interrupt vector
21// will include `j <interrupt handler name>` for each handler.
22//
23// The only requirement on the symbol in the jump is that it must be correctly
24// aligned. If the processor supports the C extension, this can be 2-byte
25// aligned, but 4-byte aligned is compatible with all RISC-V processors.
26//
27// If the processor is not using interrupt vectoring, then there will be a
28// single address where interrupts jump to, which will either contain a function
29// (which will need to be aligned), or will contain a jump to a function, again
30// which will need to be aligned.
31//
32// You only need to use this ABI for handlers that are the first function called
33// in an interrupt handler. Subsequent functions can just use the regular RISC-V
34// calling convention.
35#define INTERRUPT_HANDLER_ABI __attribute__((aligned(4), interrupt))
36
37// The following `handler_*` functions have weak definitions, provided by
38// `handler.c`. This weak definition can be overriden at link-time by providing
39// an additional non-weak definition of each function. Executables and libraries
40// must not contain more than one weak definition of the same symbol.
41
42/**
43 * Default exception handler.
44 *
45 * `handler.c` provides a weak definition of this symbol, which can be overriden
46 * at link-time by providing an additional non-weak definition.
47 */
48INTERRUPT_HANDLER_ABI void handler_exception(void);
49
50/**
51 * SW IRQ handler.
52 *
53 * `handler.c` provides a weak definition of this symbol, which can be overriden
54 * at link-time by providing an additional non-weak definition.
55 */
56INTERRUPT_HANDLER_ABI void handler_irq_software(void);
57
58/**
59 * Timer IRQ handler.
60 *
61 * `handler.c` provides a weak definition of this symbol, which can be overriden
62 * at link-time by providing an additional non-weak definition.
63 */
64INTERRUPT_HANDLER_ABI void handler_irq_timer(void);
65
66/**
67 * external IRQ handler.
68 *
69 * `handler.c` provides a weak definition of this symbol, which can be overriden
70 * at link-time by providing an additional non-weak definition.
71 */
72INTERRUPT_HANDLER_ABI void handler_irq_external(void);
73
74/**
75 * Instruction access fault.
76 *
77 * Called by default implementation of `handler_exception`. If that function is
78 * overriden, this function may not be called.
79 *
80 * `handler.c` provides a weak definition of this symbol, which can be overriden
81 * at link-time by providing an additional non-weak definition.
82 */
83void handler_instr_acc_fault(void);
84
85/**
86 * Illegal Instruction fault.
87 *
88 * Called by default implementation of `handler_exception`. If that function is
89 * overriden, this function may not be called.
90 *
91 * `handler.c` provides a weak definition of this symbol, which can be overriden
92 * at link-time by providing an additional non-weak definition.
93 */
94void handler_instr_ill_fault(void);
95
96/**
97 * Breakpoint handler.
98 *
99 * Called by default implementation of `handler_exception`. If that function is
100 * overriden, this function may not be called.
101 *
102 * `handler.c` provides a weak definition of this symbol, which can be overriden
103 * at link-time by providing an additional non-weak definition.
104 */
105void handler_bkpt(void);
106
107/**
108 * Load store unit fault.
109 *
110 * Called by default implementation of `handler_exception`. If that function is
111 * overriden, this function may not be called.
112 *
113 * `handler.c` provides a weak definition of this symbol, which can be overriden
114 * at link-time by providing an additional non-weak definition.
115 */
116void handler_lsu_fault(void);
117
118/**
119 * Exception call handler.
120 *
121 * Called by default implementation of `handler_exception`. If that function is
122 * overriden, this function may not be called.
123 *
124 * `handler.c` provides a weak definition of this symbol, which can be overriden
125 * at link-time by providing an additional non-weak definition.
126 */
127void handler_ecall(void);
128
Miguel Young de la Sota960fd8e2020-01-14 13:52:13 -0500129#endif // OPENTITAN_SW_DEVICE_LIB_HANDLER_H_