aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 76bdadfd1135d60ef7aa395d16250eb559bba391 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
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 {
    magic: u32,
    flags: u32,
    len: u32,
    checksum: u32,

    tag0: u16,
    tag1: u16,
    tag2: u32,
};

export const multiboot2 align(4) linksection(".multiboot") = MultibootHeader{
    .magic = MAGIC,
    .flags = FLAGS,
    .len = 24,
    .checksum = 0x100000000 - (MAGIC + FLAGS + 24),
    .tag0 = 0,
    .tag1 = 0,
    .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 {
    //print OK
    vga[0] = 0x2f4f;
    vga[1] = 0x2f4b;

    // write debug data
    debug.outb(0xe9, 'H');
    debug.outb(0xe9, 'i');
    debug.outb(0xe9, '!');
    debug.outb(0xe9, '\n');

    while (true) {}
}