-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.c
More file actions
64 lines (57 loc) · 1.41 KB
/
Copy pathkernel.c
File metadata and controls
64 lines (57 loc) · 1.41 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
// kernel.c
#include "kernel.h"
#include "console.h"
#include "gdt.h"
#include "idt.h"
#include "io.h"
#include "keyboard.h"
#include "pic.h"
#include "pmm.h"
#include "process.h"
#include "tss.h"
#include "vga.h"
#include "vmm.h"
void panic(const char *msg);
static void pit_init(uint32_t hz) {
uint32_t divisor = 1193180 / hz;
outb(0x43, 0x36);
outb(0x40, divisor & 0xFF);
outb(0x40, (divisor >> 8) & 0xFF);
}
void task_kernel_init();
int kernel_main(uint32_t magic, multiboot_info_t *mbi) {
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
PANIC("Invalid multiboot magic. Not booted by a multiboot loader.");
}
print("MuxOS booting...\n", VGA_COLOR_GREEN);
gdt_init();
tss_init();
pic_init();
idt_init();
pit_init(1000);
pmm_init(mbi);
vmm_init();
process_register_current();
process_create_kernel(task_kernel_init);
// 禁用中断,避免在创建用户进程时被调度打断
asm volatile("cli");
process_create_user(0); // 用户程序在 userlib.c 中
keyboard_init();
start_user_process(3);
// start_user_process 不会返回,所以不需要 sti
for (;;)
asm volatile("hlt");
}
void panic(const char *msg) {
clear_screen();
print("\n=== KERNEL PANIC! ===\n", 0);
print(msg, 0x0c);
print("\n", 0x0c);
for (;;)
;
}
void task_kernel_init() {
print("kernel task init!\n", 0x0B);
while (1)
;
}