formated code and fix include error in interrupts.c
[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
32         movl $_gdt, 2(%esp)
33         movw _gdt_limit, %ax
34         movw %ax, (%esp)
35         lgdt (%esp)
36
37         movl $_idt, 2(%esp)
38         movw _idt_limit, %ax
39         movw %ax, (%esp)
40         lidt (%esp)
41
42         addl $0x6, %esp
43
44         movw $0x10, %cx
45         movw %cx, %es
46         movw %cx, %ds
47         movw %cx, %fs
48         movw %cx, %gs
49         movw %cx, %ss
50
51         pushw $0x08
52         pushl $_after_gdt
53         retf
54
55     _after_gdt:
56         pushl %ebx
57         call _kernel_main
58
59         cli
60     j_:
61         hlt
62         jmp j_