Files
osc2025/kernel/main.c
2025-04-08 07:01:24 +08:00

124 lines
2.2 KiB
C

#include <logger.h>
#include <timer.h>
#include <kmalloc.h>
#include <uart.h>
#include <dtb.h>
#include <initrd.h>
#include <mman.h>
#include <shell.h>
#include <vector.h>
#include <utils.h>
#include <exception.h>
#include <interrupt.h>
void init(void *dtb, file_node_t **initrd_root)
{
init_exception();
init_interrupt();
// UART
uart_init();
// Device tree
DEBUG_DTB(dtb);
dtb_start = dtb;
vector_t *dtb_struct_cbs = make_vector(0);
VEC_PUSH(dtb_struct_cbs, &initrd_dtb_cb);
VEC_PUSH(dtb_struct_cbs, &mman_dtb_memory_cb);
fdt_traverse(dtb_struct_cbs);
DEBUG_DTB("device tree parse done");
// Initramfs
DEBUG_INITRD(initrd_start);
*initrd_root = initrd_init();
// Memory (Buddy system)
mman_init();
}
static inline
void _print_time(uint64_t)
{
uint64_t cntpct_el0, cntfrq_el0;
R_SYSREG(cntpct_el0, cntpct_el0);
R_SYSREG(cntfrq_el0, cntfrq_el0);
DEBUG_EXCEP(cntpct_el0 / cntpct_el0);
}
void main(void *dtb)
{
file_node_t *initrd_root = 0x0;
init(dtb, &initrd_root);
LOG("system booting in");
_print_time(0x0);
uint64_t cntpct_el0, cntfrq_el0;
R_SYSREG(cntpct_el0, cntpct_el0);
R_SYSREG(cntfrq_el0, cntfrq_el0);
task_t task = {
.firing_tick = cntpct_el0 + 2 * cntfrq_el0,
.interval = 2 * cntfrq_el0,
.repeat = 1,
.func = _print_time,
.param = 0x0,
};
add_task(task);
uint64_t el;
R_SYSREG(el, CurrentEL);
INFOR(el);
void *page1 = allocate_page(1);
INFOR(page1);
void *page2 = allocate_page(2);
INFOR(page2);
void *page4 = allocate_page(4);
INFOR(page4);
void *page16 = allocate_page(16);
INFOR(page16);
free_page(page1);
free_page(page2);
free_page(page4);
free_page(page16);
void *page32 = allocate_page(32);
INFOR(page32);
page1 = allocate_page(1);
INFOR(page1);
free_page(page1);
void *kmalloc8 = kmalloc(8);
INFOR(kmalloc8);
kfree(kmalloc8);
kmalloc8 = kmalloc(8);
INFOR(kmalloc8);
kfree(kmalloc8);
void *kmalloc7k = kmalloc(7 * (1 << 10));
INFOR(kmalloc7k);
void *kmalloc8k = kmalloc(1 << 13);
INFOR(kmalloc8k);
kfree(kmalloc7k);
kfree(kmalloc8k);
page1 = allocate_page(1);
INFOR(page1);
int shell_cont = 1;
while (shell_cont) {
shell_cont = shell(initrd_root);
}
}