summaryrefslogtreecommitdiff
path: root/src/kernel/main.cc
blob: beda9dca749146d399743c7b741b1b92cf0e6e92 (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
#include "drivers/uart.h"
#include "kernel/pmm.h"
#include "kernel/mm.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: ");
    print_hex((uint64_t)p1);
    Drivers::uart_puts("\n");

    Drivers::uart_puts("Allocated Page 2: ");
    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: ");
    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");

    while (1)
    {

    }
}