course 5 and some old slides
[lunaix-os.git] / lunaix-os / arch / x86 / boot.S
1 #include "multiboot.h"
2
3 .section .multiboot
4     .long MB_MAGIC
5     .long MB_ALIGNED_4K_MEM_MAP
6     .long CHECKSUM(MB_ALIGNED_4K_MEM_MAP)
7
8 .section .bss
9     /* According to System V ABI, the stack must be aligned at 16 bytes boundary */
10     .align 16
11     stack_bottom:
12         .skip 16318, 0
13     stack_top:
14
15 .section .text
16     .global start_
17     .type start_, @function     /* Optional, this just give the 
18                                  * linker more knowledge about the label 
19                                  */
20     start_:
21         movl $stack_top, %esp
22         /* 
23             TODO: kernel init
24                 1. Load GDT
25                 2. Load IDT
26                 3. Enable paging
27         */
28         call _kernel_init
29         
30         subl $0x6, %esp
31         movl $_gdt, 2(%esp)
32         movw _gdt_limit, %ax
33         movw %ax, (%esp)
34         lgdt (%esp)
35         addl $0x6, %esp
36
37         movw $0x10, %cx
38         movw %cx, %es
39         movw %cx, %ds
40         movw %cx, %fs
41         movw %cx, %gs
42         movw %cx, %ss
43
44         pushw $0x08
45         pushl $_after_gdt
46         retf
47
48     _after_gdt:
49         pushl %ebx
50         call _kernel_main
51
52         cli
53     j_:
54         hlt
55         jmp j_