refactor: restructure the user space stuff.
[lunaix-os.git] / lunaix-os / kernel / asm / x86 / prologue.S
1 /* 高半核入口点 - 0xC0000000 */
2
3 #define __ASM__
4 #include <arch/x86/i386_asm.h>
5
6 .section .text
7     .global hhk_entry_
8     hhk_entry_:
9         /*
10             欢迎来到虚拟内存的世界! :D
11          */
12
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         movl $_gdt, 2(%esp)
25         movw _gdt_limit, %ax
26         movw %ax, (%esp)
27         lgdt (%esp)
28
29         /* 更新段寄存器 */
30         movw $KDATA_SEG, %cx
31         movw %cx, %es
32         movw %cx, %ds
33         movw %cx, %fs
34         movw %cx, %gs
35         movw %cx, %ss
36
37         /* 更新 CS:EIP */
38         pushw $KCODE_SEG
39         pushl $_after_gdt
40         retf
41
42     _after_gdt:
43
44         movl $mb_info, _k_init_mb_info
45
46         call _kernel_pre_init
47
48         subl $6, %esp
49
50         # 加载 IDT
51         movl $_idt, 2(%esp)
52         movw _idt_limit, %ax
53         movw %ax, (%esp)
54         lidt (%esp)
55
56         /* 加载TSS段选择器 */
57         movw $TSS_SEG, %ax
58         ltr %ax
59
60         addl $6, %esp
61
62         call _kernel_init
63
64     1:
65         hlt
66         jmp 1b