Software APIs
ottf_isrs.h
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 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_ISRS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_ISRS_H_
7 #include <stdint.h>
8 
10 
11 /**
12  * OTTF global PLIC interface.
13  */
14 extern dif_rv_plic_t ottf_plic;
15 
16 /**
17  * OTTF fault printing function.
18  *
19  * Called by exception handlers to print a fault code for unhandled
20  * exceptions or interrupts. The printed message will be in the standard OTTF
21  * form that can be detected by test automation.
22  *
23  * @param reason A string describing the fault reason.
24  * @param mcause The value of the mcause register for this fault.
25  */
26 void ottf_generic_fault_print(uint32_t *exc_info, const char *reason,
27  uint32_t mcause);
28 
29 /**
30  * OTTF exception handler.
31  *
32  * Called by the asm exception handler `handler_exception` subroutine.
33  *
34  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
35  * overridden at link-time by providing an additional non-weak definition.
36  */
37 void ottf_exception_handler(uint32_t *exc_info);
38 
39 /**
40  * OTTF instruction misaligned fault handler.
41  *
42  * Called by default implementation of `ottf_exception_handler`. If that
43  * function is overridden, this function may not be called.
44  *
45  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
46  * overridden at link-time by providing an additional non-weak definition.
47  */
48 void ottf_instr_misaligned_fault_handler(uint32_t *exc_info);
49 
50 /**
51  * OTTF instruction access fault handler.
52  *
53  * Called by default implementation of `ottf_exception_handler`. If that
54  * function is overridden, this function may not be called.
55  *
56  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
57  * overridden at link-time by providing an additional non-weak definition.
58  */
59 void ottf_instr_access_fault_handler(uint32_t *exc_info);
60 
61 /**
62  * OTTF illegal instruction fault handler.
63  *
64  * Called by default implementation of `ottf_exception_handler`. If that
65  * function is overridden, this function may not be called.
66  *
67  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
68  * overridden at link-time by providing an additional non-weak definition.
69  */
70 void ottf_illegal_instr_fault_handler(uint32_t *exc_info);
71 
72 /**
73  * OTTF breakpoint handler.
74  *
75  * Called by default implementation of `ottf_exception_handler`. If that
76  * function is overridden, this function may not be called.
77  *
78  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
79  * overridden at link-time by providing an additional non-weak definition.
80  */
81 void ottf_breakpoint_handler(uint32_t *exc_info);
82 
83 /**
84  * OTTF load/store fault handler.
85  *
86  * Called by default implementation of `ottf_exception_handler`. If that
87  * function is overridden, this function may not be called.
88  *
89  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
90  * overridden at link-time by providing an additional non-weak definition.
91  */
92 void ottf_load_store_fault_handler(uint32_t *exc_info);
93 
94 /**
95  * OTTF machine-mode environment call handler.
96  *
97  * Called by default implementation of `ottf_exception_handler`. If that
98  * function is overridden, this function may not be called.
99  *
100  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
101  * overridden at link-time by providing an additional non-weak definition.
102  */
103 void ottf_machine_ecall_handler(uint32_t *exc_info);
104 
105 /**
106  * OTTF user-mode environment call handler.
107  *
108  * Called by default implementation of `ottf_exception_handler`. If that
109  * function is overridden, this function may not be called.
110  *
111  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
112  * overridden at link-time by providing an additional non-weak definition.
113  */
114 void ottf_user_ecall_handler(uint32_t *exc_info);
115 
116 /**
117  * OTTF software IRQ handler.
118  *
119  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
120  * overridden at link-time by providing an additional non-weak definition.
121  */
122 void ottf_software_isr(uint32_t *exc_info);
123 
124 /**
125  * OTTF timer IRQ handler.
126  *
127  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
128  * overridden at link-time by providing an additional non-weak definition.
129  */
130 void ottf_timer_isr(uint32_t *exc_info);
131 
132 /**
133  * OTTF external IRQ handler.
134  *
135  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
136  * overridden at link-time by providing an additional non-weak definition.
137  */
138 void ottf_external_isr(uint32_t *exc_info);
139 
140 /**
141  * Test external IRQ handler.
142  *
143  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
144  * overridden at link-time by providing an additional non-weak definition.
145  *
146  * Overriding this function is the preferred way for device tests to handle
147  * IRQs, unless they really need to bypass the OTTF entirely.
148  *
149  * Before calling this function, `ottf_external_isr` will claim the interrupt
150  * at the PLIC and obtain the corresponding instance ID using the DT.
151  * If this function returns true, `ottf_external_isr` will complete the
152  * interrupt at the PLIC. If this function returns false, the OTTF will try
153  * to handle this IRQ for its internal functions (e.g. ottf_console). If that's
154  * not possible, a fatal error will occur.
155  *
156  * NOTE When overriding `ottf_handle_irq`, the code does not need to call
157  * `ottf_console_flow_control_isr`, this will be done automatically if the
158  * function returns false.
159  *
160  * @param inst_id The device instance that produced the interrupt.
161  * @param plid_id The PLIC IRQ ID to handle.
162  * @returns Whether the IRQ was handled.
163  */
164 bool ottf_handle_irq(uint32_t *exc_info, dt_instance_id_t inst_id,
165  dif_rv_plic_irq_id_t plic_id);
166 
167 /**
168  * OTTF external NMI internal IRQ handler.
169  *
170  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
171  * overridden at link-time by providing an additional non-weak definition.
172  */
173 void ottf_external_nmi_handler(uint32_t *exc_info);
174 
175 /**
176  * OTTF load integrity internal IRQ handler.
177  *
178  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
179  * overridden at link-time by providing an additional non-weak definition.
180  */
181 void ottf_load_integrity_error_handler(uint32_t *exc_info);
182 
183 /**
184  * OTTF internal IRQ handler.
185  *
186  * `ottf_isrs.c` provides a weak definition of this symbol, which can be
187  * overridden at link-time by providing an additional non-weak definition.
188  */
189 void ottf_internal_isr(uint32_t *exc_info);
190 
191 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_ISRS_H_