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 | |
| parent | d45a5e8d11bcb7cb6942dd73aa3801c4ee5181e6 (diff) | |
debugcon: add printf
| -rw-r--r-- | src/debugcon.zig | 18 | ||||
| -rw-r--r-- | src/main.zig | 2 |
2 files changed, 17 insertions, 3 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; +} diff --git a/src/main.zig b/src/main.zig index e647a81..55e30f8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -11,7 +11,7 @@ export fn kmain() noreturn { console.puts("64-bit Yadka"); // write debug data - debug.write("Hi!\n"); + debug.printf("Hi from {p}\n", .{&kmain}); while (true) {} } |
