This commit is contained in:
2021-02-01 23:28:24 +01:00
parent 9986d95dbb
commit 4673a23db7
11 changed files with 140 additions and 42 deletions

View File

@@ -12,23 +12,43 @@
#include <libc/readline.h>
#include <libc/string.h>
char *msg_booted = "Booted Successfully!\n";
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();
init_mmap((struct multiboot_mmap_entry *) multiboot_info->mmap_addr,
multiboot_info->mmap_length / sizeof(struct multiboot_mmap_entry));
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);
@@ -51,15 +71,9 @@ void kmain(multiboot_info_t *multiboot_info) {
do {} while (1);
}
const char* newline = "\n";
const char* msg_unknown_command = "Unknown command: ";
const char* cmd_echo = "echo";
const char* cmd_print_mmap = "print_mmap";
void main_loop() {
char* msg = readline(NULL);
char* args = strchr(msg, ' ') + 1;
char *msg = readline(NULL);
char *args = strchr(msg, ' ') + 1;
args[-1] = 0;
if (strcmp(cmd_echo, msg) == 0) {
kprint(args);
@@ -70,10 +84,18 @@ void main_loop() {
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:
_main_loop_end:
free(msg);
}