add UART console

This commit is contained in:
Lorenzo Torres 2026-01-31 15:57:54 +01:00
parent 25ec14c4a1
commit 48421fc0ef
3 changed files with 55 additions and 48 deletions

View file

@ -1,9 +1,12 @@
const std = @import("std");
const isa = @import("riscv/isa.zig");
const Fdt = @import("Fdt.zig");
const Console = @import("drivers/Console.zig");
const UART_BASE: usize = 0x10000000;
var console: Console = undefined;
fn uart_put(c: u8) void {
const uart: *volatile u8 = @ptrFromInt(UART_BASE);
uart.* = c;
@ -24,22 +27,14 @@ export fn _start() linksection(".text.init") callconv(.naked) noreturn {
export fn kmain(hartid: u64, fdt_ptr: *const anyopaque) callconv(.c) noreturn {
_ = hartid;
print("Booting hydra...\n");
const fdt = Fdt.parse(fdt_ptr) catch {
print("Failed to parse FDT\n");
while (true) asm volatile ("wfi");
};
if (fdt.findFirstCompatible("ns16550a")) |console| {
var iter = console.getProperty("reg").?.asU32Array();
const start = iter.next();
const end = iter.next();
_ = end;
if (start == 0x100) {
print("Found console\n");
}
}
console = Console.init(fdt).?;
console.print("booting hydra...\n", .{});
while (true) {
asm volatile ("wfi");