diff --git a/build.zig b/build.zig index d63a392..b743dd2 100644 --- a/build.zig +++ b/build.zig @@ -13,6 +13,7 @@ const File = fs.File; const Mode = std.builtin.Mode; const TestMode = rt.TestMode; const ArrayList = std.ArrayList; +const Pkg = std.build.Pkg; const Fat32 = @import("mkfat32.zig").Fat32; const x86_i686 = CrossTarget{ @@ -37,7 +38,10 @@ pub fn build(b: *Builder) !void { b.default_step.dependOn(&fmt_step.step); const main_src = "src/kernel/kmain.zig"; + const pluto_src = "src/kernel/pluto.zig"; const arch_root = "src/kernel/arch"; + const arch_mock_src = "test/mock/kernel/arch_mock.zig"; + const arch_src = try fs.path.join(b.allocator, &[_][]const u8{ arch_root, arch, "arch.zig" }); const linker_script_path = try fs.path.join(b.allocator, &[_][]const u8{ arch_root, arch, "link.ld" }); const output_iso = try fs.path.join(b.allocator, &[_][]const u8{ b.install_path, "pluto.iso" }); const iso_dir_path = try fs.path.join(b.allocator, &[_][]const u8{ b.install_path, "iso" }); @@ -68,6 +72,16 @@ pub fn build(b: *Builder) !void { exec.setLinkerScriptPath(std.build.FileSource{ .path = linker_script_path }); exec.setTarget(target); + var pluto_pkg = Pkg{ .name = "pluto", .path = .{ .path = pluto_src } }; + var arch_pkg = Pkg{ .name = "arch", .path = .{ .path = arch_src } }; + var arch_mock_pkg = Pkg{ .name = "arch_mock", .path = .{ .path = arch_mock_src } }; + arch_mock_pkg.dependencies = &[_]Pkg{ arch_pkg, pluto_pkg, exec_options.getPackage("build_options") }; + pluto_pkg.dependencies = &[_]Pkg{ arch_pkg, arch_mock_pkg, exec_options.getPackage("build_options") }; + arch_pkg.dependencies = &[_]Pkg{ pluto_pkg, arch_mock_pkg, exec_options.getPackage("build_options") }; + exec.addPackage(pluto_pkg); + exec.addPackage(arch_pkg); + exec.addPackage(arch_mock_pkg); + const make_iso = switch (target.getCpuArch()) { .i386 => b.addSystemCommand(&[_][]const u8{ "./makeiso.sh", boot_path, modules_path, iso_dir_path, exec_output_path, ramdisk_path, output_iso }), else => unreachable, @@ -113,6 +127,9 @@ pub fn build(b: *Builder) !void { unit_tests.addOptions("build_options", unit_test_options); unit_test_options.addOption(TestMode, "test_mode", test_mode); unit_tests.setTarget(.{ .cpu_arch = target.cpu_arch }); + unit_tests.addPackage(pluto_pkg); + unit_tests.addPackage(arch_pkg); + unit_tests.addPackage(arch_mock_pkg); if (builtin.os.tag != .windows) { b.enable_qemu = true; @@ -123,6 +140,8 @@ pub fn build(b: *Builder) !void { mock_gen.setMainPkgPath("."); const mock_gen_run = mock_gen.run(); unit_tests.step.dependOn(&mock_gen_run.step); + exec.step.dependOn(&mock_gen_run.step); + b.default_step.dependOn(&mock_gen_run.step); // Create test FAT32 image const test_fat32_img_step = Fat32BuilderStep.create(b, .{}, test_fat32_image_path); diff --git a/src/kernel/arch.zig b/src/kernel/arch.zig deleted file mode 100644 index e3e812e..0000000 --- a/src/kernel/arch.zig +++ /dev/null @@ -1,13 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const is_test = builtin.is_test; -const build_options = @import("build_options"); - -pub const internals = if (is_test) @import("../../test/mock/kernel/arch_mock.zig") else switch (builtin.cpu.arch) { - .i386 => @import("arch/x86/arch.zig"), - else => unreachable, -}; - -test "" { - _ = @import("arch/x86/arch.zig"); -} diff --git a/src/kernel/arch/x86/arch.zig b/src/kernel/arch/x86/arch.zig index 2b4db4f..c7f4c29 100644 --- a/src/kernel/arch/x86/arch.zig +++ b/src/kernel/arch/x86/arch.zig @@ -3,11 +3,11 @@ const Allocator = std.mem.Allocator; const log = std.log.scoped(.x86_arch); const builtin = @import("builtin"); const cmos = @import("cmos.zig"); -const gdt = @import("gdt.zig"); -const idt = @import("idt.zig"); +pub const gdt = @import("gdt.zig"); +pub const idt = @import("idt.zig"); const irq = @import("irq.zig"); const isr = @import("isr.zig"); -const paging = @import("paging.zig"); +pub const paging = @import("paging.zig"); const pic = @import("pic.zig"); const pci = @import("pci.zig"); const pit = @import("pit.zig"); @@ -16,15 +16,16 @@ const serial = @import("serial.zig"); const syscalls = @import("syscalls.zig"); const tty = @import("tty.zig"); const vga = @import("vga.zig"); -const mem = @import("../../mem.zig"); const multiboot = @import("multiboot.zig"); -const vmm = @import("../../vmm.zig"); const keyboard = @import("keyboard.zig"); -const Serial = @import("../../serial.zig").Serial; -const panic = @import("../../panic.zig").panic; -const TTY = @import("../../tty.zig").TTY; -const Keyboard = @import("../../keyboard.zig").Keyboard; -const Task = @import("../../task.zig").Task; +const pluto = @import("pluto"); +const mem = pluto.mem; +const vmm = pluto.vmm; +const Keyboard = pluto.keyboard.Keyboard; +const Serial = pluto.serial.Serial; +const panic = pluto.panic_root.panic; +const TTY = pluto.tty.TTY; +const Task = pluto.task.Task; const MemProfile = mem.MemProfile; /// The type of a device. diff --git a/src/kernel/arch/x86/cmos.zig b/src/kernel/arch/x86/cmos.zig index f95b1db..a8d0370 100644 --- a/src/kernel/arch/x86/cmos.zig +++ b/src/kernel/arch/x86/cmos.zig @@ -3,7 +3,7 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; const expectEqual = std.testing.expectEqual; const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); /// The current year to be used for calculating the 4 digit year, as the CMOS return the last two /// digits of the year. diff --git a/src/kernel/arch/x86/gdt.zig b/src/kernel/arch/x86/gdt.zig index 8483cb6..fd947ae 100644 --- a/src/kernel/arch/x86/gdt.zig +++ b/src/kernel/arch/x86/gdt.zig @@ -6,7 +6,7 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; const panic = @import("../../panic.zig").panic; const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); /// The access bits for a GDT entry. const AccessBits = packed struct { diff --git a/src/kernel/arch/x86/idt.zig b/src/kernel/arch/x86/idt.zig index b4567b7..048bfa5 100644 --- a/src/kernel/arch/x86/idt.zig +++ b/src/kernel/arch/x86/idt.zig @@ -8,7 +8,7 @@ const is_test = builtin.is_test; const panic = @import("../../panic.zig").panic; const build_options = @import("build_options"); const gdt = if (is_test) @import("../../../../test/mock/kernel/gdt_mock.zig") else @import("gdt.zig"); -const arch = if (builtin.is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (builtin.is_test) @import("arch_mock") else @import("arch.zig"); /// The structure that contains all the information that each IDT entry needs. pub const IdtEntry = packed struct { diff --git a/src/kernel/arch/x86/irq.zig b/src/kernel/arch/x86/irq.zig index 94e2152..4e6a030 100644 --- a/src/kernel/arch/x86/irq.zig +++ b/src/kernel/arch/x86/irq.zig @@ -7,9 +7,9 @@ const expectError = std.testing.expectError; const log = std.log.scoped(.x86_irq); const build_options = @import("build_options"); const panic = @import("../../panic.zig").panic; -const idt = if (is_test) @import("../../../../test/mock/kernel/idt_mock.zig") else @import("idt.zig"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); -const pic = if (is_test) @import("../../../../test/mock/kernel/pic_mock.zig") else @import("pic.zig"); +const idt = if (is_test) @import("arch_mock").idt_mock else @import("idt.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); +const pic = if (is_test) @import("arch_mock").pic_mock else @import("pic.zig"); const interrupts = @import("interrupts.zig"); /// The error set for the IRQ. This will be from installing a IRQ handler. diff --git a/src/kernel/arch/x86/isr.zig b/src/kernel/arch/x86/isr.zig index eabb1a1..3a44a63 100644 --- a/src/kernel/arch/x86/isr.zig +++ b/src/kernel/arch/x86/isr.zig @@ -8,8 +8,8 @@ const log = std.log.scoped(.x86_isr); const build_options = @import("build_options"); const syscalls = @import("syscalls.zig"); const panic = @import("../../panic.zig").panic; -const idt = if (is_test) @import("../../../../test/mock/kernel/idt_mock.zig") else @import("idt.zig"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const idt = if (is_test) @import("arch_mock").idt_mock else @import("idt.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); const interrupts = @import("interrupts.zig"); /// The error set for the ISR. This will be from installing a ISR handler. diff --git a/src/kernel/arch/x86/keyboard.zig b/src/kernel/arch/x86/keyboard.zig index 567573e..dc6f263 100644 --- a/src/kernel/arch/x86/keyboard.zig +++ b/src/kernel/arch/x86/keyboard.zig @@ -6,7 +6,7 @@ const testing = std.testing; const log = std.log.scoped(.x86_keyboard); const irq = @import("irq.zig"); const pic = @import("pic.zig"); -const arch = if (builtin.is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (builtin.is_test) @import("arch_mock") else @import("arch.zig"); const panic = @import("../../panic.zig").panic; const kb = @import("../../keyboard.zig"); const Keyboard = kb.Keyboard; diff --git a/src/kernel/arch/x86/paging.zig b/src/kernel/arch/x86/paging.zig index f87abf0..1de58d2 100644 --- a/src/kernel/arch/x86/paging.zig +++ b/src/kernel/arch/x86/paging.zig @@ -7,7 +7,7 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; const panic = @import("../../panic.zig").panic; const build_options = @import("build_options"); -const arch = if (builtin.is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (builtin.is_test) @import("arch_mock") else @import("arch.zig"); const isr = @import("isr.zig"); const MemProfile = @import("../../mem.zig").MemProfile; const tty = @import("../../tty.zig"); diff --git a/src/kernel/arch/x86/pci.zig b/src/kernel/arch/x86/pci.zig index 769b996..d0e6654 100644 --- a/src/kernel/arch/x86/pci.zig +++ b/src/kernel/arch/x86/pci.zig @@ -6,7 +6,7 @@ const build_options = @import("build_options"); const Allocator = std.mem.Allocator; const ArrayList = std.ArrayList; const log = std.log.scoped(.pci); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); /// The port address for selecting a 32bit register in the PCI configuration space. const CONFIG_ADDRESS: u16 = 0x0CF8; diff --git a/src/kernel/arch/x86/pic.zig b/src/kernel/arch/x86/pic.zig index f37ad46..85cb244 100644 --- a/src/kernel/arch/x86/pic.zig +++ b/src/kernel/arch/x86/pic.zig @@ -5,7 +5,7 @@ const log = std.log.scoped(.x86_pic); const builtin = @import("builtin"); const is_test = builtin.is_test; const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); const panic = @import("../../panic.zig").panic; // ---------- diff --git a/src/kernel/arch/x86/pit.zig b/src/kernel/arch/x86/pit.zig index 6f3e961..946e870 100644 --- a/src/kernel/arch/x86/pit.zig +++ b/src/kernel/arch/x86/pit.zig @@ -7,7 +7,7 @@ const expectEqual = std.testing.expectEqual; const expectError = std.testing.expectError; const log = std.log.scoped(.x86_pit); const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); const panic = @import("../../panic.zig").panic; const irq = @import("irq.zig"); const pic = @import("pic.zig"); diff --git a/src/kernel/arch/x86/rtc.zig b/src/kernel/arch/x86/rtc.zig index 7221ca6..1091ead 100644 --- a/src/kernel/arch/x86/rtc.zig +++ b/src/kernel/arch/x86/rtc.zig @@ -6,11 +6,11 @@ const expectEqual = std.testing.expectEqual; const expectError = std.testing.expectError; const log = std.log.scoped(.x86_rtc); const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); const pic = @import("pic.zig"); const pit = @import("pit.zig"); const irq = @import("irq.zig"); -const cmos = if (is_test) @import("../../../../test/mock/kernel/cmos_mock.zig") else @import("cmos.zig"); +const cmos = if (is_test) @import("arch_mock").cmos_mock else @import("cmos.zig"); const panic = @import("../../panic.zig").panic; const scheduler = @import("../../scheduler.zig"); diff --git a/src/kernel/arch/x86/syscalls.zig b/src/kernel/arch/x86/syscalls.zig index 01ee414..9cdbaca 100644 --- a/src/kernel/arch/x86/syscalls.zig +++ b/src/kernel/arch/x86/syscalls.zig @@ -3,12 +3,13 @@ const log = std.log.scoped(.x86_syscalls); const builtin = @import("builtin"); const is_test = builtin.is_test; const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); const testing = std.testing; const expect = std.testing.expect; const isr = @import("isr.zig"); -const panic = @import("../../panic.zig").panic; -const syscalls = @import("../../syscalls.zig"); +const pluto = @import("pluto"); +const panic = pluto.panic_root.panic; +const syscalls = pluto.syscalls; /// The isr number associated with syscalls pub const INTERRUPT: u16 = 0x80; diff --git a/src/kernel/arch/x86/tty.zig b/src/kernel/arch/x86/tty.zig index 0c4db91..a3144fc 100644 --- a/src/kernel/arch/x86/tty.zig +++ b/src/kernel/arch/x86/tty.zig @@ -7,7 +7,7 @@ const expectEqual = std.testing.expectEqual; const expectError = std.testing.expectError; const log = std.log.scoped(.x86_tty); const build_options = @import("build_options"); -const vga = if (is_test) @import("../../../../test/mock/kernel/vga_mock.zig") else @import("vga.zig"); +const vga = if (is_test) @import("arch_mock").vga_mock else @import("vga.zig"); const panic = @import("../../panic.zig").panic; /// The error set for if there is an error whiles printing. diff --git a/src/kernel/arch/x86/vga.zig b/src/kernel/arch/x86/vga.zig index d016276..d448815 100644 --- a/src/kernel/arch/x86/vga.zig +++ b/src/kernel/arch/x86/vga.zig @@ -4,7 +4,7 @@ const is_test = builtin.is_test; const expectEqual = std.testing.expectEqual; const log = std.log.scoped(.x86_vga); const build_options = @import("build_options"); -const arch = if (is_test) @import("../../../../test/mock/kernel/arch_mock.zig") else @import("arch.zig"); +const arch = if (is_test) @import("arch_mock") else @import("arch.zig"); const panic = @import("../../panic.zig").panic; /// The port address for the VGA register selection. diff --git a/src/kernel/filesystem/fat32.zig b/src/kernel/filesystem/fat32.zig index aba3e5f..cf554be 100644 --- a/src/kernel/filesystem/fat32.zig +++ b/src/kernel/filesystem/fat32.zig @@ -8,7 +8,9 @@ const log = std.log.scoped(.fat32); const AutoHashMap = std.AutoHashMap; const Allocator = std.mem.Allocator; const ArrayList = std.ArrayList; -const arch = @import("../arch.zig").internals; +const builtins = @import("builtin"); +const is_test = builtins.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const vfs = @import("vfs.zig"); const mem = @import("../mem.zig"); const CodePage = @import("../code_page/code_page.zig").CodePage; diff --git a/src/kernel/keyboard.zig b/src/kernel/keyboard.zig index 8e5a5fe..463467f 100644 --- a/src/kernel/keyboard.zig +++ b/src/kernel/keyboard.zig @@ -2,7 +2,9 @@ const std = @import("std"); const testing = std.testing; const ArrayList = std.ArrayList; const Allocator = std.mem.Allocator; -const arch = @import("arch.zig").internals; +const builtin = @import("builtin"); +const is_test = builtin.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); /// An arbitrary number of keys to remember before dropping any more that arrive. Is a power of two so we can use nice overflowing addition pub const QUEUE_SIZE = 32; diff --git a/src/kernel/kmain.zig b/src/kernel/kmain.zig index 89b52ff..27eee06 100644 --- a/src/kernel/kmain.zig +++ b/src/kernel/kmain.zig @@ -1,23 +1,23 @@ const std = @import("std"); -const kmain_log = std.log.scoped(.kmain); const builtin = @import("builtin"); -const is_test = builtin.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); +const pluto = @import("pluto"); const build_options = @import("build_options"); -const arch = @import("arch.zig").internals; -const tty = @import("tty.zig"); -const log_root = @import("log.zig"); -const pmm = @import("pmm.zig"); -const serial = @import("serial.zig"); -const vmm = @import("vmm.zig"); -const mem = @import("mem.zig"); -const panic_root = @import("panic.zig"); -const task = @import("task.zig"); -const heap = @import("heap.zig"); -const scheduler = @import("scheduler.zig"); -const vfs = @import("filesystem/vfs.zig"); -const initrd = @import("filesystem/initrd.zig"); -const keyboard = @import("keyboard.zig"); +const is_test = builtin.is_test; +const kmain_log = std.log.scoped(.kmain); const Allocator = std.mem.Allocator; +const tty = pluto.tty; +const panic_root = pluto.panic_root; +const log_root = pluto.log_root; +const heap = pluto.heap; +const serial = pluto.serial; +const pmm = pluto.pmm; +const vmm = pluto.vmm; +const keyboard = pluto.keyboard; +const initrd = pluto.initrd; +const vfs = pluto.vfs; +const scheduler = pluto.scheduler; +const task = pluto.task; comptime { if (!is_test) { diff --git a/src/kernel/panic.zig b/src/kernel/panic.zig index bfc2a28..31814b0 100644 --- a/src/kernel/panic.zig +++ b/src/kernel/panic.zig @@ -1,6 +1,8 @@ const std = @import("std"); const builtin = std.builtin; -const arch = @import("arch.zig").internals; +const builtins = @import("builtin"); +const is_test = builtins.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const mem = @import("mem.zig"); const build_options = @import("build_options"); const ArrayList = std.ArrayList; diff --git a/src/kernel/pluto.zig b/src/kernel/pluto.zig new file mode 100644 index 0000000..91e38f0 --- /dev/null +++ b/src/kernel/pluto.zig @@ -0,0 +1,14 @@ +pub const tty = @import("tty.zig"); +pub const log_root = @import("log.zig"); +pub const pmm = @import("pmm.zig"); +pub const serial = @import("serial.zig"); +pub const vmm = @import("vmm.zig"); +pub const mem = @import("mem.zig"); +pub const panic_root = @import("panic.zig"); +pub const task = @import("task.zig"); +pub const heap = @import("heap.zig"); +pub const scheduler = @import("scheduler.zig"); +pub const vfs = @import("filesystem/vfs.zig"); +pub const initrd = @import("filesystem/initrd.zig"); +pub const keyboard = @import("keyboard.zig"); +pub const syscalls = @import("syscalls.zig"); diff --git a/src/kernel/pmm.zig b/src/kernel/pmm.zig index 395269d..0299a9f 100644 --- a/src/kernel/pmm.zig +++ b/src/kernel/pmm.zig @@ -2,7 +2,7 @@ const is_test = @import("builtin").is_test; const std = @import("std"); const log = std.log.scoped(.pmm); const build_options = @import("build_options"); -const arch = @import("arch.zig").internals; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const MemProfile = @import("mem.zig").MemProfile; const testing = std.testing; const panic = @import("panic.zig").panic; diff --git a/src/kernel/scheduler.zig b/src/kernel/scheduler.zig index d05336e..62099fd 100644 --- a/src/kernel/scheduler.zig +++ b/src/kernel/scheduler.zig @@ -6,7 +6,7 @@ const log = std.log.scoped(.scheduler); const builtin = @import("builtin"); const is_test = builtin.is_test; const build_options = @import("build_options"); -const arch = @import("arch.zig").internals; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const panic = @import("panic.zig").panic; const task = @import("task.zig"); const vmm = @import("vmm.zig"); diff --git a/src/kernel/serial.zig b/src/kernel/serial.zig index 2ee6ea7..1b56f87 100644 --- a/src/kernel/serial.zig +++ b/src/kernel/serial.zig @@ -1,4 +1,6 @@ -const arch = @import("arch.zig").internals; +const builtin = @import("builtin"); +const is_test = builtin.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const build_options = @import("build_options"); pub const Serial = struct { diff --git a/src/kernel/syscalls.zig b/src/kernel/syscalls.zig index bb25793..02b5791 100644 --- a/src/kernel/syscalls.zig +++ b/src/kernel/syscalls.zig @@ -2,7 +2,9 @@ const std = @import("std"); const scheduler = @import("scheduler.zig"); const panic = @import("panic.zig").panic; const log = std.log.scoped(.syscalls); -const arch = @import("arch.zig").internals; +const builtin = @import("builtin"); +const is_test = builtin.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); /// A compilation of all errors that syscall handlers could return. pub const Error = error{OutOfMemory}; diff --git a/src/kernel/task.zig b/src/kernel/task.zig index fa45f88..426e0d0 100644 --- a/src/kernel/task.zig +++ b/src/kernel/task.zig @@ -4,7 +4,7 @@ const expectError = std.testing.expectError; const builtin = @import("builtin"); const is_test = builtin.is_test; const build_options = @import("build_options"); -const arch = @import("arch.zig").internals; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const panic = @import("panic.zig").panic; const vmm = @import("vmm.zig"); const pmm = @import("pmm.zig"); diff --git a/src/kernel/tty.zig b/src/kernel/tty.zig index 9a4cf54..0f2dc34 100644 --- a/src/kernel/tty.zig +++ b/src/kernel/tty.zig @@ -3,7 +3,9 @@ const fmt = std.fmt; const Allocator = std.mem.Allocator; const log = std.log.scoped(.tty); const build_options = @import("build_options"); -const arch = @import("arch.zig").internals; +const builtin = @import("builtin"); +const is_test = builtin.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const panic = @import("panic.zig").panic; /// The OutStream for the format function diff --git a/src/kernel/vmm.zig b/src/kernel/vmm.zig index 453fb0f..8bfda75 100644 --- a/src/kernel/vmm.zig +++ b/src/kernel/vmm.zig @@ -1,7 +1,5 @@ const build_options = @import("build_options"); const mock_path = build_options.mock_path; -const builtin = std.builtin; -const is_test = builtin.is_test; const std = @import("std"); const log = std.log.scoped(.vmm); const bitmap = @import("bitmap.zig"); @@ -9,7 +7,9 @@ const pmm = @import("pmm.zig"); const mem = @import("mem.zig"); const tty = @import("tty.zig"); const panic = @import("panic.zig").panic; -const arch = @import("arch.zig").internals; +const builtins = @import("builtin"); +const is_test = builtins.is_test; +const arch = if (is_test) @import("arch_mock") else @import("arch"); const Allocator = std.mem.Allocator; const assert = std.debug.assert; diff --git a/test/mock/kernel/arch_mock.zig b/test/mock/kernel/arch_mock.zig index a2b38b4..a08c9ef 100644 --- a/test/mock/kernel/arch_mock.zig +++ b/test/mock/kernel/arch_mock.zig @@ -1,18 +1,25 @@ const std = @import("std"); const builtin = @import("builtin"); -const Allocator = std.mem.Allocator; -const mem = @import("../../../src/kernel/mem.zig"); -const MemProfile = mem.MemProfile; +const pluto = @import("pluto"); +const arch = @import("arch"); const pci = @import("pci_mock.zig"); const gdt = @import("gdt_mock.zig"); const idt = @import("idt_mock.zig"); -const vmm = @import("../../../src/kernel/vmm.zig"); const paging = @import("paging_mock.zig"); -const Serial = @import("../../../src/kernel/serial.zig").Serial; -const TTY = @import("../../../src/kernel/tty.zig").TTY; -const Keyboard = @import("../../../src/kernel/keyboard.zig").Keyboard; -const task = @import("../../../src/kernel/task.zig"); -const x86_paging = @import("../../../src/kernel/arch/x86/paging.zig"); +pub const cmos_mock = @import("cmos_mock.zig"); +pub const vga_mock = @import("vga_mock.zig"); +pub const pic_mock = @import("pic_mock.zig"); +pub const idt_mock = @import("idt_mock.zig"); +pub const pci_mock = @import("pci_mock.zig"); +const x86_paging = arch.paging; +const vmm = pluto.vmm; +const mem = pluto.mem; +const Serial = pluto.serial.Serial; +const TTY = pluto.tty.TTY; +const Keyboard = pluto.keyboard.Keyboard; +const task = pluto.task; +const Allocator = std.mem.Allocator; +const MemProfile = mem.MemProfile; pub const Device = pci.PciDeviceInfo; pub const DateTime = struct { diff --git a/test/mock/kernel/gdt_mock.zig b/test/mock/kernel/gdt_mock.zig index 2c65f8b..414aa3b 100644 --- a/test/mock/kernel/gdt_mock.zig +++ b/test/mock/kernel/gdt_mock.zig @@ -1,6 +1,4 @@ -// Can't do: TODO: https://github.com/SamTebbs33/pluto/issues/77 -//const src_gdt = @import("arch").gdt; -const src_gdt = @import("../../../src/kernel/arch/x86/gdt.zig"); +const src_gdt = @import("arch").gdt; const mock_framework = @import("mock_framework.zig"); pub const initTest = mock_framework.initTest; diff --git a/test/mock/kernel/idt_mock.zig b/test/mock/kernel/idt_mock.zig index ed50fd2..b8abe14 100644 --- a/test/mock/kernel/idt_mock.zig +++ b/test/mock/kernel/idt_mock.zig @@ -1,4 +1,4 @@ -const src_idt = @import("../../../src/kernel/arch/x86/idt.zig"); +const src_idt = @import("arch").idt; const mock_framework = @import("mock_framework.zig"); pub const initTest = mock_framework.initTest;