diff --git a/drivers/descriptor/descriptor.h b/drivers/descriptor/descriptor.h index fb1cf8e..f32eb53 100644 --- a/drivers/descriptor/descriptor.h +++ b/drivers/descriptor/descriptor.h @@ -5,6 +5,7 @@ #include "../../lib/stdlib/stdlib.h" #include "../../lib/stdio/stdio.h" #include "../../lib/string/string.h" +#include "../../memory/pmm/pmm.h" extern void isr0(); extern void isr1(); diff --git a/drivers/descriptor/isr.c b/drivers/descriptor/isr.c index 4e79951..797c491 100644 --- a/drivers/descriptor/isr.c +++ b/drivers/descriptor/isr.c @@ -40,8 +40,31 @@ static char* exception_msg[] = { "Reserved" }; -void isr_handler(registers_t* r) { +void panic(registers_t* r) { + asm volatile("cli"); + uint32_t stack = r->esp; printf("Number: %d | Message: %s\n", r->int_no, exception_msg[r->int_no]); + uint32_t* cp_stack = (uint32_t*)pmm_alloc_block(); + for (uint32_t* ptr = (uint32_t*)stack; *ptr && ptr < (uint32_t*)stack + 0x1000; ptr++) { + *cp_stack++ = *ptr; + } + asm volatile( + "xor %eax, %eax\n" + "xor %ebx, %ebx\n" + "xor %ecx, %ecx\n" + "xor %edx, %edx\n" + "xor %edi, %edi\n" + "xor %esi, %esi\n" + "xor %ebp, %ebp\n" + //"xor %eip, %eip\n" RD ONLY + "xor %esp, %esp\n" + ); + asm volatile("hlt"); + +} + +void isr_handler(registers_t* r) { + panic(r); } void isr_install() { diff --git a/drivers/keyboard/keyboard.h b/drivers/keyboard/keyboard.h index 13d422b..28d72e9 100644 --- a/drivers/keyboard/keyboard.h +++ b/drivers/keyboard/keyboard.h @@ -8,6 +8,7 @@ void init_keyboard(); void exec_command(); void cmd_add_char(uint8_t c); void tests_string(int* total, int* success, int* failure); +void tests_stdlib(int* total, int* success, int* failure); typedef enum { SHELL, diff --git a/drivers/keyboard/kshell.c b/drivers/keyboard/kshell.c index 036df7f..ed32cd6 100644 --- a/drivers/keyboard/kshell.c +++ b/drivers/keyboard/kshell.c @@ -64,6 +64,7 @@ void exec_tests() { printf("TEST SUITE FOR THE KERNEL\n"); //TODO: write test suite for functions that give an output tests_string(&total, &success, &failure); + tests_stdlib(&total, &success, &failure); printf("\nTEST SUITE DONE:\n TOTAL : %d\n SUCCESS : %d\n FAILURE : %d\n", total, success, failure); } @@ -97,6 +98,75 @@ void print_stack() { printf("\n"); } +void int_0x0() { asm volatile("int $0x0"); } +void int_0x1() { asm volatile("int $0x1"); } +void int_0x2() { asm volatile("int $0x2"); } +void int_0x3() { asm volatile("int $0x3"); } +void int_0x4() { asm volatile("int $0x4"); } +void int_0x5() { asm volatile("int $0x5"); } +void int_0x6() { asm volatile("int $0x6"); } +void int_0x7() { asm volatile("int $0x7"); } +void int_0x8() { asm volatile("int $0x8"); } +void int_0x9() { asm volatile("int $0x9"); } +void int_0xA() { asm volatile("int $0xA"); } +void int_0xB() { asm volatile("int $0xB"); } +void int_0xC() { asm volatile("int $0xC"); } +void int_0xD() { asm volatile("int $0xD"); } +void int_0xE() { asm volatile("int $0xE"); } +void int_0xF() { asm volatile("int $0xF"); } +void int_0x10() { asm volatile("int $0x10"); } +void int_0x11() { asm volatile("int $0x11"); } +void int_0x12() { asm volatile("int $0x12"); } +void int_0x13() { asm volatile("int $0x13"); } +void int_0x14() { asm volatile("int $0x14"); } +void int_0x15() { asm volatile("int $0x15"); } +void int_0x16() { asm volatile("int $0x16"); } +void int_0x17() { asm volatile("int $0x17"); } +void int_0x18() { asm volatile("int $0x18"); } +void int_0x19() { asm volatile("int $0x19"); } +void int_0x1A() { asm volatile("int $0x1A"); } +void int_0x1B() { asm volatile("int $0x1B"); } +void int_0x1C() { asm volatile("int $0x1C"); } +void int_0x1D() { asm volatile("int $0x1D"); } +void int_0x1E() { asm volatile("int $0x1E"); } +void int_0x1F() { asm volatile("int $0x1F"); } +void int_0x20() { asm volatile("int $0x20"); } +void int_0x21() { asm volatile("int $0x21"); } +void int_0x22() { asm volatile("int $0x22"); } +void int_0x23() { asm volatile("int $0x23"); } +void int_0x24() { asm volatile("int $0x24"); } +void int_0x25() { asm volatile("int $0x25"); } + +typedef void (*inter_func)(void); + +inter_func tab[] = { + int_0x0, int_0x1, int_0x2, int_0x3, + int_0x4, int_0x5, int_0x6, int_0x7, + int_0x8, int_0x9, int_0xA, int_0xB, + int_0xC, int_0xD, int_0xE, int_0xF, + int_0x10, int_0x11, int_0x12, int_0x13, + int_0x14, int_0x15, int_0x16, int_0x17, + int_0x18, int_0x19, int_0x1A, int_0x1B, + int_0x1C, int_0x1D, int_0x1E, int_0x1F, + int_0x20, int_0x21, int_0x22, int_0x23, + int_0x24, int_0x25 +}; + +void do_interrupt(char* nb) { + int n = atoi(nb); + if (n < 0 || n > 0x25) return; + tab[n](); +} + +void shut_down() { + asm volatile( + "movw $0x2000, %ax\n" + "movw $0x604, %dx\n" + "outw %ax, %dx\n" + "hlt" + ); +} + void exec_command() { char words[4][256]; size_t i = 0; @@ -118,10 +188,14 @@ void exec_command() { exec_tests(); } else if (!strcmp(words[0], "REBOOT")){ reboot(); + } else if (!strcmp(words[0], "EXIT")){ + shut_down(); } else if (!strcmp(words[0], "HALT")){ asm volatile("hlt\n\t"); } else if (!strcmp(words[0], "STACK")){ print_stack(); + } else if (!strcmp(words[0], "INT")){ + do_interrupt(words[1]); } else if (!strcmp(words[0], "HELP")) { printf("WELCOME TO THE KERNEL\n\ THE CLI IS STILL UNDER DEVELOPMENT.\n\ @@ -132,8 +206,10 @@ COMMANDS AVAILABLE:\n\ - KEYBOARD = TWO LAYOUT ARE AVAILABLE, FR AND US\n\ CLEAR : CLEARS THE CLI\n\ REBOOT : REBOOTS THE KERNEL\n\ + EXIT : SHUT DOWN THE KERNEL AND THE VM\n\ HALT : HALTS THE KERNEL\n\ STACK : PRINTS STACK\n\ + INT [NUM] : DOES INTERRUPTION [NUM]\n\ TEST : EXECUTES A TEST SUITE FOR THE KERNEL\n\ HELP : PRINTS THIS MESSAGE\n"); } diff --git a/drivers/keyboard/tester.c b/drivers/keyboard/tester.c index 57bce7a..5aef08a 100644 --- a/drivers/keyboard/tester.c +++ b/drivers/keyboard/tester.c @@ -79,3 +79,15 @@ void tests_string(int* total, int* success, int* failure) { printf("memset : failure\n"); } } + +void tests_stdlib(int* total, int* success, int* failure) { + printf("\ntests for stdlib.h\n"); + *total += 1; + if (atoi("5") == 5 && atoi("-5") == -5 && atoi("zda") == 0) { + *success += 1; + printf("atoi : success\n"); + } else { + *failure += 1; + printf("atoi : failure atoi(5) == %d | atoi(-5) == %d | atoi('zda') == %d\n", atoi("5"), atoi("-5"), atoi("zda")); + } +} diff --git a/lib/stdlib/stdlib.c b/lib/stdlib/stdlib.c index cb27796..0d81fc7 100644 --- a/lib/stdlib/stdlib.c +++ b/lib/stdlib/stdlib.c @@ -72,15 +72,15 @@ size_t itoxx(char *dest, unsigned int n) { } inline int atoi(const char *nptr) { - if (!nptr) return 0x0; - int sign = 0x0; - while (*nptr && !isnum(*nptr)) { + if (!nptr) return 0; + int sign = 1; + if (*nptr == '+' || *nptr == '-') { if (*(nptr) == '-') - sign = 0xFF; + sign = -1; nptr++; } - int res = 0x0; - while (*nptr) { + int res = 0; + while (*nptr && isnum(*nptr)) { res = res * 0xA + *nptr - 0x30; nptr++; } diff --git a/screenshots/HELPER.png b/screenshots/HELPER.png index d802b7e..bfc465e 100644 Binary files a/screenshots/HELPER.png and b/screenshots/HELPER.png differ