From 4263a0051e0545559cbcabda8bc215dd8c60d981 Mon Sep 17 00:00:00 2001 From: Marin Ivanov Date: Fri, 3 May 2024 22:57:29 +0300 Subject: debugcon: add printf --- src/debugcon.zig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/debugcon.zig') diff --git a/src/debugcon.zig b/src/debugcon.zig index e721a4d..6f8b8e7 100644 --- a/src/debugcon.zig +++ b/src/debugcon.zig @@ -1,11 +1,14 @@ -pub inline fn inb(port: u16) u8 { +const fmt = @import("std").fmt; +const Writer = @import("std").io.Writer; + +fn inb(port: u16) u8 { return asm volatile ("inb %[port], %[result]" : [result] "={al}" (-> u8), : [port] "{dx}" (port), ); } -pub fn outb(port: u16, data: u8) void { +fn outb(port: u16, data: u8) void { asm volatile ("outb %[data], %[port]" : : [port] "{dx}" (port), @@ -18,3 +21,14 @@ pub fn write(data: []const u8) void { outb(0xe9, x); } } + +pub const writer = Writer(void, error{}, callback){ .context = {} }; + +fn callback(_: void, string: []const u8) error{}!usize { + write(string); + return string.len; +} + +pub fn printf(comptime format: []const u8, args: anytype) void { + fmt.format(writer, format, args) catch unreachable; +} -- cgit v1.2.3