2019-05-23 17:50:37 +01:00
|
|
|
const std = @import("std");
|
2019-04-17 17:40:26 +01:00
|
|
|
const builtin = @import("builtin");
|
2019-10-05 20:46:31 +01:00
|
|
|
const is_test = builtin.is_test;
|
2019-09-16 22:19:21 +01:00
|
|
|
const build_options = @import("build_options");
|
2019-10-05 20:46:31 +01:00
|
|
|
const mock_path = build_options.mock_path;
|
2019-09-08 20:48:23 +01:00
|
|
|
const arch = @import("arch.zig").internals;
|
2019-05-18 16:26:44 +01:00
|
|
|
const multiboot = @import("multiboot.zig");
|
2019-05-22 20:12:46 +01:00
|
|
|
const tty = @import("tty.zig");
|
|
|
|
const vga = @import("vga.zig");
|
2019-06-22 10:00:57 +01:00
|
|
|
const log = @import("log.zig");
|
2019-06-16 23:48:32 +01:00
|
|
|
const serial = @import("serial.zig");
|
2019-10-05 20:46:31 +01:00
|
|
|
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
|
2019-11-02 02:18:02 +00:00
|
|
|
const panic_root = if (is_test) @import(mock_path ++ "panic_mock.zig") else @import("panic.zig");
|
|
|
|
const options = @import("build_options");
|
2019-04-17 17:40:26 +01:00
|
|
|
|
2019-09-03 14:13:26 -04:00
|
|
|
comptime {
|
|
|
|
switch (builtin.arch) {
|
|
|
|
.i386 => _ = @import("arch/x86/boot.zig"),
|
|
|
|
else => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 20:48:23 +01:00
|
|
|
// This is for unit testing as we need to export KERNEL_ADDR_OFFSET as it is no longer available
|
|
|
|
// from the linker script
|
|
|
|
export var KERNEL_ADDR_OFFSET: u32 = if (builtin.is_test) 0xC0000000 else undefined;
|
|
|
|
|
2019-05-31 07:41:28 +01:00
|
|
|
// Just call the panic function, as this need to be in the root source file
|
2019-04-17 17:40:26 +01:00
|
|
|
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
|
|
|
|
@setCold(true);
|
2019-11-02 02:18:02 +00:00
|
|
|
panic_root.panic(error_return_trace, "{}", msg);
|
2019-04-17 17:40:26 +01:00
|
|
|
}
|
|
|
|
|
2019-09-16 22:19:21 +01:00
|
|
|
export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void {
|
2019-05-18 16:26:44 +01:00
|
|
|
if (mb_magic == multiboot.MULTIBOOT_BOOTLOADER_MAGIC) {
|
|
|
|
// Booted with compatible bootloader
|
2019-10-08 11:20:37 +01:00
|
|
|
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch |e| {
|
2019-11-02 02:18:02 +00:00
|
|
|
panic_root.panic(@errorReturnTrace(), "Failed to initialise serial: {}", e);
|
2019-10-08 11:20:37 +01:00
|
|
|
};
|
|
|
|
if (build_options.rt_test)
|
|
|
|
log.runtimeTests();
|
2019-11-02 02:00:49 +00:00
|
|
|
const mem_profile = mem.init(mb_info);
|
|
|
|
var buffer = mem_profile.vaddr_end[0..mem_profile.fixed_alloc_size];
|
|
|
|
var fixed_allocator = std.heap.FixedBufferAllocator.init(buffer);
|
2019-06-22 10:00:57 +01:00
|
|
|
|
|
|
|
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n");
|
2019-11-02 02:00:49 +00:00
|
|
|
arch.init(mb_info, &mem_profile, &fixed_allocator.allocator);
|
2019-06-29 23:50:44 +01:00
|
|
|
log.logInfo("Arch init done\n");
|
2019-11-02 02:18:02 +00:00
|
|
|
panic_root.init(&mem_profile, &fixed_allocator.allocator) catch |e| {
|
|
|
|
panic_root.panic(@errorReturnTrace(), "Failed to initialise panic: {}", e);
|
|
|
|
};
|
2019-05-22 20:12:46 +01:00
|
|
|
vga.init();
|
|
|
|
tty.init();
|
2019-06-16 23:48:32 +01:00
|
|
|
|
2019-06-29 23:50:44 +01:00
|
|
|
log.logInfo("Init done\n");
|
2019-05-31 07:41:28 +01:00
|
|
|
tty.print("Hello Pluto from kernel :)\n");
|
2019-11-02 02:18:02 +00:00
|
|
|
// The panic runtime tests must run last as they never return
|
|
|
|
if (options.rt_test) panic_root.runtimeTests();
|
2019-05-18 16:26:44 +01:00
|
|
|
}
|
2019-04-17 17:40:26 +01:00
|
|
|
}
|