This repository was archived by the owner on Jul 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.c
More file actions
68 lines (64 loc) · 1.88 KB
/
Copy pathkernel.c
File metadata and controls
68 lines (64 loc) · 1.88 KB
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
#include "pmm.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "vga.h"
#include "gdt.h"
#include "isr.h"
#include "idt.h"
#include "kstd.h"
#include "paging.h"
#include "console.h"
#include "multiboot.h"
extern uint8_t kernel_stack[];
// GDT flush expects this symbol; reserve a 16 KiB kernel stack.
uint8_t kernel_stack[16384] __attribute__((aligned(16)));
void kernel_main(uint32_t magic, void* mb_info){
terminal_initialize();
if (magic != 0x2BADB002 && magic != 0x36D76289) {
terminal_writestring("Unknown boot magic, halting.\n");
while (1) __asm__ volatile("hlt");
}
pmm_init((uint32_t)mb_info);
uint32_t a = pmm_alloc_frame();
uint32_t b = pmm_alloc_frame();
uint32_t c = pmm_alloc_frame();
pmm_free_frame(b);
uint32_t d = pmm_alloc_frame();
femboysay("Will init GDT\n");
gdt_init();
femboysay("GDT initialized\n");
femboysay("Will init IDT\n");
idt_init();
isr_init();
femboysay("IDT initialized\n");
femboysay("Will remap PIC\n");
pic_remap();
femboysay("PIC remapped\n");
femboysay("Will unmask/mask\n");
outb(0x21, 0xFC); // unmask timer + keyboard
outb(0xA1, 0xFF); // mask all IRQs on slavep
femboysay("Done.\n");
femboysay("Will change PIT divisor\n");
uint16_t divisor = 1193;
outb(0x43,0x36);
outb(0x40,divisor & 0xFF);
outb(0x40,(divisor >> 8)&0xFF);
waitmode = 1;
femboysay("Accurate timing implemented\n");
femboysay("Will enable interrupts\n");
__asm__ volatile("sti");
kwait(1);
femboysay("Interrupts enabled\n");
femboysay("Will init paging\n");
init_paging();
femboysay("Paging init\n");
uint32_t* heap_test = (uint32_t*)0x40000000;
*heap_test = 1234;
terminal_writestring("Heap page allocated\n");
changeout(handle_shell,0);
while (1)
{
__asm__ volatile("hlt");
}
}