2026-06-14 00:34:11 -05:00
|
|
|
#include "multiboot.h"
|
2026-06-26 20:05:01 -05:00
|
|
|
#include "interrupts.h"
|
|
|
|
|
#include "gdt.h"
|
|
|
|
|
#include "scheduler.h"
|
2026-06-28 17:58:58 -05:00
|
|
|
#include "common.h"
|
2026-06-24 16:47:22 -05:00
|
|
|
|
2026-06-10 18:28:33 -05:00
|
|
|
#include <lib/print.h>
|
|
|
|
|
#include <lib/stream.h>
|
2026-06-24 16:47:22 -05:00
|
|
|
#include <lib/memory.h>
|
|
|
|
|
|
2026-06-26 20:05:01 -05:00
|
|
|
#include <memory/mm.h>
|
2026-06-09 23:16:25 -05:00
|
|
|
|
2026-06-26 20:05:01 -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;
|
|
|
|
|
|
2026-06-28 17:58:58 -05:00
|
|
|
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
|
|
|
}
|
2026-06-28 17:58:58 -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) {
|
2026-06-28 17:58:58 -05:00
|
|
|
disable_interrupts();
|
2026-06-15 23:35:01 -05:00
|
|
|
if (!(mbi->flags & (1 << 6))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-06-12 23:03:00 -04:00
|
|
|
|
2026-06-26 20:05:01 -05: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);
|
2026-06-26 20:05:01 -05:00
|
|
|
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-26 20:05:01 -05:00
|
|
|
|
2026-06-15 18:09:04 -04:00
|
|
|
init_page_tables();
|
2026-06-24 16:47:22 -05:00
|
|
|
|
2026-06-26 20:05:01 -05:00
|
|
|
kprintf("basic initializations complete\n");
|
2026-06-16 10:04:49 -04:00
|
|
|
|
2026-06-28 17:58:58 -05:00
|
|
|
disable_interrupts(); // just paranoid... do it again
|
2026-06-26 20:05:01 -05:00
|
|
|
init_scheduler();
|
|
|
|
|
enable_interrupts();
|
2026-06-24 16:47:22 -05:00
|
|
|
|
2026-06-28 17:58:58 -05:00
|
|
|
create_task((uint32_t)first_task, fetch_cr3());
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
sleep(5000);
|
|
|
|
|
kprintf("kernel awake\n");
|
|
|
|
|
}
|
2026-06-09 23:16:25 -05:00
|
|
|
}
|