mirror of
https://github.com/tailix/mrubyvisor.git
synced 2024-11-11 13:50:47 -05:00
Move panic/assert to separate module
This commit is contained in:
parent
cf40b5b917
commit
1225085ee1
4 changed files with 31 additions and 18 deletions
|
@ -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)
|
||||
|
||||
|
|
20
src/main.c
20
src/main.c
|
@ -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
16
src/panic.c
Normal 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
11
src/panic.h
Normal 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
|
Loading…
Reference in a new issue