5-malloc.md (#25)
[lunaix-os.git] / lunaix-os / arch / i386 / boot / prologue.S
1 /* 高半核入口点 - 0xC0000000 */
2
3 #define __ASM__
4 #include <sys/abi.h>
5
6 .section .text
7     .global hhk_entry_
8     hhk_entry_:
9         /*
10             欢迎来到虚拟内存的世界! :D
11          */
12         andl $stack_alignment, %esp
13         subl $16, %esp
14         /* 
15             最终还是决定将IDT&GDT的初始化和安装放在这里
16             注意:由于已开启分页,GDTR与IDTR里面放的不是物理地址,是线性地址! 
17         */
18         /* 
19             加载 GDT 
20             P.s. 虽然GDT在分页后已变得不重要,甚至可以忽略不作。但为了保持完整性,还是选择加载他
21                     这主要是为了保险起见,让GDTR有一个合法的值,否则多咱的粗心大意,容易出#GP
22         */
23         call _init_gdt
24
25         movl $_gdt, 2(%esp)
26         movw _gdt_limit, %ax
27         movw %ax, (%esp)
28         lgdt (%esp)
29
30         /* 更新段寄存器 */
31         movw $KDATA_SEG, %cx
32         movw %cx, %es
33         movw %cx, %ds
34         movw %cx, %fs
35         movw %cx, %gs
36         movw %cx, %ss
37         
38         /* 更新 CS:EIP */
39         pushw $KCODE_SEG
40         pushl $_after_gdt
41         retf
42
43     _after_gdt:
44         subl $16, %esp
45
46         # 加载 IDT
47         movl $_idt, 2(%esp)
48         movw _idt_limit, %ax
49         movw %ax, (%esp)
50         lidt (%esp)
51
52         # perform arch-specific initialization before diving into kernel
53         call arch_preinit
54
55         /* 加载TSS段选择器 */
56         movw $TSS_SEG, %ax
57         ltr %ax
58
59         movl $bhctx_buffer, (%esp)       # mb_parser.c
60         call kernel_bootstrap
61
62     1:
63         hlt
64         jmp 1b