initial commit
[3sys] / sys1 / kern / src / start.asm
1         bits 32
2         section .text
3
4         extern _bss_start
5         extern _bss_size
6         extern kmain
7
8 MB_MAGIC equ 0x1badb002
9 MB_FLAGS equ 0
10
11
12         global start
13 start:
14         jmp .skip_mboot_hdr
15
16         ; multiboot header
17         align 4
18         dd MB_MAGIC
19         dd MB_FLAGS
20         dd -(MB_MAGIC + MB_FLAGS)       ; checksum
21         times 5 dd 0
22
23 .skip_mboot_hdr:
24         ; init temporary kernel stack at the top of conventional memory
25         mov esp, 0xa0000
26
27         ; clear .bss (if it's not empty)
28         ; due to the ALIGN(4) statements in the linker script, it's guaranteed
29         ; that _bss_start and _bss_end will be 32bit-aligned, so we can use
30         ; rep stosd to clear it
31         mov ecx, _bss_size
32         test ecx, ecx
33         jz .skip_bss
34         xor eax, eax
35         mov edi, _bss_start
36         shr ecx, 2      ; _bss_size is in bytes, we need count in "dwords"
37         rep stosd
38 .skip_bss:
39
40         call kmain
41         ; kmain shouldn't ever return, but we'll enter a hlt loop just in case
42 .inf:   hlt
43         jmp .inf
44
45 ; vi:ft=nasm: