caos-with-snake/kernel.c

45 lines
962 B
C
Raw Normal View History

2022-11-18 22:58:49 +03:00
asm(".asciz \"kernel start\"");
2022-11-20 19:48:55 +03:00
#include "console.h"
2022-11-20 18:59:53 +03:00
#include "cpu/isr.h"
2022-11-22 21:24:49 +03:00
#include "cpu/gdt.h"
2022-11-20 19:48:55 +03:00
#include "drivers/keyboard.h"
2022-11-20 16:06:32 +03:00
#include "drivers/vga.h"
2022-11-18 22:58:49 +03:00
#include "drivers/ata.h"
#include "drivers/misc.h"
2022-11-21 00:53:29 +03:00
#include "drivers/uart.h"
2022-12-13 00:50:28 +03:00
#include "fs/fs.h"
2022-12-13 01:18:30 +03:00
#include "string.h"
2022-11-14 00:23:42 +03:00
2022-11-17 23:16:57 +03:00
void _start() {
2022-11-22 21:24:49 +03:00
load_gdt();
2022-11-20 19:48:55 +03:00
init_keyboard();
2022-11-21 00:53:29 +03:00
uartinit();
2022-11-20 18:59:53 +03:00
load_idt();
sti();
2022-12-13 01:18:30 +03:00
char *buf = (char*)(16 << 20);
2022-11-18 22:58:49 +03:00
2022-11-14 00:23:42 +03:00
vga_clear_screen();
2022-11-20 19:48:55 +03:00
printk("YABLOKO\n");
2022-11-18 22:58:49 +03:00
2022-12-13 01:18:30 +03:00
if (read_file("kernel.bin", buf, 4096 + sector_size) > 0) {
2022-12-13 00:50:28 +03:00
printk(buf + 4096);
} else {
printk("failed to read file\n");
}
2022-12-13 01:18:30 +03:00
printk("\n> ");
2022-11-18 22:58:49 +03:00
2022-11-20 19:48:55 +03:00
while (1) {
2022-12-13 01:18:30 +03:00
if (kbd_buf_size > 0 && kbd_buf[kbd_buf_size-1] == '\n') {
if (!strncmp("halt\n", kbd_buf, kbd_buf_size)) {
qemu_shutdown();
} else {
printk("unknown command, try: halt\n> ");
}
kbd_buf_size = 0;
}
2022-11-21 00:53:29 +03:00
asm("hlt");
2022-11-20 19:48:55 +03:00
}
2022-09-21 18:25:06 +03:00
}