-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexception.h
58 lines (50 loc) · 2.02 KB
/
exception.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
#include <stdint.h>
#include "csr.h"
//-----------------------------------------------------------------
// Defines:
//-----------------------------------------------------------------
#define REG_RA 1
#define REG_SP 2
#define REG_ARG0 10
#define REG_RET REG_ARG0
#define NUM_GP_REG 32
#define NUM_CSR_REG 3
#define CAUSE_MISALIGNED_FETCH 0
#define CAUSE_FAULT_FETCH 1
#define CAUSE_ILLEGAL_INSTRUCTION 2
#define CAUSE_BREAKPOINT 3
#define CAUSE_MISALIGNED_LOAD 4
#define CAUSE_FAULT_LOAD 5
#define CAUSE_MISALIGNED_STORE 6
#define CAUSE_FAULT_STORE 7
#define CAUSE_ECALL_U 8
#define CAUSE_ECALL_S 9
#define CAUSE_ECALL_M 11
#define CAUSE_PAGE_FAULT_INST 12
#define CAUSE_PAGE_FAULT_LOAD 13
#define CAUSE_PAGE_FAULT_STORE 15
#define CAUSE_INTERRUPT (1 << 31)
//-----------------------------------------------------------------
// Types:
//-----------------------------------------------------------------
struct irq_context
{
uint32_t pc;
uint32_t status;
uint32_t cause;
uint32_t reg[NUM_GP_REG];
};
typedef struct irq_context *(*fp_exception)(struct irq_context *ctx);
typedef struct irq_context *(*fp_irq)(struct irq_context *ctx);
typedef struct irq_context *(*fp_syscall)(struct irq_context *ctx);
//-----------------------------------------------------------------
// Prototypes:
//-----------------------------------------------------------------
struct irq_context * exception_handler(struct irq_context *ctx);
void exception_set_irq_handler(fp_irq irq_handler);
void exception_set_syscall_handler(fp_syscall syscall_handler);
void exception_set_handler(int cause, fp_exception handler);
extern void _exit(int arg);
#endif