Files
RockOS/kernel/kmain.c

69 lines
1.3 KiB
C
Raw Normal View History

2026-06-14 00:34:11 -05:00
#include "multiboot.h"
#include "interrupts.h"
#include "gdt.h"
#include "scheduler.h"
#include "common.h"
#include <lib/print.h>
#include <lib/stream.h>
#include <lib/memory.h>
#include <memory/mm.h>
2026-06-09 23:16:25 -05:00
#include <drivers/iso/iso.h>
#include <drivers/ide/ide.h>
#include <drivers/pic/pic.h>
#include <drivers/ps2/ps2.h>
#include <drivers/pit/pit.h>
#include <drivers/vga/vga.h>
2026-06-11 23:23:39 -05:00
2026-06-14 00:34:11 -05:00
#include <stddef.h>
2026-06-11 23:23:39 -05:00
#include <stdint.h>
2026-06-15 18:09:04 -04:00
extern char __kernel_start;
extern char __kernel_end;
void first_task() {
kprintf("task started\n");
int i = 5;
while (i--) {
sleep(1000);
kprintf("task awake [%d]\n", i);
2026-06-16 18:44:31 -05:00
}
kprintf("exiting\n");
exit();
2026-06-16 18:44:31 -05:00
}
2026-06-14 00:34:11 -05:00
void kmain(uint32_t magic, multiboot_info* mbi) {
disable_interrupts();
2026-06-15 23:35:01 -05:00
if (!(mbi->flags & (1 << 6))) {
return;
}
2026-06-12 23:03:00 -04:00
vga_init();
2026-06-16 18:44:31 -05:00
2026-06-15 23:35:01 -05:00
uint32_t mmap_virtual_addr = mbi->mmap_addr + 0xC0000000;
init_pmm((void*)mmap_virtual_addr, mbi->mmap_length);
kprintf("memory detection complete. total free memory: %dMB\n", total_free_memory() / 1024 / 1024);
2026-06-15 23:35:01 -05:00
2026-06-12 23:03:00 -04:00
init_gdt();
2026-06-11 23:23:39 -05:00
init_idt();
2026-06-13 13:27:39 -05:00
init_pic();
init_pit();
2026-06-15 18:09:04 -04:00
init_page_tables();
kprintf("basic initializations complete\n");
disable_interrupts(); // just paranoid... do it again
init_scheduler();
enable_interrupts();
create_task((uint32_t)first_task, fetch_cr3());
while(1) {
sleep(5000);
kprintf("kernel awake\n");
}
2026-06-09 23:16:25 -05:00
}