Add simple stacktrace logging

This commit is contained in:
Sam Tebbs 2019-11-02 02:18:02 +00:00
parent 9d52e08ea7
commit f0161f0ec9
10 changed files with 477 additions and 14 deletions

View file

@ -10,7 +10,8 @@ const vga = @import("vga.zig");
const log = @import("log.zig");
const serial = @import("serial.zig");
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
const panic_root = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
const panic_root = if (is_test) @import(mock_path ++ "panic_mock.zig") else @import("panic.zig");
const options = @import("build_options");
comptime {
switch (builtin.arch) {
@ -26,14 +27,14 @@ export var KERNEL_ADDR_OFFSET: u32 = if (builtin.is_test) 0xC0000000 else undefi
// Just call the panic function, as this need to be in the root source file
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
@setCold(true);
panic_root(error_return_trace, "{}", msg);
panic_root.panic(error_return_trace, "{}", msg);
}
export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void {
if (mb_magic == multiboot.MULTIBOOT_BOOTLOADER_MAGIC) {
// Booted with compatible bootloader
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch |e| {
panic_root(@errorReturnTrace(), "Failed to initialise serial: {}", e);
panic_root.panic(@errorReturnTrace(), "Failed to initialise serial: {}", e);
};
if (build_options.rt_test)
log.runtimeTests();
@ -44,10 +45,15 @@ export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void {
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n");
arch.init(mb_info, &mem_profile, &fixed_allocator.allocator);
log.logInfo("Arch init done\n");
panic_root.init(&mem_profile, &fixed_allocator.allocator) catch |e| {
panic_root.panic(@errorReturnTrace(), "Failed to initialise panic: {}", e);
};
vga.init();
tty.init();
log.logInfo("Init done\n");
tty.print("Hello Pluto from kernel :)\n");
// The panic runtime tests must run last as they never return
if (options.rt_test) panic_root.runtimeTests();
}
}