setup framebuffer with console
This commit is contained in:
+24
-12
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const danos = @import("danos");
|
||||
const console = @import("console.zig");
|
||||
const BootInfo = danos.BootInfo;
|
||||
|
||||
/// The calling convention used to enter the kernel. Pinned to SysV explicitly:
|
||||
@@ -9,6 +10,11 @@ const BootInfo = danos.BootInfo;
|
||||
/// register the other expects. `danos.kernel_abi` re-exports it to the loader.
|
||||
pub const kernel_abi = danos.kernel_abi;
|
||||
|
||||
/// The system console, valid once `kmain` has initialised it. Global so the
|
||||
/// panic handler can reach it too.
|
||||
var con: console.Console = undefined;
|
||||
var con_ready = false;
|
||||
|
||||
/// Kernel entry point. The bootloader jumps here after `ExitBootServices` with a
|
||||
/// pointer to the handoff data. There is no runtime, no stack unwinding, and no
|
||||
/// caller to return to, so this never returns.
|
||||
@@ -17,16 +23,17 @@ export fn _start(boot_info: *const BootInfo) callconv(kernel_abi) noreturn {
|
||||
}
|
||||
|
||||
fn kmain(boot_info: *const BootInfo) noreturn {
|
||||
// Paint the whole screen so it is visually obvious the kernel took over.
|
||||
// We honour `pitch` because it can exceed `width * 4`.
|
||||
const fb = boot_info.framebuffer;
|
||||
const base: [*]volatile u8 = @ptrFromInt(fb.base);
|
||||
var y: u32 = 0;
|
||||
while (y < fb.height) : (y += 1) {
|
||||
const row: [*]volatile u32 = @ptrCast(@alignCast(base + y * fb.pitch));
|
||||
var x: u32 = 0;
|
||||
while (x < fb.width) : (x += 1) row[x] = 0x0033_66cc;
|
||||
}
|
||||
con = console.Console.init(fb);
|
||||
con.clear();
|
||||
con_ready = true;
|
||||
|
||||
con.write("danos: framebuffer console online\n");
|
||||
con.print(" resolution : {d}x{d}\n", .{ fb.width, fb.height });
|
||||
con.print(" pitch : {d} bytes\n", .{fb.pitch});
|
||||
con.print(" format : {s}\n", .{@tagName(fb.format)});
|
||||
con.print(" framebuffer: 0x{x:0>16}\n", .{fb.base});
|
||||
con.write("\nkernel initialised; nothing left to do, halting.\n");
|
||||
|
||||
hang();
|
||||
}
|
||||
@@ -37,12 +44,17 @@ fn hang() noreturn {
|
||||
while (true) asm volatile ("hlt");
|
||||
}
|
||||
|
||||
/// Freestanding has no OS to receive a panic, so override std's default panic
|
||||
/// handler to simply halt. (Later this can print to the framebuffer/serial.)
|
||||
/// Freestanding has no OS to receive a panic. Print it to the console (if it is
|
||||
/// up yet) in red, then halt.
|
||||
pub const panic = std.debug.FullPanic(struct {
|
||||
fn panic(msg: []const u8, first_trace_addr: ?usize) noreturn {
|
||||
_ = msg;
|
||||
_ = first_trace_addr;
|
||||
if (con_ready) {
|
||||
con.fg = 0x00ff_5555;
|
||||
con.write("\nKERNEL PANIC: ");
|
||||
con.write(msg);
|
||||
con.write("\n");
|
||||
}
|
||||
hang();
|
||||
}
|
||||
}.panic);
|
||||
|
||||
Reference in New Issue
Block a user