Skip to content

Commit

Permalink
Fix dmesg allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratakor committed Oct 25, 2024
1 parent 4b39e6f commit 02262be
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions kernel/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions kernel/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion kernel/mm/vmm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions kernel/sched.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }

Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down

0 comments on commit 02262be

Please sign in to comment.