aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: dedcb65951602d1e75afedb0d3ef6e07947a552f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const console = @import("console.zig");

const ALIGN = 1 << 0;
const MEMINFO = 1 << 1;
const MAGIC = 0x1BADB002;
const FLAGS = ALIGN | MEMINFO;

const MultibootHeader = extern struct {
    magic: i32,
    flags: i32,
    checksum: i32,
};

export const multiboot align(4) linksection(".multiboot") = MultibootHeader{
    .magic = MAGIC,
    .flags = FLAGS,
    .checksum = -(MAGIC + FLAGS),
};

export var stack: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
const stack_bytes_slice = stack[0..];

export fn _start() callconv(.Naked) noreturn {
    // @call(.{ .stack = stack_bytes_slice }, kmain, .{});
    asm volatile (
        \\ mov %[stk], %rsp
        \\ mov %rsp, %rbp
        :
        : [stk] "{rcx}" (@intFromPtr(&stack) + @sizeOf(@TypeOf(stack))),
    );
    asm volatile ("call kmain");

    while (true) {}
}

export fn kmain() void {
    console.initialize();
    console.puts("Hello world!");
}