1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00

Remove logger

This commit is contained in:
Alex Kotov 2020-12-06 08:04:34 +05:00
parent e23553de85
commit a3e6bdd0c2
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
11 changed files with 30 additions and 144 deletions

View file

@ -21,9 +21,6 @@ OBJS += info.c.o
OBJS += pic.c.o
OBJS += timer.c.o
# For debugging
OBJS += logger.c.o
OBJS += protected.c.o protected.asm.cpp.o
OBJS += tss.c.o tss.asm.cpp.o

View file

@ -1,8 +1,9 @@
#include "interrupt.h"
#include "config.h"
#include "logger.h"
#include "panic.h"
#include <kernaux/console.h>
static const char *const messages[] = {
"0 #DE - Divide Error Exception",
"1 #DB - Debug Exception",
@ -47,7 +48,7 @@ void exception_handler(struct IsrRegisters regs)
return;
}
logger_fail_from("exception", "Unhandled protected-mode exception:\n%s", messages[regs.int_no]);
kernaux_console_printf("[FAIL] exception: Unhandled protected-mode exception: %s\n", messages[regs.int_no]);
panic("Can not continue.");
}

View file

@ -2,9 +2,10 @@
#include "interrupt.h"
#include "config.h"
#include "logger.h"
#include "pic.h"
#include <kernaux/console.h>
static hwint_handler_t handlers[INT_HWINT_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void hwint_handler(struct IsrRegisters regs)
@ -18,7 +19,7 @@ void hwint_handler(struct IsrRegisters regs)
const hwint_handler_t handler = handlers[hwint_no];
if (!handler) {
logger_warn_from("hwint", "Unhandled hardware interrupt: %u", hwint_no);
kernaux_console_printf("[WARN] hwint: Unhandled hardware interrupt: %u\n", hwint_no);
return;
}

View file

@ -1,94 +0,0 @@
#include "logger.h"
#include <kernaux/console.h>
#include <kernaux/stdlib.h>
#define LEVELS_COUNT 4
static const char *const level_text[LEVELS_COUNT] = {
"DBUG",
"INFO",
"WARN",
"FAIL",
};
static void print_prefix(unsigned char level, const char *source);
void logger_log(unsigned char level, const char *const source, const char *format, ...)
{
if (level >= LEVELS_COUNT) {
level = LEVELS_COUNT - 1;
}
print_prefix(level, source);
char **arg = (char **) &format;
int c;
char buf[20];
arg++;
while ((c = *format++) != 0)
{
if (c == '\n') {
kernaux_console_putc('\n');
print_prefix(level, source);
}
else if (c != '%') {
kernaux_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':
kernaux_itoa(*((int*)arg++), buf, c);
p = buf;
goto string;
break;
case 's':
p = *arg++;
if (! p)
p = "(null)";
string:
for (p2 = p; *p2; p2++);
for (; p2 < p + pad; p2++)
kernaux_console_putc(pad0 ? '0' : ' ');
while (*p)
kernaux_console_putc(*p++);
break;
default:
kernaux_console_putc(*((int *) arg++));
break;
}
}
}
kernaux_console_putc('\n');
}
void print_prefix(const unsigned char level, const char *const source)
{
kernaux_console_putc('[');
kernaux_console_print(level_text[level]);
kernaux_console_putc(']');
kernaux_console_putc(' ');
if (source) {
kernaux_console_print(source);
kernaux_console_print(": ");
}
}

View file

@ -1,16 +0,0 @@
#ifndef KERNELMQ_INCLUDED_LOGGER
#define KERNELMQ_INCLUDED_LOGGER 1
#define logger_debug_from(source, ...) logger_log(0, source, __VA_ARGS__)
#define logger_info_from(source, ...) logger_log(1, source, __VA_ARGS__)
#define logger_warn_from(source, ...) logger_log(2, source, __VA_ARGS__)
#define logger_fail_from(source, ...) logger_log(3, source, __VA_ARGS__)
#define logger_debug(...) logger_debug_from(0, __VA_ARGS__)
#define logger_info(...) logger_info_from(0, __VA_ARGS__)
#define logger_warn(...) logger_warn_from(0, __VA_ARGS__)
#define logger_fail(...) logger_fail_from(0, __VA_ARGS__)
void logger_log(unsigned char level, const char *source, const char *format, ...);
#endif

View file

@ -7,7 +7,6 @@
#include "tasks.h"
#include "elf.h"
#include "logger.h"
#include <kernaux/console.h>
#include <kernaux/multiboot2.h>
@ -177,7 +176,7 @@ void main(
tasks_switch_to_user(real_entrypoint);
}
else {
logger_warn_from("init", "Invalid ELF header");
kernaux_console_print("[WARN] init: Invalid ELF header.\n");
}
}
}

View file

@ -1,12 +1,11 @@
#include "panic.h"
#include "logger.h"
#include <kernaux/arch/x86.h>
#include <kernaux/console.h>
void panic(const char *const s)
{
logger_fail_from("panic", s);
kernaux_console_printf("[FAIL] panic: %s\n", s);
kernaux_arch_x86_hang();
}

View file

@ -1,8 +1,7 @@
#include "pic.h"
#include "logger.h"
#include <kernaux/arch/x86.h>
#include <kernaux/console.h>
#define MASTER_COMMAND 0x20
#define MASTER_DATA 0x21
@ -18,7 +17,7 @@ static unsigned char slave_irq_start = 8;
void pic_enable_all()
{
logger_info_from("pic", "Enable all IRQs.");
kernaux_console_print("[INFO] pic: Enable all IRQs.\n");
kernaux_arch_x86_outportb(MASTER_DATA, 0);
kernaux_arch_x86_outportb(SLAVE_DATA, 0);
@ -26,7 +25,7 @@ void pic_enable_all()
void pic_disable_all()
{
logger_info_from("pic", "Disable all IRQs.");
kernaux_console_print("[INFO] pic: Disable all IRQs.\n");
kernaux_arch_x86_outportb(MASTER_DATA, 0xFF);
kernaux_arch_x86_outportb(SLAVE_DATA, 0xFF);
@ -35,11 +34,11 @@ void pic_disable_all()
void pic_enable(const unsigned char line)
{
if (line >= IRQS_TOTAL) {
logger_warn_from("pic", "Invalid line %u.", line);
kernaux_console_printf("[WARN] pic: Invalid line %u.\n", line);
return;
}
logger_info_from("pic", "Enable line %u.", line);
kernaux_console_printf("[INFO] pic: Enable line %u.\n", line);
if (line < IRQS_COUNT) {
const unsigned char mask = kernaux_arch_x86_inportb(MASTER_DATA);
@ -54,11 +53,11 @@ void pic_enable(const unsigned char line)
void pic_disable(const unsigned char line)
{
if (line >= IRQS_TOTAL) {
logger_warn_from("pic", "Invalid line %u.", line);
kernaux_console_printf("[WARN] pic: Invalid line %u.\n", line);
return;
}
logger_info_from("pic", "Disable line %u.", line);
kernaux_console_printf("[INFO] pic: Disable line %u.\n", line);
if (line < IRQS_COUNT) {
const unsigned char mask = kernaux_arch_x86_inportb(MASTER_DATA);
@ -73,7 +72,7 @@ void pic_disable(const unsigned char line)
void pic_remap(const unsigned char new_master_irq_start, const unsigned char new_slave_irq_start)
{
logger_info_from("pic", "Remap the IRQ table.");
kernaux_console_print("[INFO] pic: Remap the IRQ table.\n");
// Remember IRQ numbers
master_irq_start = new_master_irq_start;

View file

@ -1,12 +1,12 @@
#include "protected.h"
#include "config.h"
#include "logger.h"
#include "interrupt.h"
#include "hwint.h"
#include "tss.h"
#include "pic.h"
#include <kernaux/console.h>
#include <kernaux/stdlib.h>
struct GdtPointer {
@ -56,7 +56,7 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo)
pic_remap(32, 40);
pic_disable_all();
logger_info_from("protected", "Setup GDT.");
kernaux_console_print("[INFO] protected: Setup GDT.\n");
gdt_set_gate(GDT_NULL_INDEX, 0, 0x00000000, 0, 0);
gdt_set_gate(GDT_KERNEL_CS_INDEX, 0, 0xFFFFFFFF, 0x9A, 0xCF);
@ -66,7 +66,7 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo)
tss_write_to_gdt(kinfo, &gdt_entries[GDT_TSS_INDEX]);
logger_info_from("protected", "Setup IDT.");
kernaux_console_print("[INFO] protected: Setup IDT.\n");
kernaux_memset(idt_entries, 0, sizeof(idt_entries));
@ -125,25 +125,25 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo)
idt_set_gate(INT_SYSCALL, (unsigned int)interrupt_0x80, 0x08, 0x8E | 0x60);
logger_info_from("protected", "Load GDT.");
kernaux_console_print("[INFO] protected: Load GDT.\n");
gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1;
gdt_pointer.base = (unsigned int)&gdt_entries;
gdt_flush(&gdt_pointer);
logger_info_from("protected", "Load IDT.");
kernaux_console_print("[INFO] protected: Load IDT.\n");
idt_pointer.limit = sizeof(struct IdtEntry) * IDT_SIZE - 1;
idt_pointer.base = (unsigned int)&idt_entries;
idt_flush(&idt_pointer);
logger_info_from("protected", "Load TSS.");
kernaux_console_print("[INFO] protected: Load TSS.\n");
tss_flush();
logger_info_from("protected", "Enable interrupts.");
kernaux_console_print("[INFO] protected: Enable interrupts.\n");
asm volatile ("sti");
}

View file

@ -1,15 +1,16 @@
#include "interrupt.h"
#include "logger.h"
#include "syscall.h"
#include <kernaux/console.h>
static void syscall_do_exit(struct IsrRegisters regs);
void syscall_handler(const struct IsrRegisters regs)
{
const unsigned int id = regs.eax << 16 >> 16;
logger_info_from("syscall", "number %u", id);
kernaux_console_printf("[INFO] syscall: number %u\n", id);
switch (id) {
case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs);
@ -20,5 +21,5 @@ void syscall_do_exit(const struct IsrRegisters regs)
{
const unsigned int exit_code = regs.ebx << 16 >> 16;
logger_warn_from("syscall", "process try to exit with error code %u, haha", exit_code);
kernaux_console_printf("[WARN] syscall: process try to exit with error code %u, haha\n", exit_code);
}

View file

@ -1,12 +1,11 @@
#include "timer.h"
#include "logger.h"
#include <kernaux/arch/x86.h>
#include <kernaux/console.h>
void timer_initialize(unsigned int frequency)
{
logger_info_from("timer", "Initialize timer.");
kernaux_console_print("[INFO] timer: Initialize timer.\n");
const unsigned int divisor = 1193180 / frequency;