From 7214ce8e53319a8fa51e83cb84cdaea2acf7615a Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Sat, 10 May 2025 19:42:48 +0200 Subject: [PATCH] foo --- arch/ioapic.cc | 11 ++- compile_flags.txt | 2 + debug/assert.cc | 2 +- debug/kernelpanic.h | 2 +- interrupt/handlers.cc | 4 +- main.cc | 4 +- utils/printf.cc | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++ utils/printf.h | 7 ++ 8 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 compile_flags.txt create mode 100644 utils/printf.cc create mode 100644 utils/printf.h diff --git a/arch/ioapic.cc b/arch/ioapic.cc index cd67118..f6d1ce3 100644 --- a/arch/ioapic.cc +++ b/arch/ioapic.cc @@ -71,9 +71,18 @@ void config(uint8_t slot, Core::Interrupt::Vector vector, } void allow(uint8_t slot) { + assert(slot < slot_max); + RedirectionTableEntry entry = readEntry(slot); + entry.interrupt_mask = UNMASKED; + writeEntry(slot, entry); } -void forbid(uint8_t slot) { (void)slot; } +void forbid(uint8_t slot) { + assert(slot < slot_max); + RedirectionTableEntry entry = readEntry(slot); + entry.interrupt_mask = MASKED; + writeEntry(slot, entry); +} bool status(uint8_t slot) { (void)slot; diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..664c608 --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,2 @@ +-Iarch +-xc++ diff --git a/debug/assert.cc b/debug/assert.cc index e7149a8..75dfac5 100644 --- a/debug/assert.cc +++ b/debug/assert.cc @@ -7,7 +7,7 @@ (void)func; (void)file; (void)line; - DBG << "Assertion failed: " << exp << "\nin function: " << func << "\nfrom file: \"" << file << "\" in line " << line << flush; + DBG << "Assertion failed: " << exp << "\nin function: " << func << "\nfrom file: \"" << file << "\" in line " << dec << line << flush; // TODO: Print error message (in debug window) // TODO: Then stop the current core permanently // Use appropriate method from class Core to do so. diff --git a/debug/kernelpanic.h b/debug/kernelpanic.h index f83fbd8..3b4ee9b 100644 --- a/debug/kernelpanic.h +++ b/debug/kernelpanic.h @@ -17,7 +17,7 @@ #define kernelpanic(MSG) \ do { \ DBG << "PANIC: '" << (MSG) << "' in " << __func__ << " @ " << __FILE__ \ - << ":" << __LINE__ << ") - CPU stopped." << endl; \ + << ":" << dec << __LINE__ << ") - CPU stopped." << endl; \ Core::die(); \ } while (0) diff --git a/interrupt/handlers.cc b/interrupt/handlers.cc index 46f47b5..42b7779 100644 --- a/interrupt/handlers.cc +++ b/interrupt/handlers.cc @@ -65,7 +65,9 @@ enum PAGE_FAULT_ERROR { kernelpanic("Page fault!"); } -void handle_keyboard() {} +void handle_keyboard() { + dout[0] << "test"< 0) { + int len = 0; + const char *ptr; + for (ptr = string; *ptr; ++ptr) ++len; + if (len >= width) width = 0; + else width -= len; + if (pad & PAD_ZERO) padchar = '0'; + } + if (!(pad & PAD_RIGHT)) { + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + } + for ( ; *string ; ++string) { + printchar (out, *string); + ++pc; + } + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + + return pc; +} + +/* the following should be enough for 32 bit int */ +#define PRINT_BUF_LEN 12 + +static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) +{ + char print_buf[PRINT_BUF_LEN]; + char *s; + int t, neg = 0, pc = 0; + unsigned int u = i; + + if (i == 0) { + print_buf[0] = '0'; + print_buf[1] = '\0'; + return prints (out, print_buf, width, pad); + } + + if (sg && b == 10 && i < 0) { + neg = 1; + u = -i; + } + + s = print_buf + PRINT_BUF_LEN-1; + *s = '\0'; + + while (u) { + t = u % b; + if( t >= 10 ) + t += letbase - '0' - 10; + *--s = t + '0'; + u /= b; + } + + if (neg) { + if( width && (pad & PAD_ZERO) ) { + printchar (out, '-'); + ++pc; + --width; + } + else { + *--s = '-'; + } + } + + return pc + prints (out, s, width, pad); +} + +static int print(char **out, int *varg) +{ + int width, pad; + int pc = 0; + char *format = reinterpret_cast(*varg++); + char scr[2]; + + for (; *format != 0; ++format) { + if (*format == '%') { + ++format; + width = pad = 0; + if (*format == '\0') break; + if (*format == '%') goto out; + if (*format == '-') { + ++format; + pad = PAD_RIGHT; + } + while (*format == '0') { + ++format; + pad |= PAD_ZERO; + } + for ( ; *format >= '0' && *format <= '9'; ++format) { + width *= 10; + width += *format - '0'; + } + if( *format == 's' ) { + char *s = *((char **)varg++); + pc += prints (out, s?s:"(null)", width, pad); + continue; + } + if( *format == 'd' ) { + pc += printi (out, *varg++, 10, 1, width, pad, 'a'); + continue; + } + if( *format == 'x' ) { + pc += printi (out, *varg++, 16, 0, width, pad, 'a'); + continue; + } + if( *format == 'X' ) { + pc += printi (out, *varg++, 16, 0, width, pad, 'A'); + continue; + } + if( *format == 'u' ) { + pc += printi (out, *varg++, 10, 0, width, pad, 'a'); + continue; + } + if( *format == 'c' ) { + /* char are converted to int then pushed on the stack */ + scr[0] = *varg++; + scr[1] = '\0'; + pc += prints (out, scr, width, pad); + continue; + } + } + else { + out: + printchar (out, *format); + ++pc; + } + } + if (out) **out = '\0'; + return pc; +} + +/* assuming sizeof(void *) == sizeof(int) */ + +extern "C" int printf(const char *format, ...) +{ + int *varg = (int *)(&format); + return print(0, varg); +} + +extern "C" int sprintf(char *out, const char *format, ...) +{ + int *varg = (int *)(&format); + return print(&out, varg); +} + diff --git a/utils/printf.h b/utils/printf.h new file mode 100644 index 0000000..f7a83d7 --- /dev/null +++ b/utils/printf.h @@ -0,0 +1,7 @@ +extern "C" { + +int printf(const char *format, ...); + +int sprintf(char *out, const char *format, ...); + +}