Architectural Support: x86_64 (#37)
[lunaix-os.git] / lunaix-os / arch / x86 / boot / x86_64 / prologue64.S
1 /* 高半核入口点 - 0xC0000000 */
2
3 #define __ASM__
4 #include <sys/abi.h>
5 #include <sys/failsafe.h>
6
7 .section .bss.kstack
8     .global __kinit_stack_end
9     
10     .align 16
11     __kinit_stack_end:
12         .skip 2048, 0
13     __kinit_stack_top:
14
15
16 .section .text
17     .global hhk_entry_
18     hhk_entry_:
19
20         movq $__kinit_stack_top, %rsp
21         andq $stack_alignment, %rsp
22
23         movq $__kinit_stack_end, %rax
24         movl $STACK_SANITY, (%rax)
25         movl $STACK_SANITY, 4(%rax)
26         movl $STACK_SANITY, 8(%rax)
27         movl $STACK_SANITY, 12(%rax)
28
29         andq $stack_alignment, %rsp
30         subq $16, %rsp
31
32         # replace the temporary gdt
33         call _init_gdt
34
35         movq $_gdt, 2(%rsp)
36         movw _gdt_limit, %ax
37         movw %ax, (%rsp)
38         lgdt (%rsp)
39         
40         # do a far jump to switch cs
41         pushq $KCODE_SEG
42         pushq $_after_gdt
43         retfq
44
45     _after_gdt:
46
47         # initialize segment registers
48         # we will not touch them again in x86_64
49         movw $KDATA_SEG, %cx
50         movw %cx, %es
51         movw %cx, %ds
52         movw %cx, %ss
53
54         # perform arch-specific initialization before diving into kernel
55         call arch_preinit
56
57         # 加载 IDT
58         movq $_idt, 2(%rsp)
59         movw _idt_limit, %ax
60         movw %ax, (%rsp)
61         lidt (%rsp)
62
63         /* 加载TSS段选择器 */
64         movw $TSS_SEG, %ax
65         ltr %ax
66
67         xorq %rbp, %rbp
68         movq $bhctx_buffer, %rdi       # mb_parser.c
69         call kernel_bootstrap
70
71     1:
72         hlt
73         jmp 1b