-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.cpp
80 lines (62 loc) · 1.78 KB
/
kernel.cpp
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
#include <uart.h>
#include <mem.h>
#include <util.h>
#include <exception.h>
#include <larchintrin.h>
#include <timer.h>
#include <lwp.h>
#include <sdcard.h>
#include <fat32.h>
const u64 vaddrEnd = 1ull << (getPartical(getCPUCFG(1), 19, 12) - 1);
UART uPut((u8 *)(0x800000001ff40800llu));
Exception SysException;
Timer SysTimer;
PageAllocator pageAllocator;
SlabNodeArea slabNodeZone;
SlabNodeAllocator slabNodeAllocator;
SlabArea defaultSlabZone;
SlabAllocator defaultSlabAllocator;
ProcessController processController;
SDCard sdcard((void*)0x800000001ff64000, (void*) 0x800000001fe10c30);
extern "C" {
void handleDefaultException() {
SysException.HandleDefaultException();
}
void handleTLBException() {
SysException.HandleTLBException();
}
void handleMachineError() {
SysException.HandleMachineError();
}
}
inline void invokeInit() {
using func_ptr = void (*) (void);
extern char __init_array_start, __init_array_end;
for (func_ptr *func = (func_ptr *) &__init_array_start; func != (func_ptr *) &__init_array_end; ++func) {
if (func) (*func)();
}
}
inline void initMem() {
__csrwr_d(0x13E4D52C, 0x1C);
__csrwr_d(0x267, 0x1D);
__csrwr_d(0xC, 0x1E);
}
inline void initException() {
extern void *HandleDefaultExceptionEntry, *HandleMachineErrorEntry, *HandleTLBExceptionEntry;
__csrwr_d((u64)&HandleDefaultExceptionEntry, 0xC);
__csrwr_d((u64)&HandleTLBExceptionEntry, 0x88);
__csrwr_d((u64)&HandleMachineErrorEntry, 0x93);
SysException.IntOn();
}
extern "C" void KernelMain() {
invokeInit();
initMem();
initException();
fat32_mount();
ELFProgram program("open");
program.CreateProcess();
SysTimer.TimerOn();
extern void StartProcess();
StartProcess();
while (1);
}