From 2ae431b4fb4460cc222f059a343dd8ecade8e1ea Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Fri, 16 Feb 2024 21:17:51 -0600 Subject: Forgot to add these last time womp womp --- src/include/print.h | 4 ++-- src/kernel/exceptions.c | 12 ++++++++---- src/kernel/keyboard/isr.c | 8 ++++++-- src/kernel/keyboard/pic.c | 5 +++++ src/kernel/print.c | 25 +++++++++++++++++-------- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/include/print.h b/src/include/print.h index eeecfec..7ef7fa3 100644 --- a/src/include/print.h +++ b/src/include/print.h @@ -27,6 +27,6 @@ void update_cursor(); void delete_char(); void print_clear(); void print_char(char); -void print_str(char *); +int print_str(char *); void print_set_color(uint8_t, uint8_t); -void printf(const char *, ...); +int printf(const char *, ...); diff --git a/src/kernel/exceptions.c b/src/kernel/exceptions.c index ded9e9b..11e45fb 100644 --- a/src/kernel/exceptions.c +++ b/src/kernel/exceptions.c @@ -1,9 +1,13 @@ #include "print.h" -__attribute__((noreturn)) void exception_handler(void); -void exception_handler() { - print_set_color(PRINT_COLOR_RED, PRINT_COLOR_BLACK); +__attribute__((noreturn)) void panic(const char *msg) { + print_set_color(PRINT_COLOR_BLACK, PRINT_COLOR_RED); print_clear(); - printf("KERNEL EXCEPTION"); + printf("PANIC!!\n\t%s", msg); __asm__ volatile("cli; hlt"); + while (1) + ; } + +__attribute__((noreturn)) void exception_handler(void); +void exception_handler() { panic("KERNEL EXCEPTION"); } diff --git a/src/kernel/keyboard/isr.c b/src/kernel/keyboard/isr.c index 223bf9f..de7415c 100644 --- a/src/kernel/keyboard/isr.c +++ b/src/kernel/keyboard/isr.c @@ -1,4 +1,5 @@ #include "asm.h" +#include "exceptions.h" #include "print.h" #include "str.h" #include @@ -14,8 +15,7 @@ void keyboard_handler() { unsigned char sc = inb(0x60); uint8_t isheld = shift_held != 0; - char c = ((isheld | capslock) & !(isheld & capslock)) ? SCANCODES[sc] - : scancodes[sc]; + char c = (isheld ^ capslock) ? SCANCODES[sc] : scancodes[sc]; if (capslock & (!isheld) && !isalpha(c)) c = scancodes[sc]; @@ -45,5 +45,9 @@ void keyboard_handler() { capslock = !capslock; break; } + + if (shift_held && sc == 0xE0) + panic("Test panic"); + outb(0x20, 0x20); } diff --git a/src/kernel/keyboard/pic.c b/src/kernel/keyboard/pic.c index e1b4fb3..2161c93 100644 --- a/src/kernel/keyboard/pic.c +++ b/src/kernel/keyboard/pic.c @@ -7,6 +7,11 @@ #define PIC2_COMMAND PIC2 #define PIC2_DATA (PIC2 + 1) +// Gonna be honest i just kinda yoinked most of this +// from the wiki, i am gonna have to rewrite these +// sooner rather than later if i want to actually +// learn. + void PIC_init(int offset1, int offset2) { uint8_t a1, a2; diff --git a/src/kernel/print.c b/src/kernel/print.c index 7a54c7b..3ddb445 100644 --- a/src/kernel/print.c +++ b/src/kernel/print.c @@ -54,6 +54,8 @@ void print_clear() { for (size_t i = 0; i < NUM_ROWS; i++) { clear_row(i); } + col = 0; + row = 0; } // newline @@ -115,10 +117,12 @@ void print_char(char character) { } // print_str -void print_str(char *str) { +int print_str(char *str) { // while character != '\0' print char - for (size_t i = 0; str[i] != '\0'; ++i) + size_t i; + for (i = 0; str[i] != '\0'; ++i) print_char(str[i]); + return i; } // Set color byte to requested colors using color enum from print.h @@ -126,30 +130,34 @@ void print_set_color(uint8_t foreground, uint8_t background) { color = foreground + (background << 4); } -void printf(const char *str, ...) { +int printf(const char *str, ...) { va_list args; va_start(args, str); char temp_str[256] = ""; + int len = 0; - for (size_t i = 0; str[i] != '\0'; ++i) { + size_t i; + for (i = 0; str[i] != '\0'; ++i) { if (str[i] == '%') { switch (str[++i]) { case 'i': case 'd': - print_str(itoa(va_arg(args, int), temp_str, 10)); + len += print_str(itoa(va_arg(args, int), temp_str, 10)); break; case 'x': - print_str("0x"); - print_str(itoa(va_arg(args, int), temp_str, 16)); + len += print_str("0x"); + len += print_str(itoa(va_arg(args, int), temp_str, 16)); break; case 's': - print_str(va_arg(args, char *)); + len += print_str(va_arg(args, char *)); break; case 'c': print_char(va_arg(args, int)); + len++; break; case '%': print_char('%'); + len++; case 'n': break; } @@ -158,4 +166,5 @@ void printf(const char *str, ...) { print_char(str[i]); } va_end(args); + return i; } -- cgit v1.2.3