From 798b1c1d349013da82af979f744ea0ee36f8cd46 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 3 Sep 2019 14:13:26 -0400 Subject: [PATCH] Update to zig master and simplify build script --- azure-pipelines.yml | 5 +- build.zig | 230 +++++------------ src/kernel/arch/x86/gdt.zig | 61 +++-- src/kernel/arch/x86/idt.zig | 8 +- src/kernel/arch/x86/irq.zig | 6 +- src/kernel/arch/x86/isr.zig | 14 +- src/kernel/arch/x86/syscalls.zig | 21 +- src/kernel/kmain.zig | 7 + src/kernel/tty.zig | 427 +------------------------------ 9 files changed, 143 insertions(+), 636 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 63aa206..2ce5eba 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,7 +15,7 @@ pool: vmImage: 'ubuntu-latest' variables: - zig_version: 0.4.0 + zig_version: master steps: - script: | @@ -37,6 +37,5 @@ steps: displayName: 'Download qemu' - script: | - zig*/zig build -Drt-test=true - zig*/zig build test -Drt-test=true -Dzig-path=zig*/zig + zig*/zig build test -Drt-test=true displayName: 'Runtime tests' diff --git a/build.zig b/build.zig index 189d899..435fc96 100644 --- a/build.zig +++ b/build.zig @@ -1,187 +1,93 @@ -// Zig version: 0.4.0 - -const Builder = @import("std").build.Builder; -const Step = @import("std").build.Step; -const builtin = @import("builtin"); const std = @import("std"); -const os = std.os; -const ArrayList = std.ArrayList; -const warn = std.debug.warn; -const mem = std.mem; +const builtin = @import("builtin"); +const Builder = std.build.Builder; +const Step = std.build.Step; +const Target = std.build.Target; +const fs = std.fs; -var src_files: ArrayList([]const u8) = undefined; -var src_files_asm: ArrayList([]const u8) = undefined; - -fn concat(allocator: *std.mem.Allocator, str: []const u8, str2: []const u8) !std.Buffer { - var b = try std.Buffer.init(allocator, str); - try b.append(str2); - return b; -} - -pub fn build(b: *Builder) void { - src_files = ArrayList([]const u8).init(b.allocator); - src_files_asm = ArrayList([]const u8).init(b.allocator); +pub fn build(b: *Builder) !void { + const target = Target{ + .Cross = std.build.CrossTarget{ + .arch = .i386, + .os = .freestanding, + .abi = .gnu, + }, + }; const debug = b.option(bool, "debug", "build with debug symbols / make qemu wait for a debug connection") orelse false; - var build_path = b.option([]const u8, "build-path", "path to build to") orelse "bin"; - var src_path = b.option([]const u8, "source-path", "path to source") orelse "src"; - var target = b.option([]const u8, "target", "target to build/run for") orelse "x86"; const rt_test = b.option(bool, "rt-test", "enable/disable runtime testing") orelse false; - const builtin_target = if (mem.eql(u8, target, "x86")) builtin.Arch.i386 else unreachable; - const zig_path = b.option([]const u8, "zig-path", "the path to the zig binary to use for rt testing") orelse "/snap/bin/zig"; - b.makePath(build_path) catch unreachable; - var grub_path = concat(b.allocator, build_path, "/iso/boot/grub") catch unreachable; - var kern_path = concat(b.allocator, build_path, "/kernel") catch unreachable; - var a_path = concat(b.allocator, build_path, "/kernel/arch/") catch unreachable; - a_path = concat(b.allocator, a_path.toSlice(), target) catch unreachable; - b.makePath(grub_path.toSlice()) catch unreachable; - b.makePath(kern_path.toSlice()) catch unreachable; - b.makePath(a_path.toSlice()) catch unreachable; - b.makePath("zig-cache/kernel") catch unreachable; - - src_files.append("kernel/kmain") catch unreachable; - - // Add the assemblies - switch (builtin_target) { - builtin.Arch.i386 => { - src_files_asm.append("kernel/arch/x86/irq_asm") catch unreachable; - src_files_asm.append("kernel/arch/x86/isr_asm") catch unreachable; + const main_src = "src/kernel/kmain.zig"; + const exec = b.addExecutable("pluto", main_src); + exec.setMainPkgPath("."); + exec.addBuildOption(bool, "rt_test", rt_test); + exec.setLinkerScriptPath("link.ld"); + exec.setTheTarget(target); + switch (target.getArch()) { + .i386 => { + exec.addAssemblyFile("src/kernel/arch/x86/irq_asm.s"); + exec.addAssemblyFile("src/kernel/arch/x86/isr_asm.s"); }, else => {}, } - var arch_boot = concat(b.allocator, "kernel/arch/", target) catch unreachable; - arch_boot.append("/boot") catch unreachable; - src_files.append(arch_boot.toSlice()) catch unreachable; + const iso_path = fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "pluto.iso" }) catch unreachable; + const grub_build_path = fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "iso", "boot" }) catch unreachable; + const iso_dir_path = fs.path.join(b.allocator, [_][]const u8{ b.exe_dir, "iso" }) catch unreachable; - const iso_path = concat(b.allocator, build_path, "/pluto.iso") catch unreachable; - var objects = buildObjects(b, builtin_target, build_path, src_path); - var link_step = buildLink(b, builtin_target, build_path); - const iso_step = buildISO(b, build_path, iso_path.toSlice()); + const mkdir_cmd = b.addSystemCommand([_][]const u8{ "mkdir", "-p", fs.path.dirname(grub_build_path).? }); - for (objects.toSlice()) |obj| { - if (std.mem.eql(u8, obj.name, "kernel/kmain")) { - // Add build options here - obj.addBuildOption(bool, "rt_test", rt_test); - } - b.default_step.dependOn(&obj.step); - } - b.default_step.dependOn(link_step); - for (iso_step.toSlice()) |step| b.default_step.dependOn(step); + const grub_cmd = b.addSystemCommand([_][]const u8{ "cp", "-r", "grub", grub_build_path }); + grub_cmd.step.dependOn(&mkdir_cmd.step); - buildRun(b, builtin_target, build_path, iso_path.toSlice(), debug, rt_test); - buildDebug(b); - buildTest(b, src_path, rt_test, target, zig_path); -} + const cp_elf_cmd = b.addSystemCommand([_][]const u8{"cp"}); + cp_elf_cmd.addArtifactArg(exec); + cp_elf_cmd.addArg(try fs.path.join(b.allocator, [_][]const u8{ grub_build_path, "pluto.elf" })); + cp_elf_cmd.step.dependOn(&grub_cmd.step); + cp_elf_cmd.step.dependOn(&exec.step); -fn buildTest(b: *Builder, src_path: []const u8, rt_test: bool, target: []const u8, zig_path: []const u8) void { - const step = b.step("test", "Run tests"); - if (rt_test) { - const script = b.addSystemCommand([][]const u8{ "python3", "test/rt-test.py", target, zig_path}); - step.dependOn(&script.step); - } else { - const src_path2 = concat(b.allocator, src_path, "/") catch unreachable; - for (src_files.toSlice()) |file| { - var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable; - file_src.append(".zig") catch unreachable; - const tst = b.addTest(file_src.toSlice()); - tst.setMainPkgPath("."); - step.dependOn(&tst.step); - } - } -} + const iso_cmd = b.addSystemCommand([_][]const u8{ "grub-mkrescue", "-o", iso_path, iso_dir_path }); + iso_cmd.step.dependOn(&cp_elf_cmd.step); + b.default_step.dependOn(&iso_cmd.step); -fn buildDebug(b: *Builder) void { - const step = b.step("debug", "Debug with gdb"); - const cmd = b.addSystemCommand([][]const u8{ - "gdb", - "-ex", - "symbol-file bin/iso/boot/pluto.elf", - "-ex", - "target remote localhost:1234", - }); - step.dependOn(&cmd.step); -} - -fn buildRun(b: *Builder, target: builtin.Arch, build_path: []const u8, iso_path: []const u8, debug: bool, rt_test: bool) void { - const step = b.step("run", "Run with qemu"); - const qemu = if (target == builtin.Arch.i386) "qemu-system-i386" else unreachable; - var qemu_flags = ArrayList([]const u8).init(b.allocator); - qemu_flags.appendSlice([][]const u8{ - qemu, + const run_step = b.step("run", "Run with qemu"); + const qemu_bin = if (target.getArch() == builtin.Arch.i386) "qemu-system-i386" else unreachable; + const qemu_cmd = b.addSystemCommand([_][]const u8{ + qemu_bin, "-cdrom", iso_path, "-boot", "d", "-serial", "stdio", - }) catch unreachable; + }); if (debug) - qemu_flags.appendSlice([][]const u8{ - "-s", - "-S", - }) catch unreachable; + qemu_cmd.addArgs([_][]const u8{ "-s", "-S" }); if (rt_test) - qemu_flags.appendSlice([][]const u8{ - "-display", - "none" - }) catch unreachable; - const cmd = b.addSystemCommand(qemu_flags.toSlice()); - step.dependOn(&cmd.step); -} + qemu_cmd.addArgs([_][]const u8{ "-display", "none" }); + run_step.dependOn(&qemu_cmd.step); + qemu_cmd.step.dependOn(&iso_cmd.step); -fn buildISO(b: *Builder, build_path: []const u8, iso_path: []const u8) ArrayList(*Step) { - const grub_build_path = concat(b.allocator, build_path, "/iso/boot/") catch unreachable; - const iso_dir_path = concat(b.allocator, build_path, "/iso") catch unreachable; - const grub_cmd = b.addSystemCommand([][]const u8{ "cp", "-r", "grub", grub_build_path.toSlice() }); - const iso_cmd = b.addSystemCommand([][]const u8{ "grub-mkrescue", "-o", iso_path, iso_dir_path.toSlice() }); - var steps = ArrayList(*Step).init(b.allocator); - steps.append(&grub_cmd.step) catch unreachable; - steps.append(&iso_cmd.step) catch unreachable; - return steps; -} + const test_step = b.step("test", "Run tests"); + if (rt_test) { + const script = b.addSystemCommand([_][]const u8{ "python3", "test/rt-test.py", "x86", b.zig_exe }); + test_step.dependOn(&script.step); + } else { + const unit_tests = b.addTest(main_src); + unit_tests.setMainPkgPath("."); + unit_tests.addBuildOption(bool, "rt_test", rt_test); + test_step.dependOn(&unit_tests.step); + } -fn buildLink(b: *Builder, target: builtin.Arch, build_path: []const u8) *Step { - const exec = b.addExecutable("pluto.elf", null); - const elf_path = concat(b.allocator, build_path, "/iso/boot") catch unreachable; - exec.setOutputDir(elf_path.toSlice()); - exec.setLinkerScriptPath("link.ld"); - exec.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu); - for (src_files.toSlice()) |file| { - var file_obj = concat(b.allocator, build_path, "/") catch unreachable; - file_obj.append(file) catch unreachable; - file_obj.append(".o") catch unreachable; - exec.addObjectFile(file_obj.toSlice()); - exec.setMainPkgPath("."); - } - for (src_files_asm.toSlice()) |file| { - var file_obj = concat(b.allocator, build_path, "/") catch unreachable; - file_obj.append(file) catch unreachable; - file_obj.append(".o") catch unreachable; - exec.addObjectFile(file_obj.toSlice()); - } - return &exec.step; -} - -fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_path: []const u8) ArrayList(*std.build.LibExeObjStep) { - var objects = ArrayList(*std.build.LibExeObjStep).init(b.allocator); - const src_path2 = concat(b.allocator, src_path, "/") catch unreachable; - for (src_files.toSlice()) |file| { - var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable; - file_src.append(".zig") catch unreachable; - const obj = b.addObject(file, file_src.toSlice()); - obj.setMainPkgPath("."); - obj.setOutputDir(build_path); - obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu); - objects.append(obj) catch unreachable; - } - for (src_files_asm.toSlice()) |file| { - var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable; - file_src.append(".s") catch unreachable; - const obj = b.addAssemble(file, file_src.toSlice()); - obj.setOutputDir(build_path); - obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu); - objects.append(obj) catch unreachable; - } - return objects; + const debug_step = b.step("debug", "Debug with gdb"); + const debug_cmd = b.addSystemCommand([_][]const u8{ + "gdb", + "-ex", + "symbol-file", + }); + debug_cmd.addArtifactArg(exec); + debug_cmd.addArgs([_][]const u8{ + "-ex", + "target remote localhost:1234", + }); + debug_step.dependOn(&debug_cmd.step); } diff --git a/src/kernel/arch/x86/gdt.zig b/src/kernel/arch/x86/gdt.zig index 2875be0..59dd024 100644 --- a/src/kernel/arch/x86/gdt.zig +++ b/src/kernel/arch/x86/gdt.zig @@ -9,58 +9,56 @@ const TABLE_SIZE: u16 = @sizeOf(GdtEntry) * NUMBER_OF_ENTRIES - 1; // The indexes into the GDT where each segment resides. /// The index of the NULL GDT entry. -const NULL_INDEX: u16 = 0x00; +const NULL_INDEX: u16 = 0x00; /// The index of the kernel code GDT entry. -const KERNEL_CODE_INDEX: u16 = 0x01; +const KERNEL_CODE_INDEX: u16 = 0x01; /// The index of the kernel data GDT entry. -const KERNEL_DATA_INDEX: u16 = 0x02; +const KERNEL_DATA_INDEX: u16 = 0x02; /// The index of the user code GDT entry. -const USER_CODE_INDEX: u16 = 0x03; +const USER_CODE_INDEX: u16 = 0x03; /// The index of the user data GDT entry. -const USER_DATA_INDEX: u16 = 0x04; +const USER_DATA_INDEX: u16 = 0x04; /// The index of the task state segment GDT entry. -const TSS_INDEX: u16 = 0x05; - +const TSS_INDEX: u16 = 0x05; // The offsets into the GDT where each segment resides. /// The offset of the NULL GDT entry. -pub const NULL_OFFSET: u16 = 0x00; +pub const NULL_OFFSET: u16 = 0x00; /// The offset of the kernel code GDT entry. -pub const KERNEL_CODE_OFFSET: u16 = 0x08; +pub const KERNEL_CODE_OFFSET: u16 = 0x08; /// The offset of the kernel data GDT entry. -pub const KERNEL_DATA_OFFSET: u16 = 0x10; +pub const KERNEL_DATA_OFFSET: u16 = 0x10; /// The offset of the user code GDT entry. -pub const USER_CODE_OFFSET: u16 = 0x18; +pub const USER_CODE_OFFSET: u16 = 0x18; /// The offset of the user data GDT entry. -pub const USER_DATA_OFFSET: u16 = 0x20; +pub const USER_DATA_OFFSET: u16 = 0x20; /// The offset of the TTS GDT entry. -pub const TSS_OFFSET: u16 = 0x28; +pub const TSS_OFFSET: u16 = 0x28; // The access bits -const ACCESSED_BIT = 0x01; // 00000001 -const WRITABLE_BIT = 0x02; // 00000010 -const DIRECTION_CONFORMING_BIT = 0x04; // 00000100 -const EXECUTABLE_BIT = 0x08; // 00001000 -const DESCRIPTOR_BIT = 0x10; // 00010000 +const ACCESSED_BIT = 0x01; // 00000001 +const WRITABLE_BIT = 0x02; // 00000010 +const DIRECTION_CONFORMING_BIT = 0x04; // 00000100 +const EXECUTABLE_BIT = 0x08; // 00001000 +const DESCRIPTOR_BIT = 0x10; // 00010000 -const PRIVILEGE_RING_0 = 0x00; // 00000000 -const PRIVILEGE_RING_1 = 0x20; // 00100000 -const PRIVILEGE_RING_2 = 0x40; // 01000000 -const PRIVILEGE_RING_3 = 0x60; // 01100000 - -const PRESENT_BIT = 0x80; // 10000000 +const PRIVILEGE_RING_0 = 0x00; // 00000000 +const PRIVILEGE_RING_1 = 0x20; // 00100000 +const PRIVILEGE_RING_2 = 0x40; // 01000000 +const PRIVILEGE_RING_3 = 0x60; // 01100000 +const PRESENT_BIT = 0x80; // 10000000 const KERNEL_SEGMENT = PRESENT_BIT | PRIVILEGE_RING_0 | DESCRIPTOR_BIT; const USER_SEGMENT = PRESENT_BIT | PRIVILEGE_RING_3 | DESCRIPTOR_BIT; @@ -70,11 +68,10 @@ const DATA_SEGMENT = WRITABLE_BIT; const TSS_SEGMENT = PRESENT_BIT | EXECUTABLE_BIT | ACCESSED_BIT; - // The flag bits -const IS_64_BIT = 0x02; // 0010 -const IS_32_BIT = 0x04; // 0100 -const IS_LIMIT_4K_BIT = 0x08; // 1000 +const IS_64_BIT = 0x02; // 0010 +const IS_32_BIT = 0x04; // 0100 +const IS_LIMIT_4K_BIT = 0x08; // 1000 /// The structure that contains all the information that each GDT entry needs. const GdtEntry = packed struct { @@ -213,7 +210,7 @@ const TtsEntry = packed struct { /// A new GDT entry with the give access and flag bits set with the base at 0x00000000 and limit at 0xFFFFF. /// fn makeEntry(base: u32, limit: u20, access: u8, flags: u4) GdtEntry { - return GdtEntry { + return GdtEntry{ .limit_low = @truncate(u16, limit), .base_low = @truncate(u24, base), .access = access, @@ -224,7 +221,7 @@ fn makeEntry(base: u32, limit: u20, access: u8, flags: u4) GdtEntry { } /// The GDT entry table of NUMBER_OF_ENTRIES entries. -var gdt_entries: [NUMBER_OF_ENTRIES]GdtEntry = []GdtEntry { +var gdt_entries: [NUMBER_OF_ENTRIES]GdtEntry = [_]GdtEntry{ // Null descriptor makeEntry(0, 0, 0, 0), @@ -246,13 +243,13 @@ var gdt_entries: [NUMBER_OF_ENTRIES]GdtEntry = []GdtEntry { /// The GDT pointer that the CPU is loaded with that contains the base address of the GDT and the /// size. -const gdt_ptr: GdtPtr = GdtPtr { +const gdt_ptr: GdtPtr = GdtPtr{ .limit = TABLE_SIZE, .base = &gdt_entries[0], }; /// The task state segment entry. -var tss: TtsEntry = TtsEntry { +var tss: TtsEntry = TtsEntry{ .prev_tss = 0, .esp0 = undefined, .ss0 = KERNEL_DATA_OFFSET, diff --git a/src/kernel/arch/x86/idt.zig b/src/kernel/arch/x86/idt.zig index 8b56a3c..3ea6193 100644 --- a/src/kernel/arch/x86/idt.zig +++ b/src/kernel/arch/x86/idt.zig @@ -58,11 +58,11 @@ pub const IdtPtr = packed struct { }; /// The IDT entry table of NUMBER_OF_ENTRIES entries. -var idt: [NUMBER_OF_ENTRIES]IdtEntry = []IdtEntry{makeEntry(0, 0, 0, 0, 0)} ** NUMBER_OF_ENTRIES; +var idt: [NUMBER_OF_ENTRIES]IdtEntry = [_]IdtEntry{makeEntry(0, 0, 0, 0, 0)} ** NUMBER_OF_ENTRIES; /// The IDT pointer that the CPU is loaded with that contains the base address of the IDT and the /// size. -const idt_ptr: IdtPtr = IdtPtr { +const idt_ptr: IdtPtr = IdtPtr{ .limit = TABLE_SIZE, .base = &idt[0], }; @@ -83,7 +83,7 @@ const idt_ptr: IdtPtr = IdtPtr { /// A new IDT entry. /// fn makeEntry(base: u32, selector: u16, gate_type: u4, privilege: u2, present: u1) IdtEntry { - return IdtEntry { + return IdtEntry{ .base_low = @truncate(u16, base), .selector = selector, .zero = 0, @@ -102,7 +102,7 @@ fn makeEntry(base: u32, selector: u16, gate_type: u4, privilege: u2, present: u1 /// IN index: u8 - The interrupt number to close. /// IN base: extern fn()void - The function handler for the interrupt. /// -pub fn openInterruptGate(index: u8, base: extern fn()void) void { +pub fn openInterruptGate(index: u8, base: extern fn () void) void { idt[index] = makeEntry(@ptrToInt(base), gdt.KERNEL_CODE_OFFSET, INTERRUPT_GATE_32BIT, PRIVILEGE_RING_0, 1); } diff --git a/src/kernel/arch/x86/irq.zig b/src/kernel/arch/x86/irq.zig index 3fc74ae..5dbdf67 100644 --- a/src/kernel/arch/x86/irq.zig +++ b/src/kernel/arch/x86/irq.zig @@ -28,7 +28,7 @@ extern fn irq14() void; extern fn irq15() void; /// The list of IRQ handlers initialised to unhandled. -var irq_handlers: [NUMBER_OF_ENTRIES]fn(*arch.InterruptContext)void = []fn(*arch.InterruptContext)void {unhandled} ** NUMBER_OF_ENTRIES; +var irq_handlers: [NUMBER_OF_ENTRIES]fn (*arch.InterruptContext) void = [_]fn (*arch.InterruptContext) void{unhandled} ** NUMBER_OF_ENTRIES; /// /// A dummy handler that will make a call to panic as it is a unhandled interrupt. @@ -66,7 +66,7 @@ export fn irqHandler(context: *arch.InterruptContext) void { /// Arguments: /// IN irq_num: u16 - The IRQ number to register. /// -pub fn registerIrq(irq_num: u16, handler: fn(*arch.InterruptContext)void) void { +pub fn registerIrq(irq_num: u16, handler: fn (*arch.InterruptContext) void) void { irq_handlers[irq_num] = handler; pic.clearMask(irq_num); } @@ -108,4 +108,4 @@ pub fn init() void { idt.openInterruptGate(45, irq13); idt.openInterruptGate(46, irq14); idt.openInterruptGate(47, irq15); -} \ No newline at end of file +} diff --git a/src/kernel/arch/x86/isr.zig b/src/kernel/arch/x86/isr.zig index 3d6e38c..e4b4ea9 100644 --- a/src/kernel/arch/x86/isr.zig +++ b/src/kernel/arch/x86/isr.zig @@ -43,7 +43,7 @@ extern fn isr31() void; extern fn isr128() void; /// The exception messaged that is printed when a exception happens -const exception_msg: [NUMBER_OF_ENTRIES][]const u8 = [NUMBER_OF_ENTRIES][]const u8 { +const exception_msg: [NUMBER_OF_ENTRIES][]const u8 = [NUMBER_OF_ENTRIES][]const u8{ "Divide By Zero", "Single Step (Debugger)", "Non Maskable Interrupt", @@ -75,20 +75,18 @@ const exception_msg: [NUMBER_OF_ENTRIES][]const u8 = [NUMBER_OF_ENTRIES][]const "Reserved", "Reserved", "Security", - "Reserved" + "Reserved", }; /// Errors that an isr function can return -pub const IsrError = error { - UnrecognisedIsr -}; +pub const IsrError = error{UnrecognisedIsr}; /// An isr handler. Takes an interrupt context and returns void. /// Should finish quickly to avoid delaying further interrupts and the previously running code -pub const IsrHandler = fn(*arch.InterruptContext)void; +pub const IsrHandler = fn (*arch.InterruptContext) void; // The of exception handlers initialised to unhandled. -var isr_handlers: [NUMBER_OF_ENTRIES]IsrHandler = []IsrHandler{unhandled} ** NUMBER_OF_ENTRIES; +var isr_handlers: [NUMBER_OF_ENTRIES]IsrHandler = [_]IsrHandler{unhandled} ** NUMBER_OF_ENTRIES; var syscall_handler: IsrHandler = unhandled; /// @@ -141,7 +139,7 @@ export fn isrHandler(context: *arch.InterruptContext) void { /// Errors: /// IsrError.UnrecognisedIsr - If `isr_num` is invalid (see isValidIsr) /// -pub fn registerIsr(isr_num: u16, handler: fn(*arch.InterruptContext)void) !void { +pub fn registerIsr(isr_num: u16, handler: fn (*arch.InterruptContext) void) !void { if (isr_num == syscalls.INTERRUPT) { syscall_handler = handler; } else if (isValidIsr(isr_num)) { diff --git a/src/kernel/arch/x86/syscalls.zig b/src/kernel/arch/x86/syscalls.zig index 429e574..a0c6736 100644 --- a/src/kernel/arch/x86/syscalls.zig +++ b/src/kernel/arch/x86/syscalls.zig @@ -14,13 +14,13 @@ pub const NUM_HANDLERS: u16 = 256; pub const SyscallHandler = fn (ctx: *arch.InterruptContext) u32; /// Errors that syscall utility functions can throw -pub const SyscallError = error { +pub const SyscallError = error{ SyscallExists, - InvalidSyscall + InvalidSyscall, }; /// The array of registered syscalls -var handlers: [NUM_HANDLERS]?SyscallHandler = []?SyscallHandler{null} ** NUM_HANDLERS; +var handlers: [NUM_HANDLERS]?SyscallHandler = [_]?SyscallHandler{null} ** NUM_HANDLERS; /// /// Returns true if the syscall is valid, else false. @@ -84,7 +84,7 @@ inline fn syscall0(syscall: u32) u32 { return asm volatile ( \\int $0x80 : [ret] "={eax}" (-> u32) - : [syscall] "{eax}" (syscall), + : [syscall] "{eax}" (syscall) ); } @@ -100,7 +100,7 @@ inline fn syscall1(syscall: u32, arg: u32) u32 { \\int $0x80 : [ret] "={eax}" (-> u32) : [syscall] "{eax}" (syscall), - [arg1] "{ebx}" (arg), + [arg1] "{ebx}" (arg) ); } @@ -118,7 +118,7 @@ inline fn syscall2(syscall: u32, arg1: u32, arg2: u32) u32 { : [ret] "={eax}" (-> u32) : [syscall] "{eax}" (syscall), [arg1] "{ebx}" (arg1), - [arg2] "{ecx}" (arg2), + [arg2] "{ecx}" (arg2) ); } @@ -138,7 +138,7 @@ inline fn syscall3(syscall: u32, arg1: u32, arg2: u32, arg3: u32) u32 { : [syscall] "{eax}" (syscall), [arg1] "{ebx}" (arg1), [arg2] "{ecx}" (arg2), - [arg3] "{edx}" (arg3), + [arg3] "{edx}" (arg3) ); } @@ -160,7 +160,7 @@ inline fn syscall4(syscall: u32, arg1: u32, arg2: u32, arg3: u32, arg4: u32) u32 [arg1] "{ebx}" (arg1), [arg2] "{ecx}" (arg2), [arg3] "{edx}" (arg3), - [arg4] "{esi}" (arg4), + [arg4] "{esi}" (arg4) ); } @@ -184,7 +184,7 @@ inline fn syscall5(syscall: u32, arg1: u32, arg2: u32, arg3: u32, arg4: u32, arg [arg2] "{ecx}" (arg2), [arg3] "{edx}" (arg3), [arg4] "{esi}" (arg4), - [arg5] "{edi}" (arg5), + [arg5] "{edi}" (arg5) ); } @@ -202,7 +202,7 @@ inline fn syscallArg(ctx: *arch.InterruptContext, comptime arg_idx: u32) u32 { 2 => ctx.edx, 3 => ctx.esi, 4 => ctx.edi, - else => @compileError("Arg index must be between 0 and 4") + else => @compileError("Arg index must be between 0 and 4"), }; } @@ -217,7 +217,6 @@ pub fn init(comptime options: type) void { } /// Tests - var testInt: u32 = 0; fn testHandler0(ctx: *arch.InterruptContext) u32 { diff --git a/src/kernel/kmain.zig b/src/kernel/kmain.zig index e276f3e..9d05d46 100644 --- a/src/kernel/kmain.zig +++ b/src/kernel/kmain.zig @@ -11,6 +11,13 @@ const serial = @import("serial.zig"); const mem = @import("mem.zig"); const options = @import("build_options"); +comptime { + switch (builtin.arch) { + .i386 => _ = @import("arch/x86/boot.zig"), + else => {}, + } +} + // Need to import this as we need the panic to be in the root source file, or zig will just use the // builtin panic and just loop, which is what we don't want const panic_root = @import("panic.zig"); diff --git a/src/kernel/tty.zig b/src/kernel/tty.zig index 3ebaceb..f11c842 100644 --- a/src/kernel/tty.zig +++ b/src/kernel/tty.zig @@ -29,9 +29,7 @@ const START_OF_DISPLAYABLE_REGION: u16 = vga.WIDTH * ROW_MIN; /// The total number of VGA elements (or characters) the video buffer can display const VIDEO_BUFFER_SIZE: u16 = vga.WIDTH * vga.HEIGHT; -const PrintError = error { - OutOfBounds, -}; +const PrintError = error{OutOfBounds}; /// The current x position of the cursor. var column: u8 = 0; @@ -55,7 +53,7 @@ var pages: [TOTAL_NUM_PAGES][TOTAL_CHAR_ON_PAGE]u16 = init: { var p: [TOTAL_NUM_PAGES][TOTAL_CHAR_ON_PAGE]u16 = undefined; for (p) |*page| { - page.* = []u16{0} ** TOTAL_CHAR_ON_PAGE; + page.* = [_]u16{0} ** TOTAL_CHAR_ON_PAGE; } break :init p; @@ -82,8 +80,9 @@ var page_index: u8 = 0; fn videoCopy(video_buf_offset: u16, data: []const u16, size: u16) PrintError!void { // Secure programming ;) if (video_buf_offset >= video_buffer.len and - size > video_buffer.len - video_buf_offset and - size > data.len) { + size > video_buffer.len - video_buf_offset and + size > data.len) + { return PrintError.OutOfBounds; } @@ -357,7 +356,7 @@ fn putChar(char: u8) PrintError!void { row -= 1; } } else { - column -= 1; + column -= 1; } }, else => { @@ -496,7 +495,7 @@ pub fn pageDown() void { page_index -= 1; videoCopy(START_OF_DISPLAYABLE_REGION, pages[page_index][0..TOTAL_CHAR_ON_PAGE], TOTAL_CHAR_ON_PAGE) catch unreachable; displayPageNumber(); - if(page_index == 0) { + if (page_index == 0) { vga.enableCursor(); updateCursor(); } else { @@ -608,7 +607,7 @@ pub fn init() void { // Copy rows 7 down to make room for logo // If there isn't enough room, only take the bottom rows var row_offset: u16 = 0; - if(vga.HEIGHT - 1 - row < ROW_MIN) { + if (vga.HEIGHT - 1 - row < ROW_MIN) { row_offset = u16(ROW_MIN - (vga.HEIGHT - 1 - row)); } @@ -761,31 +760,21 @@ fn defaultAllTesting(p_i: u8, r: u8, c: u8) void { } test "updateCursor" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // updateCursor(); - - // // Post test // defaultAllTesting(0, 0, 0); - - // // Tear down // @@ -797,27 +786,19 @@ test "getCursor all" { } test "displayPageNumber column and row is reset" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 5; row = 6; defaultAllTesting(0, 6, 5); - - // // Call function // displayPageNumber(); - - // // Post test // @@ -835,8 +816,6 @@ test "displayPageNumber column and row is reset" { expectEqual(blank, b); } } - - // // Tear down // @@ -844,31 +823,21 @@ test "displayPageNumber column and row is reset" { } test "putEntryAt out of bounds" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // expectError(PrintError.OutOfBounds, putEntryAt('A', 100, 100)); - - // // Post test // defaultAllTesting(0, 0, 0); - - // // Tear down (resets globals) // @@ -876,19 +845,13 @@ test "putEntryAt out of bounds" { } test "putEntryAt not in displayable region" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // @@ -896,8 +859,6 @@ test "putEntryAt not in displayable region" { const y: u8 = 0; const char: u8 = 'A'; putEntryAt(char, x, y) catch unreachable; - - // // Post test // @@ -911,8 +872,6 @@ test "putEntryAt not in displayable region" { expectEqual(vga.entry(0, test_colour), b); } } - - // // Tear down (resets globals) // @@ -920,19 +879,13 @@ test "putEntryAt not in displayable region" { } test "putEntryAt in displayable region page_index is 0" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // @@ -940,8 +893,6 @@ test "putEntryAt in displayable region page_index is 0" { const y: u16 = ROW_MIN; const char: u8 = 'A'; putEntryAt(char, x, y) catch unreachable; - - // // Post test // @@ -963,8 +914,6 @@ test "putEntryAt in displayable region page_index is 0" { expectEqual(vga.entry(0, test_colour), b); } } - - // // Tear down (resets globals) // @@ -972,10 +921,8 @@ test "putEntryAt in displayable region page_index is 0" { } test "putEntryAt in displayable region page_index is not 0" { - // // Set up // - setVideoBufferBlankPages(); // Fill the 1'nd page (index 1) will all 1's @@ -991,8 +938,6 @@ test "putEntryAt in displayable region page_index is not 0" { } page_index = 1; - - // // Pre testing // @@ -1008,8 +953,6 @@ test "putEntryAt in displayable region page_index is not 0" { } } } - - // // Call function // @@ -1017,8 +960,6 @@ test "putEntryAt in displayable region page_index is not 0" { const y: u16 = ROW_MIN; const char: u8 = 'A'; putEntryAt(char, x, y) catch unreachable; - - // // Post test // @@ -1050,8 +991,6 @@ test "putEntryAt in displayable region page_index is not 0" { expectEqual(ones, b); } } - - // // Tear down // @@ -1059,37 +998,27 @@ test "putEntryAt in displayable region page_index is not 0" { } test "pagesMoveRowsUp out of bounds" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // const rows_to_move: u16 = ROW_TOTAL + 1; expectError(PrintError.OutOfBounds, pagesMoveRowsUp(rows_to_move)); - - // // Post test // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Tear down // @@ -1097,37 +1026,27 @@ test "pagesMoveRowsUp out of bounds" { } test "pagesMoveRowsUp 0 rows" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // const rows_to_move: u16 = 0; pagesMoveRowsUp(rows_to_move) catch unreachable; - - // // Post test // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Tear down // @@ -1135,29 +1054,21 @@ test "pagesMoveRowsUp 0 rows" { } test "pagesMoveRowsUp 1 rows" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // const rows_to_move: u16 = 1; pagesMoveRowsUp(rows_to_move) catch unreachable; - - // // Post test // @@ -1182,8 +1093,6 @@ test "pagesMoveRowsUp 1 rows" { } } } - - // // Tear down // @@ -1191,29 +1100,21 @@ test "pagesMoveRowsUp 1 rows" { } test "pagesMoveRowsUp ROW_TOTAL - 1 rows" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // const rows_to_move: u16 = ROW_TOTAL - 1; pagesMoveRowsUp(rows_to_move) catch unreachable; - - // // Post test // @@ -1238,8 +1139,6 @@ test "pagesMoveRowsUp ROW_TOTAL - 1 rows" { } } } - - // // Tear down // @@ -1247,29 +1146,21 @@ test "pagesMoveRowsUp ROW_TOTAL - 1 rows" { } test "pagesMoveRowsUp ROW_TOTAL rows" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // const rows_to_move: u16 = ROW_TOTAL; pagesMoveRowsUp(rows_to_move) catch unreachable; - - // // Post test // @@ -1288,8 +1179,6 @@ test "pagesMoveRowsUp ROW_TOTAL rows" { } } } - - // // Tear down // @@ -1297,36 +1186,26 @@ test "pagesMoveRowsUp ROW_TOTAL rows" { } test "scroll row is less then max height" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // scroll(); - - // // Post test // defaultVariablesTesting(0, 0, 0); defaultVideoBufferTesting(); incrementingPagesTesting(); - - // // Tear down // @@ -1334,32 +1213,24 @@ test "scroll row is less then max height" { } test "scroll row is equal to height" { - // // Set up // - setVideoBufferIncrementingBlankPages(); setPagesIncrementing(); const row_test: u16 = vga.HEIGHT; row = row_test; - - // // Pre testing // defaultVariablesTesting(0, row_test, 0); incrementingPagesTesting(); incrementingVideoBufferTesting(); - - // // Call function // // Rows move up one scroll(); - - // // Post test // @@ -1394,8 +1265,6 @@ test "scroll row is equal to height" { expectEqual(k + to_add, video_buffer[k]); } } - - // // Tear down // @@ -1403,32 +1272,24 @@ test "scroll row is equal to height" { } test "scroll row is more than height" { - // // Set up // - setVideoBufferIncrementingBlankPages(); setPagesIncrementing(); const row_test: u16 = vga.HEIGHT + 5; row = row_test; - - // // Pre testing // defaultVariablesTesting(0, row_test, 0); incrementingPagesTesting(); incrementingVideoBufferTesting(); - - // // Call function // // Rows move up 5 scroll(); - - // // Post test // @@ -1463,8 +1324,6 @@ test "scroll row is more than height" { expectEqual(k + to_add, video_buffer[k]); } } - - // // Tear down // @@ -1472,33 +1331,23 @@ test "scroll row is more than height" { } test "putChar new line within screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 5; row = 5; defaultAllTesting(0, 5, 5); - - // // Call function // putChar('\n') catch unreachable; - - // // Post test // defaultAllTesting(0, 6, 0); - - // // Tear down // @@ -1506,33 +1355,23 @@ test "putChar new line within screen" { } test "putChar new line outside screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 5; row = vga.HEIGHT - 1; defaultAllTesting(0, vga.HEIGHT - 1, 5); - - // // Call function // putChar('\n') catch unreachable; - - // // Post test // defaultAllTesting(0, vga.HEIGHT - 1, 0); - - // // Tear down // @@ -1540,33 +1379,23 @@ test "putChar new line outside screen" { } test "putChar tab within line" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 5; row = 6; defaultAllTesting(0, 6, 5); - - // // Call function // putChar('\t') catch unreachable; - - // // Post test // defaultAllTesting(0, 6, 9); - - // // Tear down // @@ -1574,33 +1403,23 @@ test "putChar tab within line" { } test "putChar tab end of line" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = vga.WIDTH - 1; row = 6; defaultAllTesting(0, 6, vga.WIDTH - 1); - - // // Call function // putChar('\t') catch unreachable; - - // // Post test // defaultAllTesting(0, 7, 3); - - // // Tear down // @@ -1608,33 +1427,23 @@ test "putChar tab end of line" { } test "putChar tab end of screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = vga.WIDTH - 1; row = vga.HEIGHT - 1; defaultAllTesting(0, vga.HEIGHT - 1, vga.WIDTH - 1); - - // // Call function // putChar('\t') catch unreachable; - - // // Post test // defaultAllTesting(0, vga.HEIGHT - 1, 3); - - // // Tear down // @@ -1642,33 +1451,23 @@ test "putChar tab end of screen" { } test "putChar line feed" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = vga.WIDTH - 1; row = vga.HEIGHT - 1; defaultAllTesting(0, vga.HEIGHT - 1, vga.WIDTH - 1); - - // // Call function // putChar('\r') catch unreachable; - - // // Post test // defaultAllTesting(0, vga.HEIGHT - 1, 0); - - // // Tear down // @@ -1676,31 +1475,21 @@ test "putChar line feed" { } test "putChar back char top left of screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // putChar('\x08') catch unreachable; - - // // Post test // defaultAllTesting(0, 0, 0); - - // // Tear down // @@ -1708,32 +1497,22 @@ test "putChar back char top left of screen" { } test "putChar back char top row" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 8; defaultAllTesting(0, 0, 8); - - // // Call function // putChar('\x08') catch unreachable; - - // // Post test // defaultAllTesting(0, 0, 7); - - // // Tear down // @@ -1741,32 +1520,22 @@ test "putChar back char top row" { } test "putChar back char beginning of row" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // row = 1; defaultAllTesting(0, 1, 0); - - // // Call function // putChar('\x08') catch unreachable; - - // // Post test // defaultAllTesting(0, 0, vga.WIDTH - 1); - - // // Tear down // @@ -1774,25 +1543,17 @@ test "putChar back char beginning of row" { } test "putChar any char in row" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // putChar('A') catch unreachable; - - // // Post test // @@ -1807,8 +1568,6 @@ test "putChar any char in row" { expectEqual(blank, video_buffer[k]); } } - - // // Tear down // @@ -1816,26 +1575,18 @@ test "putChar any char in row" { } test "putChar any char end of row" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = vga.WIDTH - 1; defaultAllTesting(0, 0, vga.WIDTH - 1); - - // // Call function // putChar('A') catch unreachable; - - // // Post test // @@ -1850,8 +1601,6 @@ test "putChar any char end of row" { expectEqual(blank, video_buffer[k]); } } - - // // Tear down // @@ -1859,41 +1608,32 @@ test "putChar any char end of row" { } test "putChar any char end of screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // row = vga.HEIGHT - 1; column = vga.WIDTH - 1; defaultAllTesting(0, vga.HEIGHT - 1, vga.WIDTH - 1); - - // // Call function // putChar('A') catch unreachable; - - // // Post test // defaultVariablesTesting(0, vga.HEIGHT - 1, 0); for (pages) |page, i| { - for (page) |c, j| { - if ((i == 0) and (j == TOTAL_CHAR_ON_PAGE - vga.WIDTH - 1)) { - expectEqual(vga.entry('A', colour), c); - } else { - expectEqual(blank, c); - } + for (page) |c, j| { + if ((i == 0) and (j == TOTAL_CHAR_ON_PAGE - vga.WIDTH - 1)) { + expectEqual(vga.entry('A', colour), c); + } else { + expectEqual(blank, c); } } - + } var k: u16 = 0; while (k < VIDEO_BUFFER_SIZE) : (k += 1) { @@ -1903,8 +1643,6 @@ test "putChar any char end of screen" { expectEqual(blank, video_buffer[k]); } } - - // // Tear down // @@ -1912,13 +1650,9 @@ test "putChar any char end of screen" { } test "printLogo all" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // @@ -1926,14 +1660,10 @@ test "printLogo all" { row = ROW_MIN; defaultAllTesting(0, ROW_MIN, 0); - - // // Call function // printLogo(); - - // // Post test // @@ -1949,8 +1679,6 @@ test "printLogo all" { expectEqual(blank, video_buffer[k]); } } - - // // Tear down // @@ -1958,14 +1686,10 @@ test "printLogo all" { } test "pageUp top page" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // @@ -1974,22 +1698,16 @@ test "pageUp top page" { defaultVariablesTesting(TOTAL_NUM_PAGES - 1, 0, 0); incrementingPagesTesting(); defaultVideoBufferTesting(); - - // // Call function // pageUp(); - - // // Post test // defaultVariablesTesting(TOTAL_NUM_PAGES - 1, 0, 0); incrementingPagesTesting(); defaultVideoBufferTesting(); - - // // Tear down // @@ -1997,28 +1715,20 @@ test "pageUp top page" { } test "pageUp bottom page" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); incrementingPagesTesting(); defaultVideoBufferTesting(); - - // // Call function // pageUp(); - - // // Post test // @@ -2038,8 +1748,6 @@ test "pageUp bottom page" { expectEqual(i - START_OF_DISPLAYABLE_REGION + TOTAL_CHAR_ON_PAGE, b); } } - - // // Tear down // @@ -2047,36 +1755,26 @@ test "pageUp bottom page" { } test "pageDown bottom page" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); incrementingPagesTesting(); defaultVideoBufferTesting(); - - // // Call function // pageDown(); - - // // Post test // defaultVariablesTesting(0, 0, 0); incrementingPagesTesting(); defaultVideoBufferTesting(); - - // // Tear down // @@ -2084,14 +1782,10 @@ test "pageDown bottom page" { } test "pageDown top page" { - // // Set up // - setVideoBufferBlankPages(); setPagesIncrementing(); - - // // Pre testing // @@ -2100,14 +1794,10 @@ test "pageDown top page" { defaultVariablesTesting(TOTAL_NUM_PAGES - 1, 0, 0); incrementingPagesTesting(); defaultVideoBufferTesting(); - - // // Call function // pageDown(); - - // // Post test // @@ -2127,8 +1817,6 @@ test "pageDown top page" { expectEqual((i - START_OF_DISPLAYABLE_REGION) + (TOTAL_CHAR_ON_PAGE * page_index), b); } } - - // // Tear down // @@ -2136,28 +1824,20 @@ test "pageDown top page" { } test "clearScreen all" { - // // Set up // - setVideoBufferIncrementingBlankPages(); setPagesIncrementing(); - - // // Pre testing // defaultVariablesTesting(0, 0, 0); incrementingVideoBufferTesting(); incrementingPagesTesting(); - - // // Call function // clearScreen(); - - // // Post test // @@ -2183,8 +1863,6 @@ test "clearScreen all" { } } } - - // // Tear down // @@ -2192,31 +1870,21 @@ test "clearScreen all" { } test "moveCursorLeft top left of screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // defaultAllTesting(0, 0, 0); - - // // Call function // moveCursorLeft(); - - // // Post test // defaultAllTesting(0, 0, 0); - - // // Tear down // @@ -2224,32 +1892,22 @@ test "moveCursorLeft top left of screen" { } test "moveCursorLeft top screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 5; defaultAllTesting(0, 0, 5); - - // // Call function // moveCursorLeft(); - - // // Post test // defaultAllTesting(0, 0, 4); - - // // Tear down // @@ -2257,32 +1915,22 @@ test "moveCursorLeft top screen" { } test "moveCursorLeft start of row" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // row = 5; defaultAllTesting(0, 5, 0); - - // // Call function // moveCursorLeft(); - - // // Post test // defaultAllTesting(0, 4, vga.WIDTH - 1); - - // // Tear down // @@ -2290,33 +1938,23 @@ test "moveCursorLeft start of row" { } test "moveCursorRight bottom right of screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // row = vga.HEIGHT - 1; column = vga.WIDTH - 1; defaultAllTesting(0, vga.HEIGHT - 1, vga.WIDTH - 1); - - // // Call function // moveCursorRight(); - - // // Post test // defaultAllTesting(0, vga.HEIGHT - 1, vga.WIDTH - 1); - - // // Tear down // @@ -2324,32 +1962,22 @@ test "moveCursorRight bottom right of screen" { } test "moveCursorRight top screen" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // column = 5; defaultAllTesting(0, 0, 5); - - // // Call function // moveCursorRight(); - - // // Post test // defaultAllTesting(0, 0, 6); - - // // Tear down // @@ -2357,33 +1985,23 @@ test "moveCursorRight top screen" { } test "moveCursorRight end of row" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // row = 5; column = vga.WIDTH - 1; defaultAllTesting(0, 5, vga.WIDTH - 1); - - // // Call function // moveCursorRight(); - - // // Post test // defaultAllTesting(0, 6, 0); - - // // Tear down // @@ -2391,7 +2009,6 @@ test "moveCursorRight end of row" { } test "setColour all" { - // // Set up // @@ -2402,43 +2019,30 @@ test "setColour all" { // // Call function // - const new_colour: u8 = vga.entryColour(vga.COLOUR_WHITE, vga.COLOUR_WHITE); setColour(new_colour); - - // // Post test // expectEqual(new_colour, colour); expectEqual(vga.entry(0, new_colour), blank); - - // // Tear down // resetGlobals(); } test "writeString all" { - // // Set up // - setVideoBufferBlankPages(); - - // // Pre testing // row = ROW_MIN; defaultAllTesting(0, ROW_MIN, 0); - - // // Call function // writeString("ABC") catch unreachable; - - // // Post test // @@ -2457,7 +2061,6 @@ test "writeString all" { } } - var k: u16 = 0; while (k < VIDEO_BUFFER_SIZE) : (k += 1) { if (k == START_OF_DISPLAYABLE_REGION) { @@ -2470,8 +2073,6 @@ test "writeString all" { expectEqual(blank, video_buffer[k]); } } - - // // Tear down //