aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/debugcon.zig25
-rw-r--r--src/main.zig41
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');
}