Fix for TailQueue and std.log changes

This commit is contained in:
Sam Tebbs 2020-08-23 14:32:32 +01:00
parent fb66e2795f
commit b7c3084f09
24 changed files with 137 additions and 112 deletions

View file

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const log = std.log.scoped(.x86_arch);
const builtin = @import("builtin"); const builtin = @import("builtin");
const cmos = @import("cmos.zig"); const cmos = @import("cmos.zig");
const gdt = @import("gdt.zig"); const gdt = @import("gdt.zig");
@ -326,16 +327,16 @@ pub fn initTTY(boot_payload: BootPayload) TTY {
/// Allocator.Error.OutOfMemory - There wasn't enough memory in the allocated created to populate the memory profile, consider increasing mem.FIXED_ALLOC_SIZE /// Allocator.Error.OutOfMemory - There wasn't enough memory in the allocated created to populate the memory profile, consider increasing mem.FIXED_ALLOC_SIZE
/// ///
pub fn initMem(mb_info: BootPayload) Allocator.Error!MemProfile { pub fn initMem(mb_info: BootPayload) Allocator.Error!MemProfile {
std.log.info(.arch_x86, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.arch_x86, "Done\n", .{}); defer log.info("Done\n", .{});
std.log.debug(.arch_x86, "KERNEL_ADDR_OFFSET: 0x{X}\n", .{@ptrToInt(&KERNEL_ADDR_OFFSET)}); log.debug("KERNEL_ADDR_OFFSET: 0x{X}\n", .{@ptrToInt(&KERNEL_ADDR_OFFSET)});
std.log.debug(.arch_x86, "KERNEL_STACK_START: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_START)}); log.debug("KERNEL_STACK_START: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_START)});
std.log.debug(.arch_x86, "KERNEL_STACK_END: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_END)}); log.debug("KERNEL_STACK_END: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_END)});
std.log.debug(.arch_x86, "KERNEL_VADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_START)}); log.debug("KERNEL_VADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_START)});
std.log.debug(.arch_x86, "KERNEL_VADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_END)}); log.debug("KERNEL_VADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_END)});
std.log.debug(.arch_x86, "KERNEL_PHYSADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_START)}); log.debug("KERNEL_PHYSADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_START)});
std.log.debug(.arch_x86, "KERNEL_PHYSADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_END)}); log.debug("KERNEL_PHYSADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_END)});
const mods_count = mb_info.mods_count; const mods_count = mb_info.mods_count;
mem.ADDR_OFFSET = @ptrToInt(&KERNEL_ADDR_OFFSET); mem.ADDR_OFFSET = @ptrToInt(&KERNEL_ADDR_OFFSET);

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const log = std.log.scoped(.x86_gdt);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const panic = @import("../../panic.zig").panic; const panic = @import("../../panic.zig").panic;
@ -405,8 +406,8 @@ fn makeGdtEntry(base: u32, limit: u20, access: AccessBits, flags: FlagBits) GdtE
/// Initialise the Global Descriptor table. /// Initialise the Global Descriptor table.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.gdt, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.gdt, "Done\n", .{}); defer log.info("Done\n", .{});
// Initiate TSS // Initiate TSS
gdt_entries[TSS_INDEX] = makeGdtEntry(@ptrToInt(&main_tss_entry), @sizeOf(Tss) - 1, TSS_SEGMENT, NULL_FLAGS); gdt_entries[TSS_INDEX] = makeGdtEntry(@ptrToInt(&main_tss_entry), @sizeOf(Tss) - 1, TSS_SEGMENT, NULL_FLAGS);
@ -567,7 +568,7 @@ fn rt_loadedGDTSuccess() void {
if (gdt_ptr.base != loaded_gdt.base) { if (gdt_ptr.base != loaded_gdt.base) {
panic(@errorReturnTrace(), "FAILURE: GDT not loaded properly: 0x{X} != {X}\n", .{ gdt_ptr.base, loaded_gdt.base }); panic(@errorReturnTrace(), "FAILURE: GDT not loaded properly: 0x{X} != {X}\n", .{ gdt_ptr.base, loaded_gdt.base });
} }
std.log.info(.gdt, "Tested loading GDT\n", .{}); log.info("Tested loading GDT\n", .{});
} }
/// ///

View file

@ -2,6 +2,7 @@ const std = @import("std");
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const log = std.log.scoped(.x86_idt);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const panic = @import("../../panic.zig").panic; const panic = @import("../../panic.zig").panic;
@ -178,8 +179,8 @@ pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void {
/// Initialise the Interrupt descriptor table /// Initialise the Interrupt descriptor table
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.idt, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.idt, "Done\n", .{}); defer log.info("Done\n", .{});
idt_ptr.base = @ptrToInt(&idt_entries); idt_ptr.base = @ptrToInt(&idt_entries);
@ -333,7 +334,7 @@ fn rt_loadedIDTSuccess() void {
if (idt_ptr.base != loaded_idt.base) { if (idt_ptr.base != loaded_idt.base) {
panic(@errorReturnTrace(), "FAILURE: IDT not loaded properly: 0x{X} != {X}\n", .{ idt_ptr.base, loaded_idt.base }); panic(@errorReturnTrace(), "FAILURE: IDT not loaded properly: 0x{X} != {X}\n", .{ idt_ptr.base, loaded_idt.base });
} }
std.log.info(.idt, " Tested loading IDT\n", .{}); log.info("Tested loading IDT\n", .{});
} }
/// ///

View file

@ -4,6 +4,7 @@ const is_test = builtin.is_test;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const log = std.log.scoped(.x86_irq);
const build_options = @import("build_options"); const build_options = @import("build_options");
const panic = @import("../../panic.zig").panic; const panic = @import("../../panic.zig").panic;
const mock_path = build_options.arch_mock_path; const mock_path = build_options.arch_mock_path;
@ -130,8 +131,8 @@ pub fn registerIrq(irq_num: u8, handler: IrqHandler) IrqError!void {
/// the IDT interrupt gates for each IRQ. /// the IDT interrupt gates for each IRQ.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.irq, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.irq, "Done\n", .{}); defer log.info("Done\n", .{});
comptime var i = IRQ_OFFSET; comptime var i = IRQ_OFFSET;
inline while (i < IRQ_OFFSET + 16) : (i += 1) { inline while (i < IRQ_OFFSET + 16) : (i += 1) {
@ -246,7 +247,7 @@ fn rt_unregisteredHandlers() void {
} }
} }
std.log.info(.irq, "Tested registered handlers\n", .{}); log.info("Tested registered handlers\n", .{});
} }
/// ///
@ -264,7 +265,7 @@ fn rt_openedIdtEntries() void {
} }
} }
std.log.info(.irq, "Tested opened IDT entries\n", .{}); log.info("Tested opened IDT entries\n", .{});
} }
/// ///

View file

@ -4,6 +4,7 @@ const is_test = builtin.is_test;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const log = std.log.scoped(.x86_isr);
const build_options = @import("build_options"); const build_options = @import("build_options");
const mock_path = build_options.arch_mock_path; const mock_path = build_options.arch_mock_path;
const syscalls = @import("syscalls.zig"); const syscalls = @import("syscalls.zig");
@ -158,7 +159,7 @@ export fn isrHandler(ctx: *arch.CpuState) usize {
// Regular ISR exception, if there is one registered. // Regular ISR exception, if there is one registered.
ret_esp = handler(ctx); ret_esp = handler(ctx);
} else { } else {
std.log.info(.isr, "State: {X}\n", .{ctx}); log.info("State: {X}\n", .{ctx});
panic(@errorReturnTrace(), "ISR {} ({}) triggered with error code 0x{X} but not registered\n", .{ exception_msg[isr_num], isr_num, ctx.error_code }); panic(@errorReturnTrace(), "ISR {} ({}) triggered with error code 0x{X} but not registered\n", .{ exception_msg[isr_num], isr_num, ctx.error_code });
} }
} }
@ -237,8 +238,8 @@ pub fn registerIsr(isr_num: u16, handler: IsrHandler) IsrError!void {
/// Initialise the exception and opening up all the IDT interrupt gates for each exception. /// Initialise the exception and opening up all the IDT interrupt gates for each exception.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.isr, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.isr, "Done\n", .{}); defer log.info("Done\n", .{});
comptime var i = 0; comptime var i = 0;
inline while (i < 32) : (i += 1) { inline while (i < 32) : (i += 1) {
@ -384,7 +385,7 @@ fn rt_unregisteredHandlers() void {
panic(@errorReturnTrace(), "FAILURE: Pre-testing failed for syscall: {}\n", .{h}); panic(@errorReturnTrace(), "FAILURE: Pre-testing failed for syscall: {}\n", .{h});
} }
std.log.info(.isr, "Tested registered handlers\n", .{}); log.info("Tested registered handlers\n", .{});
} }
/// ///
@ -402,7 +403,7 @@ fn rt_openedIdtEntries() void {
} }
} }
std.log.info(.isr, "Tested opened IDT entries\n", .{}); log.info("Tested opened IDT entries\n", .{});
} }
/// ///

View file

@ -3,10 +3,10 @@ const build_options = @import("build_options");
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const testing = std.testing; const testing = std.testing;
const log = std.log.scoped(.x86_keyboard);
const irq = @import("irq.zig"); const irq = @import("irq.zig");
const pic = @import("pic.zig"); const pic = @import("pic.zig");
const arch = if (builtin.is_test) @import(build_options.arch_mock_path ++ "arch_mock.zig") else @import("arch.zig"); const arch = if (builtin.is_test) @import(build_options.arch_mock_path ++ "arch_mock.zig") else @import("arch.zig");
const log = if (builtin.is_test) @import(build_options.arch_mock_path ++ "log_mock.zig") else @import("../../log.zig");
const panic = @import("../../panic.zig").panic; const panic = @import("../../panic.zig").panic;
const kb = @import("../../keyboard.zig"); const kb = @import("../../keyboard.zig");
const Keyboard = kb.Keyboard; const Keyboard = kb.Keyboard;
@ -164,7 +164,7 @@ fn onKeyEvent(ctx: *arch.CpuState) usize {
const scan_code = readKeyboardBuffer(); const scan_code = readKeyboardBuffer();
if (parseScanCode(scan_code)) |action| { if (parseScanCode(scan_code)) |action| {
if (!keyboard.writeKey(action)) { if (!keyboard.writeKey(action)) {
std.log.notice(.x86_keyboard, "No room for keyboard action {}\n", .{action}); log.notice("No room for keyboard action {}\n", .{action});
} }
} }
return @ptrToInt(ctx); return @ptrToInt(ctx);

View file

@ -2,6 +2,7 @@ const std = @import("std");
const testing = std.testing; const testing = std.testing;
const expectEqual = testing.expectEqual; const expectEqual = testing.expectEqual;
const expect = testing.expect; const expect = testing.expect;
const log = std.log.scoped(.x86_paging);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const panic = @import("../../panic.zig").panic; const panic = @import("../../panic.zig").panic;
@ -383,7 +384,7 @@ pub fn unmap(virtual_start: usize, virtual_end: usize, dir: *Directory) (Allocat
/// IN state: *arch.CpuState - The CPU's state when the fault occurred. /// IN state: *arch.CpuState - The CPU's state when the fault occurred.
/// ///
fn pageFault(state: *arch.CpuState) u32 { fn pageFault(state: *arch.CpuState) u32 {
std.log.info(.paging, "State: {X}\n", .{state}); log.info("State: {X}\n", .{state});
var cr0 = asm volatile ("mov %%cr0, %[cr0]" var cr0 = asm volatile ("mov %%cr0, %[cr0]"
: [cr0] "=r" (-> u32) : [cr0] "=r" (-> u32)
); );
@ -396,7 +397,7 @@ fn pageFault(state: *arch.CpuState) u32 {
var cr4 = asm volatile ("mov %%cr4, %[cr4]" var cr4 = asm volatile ("mov %%cr4, %[cr4]"
: [cr4] "=r" (-> u32) : [cr4] "=r" (-> u32)
); );
std.log.info(.paging, "CR0: 0x{X}, CR2: 0x{X}, CR3: 0x{X}, CR4: 0x{X}\n", .{ cr0, cr2, cr3, cr4 }); log.info("CR0: 0x{X}, CR2: 0x{X}, CR3: 0x{X}, CR4: 0x{X}\n", .{ cr0, cr2, cr3, cr4 });
@panic("Page fault"); @panic("Page fault");
} }
@ -407,8 +408,8 @@ fn pageFault(state: *arch.CpuState) u32 {
/// IN mem_profile: *const MemProfile - The memory profile of the system and kernel /// IN mem_profile: *const MemProfile - The memory profile of the system and kernel
/// ///
pub fn init(mem_profile: *const MemProfile) void { pub fn init(mem_profile: *const MemProfile) void {
std.log.info(.paging, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.paging, "Done\n", .{}); defer log.info("Done\n", .{});
isr.registerIsr(isr.PAGE_FAULT, if (build_options.test_mode == .Initialisation) rt_pageFault else pageFault) catch |e| { isr.registerIsr(isr.PAGE_FAULT, if (build_options.test_mode == .Initialisation) rt_pageFault else pageFault) catch |e| {
panic(@errorReturnTrace(), "Failed to register page fault ISR: {}\n", .{e}); panic(@errorReturnTrace(), "Failed to register page fault ISR: {}\n", .{e});
@ -594,7 +595,7 @@ fn rt_accessUnmappedMem(v_end: u32) void {
var ptr = @intToPtr(*u8, v_end); var ptr = @intToPtr(*u8, v_end);
var value = ptr.*; var value = ptr.*;
// Need this as in release builds the above is optimised out so it needs to be use // Need this as in release builds the above is optimised out so it needs to be use
std.log.emerg(.paging, "FAILURE: Value: {}\n", .{value}); log.emerg("FAILURE: Value: {}\n", .{value});
// This is the label that we return to after processing the page fault // This is the label that we return to after processing the page fault
asm volatile ( asm volatile (
\\.global rt_fault_callback \\.global rt_fault_callback
@ -603,7 +604,7 @@ fn rt_accessUnmappedMem(v_end: u32) void {
if (!faulted) { if (!faulted) {
panic(@errorReturnTrace(), "FAILURE: Paging should have faulted\n", .{}); panic(@errorReturnTrace(), "FAILURE: Paging should have faulted\n", .{});
} }
std.log.info(.paging, "Tested accessing unmapped memory\n", .{}); log.info("Tested accessing unmapped memory\n", .{});
} }
fn rt_accessMappedMem(v_end: u32) void { fn rt_accessMappedMem(v_end: u32) void {
@ -619,7 +620,7 @@ fn rt_accessMappedMem(v_end: u32) void {
if (faulted) { if (faulted) {
panic(@errorReturnTrace(), "FAILURE: Paging shouldn't have faulted\n", .{}); panic(@errorReturnTrace(), "FAILURE: Paging shouldn't have faulted\n", .{});
} }
std.log.info(.paging, "Tested accessing mapped memory\n", .{}); log.info("Tested accessing mapped memory\n", .{});
} }
pub fn runtimeTests(v_end: u32) void { pub fn runtimeTests(v_end: u32) void {

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const log = std.log.scoped(.x86_pic);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const build_options = @import("build_options"); const build_options = @import("build_options");
@ -431,8 +432,8 @@ pub fn clearMask(irq_num: u8) void {
/// by Intel up to 0x1F. So this will move the IRQs from 0x00-0x0F to 0x20-0x2F. /// by Intel up to 0x1F. So this will move the IRQs from 0x00-0x0F to 0x20-0x2F.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.pic, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.pic, "Done\n", .{}); defer log.info("Done\n", .{});
// Initiate // Initiate
sendCommandMaster(ICW1_INITIALISATION | ICW1_EXPECT_ICW4); sendCommandMaster(ICW1_INITIALISATION | ICW1_EXPECT_ICW4);
@ -823,7 +824,7 @@ fn rt_picAllMasked() void {
panic(@errorReturnTrace(), "FAILURE: Slave masks are not set, found: {}\n", .{readDataSlave()}); panic(@errorReturnTrace(), "FAILURE: Slave masks are not set, found: {}\n", .{readDataSlave()});
} }
std.log.info(.pic, "Tested masking\n", .{}); log.info("Tested masking\n", .{});
} }
/// ///

View file

@ -5,6 +5,7 @@ const is_test = builtin.is_test;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const log = std.log.scoped(.x86_pit);
const build_options = @import("build_options"); const build_options = @import("build_options");
const mock_path = build_options.arch_mock_path; const mock_path = build_options.arch_mock_path;
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig"); const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
@ -362,8 +363,8 @@ pub fn getFrequency() u32 {
/// Initialise the PIT with a handler to IRQ 0. /// Initialise the PIT with a handler to IRQ 0.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.pit, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.pit, "Done\n", .{}); defer log.info("Done\n", .{});
// Set up counter 0 at 10000hz in a square wave mode counting in binary // Set up counter 0 at 10000hz in a square wave mode counting in binary
const freq: u32 = 10000; const freq: u32 = 10000;
@ -371,7 +372,7 @@ pub fn init() void {
panic(@errorReturnTrace(), "Invalid frequency: {}\n", .{freq}); panic(@errorReturnTrace(), "Invalid frequency: {}\n", .{freq});
}; };
std.log.debug(.pit, "Set frequency at: {}Hz, real frequency: {}Hz\n", .{ freq, getFrequency() }); log.debug("Set frequency at: {}Hz, real frequency: {}Hz\n", .{ freq, getFrequency() });
// Installs 'pitHandler' to IRQ0 (pic.IRQ_PIT) // Installs 'pitHandler' to IRQ0 (pic.IRQ_PIT)
irq.registerIrq(pic.IRQ_PIT, pitHandler) catch |err| switch (err) { irq.registerIrq(pic.IRQ_PIT, pitHandler) catch |err| switch (err) {
@ -549,7 +550,7 @@ fn rt_waitTicks() void {
panic(@errorReturnTrace(), "FAILURE: Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", .{ difference, previous_count, epsilon }); panic(@errorReturnTrace(), "FAILURE: Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", .{ difference, previous_count, epsilon });
} }
std.log.info(.pit, "Tested wait ticks\n", .{}); log.info("Tested wait ticks\n", .{});
} }
/// ///
@ -576,7 +577,7 @@ fn rt_waitTicks2() void {
// Reset ticks // Reset ticks
ticks = 0; ticks = 0;
std.log.info(.pit, "Tested wait ticks 2\n", .{}); log.info("Tested wait ticks 2\n", .{});
} }
/// ///
@ -621,7 +622,7 @@ fn rt_initCounter_0() void {
panic(@errorReturnTrace(), "FAILURE: Operating mode don't not set properly. Found: {}, expecting: {}\n", .{ actual_mode, expected_mode }); panic(@errorReturnTrace(), "FAILURE: Operating mode don't not set properly. Found: {}, expecting: {}\n", .{ actual_mode, expected_mode });
} }
std.log.info(.pit, "Tested init\n", .{}); log.info("Tested init\n", .{});
} }
/// ///

View file

@ -4,6 +4,7 @@ const is_test = builtin.is_test;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const log = std.log.scoped(.x86_rtc);
const build_options = @import("build_options"); const build_options = @import("build_options");
const mock_path = build_options.arch_mock_path; const mock_path = build_options.arch_mock_path;
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig"); const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
@ -265,8 +266,8 @@ fn enableInterrupts() void {
/// Initialise the RTC. /// Initialise the RTC.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.rtc, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.rtc, "Done\n", .{}); defer log.info("Done\n", .{});
// Register the interrupt handler // Register the interrupt handler
irq.registerIrq(pic.IRQ_REAL_TIME_CLOCK, rtcHandler) catch |err| switch (err) { irq.registerIrq(pic.IRQ_REAL_TIME_CLOCK, rtcHandler) catch |err| switch (err) {
@ -726,7 +727,7 @@ fn rt_init() void {
panic(@errorReturnTrace(), "FAILURE: Interrupts not enabled\n", .{}); panic(@errorReturnTrace(), "FAILURE: Interrupts not enabled\n", .{});
} }
std.log.info(.rtc, "Tested init\n", .{}); log.info("Tested init\n", .{});
} }
/// ///
@ -741,7 +742,7 @@ fn rt_interrupts() void {
panic(@errorReturnTrace(), "FAILURE: No interrupt happened\n", .{}); panic(@errorReturnTrace(), "FAILURE: No interrupt happened\n", .{});
} }
std.log.info(.rtc, "Tested interrupts\n", .{}); log.info("Tested interrupts\n", .{});
} }
/// ///

View file

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const log = std.log.scoped(.x86_syscalls);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const build_options = @import("build_options"); const build_options = @import("build_options");
@ -57,10 +58,10 @@ fn handle(ctx: *arch.CpuState) u32 {
if (handlers[syscall]) |handler| { if (handlers[syscall]) |handler| {
ctx.eax = handler(ctx, syscallArg(ctx, 0), syscallArg(ctx, 1), syscallArg(ctx, 2), syscallArg(ctx, 3), syscallArg(ctx, 4)); ctx.eax = handler(ctx, syscallArg(ctx, 0), syscallArg(ctx, 1), syscallArg(ctx, 2), syscallArg(ctx, 3), syscallArg(ctx, 4));
} else { } else {
std.log.warn(.syscall, "Syscall {} triggered but not registered\n", .{syscall}); log.warn("Syscall {} triggered but not registered\n", .{syscall});
} }
} else { } else {
std.log.warn(.syscall, "Syscall {} is invalid\n", .{syscall}); log.warn("Syscall {} is invalid\n", .{syscall});
} }
return @ptrToInt(ctx); return @ptrToInt(ctx);
} }
@ -242,8 +243,8 @@ inline fn syscallArg(ctx: *arch.CpuState, comptime arg_idx: u32) u32 {
/// Initialise syscalls. Registers the isr associated with INTERRUPT. /// Initialise syscalls. Registers the isr associated with INTERRUPT.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.syscall, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.syscall, "Done\n", .{}); defer log.info("Done\n", .{});
isr.registerIsr(INTERRUPT, handle) catch unreachable; isr.registerIsr(INTERRUPT, handle) catch unreachable;
@ -330,5 +331,5 @@ fn runtimeTests() void {
panic(@errorReturnTrace(), "FAILURE syscall5\n", .{}); panic(@errorReturnTrace(), "FAILURE syscall5\n", .{});
} }
std.log.info(.syscall, "Tested all args\n", .{}); log.info("Tested all args\n", .{});
} }

View file

@ -5,6 +5,7 @@ const is_test = builtin.is_test;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const log = std.log.scoped(.x86_tty);
const build_options = @import("build_options"); const build_options = @import("build_options");
const mock_path = build_options.mock_path; const mock_path = build_options.mock_path;
const vga = if (is_test) @import("../../" ++ mock_path ++ "vga_mock.zig") else @import("vga.zig"); const vga = if (is_test) @import("../../" ++ mock_path ++ "vga_mock.zig") else @import("vga.zig");
@ -380,7 +381,7 @@ pub fn pageUp() void {
page_index += 1; page_index += 1;
// Bounds have been checked, so shouldn't error // Bounds have been checked, so shouldn't error
videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| { videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| {
std.log.crit(.tty, "Error moving page up. Error: {}\n", .{e}); log.crit("Error moving page up. Error: {}\n", .{e});
}; };
vga.disableCursor(); vga.disableCursor();
} }
@ -396,7 +397,7 @@ pub fn pageDown() void {
page_index -= 1; page_index -= 1;
// Bounds have been checked, so shouldn't error // Bounds have been checked, so shouldn't error
videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| { videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| {
std.log.crit(.tty, "Error moving page down. Error: {}\n", .{e}); log.crit("Error moving page down. Error: {}\n", .{e});
}; };
if (page_index == 0) { if (page_index == 0) {
@ -416,7 +417,7 @@ pub fn clearScreen() void {
// Move all the rows up // Move all the rows up
// This is within bounds, so shouldn't error // This is within bounds, so shouldn't error
pagesMoveRowsUp(ROW_TOTAL) catch |e| { pagesMoveRowsUp(ROW_TOTAL) catch |e| {
std.log.crit(.tty, "Error moving all pages up. Error: {}\n", .{e}); log.crit("Error moving all pages up. Error: {}\n", .{e});
}; };
// Clear the screen // Clear the screen
@ -535,13 +536,13 @@ pub fn init() void {
// Set the top 7 rows blank // Set the top 7 rows blank
setVideoBuffer(blank, START_OF_DISPLAYABLE_REGION) catch |e| { setVideoBuffer(blank, START_OF_DISPLAYABLE_REGION) catch |e| {
std.log.crit(.tty, "Error clearing the top 7 rows. Error: {}\n", .{e}); log.crit("Error clearing the top 7 rows. Error: {}\n", .{e});
}; };
row += @truncate(u8, row_offset + ROW_MIN); row += @truncate(u8, row_offset + ROW_MIN);
} else { } else {
// Clear the screen // Clear the screen
setVideoBuffer(blank, VIDEO_BUFFER_SIZE) catch |e| { setVideoBuffer(blank, VIDEO_BUFFER_SIZE) catch |e| {
std.log.crit(.tty, "Error clearing the screen. Error: {}\n", .{e}); log.crit("Error clearing the screen. Error: {}\n", .{e});
}; };
// Set the row to below the logo // Set the row to below the logo
row = ROW_MIN; row = ROW_MIN;
@ -900,7 +901,7 @@ test "putEntryAt in displayable region page_index is not 0" {
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len); column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
row = ROW_MIN - 1; row = ROW_MIN - 1;
writeString(text) catch |e| { writeString(text) catch |e| {
std.log.crit(.tty, "Unable to print page number, printing out of bounds. Error: {}\n", .{e}); log.crit("Unable to print page number, printing out of bounds. Error: {}\n", .{e});
}; };
column = column_temp; column = column_temp;
row = row_temp; row = row_temp;
@ -1558,7 +1559,7 @@ test "pageUp bottom page" {
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len); column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
row = ROW_MIN - 1; row = ROW_MIN - 1;
writeString(text) catch |e| { writeString(text) catch |e| {
std.log.crit(.tty, "Unable to print page number, printing out of bounds. Error: {}\n", .{e}); log.crit("Unable to print page number, printing out of bounds. Error: {}\n", .{e});
}; };
column = column_temp; column = column_temp;
row = row_temp; row = row_temp;
@ -1638,7 +1639,7 @@ test "pageDown top page" {
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len); column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
row = ROW_MIN - 1; row = ROW_MIN - 1;
writeString(text) catch |e| { writeString(text) catch |e| {
std.log.crit(.tty, "Unable to print page number, printing out of bounds. Error: {}\n", .{e}); log.crit("Unable to print page number, printing out of bounds. Error: {}\n", .{e});
}; };
column = column_temp; column = column_temp;
row = row_temp; row = row_temp;
@ -2044,7 +2045,7 @@ fn rt_initialisedGlobals() void {
panic(@errorReturnTrace(), "Screen all blank, should have logo and page number\n", .{}); panic(@errorReturnTrace(), "Screen all blank, should have logo and page number\n", .{});
} }
std.log.info(.tty, "Tested globals\n", .{}); log.info("Tested globals\n", .{});
} }
/// ///
@ -2096,7 +2097,7 @@ fn rt_printString() void {
// Clear the text // Clear the text
writeString(clear_text) catch |e| panic(@errorReturnTrace(), "Failed to print string to tty: {}\n", .{e}); writeString(clear_text) catch |e| panic(@errorReturnTrace(), "Failed to print string to tty: {}\n", .{e});
std.log.info(.tty, "Tested printing\n", .{}); log.info("Tested printing\n", .{});
} }
/// ///

View file

@ -2,6 +2,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const log = std.log.scoped(.x86_vga);
const build_options = @import("build_options"); const build_options = @import("build_options");
const arch = if (is_test) @import(build_options.arch_mock_path ++ "arch_mock.zig") else @import("arch.zig"); const arch = if (is_test) @import(build_options.arch_mock_path ++ "arch_mock.zig") else @import("arch.zig");
const panic = @import("../../panic.zig").panic; const panic = @import("../../panic.zig").panic;
@ -283,8 +284,8 @@ pub fn setCursorShape(shape: CursorShape) void {
/// Initialise the VGA text mode. This sets the cursor and underline shape. /// Initialise the VGA text mode. This sets the cursor and underline shape.
/// ///
pub fn init() void { pub fn init() void {
std.log.info(.vga, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.vga, "Done\n", .{}); defer log.info("Done\n", .{});
// Set the maximum scan line to 0x0F // Set the maximum scan line to 0x0F
sendPortData(REG_MAXIMUM_SCAN_LINE, CURSOR_SCANLINE_END); sendPortData(REG_MAXIMUM_SCAN_LINE, CURSOR_SCANLINE_END);
@ -536,7 +537,7 @@ fn rt_correctMaxScanLine() void {
panic(@errorReturnTrace(), "FAILURE: Max scan line not {}, found {}\n", .{ CURSOR_SCANLINE_END, max_scan_line }); panic(@errorReturnTrace(), "FAILURE: Max scan line not {}, found {}\n", .{ CURSOR_SCANLINE_END, max_scan_line });
} }
std.log.info(.vga, "Tested max scan line\n", .{}); log.info("Tested max scan line\n", .{});
} }
/// ///
@ -555,7 +556,7 @@ fn rt_correctCursorShape() void {
panic(@errorReturnTrace(), "FAILURE: Cursor scanline are incorrect. Start: {}, end: {}\n", .{ cursor_start, cursor_end }); panic(@errorReturnTrace(), "FAILURE: Cursor scanline are incorrect. Start: {}, end: {}\n", .{ cursor_start, cursor_end });
} }
std.log.info(.vga, "Tested cursor shape\n", .{}); log.info("Tested cursor shape\n", .{});
} }
/// ///
@ -587,7 +588,7 @@ fn rt_setCursorGetCursor() void {
// Restore the previous x and y // Restore the previous x and y
updateCursor(prev_x_loc, prev_y_loc); updateCursor(prev_x_loc, prev_y_loc);
std.log.info(.vga, "Tested updating cursor\n", .{}); log.info("Tested updating cursor\n", .{});
} }
/// ///

View file

@ -5,6 +5,7 @@ const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const expectEqualSlices = std.testing.expectEqualSlices; const expectEqualSlices = std.testing.expectEqualSlices;
const log = std.log.scoped(.initrd);
const build_options = @import("build_options"); const build_options = @import("build_options");
const mock_path = build_options.mock_path; const mock_path = build_options.mock_path;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
@ -150,8 +151,8 @@ pub const InitrdFS = struct {
/// allocated will be freed. /// allocated will be freed.
/// ///
pub fn init(stream: *std.io.FixedBufferStream([]u8), allocator: *Allocator) (Error || error{EndOfStream} || Allocator.Error)!*InitrdFS { pub fn init(stream: *std.io.FixedBufferStream([]u8), allocator: *Allocator) (Error || error{EndOfStream} || Allocator.Error)!*InitrdFS {
std.log.info(.initrd, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.initrd, "Done\n", .{}); defer log.info("Done\n", .{});
// First @sizeOf(usize) bytes is the number of files // First @sizeOf(usize) bytes is the number of files
const num_of_files = try stream.reader().readIntNative(usize); const num_of_files = try stream.reader().readIntNative(usize);
@ -658,7 +659,7 @@ fn rt_openReadClose(allocator: *Allocator) void {
error.NoSuchFileOrDir => {}, error.NoSuchFileOrDir => {},
else => panic(@errorReturnTrace(), "FAILURE: Expected error\n", .{}), else => panic(@errorReturnTrace(), "FAILURE: Expected error\n", .{}),
}; };
std.log.info(.initrd, "Opened, read and closed\n", .{}); log.info("Opened, read and closed\n", .{});
} }
/// ///

View file

@ -446,23 +446,26 @@ const TestFS = struct {
} }
// Form a list containing all directory nodes to check via a breadth-first search // Form a list containing all directory nodes to check via a breadth-first search
// This is inefficient but good for testing as it's clear and easy to modify // This is inefficient but good for testing as it's clear and easy to modify
var to_check = TailQueue(*TreeNode).init(); var to_check = TailQueue(*TreeNode){};
var root_node = try to_check.createNode(&test_fs.tree, test_fs.allocator); var root_node = try test_fs.allocator.create(TailQueue(*TreeNode).Node);
root_node.* = .{ .data = &test_fs.tree };
to_check.append(root_node); to_check.append(root_node);
while (to_check.popFirst()) |queue_node| { while (to_check.popFirst()) |queue_node| {
var tree_node = queue_node.data; var tree_node = queue_node.data;
to_check.destroyNode(queue_node, test_fs.allocator); test_fs.allocator.destroy(queue_node);
if ((@TypeOf(node) == *const FileNode and tree_node.val.isFile() and &tree_node.val.File == node) or (@TypeOf(node) == *const DirNode and tree_node.val.isDir() and &tree_node.val.Dir == node) or (@TypeOf(node) == *const Node and &tree_node.val == node)) { if ((@TypeOf(node) == *const FileNode and tree_node.val.isFile() and &tree_node.val.File == node) or (@TypeOf(node) == *const DirNode and tree_node.val.isDir() and &tree_node.val.Dir == node) or (@TypeOf(node) == *const Node and &tree_node.val == node)) {
// Clean up any unused queue nodes // Clean up any unused queue nodes
while (to_check.popFirst()) |t_node| { while (to_check.popFirst()) |t_node| {
to_check.destroyNode(t_node, test_fs.allocator); test_fs.allocator.destroy(t_node);
} }
return tree_node; return tree_node;
} }
for (tree_node.children.items) |child| { for (tree_node.children.items) |child| {
// It's not the parent so add its children to the list for checking // It's not the parent so add its children to the list for checking
to_check.append(try to_check.createNode(child, test_fs.allocator)); var n = try test_fs.allocator.create(TailQueue(*TreeNode).Node);
n.* = .{ .data = child };
to_check.append(n);
} }
} }
return null; return null;

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const testing = std.testing; const testing = std.testing;
const log = std.log.scoped(.heap);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const build_options = @import("build_options"); const build_options = @import("build_options");
@ -601,8 +602,8 @@ const FreeListAllocator = struct {
/// Allocator.Error.OutOfMemory - heap_vmm's allocator didn't have enough memory available to fulfill the request /// Allocator.Error.OutOfMemory - heap_vmm's allocator didn't have enough memory available to fulfill the request
/// ///
pub fn init(comptime vmm_payload: type, heap_vmm: *vmm.VirtualMemoryManager(vmm_payload), attributes: vmm.Attributes, heap_size: usize) (FreeListAllocator.Error || Allocator.Error)!FreeListAllocator { pub fn init(comptime vmm_payload: type, heap_vmm: *vmm.VirtualMemoryManager(vmm_payload), attributes: vmm.Attributes, heap_size: usize) (FreeListAllocator.Error || Allocator.Error)!FreeListAllocator {
std.log.info(.heap, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.heap, "Done\n", .{}); defer log.info("Done\n", .{});
var heap_start = (try heap_vmm.alloc(heap_size / vmm.BLOCK_SIZE, attributes)) orelse panic(null, "Not enough contiguous virtual memory blocks to allocate to kernel heap\n", .{}); var heap_start = (try heap_vmm.alloc(heap_size / vmm.BLOCK_SIZE, attributes)) orelse panic(null, "Not enough contiguous virtual memory blocks to allocate to kernel heap\n", .{});
// This free call cannot error as it is guaranteed to have been allocated above // This free call cannot error as it is guaranteed to have been allocated above
errdefer heap_vmm.free(heap_start) catch unreachable; errdefer heap_vmm.free(heap_start) catch unreachable;

View file

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const logger = std.log.scoped(.kmain);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const build_options = @import("build_options"); const build_options = @import("build_options");
@ -78,9 +79,9 @@ export fn kmain(boot_payload: arch.BootPayload) void {
panic_root.panic(@errorReturnTrace(), "Failed to initialise kernel VMM: {}", .{e}); panic_root.panic(@errorReturnTrace(), "Failed to initialise kernel VMM: {}", .{e});
}; };
std.log.info(.kmain, "Init arch " ++ @tagName(builtin.arch) ++ "\n", .{}); logger.info("Init arch " ++ @tagName(builtin.arch) ++ "\n", .{});
arch.init(&mem_profile); arch.init(&mem_profile);
std.log.info(.kmain, "Arch init done\n", .{}); logger.info("Arch init done\n", .{});
// Give the kernel heap 10% of the available memory. This can be fine-tuned as time goes on. // Give the kernel heap 10% of the available memory. This can be fine-tuned as time goes on.
var heap_size = mem_profile.mem_kb / 10 * 1024; var heap_size = mem_profile.mem_kb / 10 * 1024;
@ -133,12 +134,12 @@ export fn kmain(boot_payload: arch.BootPayload) void {
} }
// Initialisation is finished, now does other stuff // Initialisation is finished, now does other stuff
std.log.info(.kmain, "Init\n", .{}); logger.info("Init\n", .{});
// Main initialisation finished so can enable interrupts // Main initialisation finished so can enable interrupts
arch.enableInterrupts(); arch.enableInterrupts();
std.log.info(.kmain, "Creating init2\n", .{}); logger.info("Creating init2\n", .{});
// Create a init2 task // Create a init2 task
var idle_task = task.Task.create(initStage2, &kernel_heap.allocator) catch |e| { var idle_task = task.Task.create(initStage2, &kernel_heap.allocator) catch |e| {
@ -173,7 +174,7 @@ fn initStage2() noreturn {
switch (build_options.test_mode) { switch (build_options.test_mode) {
.Initialisation => { .Initialisation => {
std.log.info(.kmain, "SUCCESS\n", .{}); logger.info("SUCCESS\n", .{});
}, },
else => {}, else => {},
} }

View file

@ -8,6 +8,7 @@ const build_options = @import("build_options");
const ArrayList = std.ArrayList; const ArrayList = std.ArrayList;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const testing = std.testing; const testing = std.testing;
const log = std.log.scoped(.panic);
/// The possible errors from panic code /// The possible errors from panic code
const PanicError = error{ const PanicError = error{
@ -111,7 +112,7 @@ var symbol_map: ?SymbolMap = null;
/// ///
fn logTraceAddress(addr: usize) void { fn logTraceAddress(addr: usize) void {
const str = if (symbol_map) |syms| syms.search(addr) orelse "?????" else "(no symbols available)"; const str = if (symbol_map) |syms| syms.search(addr) orelse "?????" else "(no symbols available)";
std.log.emerg(.panic, "{x}: {}\n", .{ addr, str }); log.emerg("{x}: {}\n", .{ addr, str });
} }
/// ///
@ -278,7 +279,7 @@ fn parseMapEntry(start: *[*]const u8, end: *const u8) (PanicError || std.fmt.Par
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn { pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn {
@setCold(true); @setCold(true);
std.log.emerg(.panic, "Kernel panic: " ++ format ++ "\n", args); log.emerg("Kernel panic: " ++ format ++ "\n", args);
if (trace) |trc| { if (trace) |trc| {
var last_addr: u64 = 0; var last_addr: u64 = 0;
for (trc.instruction_addresses) |ret_addr| { for (trc.instruction_addresses) |ret_addr| {
@ -312,8 +313,8 @@ pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: any
/// std.fmt.ParseIntError - See parseMapEntry. /// std.fmt.ParseIntError - See parseMapEntry.
/// ///
pub fn init(mem_profile: *const mem.MemProfile, allocator: *Allocator) (PanicError || Allocator.Error || std.fmt.ParseIntError)!void { pub fn init(mem_profile: *const mem.MemProfile, allocator: *Allocator) (PanicError || Allocator.Error || std.fmt.ParseIntError)!void {
std.log.info(.panic, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.panic, "Done\n", .{}); defer log.info("Done\n", .{});
// Exit if we haven't loaded all debug modules // Exit if we haven't loaded all debug modules
if (mem_profile.modules.len < 1) { if (mem_profile.modules.len < 1) {

View file

@ -1,5 +1,6 @@
const is_test = @import("builtin").is_test; const is_test = @import("builtin").is_test;
const std = @import("std"); const std = @import("std");
const log = std.log.scoped(.pmm);
const build_options = @import("build_options"); const build_options = @import("build_options");
const mock_path = build_options.mock_path; const mock_path = build_options.mock_path;
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig").internals; const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig").internals;
@ -98,8 +99,8 @@ pub fn blocksFree() usize {
/// IN allocator: *Allocator - The allocator to use to allocate the bitmaps. /// IN allocator: *Allocator - The allocator to use to allocate the bitmaps.
/// ///
pub fn init(mem_profile: *const MemProfile, allocator: *Allocator) void { pub fn init(mem_profile: *const MemProfile, allocator: *Allocator) void {
std.log.info(.pmm, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.pmm, "Done\n", .{}); defer log.info("Done\n", .{});
bitmap = PmmBitmap.init(mem_profile.mem_kb * 1024 / BLOCK_SIZE, allocator) catch |e| { bitmap = PmmBitmap.init(mem_profile.mem_kb * 1024 / BLOCK_SIZE, allocator) catch |e| {
panic(@errorReturnTrace(), "Bitmap allocation failed: {}\n", .{e}); panic(@errorReturnTrace(), "Bitmap allocation failed: {}\n", .{e});
@ -232,5 +233,5 @@ fn runtimeTests(mem_profile: *const MemProfile, allocator: *Allocator) void {
panic(@errorReturnTrace(), "FAILURE: Failed freeing allocation in PMM rt test: {}", .{e}); panic(@errorReturnTrace(), "FAILURE: Failed freeing allocation in PMM rt test: {}", .{e});
}; };
} }
std.log.info(.pmm, "Tested allocation\n", .{}); log.info("Tested allocation\n", .{});
} }

View file

@ -2,6 +2,7 @@ const std = @import("std");
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
const assert = std.debug.assert; const assert = std.debug.assert;
const log = std.log.scoped(.scheduler);
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const build_options = @import("build_options"); const build_options = @import("build_options");
@ -98,7 +99,8 @@ pub fn pickNextTask(ctx: *arch.CpuState) usize {
/// be freed on return. /// be freed on return.
/// ///
pub fn scheduleTask(new_task: *Task, allocator: *Allocator) Allocator.Error!void { pub fn scheduleTask(new_task: *Task, allocator: *Allocator) Allocator.Error!void {
var task_node = try tasks.createNode(new_task, allocator); var task_node = try allocator.create(TailQueue(*Task).Node);
task_node.* = .{ .data = new_task };
tasks.prepend(task_node); tasks.prepend(task_node);
} }
@ -116,11 +118,11 @@ pub fn scheduleTask(new_task: *Task, allocator: *Allocator) Allocator.Error!void
/// ///
pub fn init(allocator: *Allocator) Allocator.Error!void { pub fn init(allocator: *Allocator) Allocator.Error!void {
// TODO: Maybe move the task init here? // TODO: Maybe move the task init here?
std.log.info(.scheduler, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.scheduler, "Done\n", .{}); defer log.info("Done\n", .{});
// Init the task list for round robin // Init the task list for round robin
tasks = TailQueue(*Task).init(); tasks = TailQueue(*Task){};
// Set up the init task to continue execution // Set up the init task to continue execution
current_task = try allocator.create(Task); current_task = try allocator.create(Task);
@ -181,7 +183,7 @@ test "pickNextTask" {
var ctx: arch.CpuState = std.mem.zeroes(arch.CpuState); var ctx: arch.CpuState = std.mem.zeroes(arch.CpuState);
var allocator = std.testing.allocator; var allocator = std.testing.allocator;
tasks = TailQueue(*Task).init(); tasks = TailQueue(*Task){};
// Set up a current task // Set up a current task
current_task = try allocator.create(Task); current_task = try allocator.create(Task);
@ -229,7 +231,7 @@ test "pickNextTask" {
// Free the queue // Free the queue
while (tasks.pop()) |elem| { while (tasks.pop()) |elem| {
tasks.destroyNode(elem, allocator); allocator.destroy(elem);
} }
} }
@ -244,7 +246,7 @@ test "createNewTask add new task" {
var allocator = std.testing.allocator; var allocator = std.testing.allocator;
// Init the task list // Init the task list
tasks = TailQueue(*Task).init(); tasks = TailQueue(*Task){};
var test_fn1_task = try Task.create(test_fn1, allocator); var test_fn1_task = try Task.create(test_fn1, allocator);
defer test_fn1_task.destroy(allocator); defer test_fn1_task.destroy(allocator);
@ -253,7 +255,7 @@ test "createNewTask add new task" {
expectEqual(tasks.len, 1); expectEqual(tasks.len, 1);
// Free the memory // Free the memory
tasks.destroyNode(tasks.first.?, allocator); allocator.destroy(tasks.first.?);
} }
test "init" { test "init" {
@ -276,7 +278,7 @@ test "init" {
current_task.destroy(allocator); current_task.destroy(allocator);
while (tasks.pop()) |elem| { while (tasks.pop()) |elem| {
elem.data.destroy(allocator); elem.data.destroy(allocator);
tasks.destroyNode(elem, allocator); allocator.destroy(elem);
} }
} }
@ -288,7 +290,7 @@ var is_set: *volatile bool = undefined;
/// The test task function. /// The test task function.
/// ///
fn task_function() noreturn { fn task_function() noreturn {
std.log.info(.scheduler, "Switched\n", .{}); log.info("Switched\n", .{});
is_set.* = false; is_set.* = false;
while (true) {} while (true) {}
} }
@ -343,7 +345,7 @@ fn rt_variable_preserved(allocator: *Allocator) void {
panic(@errorReturnTrace(), "FAILED: z not 3, but: {}\n", .{z}); panic(@errorReturnTrace(), "FAILED: z not 3, but: {}\n", .{z});
} }
std.log.info(.scheduler, "SUCCESS: Scheduler variables preserved\n", .{}); log.info("SUCCESS: Scheduler variables preserved\n", .{});
} }
/// ///

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const fmt = std.fmt; const fmt = std.fmt;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const log = std.log.scoped(.tty);
const build_options = @import("build_options"); const build_options = @import("build_options");
const arch = @import("arch.zig").internals; const arch = @import("arch.zig").internals;
const panic = @import("panic.zig").panic; const panic = @import("panic.zig").panic;
@ -51,7 +52,7 @@ fn printCallback(ctx: void, str: []const u8) !usize {
pub fn print(comptime format: []const u8, args: anytype) void { pub fn print(comptime format: []const u8, args: anytype) void {
// Printing can't error because of the scrolling, if it does, we have a big problem // Printing can't error because of the scrolling, if it does, we have a big problem
fmt.format(OutStream{ .context = {} }, format, args) catch |e| { fmt.format(OutStream{ .context = {} }, format, args) catch |e| {
std.log.emerg(.tty, "Error printing. Error: {}\n", .{e}); log.emerg("Error printing. Error: {}\n", .{e});
}; };
} }
@ -101,8 +102,8 @@ pub fn clear() void {
/// IN boot_payload: arch.BootPayload - The payload passed to the kernel on boot /// IN boot_payload: arch.BootPayload - The payload passed to the kernel on boot
/// ///
pub fn init(alloc: *Allocator, boot_payload: arch.BootPayload) void { pub fn init(alloc: *Allocator, boot_payload: arch.BootPayload) void {
std.log.info(.tty, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.tty, "Done\n", .{}); defer log.info("Done\n", .{});
tty = arch.initTTY(boot_payload); tty = arch.initTTY(boot_payload);
allocator = alloc; allocator = alloc;
} }

View file

@ -3,6 +3,7 @@ const mock_path = build_options.mock_path;
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const std = @import("std"); const std = @import("std");
const log = std.log.scoped(.vmm);
const bitmap = @import("bitmap.zig"); const bitmap = @import("bitmap.zig");
const pmm = @import("pmm.zig"); const pmm = @import("pmm.zig");
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig"); const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
@ -418,8 +419,8 @@ pub fn VirtualMemoryManager(comptime Payload: type) type {
/// error.OutOfMemory - The allocator cannot allocate the memory required /// error.OutOfMemory - The allocator cannot allocate the memory required
/// ///
pub fn init(mem_profile: *const mem.MemProfile, allocator: *Allocator) Allocator.Error!VirtualMemoryManager(arch.VmmPayload) { pub fn init(mem_profile: *const mem.MemProfile, allocator: *Allocator) Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {
std.log.info(.vmm, "Init\n", .{}); log.info("Init\n", .{});
defer std.log.info(.vmm, "Done\n", .{}); defer log.info("Done\n", .{});
var vmm = try VirtualMemoryManager(arch.VmmPayload).init(@ptrToInt(&KERNEL_ADDR_OFFSET), 0xFFFFFFFF, allocator, arch.VMM_MAPPER, arch.KERNEL_VMM_PAYLOAD); var vmm = try VirtualMemoryManager(arch.VmmPayload).init(@ptrToInt(&KERNEL_ADDR_OFFSET), 0xFFFFFFFF, allocator, arch.VMM_MAPPER, arch.KERNEL_VMM_PAYLOAD);
@ -727,5 +728,5 @@ fn runtimeTests(comptime Payload: type, vmm: VirtualMemoryManager(Payload), mem_
} }
} }
std.log.info(.vmm, "Tested allocations\n", .{}); log.info("Tested allocations\n", .{});
} }

View file

@ -434,7 +434,7 @@ fn Mock() type {
expectEqual(@as(DataElementType, action.data), expect_type); expectEqual(@as(DataElementType, action.data), expect_type);
// Free the node // Free the node
action_list.*.destroyNode(action_node, GlobalAllocator); GlobalAllocator.destroy(action_node);
return ret; return ret;
} else { } else {
@ -456,7 +456,7 @@ fn Mock() type {
pub fn addAction(self: *Self, comptime fun_name: []const u8, data: anytype, action_type: ActionType) void { pub fn addAction(self: *Self, comptime fun_name: []const u8, data: anytype, action_type: ActionType) void {
// Add a new mapping if one doesn't exist. // Add a new mapping if one doesn't exist.
if (!self.named_actions.contains(fun_name)) { if (!self.named_actions.contains(fun_name)) {
self.named_actions.put(fun_name, TailQueue(Action).init()) catch unreachable; self.named_actions.put(fun_name, .{}) catch unreachable;
} }
// Get the function mapping to add the parameter to. // Get the function mapping to add the parameter to.
@ -466,7 +466,8 @@ fn Mock() type {
.action = action_type, .action = action_type,
.data = createDataElement(data), .data = createDataElement(data),
}; };
var a = action_list.createNode(action, GlobalAllocator) catch unreachable; var a = GlobalAllocator.create(TailQueue(Action).Node) catch unreachable;
a.* = .{ .data = action };
action_list.append(a); action_list.append(a);
// Need to re-assign the value as it isn't updated when we just append // Need to re-assign the value as it isn't updated when we just append
actions_kv.value = action_list; actions_kv.value = action_list;
@ -510,7 +511,7 @@ fn Mock() type {
expectTest(param_type, param, test_action.data); expectTest(param_type, param, test_action.data);
// Free the node // Free the node
action_list.destroyNode(test_node, GlobalAllocator); GlobalAllocator.destroy(test_node);
} }
break :ret expectGetValue(fun_name, &action_list, RetType); break :ret expectGetValue(fun_name, &action_list, RetType);
}, },
@ -550,7 +551,7 @@ fn Mock() type {
const actual_function = getDataValue(expected_function, test_element); const actual_function = getDataValue(expected_function, test_element);
// Free the node // Free the node
action_list.destroyNode(test_node, GlobalAllocator); GlobalAllocator.destroy(test_node);
// The data element will contain the function to call // The data element will contain the function to call
const r = switch (params.len) { const r = switch (params.len) {
@ -649,7 +650,7 @@ fn Mock() type {
ActionType.RepeatFunctionCall => { ActionType.RepeatFunctionCall => {
// As this is a repeat action, the function will still be here // As this is a repeat action, the function will still be here
// So need to free it // So need to free it
action_list.destroyNode(action_node, GlobalAllocator); GlobalAllocator.destroy(action_node);
next.value = action_list; next.value = action_list;
}, },
} }

View file

@ -255,7 +255,7 @@ pub const RuntimeStep = struct {
// put line in the queue // put line in the queue
var node = self.builder.allocator.create(Node) catch unreachable; var node = self.builder.allocator.create(Node) catch unreachable;
node.* = Node.init(line); node.* = .{ .next = null, .data = line };
self.msg_queue.put(node); self.msg_queue.put(node);
} }
} }