Update code to work with zig master

This commit is contained in:
Sam Tebbs 2020-01-01 19:12:36 +00:00
parent 4b870d3a65
commit 91b2a61acf
26 changed files with 476 additions and 438 deletions

View file

@ -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", .{});
}

View file

@ -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", .{});
}
///

View file

@ -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", .{});
}
///

View file

@ -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", .{});
}
///

View file

@ -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 {

View file

@ -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", .{});
}
///

View file

@ -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", .{});
}
///

View file

@ -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", .{});
}