Merge pull request #203 from SamTebbs33/feature/move-to-std.log
Move to std.log
This commit is contained in:
commit
fde6894bf2
23 changed files with 119 additions and 193 deletions
|
@ -17,7 +17,6 @@ const vga = @import("vga.zig");
|
||||||
const mem = @import("../../mem.zig");
|
const mem = @import("../../mem.zig");
|
||||||
const multiboot = @import("multiboot.zig");
|
const multiboot = @import("multiboot.zig");
|
||||||
const vmm = @import("../../vmm.zig");
|
const vmm = @import("../../vmm.zig");
|
||||||
const log = @import("../../log.zig");
|
|
||||||
const Serial = @import("../../serial.zig").Serial;
|
const Serial = @import("../../serial.zig").Serial;
|
||||||
const panic = @import("../../panic.zig").panic;
|
const panic = @import("../../panic.zig").panic;
|
||||||
const TTY = @import("../../tty.zig").TTY;
|
const TTY = @import("../../tty.zig").TTY;
|
||||||
|
@ -325,16 +324,16 @@ pub fn initTTY(boot_payload: BootPayload) TTY {
|
||||||
/// Allocator.Error.OutOfMemory - There wasn't enough memory in the allocated created to populate the memory profile, consider increasing mem.FIXED_ALLOC_SIZE
|
/// Allocator.Error.OutOfMemory - There wasn't enough memory in the allocated created to populate the memory profile, consider increasing mem.FIXED_ALLOC_SIZE
|
||||||
///
|
///
|
||||||
pub fn initMem(mb_info: BootPayload) Allocator.Error!MemProfile {
|
pub fn initMem(mb_info: BootPayload) Allocator.Error!MemProfile {
|
||||||
log.logInfo("Init mem\n", .{});
|
std.log.info(.arch_x86, "Init\n", .{});
|
||||||
defer log.logInfo("Done mem\n", .{});
|
defer std.log.info(.arch_x86, "Done\n", .{});
|
||||||
|
|
||||||
log.logDebug("KERNEL_ADDR_OFFSET: 0x{X}\n", .{@ptrToInt(&KERNEL_ADDR_OFFSET)});
|
std.log.debug(.arch_x86, "KERNEL_ADDR_OFFSET: 0x{X}\n", .{@ptrToInt(&KERNEL_ADDR_OFFSET)});
|
||||||
log.logDebug("KERNEL_STACK_START: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_START)});
|
std.log.debug(.arch_x86, "KERNEL_STACK_START: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_START)});
|
||||||
log.logDebug("KERNEL_STACK_END: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_END)});
|
std.log.debug(.arch_x86, "KERNEL_STACK_END: 0x{X}\n", .{@ptrToInt(&KERNEL_STACK_END)});
|
||||||
log.logDebug("KERNEL_VADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_START)});
|
std.log.debug(.arch_x86, "KERNEL_VADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_START)});
|
||||||
log.logDebug("KERNEL_VADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_END)});
|
std.log.debug(.arch_x86, "KERNEL_VADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_VADDR_END)});
|
||||||
log.logDebug("KERNEL_PHYSADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_START)});
|
std.log.debug(.arch_x86, "KERNEL_PHYSADDR_START: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_START)});
|
||||||
log.logDebug("KERNEL_PHYSADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_END)});
|
std.log.debug(.arch_x86, "KERNEL_PHYSADDR_END: 0x{X}\n", .{@ptrToInt(&KERNEL_PHYSADDR_END)});
|
||||||
|
|
||||||
const mods_count = mb_info.mods_count;
|
const mods_count = mb_info.mods_count;
|
||||||
mem.ADDR_OFFSET = @ptrToInt(&KERNEL_ADDR_OFFSET);
|
mem.ADDR_OFFSET = @ptrToInt(&KERNEL_ADDR_OFFSET);
|
||||||
|
|
|
@ -7,7 +7,6 @@ const panic = @import("../../panic.zig").panic;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.arch_mock_path;
|
const mock_path = build_options.arch_mock_path;
|
||||||
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
|
|
||||||
/// The access bits for a GDT entry.
|
/// The access bits for a GDT entry.
|
||||||
const AccessBits = packed struct {
|
const AccessBits = packed struct {
|
||||||
|
@ -406,8 +405,8 @@ fn makeGdtEntry(base: u32, limit: u20, access: AccessBits, flags: FlagBits) GdtE
|
||||||
/// Initialise the Global Descriptor table.
|
/// Initialise the Global Descriptor table.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init gdt\n", .{});
|
std.log.info(.gdt, "Init\n", .{});
|
||||||
defer log.logInfo("Done gdt\n", .{});
|
defer std.log.info(.gdt, "Done\n", .{});
|
||||||
// Initiate TSS
|
// Initiate TSS
|
||||||
gdt_entries[TSS_INDEX] = makeGdtEntry(@ptrToInt(&main_tss_entry), @sizeOf(Tss) - 1, TSS_SEGMENT, NULL_FLAGS);
|
gdt_entries[TSS_INDEX] = makeGdtEntry(@ptrToInt(&main_tss_entry), @sizeOf(Tss) - 1, TSS_SEGMENT, NULL_FLAGS);
|
||||||
|
|
||||||
|
@ -568,7 +567,7 @@ fn rt_loadedGDTSuccess() void {
|
||||||
if (gdt_ptr.base != loaded_gdt.base) {
|
if (gdt_ptr.base != loaded_gdt.base) {
|
||||||
panic(@errorReturnTrace(), "FAILURE: GDT not loaded properly: 0x{X} != {X}\n", .{ gdt_ptr.base, loaded_gdt.base });
|
panic(@errorReturnTrace(), "FAILURE: GDT not loaded properly: 0x{X} != {X}\n", .{ gdt_ptr.base, loaded_gdt.base });
|
||||||
}
|
}
|
||||||
log.logInfo("GDT: Tested loading GDT\n", .{});
|
std.log.info(.gdt, "Tested loading GDT\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -9,7 +9,6 @@ const build_options = @import("build_options");
|
||||||
const mock_path = build_options.arch_mock_path;
|
const mock_path = build_options.arch_mock_path;
|
||||||
const gdt = if (is_test) @import(mock_path ++ "gdt_mock.zig") else @import("gdt.zig");
|
const gdt = if (is_test) @import(mock_path ++ "gdt_mock.zig") else @import("gdt.zig");
|
||||||
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
|
|
||||||
/// The structure that contains all the information that each IDT entry needs.
|
/// The structure that contains all the information that each IDT entry needs.
|
||||||
pub const IdtEntry = packed struct {
|
pub const IdtEntry = packed struct {
|
||||||
|
@ -179,8 +178,8 @@ pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void {
|
||||||
/// Initialise the Interrupt descriptor table
|
/// Initialise the Interrupt descriptor table
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init idt\n", .{});
|
std.log.info(.idt, "Init\n", .{});
|
||||||
defer log.logInfo("Done idt\n", .{});
|
defer std.log.info(.idt, "Done\n", .{});
|
||||||
|
|
||||||
idt_ptr.base = @ptrToInt(&idt_entries);
|
idt_ptr.base = @ptrToInt(&idt_entries);
|
||||||
|
|
||||||
|
@ -334,7 +333,7 @@ fn rt_loadedIDTSuccess() void {
|
||||||
if (idt_ptr.base != loaded_idt.base) {
|
if (idt_ptr.base != loaded_idt.base) {
|
||||||
panic(@errorReturnTrace(), "FAILURE: IDT not loaded properly: 0x{X} != {X}\n", .{ idt_ptr.base, loaded_idt.base });
|
panic(@errorReturnTrace(), "FAILURE: IDT not loaded properly: 0x{X} != {X}\n", .{ idt_ptr.base, loaded_idt.base });
|
||||||
}
|
}
|
||||||
log.logInfo("IDT: Tested loading IDT\n", .{});
|
std.log.info(.idt, " Tested loading IDT\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -9,7 +9,6 @@ const panic = @import("../../panic.zig").panic;
|
||||||
const mock_path = build_options.arch_mock_path;
|
const mock_path = build_options.arch_mock_path;
|
||||||
const idt = if (is_test) @import(mock_path ++ "idt_mock.zig") else @import("idt.zig");
|
const idt = if (is_test) @import(mock_path ++ "idt_mock.zig") else @import("idt.zig");
|
||||||
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
const pic = if (is_test) @import(mock_path ++ "pic_mock.zig") else @import("pic.zig");
|
const pic = if (is_test) @import(mock_path ++ "pic_mock.zig") else @import("pic.zig");
|
||||||
const interrupts = @import("interrupts.zig");
|
const interrupts = @import("interrupts.zig");
|
||||||
|
|
||||||
|
@ -131,8 +130,8 @@ pub fn registerIrq(irq_num: u8, handler: IrqHandler) IrqError!void {
|
||||||
/// the IDT interrupt gates for each IRQ.
|
/// the IDT interrupt gates for each IRQ.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init irq\n", .{});
|
std.log.info(.irq, "Init\n", .{});
|
||||||
defer log.logInfo("Done irq\n", .{});
|
defer std.log.info(.irq, "Done\n", .{});
|
||||||
|
|
||||||
comptime var i = IRQ_OFFSET;
|
comptime var i = IRQ_OFFSET;
|
||||||
inline while (i < IRQ_OFFSET + 16) : (i += 1) {
|
inline while (i < IRQ_OFFSET + 16) : (i += 1) {
|
||||||
|
@ -247,7 +246,7 @@ fn rt_unregisteredHandlers() void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("IRQ: Tested registered handlers\n", .{});
|
std.log.info(.irq, "Tested registered handlers\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -265,7 +264,7 @@ fn rt_openedIdtEntries() void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("IRQ: Tested opened IDT entries\n", .{});
|
std.log.info(.irq, "Tested opened IDT entries\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -10,7 +10,6 @@ const syscalls = @import("syscalls.zig");
|
||||||
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
||||||
const idt = if (is_test) @import(mock_path ++ "idt_mock.zig") else @import("idt.zig");
|
const idt = if (is_test) @import(mock_path ++ "idt_mock.zig") else @import("idt.zig");
|
||||||
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
const interrupts = @import("interrupts.zig");
|
const interrupts = @import("interrupts.zig");
|
||||||
|
|
||||||
/// The error set for the ISR. This will be from installing a ISR handler.
|
/// The error set for the ISR. This will be from installing a ISR handler.
|
||||||
|
@ -159,7 +158,7 @@ export fn isrHandler(ctx: *arch.CpuState) usize {
|
||||||
// Regular ISR exception, if there is one registered.
|
// Regular ISR exception, if there is one registered.
|
||||||
ret_esp = handler(ctx);
|
ret_esp = handler(ctx);
|
||||||
} else {
|
} else {
|
||||||
log.logInfo("State: {X}\n", .{ctx});
|
std.log.info(.isr, "State: {X}\n", .{ctx});
|
||||||
panic(@errorReturnTrace(), "ISR {} ({}) triggered with error code 0x{X} but not registered\n", .{ exception_msg[isr_num], isr_num, ctx.error_code });
|
panic(@errorReturnTrace(), "ISR {} ({}) triggered with error code 0x{X} but not registered\n", .{ exception_msg[isr_num], isr_num, ctx.error_code });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,8 +237,8 @@ pub fn registerIsr(isr_num: u16, handler: IsrHandler) IsrError!void {
|
||||||
/// Initialise the exception and opening up all the IDT interrupt gates for each exception.
|
/// Initialise the exception and opening up all the IDT interrupt gates for each exception.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init isr\n", .{});
|
std.log.info(.isr, "Init\n", .{});
|
||||||
defer log.logInfo("Done isr\n", .{});
|
defer std.log.info(.isr, "Done\n", .{});
|
||||||
|
|
||||||
comptime var i = 0;
|
comptime var i = 0;
|
||||||
inline while (i < 32) : (i += 1) {
|
inline while (i < 32) : (i += 1) {
|
||||||
|
@ -385,7 +384,7 @@ fn rt_unregisteredHandlers() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Pre-testing failed for syscall: {}\n", .{h});
|
panic(@errorReturnTrace(), "FAILURE: Pre-testing failed for syscall: {}\n", .{h});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("ISR: Tested registered handlers\n", .{});
|
std.log.info(.isr, "Tested registered handlers\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -403,7 +402,7 @@ fn rt_openedIdtEntries() void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("ISR: Tested opened IDT entries\n", .{});
|
std.log.info(.isr, "Tested opened IDT entries\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,7 +11,6 @@ const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("ar
|
||||||
const isr = @import("isr.zig");
|
const isr = @import("isr.zig");
|
||||||
const MemProfile = @import("../../mem.zig").MemProfile;
|
const MemProfile = @import("../../mem.zig").MemProfile;
|
||||||
const tty = @import("../../tty.zig");
|
const tty = @import("../../tty.zig");
|
||||||
const log = @import("../../log.zig");
|
|
||||||
const mem = @import("../../mem.zig");
|
const mem = @import("../../mem.zig");
|
||||||
const vmm = @import("../../vmm.zig");
|
const vmm = @import("../../vmm.zig");
|
||||||
const multiboot = @import("multiboot.zig");
|
const multiboot = @import("multiboot.zig");
|
||||||
|
@ -366,7 +365,7 @@ pub fn unmap(virtual_start: usize, virtual_end: usize, dir: *Directory) (std.mem
|
||||||
/// IN state: *arch.CpuState - The CPU's state when the fault occurred.
|
/// IN state: *arch.CpuState - The CPU's state when the fault occurred.
|
||||||
///
|
///
|
||||||
fn pageFault(state: *arch.CpuState) u32 {
|
fn pageFault(state: *arch.CpuState) u32 {
|
||||||
log.logInfo("State: {X}\n", .{state});
|
std.log.info(.paging, "State: {X}\n", .{state});
|
||||||
var cr0 = asm volatile ("mov %%cr0, %[cr0]"
|
var cr0 = asm volatile ("mov %%cr0, %[cr0]"
|
||||||
: [cr0] "=r" (-> u32)
|
: [cr0] "=r" (-> u32)
|
||||||
);
|
);
|
||||||
|
@ -379,7 +378,7 @@ fn pageFault(state: *arch.CpuState) u32 {
|
||||||
var cr4 = asm volatile ("mov %%cr4, %[cr4]"
|
var cr4 = asm volatile ("mov %%cr4, %[cr4]"
|
||||||
: [cr4] "=r" (-> u32)
|
: [cr4] "=r" (-> u32)
|
||||||
);
|
);
|
||||||
log.logInfo("CR0: 0x{X}, CR2: 0x{X}, CR3: 0x{X}, CR4: 0x{X}\n", .{ cr0, cr2, cr3, cr4 });
|
std.log.info(.paging, "CR0: 0x{X}, CR2: 0x{X}, CR3: 0x{X}, CR4: 0x{X}\n", .{ cr0, cr2, cr3, cr4 });
|
||||||
@panic("Page fault");
|
@panic("Page fault");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,8 +390,8 @@ fn pageFault(state: *arch.CpuState) u32 {
|
||||||
/// IN allocator: *std.mem.Allocator - The allocator to use
|
/// 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 {
|
pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile, allocator: *std.mem.Allocator) void {
|
||||||
log.logInfo("Init paging\n", .{});
|
std.log.info(.paging, "Init\n", .{});
|
||||||
defer log.logInfo("Done paging\n", .{});
|
defer std.log.info(.paging, "Done\n", .{});
|
||||||
|
|
||||||
isr.registerIsr(isr.PAGE_FAULT, if (build_options.test_mode == .Initialisation) rt_pageFault else pageFault) catch |e| {
|
isr.registerIsr(isr.PAGE_FAULT, if (build_options.test_mode == .Initialisation) rt_pageFault else pageFault) catch |e| {
|
||||||
panic(@errorReturnTrace(), "Failed to register page fault ISR: {}\n", .{e});
|
panic(@errorReturnTrace(), "Failed to register page fault ISR: {}\n", .{e});
|
||||||
|
@ -564,7 +563,7 @@ fn rt_accessUnmappedMem(v_end: u32) void {
|
||||||
var ptr = @intToPtr(*u8, v_end);
|
var ptr = @intToPtr(*u8, v_end);
|
||||||
var value = ptr.*;
|
var value = ptr.*;
|
||||||
// Need this as in release builds the above is optimised out so it needs to be use
|
// Need this as in release builds the above is optimised out so it needs to be use
|
||||||
log.logError("FAILURE: Value: {}\n", .{value});
|
std.log.emerg(.paging, "FAILURE: Value: {}\n", .{value});
|
||||||
// This is the label that we return to after processing the page fault
|
// This is the label that we return to after processing the page fault
|
||||||
asm volatile (
|
asm volatile (
|
||||||
\\.global rt_fault_callback
|
\\.global rt_fault_callback
|
||||||
|
@ -573,7 +572,7 @@ fn rt_accessUnmappedMem(v_end: u32) void {
|
||||||
if (!faulted) {
|
if (!faulted) {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Paging should have faulted\n", .{});
|
panic(@errorReturnTrace(), "FAILURE: Paging should have faulted\n", .{});
|
||||||
}
|
}
|
||||||
log.logInfo("Paging: Tested accessing unmapped memory\n", .{});
|
std.log.info(.paging, "Tested accessing unmapped memory\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rt_accessMappedMem(v_end: u32) void {
|
fn rt_accessMappedMem(v_end: u32) void {
|
||||||
|
@ -589,7 +588,7 @@ fn rt_accessMappedMem(v_end: u32) void {
|
||||||
if (faulted) {
|
if (faulted) {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Paging shouldn't have faulted\n", .{});
|
panic(@errorReturnTrace(), "FAILURE: Paging shouldn't have faulted\n", .{});
|
||||||
}
|
}
|
||||||
log.logInfo("Paging: Tested accessing mapped memory\n", .{});
|
std.log.info(.paging, "Tested accessing mapped memory\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn runtimeTests(v_end: u32) void {
|
pub fn runtimeTests(v_end: u32) void {
|
||||||
|
|
|
@ -6,7 +6,6 @@ const is_test = builtin.is_test;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.arch_mock_path;
|
const mock_path = build_options.arch_mock_path;
|
||||||
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
|
@ -432,8 +431,8 @@ pub fn clearMask(irq_num: u8) void {
|
||||||
/// by Intel up to 0x1F. So this will move the IRQs from 0x00-0x0F to 0x20-0x2F.
|
/// by Intel up to 0x1F. So this will move the IRQs from 0x00-0x0F to 0x20-0x2F.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init pic\n", .{});
|
std.log.info(.pic, "Init\n", .{});
|
||||||
defer log.logInfo("Done pic\n", .{});
|
defer std.log.info(.pic, "Done\n", .{});
|
||||||
|
|
||||||
// Initiate
|
// Initiate
|
||||||
sendCommandMaster(ICW1_INITIALISATION | ICW1_EXPECT_ICW4);
|
sendCommandMaster(ICW1_INITIALISATION | ICW1_EXPECT_ICW4);
|
||||||
|
@ -824,7 +823,7 @@ fn rt_picAllMasked() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Slave masks are not set, found: {}\n", .{readDataSlave()});
|
panic(@errorReturnTrace(), "FAILURE: Slave masks are not set, found: {}\n", .{readDataSlave()});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("PIC: Tested masking\n", .{});
|
std.log.info(.pic, "Tested masking\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,7 +11,6 @@ const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("ar
|
||||||
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
||||||
const irq = @import("irq.zig");
|
const irq = @import("irq.zig");
|
||||||
const pic = @import("pic.zig");
|
const pic = @import("pic.zig");
|
||||||
const log = @import("../../log.zig");
|
|
||||||
|
|
||||||
/// The enum for selecting the counter
|
/// The enum for selecting the counter
|
||||||
const CounterSelect = enum {
|
const CounterSelect = enum {
|
||||||
|
@ -363,8 +362,8 @@ pub fn getFrequency() u32 {
|
||||||
/// Initialise the PIT with a handler to IRQ 0.
|
/// Initialise the PIT with a handler to IRQ 0.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init pit\n", .{});
|
std.log.info(.pit, "Init\n", .{});
|
||||||
defer log.logInfo("Done pit\n", .{});
|
defer std.log.info(.pit, "Done\n", .{});
|
||||||
|
|
||||||
// Set up counter 0 at 10000hz in a square wave mode counting in binary
|
// Set up counter 0 at 10000hz in a square wave mode counting in binary
|
||||||
const freq: u32 = 10000;
|
const freq: u32 = 10000;
|
||||||
|
@ -372,7 +371,7 @@ pub fn init() void {
|
||||||
panic(@errorReturnTrace(), "Invalid frequency: {}\n", .{freq});
|
panic(@errorReturnTrace(), "Invalid frequency: {}\n", .{freq});
|
||||||
};
|
};
|
||||||
|
|
||||||
log.logDebug("Set frequency at: {}Hz, real frequency: {}Hz\n", .{ freq, getFrequency() });
|
std.log.debug(.pit, "Set frequency at: {}Hz, real frequency: {}Hz\n", .{ freq, getFrequency() });
|
||||||
|
|
||||||
// Installs 'pitHandler' to IRQ0 (pic.IRQ_PIT)
|
// Installs 'pitHandler' to IRQ0 (pic.IRQ_PIT)
|
||||||
irq.registerIrq(pic.IRQ_PIT, pitHandler) catch |err| switch (err) {
|
irq.registerIrq(pic.IRQ_PIT, pitHandler) catch |err| switch (err) {
|
||||||
|
@ -550,7 +549,7 @@ fn rt_waitTicks() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", .{ difference, previous_count, epsilon });
|
panic(@errorReturnTrace(), "FAILURE: Waiting failed. difference: {}, previous_count: {}. Epsilon: {}\n", .{ difference, previous_count, epsilon });
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("PIT: Tested wait ticks\n", .{});
|
std.log.info(.pit, "Tested wait ticks\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -577,7 +576,7 @@ fn rt_waitTicks2() void {
|
||||||
// Reset ticks
|
// Reset ticks
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
|
|
||||||
log.logInfo("PIT: Tested wait ticks 2\n", .{});
|
std.log.info(.pit, "Tested wait ticks 2\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -622,7 +621,7 @@ fn rt_initCounter_0() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Operating mode don't not set properly. Found: {}, expecting: {}\n", .{ actual_mode, expected_mode });
|
panic(@errorReturnTrace(), "FAILURE: Operating mode don't not set properly. Found: {}, expecting: {}\n", .{ actual_mode, expected_mode });
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("PIT: Tested init\n", .{});
|
std.log.info(.pit, "Tested init\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -7,7 +7,6 @@ const expectError = std.testing.expectError;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.arch_mock_path;
|
const mock_path = build_options.arch_mock_path;
|
||||||
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = @import("../../log.zig");
|
|
||||||
const pic = @import("pic.zig");
|
const pic = @import("pic.zig");
|
||||||
const pit = @import("pit.zig");
|
const pit = @import("pit.zig");
|
||||||
const irq = @import("irq.zig");
|
const irq = @import("irq.zig");
|
||||||
|
@ -266,8 +265,8 @@ fn enableInterrupts() void {
|
||||||
/// Initialise the RTC.
|
/// Initialise the RTC.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init rtc\n", .{});
|
std.log.info(.rtc, "Init\n", .{});
|
||||||
defer log.logInfo("Done rtc\n", .{});
|
defer std.log.info(.rtc, "Done\n", .{});
|
||||||
|
|
||||||
// Register the interrupt handler
|
// Register the interrupt handler
|
||||||
irq.registerIrq(pic.IRQ_REAL_TIME_CLOCK, rtcHandler) catch |err| switch (err) {
|
irq.registerIrq(pic.IRQ_REAL_TIME_CLOCK, rtcHandler) catch |err| switch (err) {
|
||||||
|
@ -727,7 +726,7 @@ fn rt_init() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Interrupts not enabled\n", .{});
|
panic(@errorReturnTrace(), "FAILURE: Interrupts not enabled\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("RTC: Tested init\n", .{});
|
std.log.info(.rtc, "Tested init\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -742,7 +741,7 @@ fn rt_interrupts() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: No interrupt happened\n", .{});
|
panic(@errorReturnTrace(), "FAILURE: No interrupt happened\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("RTC: Tested interrupts\n", .{});
|
std.log.info(.rtc, "Tested interrupts\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -7,7 +7,6 @@ const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("ar
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const expect = std.testing.expect;
|
const expect = std.testing.expect;
|
||||||
const isr = @import("isr.zig");
|
const isr = @import("isr.zig");
|
||||||
const log = @import("../../log.zig");
|
|
||||||
const panic = @import("../../panic.zig").panic;
|
const panic = @import("../../panic.zig").panic;
|
||||||
|
|
||||||
/// The isr number associated with syscalls
|
/// The isr number associated with syscalls
|
||||||
|
@ -58,10 +57,10 @@ fn handle(ctx: *arch.CpuState) u32 {
|
||||||
if (handlers[syscall]) |handler| {
|
if (handlers[syscall]) |handler| {
|
||||||
ctx.eax = handler(ctx, syscallArg(ctx, 0), syscallArg(ctx, 1), syscallArg(ctx, 2), syscallArg(ctx, 3), syscallArg(ctx, 4));
|
ctx.eax = handler(ctx, syscallArg(ctx, 0), syscallArg(ctx, 1), syscallArg(ctx, 2), syscallArg(ctx, 3), syscallArg(ctx, 4));
|
||||||
} else {
|
} else {
|
||||||
log.logWarning("Syscall {} triggered but not registered\n", .{syscall});
|
std.log.warn(.syscall, "Syscall {} triggered but not registered\n", .{syscall});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.logWarning("Syscall {} is invalid\n", .{syscall});
|
std.log.warn(.syscall, "Syscall {} is invalid\n", .{syscall});
|
||||||
}
|
}
|
||||||
return @ptrToInt(ctx);
|
return @ptrToInt(ctx);
|
||||||
}
|
}
|
||||||
|
@ -243,8 +242,8 @@ inline fn syscallArg(ctx: *arch.CpuState, comptime arg_idx: u32) u32 {
|
||||||
/// Initialise syscalls. Registers the isr associated with INTERRUPT.
|
/// Initialise syscalls. Registers the isr associated with INTERRUPT.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init syscalls\n", .{});
|
std.log.info(.syscall, "Init\n", .{});
|
||||||
defer log.logInfo("Done syscalls\n", .{});
|
defer std.log.info(.syscall, "Done\n", .{});
|
||||||
|
|
||||||
isr.registerIsr(INTERRUPT, handle) catch unreachable;
|
isr.registerIsr(INTERRUPT, handle) catch unreachable;
|
||||||
|
|
||||||
|
@ -331,5 +330,5 @@ fn runtimeTests() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE syscall5\n", .{});
|
panic(@errorReturnTrace(), "FAILURE syscall5\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("Syscall: Tested all args\n", .{});
|
std.log.info(.syscall, "Tested all args\n", .{});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ const expectError = std.testing.expectError;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.mock_path;
|
const mock_path = build_options.mock_path;
|
||||||
const vga = if (is_test) @import("../../" ++ mock_path ++ "vga_mock.zig") else @import("vga.zig");
|
const vga = if (is_test) @import("../../" ++ mock_path ++ "vga_mock.zig") else @import("vga.zig");
|
||||||
const log = if (is_test) @import("../../" ++ mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
const panic = if (is_test) @import("../../" ++ mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
const panic = if (is_test) @import("../../" ++ mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
|
||||||
|
|
||||||
/// The error set for if there is an error whiles printing.
|
/// The error set for if there is an error whiles printing.
|
||||||
|
@ -381,7 +380,7 @@ pub fn pageUp() void {
|
||||||
page_index += 1;
|
page_index += 1;
|
||||||
// Bounds have been checked, so shouldn't error
|
// Bounds have been checked, so shouldn't error
|
||||||
videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| {
|
videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| {
|
||||||
log.logError("TTY: Error moving page up. Error: {}\n", .{e});
|
std.log.crit(.tty, "Error moving page up. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
vga.disableCursor();
|
vga.disableCursor();
|
||||||
}
|
}
|
||||||
|
@ -397,7 +396,7 @@ pub fn pageDown() void {
|
||||||
page_index -= 1;
|
page_index -= 1;
|
||||||
// Bounds have been checked, so shouldn't error
|
// Bounds have been checked, so shouldn't error
|
||||||
videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| {
|
videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch |e| {
|
||||||
log.logError("TTY: Error moving page down. Error: {}\n", .{e});
|
std.log.crit(.tty, "Error moving page down. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (page_index == 0) {
|
if (page_index == 0) {
|
||||||
|
@ -417,7 +416,7 @@ pub fn clearScreen() void {
|
||||||
// Move all the rows up
|
// Move all the rows up
|
||||||
// This is within bounds, so shouldn't error
|
// This is within bounds, so shouldn't error
|
||||||
pagesMoveRowsUp(ROW_TOTAL) catch |e| {
|
pagesMoveRowsUp(ROW_TOTAL) catch |e| {
|
||||||
log.logError("TTY: Error moving all pages up. Error: {}\n", .{e});
|
std.log.crit(.tty, "Error moving all pages up. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear the screen
|
// Clear the screen
|
||||||
|
@ -536,13 +535,13 @@ pub fn init() void {
|
||||||
|
|
||||||
// Set the top 7 rows blank
|
// Set the top 7 rows blank
|
||||||
setVideoBuffer(blank, START_OF_DISPLAYABLE_REGION) catch |e| {
|
setVideoBuffer(blank, START_OF_DISPLAYABLE_REGION) catch |e| {
|
||||||
log.logError("TTY: Error clearing the top 7 rows. Error: {}\n", .{e});
|
std.log.crit(.tty, "Error clearing the top 7 rows. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
row += @truncate(u8, row_offset + ROW_MIN);
|
row += @truncate(u8, row_offset + ROW_MIN);
|
||||||
} else {
|
} else {
|
||||||
// Clear the screen
|
// Clear the screen
|
||||||
setVideoBuffer(blank, VIDEO_BUFFER_SIZE) catch |e| {
|
setVideoBuffer(blank, VIDEO_BUFFER_SIZE) catch |e| {
|
||||||
log.logError("TTY: Error clearing the screen. Error: {}\n", .{e});
|
std.log.crit(.tty, "Error clearing the screen. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
// Set the row to below the logo
|
// Set the row to below the logo
|
||||||
row = ROW_MIN;
|
row = ROW_MIN;
|
||||||
|
@ -901,7 +900,7 @@ test "putEntryAt in displayable region page_index is not 0" {
|
||||||
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
|
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
|
||||||
row = ROW_MIN - 1;
|
row = ROW_MIN - 1;
|
||||||
writeString(text) catch |e| {
|
writeString(text) catch |e| {
|
||||||
log.logError("TTY: Unable to print page number, printing out of bounds. Error: {}\n", .{e});
|
std.log.crit(.tty, "Unable to print page number, printing out of bounds. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
column = column_temp;
|
column = column_temp;
|
||||||
row = row_temp;
|
row = row_temp;
|
||||||
|
@ -1559,7 +1558,7 @@ test "pageUp bottom page" {
|
||||||
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
|
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
|
||||||
row = ROW_MIN - 1;
|
row = ROW_MIN - 1;
|
||||||
writeString(text) catch |e| {
|
writeString(text) catch |e| {
|
||||||
log.logError("TTY: Unable to print page number, printing out of bounds. Error: {}\n", .{e});
|
std.log.crit(.tty, "Unable to print page number, printing out of bounds. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
column = column_temp;
|
column = column_temp;
|
||||||
row = row_temp;
|
row = row_temp;
|
||||||
|
@ -1639,7 +1638,7 @@ test "pageDown top page" {
|
||||||
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
|
column = @truncate(u8, vga.WIDTH) - @truncate(u8, text.len);
|
||||||
row = ROW_MIN - 1;
|
row = ROW_MIN - 1;
|
||||||
writeString(text) catch |e| {
|
writeString(text) catch |e| {
|
||||||
log.logError("TTY: Unable to print page number, printing out of bounds. Error: {}\n", .{e});
|
std.log.crit(.tty, "Unable to print page number, printing out of bounds. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
column = column_temp;
|
column = column_temp;
|
||||||
row = row_temp;
|
row = row_temp;
|
||||||
|
@ -2045,7 +2044,7 @@ fn rt_initialisedGlobals() void {
|
||||||
panic(@errorReturnTrace(), "Screen all blank, should have logo and page number\n", .{});
|
panic(@errorReturnTrace(), "Screen all blank, should have logo and page number\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("TTY: Tested globals\n", .{});
|
std.log.info(.tty, "Tested globals\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -2097,7 +2096,7 @@ fn rt_printString() void {
|
||||||
// Clear the text
|
// Clear the text
|
||||||
writeString(clear_text) catch |e| panic(@errorReturnTrace(), "Failed to print string to tty: {}\n", .{e});
|
writeString(clear_text) catch |e| panic(@errorReturnTrace(), "Failed to print string to tty: {}\n", .{e});
|
||||||
|
|
||||||
log.logInfo("TTY: Tested printing\n", .{});
|
std.log.info(.tty, "Tested printing\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -4,7 +4,6 @@ const is_test = builtin.is_test;
|
||||||
const expectEqual = std.testing.expectEqual;
|
const expectEqual = std.testing.expectEqual;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const arch = if (is_test) @import(build_options.arch_mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
const arch = if (is_test) @import(build_options.arch_mock_path ++ "arch_mock.zig") else @import("arch.zig");
|
||||||
const log = if (is_test) @import(build_options.arch_mock_path ++ "log_mock.zig") else @import("../../log.zig");
|
|
||||||
const panic = @import("../../panic.zig").panic;
|
const panic = @import("../../panic.zig").panic;
|
||||||
|
|
||||||
/// The port address for the VGA register selection.
|
/// The port address for the VGA register selection.
|
||||||
|
@ -284,8 +283,8 @@ pub fn setCursorShape(shape: CursorShape) void {
|
||||||
/// Initialise the VGA text mode. This sets the cursor and underline shape.
|
/// Initialise the VGA text mode. This sets the cursor and underline shape.
|
||||||
///
|
///
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
log.logInfo("Init vga\n", .{});
|
std.log.info(.vga, "Init\n", .{});
|
||||||
defer log.logInfo("Done vga\n", .{});
|
defer std.log.info(.vga, "Done\n", .{});
|
||||||
|
|
||||||
// Set the maximum scan line to 0x0F
|
// Set the maximum scan line to 0x0F
|
||||||
sendPortData(REG_MAXIMUM_SCAN_LINE, CURSOR_SCANLINE_END);
|
sendPortData(REG_MAXIMUM_SCAN_LINE, CURSOR_SCANLINE_END);
|
||||||
|
@ -537,7 +536,7 @@ fn rt_correctMaxScanLine() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Max scan line not {}, found {}\n", .{ CURSOR_SCANLINE_END, max_scan_line });
|
panic(@errorReturnTrace(), "FAILURE: Max scan line not {}, found {}\n", .{ CURSOR_SCANLINE_END, max_scan_line });
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("VGA: Tested max scan line\n", .{});
|
std.log.info(.vga, "Tested max scan line\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -556,7 +555,7 @@ fn rt_correctCursorShape() void {
|
||||||
panic(@errorReturnTrace(), "FAILURE: Cursor scanline are incorrect. Start: {}, end: {}\n", .{ cursor_start, cursor_end });
|
panic(@errorReturnTrace(), "FAILURE: Cursor scanline are incorrect. Start: {}, end: {}\n", .{ cursor_start, cursor_end });
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("VGA: Tested cursor shape\n", .{});
|
std.log.info(.vga, "Tested cursor shape\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -588,7 +587,7 @@ fn rt_setCursorGetCursor() void {
|
||||||
// Restore the previous x and y
|
// Restore the previous x and y
|
||||||
updateCursor(prev_x_loc, prev_y_loc);
|
updateCursor(prev_x_loc, prev_y_loc);
|
||||||
|
|
||||||
log.logInfo("VGA: Tested updating cursor\n", .{});
|
std.log.info(.vga, "Tested updating cursor\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -6,7 +6,6 @@ const is_test = builtin.is_test;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.mock_path;
|
const mock_path = build_options.mock_path;
|
||||||
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
|
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("log.zig");
|
|
||||||
const panic = @import("panic.zig").panic;
|
const panic = @import("panic.zig").panic;
|
||||||
|
|
||||||
const FreeListAllocator = struct {
|
const FreeListAllocator = struct {
|
||||||
|
@ -18,7 +17,7 @@ const FreeListAllocator = struct {
|
||||||
const Self = @Self();
|
const Self = @Self();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Intitialise the header for a free allocation node
|
/// Initialise the header for a free allocation node
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN size: usize - The node's size, not including the size of the header itself
|
/// IN size: usize - The node's size, not including the size of the header itself
|
||||||
|
@ -41,7 +40,7 @@ const FreeListAllocator = struct {
|
||||||
/// Initialise an empty and free FreeListAllocator
|
/// Initialise an empty and free FreeListAllocator
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN start: usize - The starting address for all alloctions
|
/// IN start: usize - The starting address for all allocations
|
||||||
/// IN size: usize - The size of the region of memory to allocate within. Must be greater than @sizeOf(Header)
|
/// IN size: usize - The size of the region of memory to allocate within. Must be greater than @sizeOf(Header)
|
||||||
///
|
///
|
||||||
/// Return: FreeListAllocator
|
/// Return: FreeListAllocator
|
||||||
|
@ -83,7 +82,7 @@ const FreeListAllocator = struct {
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN self: *FreeListAllocator - The FreeListAllocator to modify
|
/// IN self: *FreeListAllocator - The FreeListAllocator to modify
|
||||||
/// IN previos: ?*Header - The previous free node or null if there wasn't one. If null, self.first_free will be set to header, else previous.next_free will be set to header
|
/// IN previous: ?*Header - The previous free node or null if there wasn't one. If null, self.first_free will be set to header, else previous.next_free will be set to header
|
||||||
/// IN header: ?*Header - The header being pointed to. This will be the new value of self.first_free or previous.next_free
|
/// IN header: ?*Header - The header being pointed to. This will be the new value of self.first_free or previous.next_free
|
||||||
///
|
///
|
||||||
fn registerFreeHeader(self: *FreeListAllocator, previous: ?*Header, header: ?*Header) void {
|
fn registerFreeHeader(self: *FreeListAllocator, previous: ?*Header, header: ?*Header) void {
|
||||||
|
@ -425,8 +424,6 @@ const FreeListAllocator = struct {
|
||||||
testing.expectEqual(header.next_free, null);
|
testing.expectEqual(header.next_free, null);
|
||||||
testing.expectEqual(free_list.first_free, header);
|
testing.expectEqual(free_list.first_free, header);
|
||||||
|
|
||||||
std.debug.warn("", .{});
|
|
||||||
|
|
||||||
// 64 bytes aligned to 4 bytes
|
// 64 bytes aligned to 4 bytes
|
||||||
const alloc1 = try alloc(allocator, 64, 4, 0);
|
const alloc1 = try alloc(allocator, 64, 4, 0);
|
||||||
const alloc1_addr = @ptrToInt(alloc1.ptr);
|
const alloc1_addr = @ptrToInt(alloc1.ptr);
|
||||||
|
@ -564,8 +561,8 @@ const FreeListAllocator = struct {
|
||||||
/// Allocator.Error.OutOfMemory - heap_vmm's allocator didn't have enough memory available to fulfill the request
|
/// Allocator.Error.OutOfMemory - heap_vmm's allocator didn't have enough memory available to fulfill the request
|
||||||
///
|
///
|
||||||
pub fn init(comptime vmm_payload: type, heap_vmm: *vmm.VirtualMemoryManager(vmm_payload), attributes: vmm.Attributes, heap_size: usize) (FreeListAllocator.Error || Allocator.Error)!FreeListAllocator {
|
pub fn init(comptime vmm_payload: type, heap_vmm: *vmm.VirtualMemoryManager(vmm_payload), attributes: vmm.Attributes, heap_size: usize) (FreeListAllocator.Error || Allocator.Error)!FreeListAllocator {
|
||||||
log.logInfo("Init heap\n", .{});
|
std.log.info(.heap, "Init\n", .{});
|
||||||
defer log.logInfo("Done heap\n", .{});
|
defer std.log.info(.heap, "Done\n", .{});
|
||||||
var heap_start = (try heap_vmm.alloc(heap_size / vmm.BLOCK_SIZE, attributes)) orelse panic(null, "Not enough contiguous virtual memory blocks to allocate to kernel heap\n", .{});
|
var heap_start = (try heap_vmm.alloc(heap_size / vmm.BLOCK_SIZE, attributes)) orelse panic(null, "Not enough contiguous virtual memory blocks to allocate to kernel heap\n", .{});
|
||||||
// This free call cannot error as it is guaranteed to have been allocated above
|
// This free call cannot error as it is guaranteed to have been allocated above
|
||||||
errdefer heap_vmm.free(heap_start) catch unreachable;
|
errdefer heap_vmm.free(heap_start) catch unreachable;
|
||||||
|
|
|
@ -6,7 +6,7 @@ const mock_path = build_options.mock_path;
|
||||||
const arch = @import("arch.zig").internals;
|
const arch = @import("arch.zig").internals;
|
||||||
const tty = @import("tty.zig");
|
const tty = @import("tty.zig");
|
||||||
const vga = @import("vga.zig");
|
const vga = @import("vga.zig");
|
||||||
const log = @import("log.zig");
|
const log_root = @import("log.zig");
|
||||||
const pmm = @import("pmm.zig");
|
const pmm = @import("pmm.zig");
|
||||||
const serial = @import("serial.zig");
|
const serial = @import("serial.zig");
|
||||||
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
|
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
|
||||||
|
@ -45,10 +45,21 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
|
||||||
panic_root.panic(error_return_trace, "{}", .{msg});
|
panic_root.panic(error_return_trace, "{}", .{msg});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const log_level: std.log.Level = .debug;
|
||||||
|
// Define root.log to override the std implementation
|
||||||
|
pub fn log(
|
||||||
|
comptime level: std.log.Level,
|
||||||
|
comptime scope: @TypeOf(.EnumLiteral),
|
||||||
|
comptime format: []const u8,
|
||||||
|
args: anytype,
|
||||||
|
) void {
|
||||||
|
log_root.log(level, "(" ++ @tagName(scope) ++ "): " ++ format, args);
|
||||||
|
}
|
||||||
|
|
||||||
export fn kmain(boot_payload: arch.BootPayload) void {
|
export fn kmain(boot_payload: arch.BootPayload) void {
|
||||||
const serial_stream = serial.init(boot_payload);
|
const serial_stream = serial.init(boot_payload);
|
||||||
|
|
||||||
log.init(serial_stream);
|
log_root.init(serial_stream);
|
||||||
|
|
||||||
const mem_profile = arch.initMem(boot_payload) catch |e| panic_root.panic(@errorReturnTrace(), "Failed to initialise memory profile: {}", .{e});
|
const mem_profile = arch.initMem(boot_payload) catch |e| panic_root.panic(@errorReturnTrace(), "Failed to initialise memory profile: {}", .{e});
|
||||||
var fixed_allocator = mem_profile.fixed_allocator;
|
var fixed_allocator = mem_profile.fixed_allocator;
|
||||||
|
@ -60,9 +71,9 @@ export fn kmain(boot_payload: arch.BootPayload) void {
|
||||||
pmm.init(&mem_profile, &fixed_allocator.allocator);
|
pmm.init(&mem_profile, &fixed_allocator.allocator);
|
||||||
kernel_vmm = vmm.init(&mem_profile, &fixed_allocator.allocator) catch |e| panic_root.panic(@errorReturnTrace(), "Failed to initialise kernel VMM: {}", .{e});
|
kernel_vmm = vmm.init(&mem_profile, &fixed_allocator.allocator) catch |e| panic_root.panic(@errorReturnTrace(), "Failed to initialise kernel VMM: {}", .{e});
|
||||||
|
|
||||||
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n", .{});
|
std.log.info(.kmain, "Init arch " ++ @tagName(builtin.arch) ++ "\n", .{});
|
||||||
arch.init(boot_payload, &mem_profile, &fixed_allocator.allocator);
|
arch.init(boot_payload, &mem_profile, &fixed_allocator.allocator);
|
||||||
log.logInfo("Arch init done\n", .{});
|
std.log.info(.kmain, "Arch init done\n", .{});
|
||||||
|
|
||||||
// Give the kernel heap 10% of the available memory. This can be fine-tuned as time goes on.
|
// Give the kernel heap 10% of the available memory. This can be fine-tuned as time goes on.
|
||||||
var heap_size = mem_profile.mem_kb / 10 * 1024;
|
var heap_size = mem_profile.mem_kb / 10 * 1024;
|
||||||
|
@ -81,12 +92,12 @@ export fn kmain(boot_payload: arch.BootPayload) void {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialisation is finished, now does other stuff
|
// Initialisation is finished, now does other stuff
|
||||||
log.logInfo("Init done\n", .{});
|
std.log.info(.kmain, "Init\n", .{});
|
||||||
|
|
||||||
// Main initialisation finished so can enable interrupts
|
// Main initialisation finished so can enable interrupts
|
||||||
arch.enableInterrupts();
|
arch.enableInterrupts();
|
||||||
|
|
||||||
log.logInfo("Creating init2\n", .{});
|
std.log.info(.kmain, "Creating init2\n", .{});
|
||||||
|
|
||||||
// Create a init2 task
|
// Create a init2 task
|
||||||
var idle_task = task.Task.create(initStage2, &kernel_heap.allocator) catch |e| {
|
var idle_task = task.Task.create(initStage2, &kernel_heap.allocator) catch |e| {
|
||||||
|
@ -121,7 +132,7 @@ fn initStage2() noreturn {
|
||||||
|
|
||||||
switch (build_options.test_mode) {
|
switch (build_options.test_mode) {
|
||||||
.Initialisation => {
|
.Initialisation => {
|
||||||
log.logInfo("SUCCESS\n", .{});
|
std.log.info(.kmain, "SUCCESS\n", .{});
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const build_options = @import("build_options");
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const fmt = std.fmt;
|
const fmt = std.fmt;
|
||||||
|
const build_options = @import("build_options");
|
||||||
const Serial = @import("serial.zig").Serial;
|
const Serial = @import("serial.zig").Serial;
|
||||||
const scheduler = @import("scheduler.zig");
|
const scheduler = @import("scheduler.zig");
|
||||||
|
|
||||||
|
@ -10,14 +10,7 @@ const LoggingError = error{};
|
||||||
/// The OutStream for the format function
|
/// The OutStream for the format function
|
||||||
const OutStream = std.io.OutStream(void, LoggingError, logCallback);
|
const OutStream = std.io.OutStream(void, LoggingError, logCallback);
|
||||||
|
|
||||||
/// The different levels of logging that can be outputted.
|
/// The serial object where the logs will be written to. This will be a COM serial port.
|
||||||
pub const Level = enum {
|
|
||||||
INFO,
|
|
||||||
DEBUG,
|
|
||||||
WARNING,
|
|
||||||
ERROR,
|
|
||||||
};
|
|
||||||
|
|
||||||
var serial: Serial = undefined;
|
var serial: Serial = undefined;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -43,66 +36,18 @@ fn logCallback(context: void, str: []const u8) LoggingError!usize {
|
||||||
/// Write a message to the log output stream with a certain logging level.
|
/// Write a message to the log output stream with a certain logging level.
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN comptime level: Level - The logging level to use. Determines the message prefix and
|
/// IN comptime level: std.log.Level - The logging level to use. Determines the message prefix
|
||||||
/// whether it is filtered.
|
/// and whether it is filtered.
|
||||||
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
/// IN comptime format: []const u8 - The message format. Uses the standard format
|
||||||
/// options.
|
/// specification options.
|
||||||
/// IN args: anytype - A struct of the parameters for the format string.
|
/// IN args: anytype - A struct of the parameters for the format string.
|
||||||
///
|
///
|
||||||
pub fn log(comptime level: Level, comptime format: []const u8, args: anytype) void {
|
pub fn log(comptime level: std.log.Level, comptime format: []const u8, args: anytype) void {
|
||||||
scheduler.taskSwitching(false);
|
scheduler.taskSwitching(false);
|
||||||
fmt.format(OutStream{ .context = {} }, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable;
|
fmt.format(OutStream{ .context = {} }, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable;
|
||||||
scheduler.taskSwitching(true);
|
scheduler.taskSwitching(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// 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: anytype - A struct of the parameters for the format string.
|
|
||||||
///
|
|
||||||
pub fn logInfo(comptime format: []const u8, args: anytype) void {
|
|
||||||
log(Level.INFO, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 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: anytype - A struct of the parameters for the format string.
|
|
||||||
///
|
|
||||||
pub fn logDebug(comptime format: []const u8, args: anytype) void {
|
|
||||||
log(Level.DEBUG, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 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: anytype - A struct of the parameters for the format string.
|
|
||||||
///
|
|
||||||
pub fn logWarning(comptime format: []const u8, args: anytype) void {
|
|
||||||
log(Level.WARNING, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 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: anytype - A struct of the parameters for the format string.
|
|
||||||
///
|
|
||||||
pub fn logError(comptime format: []const u8, args: anytype) void {
|
|
||||||
log(Level.ERROR, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Initialise the logging stream using the given Serial instance.
|
/// Initialise the logging stream using the given Serial instance.
|
||||||
///
|
///
|
||||||
|
@ -122,17 +67,9 @@ pub fn init(ser: Serial) void {
|
||||||
/// The logging runtime tests that will test all logging levels.
|
/// The logging runtime tests that will test all logging levels.
|
||||||
///
|
///
|
||||||
fn runtimeTests() void {
|
fn runtimeTests() void {
|
||||||
inline for (@typeInfo(Level).Enum.fields) |field| {
|
inline for (@typeInfo(std.log.Level).Enum.fields) |field| {
|
||||||
const level = @field(Level, field.name);
|
const level = @field(std.log.Level, field.name);
|
||||||
log(level, "Test " ++ field.name ++ " level\n", .{});
|
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 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) });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const expectEqual = std.testing.expectEqual;
|
const expectEqual = std.testing.expectEqual;
|
||||||
const log = @import("log.zig");
|
|
||||||
|
|
||||||
pub const Module = struct {
|
pub const Module = struct {
|
||||||
/// The region of memory occupied by the module
|
/// The region of memory occupied by the module
|
||||||
|
|
|
@ -2,7 +2,6 @@ const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const tty = @import("tty.zig");
|
const tty = @import("tty.zig");
|
||||||
const arch = @import("arch.zig").internals;
|
const arch = @import("arch.zig").internals;
|
||||||
const log = @import("log.zig");
|
|
||||||
const multiboot = @import("multiboot.zig");
|
const multiboot = @import("multiboot.zig");
|
||||||
const mem = @import("mem.zig");
|
const mem = @import("mem.zig");
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
|
@ -102,12 +101,12 @@ var symbol_map: ?SymbolMap = null;
|
||||||
///
|
///
|
||||||
fn logTraceAddress(addr: usize) void {
|
fn logTraceAddress(addr: usize) void {
|
||||||
const str = if (symbol_map) |syms| syms.search(addr) orelse "?????" else "(no symbols available)";
|
const str = if (symbol_map) |syms| syms.search(addr) orelse "?????" else "(no symbols available)";
|
||||||
log.logError("{x}: {}\n", .{ addr, str });
|
std.log.emerg(.panic, "{x}: {}\n", .{ addr, str });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn {
|
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn {
|
||||||
@setCold(true);
|
@setCold(true);
|
||||||
log.logError("Kernel panic: " ++ format ++ "\n", args);
|
std.log.emerg(.panic, "Kernel panic: " ++ format ++ "\n", args);
|
||||||
if (trace) |trc| {
|
if (trace) |trc| {
|
||||||
var last_addr: u64 = 0;
|
var last_addr: u64 = 0;
|
||||||
for (trc.instruction_addresses) |ret_addr| {
|
for (trc.instruction_addresses) |ret_addr| {
|
||||||
|
@ -302,8 +301,8 @@ fn parseMapEntry(start: *[*]const u8, end: *const u8) !MapEntry {
|
||||||
/// std.fmt.ParseUnsignedError: See parseMapEntry.
|
/// std.fmt.ParseUnsignedError: See parseMapEntry.
|
||||||
///
|
///
|
||||||
pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) !void {
|
pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) !void {
|
||||||
log.logInfo("Init panic\n", .{});
|
std.log.info(.panic, "Init\n", .{});
|
||||||
defer log.logInfo("Done panic\n", .{});
|
defer std.log.info(.panic, "Done\n", .{});
|
||||||
|
|
||||||
// Exit if we haven't loaded all debug modules
|
// Exit if we haven't loaded all debug modules
|
||||||
if (mem_profile.modules.len < 1) {
|
if (mem_profile.modules.len < 1) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("ar
|
||||||
const MemProfile = (if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig")).MemProfile;
|
const MemProfile = (if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig")).MemProfile;
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const panic = @import("panic.zig").panic;
|
const panic = @import("panic.zig").panic;
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("log.zig");
|
|
||||||
const Bitmap = @import("bitmap.zig").Bitmap;
|
const Bitmap = @import("bitmap.zig").Bitmap;
|
||||||
|
|
||||||
const PmmBitmap = Bitmap(u32);
|
const PmmBitmap = Bitmap(u32);
|
||||||
|
@ -98,8 +97,8 @@ pub fn blocksFree() usize {
|
||||||
/// IN allocator: *std.mem.Allocator - The allocator to use to allocate the bitmaps.
|
/// IN allocator: *std.mem.Allocator - The allocator to use to allocate the bitmaps.
|
||||||
///
|
///
|
||||||
pub fn init(mem: *const MemProfile, allocator: *std.mem.Allocator) void {
|
pub fn init(mem: *const MemProfile, allocator: *std.mem.Allocator) void {
|
||||||
log.logInfo("Init pmm\n", .{});
|
std.log.info(.pmm, "Init\n", .{});
|
||||||
defer log.logInfo("Done pmm\n", .{});
|
defer std.log.info(.pmm, "Done\n", .{});
|
||||||
|
|
||||||
bitmap = PmmBitmap.init(mem.mem_kb * 1024 / BLOCK_SIZE, allocator) catch @panic("Bitmap allocation failed");
|
bitmap = PmmBitmap.init(mem.mem_kb * 1024 / BLOCK_SIZE, allocator) catch @panic("Bitmap allocation failed");
|
||||||
|
|
||||||
|
@ -226,5 +225,5 @@ fn runtimeTests(mem: *const MemProfile, allocator: *std.mem.Allocator) void {
|
||||||
for (alloc_list.items) |alloced| {
|
for (alloc_list.items) |alloced| {
|
||||||
free(alloced) catch |e| panic(@errorReturnTrace(), "FAILURE: Failed freeing allocation in PMM rt test: {}", .{e});
|
free(alloced) catch |e| panic(@errorReturnTrace(), "FAILURE: Failed freeing allocation in PMM rt test: {}", .{e});
|
||||||
}
|
}
|
||||||
log.logInfo("PMM: Tested allocation\n", .{});
|
std.log.info(.pmm, "Tested allocation\n", .{});
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ const is_test = builtin.is_test;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.mock_path;
|
const mock_path = build_options.mock_path;
|
||||||
const arch = @import("arch.zig").internals;
|
const arch = @import("arch.zig").internals;
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("log.zig");
|
|
||||||
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
|
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
|
||||||
const task = if (is_test) @import(mock_path ++ "task_mock.zig") else @import("task.zig");
|
const task = if (is_test) @import(mock_path ++ "task_mock.zig") else @import("task.zig");
|
||||||
const Task = task.Task;
|
const Task = task.Task;
|
||||||
|
@ -117,8 +116,8 @@ pub fn scheduleTask(new_task: *Task, allocator: *Allocator) Allocator.Error!void
|
||||||
///
|
///
|
||||||
pub fn init(allocator: *Allocator) Allocator.Error!void {
|
pub fn init(allocator: *Allocator) Allocator.Error!void {
|
||||||
// TODO: Maybe move the task init here?
|
// TODO: Maybe move the task init here?
|
||||||
log.logInfo("Init scheduler\n", .{});
|
std.log.info(.scheduler, "Init\n", .{});
|
||||||
defer log.logInfo("Done scheduler\n", .{});
|
defer std.log.info(.scheduler, "Done\n", .{});
|
||||||
|
|
||||||
// Init the task list for round robin
|
// Init the task list for round robin
|
||||||
tasks = TailQueue(*Task).init();
|
tasks = TailQueue(*Task).init();
|
||||||
|
@ -289,7 +288,7 @@ var is_set: *volatile bool = undefined;
|
||||||
/// The test task function.
|
/// The test task function.
|
||||||
///
|
///
|
||||||
fn task_function() noreturn {
|
fn task_function() noreturn {
|
||||||
log.logInfo("Switched\n", .{});
|
std.log.info(.scheduler, "Switched\n", .{});
|
||||||
is_set.* = false;
|
is_set.* = false;
|
||||||
while (true) {}
|
while (true) {}
|
||||||
}
|
}
|
||||||
|
@ -344,7 +343,7 @@ fn rt_variable_preserved(allocator: *Allocator) void {
|
||||||
panic(@errorReturnTrace(), "FAILED: z not 3, but: {}\n", .{z});
|
panic(@errorReturnTrace(), "FAILED: z not 3, but: {}\n", .{z});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("SUCCESS: Scheduler variables preserved\n", .{});
|
std.log.info(.scheduler, "SUCCESS: Scheduler variables preserved\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -6,7 +6,6 @@ const is_test = builtin.is_test;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const mock_path = build_options.mock_path;
|
const mock_path = build_options.mock_path;
|
||||||
const arch = @import("arch.zig").internals;
|
const arch = @import("arch.zig").internals;
|
||||||
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("log.zig");
|
|
||||||
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
|
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
|
||||||
const ComptimeBitmap = @import("bitmap.zig").ComptimeBitmap;
|
const ComptimeBitmap = @import("bitmap.zig").ComptimeBitmap;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
|
@ -3,7 +3,6 @@ const fmt = std.fmt;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const arch = @import("arch.zig").internals;
|
const arch = @import("arch.zig").internals;
|
||||||
const log = @import("log.zig");
|
|
||||||
const panic = @import("panic.zig").panic;
|
const panic = @import("panic.zig").panic;
|
||||||
|
|
||||||
/// The OutStream for the format function
|
/// The OutStream for the format function
|
||||||
|
@ -52,7 +51,7 @@ fn printCallback(ctx: void, str: []const u8) !usize {
|
||||||
pub fn print(comptime format: []const u8, args: anytype) void {
|
pub fn print(comptime format: []const u8, args: anytype) void {
|
||||||
// Printing can't error because of the scrolling, if it does, we have a big problem
|
// Printing can't error because of the scrolling, if it does, we have a big problem
|
||||||
fmt.format(OutStream{ .context = {} }, format, args) catch |e| {
|
fmt.format(OutStream{ .context = {} }, format, args) catch |e| {
|
||||||
log.logError("TTY: Error printing. Error: {}\n", .{e});
|
std.log.emerg(.tty, "Error printing. Error: {}\n", .{e});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,8 +101,8 @@ pub fn clear() void {
|
||||||
/// IN boot_payload: arch.BootPayload - The payload passed to the kernel on boot
|
/// IN boot_payload: arch.BootPayload - The payload passed to the kernel on boot
|
||||||
///
|
///
|
||||||
pub fn init(alloc: *Allocator, boot_payload: arch.BootPayload) void {
|
pub fn init(alloc: *Allocator, boot_payload: arch.BootPayload) void {
|
||||||
log.logInfo("Init tty\n", .{});
|
std.log.info(.tty, "Init\n", .{});
|
||||||
defer log.logInfo("Done tty\n", .{});
|
defer std.log.info(.tty, "Done\n", .{});
|
||||||
tty = arch.initTTY(boot_payload);
|
tty = arch.initTTY(boot_payload);
|
||||||
allocator = alloc;
|
allocator = alloc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ const bitmap = @import("bitmap.zig");
|
||||||
const pmm = @import("pmm.zig");
|
const pmm = @import("pmm.zig");
|
||||||
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
|
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
|
||||||
const tty = @import("tty.zig");
|
const tty = @import("tty.zig");
|
||||||
const log = @import("log.zig");
|
|
||||||
const panic = @import("panic.zig").panic;
|
const panic = @import("panic.zig").panic;
|
||||||
const arch = @import("arch.zig").internals;
|
const arch = @import("arch.zig").internals;
|
||||||
|
|
||||||
|
@ -349,8 +348,8 @@ pub fn VirtualMemoryManager(comptime Payload: type) type {
|
||||||
/// std.mem.Allocator.Error.OutOfMemory - The allocator cannot allocate the memory required
|
/// std.mem.Allocator.Error.OutOfMemory - The allocator cannot allocate the memory required
|
||||||
///
|
///
|
||||||
pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) std.mem.Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {
|
pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) std.mem.Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {
|
||||||
log.logInfo("Init vmm\n", .{});
|
std.log.info(.tty, "Init\n", .{});
|
||||||
defer log.logInfo("Done vmm\n", .{});
|
defer std.log.info(.tty, "Done\n", .{});
|
||||||
|
|
||||||
var vmm = try VirtualMemoryManager(arch.VmmPayload).init(@ptrToInt(&KERNEL_ADDR_OFFSET), 0xFFFFFFFF, allocator, arch.VMM_MAPPER, arch.KERNEL_VMM_PAYLOAD);
|
var vmm = try VirtualMemoryManager(arch.VmmPayload).init(@ptrToInt(&KERNEL_ADDR_OFFSET), 0xFFFFFFFF, allocator, arch.VMM_MAPPER, arch.KERNEL_VMM_PAYLOAD);
|
||||||
|
|
||||||
|
@ -598,5 +597,5 @@ fn runtimeTests(comptime Payload: type, vmm: VirtualMemoryManager(Payload), mem_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logInfo("VMM: Tested allocations\n", .{});
|
std.log.info(.tty, "Tested allocations\n", .{});
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,9 +118,9 @@ pub const RuntimeStep = struct {
|
||||||
defer self.builder.allocator.free(msg);
|
defer self.builder.allocator.free(msg);
|
||||||
// Print the line to see what is going on
|
// Print the line to see what is going on
|
||||||
std.debug.warn("{}\n", .{msg});
|
std.debug.warn("{}\n", .{msg});
|
||||||
if (std.mem.startsWith(u8, msg, "[ERROR] FAILURE")) {
|
if (std.mem.indexOf(u8, msg, "FAILURE")) |_| {
|
||||||
return false;
|
return false;
|
||||||
} else if (std.mem.eql(u8, msg, "[INFO] SUCCESS")) {
|
} else if (std.mem.eql(u8, msg, "[info] (kmain): SUCCESS")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ pub const RuntimeStep = struct {
|
||||||
defer self.builder.allocator.free(msg);
|
defer self.builder.allocator.free(msg);
|
||||||
// Print the line to see what is going on
|
// Print the line to see what is going on
|
||||||
std.debug.warn("{}\n", .{msg});
|
std.debug.warn("{}\n", .{msg});
|
||||||
if (std.mem.eql(u8, msg, "[ERROR] Kernel panic: integer overflow")) {
|
if (std.mem.eql(u8, msg, "[emerg] (panic): Kernel panic: integer overflow")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,9 +165,9 @@ pub const RuntimeStep = struct {
|
||||||
std.debug.warn("{}\n", .{msg});
|
std.debug.warn("{}\n", .{msg});
|
||||||
|
|
||||||
// Make sure `[INFO] Switched` then `[INFO] SUCCESS: Scheduler variables preserved` are logged in this order
|
// Make sure `[INFO] Switched` then `[INFO] SUCCESS: Scheduler variables preserved` are logged in this order
|
||||||
if (std.mem.eql(u8, msg, "[INFO] Switched") and state == 0) {
|
if (std.mem.eql(u8, msg, "[info] (scheduler): Switched") and state == 0) {
|
||||||
state = 1;
|
state = 1;
|
||||||
} else if (std.mem.eql(u8, msg, "[INFO] SUCCESS: Scheduler variables preserved") and state == 1) {
|
} else if (std.mem.eql(u8, msg, "[info] (scheduler): SUCCESS: Scheduler variables preserved") and state == 1) {
|
||||||
state = 2;
|
state = 2;
|
||||||
}
|
}
|
||||||
if (state == 2) {
|
if (state == 2) {
|
||||||
|
|
Loading…
Reference in a new issue