diff options
| author | Marin Ivanov <[email protected]> | 2024-05-01 09:51:27 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-05-01 09:51:27 +0300 |
| commit | 26e457315d5e35677dfdd2d413fbf48ed1c869ee (patch) | |
| tree | 8711c99710804502225a5e179d9a21564a63cb5e | |
| parent | 9ed08e3d2a061fd1bfdefb603dd772eb324caf09 (diff) | |
wip: move inb/outb/write to debugcon.zig
| -rw-r--r-- | src/debugcon.zig | 25 | ||||
| -rw-r--r-- | src/main.zig | 41 |
2 files changed, 34 insertions, 32 deletions
diff --git a/src/debugcon.zig b/src/debugcon.zig new file mode 100644 index 0000000..2049d22 --- /dev/null +++ b/src/debugcon.zig @@ -0,0 +1,25 @@ +pub inline fn inb(port: u16) u8 { + return asm volatile ("inb %[port], %[result]" + : [result] "={al}" (-> u8), + : [port] "{dx}" (port), + : "dx", "al" + ); +} + +pub inline fn outb(port: u16, data: u8) void { + asm volatile ("outb %[data], %[port]" + : + : [port] "{dx}" (port), + [data] "{al}" (data), + : "dx", "al" + ); +} + +pub fn write(data: []const u8) void { + const len: u8 = @intCast(data.len & 0xFF); + outb(0xe9, 0x30 + len); + for (0..len) |i| { + outb(0xe9, 0x30); + outb(0xe9, data[i]); + } +} diff --git a/src/main.zig b/src/main.zig index a43e63a..30c21a4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,4 +1,5 @@ const console = @import("console.zig"); +const debug = @import("debugcon.zig"); const ALIGN = 1 << 0; const MEMINFO = 1 << 1; @@ -20,36 +21,12 @@ export const multiboot align(4) linksection(".multiboot") = MultibootHeader{ export var stack: [16 * 1024]u8 align(16) linksection(".bss") = undefined; const stack_bytes_slice = stack[0..]; -inline fn inb(port: u16) u8 { - return asm volatile ("inb %[port], %[result]" - : [result] "={al}" (-> u8), - : [port] "N{dx}" (port), - ); -} - -inline fn outb(port: u16, data: u8) void { - asm volatile ("outb %[data], %[port]" - : - : [data] "{al}" (data), - [port] "N{dx}" (port), - ); -} - -fn write(data: []const u8) void { - const len: u8 = @intCast(data.len & 0xFF); - outb(0xe9, 0x30 + len); - for (0..len) |i| { - outb(0xe9, 0x30); - outb(0xe9, data[i]); - } -} - export fn _start() callconv(.C) noreturn { - write("test\n"); - outb(0xe9, 'H'); - outb(0xe9, 'i'); - outb(0xe9, '!'); - outb(0xe9, '\n'); + debug.write("test\n"); + debug.outb(0xe9, 'H'); + debug.outb(0xe9, 'i'); + debug.outb(0xe9, '!'); + debug.outb(0xe9, '\n'); asm volatile ( \\ mov %[stk], %rsp @@ -63,9 +40,9 @@ export fn _start() callconv(.C) noreturn { } export fn kmain() void { - outb(0xe9, '^'); + debug.outb(0xe9, '^'); console.initialize(); console.puts("Hello world!"); - outb(0xe9, '$'); - outb(0xe9, '\n'); + debug.outb(0xe9, '$'); + debug.outb(0xe9, '\n'); } |
