first commit

This commit is contained in:
Lorenzo Torres 2026-01-30 16:21:31 +01:00
commit 6f76f9dd9d
9 changed files with 1071 additions and 0 deletions

47
src/main.zig Normal file
View file

@ -0,0 +1,47 @@
const std = @import("std");
const isa = @import("riscv/isa.zig");
const Fdt = @import("Fdt.zig");
const UART_BASE: usize = 0x10000000;
fn uart_put(c: u8) void {
const uart: *volatile u8 = @ptrFromInt(UART_BASE);
uart.* = c;
}
fn print(s: []const u8) void {
for (s) |c| {
uart_put(c);
}
}
export fn _start() linksection(".text.init") callconv(.naked) noreturn {
asm volatile (
\\li sp, 0x88000000
\\tail kmain
);
}
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");
}
}
while (true) {
asm volatile ("wfi");
}
}