aboutsummaryrefslogtreecommitdiff
path: root/src/sbi/debug_console.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbi/debug_console.zig')
-rw-r--r--src/sbi/debug_console.zig34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/sbi/debug_console.zig b/src/sbi/debug_console.zig
new file mode 100644
index 0000000..2bcc097
--- /dev/null
+++ b/src/sbi/debug_console.zig
@@ -0,0 +1,34 @@
+// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+const std = @import("std");
+const riscv = @import("../riscv.zig");
+const sbi = @import("../sbi.zig");
+
+const ExtId: usize = 0x4442434E;
+
+const FnId = enum(usize) {
+ Write,
+ Read,
+ WriteByte,
+};
+
+pub const Writer = std.io.Writer(void, sbi.Error, write);
+
+fn write(_: void, bytes: []const u8) !usize {
+ const ret = riscv.ecall(ExtId, @intFromEnum(FnId.Write), bytes.len, @intFromPtr(bytes.ptr), 0);
+ if (ret.err != 0) {
+ return sbi.errorFromCode(ret.err);
+ }
+
+ return @intCast(ret.val);
+}
+
+pub fn writer() !Writer {
+ if (!try sbi.probeExt(ExtId)) {
+ return sbi.Error.NotSupported;
+ }
+
+ return .{ .context = {} };
+}