aboutsummaryrefslogtreecommitdiff
path: root/src/debugcon.zig
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2024-05-03 22:57:29 +0300
committerMarin Ivanov <[email protected]>2024-05-03 22:57:29 +0300
commit4263a0051e0545559cbcabda8bc215dd8c60d981 (patch)
treef40e1360d536c6e46dd92c676107ee9536bb6888 /src/debugcon.zig
parentd45a5e8d11bcb7cb6942dd73aa3801c4ee5181e6 (diff)
debugcon: add printf
Diffstat (limited to 'src/debugcon.zig')
-rw-r--r--src/debugcon.zig18
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;
+}