-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.h
109 lines (92 loc) · 1.65 KB
/
kernel.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef __KERNEL_H__
#define __KERNEL_H__
#include"common.h"
struct sbiret
{
long error;
long value;
};
struct trap_frame
{
uint32_t ra;
uint32_t gp;
uint32_t tp;
uint32_t t0;
uint32_t t1;
uint32_t t2;
uint32_t t3;
uint32_t t4;
uint32_t t5;
uint32_t t6;
uint32_t a0;
uint32_t a1;
uint32_t a2;
uint32_t a3;
uint32_t a4;
uint32_t a5;
uint32_t a6;
uint32_t a7;
uint32_t s0;
uint32_t s1;
uint32_t s2;
uint32_t s3;
uint32_t s4;
uint32_t s5;
uint32_t s6;
uint32_t s7;
uint32_t s8;
uint32_t s9;
uint32_t s10;
uint32_t s11;
uint32_t sp;
}__attribute__((packed));
#define PROCS_MAX 8
#define PROC_UNUSED 0
#define PROC_RUNNABLE 1
#define PROC_EXITED 2
struct process
{
pid_t pid;
int state;
vaddr_t sp;
uint32_t* page_table;
uint8_t stack[8192];
};
#define SATP_SV32 (1u << 31)
#define PAGE_V (1 << 0)
#define PAGE_R (1 << 1)
#define PAGE_W (1 << 2)
#define PAGE_X (1 << 3)
#define PAGE_U (1 << 4)
#define SSTATUS_SPIE (1 << 5)
#define SSTATUS_SUM (1 << 18)
#define SCAUSE_ECALL 8
#define USER_BASE 0x10000000
paddr_t alloc_pages(uint32_t n);
#define PANIC(fmt, ...) \
do{ \
printf("PANIC: %s:%d: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
for(;;); \
}while(0)
#define ASSERT(exp) \
do{ \
if((exp) == 0) \
PANIC("Assertion failed: " #exp); \
else ; \
}while(0)
#define ASSERT_EQ(LVAL, RVAL) \
do{ \
ASSERT((LVAL) == (RVAL)); \
}while(0)
#define READ_CSR(reg) \
({ \
unsigned long __tmp; \
__asm__ __volatile__("csrr %0, " #reg : "=r"(__tmp)); \
__tmp; \
})
#define WRITE_CSR(reg, value) \
do { \
uint32_t __tmp = (value); \
__asm__ __volatile__("csrw " #reg ", %0" :: "r"(__tmp)); \
} while(0)
#endif