46 lines
979 B
Zig
46 lines
979 B
Zig
// Rumpk Layer 0: UART Driver
|
|
// Minimal serial output for QEMU 'virt' machine
|
|
//
|
|
// QEMU virt UART: PL011 @ 0x09000000
|
|
|
|
const UART0_BASE: usize = 0x09000000;
|
|
|
|
// PL011 Register Offsets
|
|
const UARTDR: usize = 0x00; // Data Register
|
|
const UARTFR: usize = 0x18; // Flag Register
|
|
const UARTFR_TXFF: u32 = 1 << 5; // TX FIFO Full
|
|
|
|
pub fn init() void {
|
|
// QEMU PL011 is pre-initialized, no setup needed
|
|
}
|
|
|
|
fn write_char(c: u8) void {
|
|
const dr: *volatile u32 = @ptrFromInt(UART0_BASE + UARTDR);
|
|
const fr: *volatile u32 = @ptrFromInt(UART0_BASE + UARTFR);
|
|
|
|
// Wait for TX FIFO to have space
|
|
while ((fr.* & UARTFR_TXFF) != 0) {}
|
|
|
|
dr.* = c;
|
|
}
|
|
|
|
pub fn write_bytes(bytes: []const u8) void {
|
|
for (bytes) |b| {
|
|
if (b == '\n') {
|
|
write_char('\r');
|
|
}
|
|
write_char(b);
|
|
}
|
|
}
|
|
|
|
pub fn puts(s: []const u8) void {
|
|
write_bytes(s);
|
|
}
|
|
|
|
pub fn putc(c: u8) void {
|
|
if (c == '\n') {
|
|
write_char('\r');
|
|
}
|
|
write_char(c);
|
|
}
|