2 #include <arch/x86/boot/multiboot.h>
4 #define MB_FLAGS MULTIBOOT_MEMORY_INFO | MULTIBOOT_PAGE_ALIGN
5 #define KPG_SIZE 10*4096
10 .long CHECKSUM(MB_FLAGS)
15 /* 为Multiboot info struct 预留空间 */
18 /* 根据System V ABI,栈地址必须16字节对齐 */
19 /* 这里只是一个临时栈,在_hhk_init里面我们会初始化内核专用栈 */
28 1. Mapping reserved area and hhk_init
29 2-9. Remapping the kernels
40 .type start_, @function /* Optional, this just give the
41 * linker more knowledge about the label
45 # 确保屏蔽所有外中断,直到我们准备好PIC为止
47 movl $__stack_top, %esp
52 将咱们的 multiboot_info 挪个地儿,就是上述预留的空间里
53 而后在_hhk_init里,我们会对所有的高半核初始化代码(arch/x86下的所有)进行Identity map
54 这样,我们能够保证当分页与虚拟地址开启后,我们的内核能够访问到multiboot info table
57 movl $mb_info, 4(%esp)
59 call _save_multiboot_info
63 1. 初始化最简单的PD与PT(重新映射我们的内核至3GiB处,以及对相应的地方进行Identity Map)
66 movl $(KPG_SIZE), 4(%esp)
67 movl $(_k_ptd - 0xC0000000), (%esp) /* PTD物理地址 */
71 基本的映射定义好了,我们可以放心的打开分页了
72 我们只需要把PTD的基地址加载进CR3就好了。
77 andl $0xfffff000, %eax # 有点多余,但写上还算明白一点
81 orl $0x80000000, %eax /* 开启分页与地址转换 (CR0.PG=1, CR0.WP=0) */
82 andl $0xfffffffb, %eax
83 orl $0x2, %eax /* 启用x87 FPU (CR0.MP=1, CR0.EM=0) */
88 movl %eax, %cr4 /* CR4.OSFXSR=1, CR4.OSXMMEXCPT=1 */