libdragon
Loading...
Searching...
No Matches
exception.h
Go to the documentation of this file.
1
9#ifndef __LIBDRAGON_EXCEPTION_H
10#define __LIBDRAGON_EXCEPTION_H
11
12#include <stdint.h>
13#include <stdbool.h>
14
32enum
33{
42};
43
47typedef enum {
48 EXCEPTION_CODE_INTERRUPT = 0,
49 EXCEPTION_CODE_TLB_MODIFICATION = 1,
50 EXCEPTION_CODE_TLB_LOAD_I_MISS = 2,
51 EXCEPTION_CODE_TLB_STORE_MISS = 3,
52 EXCEPTION_CODE_LOAD_I_ADDRESS_ERROR = 4,
53 EXCEPTION_CODE_STORE_ADDRESS_ERROR = 5,
54 EXCEPTION_CODE_I_BUS_ERROR = 6,
55 EXCEPTION_CODE_D_BUS_ERROR = 7,
56 EXCEPTION_CODE_SYS_CALL = 8,
57 EXCEPTION_CODE_BREAKPOINT = 9,
58 EXCEPTION_CODE_RESERVED_INSTRUCTION = 10,
59 EXCEPTION_CODE_COPROCESSOR_UNUSABLE = 11,
60 EXCEPTION_CODE_ARITHMETIC_OVERFLOW = 12,
61 EXCEPTION_CODE_TRAP = 13,
62 EXCEPTION_CODE_FLOATING_POINT = 15,
63 EXCEPTION_CODE_WATCH = 23,
65
71typedef struct __attribute__((packed))
72{
74 union {
75 uint64_t gpr[32];
76 struct {
77 uint64_t zr, at, v0, v1, a0, a1, a2, a3;
78 uint64_t t0, t1, t2, t3, t4, t5, t6, t7;
79 uint64_t s0, s1, s2, s3, s4, s5, s6, s7;
80 uint64_t t8, t9, k0, k1, gp, sp, fp, ra;
81 };
82 };
84 uint64_t hi;
86 uint64_t lo;
88 uint32_t sr;
90 uint32_t cr;
101 uint32_t epc;
103 uint32_t fc31;
105 uint64_t fpr[32];
107
108/* Make sure the structure has the right size. Please keep this in sync with inthandler.S */
109_Static_assert(sizeof(reg_block_t) == 544, "invalid reg_block_t size -- this must match inthandler.S");
110
114typedef struct
115{
120 int32_t type;
126 const char* info;
130
133#ifdef __cplusplus
134extern "C" {
135#endif
136
145typedef void (*exception_handler_t)(exception_t *exc);
146
155typedef void (*syscall_handler_t)(exception_t *exc, uint32_t code);
156
188
197
203inline bool exception_is_running(void)
204{
205 extern void* interrupt_exception_frame;
206 return interrupt_exception_frame != 0;
207}
208
232void register_syscall_handler( syscall_handler_t handler, uint32_t first_code, uint32_t last_code );
233
234#ifdef __cplusplus
235}
236#endif
237
238#endif
exception_handler_t register_exception_handler(exception_handler_t cb)
Register an exception handler to handle exceptions.
Definition exception.c:42
void exception_default_handler(exception_t *ex)
Default exception handler.
Definition exception.c:212
void(* exception_handler_t)(exception_t *exc)
Generic exception handler.
Definition exception.h:145
void register_syscall_handler(syscall_handler_t handler, uint32_t first_code, uint32_t last_code)
Register a handler that will be called when a syscall exception.
Definition exception.c:474
bool exception_is_running(void)
Check if we are currently running within an exception handler.
Definition exception.h:203
void(* syscall_handler_t)(exception_t *exc, uint32_t code)
Syscall handler.
Definition exception.h:155
const char * info
String information of exception.
Definition exception.h:126
uint32_t sr
SR.
Definition exception.h:88
uint32_t epc
represents EPC - COP0 register $14
Definition exception.h:101
uint64_t hi
HI.
Definition exception.h:84
reg_block_t * regs
Registers at point of exception.
Definition exception.h:128
uint32_t cr
CR (NOTE: can't modify this from an exception handler)
Definition exception.h:90
uint32_t fc31
FC31.
Definition exception.h:103
uint64_t lo
LO.
Definition exception.h:86
exception_code_t code
Underlying exception code.
Definition exception.h:124
int32_t type
Exception type.
Definition exception.h:120
exception_code_t
Exception codes.
Definition exception.h:47
@ EXCEPTION_TYPE_CRITICAL
Critical exception.
Definition exception.h:39
@ EXCEPTION_TYPE_SYSCALL
Syscall exception.
Definition exception.h:41
@ EXCEPTION_TYPE_RESET
Reset exception.
Definition exception.h:37
@ EXCEPTION_TYPE_UNKNOWN
Unknown exception.
Definition exception.h:35
Structure representing an exception.
Definition exception.h:115
Structure representing a register block.
Definition exception.h:72