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