kornos/kernel/src/main.zig

79 lines
2.0 KiB
Zig

const std = @import("std");
const builtin = @import("builtin");
const debug = @import("debug.zig");
const kalloc = @import("allocator/kalloc.zig");
const time = @import("time.zig");
const arch = switch(builtin.cpu.arch) {
.x86_64 => @import("arch/x86_64/x86_64.zig"),
.i386 => @import("arch/i386/i386.zig"),
else => @panic("unknown architecture!"),
};
comptime {
_ = arch;
}
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
debug.zigpanic(msg, error_return_trace);
}
pub var alloc: *std.mem.Allocator = &kalloc.KAlloc.allocator;
pub const log_level = .debug;
pub fn log(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
return debug.log(level, scope, format, args);
}
comptime {
_ = debug;
_ = time;
}
const c = @cImport({
@cInclude("hal/debug.h");
@cInclude("hal/print.h");
@cInclude("print/print.h");
@cInclude("hal/ops.h");
@cInclude("hal/info.h");
if( builtin.cpu.arch == .x86_64 or builtin.cpu.arch == .i386) {
@cInclude("arch/x86/vga.h");
}
});
export fn zigmain() void {
// // const message: [*:0]const u8 = "hello, zig!\n";
std.log.info("All your codebase are belong to us.", .{});
std.log.debug("CPU info: {} ({})", .{builtin.cpu.arch, builtin.cpu.model.name});
c.puts("zig ee\n");
const msg = std.fmt.allocPrint(alloc, "Hello {}!", .{"ziguser"});
std.log.debug("message: {}", .{msg});
// var cr3: usize = asm volatile (
// "mov %%cr3, %%rax" : [cr3] "={rax}" (-> usize) ::
// );
// std.log.info("cr3 = {x}", .{cr3});
// const page_lvl4 = @intToPtr(*[512]u64, cr3);
// arch.paging.showTable(page_lvl4.*);
// time.displayTime(debug.AWriter) catch unreachable;
const cmdline = std.mem.span(c.boot_info.cmdline);
std.log.info("cmdline: {}", .{cmdline});
// std.log.info("pagefault/protectionfault time: {}", .{@intToPtr([*:0]u8, 0xcfffffff80000000)});
// @panic("ee");
}