Move tty to arch

This commit is contained in:
Sam Tebbs 2020-06-12 12:05:50 +01:00
parent c4083b0161
commit e2533a2264
8 changed files with 2231 additions and 2209 deletions

View file

@ -16,9 +16,11 @@ const multiboot = @import("multiboot.zig");
const pmm = @import("pmm.zig");
const vmm = @import("../../vmm.zig");
const log = @import("../../log.zig");
const tty = @import("../../tty.zig");
const tty = @import("tty.zig");
const vga = @import("vga.zig");
const Serial = @import("../../serial.zig").Serial;
const panic = @import("../../panic.zig").panic;
const TTY = @import("../../tty.zig").TTY;
const MemProfile = mem.MemProfile;
/// The virtual end of the kernel code
@ -282,6 +284,25 @@ pub fn initSerial(boot_payload: BootPayload) Serial {
};
}
///
/// Initialise the TTY and construct a TTY instance
///
/// Arguments:
/// IN boot_payload: BootPayload - The payload passed to the kernel on boot
///
/// Return: tty.TTY
/// The TTY instance constructed with the information required by the rest of the kernel
///
pub fn initTTY(boot_payload: BootPayload) TTY {
return .{
.print = tty.writeString,
.setCursor = tty.setCursor,
.cols = vga.WIDTH,
.rows = vga.HEIGHT,
.clear = tty.clearScreen,
};
}
///
/// Initialise the system's memory. Populates a memory profile with boot modules from grub, the amount of available memory, the reserved regions of virtual and physical memory as well as the start and end of the kernel code
///
@ -391,6 +412,11 @@ pub fn init(mb_info: *multiboot.multiboot_info_t, mem_profile: *const MemProfile
syscalls.init();
enableInterrupts();
// Initialise the VGA and TTY here since their tests belong the architecture and so should be a part of the
// arch init test messages
vga.init();
tty.init();
}
test "" {
@ -404,4 +430,7 @@ test "" {
_ = @import("rtc.zig");
_ = @import("syscalls.zig");
_ = @import("paging.zig");
_ = @import("serial.zig");
_ = @import("tty.zig");
_ = @import("vga.zig");
}

2106
src/kernel/arch/x86/tty.zig Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,10 +3,9 @@ const builtin = @import("builtin");
const is_test = builtin.is_test;
const expectEqual = std.testing.expectEqual;
const build_options = @import("build_options");
const mock_path = build_options.mock_path;
const arch = @import("arch.zig").internals;
const log = if (is_test) @import(mock_path ++ "log_mock.zig") else @import("log.zig");
const panic = @import("panic.zig").panic;
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;
/// The port address for the VGA register selection.
const PORT_ADDRESS: u16 = 0x03D4;

View file

@ -55,8 +55,6 @@ export fn kmain(boot_payload: arch.BootPayload) void {
arch.init(boot_payload, &mem_profile, &fixed_allocator.allocator);
log.logInfo("Arch init done\n", .{});
vga.init();
tty.init();
// 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;
// The heap size must be a power of two so find the power of two smaller than or equal to the heap_size
@ -66,8 +64,21 @@ export fn kmain(boot_payload: arch.BootPayload) void {
var kernel_heap = heap.init(arch.VmmPayload, &kernel_vmm, vmm.Attributes{ .kernel = true, .writable = true, .cachable = true }, heap_size, &fixed_allocator.allocator) catch |e| {
panic_root.panic(@errorReturnTrace(), "Failed to initialise kernel heap: {}\n", .{e});
};
tty.init(&kernel_heap.allocator, boot_payload);
log.logInfo("Init done\n", .{});
tty.clear();
const logo =
\\ _____ _ _ _ _______ ____
\\ | __ \ | | | | | | |__ __| / __ \
\\ | |__) | | | | | | | | | | | | |
\\ | ___/ | | | | | | | | | | | |
\\ | | | |____ | |__| | | | | |__| |
\\ |_| |______| \____/ |_| \____/
;
tty.print("{}\n\n", .{logo});
tty.print("Hello Pluto from kernel :)\n", .{});
// The panic runtime tests must run last as they never return

File diff suppressed because it is too large Load diff

View file

@ -36,4 +36,9 @@ def get_test_cases(TestCase):
TestCase("Syscalls init", [r"Init syscalls"]),
TestCase("Syscalls tests", [r"Syscalls: Tested no args", r"Syscalls: Tested 1 arg", r"Syscalls: Tested 2 args", r"Syscalls: Tested 3 args", r"Syscalls: Tested 4 args", r"Syscalls: Tested 5 args"]),
TestCase("Syscalls done", [r"Done syscalls"]),
TestCase("VGA init", [r"Init vga"]),
TestCase("VGA tests", [r"VGA: Tested max scan line", r"VGA: Tested cursor shape", r"VGA: Tested updating cursor"]),
TestCase("VGA done", [r"Done vga"]),
TestCase("TTY tests", [r"TTY: Tested globals", r"TTY: Tested printing"]),
]

View file

@ -7,6 +7,7 @@ const idt = @import("idt_mock.zig");
const vmm = @import("vmm_mock.zig");
const paging = @import("paging_mock.zig");
const Serial = @import("../../../src/kernel/serial.zig").Serial;
const TTY = @import("../../../src/kernel/tty.zig").TTY;
const mock_framework = @import("mock_framework.zig");
pub const initTest = mock_framework.initTest;
@ -106,6 +107,16 @@ pub fn initSerial(boot_payload: BootPayload) Serial {
return .{ .write = undefined };
}
pub fn initTTY(boot_payload: BootPayload) TTY {
return .{
.print = undefined,
.setCursor = undefined,
.cols = undefined,
.rows = undefined,
.clear = null,
};
}
pub fn initMem(payload: BootPayload) std.mem.Allocator.Error!mem.MemProfile {
return MemProfile{
.vaddr_end = @ptrCast([*]u8, &KERNEL_VADDR_END),

View file

@ -56,16 +56,12 @@ def get_pre_archinit_cases():
def get_post_archinit_cases():
return [
TestCase("Arch init finishes", [r"Arch init done"]),
TestCase("VGA init", [r"Init vga"]),
TestCase("VGA tests", [r"VGA: Tested max scan line", r"VGA: Tested cursor shape", r"VGA: Tested updating cursor"]),
TestCase("VGA done", [r"Done vga"]),
TestCase("TTY init", [r"Init tty"]),
TestCase("TTY tests", [r"TTY: Tested globals", r"TTY: Tested printing"]),
TestCase("TTY done", [r"Done tty"]),
TestCase("Heap", [r"Init heap", r"Done heap"]),
TestCase("TTY init", [r"Init tty"]),
TestCase("TTY done", [r"Done tty"]),
TestCase("Init finishes", [r"Init done"]),
TestCase("Panic tests", [r"Kernel panic: integer overflow", r"c[a-z\d]+: panic", r"c[a-z\d]+: panic.runtimeTests", r"c[a-z\d]+: kmain", r"c[a-z\d]+: start_higher_half"], r"\[ERROR\] ")