Move logging to separate module

This commit is contained in:
Alex Kotov 2022-11-29 02:39:43 +04:00
parent 85dab53e12
commit 7cb0b14893
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 28 additions and 3 deletions

View File

@ -20,7 +20,7 @@ CPPFLAGS = \
$(MRUBY_FLAGS) \ $(MRUBY_FLAGS) \
-DKERNAUX_DEBUG \ -DKERNAUX_DEBUG \
OBJS = start.S.o main.c.o libc.c.o OBJS = start.S.o main.c.o libc.c.o logger.c.o
all: $(MRUBYVISOR) all: $(MRUBYVISOR)

View File

@ -1,4 +1,5 @@
#include "libc.h" #include "libc.h"
#include "logger.h"
#include <stdlib.h> #include <stdlib.h>
@ -42,7 +43,7 @@ void my_abort()
void my_exit(const int status) void my_exit(const int status)
{ {
kernaux_drivers_console_printf("exit: %d\n", status); logger_exit(status);
kernaux_drivers_shutdown_poweroff(); kernaux_drivers_shutdown_poweroff();
// TODO: libkernaux shutdown poweroff noreturn // TODO: libkernaux shutdown poweroff noreturn

16
src/logger.c Normal file
View File

@ -0,0 +1,16 @@
#include "logger.h"
#include <kernaux/drivers/console.h>
void logger_assert(
const char *const file,
const int line,
const char *const str
) {
kernaux_drivers_console_printf("panic: %s:%u: \"%s\"\n", file, line, str);
}
void logger_exit(const int status)
{
kernaux_drivers_console_printf("exit: %d\n", status);
}

7
src/logger.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef INCLUDED_LOGGER
#define INCLUDED_LOGGER
void logger_assert(const char *file, int line, const char *str);
void logger_exit(int status);
#endif

View File

@ -1,4 +1,5 @@
#include "libc.h" #include "libc.h"
#include "logger.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@ -76,7 +77,7 @@ void main(
void assert(const char *const file, const int line, const char *const str) void assert(const char *const file, const int line, const char *const str)
{ {
kernaux_drivers_console_printf("panic: %s:%u: \"%s\"\n", file, line, str); logger_assert(file, line, str);
kernaux_drivers_shutdown_poweroff(); kernaux_drivers_shutdown_poweroff();
} }