1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-12-04 11:34:42 -05:00

Replace kprintf with logger

This commit is contained in:
Braiden Vasco 2017-11-06 03:48:16 +00:00
parent 2173d144b1
commit 9912bcf2a1
7 changed files with 93 additions and 122 deletions

View file

@ -14,7 +14,6 @@ OBJS += main.c.o
OBJS += logger.c.o
OBJS += console.c.o
OBJS += kprintf.c.o
OBJS += protected.c.o protected.asm.cpp.o

View file

@ -1,61 +0,0 @@
#include "kprintf.h"
#include "console.h"
#include <kernelmq/stdlib.h>
void kprintf(const char *format, ...)
{
console_setcolor(VGA_COLOR_LIGHT_GREY);
char **arg = (char **) &format;
int c;
char buf[20];
arg++;
while ((c = *format++) != 0)
{
if (c != '%') {
console_putc(c);
}
else {
char *p, *p2;
int pad0 = 0, pad = 0;
c = *format++;
if (c == '0')
{
pad0 = 1;
c = *format++;
}
if (c >= '0' && c <= '9')
{
pad = c - '0';
c = *format++;
}
switch (c)
{
case 'd':
case 'u':
case 'x':
kitoa (buf, c, *((int *) arg++));
p = buf;
goto string;
break;
case 's':
p = *arg++;
if (! p)
p = "(null)";
string:
for (p2 = p; *p2; p2++);
for (; p2 < p + pad; p2++)
console_putc(pad0 ? '0' : ' ');
while (*p)
console_putc(*p++);
break;
default:
console_putc(*((int *) arg++));
break;
}
}
}
}

View file

@ -1,6 +0,0 @@
#ifndef KERNELMQ_INCLUDED_KPRINTF
#define KERNELMQ_INCLUDED_KPRINTF 1
void kprintf(const char *format, ...);
#endif

View file

@ -2,13 +2,33 @@
#include "console.h"
void logger_info(const char *const s)
#include <kernelmq/stdlib.h>
#define LEVELS_COUNT 3
static const enum vga_color level_colors[LEVELS_COUNT] = {
VGA_COLOR_CYAN,
VGA_COLOR_MAGENTA,
VGA_COLOR_RED,
};
static const char *const level_text[LEVELS_COUNT] = {
"INFO",
"WARN",
"FAIL",
};
void logger_log(unsigned char level, const char *format, ...)
{
if (level >= LEVELS_COUNT) {
level = LEVELS_COUNT - 1;
}
console_setcolor(VGA_COLOR_LIGHT_GREY);
console_putc('[');
console_setcolor(VGA_COLOR_CYAN);
console_print("INFO");
console_setcolor(level_colors[level]);
console_print(level_text[level]);
console_setcolor(VGA_COLOR_LIGHT_GREY);
console_putc(']');
@ -16,39 +36,57 @@ void logger_info(const char *const s)
console_putc(' ');
console_setcolor(VGA_COLOR_WHITE);
console_puts(s);
}
void logger_warn(const char *const s)
{
console_setcolor(VGA_COLOR_LIGHT_GREY);
console_putc('[');
console_setcolor(VGA_COLOR_MAGENTA);
console_print("WARN");
console_setcolor(VGA_COLOR_LIGHT_GREY);
console_putc(']');
console_putc(' ');
console_setcolor(VGA_COLOR_WHITE);
console_puts(s);
}
void logger_fail(const char *const s)
{
console_setcolor(VGA_COLOR_LIGHT_GREY);
console_putc('[');
console_setcolor(VGA_COLOR_RED);
console_print("FAIL");
console_setcolor(VGA_COLOR_LIGHT_GREY);
console_putc(']');
console_putc(' ');
console_setcolor(VGA_COLOR_WHITE);
console_puts(s);
char **arg = (char **) &format;
int c;
char buf[20];
arg++;
while ((c = *format++) != 0)
{
if (c != '%') {
console_putc(c);
}
else {
char *p, *p2;
int pad0 = 0, pad = 0;
c = *format++;
if (c == '0')
{
pad0 = 1;
c = *format++;
}
if (c >= '0' && c <= '9')
{
pad = c - '0';
c = *format++;
}
switch (c)
{
case 'd':
case 'u':
case 'x':
kitoa (buf, c, *((int *) arg++));
p = buf;
goto string;
break;
case 's':
p = *arg++;
if (! p)
p = "(null)";
string:
for (p2 = p; *p2; p2++);
for (; p2 < p + pad; p2++)
console_putc(pad0 ? '0' : ' ');
while (*p)
console_putc(*p++);
break;
default:
console_putc(*((int *) arg++));
break;
}
}
}
console_putc('\n');
}

View file

@ -1,8 +1,10 @@
#ifndef KERNELMQ_INCLUDED_LOGGER
#define KERNELMQ_INCLUDED_LOGGER 1
void logger_info(const char *s);
void logger_warn(const char *s);
void logger_fail(const char *s);
#define logger_info(...) logger_log(0, __VA_ARGS__)
#define logger_warn(...) logger_log(1, __VA_ARGS__)
#define logger_fail(...) logger_log(2, __VA_ARGS__)
void logger_log(unsigned char level, const char *format, ...);
#endif

View file

@ -4,7 +4,6 @@
#include "protected.h"
#include "paging.h"
#include "timer.h"
#include "kprintf.h"
#include "tasks.h"
#include <kernelmq/info.h>
@ -26,22 +25,22 @@ void main(const struct KernelMQ_Info *const kinfo_ptr)
return;
}
kprintf("Kernel command line: %s\n", kinfo.cmdline);
logger_info("Kernel command line: %s", kinfo.cmdline);
kprintf(
"Kernel phys base 0x%x, limit 0x%x\n",
logger_info(
"Kernel phys base 0x%x, limit 0x%x",
kinfo.kernel_phys_base,
kinfo.kernel_phys_limit
);
kprintf(
"Kernel virt base 0x%x, limit 0x%x\n",
logger_info(
"Kernel virt base 0x%x, limit 0x%x",
kinfo.kernel_virt_base,
kinfo.kernel_virt_limit
);
kprintf(
"Kernel size 0x%x, offset 0x%x\n",
logger_info(
"Kernel size 0x%x, offset 0x%x",
kinfo.kernel_size,
kinfo.kernel_offset
);
@ -49,8 +48,8 @@ void main(const struct KernelMQ_Info *const kinfo_ptr)
for (unsigned int i = 0; i < kinfo.modules_count; ++i) {
struct KernelMQ_Info_Module *module = &kinfo.modules[i];
kprintf(
"Module at 0x%x, size 0x%x, command line: %s\n",
logger_info(
"Module at 0x%x, size 0x%x, command line: %s",
module->base,
module->size,
module->cmdline

View file

@ -1,5 +1,5 @@
#include "interrupt.h"
#include "kprintf.h"
#include "logger.h"
#include <kernelmq/syscall.h>
@ -13,10 +13,10 @@ void syscall_handler(const struct IsrRegisters regs)
case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs);
}
kprintf("syscall %u\n", id);
logger_info("syscall %u", id);
}
void syscall_do_exit(const struct IsrRegisters regs)
{
kprintf("process try to exit with error code %u, haha\n", regs.ebx & 0xFFFF);
logger_warn("process try to exit with error code %u, haha", regs.ebx & 0xFFFF);
}