aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/boot.s17
-rw-r--r--src/main.zig13
2 files changed, 21 insertions, 9 deletions
diff --git a/src/boot.s b/src/boot.s
new file mode 100644
index 0000000..2530d18
--- /dev/null
+++ b/src/boot.s
@@ -0,0 +1,17 @@
+.global _start
+.type _start, @function
+
+.code32
+// Entry point. It puts the machine into a consistent state,
+// starts the kernel and then waits forever.
+_start:
+ mov _sstack, %esp // Setup the stack.
+
+ push %ebx // Pass multiboot info structure.
+ push %eax // Pass multiboot magic code.
+ call kmain // Call the kernel.
+
+ // Halt the CPU.
+ cli
+ hlt
+
diff --git a/src/main.zig b/src/main.zig
index 76bdadf..f3ea424 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,9 +1,12 @@
+comptime {
+ asm (@embedFile("boot.s"));
+}
+
const debug = @import("debugcon.zig");
const ALIGN = 1 << 0;
const MEMINFO = 1 << 1;
const MAGIC = 0xE85250D6;
-// const FLAGS = ALIGN | MEMINFO;
const FLAGS = 0;
const MultibootHeader = extern struct {
@@ -27,14 +30,6 @@ export const multiboot2 align(4) linksection(".multiboot") = MultibootHeader{
.tag2 = 8,
};
-export fn _start() callconv(.Naked) noreturn {
- asm volatile (
- \\ mov _sstack, %rsp
- \\ mov %rsp, %rbp
- );
- asm volatile ("jmp kmain");
-}
-
var vga = @as([*]volatile u16, @ptrFromInt(0xB8000));
export fn kmain() noreturn {