libdragon
exception.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_EXCEPTION_H
7#define __LIBDRAGON_EXCEPTION_H
8
9#include <stdint.h>
10
19enum
20{
29};
30
34typedef enum {
35 EXCEPTION_CODE_INTERRUPT = 0,
36 EXCEPTION_CODE_TLB_MODIFICATION = 1,
37 EXCEPTION_CODE_TLB_LOAD_I_MISS = 2,
38 EXCEPTION_CODE_TLB_STORE_MISS = 3,
39 EXCEPTION_CODE_LOAD_I_ADDRESS_ERROR = 4,
40 EXCEPTION_CODE_STORE_ADDRESS_ERROR = 5,
41 EXCEPTION_CODE_I_BUS_ERROR = 6,
42 EXCEPTION_CODE_D_BUS_ERROR = 7,
43 EXCEPTION_CODE_SYS_CALL = 8,
44 EXCEPTION_CODE_BREAKPOINT = 9,
45 EXCEPTION_CODE_RESERVED_INSTRUCTION = 10,
46 EXCEPTION_CODE_COPROCESSOR_UNUSABLE = 11,
47 EXCEPTION_CODE_ARITHMETIC_OVERFLOW = 12,
48 EXCEPTION_CODE_TRAP = 13,
49 EXCEPTION_CODE_FLOATING_POINT = 15,
50 EXCEPTION_CODE_WATCH = 23,
52
58typedef struct __attribute__((packed))
59{
61 uint64_t gpr[32];
63 uint64_t hi;
65 uint64_t lo;
67 uint32_t sr;
69 uint32_t cr;
80 uint32_t epc;
82 uint32_t fc31;
84 uint64_t fpr[32];
86
87/* Make sure the structure has the right size. Please keep this in sync with inthandler.S */
88_Static_assert(sizeof(reg_block_t) == 544, "invalid reg_block_t size -- this must match inthandler.S");
89
93typedef struct
94{
99 int32_t type;
105 const char* info;
109
112#ifdef __cplusplus
113extern "C" {
114#endif
115
124typedef void (*exception_handler_t)(exception_t *exc);
125
134typedef void (*syscall_handler_t)(exception_t *exc, uint32_t code);
135
138
139void register_syscall_handler( syscall_handler_t cb, uint32_t first_code, uint32_t last_code );
140
141#ifdef __cplusplus
142}
143#endif
144
145#endif
void(* exception_handler_t)(exception_t *exc)
Generic exception handler.
Definition: exception.h:124
void(* syscall_handler_t)(exception_t *exc, uint32_t code)
Syscall handler.
Definition: exception.h:134
const char * info
String information of exception.
Definition: exception.h:105
uint32_t sr
SR.
Definition: exception.h:67
uint32_t epc
represents EPC - COP0 register $14
Definition: exception.h:80
uint64_t hi
HI.
Definition: exception.h:63
reg_block_t * regs
Registers at point of exception.
Definition: exception.h:107
uint32_t cr
CR (NOTE: can't modify this from an exception handler)
Definition: exception.h:69
uint32_t fc31
FC31.
Definition: exception.h:82
uint64_t lo
LO.
Definition: exception.h:65
exception_code_t code
Underlying exception code.
Definition: exception.h:103
int32_t type
Exception type.
Definition: exception.h:99
exception_handler_t register_exception_handler(exception_handler_t cb)
Register an exception handler to handle exceptions.
Definition: exception.c:84
void exception_default_handler(exception_t *ex)
Default exception handler.
Definition: exception.c:244
exception_code_t
Exception codes.
Definition: exception.h:34
void register_syscall_handler(syscall_handler_t cb, uint32_t first_code, uint32_t last_code)
Register a handler that will be called when a syscall exception.
Definition: exception.c:468
@ EXCEPTION_TYPE_CRITICAL
Critical exception.
Definition: exception.h:26
@ EXCEPTION_TYPE_SYSCALL
Syscall exception.
Definition: exception.h:28
@ EXCEPTION_TYPE_RESET
Reset exception.
Definition: exception.h:24
@ EXCEPTION_TYPE_UNKNOWN
Unknown exception.
Definition: exception.h:22
Structure representing an exception.
Definition: exception.h:94
Structure representing a register block.
Definition: exception.h:59