diff --git a/README.md b/README.md index 7710646..8501bea 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A kernel - Support RISC-V64, aarch64 and x86_64 - Replace @import("root") with @import("main.zig") to allow for testing - Replace limine with a custom bootloader? +- write core in zig and the rest in nov? # Clone, build and run Make sure to have `zig master`, `xorriso` and `qemu-system-x86` then run diff --git a/kernel/debug.zig b/kernel/debug.zig index f7431e1..f8e2ece 100644 --- a/kernel/debug.zig +++ b/kernel/debug.zig @@ -17,15 +17,14 @@ const debug_allocator = debug_fba.allocator(); var debug_info: ?std.debug.Dwarf = null; // https://github.com/ziglang/zig/issues/21233 -// var dmesg = blk: { -// var dmesg_sfa = std.heap.stackFallback(4096, root.allocator); -// break :blk std.ArrayList(u8).init(dmesg_sfa.get()); -// }; -var dmesg_fba_buffer: [1024 * 1024]u8 = undefined; -var dmesg_fba = std.heap.FixedBufferAllocator.init(&dmesg_fba_buffer); -var dmesg = std.ArrayList(u8).init(dmesg_fba.allocator()); +var dmesg_sfa = std.heap.stackFallback(4096, root.allocator); +var dmesg: std.ArrayList(u8) = undefined; const dmesg_writer = dmesg.writer(); +pub fn init() void { + dmesg = std.ArrayList(u8).init(dmesg_sfa.get()); +} + pub fn log( comptime level: std.log.Level, comptime scope: @TypeOf(.EnumLiteral), diff --git a/kernel/main.zig b/kernel/main.zig index 555d921..703c407 100644 --- a/kernel/main.zig +++ b/kernel/main.zig @@ -73,6 +73,7 @@ export fn _start() noreturn { arch.disableInterrupts(); std.debug.assert(base_revision.is_supported()); + debug.init(); serial.init(); arch.init(); pmm.init(); diff --git a/kernel/mm/vmm.zig b/kernel/mm/vmm.zig index 3413ec7..7694a81 100644 --- a/kernel/mm/vmm.zig +++ b/kernel/mm/vmm.zig @@ -18,7 +18,8 @@ const page_size = std.mem.page_size; // TODO: mapRange/unmapRange? // TODO: move paging code to paging.zig -// TODO: use ArenaAllocator for vmm +// TODO: use ArenaAllocator for vmm, especially where there is a lot of +// allocation in a loop or batch alloc/dealloc pub const MapError = error{ OutOfMemory, diff --git a/kernel/sched.zig b/kernel/sched.zig index 5b95237..a80becf 100644 --- a/kernel/sched.zig +++ b/kernel/sched.zig @@ -357,7 +357,7 @@ pub fn enqueue(thread: *Thread) !void { if (cpu.current_thread == null) { // only for debug build // fix to not crash when starting the first kernel thread - // if (comptime @import("builtin").mode == .Debug) { + // if (@import("builtin").mode == .Debug) { // if (cpu.id == smp.thisCpu().id) continue; // } @@ -415,7 +415,7 @@ fn schedHandler(ctx: *arch.Context) callconv(.SysV) void { current_thread.ctx = ctx.*; - if (comptime arch.arch == .x86_64) { + if (arch.arch == .x86_64) { current_thread.fs_base = arch.rdmsr(.fs_base); current_thread.cr3 = arch.readRegister("cr3"); arch.cpu.fpuSave(current_thread.fpu_storage); @@ -425,7 +425,7 @@ fn schedHandler(ctx: *arch.Context) callconv(.SysV) void { } if (maybe_next_thread) |next_thread| { - if (comptime arch.arch == .x86_64) { + if (arch.arch == .x86_64) { arch.wrmsr(.fs_base, next_thread.fs_base); cpu.current_thread = next_thread;