aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/system.c
diff options
context:
space:
mode:
authorMarvin Borner2020-04-15 21:17:41 +0200
committerMarvin Borner2020-04-15 21:17:41 +0200
commite07894d21a0101b10ee6ad851773b725cbb9150d (patch)
tree75631b318a9403395fbb3b40abdade8a475cd30b /src/kernel/system.c
parentaa3d1b4689e6dadd982fe1e5ca8af69ca39c617d (diff)
Used macro magic to implement function-based logs
Diffstat (limited to 'src/kernel/system.c')
-rw-r--r--src/kernel/system.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/kernel/system.c b/src/kernel/system.c
index a8544e6..9a181f3 100644
--- a/src/kernel/system.c
+++ b/src/kernel/system.c
@@ -28,7 +28,7 @@ void vga_log(char *msg)
uint16_t *terminal_buffer = (uint16_t *)0xB8000;
for (size_t i = 0; i < strlen(msg); i++)
terminal_buffer[line * 80 + i] = (uint16_t)msg[i] | (uint16_t)0x700;
- serial_printf(msg);
+ log("%s", msg);
char string[80];
strcpy(string, "[");
strcat(string, itoa((int)get_time()));
@@ -40,16 +40,10 @@ void vga_log(char *msg)
line++;
}
-void kernel_time()
-{
- printf("[%d] ", (int)get_time());
-}
-
-void debug(const char *fmt, ...)
+void _debug(const char *f, const char *fmt, ...)
{
vesa_set_color(vesa_dark_white);
- kernel_time();
- printf("DBG: ");
+ printf("[%s] DBG: ", f);
va_list args;
va_start(args, fmt);
@@ -60,11 +54,10 @@ void debug(const char *fmt, ...)
writec('\n');
}
-void info(const char *fmt, ...)
+void _info(const char *f, const char *fmt, ...)
{
vesa_set_color(vesa_blue);
- kernel_time();
- printf("INF: ");
+ printf("[%s] INF: ", f);
va_list args;
va_start(args, fmt);
@@ -75,11 +68,10 @@ void info(const char *fmt, ...)
writec('\n');
}
-void warn(const char *fmt, ...)
+void _warn(const char *f, const char *fmt, ...)
{
vesa_set_color(vesa_dark_yellow);
- kernel_time();
- printf("WRN: ");
+ printf("[%s] WRN: ", f);
va_list args;
va_start(args, fmt);
@@ -90,12 +82,15 @@ void warn(const char *fmt, ...)
writec('\n');
}
-void log(const char *fmt, ...)
+void _log(const char *f, const char *fmt, ...)
{
+ serial_printf("[%s] ", f);
va_list args;
va_start(args, fmt);
- serial_printf(fmt, args);
+ serial_vprintf(fmt, args);
va_end(args);
+
+ serial_put('\n');
}
const char *random_message[10] = { "Uh... Did I do that?",
@@ -109,21 +104,20 @@ const char *random_message[10] = { "Uh... Did I do that?",
"Call 01189998819991197253 pls",
"Please fix me!" };
-void panic(char *msg)
+void _panic(const char *f, const char *msg)
{
cli();
vesa_set_color(vesa_dark_red);
- kernel_time();
- serial_printf("PNC: %s - System halted!", msg);
- printf("PNC: %s - System halted!\n\n", msg);
+ _log(f, "PNC: %s - System halted!", msg);
+ printf("[%s] PNC: %s - System halted!\n\n", f, msg);
printf("> %s", random_message[get_time() % 10]);
halt_loop();
}
-void assert(int x)
+void _assert(const char *f, int x)
{
if (x == 0) {
- panic("Assertion failed");
+ _panic(f, "Assertion failed");
}
}
@@ -140,4 +134,4 @@ void v86(uint8_t code, regs16_t *regs)
paging_disable();
int32(code, regs);
paging_enable();
-} \ No newline at end of file
+}