blob: 2fa10a290f3307aaff5ddc0adf9985a180e9f02a (
plain)
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
|
#include "drivers/uart.h"
#include "kernel/pmm.h"
#include "kernel/mm.h"
#include "kernel/trap.h"
// void print_hex(uint64_t val)
// {
// char buf[17];
// buf[16] = 0;
// const char *digits = "0123456789ABCDEF";
// for (int i = 15; i >= 0; i--)
// {
// buf[i] = digits[val & 0xf];
// val >>= 4;
// }
// Drivers::uart_puts("0x");
// Drivers::uart_puts(buf);
// }
extern "C" void kernel_main()
{
Drivers::uart_init();
Drivers::uart_puts("\n[Modern DOS Kernel] Booted in S-Mode.\n");
Drivers::uart_puts("2025 Richard Qin\n");
Drivers::uart_puts("\n");
Drivers::uart_puts("[Kernel] Initializing PMM...\n");
PMM::init();
Drivers::uart_puts("[Kernel] PMM initialized.\n");
Drivers::uart_puts("[Kernel] Testing alloc_page...\n");
void *p1 = PMM::alloc_page();
void *p2 = PMM::alloc_page();
Drivers::uart_puts("Allocated Page 1: ");
Drivers::print_hex((uint64_t)p1);
Drivers::uart_puts("\n");
Drivers::uart_puts("Allocated Page 2: ");
Drivers::print_hex((uint64_t)p2);
Drivers::uart_puts("\n");
Drivers::uart_puts("[Kernel] Freeing Page 1...\n");
PMM::free_page(p1);
void *p3 = PMM::alloc_page();
Drivers::uart_puts("Allocated Page 3: ");
Drivers::print_hex((uint64_t)p3);
Drivers::uart_puts("\n");
if (p3 == p1)
{
Drivers::uart_puts("[Test Passed] Reuse freed memory successfully.\n");
}
else
{
Drivers::uart_puts("[Test Failed] Memory leak or logic error.\n");
}
VM::kvminit();
Drivers::uart_puts("[Boot] Kernel page table created.\n");
VM::kvminithart();
Drivers::uart_puts("[Boot] MMU ENABLED! We are now using virtual addresses.\n");
Trap::init();
Drivers::uart_puts("[Boot] Trap Handler Installed.\n");
Drivers::uart_puts("\n[Test] Triggering Page Fault by reading 0x0...\n");
volatile int *p = (int *)0x0;
int crash = *p;
(void)crash;
Drivers::uart_puts("[Test Failed] Shuold not reach here.\n");
Drivers::uart_puts("\n[Test] Triggering Store Fault on Text Segment...\n");
*(int*)0x80000000 = 1234;
while (1)
{
}
}
|