caos-with-snake/kernel.c

58 lines
1.4 KiB
C
Raw Normal View History

2022-12-13 19:06:51 +03:00
asm(".asciz \"kernel start\\n\"");
2022-11-18 22:58:49 +03:00
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"
2023-01-25 14:56:38 +04:00
#include "drivers/pit.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 19:06:51 +03:00
#include "lib/string.h"
2022-12-14 09:00:32 +03:00
#include "proc.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();
2023-01-25 14:56:38 +04:00
init_pit();
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-14 17:17:27 +03:00
printk("\n> ");
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();
2023-01-25 14:56:38 +04:00
} else if (!strncmp("work\n", kbd_buf, kbd_buf_size)) {
for (int i = 0; i < 5; ++i) {
msleep(1000);
printk(".");
}
2022-12-14 09:00:32 +03:00
} else if (!strncmp("run ", kbd_buf, 4)) {
2022-12-13 19:06:51 +03:00
kbd_buf[kbd_buf_size-1] = '\0';
2022-12-14 09:00:32 +03:00
const char* cmd = kbd_buf + 4;
run_elf(cmd);
2022-12-13 01:18:30 +03:00
} else {
2022-12-14 17:17:27 +03:00
printk("unknown command, try: halt | run CMD");
2022-12-13 01:18:30 +03:00
}
kbd_buf_size = 0;
2022-12-14 09:00:32 +03:00
printk("\n> ");
2022-12-13 01:18:30 +03:00
}
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
}