Merge pull request #324 from Dawid33/arch-package

Putting arch file into a package.
This commit is contained in:
Sam Tebbs 2022-06-18 19:33:29 +01:00 committed by GitHub
commit 474073a695
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 123 additions and 84 deletions

View file

@ -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);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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");

View file

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

View file

@ -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;
// ----------

View file

@ -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");

View file

@ -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");

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

14
src/kernel/pluto.zig Normal file
View file

@ -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");

View file

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

View file

@ -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");

View file

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

View file

@ -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};

View file

@ -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");

View file

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

View file

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

View file

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

View file

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

View file

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