Move panic/assert to separate module

This commit is contained in:
Alex Kotov 2022-11-29 17:19:03 +04:00
parent cf40b5b917
commit 1225085ee1
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 31 additions and 18 deletions

View File

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

View File

@ -1,13 +1,12 @@
#include "libc.h"
#include "logger.h"
#include "panic.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <kernaux/assert.h>
#include <kernaux/drivers/console.h>
#include <kernaux/drivers/shutdown.h>
#include <kernaux/multiboot2.h>
#include <mruby.h>
@ -15,14 +14,9 @@
#include <mruby/proc.h>
#include <mruby/string.h>
#define PANIC(msg) (assert(__FILE__, __LINE__, msg))
#define ASSERT(cond) ((cond) ? (void)0 : PANIC(#cond))
static mrb_state *mrb = NULL;
static mrbc_context *context = NULL;
static void assert(const char *file, int line, const char *str);
static bool load_module(const char *source, size_t size, const char *cmdline);
static mrb_value ruby_console_puts(mrb_state *mrb, mrb_value self);
@ -31,12 +25,10 @@ void main(
const uint32_t multiboot2_info_magic,
const struct KernAux_Multiboot2_Info *const multiboot2_info
) {
kernaux_assert_cb = assert;
ASSERT(multiboot2_info_magic == KERNAUX_MULTIBOOT2_INFO_MAGIC);
panic_init();
libc_init();
ASSERT(multiboot2_info_magic == KERNAUX_MULTIBOOT2_INFO_MAGIC);
ASSERT(mrb = mrb_open());
ASSERT(context = mrbc_context_new(mrb));
@ -74,12 +66,6 @@ void main(
}
}
void assert(const char *const file, const int line, const char *const str)
{
logger_assert(file, line, str);
kernaux_drivers_shutdown_poweroff();
}
bool load_module(
const char *const source,
const size_t size,

16
src/panic.c Normal file
View File

@ -0,0 +1,16 @@
#include "logger.h"
#include "panic.h"
#include <kernaux/assert.h>
#include <kernaux/drivers/shutdown.h>
void panic_init()
{
kernaux_assert_cb = assert;
}
void assert(const char *const file, const int line, const char *const str)
{
logger_assert(file, line, str);
kernaux_drivers_shutdown_poweroff();
}

11
src/panic.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef INCLUDED_PANIC
#define INCLUDED_LOGGERPANIC
#define PANIC(msg) (assert(__FILE__, __LINE__, msg))
#define ASSERT(cond) ((cond) ? (void)0 : PANIC(#cond))
void panic_init();
void assert(const char *file, int line, const char *str);
#endif