diff options
| author | Marin Ivanov <[email protected]> | 2024-05-03 22:57:29 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-05-03 22:57:29 +0300 |
| commit | 4263a0051e0545559cbcabda8bc215dd8c60d981 (patch) | |
| tree | f40e1360d536c6e46dd92c676107ee9536bb6888 /src/debugcon.zig | |
| parent | d45a5e8d11bcb7cb6942dd73aa3801c4ee5181e6 (diff) | |
debugcon: add printf
Diffstat (limited to 'src/debugcon.zig')
| -rw-r--r-- | src/debugcon.zig | 18 |
1 files changed, 16 insertions, 2 deletions
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; +} |
