101 lines
2.5 KiB
C
101 lines
2.5 KiB
C
#include <drivers/ports.h>
|
|
#include <drivers/vgascreen.h>
|
|
#include <libc/libc.h>
|
|
#include <libc/stdbool.h>
|
|
#include <cpu/isr.h>
|
|
#include <cpu/timer.h>
|
|
#include <drivers/keyboard.h>
|
|
#include <mem/mem.h>
|
|
#include <multiboot.h>
|
|
#include <drivers/serial.h>
|
|
#include <kprint.h>
|
|
#include <libc/readline.h>
|
|
#include <libc/string.h>
|
|
|
|
const char *msg_booted = "Booted Successfully!\n";
|
|
const char *newline = "\n";
|
|
const char *msg_unknown_command = "Unknown command: ";
|
|
|
|
const char *cmd_echo = "echo";
|
|
const char *cmd_print_mmap = "print_mmap";
|
|
const char *cmd_print_malloc = "print_malloc";
|
|
const char *cmd_print_tick = "print_tick";
|
|
|
|
void main_loop();
|
|
|
|
void panic() {
|
|
kprint("PANIC!");
|
|
asm("cli;"
|
|
"hlt;");
|
|
}
|
|
|
|
void kmain(multiboot_info_t *multiboot_info) {
|
|
isr_install();
|
|
vga_clear_screen();
|
|
vga_clear_screen(' ', VGA_WHITE | (VGA_GRAY << VGA_SHIFT_BG));
|
|
kprint_register(vga_kprint);
|
|
serial_init();
|
|
kprint_register(serial_kprint);
|
|
if (multiboot_info->flags & (1 << 6)) {
|
|
kprint("mmap valid\n");
|
|
init_mmap((struct multiboot_mmap_entry *) multiboot_info->mmap_addr,
|
|
multiboot_info->mmap_length / sizeof(struct multiboot_mmap_entry));
|
|
} else {
|
|
kprint("mmap invalid!\n");
|
|
panic();
|
|
}
|
|
|
|
// vga_print_string(msg_booted, VGA_WHITE | (VGA_DARK_GRAY << VGA_SHIFT_BG));
|
|
kprint(msg_booted);
|
|
kprint((char *) multiboot_info->boot_loader_name);
|
|
kprint(newline);
|
|
// multiboot_memory_map_t *fe = multiboot_info->mmap_addr;
|
|
// port_byte_out(0x3d4, 14);
|
|
// int pos = port_byte_in(0x3d5);
|
|
// pos <<= 8;
|
|
//
|
|
// port_byte_out(0x3d4, 15);
|
|
// pos += port_byte_in(0x3d5);
|
|
|
|
asm volatile("sti");
|
|
init_timer(50);
|
|
init_keyboard();
|
|
|
|
// print_mmap_info();
|
|
while (true) {
|
|
main_loop();
|
|
}
|
|
|
|
// vga_set_raw(pos * 2, 'X');
|
|
// vga_set_raw(pos * 2 + 1, 0xf);
|
|
do {} while (1);
|
|
}
|
|
|
|
void main_loop() {
|
|
char *msg = readline(NULL);
|
|
char *args = strchr(msg, ' ') + 1;
|
|
args[-1] = 0;
|
|
if (strcmp(cmd_echo, msg) == 0) {
|
|
kprint(args);
|
|
kprint(newline);
|
|
goto _main_loop_end;
|
|
}
|
|
if (strcmp(cmd_print_mmap, msg) == 0) {
|
|
print_mmap_info();
|
|
goto _main_loop_end;
|
|
}
|
|
if (strcmp(cmd_print_malloc, msg) == 0) {
|
|
print_malloc_info();
|
|
goto _main_loop_end;
|
|
}
|
|
if (strcmp(cmd_print_tick, msg) == 0) {
|
|
print_current_tick();
|
|
goto _main_loop_end;
|
|
}
|
|
|
|
kprint(msg_unknown_command);
|
|
kprint(msg);
|
|
kprint(newline);
|
|
_main_loop_end:
|
|
free(msg);
|
|
} |