diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d92b745..272aef6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - name: Download zig run: | export PYTHONIOENCODING=utf8 - wget https://ziglang.org/builds/zig-linux-x86_64-0.5.0+ae0a219d1.tar.xz + wget $(curl -s 'https://ziglang.org/download/index.json' | python3 -c "import sys, json; print(json.load(sys.stdin)['master']['x86_64-linux']['tarball'])") sudo apt-get install mtools tar -xvf zig* - name: Build kernel diff --git a/build.zig b/build.zig index c0d799b..9808d9d 100644 --- a/build.zig +++ b/build.zig @@ -27,38 +27,38 @@ pub fn build(b: *Builder) !void { const main_src = "src/kernel/kmain.zig"; const exec = b.addExecutable("pluto", main_src); - const constants_path = try fs.path.join(b.allocator, [_][]const u8{ "src/kernel/arch", target_str, "constants.zig" }); + const constants_path = try fs.path.join(b.allocator, &[_][]const u8{ "src/kernel/arch", target_str, "constants.zig" }); exec.addPackagePath("constants", constants_path); exec.setBuildMode(build_mode); exec.addBuildOption(bool, "rt_test", rt_test); exec.setLinkerScriptPath("link.ld"); exec.setTheTarget(target); - const iso_path = try fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "pluto.iso" }); - const grub_build_path = try fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "iso", "boot" }); - const iso_dir_path = try fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "iso" }); + const iso_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "pluto.iso" }); + const grub_build_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "boot" }); + const iso_dir_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso" }); - const mkdir_cmd = b.addSystemCommand([_][]const u8{ "mkdir", "-p", fs.path.dirname(grub_build_path).? }); + const mkdir_cmd = b.addSystemCommand(&[_][]const u8{ "mkdir", "-p", fs.path.dirname(grub_build_path).? }); - const grub_cmd = b.addSystemCommand([_][]const u8{ "cp", "-r", "grub", grub_build_path }); + const grub_cmd = b.addSystemCommand(&[_][]const u8{ "cp", "-r", "grub", grub_build_path }); grub_cmd.step.dependOn(&mkdir_cmd.step); - const cp_elf_cmd = b.addSystemCommand([_][]const u8{"cp"}); - const elf_path = try fs.path.join(b.allocator, [_][]const u8{ grub_build_path, "pluto.elf" }); + const cp_elf_cmd = b.addSystemCommand(&[_][]const u8{"cp"}); + const elf_path = try fs.path.join(b.allocator, &[_][]const u8{ grub_build_path, "pluto.elf" }); cp_elf_cmd.addArtifactArg(exec); cp_elf_cmd.addArg(elf_path); cp_elf_cmd.step.dependOn(&grub_cmd.step); cp_elf_cmd.step.dependOn(&exec.step); - const modules_path = try fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "iso", "modules" }); - const mkdir_modules_cmd = b.addSystemCommand([_][]const u8{ "mkdir", "-p", modules_path }); + const modules_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "modules" }); + const mkdir_modules_cmd = b.addSystemCommand(&[_][]const u8{ "mkdir", "-p", modules_path }); - const map_file_path = try fs.path.join(b.allocator, [_][]const u8{ modules_path, "kernel.map" }); - const map_file_cmd = b.addSystemCommand([_][]const u8{ "./make_map.sh", elf_path, map_file_path }); + const map_file_path = try fs.path.join(b.allocator, &[_][]const u8{ modules_path, "kernel.map" }); + const map_file_cmd = b.addSystemCommand(&[_][]const u8{ "./make_map.sh", elf_path, map_file_path }); map_file_cmd.step.dependOn(&cp_elf_cmd.step); map_file_cmd.step.dependOn(&mkdir_modules_cmd.step); - const iso_cmd = b.addSystemCommand([_][]const u8{ "grub-mkrescue", "-o", iso_path, iso_dir_path }); + const iso_cmd = b.addSystemCommand(&[_][]const u8{ "grub-mkrescue", "-o", iso_path, iso_dir_path }); iso_cmd.step.dependOn(&map_file_cmd.step); b.default_step.dependOn(&iso_cmd.step); @@ -69,7 +69,7 @@ pub fn build(b: *Builder) !void { .i386 => "qemu-system-i386", else => unreachable, }; - const qemu_args = [_][]const u8{ + const qemu_args = &[_][]const u8{ qemu_bin, "-cdrom", iso_path, @@ -80,10 +80,10 @@ pub fn build(b: *Builder) !void { }; const qemu_cmd = b.addSystemCommand(qemu_args); const qemu_debug_cmd = b.addSystemCommand(qemu_args); - qemu_debug_cmd.addArgs([_][]const u8{ "-s", "-S" }); + qemu_debug_cmd.addArgs(&[_][]const u8{ "-s", "-S" }); if (rt_test) { - const qemu_rt_test_args = [_][]const u8{ "-display", "none" }; + const qemu_rt_test_args = &[_][]const u8{ "-display", "none" }; qemu_cmd.addArgs(qemu_rt_test_args); qemu_debug_cmd.addArgs(qemu_rt_test_args); } @@ -96,7 +96,7 @@ pub fn build(b: *Builder) !void { const test_step = b.step("test", "Run tests"); if (rt_test) { - const script = b.addSystemCommand([_][]const u8{ "python3", "test/rt-test.py", "x86", b.zig_exe }); + const script = b.addSystemCommand(&[_][]const u8{ "python3", "test/rt-test.py", "x86", b.zig_exe }); test_step.dependOn(&script.step); } else { const mock_path = "\"../../test/mock/kernel/\""; @@ -112,13 +112,13 @@ pub fn build(b: *Builder) !void { } const debug_step = b.step("debug", "Debug with gdb and connect to a running qemu instance"); - const symbol_file_arg = try std.mem.join(b.allocator, " ", [_][]const u8{ "symbol-file", elf_path }); - const debug_cmd = b.addSystemCommand([_][]const u8{ + const symbol_file_arg = try std.mem.join(b.allocator, " ", &[_][]const u8{ "symbol-file", elf_path }); + const debug_cmd = b.addSystemCommand(&[_][]const u8{ "gdb", "-ex", symbol_file_arg, }); - debug_cmd.addArgs([_][]const u8{ + debug_cmd.addArgs(&[_][]const u8{ "-ex", "target remote localhost:1234", }); diff --git a/src/kernel/arch/x86/gdt.zig b/src/kernel/arch/x86/gdt.zig index 0e629b7..76b5452 100644 --- a/src/kernel/arch/x86/gdt.zig +++ b/src/kernel/arch/x86/gdt.zig @@ -424,7 +424,7 @@ pub fn setTssStack(esp0: u32) void { /// Initialise the Global Descriptor table. /// pub fn init() void { - log.logInfo("Init gdt\n"); + log.logInfo("Init gdt\n", .{}); // Initiate TSS gdt_entries[TSS_INDEX] = makeEntry(@intCast(u32, @ptrToInt(&tss)), @sizeOf(TtsEntry) - 1, TSS_SEGMENT, NULL_FLAGS); @@ -437,7 +437,7 @@ pub fn init() void { // Load the TSS arch.ltr(TSS_OFFSET); - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -639,7 +639,7 @@ test "init" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("ltr", TSS_OFFSET); + arch.addTestParams("ltr", .{TSS_OFFSET}); arch.addConsumeFunction("lgdt", mock_lgdt); @@ -681,5 +681,5 @@ fn rt_loadedGDTSuccess() void { /// fn runtimeTests() void { rt_loadedGDTSuccess(); - log.logInfo("GDT: Tested loading GDT\n"); + log.logInfo("GDT: Tested loading GDT\n", .{}); } diff --git a/src/kernel/arch/x86/idt.zig b/src/kernel/arch/x86/idt.zig index fec9739..2e2eba3 100644 --- a/src/kernel/arch/x86/idt.zig +++ b/src/kernel/arch/x86/idt.zig @@ -179,12 +179,12 @@ pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void { /// Initialise the Interrupt descriptor table /// pub fn init() void { - log.logInfo("Init idt\n"); + log.logInfo("Init idt\n", .{}); idt_ptr.base = @intCast(u32, @ptrToInt(&idt_entries)); arch.lidt(&idt_ptr); - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -327,7 +327,7 @@ fn rt_loadedIDTSuccess() void { const loaded_idt = arch.sidt(); expect(idt_ptr.limit == loaded_idt.limit); expect(idt_ptr.base == loaded_idt.base); - log.logInfo("IDT: Tested loading IDT\n"); + log.logInfo("IDT: Tested loading IDT\n", .{}); } /// diff --git a/src/kernel/arch/x86/irq.zig b/src/kernel/arch/x86/irq.zig index caf9b6d..b5651df 100644 --- a/src/kernel/arch/x86/irq.zig +++ b/src/kernel/arch/x86/irq.zig @@ -44,7 +44,7 @@ var irq_handlers: [NUMBER_OF_ENTRIES]?IrqHandler = [_]?IrqHandler{null} ** NUMBE export fn irqHandler(ctx: *arch.InterruptContext) void { // Get the IRQ index, by getting the interrupt number and subtracting the offset. if (ctx.int_num < IRQ_OFFSET) { - panic(@errorReturnTrace(), "Not an IRQ number: {}\n", ctx.int_num); + panic(@errorReturnTrace(), "Not an IRQ number: {}\n", .{ctx.int_num}); } const irq_offset = ctx.int_num - IRQ_OFFSET; @@ -59,10 +59,10 @@ export fn irqHandler(ctx: *arch.InterruptContext) void { pic.sendEndOfInterrupt(irq_num); } } else { - panic(@errorReturnTrace(), "IRQ not registered: {}", irq_num); + panic(@errorReturnTrace(), "IRQ not registered: {}", .{irq_num}); } } else { - panic(@errorReturnTrace(), "Invalid IRQ index: {}", irq_offset); + panic(@errorReturnTrace(), "Invalid IRQ index: {}", .{irq_offset}); } } @@ -76,7 +76,7 @@ export fn irqHandler(ctx: *arch.InterruptContext) void { fn openIrq(index: u8, handler: idt.InterruptHandler) void { idt.openInterruptGate(index, handler) catch |err| switch (err) { error.IdtEntryExists => { - panic(@errorReturnTrace(), "Error opening IRQ number: {} exists", index); + panic(@errorReturnTrace(), "Error opening IRQ number: {} exists", .{index}); }, }; } @@ -128,14 +128,14 @@ pub fn registerIrq(irq_num: u8, handler: IrqHandler) IrqError!void { /// the IDT interrupt gates for each IRQ. /// pub fn init() void { - log.logInfo("Init irq\n"); + log.logInfo("Init irq\n", .{}); comptime var i = IRQ_OFFSET; inline while (i < IRQ_OFFSET + 16) : (i += 1) { openIrq(i, interrupts.getInterruptStub(i)); } - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -152,7 +152,7 @@ test "openIrq" { const handler = testFunction0; const ret: idt.IdtError!void = {}; - idt.addTestParams("openInterruptGate", index, handler, ret); + idt.addTestParams("openInterruptGate", .{ index, handler, ret }); openIrq(index, handler); } @@ -171,7 +171,7 @@ test "registerIrq re-register irq handler" { pic.initTest(); defer pic.freeTest(); - pic.addTestParams("clearMask", @as(u16, 0)); + pic.addTestParams("clearMask", .{@as(u16, 0)}); // Pre testing for (irq_handlers) |h| { @@ -200,7 +200,7 @@ test "registerIrq register irq handler" { pic.initTest(); defer pic.freeTest(); - pic.addTestParams("clearMask", @as(u16, 0)); + pic.addTestParams("clearMask", .{@as(u16, 0)}); // Pre testing for (irq_handlers) |h| { @@ -234,11 +234,11 @@ fn rt_unregisteredHandlers() void { // Ensure all ISR are not registered yet for (irq_handlers) |h, i| { if (h) |_| { - panic(@errorReturnTrace(), "Handler found for IRQ: {}-{}\n", i, h); + panic(@errorReturnTrace(), "Handler found for IRQ: {}-{}\n", .{ i, h }); } } - log.logInfo("IRQ: Tested registered handlers\n"); + log.logInfo("IRQ: Tested registered handlers\n", .{}); } /// @@ -251,12 +251,12 @@ fn rt_openedIdtEntries() void { for (idt_entries) |entry, i| { if (i >= IRQ_OFFSET and isValidIrq(i - IRQ_OFFSET)) { if (!idt.isIdtOpen(entry)) { - panic(@errorReturnTrace(), "IDT entry for {} is not open\n", i); + panic(@errorReturnTrace(), "IDT entry for {} is not open\n", .{i}); } } } - log.logInfo("IRQ: Tested opened IDT entries\n"); + log.logInfo("IRQ: Tested opened IDT entries\n", .{}); } /// diff --git a/src/kernel/arch/x86/isr.zig b/src/kernel/arch/x86/isr.zig index 1a5e627..92ce3f4 100644 --- a/src/kernel/arch/x86/isr.zig +++ b/src/kernel/arch/x86/isr.zig @@ -150,18 +150,18 @@ export fn isrHandler(ctx: *arch.InterruptContext) void { if (syscall_handler) |handler| { handler(ctx); } else { - panic(@errorReturnTrace(), "Syscall handler not registered\n"); + panic(@errorReturnTrace(), "Syscall handler not registered\n", .{}); } } else { if (isr_handlers[isr_num]) |handler| { // Regular ISR exception, if there is one registered. handler(ctx); } else { - panic(@errorReturnTrace(), "ISR not registered to: {}-{}\n", isr_num, exception_msg[isr_num]); + panic(@errorReturnTrace(), "ISR not registered to: {}-{}\n", .{ isr_num, exception_msg[isr_num] }); } } } else { - panic(@errorReturnTrace(), "Invalid ISR index: {}\n", isr_num); + panic(@errorReturnTrace(), "Invalid ISR index: {}\n", .{isr_num}); } } @@ -175,7 +175,7 @@ export fn isrHandler(ctx: *arch.InterruptContext) void { fn openIsr(index: u8, handler: idt.InterruptHandler) void { idt.openInterruptGate(index, handler) catch |err| switch (err) { error.IdtEntryExists => { - panic(@errorReturnTrace(), "Error opening ISR number: {} exists\n", index); + panic(@errorReturnTrace(), "Error opening ISR number: {} exists\n", .{index}); }, }; } @@ -234,7 +234,7 @@ pub fn registerIsr(isr_num: u16, handler: IsrHandler) IsrError!void { /// Initialise the exception and opening up all the IDT interrupt gates for each exception. /// pub fn init() void { - log.logInfo("Init isr\n"); + log.logInfo("Init isr\n", .{}); comptime var i = 0; inline while (i < 32) : (i += 1) { @@ -243,7 +243,7 @@ pub fn init() void { openIsr(syscalls.INTERRUPT, interrupts.getInterruptStub(syscalls.INTERRUPT)); - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -262,7 +262,7 @@ test "openIsr" { const handler = testFunction0; const ret: idt.IdtError!void = {}; - idt.addTestParams("openInterruptGate", index, handler, ret); + idt.addTestParams("openInterruptGate", .{ index, handler, ret }); openIsr(index, handler); } @@ -363,15 +363,15 @@ fn rt_unregisteredHandlers() void { // Ensure all ISR are not registered yet for (isr_handlers) |h, i| { if (h) |_| { - panic(@errorReturnTrace(), "Handler found for ISR: {}-{}\n", i, h); + panic(@errorReturnTrace(), "Handler found for ISR: {}-{}\n", .{ i, h }); } } if (syscall_handler) |h| { - panic(@errorReturnTrace(), "Pre-testing failed for syscall: {}\n", h); + panic(@errorReturnTrace(), "Pre-testing failed for syscall: {}\n", .{h}); } - log.logInfo("ISR: Tested registered handlers\n"); + log.logInfo("ISR: Tested registered handlers\n", .{}); } /// @@ -384,12 +384,12 @@ fn rt_openedIdtEntries() void { for (idt_entries) |entry, i| { if (isValidIsr(i)) { if (!idt.isIdtOpen(entry)) { - panic(@errorReturnTrace(), "IDT entry for {} is not open\n", i); + panic(@errorReturnTrace(), "IDT entry for {} is not open\n", .{i}); } } } - log.logInfo("ISR: Tested opened IDT entries\n"); + log.logInfo("ISR: Tested opened IDT entries\n", .{}); } /// diff --git a/src/kernel/arch/x86/paging.zig b/src/kernel/arch/x86/paging.zig index 2b98eaf..c5fb89b 100644 --- a/src/kernel/arch/x86/paging.zig +++ b/src/kernel/arch/x86/paging.zig @@ -292,7 +292,7 @@ fn pageFault(state: *arch.InterruptContext) void { /// IN allocator: *std.mem.Allocator - The allocator to use /// pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile, allocator: *std.mem.Allocator) void { - log.logInfo("Init paging\n"); + log.logInfo("Init paging\n", .{}); // Calculate start and end of mapping const v_start = std.mem.alignBackward(@ptrToInt(mem_profile.vaddr_start), PAGE_SIZE_4KB); const v_end = std.mem.alignForward(@ptrToInt(mem_profile.vaddr_end) + mem_profile.fixed_alloc_size, PAGE_SIZE_4KB); @@ -300,14 +300,14 @@ pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile const p_end = std.mem.alignForward(@ptrToInt(mem_profile.physaddr_end) + mem_profile.fixed_alloc_size, PAGE_SIZE_4KB); var tmp = allocator.alignedAlloc(Directory, @truncate(u29, PAGE_SIZE_4KB), 1) catch |e| { - panic(@errorReturnTrace(), "Failed to allocate page directory: {}\n", e); + panic(@errorReturnTrace(), "Failed to allocate page directory: {}\n", .{e}); }; var kernel_directory = @ptrCast(*Directory, tmp.ptr); @memset(@ptrCast([*]u8, kernel_directory), 0, @sizeOf(Directory)); // Map in kernel mapDir(kernel_directory, v_start, v_end, p_start, p_end, allocator) catch |e| { - panic(@errorReturnTrace(), "Failed to map kernel directory: {}\n", e); + panic(@errorReturnTrace(), "Failed to map kernel directory: {}\n", .{e}); }; const tty_addr = tty.getVideoBufferAddress(); // If the previous mapping space didn't cover the tty buffer, do so now @@ -315,7 +315,7 @@ pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile const tty_phys = mem.virtToPhys(tty_addr); const tty_buff_size = 32 * 1024; mapDir(kernel_directory, tty_addr, tty_addr + tty_buff_size, tty_phys, tty_phys + tty_buff_size, allocator) catch |e| { - panic(@errorReturnTrace(), "Failed to map vga buffer in kernel directory: {}\n", e); + panic(@errorReturnTrace(), "Failed to map vga buffer in kernel directory: {}\n", .{e}); }; } @@ -325,7 +325,7 @@ pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile if (v_start > mb_info_addr) { const mb_info_end = mb_info_addr + PAGE_SIZE_4MB / 2; mapDir(kernel_directory, mb_info_addr, mb_info_end, mem.virtToPhys(mb_info_addr), mem.virtToPhys(mb_info_end), allocator) catch |e| { - panic(@errorReturnTrace(), "Failed to map mb_info in kernel directory: {}\n", e); + panic(@errorReturnTrace(), "Failed to map mb_info in kernel directory: {}\n", .{e}); }; } @@ -334,12 +334,12 @@ pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile const mod_v_struct_start = std.mem.alignBackward(@ptrToInt(module), PAGE_SIZE_4KB); const mod_v_struct_end = std.mem.alignForward(mod_v_struct_start + @sizeOf(multiboot.multiboot_module_t), PAGE_SIZE_4KB); mapDir(kernel_directory, mod_v_struct_start, mod_v_struct_end, mem.virtToPhys(mod_v_struct_start), mem.virtToPhys(mod_v_struct_end), allocator) catch |e| { - panic(@errorReturnTrace(), "Failed to map module struct: {}\n", e); + panic(@errorReturnTrace(), "Failed to map module struct: {}\n", .{e}); }; const mod_p_start = std.mem.alignBackward(module.mod_start, PAGE_SIZE_4KB); const mod_p_end = std.mem.alignForward(module.mod_end, PAGE_SIZE_4KB); mapDir(kernel_directory, mem.physToVirt(mod_p_start), mem.physToVirt(mod_p_end), mod_p_start, mod_p_end, allocator) catch |e| { - panic(@errorReturnTrace(), "Failed to map boot module in kernel directory: {}\n", e); + panic(@errorReturnTrace(), "Failed to map boot module in kernel directory: {}\n", .{e}); }; } @@ -349,9 +349,9 @@ pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile : [addr] "{eax}" (dir_physaddr) ); isr.registerIsr(isr.PAGE_FAULT, if (options.rt_test) 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}); }; - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (options.rt_test) runtimeTests(v_end); } @@ -482,7 +482,7 @@ fn rt_accessUnmappedMem(v_end: u32) void { \\rt_fault_callback: ); testing.expect(faulted); - log.logInfo("Paging: Tested accessing unmapped memory\n"); + log.logInfo("Paging: Tested accessing unmapped memory\n", .{}); } fn rt_accessMappedMem(v_end: u32) void { @@ -496,7 +496,7 @@ fn rt_accessMappedMem(v_end: u32) void { \\rt_fault_callback2: ); testing.expect(!faulted); - log.logInfo("Paging: Tested accessing mapped memory\n"); + log.logInfo("Paging: Tested accessing mapped memory\n", .{}); } fn runtimeTests(v_end: u32) void { diff --git a/src/kernel/arch/x86/pic.zig b/src/kernel/arch/x86/pic.zig index ed7afe7..a1e152b 100644 --- a/src/kernel/arch/x86/pic.zig +++ b/src/kernel/arch/x86/pic.zig @@ -432,7 +432,7 @@ pub fn clearMask(irq_num: u8) void { /// by Intel up to 0x1F. So this will move the IRQs from 0x00-0x0F to 0x20-0x2F. /// pub fn init() void { - log.logInfo("Init pic\n"); + log.logInfo("Init pic\n", .{}); // Initiate sendCommandMaster(ICW1_INITIALISATION | ICW1_EXPECT_ICW4); @@ -454,7 +454,7 @@ pub fn init() void { sendDataMaster(0xFF); sendDataSlave(0xFF); - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -466,7 +466,7 @@ test "sendCommandMaster" { const cmd: u8 = 10; - arch.addTestParams("outb", MASTER_COMMAND_REG, cmd); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, cmd }); sendCommandMaster(cmd); } @@ -478,7 +478,7 @@ test "sendCommandSlave" { const cmd: u8 = 10; - arch.addTestParams("outb", SLAVE_COMMAND_REG, cmd); + arch.addTestParams("outb", .{ SLAVE_COMMAND_REG, cmd }); sendCommandSlave(cmd); } @@ -490,7 +490,7 @@ test "sendDataMaster" { const data: u8 = 10; - arch.addTestParams("outb", MASTER_DATA_REG, data); + arch.addTestParams("outb", .{ MASTER_DATA_REG, data }); sendDataMaster(data); } @@ -502,7 +502,7 @@ test "sendDataSlave" { const data: u8 = 10; - arch.addTestParams("outb", SLAVE_DATA_REG, data); + arch.addTestParams("outb", .{ SLAVE_DATA_REG, data }); sendDataSlave(data); } @@ -512,7 +512,7 @@ test "readDataMaster" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("inb", MASTER_DATA_REG, @as(u8, 10)); + arch.addTestParams("inb", .{ MASTER_DATA_REG, @as(u8, 10) }); expectEqual(@as(u8, 10), readDataMaster()); } @@ -522,7 +522,7 @@ test "readDataSlave" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("inb", SLAVE_DATA_REG, @as(u8, 10)); + arch.addTestParams("inb", .{ SLAVE_DATA_REG, @as(u8, 10) }); expectEqual(@as(u8, 10), readDataSlave()); } @@ -532,8 +532,8 @@ test "readMasterIrr" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", MASTER_COMMAND_REG, @as(u8, 0x0A)); - arch.addTestParams("inb", MASTER_STATUS_REG, @as(u8, 10)); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, @as(u8, 0x0A) }); + arch.addTestParams("inb", .{ MASTER_STATUS_REG, @as(u8, 10) }); expectEqual(@as(u8, 10), readMasterIrr()); } @@ -543,8 +543,8 @@ test "readSlaveIrr" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", SLAVE_COMMAND_REG, @as(u8, 0x0A)); - arch.addTestParams("inb", SLAVE_STATUS_REG, @as(u8, 10)); + arch.addTestParams("outb", .{ SLAVE_COMMAND_REG, @as(u8, 0x0A) }); + arch.addTestParams("inb", .{ SLAVE_STATUS_REG, @as(u8, 10) }); expectEqual(@as(u8, 10), readSlaveIrr()); } @@ -554,8 +554,8 @@ test "readMasterIsr" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", MASTER_COMMAND_REG, @as(u8, 0x0B)); - arch.addTestParams("inb", MASTER_STATUS_REG, @as(u8, 10)); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, @as(u8, 0x0B) }); + arch.addTestParams("inb", .{ MASTER_STATUS_REG, @as(u8, 10) }); expectEqual(@as(u8, 10), readMasterIsr()); } @@ -565,8 +565,8 @@ test "readSlaveIsr" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", SLAVE_COMMAND_REG, @as(u8, 0x0B)); - arch.addTestParams("inb", SLAVE_STATUS_REG, @as(u8, 10)); + arch.addTestParams("outb", .{ SLAVE_COMMAND_REG, @as(u8, 0x0B) }); + arch.addTestParams("inb", .{ SLAVE_STATUS_REG, @as(u8, 10) }); expectEqual(@as(u8, 10), readSlaveIsr()); } @@ -578,7 +578,7 @@ test "sendEndOfInterrupt master only" { var i: u8 = 0; while (i < 8) : (i += 1) { - arch.addTestParams("outb", MASTER_COMMAND_REG, OCW2_END_OF_INTERRUPT); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, OCW2_END_OF_INTERRUPT }); sendEndOfInterrupt(i); } @@ -591,8 +591,8 @@ test "sendEndOfInterrupt master and slave" { var i: u8 = 8; while (i < 16) : (i += 1) { - arch.addTestParams("outb", SLAVE_COMMAND_REG, OCW2_END_OF_INTERRUPT); - arch.addTestParams("outb", MASTER_COMMAND_REG, OCW2_END_OF_INTERRUPT); + arch.addTestParams("outb", .{ SLAVE_COMMAND_REG, OCW2_END_OF_INTERRUPT }); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, OCW2_END_OF_INTERRUPT }); sendEndOfInterrupt(i); } @@ -621,9 +621,9 @@ test "spuriousIrq spurious master IRQ number not spurious" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", MASTER_COMMAND_REG, @as(u8, 0x0B)); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, @as(u8, 0x0B) }); // Return 0x80 from readMasterIsr() which will mean this was a real IRQ - arch.addTestParams("inb", MASTER_STATUS_REG, @as(u8, 0x80)); + arch.addTestParams("inb", .{ MASTER_STATUS_REG, @as(u8, 0x80) }); // Pre testing expectEqual(@as(u32, 0), spurious_irq_counter); @@ -643,9 +643,9 @@ test "spuriousIrq spurious master IRQ number spurious" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", MASTER_COMMAND_REG, @as(u8, 0x0B)); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, @as(u8, 0x0B) }); // Return 0x0 from readMasterIsr() which will mean this was a spurious IRQ - arch.addTestParams("inb", MASTER_STATUS_REG, @as(u8, 0x0)); + arch.addTestParams("inb", .{ MASTER_STATUS_REG, @as(u8, 0x0) }); // Pre testing expectEqual(@as(u32, 0), spurious_irq_counter); @@ -665,9 +665,9 @@ test "spuriousIrq spurious slave IRQ number not spurious" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", SLAVE_COMMAND_REG, @as(u8, 0x0B)); + arch.addTestParams("outb", .{ SLAVE_COMMAND_REG, @as(u8, 0x0B) }); // Return 0x80 from readSlaveIsr() which will mean this was a real IRQ - arch.addTestParams("inb", SLAVE_STATUS_REG, @as(u8, 0x80)); + arch.addTestParams("inb", .{ SLAVE_STATUS_REG, @as(u8, 0x80) }); // Pre testing expectEqual(@as(u32, 0), spurious_irq_counter); @@ -687,11 +687,11 @@ test "spuriousIrq spurious slave IRQ number spurious" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", SLAVE_COMMAND_REG, @as(u8, 0x0B)); + arch.addTestParams("outb", .{ SLAVE_COMMAND_REG, @as(u8, 0x0B) }); // Return 0x0 from readSlaveIsr() which will mean this was a spurious IRQ - arch.addTestParams("inb", SLAVE_STATUS_REG, @as(u8, 0x0)); + arch.addTestParams("inb", .{ SLAVE_STATUS_REG, @as(u8, 0x0) }); // A EOI will be sent for a spurious IRQ 15 - arch.addTestParams("outb", MASTER_COMMAND_REG, OCW2_END_OF_INTERRUPT); + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, OCW2_END_OF_INTERRUPT }); // Pre testing expectEqual(@as(u32, 0), spurious_irq_counter); @@ -712,9 +712,9 @@ test "setMask master IRQ masked" { defer arch.freeTest(); // Going to assume all bits are masked out - arch.addTestParams("inb", MASTER_DATA_REG, @as(u8, 0xFF)); + arch.addTestParams("inb", .{ MASTER_DATA_REG, @as(u8, 0xFF) }); // Expect the 2nd bit to be set - arch.addTestParams("outb", MASTER_DATA_REG, @as(u8, 0xFF)); + arch.addTestParams("outb", .{ MASTER_DATA_REG, @as(u8, 0xFF) }); setMask(1); } @@ -725,9 +725,9 @@ test "setMask master IRQ unmasked" { defer arch.freeTest(); // IRQ already unmasked - arch.addTestParams("inb", MASTER_DATA_REG, @as(u8, 0xFD)); + arch.addTestParams("inb", .{ MASTER_DATA_REG, @as(u8, 0xFD) }); // Expect the 2nd bit to be set - arch.addTestParams("outb", MASTER_DATA_REG, @as(u8, 0xFF)); + arch.addTestParams("outb", .{ MASTER_DATA_REG, @as(u8, 0xFF) }); setMask(1); } @@ -738,9 +738,9 @@ test "clearMask master IRQ masked" { defer arch.freeTest(); // Going to assume all bits are masked out - arch.addTestParams("inb", MASTER_DATA_REG, @as(u8, 0xFF)); + arch.addTestParams("inb", .{ MASTER_DATA_REG, @as(u8, 0xFF) }); // Expect the 2nd bit to be clear - arch.addTestParams("outb", MASTER_DATA_REG, @as(u8, 0xFD)); + arch.addTestParams("outb", .{ MASTER_DATA_REG, @as(u8, 0xFD) }); clearMask(1); } @@ -751,9 +751,9 @@ test "clearMask master IRQ unmasked" { defer arch.freeTest(); // IRQ already unmasked - arch.addTestParams("inb", MASTER_DATA_REG, @as(u8, 0xFD)); + arch.addTestParams("inb", .{ MASTER_DATA_REG, @as(u8, 0xFD) }); // Expect the 2nd bit to still be clear - arch.addTestParams("outb", MASTER_DATA_REG, @as(u8, 0xFD)); + arch.addTestParams("outb", .{ MASTER_DATA_REG, @as(u8, 0xFD) }); clearMask(1); } @@ -764,8 +764,7 @@ test "init" { defer arch.freeTest(); // Just a long list of OUT instructions setting up the PIC - arch.addTestParams( - "outb", + arch.addTestParams("outb", .{ MASTER_COMMAND_REG, ICW1_INITIALISATION | ICW1_EXPECT_ICW4, SLAVE_COMMAND_REG, @@ -786,7 +785,7 @@ test "init" { @as(u8, 0xFF), SLAVE_DATA_REG, @as(u8, 0xFF), - ); + }); init(); } @@ -796,14 +795,14 @@ test "init" { /// fn rt_picAllMasked() void { if (readDataMaster() != 0xFF) { - panic(@errorReturnTrace(), "Master masks are not set, found: {}\n", readDataMaster()); + panic(@errorReturnTrace(), "Master masks are not set, found: {}\n", .{readDataMaster()}); } if (readDataSlave() != 0xFF) { - panic(@errorReturnTrace(), "Slave masks are not set, found: {}\n", readDataSlave()); + panic(@errorReturnTrace(), "Slave masks are not set, found: {}\n", .{readDataSlave()}); } - log.logInfo("PIC: Tested masking\n"); + log.logInfo("PIC: Tested masking\n", .{}); } /// diff --git a/src/kernel/arch/x86/pit.zig b/src/kernel/arch/x86/pit.zig index d3463b9..ebd31f7 100644 --- a/src/kernel/arch/x86/pit.zig +++ b/src/kernel/arch/x86/pit.zig @@ -370,26 +370,26 @@ pub fn getFrequency() u32 { /// Initialise the PIT with a handler to IRQ 0. /// pub fn init() void { - log.logInfo("Init pit\n"); + log.logInfo("Init pit\n", .{}); // Set up counter 0 at 10000hz in a square wave mode counting in binary const freq: u32 = 10000; setupCounter(CounterSelect.Counter0, freq, OCW_MODE_SQUARE_WAVE_GENERATOR | OCW_BINARY_COUNT_BINARY) catch |e| { - panic(@errorReturnTrace(), "Invalid frequency: {}\n", freq); + panic(@errorReturnTrace(), "Invalid frequency: {}\n", .{freq}); }; - log.logDebug("Set frequency at: {}Hz, real frequency: {}Hz\n", freq, getFrequency()); + log.logDebug("Set frequency at: {}Hz, real frequency: {}Hz\n", .{ freq, getFrequency() }); // Installs 'pitHandler' to IRQ0 (pic.IRQ_PIT) irq.registerIrq(pic.IRQ_PIT, pitHandler) catch |err| switch (err) { error.IrqExists => { - panic(@errorReturnTrace(), "IRQ for PIT, IRQ number: {} exists", pic.IRQ_PIT); + panic(@errorReturnTrace(), "IRQ for PIT, IRQ number: {} exists", .{pic.IRQ_PIT}); }, error.InvalidIrq => { - panic(@errorReturnTrace(), "IRQ for PIT, IRQ number: {} is invalid", pic.IRQ_PIT); + panic(@errorReturnTrace(), "IRQ for PIT, IRQ number: {} is invalid", .{pic.IRQ_PIT}); }, }; - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -400,7 +400,7 @@ test "sendCommand" { const cmd: u8 = 10; - arch.addTestParams("outb", COMMAND_REGISTER, cmd); + arch.addTestParams("outb", .{ COMMAND_REGISTER, cmd }); sendCommand(cmd); } @@ -411,8 +411,8 @@ test "readBackCommand" { const cmd: u8 = 0xC2; - arch.addTestParams("outb", COMMAND_REGISTER, cmd); - arch.addTestParams("inb", COUNTER_0_REGISTER, @as(u8, 0x20)); + arch.addTestParams("outb", .{ COMMAND_REGISTER, cmd }); + arch.addTestParams("inb", .{ COUNTER_0_REGISTER, @as(u8, 0x20) }); const actual = readBackCommand(CounterSelect.Counter0); @@ -425,7 +425,7 @@ test "sendDataToCounter" { const data: u8 = 10; - arch.addTestParams("outb", COUNTER_0_REGISTER, data); + arch.addTestParams("outb", .{ COUNTER_0_REGISTER, data }); sendDataToCounter(CounterSelect.Counter0, data); } @@ -519,7 +519,7 @@ test "setupCounter normal frequency" { const mode = OCW_MODE_SQUARE_WAVE_GENERATOR | OCW_BINARY_COUNT_BINARY; const command = mode | OCW_READ_LOAD_DATA | counter.getCounterOCW(); - arch.addTestParams("outb", COMMAND_REGISTER, command, port, @truncate(u8, expected_reload_value), port, @truncate(u8, expected_reload_value >> 8)); + arch.addTestParams("outb", .{ COMMAND_REGISTER, command, port, @truncate(u8, expected_reload_value), port, @truncate(u8, expected_reload_value >> 8) }); setupCounter(counter, freq, mode) catch unreachable; @@ -551,10 +551,10 @@ fn rt_waitTicks() void { const difference = getTicks() - waiting; if (previous_count + epsilon < difference or previous_count > difference + epsilon) { - panic(@errorReturnTrace(), "Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", difference, previous_count, epsilon); + panic(@errorReturnTrace(), "Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", .{ difference, previous_count, epsilon }); } - log.logInfo("PIT: Tested wait ticks\n"); + log.logInfo("PIT: Tested wait ticks\n", .{}); } /// @@ -575,10 +575,10 @@ fn rt_waitTicks2() void { const difference = getTicks() + 15 - waiting; if (previous_count + epsilon < difference or previous_count > difference + epsilon) { - panic(@errorReturnTrace(), "Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", difference, previous_count, epsilon); + panic(@errorReturnTrace(), "Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", .{ difference, previous_count, epsilon }); } - log.logInfo("PIT: Tested wait ticks 2\n"); + log.logInfo("PIT: Tested wait ticks 2\n", .{}); // Reset ticks ticks = 0; @@ -593,16 +593,14 @@ fn rt_initCounter_0() void { const expected_hz: u32 = 10027; if (time_ns != expected_ns or time_under_1_ns != expected_ps or getFrequency() != expected_hz) { - panic( - @errorReturnTrace(), - "Frequency not set properly. Hz: {}!={}, ns: {}!={}, ps: {}!= {}\n", + panic(@errorReturnTrace(), "Frequency not set properly. Hz: {}!={}, ns: {}!={}, ps: {}!= {}\n", .{ getFrequency(), expected_hz, time_ns, expected_ns, time_under_1_ns, expected_ps, - ); + }); } var irq_exists = false; @@ -613,22 +611,22 @@ fn rt_initCounter_0() void { irq_exists = true; }, error.InvalidIrq => { - panic(@errorReturnTrace(), "IRQ for PIT, IRQ number: {} is invalid", pic.IRQ_PIT); + panic(@errorReturnTrace(), "IRQ for PIT, IRQ number: {} is invalid", .{pic.IRQ_PIT}); }, }; if (!irq_exists) { - panic(@errorReturnTrace(), "IRQ for PIT doesn't exists\n"); + panic(@errorReturnTrace(), "IRQ for PIT doesn't exists\n", .{}); } const expected_mode = OCW_READ_LOAD_DATA | OCW_MODE_SQUARE_WAVE_GENERATOR | OCW_SELECT_COUNTER_0 | OCW_BINARY_COUNT_BINARY; const actual_mode = readBackCommand(CounterSelect.Counter0); if (expected_mode != actual_mode) { - panic(@errorReturnTrace(), "Operating mode don't not set properly. Found: {}, expecting: {}\n", actual_mode, expected_mode); + panic(@errorReturnTrace(), "Operating mode don't not set properly. Found: {}, expecting: {}\n", .{ actual_mode, expected_mode }); } - log.logInfo("PIT: Tested init\n"); + log.logInfo("PIT: Tested init\n", .{}); } /// diff --git a/src/kernel/arch/x86/syscalls.zig b/src/kernel/arch/x86/syscalls.zig index f208fb5..6d503d5 100644 --- a/src/kernel/arch/x86/syscalls.zig +++ b/src/kernel/arch/x86/syscalls.zig @@ -53,10 +53,10 @@ fn handle(ctx: *arch.InterruptContext) void { if (handlers[syscall]) |handler| { ctx.eax = handler(ctx, syscallArg(ctx, 0), syscallArg(ctx, 1), syscallArg(ctx, 2), syscallArg(ctx, 3), syscallArg(ctx, 4)); } else { - log.logWarning("Syscall {} triggered but not registered\n", syscall); + log.logWarning("Syscall {} triggered but not registered\n", .{syscall}); } } else { - log.logWarning("Syscall {} is invalid\n", syscall); + log.logWarning("Syscall {} is invalid\n", .{syscall}); } } @@ -237,9 +237,9 @@ inline fn syscallArg(ctx: *arch.InterruptContext, comptime arg_idx: u32) u32 { /// Initialise syscalls. Registers the isr associated with INTERRUPT. /// pub fn init() void { - log.logInfo("Init syscalls\n"); + log.logInfo("Init syscalls\n", .{}); isr.registerIsr(INTERRUPT, handle) catch unreachable; - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (options.rt_test) runtimeTests(); } @@ -294,20 +294,20 @@ fn runtimeTests() void { assert(testInt == 0); if (syscall0(123) == 0 and testInt == 1) - log.logInfo("Syscalls: Tested no args\n"); + log.logInfo("Syscalls: Tested no args\n", .{}); if (syscall1(124, 2) == 1 and testInt == 3) - log.logInfo("Syscalls: Tested 1 arg\n"); + log.logInfo("Syscalls: Tested 1 arg\n", .{}); if (syscall2(125, 2, 3) == 2 and testInt == 8) - log.logInfo("Syscalls: Tested 2 args\n"); + log.logInfo("Syscalls: Tested 2 args\n", .{}); if (syscall3(126, 2, 3, 4) == 3 and testInt == 17) - log.logInfo("Syscalls: Tested 3 args\n"); + log.logInfo("Syscalls: Tested 3 args\n", .{}); if (syscall4(127, 2, 3, 4, 5) == 4 and testInt == 31) - log.logInfo("Syscalls: Tested 4 args\n"); + log.logInfo("Syscalls: Tested 4 args\n", .{}); if (syscall5(128, 2, 3, 4, 5, 6) == 5 and testInt == 51) - log.logInfo("Syscalls: Tested 5 args\n"); + log.logInfo("Syscalls: Tested 5 args\n", .{}); } diff --git a/src/kernel/kmain.zig b/src/kernel/kmain.zig index eb9c0ef..1fc5046 100644 --- a/src/kernel/kmain.zig +++ b/src/kernel/kmain.zig @@ -27,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.panic(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.panic(@errorReturnTrace(), "Failed to initialise serial: {}", e); + panic_root.panic(@errorReturnTrace(), "Failed to initialise serial: {}", .{e}); }; if (build_options.rt_test) log.runtimeTests(); @@ -42,17 +42,17 @@ export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void { var buffer = mem_profile.vaddr_end[0..mem_profile.fixed_alloc_size]; var fixed_allocator = std.heap.FixedBufferAllocator.init(buffer); - log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n"); + log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n", .{}); arch.init(mb_info, &mem_profile, &fixed_allocator.allocator); - log.logInfo("Arch init done\n"); + 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); + 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"); + 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(); } diff --git a/src/kernel/log.zig b/src/kernel/log.zig index 32fd7e4..b46a66f 100644 --- a/src/kernel/log.zig +++ b/src/kernel/log.zig @@ -12,38 +12,74 @@ fn logCallback(context: void, str: []const u8) anyerror!void { serial.writeBytes(str, serial.Port.COM1); } -pub fn log(comptime level: Level, comptime format: []const u8, args: ...) void { +/// +/// Write a message to the log output stream with a certain logging level. +/// +/// Arguments: +/// IN comptime level: Level - The logging level to use. Determines the message prefix and whether it is filtered. +/// IN comptime format: []const u8 - The message format. Uses the standard format specification options. +/// IN args: var - A struct of the parameters for the format string. +/// +pub fn log(comptime level: Level, comptime format: []const u8, args: var) void { fmt.format({}, anyerror, logCallback, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable; } -pub fn logInfo(comptime format: []const u8, args: ...) void { +/// +/// Write a message to the log output stream with the INFO level. +/// +/// Arguments: +/// IN comptime format: []const u8 - The message format. Uses the standard format specification options. +/// IN args: var - A struct of the parameters for the format string. +/// +pub fn logInfo(comptime format: []const u8, args: var) void { log(Level.INFO, format, args); } -pub fn logDebug(comptime format: []const u8, args: ...) void { +/// +/// Write a message to the log output stream with the DEBUG level. +/// +/// Arguments: +/// IN comptime format: []const u8 - The message format. Uses the standard format specification options. +/// IN args: var - A struct of the parameters for the format string. +/// +pub fn logDebug(comptime format: []const u8, args: var) void { log(Level.DEBUG, format, args); } -pub fn logWarning(comptime format: []const u8, args: ...) void { +/// +/// Write a message to the log output stream with the WARNING level. +/// +/// Arguments: +/// IN comptime format: []const u8 - The message format. Uses the standard format specification options. +/// IN args: var - A struct of the parameters for the format string. +/// +pub fn logWarning(comptime format: []const u8, args: var) void { log(Level.WARNING, format, args); } -pub fn logError(comptime format: []const u8, args: ...) void { +/// +/// Write a message to the log output stream with the ERROR level. +/// +/// Arguments: +/// IN comptime format: []const u8 - The message format. Uses the standard format specification options. +/// IN args: var - A struct of the parameters for the format string. +/// +pub fn logError(comptime format: []const u8, args: var) void { log(Level.ERROR, format, args); } pub fn runtimeTests() void { inline for (@typeInfo(Level).Enum.fields) |field| { const level = @field(Level, field.name); - log(level, "Test " ++ field.name ++ " level\n"); - log(level, "Test " ++ field.name ++ " level with args {}, {}\n", "a", @as(u32, 1)); + log(level, "Test " ++ field.name ++ " level\n", .{}); + log(level, "Test " ++ field.name ++ " level with args {}, {}\n", .{ "a", @as(u32, 1) }); const logFn = switch (level) { .INFO => logInfo, .DEBUG => logDebug, .WARNING => logWarning, .ERROR => logError, }; - logFn("Test " ++ field.name ++ " function\n"); - logFn("Test " ++ field.name ++ " function with args {}, {}\n", "a", @as(u32, 1)); + logFn("Test " ++ field.name ++ " function\n", .{}); + logFn("Test " ++ field.name ++ " function with args {}, {}\n", .{ "a", @as(u32, 1) }); } } diff --git a/src/kernel/mem.zig b/src/kernel/mem.zig index f6ae59e..43b42f5 100644 --- a/src/kernel/mem.zig +++ b/src/kernel/mem.zig @@ -46,7 +46,7 @@ var ADDR_OFFSET: usize = undefined; /// The memory profile constructed from the exported linker symbols and the relevant multiboot info. /// pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile { - log.logInfo("Init mem\n"); + log.logInfo("Init mem\n", .{}); const mods_count = mb_info.mods_count; ADDR_OFFSET = @ptrToInt(&KERNEL_ADDR_OFFSET); const mem_profile = MemProfile{ @@ -59,7 +59,7 @@ pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile { .fixed_alloc_size = FIXED_ALLOC_SIZE, .boot_modules = @intToPtr([*]multiboot.multiboot_mod_list, physToVirt(mb_info.mods_addr))[0..mods_count], }; - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); return mem_profile; } @@ -69,11 +69,11 @@ pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile { /// Arguments: /// IN virt: var - The virtual address to covert. Either an integer or pointer. /// -/// Return: @typeOf(virt) +/// Return: @TypeOf(virt) /// The physical address. /// -pub inline fn virtToPhys(virt: var) @typeOf(virt) { - const T = @typeOf(virt); +pub inline fn virtToPhys(virt: var) @TypeOf(virt) { + const T = @TypeOf(virt); return switch (@typeId(T)) { .Pointer => @intToPtr(T, @ptrToInt(virt) - ADDR_OFFSET), .Int => virt - ADDR_OFFSET, @@ -87,11 +87,11 @@ pub inline fn virtToPhys(virt: var) @typeOf(virt) { /// Arguments: /// IN phys: var - The physical address to covert. Either an integer or pointer. /// -/// Return: @typeOf(virt) +/// Return: @TypeOf(virt) /// The virtual address. /// -pub inline fn physToVirt(phys: var) @typeOf(phys) { - const T = @typeOf(phys); +pub inline fn physToVirt(phys: var) @TypeOf(phys) { + const T = @TypeOf(phys); return switch (@typeId(T)) { .Pointer => @intToPtr(T, @ptrToInt(phys) + ADDR_OFFSET), .Int => phys + ADDR_OFFSET, @@ -104,7 +104,7 @@ test "physToVirt" { const offset: usize = ADDR_OFFSET; expectEqual(physToVirt(@as(usize, 0)), offset + 0); expectEqual(physToVirt(@as(usize, 123)), offset + 123); - expectEqual(@ptrToInt(physToVirt(@intToPtr(*usize, 123))), offset + 123); + expectEqual(@ptrToInt(physToVirt(@intToPtr(*align(1) usize, 123))), offset + 123); } test "virtToPhys" { @@ -112,5 +112,5 @@ test "virtToPhys" { const offset: usize = ADDR_OFFSET; expectEqual(virtToPhys(offset + 0), 0); expectEqual(virtToPhys(offset + 123), 123); - expectEqual(@ptrToInt(virtToPhys(@intToPtr(*usize, offset + 123))), 123); + expectEqual(@ptrToInt(virtToPhys(@intToPtr(*align(1) usize, offset + 123))), 123); } diff --git a/src/kernel/multiboot.zig b/src/kernel/multiboot.zig index 76fbfca..416d859 100644 --- a/src/kernel/multiboot.zig +++ b/src/kernel/multiboot.zig @@ -1,4 +1,3 @@ -// Autogenerated by zig translate-c pub const multiboot_uint8_t = u8; pub const multiboot_uint16_t = c_ushort; pub const multiboot_uint32_t = c_uint; @@ -109,72 +108,75 @@ pub const struct_multiboot_apm_info = extern struct { dseg_len: multiboot_uint16_t, }; pub const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1; -pub const __FLT16_MAX_EXP__ = 15; pub const __BIGGEST_ALIGNMENT__ = 16; pub const __SIZEOF_FLOAT__ = 4; -pub const __INT64_FMTd__ = c"ld"; -pub const __STDC_VERSION__ = c_long(201112); -pub const __INT_LEAST32_FMTi__ = c"i"; -pub const __INT_LEAST8_FMTi__ = c"hhi"; -pub const __LDBL_EPSILON__ = -nan; +pub const __INT64_FMTd__ = "ld"; +pub const __STDC_VERSION__ = @as(c_long, 201112); +pub const __INT_LEAST32_FMTi__ = "i"; +pub const __tune_znver1__ = 1; +pub const __INT_LEAST8_FMTi__ = "hhi"; +pub const __LDBL_EPSILON__ = 0.000000; pub const __LZCNT__ = 1; -pub const __INT_LEAST32_FMTd__ = c"d"; +pub const __INT_LEAST32_FMTd__ = "d"; pub const __STDC_UTF_32__ = 1; -pub const __INVPCID__ = 1; pub const __SIG_ATOMIC_WIDTH__ = 32; pub const MULTIBOOT_MEMORY_BADRAM = 5; -pub const __UINT_FAST64_FMTX__ = c"lX"; +pub const __UINT_FAST64_FMTX__ = "lX"; pub const __GCC_ATOMIC_LLONG_LOCK_FREE = 2; -pub const __clang_version__ = c"8.0.0 (tags/RELEASE_800/rc5)"; -pub const __UINT_LEAST8_FMTo__ = c"hho"; +pub const __SEG_FS = 1; +pub const __clang_version__ = "9.0.0 (tags/RELEASE_900/final)"; +pub const __UINT_LEAST8_FMTo__ = "hho"; +pub const __GCC_ASM_FLAG_OUTPUTS__ = 1; pub const __SIZEOF_DOUBLE__ = 8; -pub const __INTMAX_FMTd__ = c"ld"; +pub const __INTMAX_FMTd__ = "ld"; pub const __CLANG_ATOMIC_CHAR_LOCK_FREE = 2; -pub const __INT_LEAST16_FMTi__ = c"hi"; +pub const __INT_LEAST16_FMTi__ = "hi"; pub const __GCC_ATOMIC_SHORT_LOCK_FREE = 2; pub const __FMA__ = 1; pub const __MMX__ = 1; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 = 1; -pub const __SIZE_FMTX__ = c"lX"; +pub const __SIZE_FMTX__ = "lX"; +pub const __RDSEED__ = 1; pub const __WCHAR_WIDTH__ = 32; pub const __FSGSBASE__ = 1; -pub const __PTRDIFF_FMTd__ = c"ld"; +pub const __PTRDIFF_FMTd__ = "ld"; pub const __DBL_MIN_EXP__ = -1021; pub const __FLT_EVAL_METHOD__ = 0; pub const __SSE_MATH__ = 1; -pub const __UINT_FAST8_FMTo__ = c"hho"; -pub const __UINT_LEAST64_MAX__ = c_ulong(18446744073709551615); +pub const __UINT_FAST8_FMTo__ = "hho"; +pub const __UINT_LEAST64_MAX__ = @as(c_ulong, 18446744073709551615); pub const MULTIBOOT_INFO_BOOT_LOADER_NAME = 512; -pub const __UINT_LEAST64_FMTx__ = c"lx"; +pub const __UINT_LEAST64_FMTx__ = "lx"; pub const __INT8_MAX__ = 127; +pub const __znver1 = 1; pub const MULTIBOOT_MEMORY_AVAILABLE = 1; pub const __DBL_HAS_DENORM__ = 1; pub const __FLOAT128__ = 1; -pub const __FLT16_HAS_QUIET_NAN__ = 1; pub const __ATOMIC_RELAXED = 0; pub const __DBL_DECIMAL_DIG__ = 17; +pub const __XSAVEC__ = 1; pub const MULTIBOOT_SEARCH = 8192; pub const __SIZEOF_SHORT__ = 2; -pub const __UINT16_FMTX__ = c"hX"; pub const __UINT_FAST16_MAX__ = 65535; +pub const __UINT16_FMTX__ = "hX"; pub const __CLANG_ATOMIC_SHORT_LOCK_FREE = 2; pub const __SSSE3__ = 1; pub const __CONSTANT_CFSTRINGS__ = 1; pub const __AVX2__ = 1; pub const __LDBL_MAX_EXP__ = 16384; -pub const __WINT_MAX__ = c_uint(4294967295); +pub const __WINT_MAX__ = @as(c_uint, 4294967295); pub const __NO_MATH_INLINES = 1; pub const __WCHAR_TYPE__ = int; -pub const __LONG_MAX__ = c_long(9223372036854775807); +pub const __LONG_MAX__ = @as(c_long, 9223372036854775807); pub const __STDC_HOSTED__ = 1; pub const MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT = 2; -pub const __INT_FAST16_FMTi__ = c"hi"; pub const __PTRDIFF_WIDTH__ = 64; +pub const __INT_FAST16_FMTi__ = "hi"; pub const __INT_LEAST32_TYPE__ = int; pub const __SCHAR_MAX__ = 127; -pub const __LDBL_DENORM_MIN__ = -nan; -pub const __FLT16_MIN_EXP__ = -14; +pub const __LDBL_DENORM_MIN__ = 0.000000; pub const MULTIBOOT_INFO_AOUT_SYMS = 16; +pub const __PRFCHW__ = 1; pub const __INT64_C_SUFFIX__ = L; pub const __ELF__ = 1; pub const __LDBL_MANT_DIG__ = 64; @@ -183,40 +185,40 @@ pub const MULTIBOOT_INFO_CONFIG_TABLE = 256; pub const __CLANG_ATOMIC_INT_LOCK_FREE = 2; pub const __SIZEOF_PTRDIFF_T__ = 8; pub const __SIG_ATOMIC_MAX__ = 2147483647; -pub const __UINT64_FMTX__ = c"lX"; -pub const __UINT64_MAX__ = c_ulong(18446744073709551615); +pub const __UINT64_FMTX__ = "lX"; +pub const __UINT64_MAX__ = @as(c_ulong, 18446744073709551615); pub const __DBL_MANT_DIG__ = 53; pub const __FLT_DECIMAL_DIG__ = 9; pub const __INT_LEAST32_MAX__ = 2147483647; pub const __DBL_DIG__ = 15; pub const __ATOMIC_ACQUIRE = 2; pub const __OPENCL_MEMORY_SCOPE_WORK_GROUP = 1; -pub const __FLT16_HAS_DENORM__ = 1; -pub const __UINT_FAST16_FMTu__ = c"hu"; -pub const __INTPTR_FMTi__ = c"li"; +pub const __UINT_FAST16_FMTu__ = "hu"; +pub const __INTPTR_FMTi__ = "li"; pub const MULTIBOOT_INFO_MODS = 8; -pub const __UINT_FAST8_FMTX__ = c"hhX"; +pub const __UINT_FAST8_FMTX__ = "hhX"; pub const __LITTLE_ENDIAN__ = 1; pub const __SSE__ = 1; pub const __FLT_HAS_QUIET_NAN__ = 1; pub const __SIZEOF_SIZE_T__ = 8; -pub const __UINT_LEAST16_FMTo__ = c"ho"; -pub const __UINT8_FMTo__ = c"hho"; -pub const __UINT_LEAST16_FMTx__ = c"hx"; +pub const __SEG_GS = 1; +pub const __UINT_LEAST16_FMTo__ = "ho"; +pub const __UINT8_FMTo__ = "hho"; +pub const __UINT_LEAST16_FMTx__ = "hx"; pub const __CLANG_ATOMIC_WCHAR_T_LOCK_FREE = 2; -pub const __UINT_FAST16_FMTX__ = c"hX"; -pub const __VERSION__ = c"4.2.1 Compatible Clang 8.0.0 (tags/RELEASE_800/rc5)"; -pub const __UINT_FAST32_FMTx__ = c"x"; -pub const __UINTPTR_MAX__ = c_ulong(18446744073709551615); +pub const __UINT_FAST16_FMTX__ = "hX"; +pub const __VERSION__ = "Clang 9.0.0 (tags/RELEASE_900/final)"; +pub const __UINT_FAST32_FMTx__ = "x"; +pub const __UINTPTR_MAX__ = @as(c_ulong, 18446744073709551615); pub const MULTIBOOT_INFO_ALIGN = 4; -pub const __UINT_FAST8_FMTu__ = c"hhu"; -pub const __UINT_LEAST8_FMTu__ = c"hhu"; -pub const __UINT_LEAST64_FMTo__ = c"lo"; +pub const __UINT_FAST8_FMTu__ = "hhu"; +pub const __UINT_LEAST8_FMTu__ = "hhu"; +pub const __UINT_LEAST64_FMTo__ = "lo"; pub const __UINT_LEAST8_MAX__ = 255; pub const __RDRND__ = 1; pub const __SIZEOF_WCHAR_T__ = 4; pub const __MOVBE__ = 1; -pub const __LDBL_MAX__ = -nan; +pub const __LDBL_MAX__ = inf; pub const __UINT16_MAX__ = 65535; pub const _LP64 = 1; pub const __x86_64 = 1; @@ -224,168 +226,165 @@ pub const __code_model_small_ = 1; pub const linux = 1; pub const __SIZEOF_WINT_T__ = 4; pub const MULTIBOOT_INFO_CMDLINE = 4; -pub const __UINTMAX_FMTo__ = c"lo"; +pub const __UINTMAX_FMTo__ = "lo"; pub const __FLT_DIG__ = 6; -pub const __UINT_LEAST8_FMTX__ = c"hhX"; +pub const __UINT_LEAST8_FMTX__ = "hhX"; pub const __INT16_MAX__ = 32767; pub const __WINT_UNSIGNED__ = 1; pub const __FLT_MAX_10_EXP__ = 38; -pub const __UINTPTR_FMTX__ = c"lX"; -pub const __UINT_LEAST16_FMTu__ = c"hu"; +pub const __UINTPTR_FMTX__ = "lX"; +pub const __UINT_LEAST16_FMTu__ = "hu"; pub const __CLANG_ATOMIC_POINTER_LOCK_FREE = 2; pub const __WINT_WIDTH__ = 32; pub const __F16C__ = 1; pub const __SHRT_MAX__ = 32767; +pub const __znver1__ = 1; pub const __GCC_ATOMIC_BOOL_LOCK_FREE = 2; pub const __POINTER_WIDTH__ = 64; -pub const __PTRDIFF_MAX__ = c_long(9223372036854775807); -pub const __tune_corei7__ = 1; -pub const __FLT16_DIG__ = 3; -pub const __INT32_FMTd__ = c"d"; -pub const __DBL_MIN__ = -nan; +pub const __PTRDIFF_MAX__ = @as(c_long, 9223372036854775807); +pub const __INT32_FMTd__ = "d"; +pub const __DBL_MIN__ = 0.000000; pub const __SIZEOF_LONG__ = 8; pub const __INTPTR_WIDTH__ = 64; pub const MULTIBOOT_INFO_VBE_INFO = 2048; -pub const __FLT16_MAX_10_EXP__ = 4; pub const __INT_FAST32_TYPE__ = int; pub const __NO_INLINE__ = 1; -pub const __UINT_FAST32_FMTX__ = c"X"; +pub const __UINT_FAST32_FMTX__ = "X"; pub const MULTIBOOT_AOUT_KLUDGE = 65536; pub const __gnu_linux__ = 1; pub const __INT_FAST32_MAX__ = 2147483647; -pub const __corei7__ = 1; -pub const __UINTMAX_FMTu__ = c"lu"; +pub const __UINTMAX_FMTu__ = "lu"; pub const MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED = 0; pub const __BMI__ = 1; pub const MULTIBOOT_INFO_BOOTDEV = 2; pub const __FLT_RADIX__ = 2; pub const MULTIBOOT_INFO_MEMORY = 1; -pub const __FLT16_HAS_INFINITY__ = 1; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1; pub const MULTIBOOT_FRAMEBUFFER_TYPE_RGB = 1; pub const __GCC_ATOMIC_INT_LOCK_FREE = 2; pub const __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES = 3; -pub const __FLT16_DECIMAL_DIG__ = 5; pub const __PRAGMA_REDEFINE_EXTNAME = 1; -pub const __INT_FAST8_FMTd__ = c"hhd"; +pub const __INT_FAST8_FMTd__ = "hhd"; pub const __INT32_TYPE__ = int; pub const MULTIBOOT_BOOTLOADER_MAGIC = 732803074; pub const __UINTMAX_WIDTH__ = 64; -pub const __FLT_MIN__ = -nan; -pub const __INT64_FMTi__ = c"li"; -pub const __UINT_FAST64_FMTu__ = c"lu"; -pub const __INT8_FMTd__ = c"hhd"; +pub const __FLT_MIN__ = 0.000000; +pub const __INT64_FMTi__ = "li"; +pub const __UINT_FAST64_FMTu__ = "lu"; +pub const __INT8_FMTd__ = "hhd"; pub const __INT_FAST16_TYPE__ = short; pub const __FLT_MAX_EXP__ = 128; pub const __XSAVE__ = 1; pub const __DBL_MAX_10_EXP__ = 308; -pub const __LDBL_MIN__ = -nan; -pub const __INT_FAST64_FMTi__ = c"li"; -pub const __INT_LEAST8_FMTd__ = c"hhd"; +pub const __LDBL_MIN__ = 0.000000; +pub const __INT_FAST64_FMTi__ = "li"; +pub const __INT_LEAST8_FMTd__ = "hhd"; pub const __CLANG_ATOMIC_LLONG_LOCK_FREE = 2; -pub const __UINT_LEAST32_FMTX__ = c"X"; -pub const __UINTMAX_MAX__ = c_ulong(18446744073709551615); -pub const __UINT_FAST16_FMTo__ = c"ho"; +pub const __UINT_LEAST32_FMTX__ = "X"; +pub const __UINTMAX_MAX__ = @as(c_ulong, 18446744073709551615); +pub const __UINT_FAST16_FMTo__ = "ho"; pub const __LDBL_DECIMAL_DIG__ = 21; -pub const __UINT_LEAST64_FMTX__ = c"lX"; +pub const __UINT_LEAST64_FMTX__ = "lX"; pub const __clang_minor__ = 0; pub const __SIZEOF_FLOAT128__ = 16; -pub const __UINT_FAST64_FMTo__ = c"lo"; -pub const __SIZE_FMTx__ = c"lx"; -pub const __DBL_MAX__ = -nan; -pub const __DBL_EPSILON__ = -nan; -pub const __UINT64_FMTx__ = c"lx"; +pub const __UINT_FAST64_FMTo__ = "lo"; +pub const __SIZE_FMTx__ = "lx"; +pub const __DBL_MAX__ = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878; +pub const __DBL_EPSILON__ = 0.000000; +pub const __UINT64_FMTx__ = "lx"; pub const MULTIBOOT_HEADER = 1; +pub const __CLWB__ = 1; pub const __CHAR_BIT__ = 8; -pub const __INT16_FMTi__ = c"hi"; +pub const __INT16_FMTi__ = "hi"; pub const _DEBUG = 1; pub const __GNUC_MINOR__ = 2; -pub const __UINT_FAST32_MAX__ = c_uint(4294967295); -pub const __UINT8_FMTX__ = c"hhX"; -pub const __FLT_EPSILON__ = -nan; +pub const __UINT_FAST32_MAX__ = @as(c_uint, 4294967295); +pub const __UINT8_FMTX__ = "hhX"; +pub const __FLT_EPSILON__ = 0.000000; pub const __UINTPTR_WIDTH__ = 64; pub const __llvm__ = 1; -pub const __UINT_FAST64_MAX__ = c_ulong(18446744073709551615); -pub const __INT_FAST32_FMTi__ = c"i"; +pub const __UINT_FAST64_MAX__ = @as(c_ulong, 18446744073709551615); +pub const __INT_FAST32_FMTi__ = "i"; pub const __FLT_HAS_INFINITY__ = 1; pub const __AES__ = 1; -pub const __UINT8_FMTx__ = c"hhx"; +pub const __UINT8_FMTx__ = "hhx"; pub const __INTMAX_C_SUFFIX__ = L; pub const __ORDER_LITTLE_ENDIAN__ = 1234; pub const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2; -pub const __INT16_FMTd__ = c"hd"; -pub const __UINT32_FMTX__ = c"X"; +pub const __INT16_FMTd__ = "hd"; +pub const __UINT32_FMTX__ = "X"; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1; pub const __UINT32_C_SUFFIX__ = U; pub const __INT32_MAX__ = 2147483647; pub const __GCC_ATOMIC_CHAR_LOCK_FREE = 2; pub const __INTMAX_WIDTH__ = 64; pub const __CLANG_ATOMIC_BOOL_LOCK_FREE = 2; -pub const __SIZE_FMTo__ = c"lo"; +pub const __SIZE_FMTo__ = "lo"; pub const __DBL_HAS_QUIET_NAN__ = 1; -pub const __INT_FAST8_FMTi__ = c"hhi"; -pub const __UINT_LEAST32_FMTo__ = c"o"; +pub const __INT_FAST8_FMTi__ = "hhi"; +pub const __UINT_LEAST32_FMTo__ = "o"; pub const __STDC_UTF_16__ = 1; -pub const __UINT_LEAST32_MAX__ = c_uint(4294967295); +pub const __UINT_LEAST32_MAX__ = @as(c_uint, 4294967295); pub const __ATOMIC_RELEASE = 3; -pub const __UINT_FAST16_FMTx__ = c"hx"; +pub const __UINT_FAST16_FMTx__ = "hx"; pub const __UINTMAX_C_SUFFIX__ = UL; pub const __FLT_MIN_EXP__ = -125; pub const __SIZEOF_LONG_DOUBLE__ = 16; -pub const __UINT_LEAST64_FMTu__ = c"lu"; +pub const __UINT_LEAST64_FMTu__ = "lu"; pub const MULTIBOOT_MOD_ALIGN = 4096; pub const __GCC_ATOMIC_LONG_LOCK_FREE = 2; pub const __ORDER_PDP_ENDIAN__ = 3412; pub const MULTIBOOT_PAGE_ALIGN = 1; -pub const __INT_FAST64_FMTd__ = c"ld"; +pub const __INT_FAST64_FMTd__ = "ld"; pub const __CLANG_ATOMIC_LONG_LOCK_FREE = 2; pub const __GXX_ABI_VERSION = 1002; pub const __INT16_TYPE__ = short; +pub const __MWAITX__ = 1; pub const __SSE2_MATH__ = 1; pub const __FLT_MANT_DIG__ = 24; -pub const __UINT_FAST64_FMTx__ = c"lx"; +pub const __UINT_FAST64_FMTx__ = "lx"; pub const __STDC__ = 1; pub const __INT_FAST8_MAX__ = 127; -pub const __INTPTR_FMTd__ = c"ld"; +pub const __INTPTR_FMTd__ = "ld"; pub const __GNUC_PATCHLEVEL__ = 1; -pub const __UINT_LEAST8_FMTx__ = c"hhx"; +pub const __UINT_LEAST8_FMTx__ = "hhx"; pub const __SIZE_WIDTH__ = 64; -pub const __INT_LEAST64_FMTi__ = c"li"; +pub const __INT_LEAST64_FMTi__ = "li"; pub const __SSE4_2__ = 1; pub const __AVX__ = 1; pub const __INT_FAST16_MAX__ = 32767; -pub const __INTPTR_MAX__ = c_long(9223372036854775807); +pub const __INTPTR_MAX__ = @as(c_long, 9223372036854775807); pub const __CLANG_ATOMIC_CHAR16_T_LOCK_FREE = 2; -pub const __UINT64_FMTu__ = c"lu"; +pub const __UINT64_FMTu__ = "lu"; pub const __BYTE_ORDER__ = __ORDER_LITTLE_ENDIAN__; pub const __SSE2__ = 1; pub const MULTIBOOT_INFO_FRAMEBUFFER_INFO = 4096; pub const __INT_MAX__ = 2147483647; -pub const __INTMAX_FMTi__ = c"li"; -pub const __DBL_DENORM_MIN__ = -nan; +pub const __INTMAX_FMTi__ = "li"; +pub const __DBL_DENORM_MIN__ = 0.000000; pub const MULTIBOOT_INFO_APM_TABLE = 1024; -pub const __clang_major__ = 8; -pub const __FLT16_MANT_DIG__ = 11; +pub const __clang_major__ = 9; pub const __GNUC__ = 4; -pub const __UINT32_MAX__ = c_uint(4294967295); +pub const __UINT32_MAX__ = @as(c_uint, 4294967295); pub const MULTIBOOT_MEMORY_RESERVED = 2; -pub const __FLT_DENORM_MIN__ = -nan; +pub const __FLT_DENORM_MIN__ = 0.000000; pub const __DBL_MAX_EXP__ = 1024; -pub const __INT8_FMTi__ = c"hhi"; +pub const __INT8_FMTi__ = "hhi"; pub const __UINT_LEAST16_MAX__ = 65535; +pub const __XSAVES__ = 1; pub const __LDBL_HAS_DENORM__ = 1; -pub const __FLT16_MIN_10_EXP__ = -13; pub const __LDBL_HAS_QUIET_NAN__ = 1; pub const __UINT_FAST8_MAX__ = 255; pub const __DBL_MIN_10_EXP__ = -307; -pub const __UINT8_FMTu__ = c"hhu"; -pub const __INT_FAST64_MAX__ = c_long(9223372036854775807); +pub const __UINT8_FMTu__ = "hhu"; +pub const __SSE4A__ = 1; +pub const __INT_FAST64_MAX__ = @as(c_long, 9223372036854775807); pub const __SSE3__ = 1; -pub const __UINT16_FMTu__ = c"hu"; +pub const __UINT16_FMTu__ = "hu"; pub const __ATOMIC_SEQ_CST = 5; -pub const __SIZE_FMTu__ = c"lu"; +pub const __SIZE_FMTu__ = "lu"; pub const __LDBL_MIN_EXP__ = -16381; -pub const __UINT_FAST32_FMTu__ = c"u"; +pub const __UINT_FAST32_FMTu__ = "u"; pub const __clang_patchlevel__ = 0; pub const __SIZEOF_LONG_LONG__ = 8; pub const __BMI2__ = 1; @@ -395,35 +394,34 @@ pub const __PCLMUL__ = 1; pub const __FXSR__ = 1; pub const __UINT8_MAX__ = 255; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1; -pub const __UINT32_FMTx__ = c"x"; -pub const __UINT16_FMTo__ = c"ho"; +pub const __UINT32_FMTx__ = "x"; +pub const __UINT16_FMTo__ = "ho"; pub const __POPCNT__ = 1; pub const __OPENCL_MEMORY_SCOPE_DEVICE = 2; pub const MULTIBOOT_VIDEO_MODE = 4; -pub const __UINT32_FMTu__ = c"u"; +pub const __UINT32_FMTu__ = "u"; pub const __SIZEOF_POINTER__ = 8; -pub const __SIZE_MAX__ = c_ulong(18446744073709551615); +pub const __SIZE_MAX__ = @as(c_ulong, 18446744073709551615); pub const __unix = 1; -pub const __INT_FAST16_FMTd__ = c"hd"; +pub const __INT_FAST16_FMTd__ = "hd"; pub const unix = 1; -pub const __UINT_LEAST32_FMTu__ = c"u"; -pub const __FLT_MAX__ = -nan; -pub const __corei7 = 1; +pub const __UINT_LEAST32_FMTu__ = "u"; +pub const __FLT_MAX__ = 340282346999999984391321947108527833088.000000; pub const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2; pub const __ATOMIC_CONSUME = 1; pub const __unix__ = 1; pub const __x86_64__ = 1; pub const __LDBL_HAS_INFINITY__ = 1; -pub const __UINTMAX_FMTx__ = c"lx"; +pub const __UINTMAX_FMTx__ = "lx"; pub const __UINT64_C_SUFFIX__ = UL; -pub const __INT_LEAST16_MAX__ = 32767; pub const __FLT_MIN_10_EXP__ = -37; -pub const __UINT32_FMTo__ = c"o"; -pub const __UINTPTR_FMTo__ = c"lo"; -pub const __INT_LEAST16_FMTd__ = c"hd"; -pub const __UINTPTR_FMTx__ = c"lx"; +pub const __INT_LEAST16_MAX__ = 32767; +pub const __UINT32_FMTo__ = "o"; +pub const __UINTPTR_FMTo__ = "lo"; +pub const __INT_LEAST16_FMTd__ = "hd"; +pub const __UINTPTR_FMTx__ = "lx"; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1; -pub const __INT_LEAST64_FMTd__ = c"ld"; +pub const __INT_LEAST64_FMTd__ = "ld"; pub const __INT_LEAST16_TYPE__ = short; pub const MULTIBOOT_HEADER_MAGIC = 464367618; pub const __ORDER_BIG_ENDIAN__ = 4321; @@ -432,45 +430,51 @@ pub const __INT_LEAST8_MAX__ = 127; pub const __SIZEOF_INT__ = 4; pub const __GCC_ATOMIC_POINTER_LOCK_FREE = 2; pub const MULTIBOOT_INFO_DRIVE_INFO = 128; +pub const __SHA__ = 1; pub const MULTIBOOT_MEMORY_INFO = 2; pub const __amd64 = 1; pub const __OBJC_BOOL_IS_BOOL = 0; +pub const __ADX__ = 1; pub const __LDBL_MAX_10_EXP__ = 4932; pub const __SIZEOF_INT128__ = 16; -pub const __UINT_FAST8_FMTx__ = c"hhx"; +pub const __UINT_FAST8_FMTx__ = "hhx"; +pub const __CLZERO__ = 1; pub const __linux = 1; -pub const __UINT16_FMTx__ = c"hx"; -pub const __UINTPTR_FMTu__ = c"lu"; -pub const __UINT_LEAST16_FMTX__ = c"hX"; +pub const __UINT16_FMTx__ = "hx"; +pub const __UINTPTR_FMTu__ = "lu"; +pub const __UINT_LEAST16_FMTX__ = "hX"; +pub const __CLFLUSHOPT__ = 1; pub const __amd64__ = 1; -pub const __UINT_FAST32_FMTo__ = c"o"; +pub const __UINT_FAST32_FMTo__ = "o"; pub const __linux__ = 1; pub const __clang__ = 1; pub const __LP64__ = 1; -pub const __PTRDIFF_FMTi__ = c"li"; +pub const __PTRDIFF_FMTi__ = "li"; +pub const __WBNOINVD__ = 1; pub const __SSE4_1__ = 1; pub const __LDBL_DIG__ = 18; pub const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2; pub const __XSAVEOPT__ = 1; -pub const __UINT64_FMTo__ = c"lo"; -pub const __INT_FAST32_FMTd__ = c"d"; +pub const __UINT64_FMTo__ = "lo"; +pub const __INT_FAST32_FMTd__ = "d"; pub const __ATOMIC_ACQ_REL = 4; pub const MULTIBOOT_MEMORY_ACPI_RECLAIMABLE = 3; -pub const __LONG_LONG_MAX__ = c_longlong(9223372036854775807); +pub const __LONG_LONG_MAX__ = @as(c_longlong, 9223372036854775807); pub const __OPENCL_MEMORY_SCOPE_SUB_GROUP = 4; pub const MULTIBOOT_MEMORY_NVS = 4; +pub const __RDPID__ = 1; pub const MULTIBOOT_INFO_MEM_MAP = 64; -pub const __INTMAX_MAX__ = c_long(9223372036854775807); -pub const __UINT_LEAST32_FMTx__ = c"x"; +pub const __INTMAX_MAX__ = @as(c_long, 9223372036854775807); +pub const __UINT_LEAST32_FMTx__ = "x"; pub const __WCHAR_MAX__ = 2147483647; -pub const __INT64_MAX__ = c_long(9223372036854775807); +pub const __INT64_MAX__ = @as(c_long, 9223372036854775807); pub const __CLANG_ATOMIC_CHAR32_T_LOCK_FREE = 2; -pub const __INT_LEAST64_MAX__ = c_long(9223372036854775807); -pub const __UINTMAX_FMTX__ = c"lX"; +pub const __INT_LEAST64_MAX__ = @as(c_long, 9223372036854775807); +pub const __UINTMAX_FMTX__ = "lX"; pub const __OPENCL_MEMORY_SCOPE_WORK_ITEM = 0; pub const __FLT_HAS_DENORM__ = 1; pub const __DECIMAL_DIG__ = __LDBL_DECIMAL_DIG__; -pub const __INT32_FMTi__ = c"i"; +pub const __INT32_FMTi__ = "i"; pub const __DBL_HAS_INFINITY__ = 1; pub const __FINITE_MATH_ONLY__ = 0; pub const multiboot_header = struct_multiboot_header; diff --git a/src/kernel/panic.zig b/src/kernel/panic.zig index 9f3521f..58ba85d 100644 --- a/src/kernel/panic.zig +++ b/src/kernel/panic.zig @@ -77,12 +77,11 @@ const SymbolMap = struct { /// The function name associated with that program address, or null if one wasn't found. /// pub fn search(self: *const SymbolMap, addr: usize) ?[]const u8 { - if (self.symbols.count() == 0) + if (self.symbols.len == 0) return null; // Find the first element whose address is greater than addr var previous_name: ?[]const u8 = null; - var it = self.symbols.iterator(); - while (it.next()) |entry| { + for (self.symbols.toSliceConst()) |entry| { if (entry.addr > addr) return previous_name; previous_name = entry.func_name; @@ -102,10 +101,10 @@ var symbol_map: ?SymbolMap = null; /// fn logTraceAddress(addr: usize) void { const str = if (symbol_map) |syms| syms.search(addr) orelse "?????" else "(no symbols available)"; - log.logError("{x}: {}\n", addr, str); + log.logError("{x}: {}\n", .{ addr, str }); } -pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: ...) noreturn { +pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn { @setCold(true); log.logError("Kernel panic: " ++ format ++ "\n", args); if (trace) |trc| { @@ -278,8 +277,8 @@ fn parseMapEntry(start: *[*]const u8, end: *const u8) !MapEntry { /// std.fmt.ParseUnsignedError: See parseMapEntry. /// pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) !void { - log.logInfo("Init panic\n"); - defer log.logInfo("Done\n"); + log.logInfo("Init panic\n", .{}); + defer log.logInfo("Done\n", .{}); // Exit if we haven't loaded all debug modules if (mem_profile.boot_modules.len < 1) return; @@ -288,7 +287,7 @@ pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) ! for (mem_profile.boot_modules) |module| { const mod_start = mem.physToVirt(module.mod_start); const mod_end = mem.physToVirt(module.mod_end) - 1; - const mod_str_ptr = mem.physToVirt(@intToPtr([*]u8, module.cmdline)); + const mod_str_ptr = mem.physToVirt(@intToPtr([*:0]u8, module.cmdline)); if (std.mem.eql(u8, std.mem.toSlice(u8, mod_str_ptr), "kernel.map")) { kmap_start = mod_start; kmap_end = mod_end; diff --git a/src/kernel/serial.zig b/src/kernel/serial.zig index dfdfda8..bc89f1c 100644 --- a/src/kernel/serial.zig +++ b/src/kernel/serial.zig @@ -140,14 +140,14 @@ pub fn init(baud: u32, port: Port) SerialError!void { const port_int = @enumToInt(port); // Send a byte to start setting the baudrate arch.outb(port_int + LCR, lcrValue(0, false, false, 1) catch |e| { - panic(@errorReturnTrace(), "Failed to initialise serial output setup: {}", e); + panic(@errorReturnTrace(), "Failed to initialise serial output setup: {}", .{e}); }); // Send the divisor's lsb arch.outb(port_int, @truncate(u8, divisor)); // Send the divisor's msb arch.outb(port_int + 1, @truncate(u8, divisor >> 8)); // Send the properties to use - arch.outb(port_int + LCR, lcrValue(CHAR_LEN, SINGLE_STOP_BIT, PARITY_BIT, 0) catch |e| panic(@errorReturnTrace(), "Failed to setup serial properties: {}", e)); + arch.outb(port_int + LCR, lcrValue(CHAR_LEN, SINGLE_STOP_BIT, PARITY_BIT, 0) catch |e| panic(@errorReturnTrace(), "Failed to setup serial properties: {}", .{e})); // Stop initialisation arch.outb(port_int + 1, 0); @@ -212,5 +212,5 @@ fn rt_writeByte() void { /// Test writing a series of bytes /// fn rt_writeBytes() void { - writeBytes([_]u8{ '1', '2', '3', '\n' }, Port.COM1); + writeBytes(&[_]u8{ '1', '2', '3', '\n' }, Port.COM1); } diff --git a/src/kernel/tty.zig b/src/kernel/tty.zig index 65ccc71..e093b0f 100644 --- a/src/kernel/tty.zig +++ b/src/kernel/tty.zig @@ -182,8 +182,8 @@ fn displayPageNumber() void { var text_buf = [_]u8{0} ** vga.WIDTH; // Formate the page number string so can work out the right alignment. - const fmt_text = fmt.bufPrint(text_buf[0..], "Page {} of {}", page_index, TOTAL_NUM_PAGES - 1) catch |e| { - log.logError("TTY: Unable to print page number, buffer too small. Error: {}\n", e); + const fmt_text = fmt.bufPrint(text_buf[0..], "Page {} of {}", .{ page_index, TOTAL_NUM_PAGES - 1 }) catch |e| { + log.logError("TTY: Unable to print page number, buffer too small. Error: {}\n", .{e}); return; }; @@ -194,7 +194,7 @@ fn displayPageNumber() void { row = ROW_MIN - 1; writeString(fmt_text) catch |e| { - log.logError("TTY: Unable to print page number, printing out of bounds. Error: {}\n", e); + log.logError("TTY: Unable to print page number, printing out of bounds. Error: {}\n", .{e}); }; } @@ -292,7 +292,7 @@ fn scroll() void { // Move rows up pages by temp, will usually be one. // TODO: Maybe panic here as we have the check above, so if this fails, then is a big problem pagesMoveRowsUp(rows_to_move) catch |e| { - panic(@errorReturnTrace(), "Can't move {} rows up. Must be less than {}\n", rows_to_move, ROW_TOTAL); + panic(@errorReturnTrace(), "Can't move {} rows up. Must be less than {}\n", .{ rows_to_move, ROW_TOTAL }); }; // Move all rows up by rows_to_move @@ -413,7 +413,7 @@ fn printLogo() void { row = 0; writeString(logo) catch |e| { - log.logError("TTY: Error print logo. Error {}\n", e); + log.logError("TTY: Error print logo. Error {}\n", .{e}); }; } @@ -437,12 +437,12 @@ fn printCallback(ctx: void, str: []const u8) TtyError!void { /// /// Arguments: /// IN comptime format: []const u8 - The format string to print -/// IN args: ... - The arguments to be used in the formatted string +/// IN args: var - The arguments to be used in the formatted string /// -pub fn print(comptime format: []const u8, args: ...) void { +pub fn print(comptime format: []const u8, args: var) void { // Printing can't error because of the scrolling, if it does, we have a big problem fmt.format({}, TtyError, printCallback, format, args) catch |e| { - log.logError("TTY: Error printing. Error: {}\n", e); + log.logError("TTY: Error printing. Error: {}\n", .{e}); }; } @@ -456,7 +456,7 @@ pub fn pageUp() void { page_index += 1; // 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| { - log.logError("TTY: Error moving page up. Error: {}\n", e); + log.logError("TTY: Error moving page up. Error: {}\n", .{e}); }; displayPageNumber(); vga.disableCursor(); @@ -473,7 +473,7 @@ pub fn pageDown() void { page_index -= 1; // 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| { - log.logError("TTY: Error moving page down. Error: {}\n", e); + log.logError("TTY: Error moving page down. Error: {}\n", .{e}); }; displayPageNumber(); @@ -494,7 +494,7 @@ pub fn clearScreen() void { // Move all the rows up // This is within bounds, so shouldn't error pagesMoveRowsUp(ROW_TOTAL) catch |e| { - log.logError("TTY: Error moving all pages up. Error: {}\n", e); + log.logError("TTY: Error moving all pages up. Error: {}\n", .{e}); }; // Clear the screen @@ -569,7 +569,7 @@ pub fn getVideoBufferAddress() usize { /// entry, print the logo and display the 0'th page. /// pub fn init() void { - log.logInfo("Init tty\n"); + log.logInfo("Init tty\n", .{}); // Video buffer in higher half if (is_test) { @@ -615,13 +615,13 @@ pub fn init() void { // Set the top 7 rows blank setVideoBuffer(blank, START_OF_DISPLAYABLE_REGION) catch |e| { - log.logError("TTY: Error clearing the top 7 rows. Error: {}\n", e); + log.logError("TTY: Error clearing the top 7 rows. Error: {}\n", .{e}); }; row += @truncate(u8, row_offset + ROW_MIN); } else { // Clear the screen setVideoBuffer(blank, VIDEO_BUFFER_SIZE) catch |e| { - log.logError("TTY: Error clearing the screen. Error: {}\n", e); + log.logError("TTY: Error clearing the screen. Error: {}\n", .{e}); }; // Set the row to below the logo row = ROW_MIN; @@ -631,7 +631,7 @@ pub fn init() void { displayPageNumber(); updateCursor(); - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -756,7 +756,7 @@ test "updateCursor" { vga.initTest(); defer vga.freeTest(); - vga.addTestParams("updateCursor", @as(u16, 0), @as(u16, 0)); + vga.addTestParams("updateCursor", .{ @as(u16, 0), @as(u16, 0) }); // Pre testing defaultAllTesting(0, 0, 0); @@ -779,7 +779,7 @@ test "getCursor zero" { vga.initTest(); defer vga.freeTest(); - vga.addTestParams("getCursor", @as(u16, 0)); + vga.addTestParams("getCursor", .{@as(u16, 0)}); // Pre testing defaultAllTesting(0, 0, 0); @@ -802,7 +802,7 @@ test "getCursor EEF" { vga.initTest(); defer vga.freeTest(); - vga.addTestParams("getCursor", @as(u16, 0x0EEF)); + vga.addTestParams("getCursor", .{@as(u16, 0x0EEF)}); // Pre testing defaultAllTesting(0, 0, 0); @@ -2036,7 +2036,7 @@ test "init 0,0" { vga.initTest(); defer vga.freeTest(); - vga.addTestParams("getCursor", @as(u16, 0)); + vga.addTestParams("getCursor", .{@as(u16, 0)}); vga.addRepeatFunction("entryColour", vga.orig_entryColour); vga.addRepeatFunction("entry", vga.orig_entry); @@ -2075,7 +2075,7 @@ test "init not 0,0" { vga.initTest(); defer vga.freeTest(); - vga.addTestParams("getCursor", vga.WIDTH); + vga.addTestParams("getCursor", .{vga.WIDTH}); vga.addRepeatFunction("entryColour", vga.orig_entryColour); vga.addRepeatFunction("entry", vga.orig_entry); @@ -2111,19 +2111,19 @@ test "init not 0,0" { /// fn rt_initialisedGlobals() void { if (@ptrToInt(video_buffer.ptr) != @ptrToInt(&KERNEL_ADDR_OFFSET) + 0xB8000) { - panic(@errorReturnTrace(), "Video buffer not at correct virtual address, found: {}\n", @ptrToInt(video_buffer.ptr)); + panic(@errorReturnTrace(), "Video buffer not at correct virtual address, found: {}\n", .{@ptrToInt(video_buffer.ptr)}); } if (page_index != 0) { - panic(@errorReturnTrace(), "Page index not at zero, found: {}\n", page_index); + panic(@errorReturnTrace(), "Page index not at zero, found: {}\n", .{page_index}); } if (colour != vga.entryColour(vga.COLOUR_LIGHT_GREY, vga.COLOUR_BLACK)) { - panic(@errorReturnTrace(), "Colour not set up properly, found: {}\n", colour); + panic(@errorReturnTrace(), "Colour not set up properly, found: {}\n", .{colour}); } if (blank != vga.entry(0, colour)) { - panic(@errorReturnTrace(), "Blank not set up properly, found: {}\n", blank); + panic(@errorReturnTrace(), "Blank not set up properly, found: {}\n", .{blank}); } // Make sure the screen isn't all blank @@ -2136,10 +2136,10 @@ fn rt_initialisedGlobals() void { } if (all_blank) { - panic(@errorReturnTrace(), "Screen all blank, should have logo and page number\n"); + panic(@errorReturnTrace(), "Screen all blank, should have logo and page number\n", .{}); } - log.logInfo("TTY: Tested globals\n"); + log.logInfo("TTY: Tested globals\n", .{}); } /// @@ -2150,7 +2150,7 @@ fn rt_printString() void { const text = "abcdefg"; const clear_text = "\x08" ** text.len; - print(text); + print(text, .{}); // Check the video memory var counter: u32 = 0; @@ -2166,7 +2166,7 @@ fn rt_printString() void { } if (counter != text.len) { - panic(@errorReturnTrace(), "Didn't find the printed text in video memory\n"); + panic(@errorReturnTrace(), "Didn't find the printed text in video memory\n", .{}); } // Check the pages @@ -2183,13 +2183,13 @@ fn rt_printString() void { } if (counter != text.len) { - panic(@errorReturnTrace(), "Didn't find the printed text in pages\n"); + panic(@errorReturnTrace(), "Didn't find the printed text in pages\n", .{}); } // Clear the text - print(clear_text); + print(clear_text, .{}); - log.logInfo("TTY: Tested printing\n"); + log.logInfo("TTY: Tested printing\n", .{}); } /// diff --git a/src/kernel/vga.zig b/src/kernel/vga.zig index c7114f3..4c31ae8 100644 --- a/src/kernel/vga.zig +++ b/src/kernel/vga.zig @@ -286,7 +286,7 @@ pub fn setCursorShape(shape: CursorShape) void { /// Initialise the VGA text mode. This sets the cursor and underline shape. /// pub fn init() void { - log.logInfo("Init vga\n"); + log.logInfo("Init vga\n", .{}); // Set the maximum scan line to 0x0F sendPortData(REG_MAXIMUM_SCAN_LINE, CURSOR_SCANLINE_END); @@ -294,7 +294,7 @@ pub fn init() void { // Set by default the underline cursor setCursorShape(CursorShape.UNDERLINE); - log.logInfo("Done\n"); + log.logInfo("Done\n", .{}); if (build_options.rt_test) runtimeTests(); } @@ -345,7 +345,7 @@ test "updateCursor width out of bounds" { defer arch.freeTest(); // Mocking out the arch.outb calls for changing the hardware cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper }); updateCursor(x, y); } @@ -362,7 +362,7 @@ test "updateCursor height out of bounds" { defer arch.freeTest(); // Mocking out the arch.outb calls for changing the hardware cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper }); updateCursor(x, y); } @@ -379,7 +379,7 @@ test "updateCursor width and height out of bounds" { defer arch.freeTest(); // Mocking out the arch.outb calls for changing the hardware cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper }); updateCursor(x, y); } @@ -396,7 +396,7 @@ test "updateCursor width-1 and height out of bounds" { defer arch.freeTest(); // Mocking out the arch.outb calls for changing the hardware cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper }); updateCursor(x, y); } @@ -413,7 +413,7 @@ test "updateCursor width and height-1 out of bounds" { defer arch.freeTest(); // Mocking out the arch.outb calls for changing the hardware cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper }); updateCursor(x, y); } @@ -430,7 +430,7 @@ test "updateCursor in bounds" { defer arch.freeTest(); // Mocking out the arch.outb calls for changing the hardware cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW, PORT_DATA, expected_lower, PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH, PORT_DATA, expected_upper }); updateCursor(x, y); } @@ -441,10 +441,10 @@ test "getCursor 1: 10" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW); - arch.addTestParams("inb", PORT_DATA, @as(u8, 10)); - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH); - arch.addTestParams("inb", PORT_DATA, @as(u8, 0)); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW }); + arch.addTestParams("inb", .{ PORT_DATA, @as(u8, 10) }); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH }); + arch.addTestParams("inb", .{ PORT_DATA, @as(u8, 0) }); const actual = getCursor(); expectEqual(expect, actual); @@ -457,10 +457,10 @@ test "getCursor 2: 0xBEEF" { arch.initTest(); defer arch.freeTest(); - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_LOW); - arch.addTestParams("inb", PORT_DATA, @as(u8, 0xEF)); - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH); - arch.addTestParams("inb", PORT_DATA, @as(u8, 0xBE)); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_LOW }); + arch.addTestParams("inb", .{ PORT_DATA, @as(u8, 0xEF) }); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_LOCATION_HIGH }); + arch.addTestParams("inb", .{ PORT_DATA, @as(u8, 0xBE) }); const actual = getCursor(); expectEqual(expect, actual); @@ -471,10 +471,12 @@ test "enableCursor" { defer arch.freeTest(); // Need to init the cursor start and end positions, so call the init() to set this up - arch.addTestParams("outb", PORT_ADDRESS, REG_MAXIMUM_SCAN_LINE, PORT_DATA, CURSOR_SCANLINE_END, PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END, - // Mocking out the arch.outb calls for enabling the cursor: - // These are the default cursor positions from init() - PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END); + arch.addTestParams("outb", .{ + PORT_ADDRESS, REG_MAXIMUM_SCAN_LINE, PORT_DATA, CURSOR_SCANLINE_END, PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END, + // Mocking out the arch.outb calls for enabling the cursor: + // These are the default cursor positions from init() + PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END, + }); init(); enableCursor(); @@ -485,7 +487,7 @@ test "disableCursor" { defer arch.freeTest(); // Mocking out the arch.outb calls for disabling the cursor: - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_DISABLE); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_DISABLE }); disableCursor(); } @@ -496,7 +498,7 @@ test "setCursorShape UNDERLINE" { // Mocking out the arch.outb calls for setting the cursor shape to underline: // This will also check that the scan line variables were set properly as these are using in // the arch.outb call - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END }); setCursorShape(CursorShape.UNDERLINE); } @@ -508,7 +510,7 @@ test "setCursorShape BLOCK" { // Mocking out the arch.outb calls for setting the cursor shape to block: // This will also check that the scan line variables were set properly as these are using in // the arch.outb call - arch.addTestParams("outb", PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_START, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_START, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END }); setCursorShape(CursorShape.BLOCK); } @@ -520,7 +522,7 @@ test "init" { // Mocking out the arch.outb calls for setting the cursor max scan line and the shape to block: // This will also check that the scan line variables were set properly as these are using in // the arch.outb call for setting the cursor shape. - arch.addTestParams("outb", PORT_ADDRESS, REG_MAXIMUM_SCAN_LINE, PORT_DATA, CURSOR_SCANLINE_END, PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END); + arch.addTestParams("outb", .{ PORT_ADDRESS, REG_MAXIMUM_SCAN_LINE, PORT_DATA, CURSOR_SCANLINE_END, PORT_ADDRESS, REG_CURSOR_START, PORT_DATA, CURSOR_SCANLINE_MIDDLE, PORT_ADDRESS, REG_CURSOR_END, PORT_DATA, CURSOR_SCANLINE_END }); init(); } @@ -532,10 +534,10 @@ fn rt_correctMaxScanLine() void { const max_scan_line = getPortData(REG_MAXIMUM_SCAN_LINE); if (max_scan_line != CURSOR_SCANLINE_END) { - panic(@errorReturnTrace(), "Max scan line not {}, found {}\n", CURSOR_SCANLINE_END, max_scan_line); + panic(@errorReturnTrace(), "Max scan line not {}, found {}\n", .{ CURSOR_SCANLINE_END, max_scan_line }); } - log.logInfo("VGA: Tested max scan line\n"); + log.logInfo("VGA: Tested max scan line\n", .{}); } /// @@ -544,17 +546,17 @@ fn rt_correctMaxScanLine() void { fn rt_correctCursorShape() void { // Check the global variables are correct if (cursor_scanline_start != CURSOR_SCANLINE_MIDDLE or cursor_scanline_end != CURSOR_SCANLINE_END) { - panic(@errorReturnTrace(), "Global cursor scanline incorrect. Start: {}, end: {}\n", cursor_scanline_start, cursor_scanline_end); + panic(@errorReturnTrace(), "Global cursor scanline incorrect. Start: {}, end: {}\n", .{ cursor_scanline_start, cursor_scanline_end }); } const cursor_start = getPortData(REG_CURSOR_START); const cursor_end = getPortData(REG_CURSOR_END); if (cursor_start != CURSOR_SCANLINE_MIDDLE or cursor_end != CURSOR_SCANLINE_END) { - panic(@errorReturnTrace(), "Cursor scanline are incorrect. Start: {}, end: {}\n", cursor_start, cursor_end); + panic(@errorReturnTrace(), "Cursor scanline are incorrect. Start: {}, end: {}\n", .{ cursor_start, cursor_end }); } - log.logInfo("VGA: Tested cursor shape\n"); + log.logInfo("VGA: Tested cursor shape\n", .{}); } /// @@ -580,13 +582,13 @@ fn rt_setCursorGetCursor() void { const actual_y_loc = @truncate(u8, actual_linear_loc / WIDTH); if (x != actual_x_loc or y != actual_y_loc) { - panic(@errorReturnTrace(), "VGA cursor not the same: a_x: {}, a_y: {}, e_x: {}, e_y: {}\n", x, y, actual_x_loc, actual_y_loc); + panic(@errorReturnTrace(), "VGA cursor not the same: a_x: {}, a_y: {}, e_x: {}, e_y: {}\n", .{ x, y, actual_x_loc, actual_y_loc }); } // Restore the previous x and y updateCursor(prev_x_loc, prev_y_loc); - log.logInfo("VGA: Tested updating cursor\n"); + log.logInfo("VGA: Tested updating cursor\n", .{}); } /// diff --git a/test/mock/kernel/arch_mock.zig b/test/mock/kernel/arch_mock.zig index 61c3a1a..1d043e8 100644 --- a/test/mock/kernel/arch_mock.zig +++ b/test/mock/kernel/arch_mock.zig @@ -36,47 +36,47 @@ pub const InterruptContext = struct { }; pub fn outb(port: u16, data: u8) void { - return mock_framework.performAction("outb", void, port, data); + return mock_framework.performAction("outb", void, .{ port, data }); } pub fn inb(port: u16) u8 { - return mock_framework.performAction("inb", u8, port); + return mock_framework.performAction("inb", u8, .{port}); } pub fn ioWait() void { - return mock_framework.performAction("ioWait", void); + return mock_framework.performAction("ioWait", void, .{}); } pub fn lgdt(gdt_ptr: *const gdt.GdtPtr) void { - return mock_framework.performAction("lgdt", void, gdt_ptr); + return mock_framework.performAction("lgdt", void, .{gdt_ptr}); } pub fn sgdt() gdt.GdtPtr { - return mock_framework.performAction("sgdt", gdt.GdtPtr); + return mock_framework.performAction("sgdt", gdt.GdtPtr, .{}); } pub fn ltr(offset: u16) void { - return mock_framework.performAction("ltr", void, offset); + return mock_framework.performAction("ltr", void, .{offset}); } pub fn lidt(idt_ptr: *const idt.IdtPtr) void { - return mock_framework.performAction("lidt", void, idt_ptr); + return mock_framework.performAction("lidt", void, .{idt_ptr}); } pub fn sidt() idt.IdtPtr { - return mock_framework.performAction("sidt", idt.IdtPtr); + return mock_framework.performAction("sidt", idt.IdtPtr, .{}); } pub fn enableInterrupts() void { - return mock_framework.performAction("enableInterrupts", void); + return mock_framework.performAction("enableInterrupts", void, .{}); } pub fn disableInterrupts() void { - return mock_framework.performAction("disableInterrupts", void); + return mock_framework.performAction("disableInterrupts", void, .{}); } pub fn halt() void { - return mock_framework.performAction("halt", void); + return mock_framework.performAction("halt", void, .{}); } pub fn spinWait() noreturn { diff --git a/test/mock/kernel/idt_mock.zig b/test/mock/kernel/idt_mock.zig index 41f44e1..ee5e297 100644 --- a/test/mock/kernel/idt_mock.zig +++ b/test/mock/kernel/idt_mock.zig @@ -39,7 +39,7 @@ const NUMBER_OF_ENTRIES: u16 = 256; const TABLE_SIZE: u16 = @sizeOf(IdtEntry) * NUMBER_OF_ENTRIES - 1; pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void { - return mock_framework.performAction("openInterruptGate", IdtError!void, index, handler); + return mock_framework.performAction("openInterruptGate", IdtError!void, .{ index, handler }); } pub fn init() void { diff --git a/test/mock/kernel/log_mock.zig b/test/mock/kernel/log_mock.zig index a6c54a3..09ce7de 100644 --- a/test/mock/kernel/log_mock.zig +++ b/test/mock/kernel/log_mock.zig @@ -12,22 +12,22 @@ pub const Level = enum { ERROR, }; -pub fn log(comptime level: Level, comptime format: []const u8, args: ...) void { +pub fn log(comptime level: Level, comptime format: []const u8, args: var) void { //return mock_framework.performAction("log", void, level, format, args); } -pub fn logInfo(comptime format: []const u8, args: ...) void { +pub fn logInfo(comptime format: []const u8, args: var) void { //return mock_framework.performAction("logInfo", void, format, args); } -pub fn logDebug(comptime format: []const u8, args: ...) void { +pub fn logDebug(comptime format: []const u8, args: var) void { //return mock_framework.performAction("logDebug", void, format, args); } -pub fn logWarning(comptime format: []const u8, args: ...) void { +pub fn logWarning(comptime format: []const u8, args: var) void { //return mock_framework.performAction("logWarning", void, format, args); } -pub fn logError(comptime format: []const u8, args: ...) void { +pub fn logError(comptime format: []const u8, args: var) void { //return mock_framework.performAction("logError", void, format, args); } diff --git a/test/mock/kernel/mem_mock.zig b/test/mock/kernel/mem_mock.zig index 78e6c40..62abeff 100644 --- a/test/mock/kernel/mem_mock.zig +++ b/test/mock/kernel/mem_mock.zig @@ -6,7 +6,7 @@ pub const MemProfile = struct { physaddr_end: [*]u8, physaddr_start: [*]u8, mem_kb: u32, - fixed_alloc_size: u32 + fixed_alloc_size: u32, }; // The virtual/physical start/end of the kernel code @@ -27,6 +27,6 @@ pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile { .physaddr_start = @ptrCast([*]u8, &KERNEL_PHYSADDR_START), // Total memory available including the initial 1MiB that grub doesn't include .mem_kb = mb_info.mem_upper + mb_info.mem_lower + 1024, - .fixed_alloc_size = FIXED_ALLOC_SIZE + .fixed_alloc_size = FIXED_ALLOC_SIZE, }; } diff --git a/test/mock/kernel/mock_framework.zig b/test/mock/kernel/mock_framework.zig index df6c3c4..480a46c 100644 --- a/test/mock/kernel/mock_framework.zig +++ b/test/mock/kernel/mock_framework.zig @@ -145,7 +145,7 @@ fn Mock() type { /// A DataElement with the data wrapped. /// fn createDataElement(arg: var) DataElement { - return switch (@typeOf(arg)) { + return switch (@TypeOf(arg)) { bool => DataElement{ .BOOL = arg }, u4 => DataElement{ .U4 = arg }, u8 => DataElement{ .U8 = arg }, @@ -171,7 +171,7 @@ fn Mock() type { fn (*const idt.IdtPtr) void => DataElement{ .FN_IPTRCONSTIDTPTR_OVOID = arg }, fn (u8, extern fn () void) idt.IdtError!void => DataElement{ .FN_IU8_IEFNOVOID_OERRORIDTERRORVOID = arg }, fn (u8, nakedcc fn () void) idt.IdtError!void => DataElement{ .FN_IU8_INFNOVOID_OERRORIDTERRORVOID = arg }, - else => @compileError("Type not supported: " ++ @typeName(@typeOf(arg))), + else => @compileError("Type not supported: " ++ @typeName(@TypeOf(arg))), }; } @@ -266,11 +266,11 @@ fn Mock() type { /// Return: type /// A function type that represents the return type and its arguments. /// - fn getFunctionType(comptime RetType: type, params: ...) type { + fn getFunctionType(comptime RetType: type, params: var) type { return switch (params.len) { 0 => fn () RetType, - 1 => fn (@typeOf(params[0])) RetType, - 2 => fn (@typeOf(params[0]), @typeOf(params[1])) RetType, + 1 => fn (@TypeOf(params[0])) RetType, + 2 => fn (@TypeOf(params[0]), @TypeOf(params[1])) RetType, else => @compileError("Couldn't generate function type for " ++ params.len ++ "parameters\n"), }; } @@ -288,7 +288,7 @@ fn Mock() type { fn expectTest(comptime ExpectedType: type, expected_value: ExpectedType, elem: DataElement) void { if (ExpectedType == void) { // Can't test void as it has no value - std.debug.panic("Can not test a value for void\n"); + std.debug.panic("Can not test a value for void\n", .{}); } // Test that the types match @@ -330,7 +330,7 @@ fn Mock() type { return ret; } else { - std.debug.panic("No more test values for the return of function: " ++ fun_name ++ "\n"); + std.debug.panic("No more test values for the return of function: " ++ fun_name ++ "\n", .{}); } } @@ -365,7 +365,7 @@ fn Mock() type { } else { // Shouldn't get here as we would have just added a new mapping // But just in case ;) - std.debug.panic("No function name: " ++ fun_name ++ "\n"); + std.debug.panic("No function name: " ++ fun_name ++ "\n", .{}); } } @@ -382,7 +382,7 @@ fn Mock() type { /// Return: RetType /// The return value of the mocked function. This can be void. /// - pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: ...) RetType { + pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: var) RetType { if (self.named_actions.get(fun_name)) |kv_actions_list| { var action_list = kv_actions_list.value; // Peak the first action to test the action type @@ -397,7 +397,7 @@ fn Mock() type { const test_node = action_list.popFirst().?; const test_action = test_node.data; const param = params[i]; - const param_type = @typeOf(params[i]); + const param_type = @TypeOf(params[i]); expectTest(param_type, param, test_action.data); @@ -420,8 +420,8 @@ fn Mock() type { // to be resolved const expected_function = switch (params.len) { 0 => fn () RetType, - 1 => fn (@typeOf(params[0])) RetType, - 2 => fn (@typeOf(params[0]), @typeOf(params[1])) RetType, + 1 => fn (@TypeOf(params[0])) RetType, + 2 => fn (@TypeOf(params[0]), @TypeOf(params[1])) RetType, else => @compileError("Couldn't generate function type for " ++ params.len ++ "parameters\n"), }; @@ -438,10 +438,10 @@ fn Mock() type { action_list.destroyNode(test_node, GlobalAllocator); // The data element will contain the function to call - const r = switch (params.len) { - 0 => @noInlineCall(actual_function), - 1 => @noInlineCall(actual_function, params[0]), - 2 => @noInlineCall(actual_function, params[0], params[1]), + var r = switch (params.len) { + 0 => actual_function(), + 1 => actual_function(params[0]), + 2 => actual_function(params[0], params[1]), else => @compileError(params.len ++ " or more parameters not supported"), }; @@ -453,8 +453,8 @@ fn Mock() type { const test_element = action.data; const expected_function = switch (params.len) { 0 => fn () RetType, - 1 => fn (@typeOf(params[0])) RetType, - 2 => fn (@typeOf(params[0]), @typeOf(params[1])) RetType, + 1 => fn (@TypeOf(params[0])) RetType, + 2 => fn (@TypeOf(params[0]), @TypeOf(params[1])) RetType, else => @compileError("Couldn't generate function type for " ++ params.len ++ "parameters\n"), }; @@ -469,9 +469,9 @@ fn Mock() type { // The data element will contain the function to call const r = switch (params.len) { - 0 => @noInlineCall(actual_function), - 1 => @noInlineCall(actual_function, params[0]), - 2 => @noInlineCall(actual_function, params[0], params[1]), + 0 => actual_function(), + 1 => actual_function(params[0]), + 2 => actual_function(params[0], params[1]), else => @compileError(params.len ++ " or more parameters not supported"), }; @@ -483,10 +483,10 @@ fn Mock() type { kv_actions_list.value = action_list; return ret; } else { - std.debug.panic("No action list elements for function: " ++ fun_name ++ "\n"); + std.debug.panic("No action list elements for function: " ++ fun_name ++ "\n", .{}); } } else { - std.debug.panic("No function name: " ++ fun_name ++ "\n"); + std.debug.panic("No function name: " ++ fun_name ++ "\n", .{}); } } @@ -520,7 +520,7 @@ fn Mock() type { switch (action.action) { ActionType.TestValue, ActionType.ConsumeFunctionCall => { // These need to be all consumed - std.debug.panic("Unused testing value: Type: {}, value: {} for function '{}'\n", action.action, @as(DataElementType, action.data), next.key); + std.debug.panic("Unused testing value: Type: {}, value: {} for function '{}'\n", .{ action.action, @as(DataElementType, action.data), next.key }); }, ActionType.RepeatFunctionCall => { // As this is a repeat action, the function will still be here @@ -553,7 +553,7 @@ fn getMockObject() *Mock() { if (mock) |*m| { return m; } else { - warn("MOCK object doesn't exists, please initiate this test\n"); + warn("MOCK object doesn't exists, please initiate this test\n", .{}); expect(false); unreachable; } @@ -565,7 +565,7 @@ fn getMockObject() *Mock() { pub fn initTest() void { // Make sure there isn't a mock object if (mock) |_| { - warn("MOCK object already exists, please free previous test\n"); + warn("MOCK object already exists, please free previous test\n", .{}); expect(false); unreachable; } else { @@ -596,7 +596,7 @@ pub fn freeTest() void { /// IN fun_name: []const u8 - The function name to add the test parameters to. /// IN params: arglist - The parameters to add. /// -pub fn addTestParams(comptime fun_name: []const u8, params: ...) void { +pub fn addTestParams(comptime fun_name: []const u8, params: var) void { var mock_obj = getMockObject(); comptime var i = 0; inline while (i < params.len) : (i += 1) { @@ -639,6 +639,6 @@ pub fn addRepeatFunction(comptime fun_name: []const u8, function: var) void { /// Return: RetType /// The return value of the mocked function. This can be void. /// -pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: ...) RetType { +pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: var) RetType { return getMockObject().performAction(fun_name, RetType, params); } diff --git a/test/mock/kernel/panic_mock.zig b/test/mock/kernel/panic_mock.zig index 7aab78c..632ec1f 100644 --- a/test/mock/kernel/panic_mock.zig +++ b/test/mock/kernel/panic_mock.zig @@ -2,7 +2,7 @@ const builtin = @import("builtin"); const std = @import("std"); const MemProfile = @import("mem_mock.zig").MemProfile; -pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: ...) noreturn { +pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn { @setCold(true); std.debug.panic(format, args); } diff --git a/test/mock/kernel/pic_mock.zig b/test/mock/kernel/pic_mock.zig index fee1341..9e45f55 100644 --- a/test/mock/kernel/pic_mock.zig +++ b/test/mock/kernel/pic_mock.zig @@ -72,19 +72,19 @@ pub const IRQ_FLOATING_POINT_UNIT: u8 = 0x0D; pub const IRQ_HARD_DISK_CONTROLLER: u8 = 0x0E; pub fn sendEndOfInterrupt(irq_num: u8) void { - return mock_framework.performAction("sendEndOfInterrupt", void, irq_num); + return mock_framework.performAction("sendEndOfInterrupt", void, .{irq_num}); } pub fn spuriousIrq(irq_num: u8) bool { - return mock_framework.performAction("spuriousIrq", bool, irq_num); + return mock_framework.performAction("spuriousIrq", bool, .{irq_num}); } pub fn setMask(irq_num: u16) void { - return mock_framework.performAction("setMask", void, irq_num); + return mock_framework.performAction("setMask", void, .{irq_num}); } pub fn clearMask(irq_num: u16) void { - return mock_framework.performAction("clearMask", void, irq_num); + return mock_framework.performAction("clearMask", void, .{irq_num}); } pub fn remapIrq() void { diff --git a/test/mock/kernel/vga_mock.zig b/test/mock/kernel/vga_mock.zig index e57e902..dcb3db4 100644 --- a/test/mock/kernel/vga_mock.zig +++ b/test/mock/kernel/vga_mock.zig @@ -36,35 +36,35 @@ pub const CursorShape = enum { }; pub fn entryColour(fg: u4, bg: u4) u8 { - return mock_framework.performAction("entryColour", u8, fg, bg); + return mock_framework.performAction("entryColour", u8, .{ fg, bg }); } pub fn entry(uc: u8, colour: u8) u16 { - return mock_framework.performAction("entry", u16, uc, colour); + return mock_framework.performAction("entry", u16, .{ uc, colour }); } pub fn updateCursor(x: u16, y: u16) void { - return mock_framework.performAction("updateCursor", void, x, y); + return mock_framework.performAction("updateCursor", void, .{ x, y }); } pub fn getCursor() u16 { - return mock_framework.performAction("getCursor", u16); + return mock_framework.performAction("getCursor", u16, .{}); } pub fn enableCursor() void { - return mock_framework.performAction("enableCursor", void); + return mock_framework.performAction("enableCursor", void, .{}); } pub fn disableCursor() void { - return mock_framework.performAction("disableCursor", void); + return mock_framework.performAction("disableCursor", void, .{}); } pub fn setCursorShape(shape: CursorShape) void { - return mock_framework.performAction("setCursorShape", void, shape); + return mock_framework.performAction("setCursorShape", void, .{shape}); } pub fn init() void { - return mock_framework.performAction("init", void); + return mock_framework.performAction("init", void, .{}); } // User defined mocked functions