xref: /DragonOS/kernel/src/arch/x86_64/asm/apu_boot.S (revision 86ee1395de7c614865236ee15071c3603b794e44)
1#include "../common/asm.h"
2#include <asm/apu_boot.h>
3
4
5.align 0x1000  // 按照4k对齐
6
7.section .text
8.code16
9
10ENTRY(_apu_boot_start)
11_apu_boot_base = .
12    cli
13    wbinvd  // 将处理器缓存同步到内存中
14
15    mov %cs, %ax
16    mov %ax, %ds
17    mov %ax, %es
18    mov %ax, %ss
19    mov %ax, %fs
20    mov %ax, %gs
21
22    // 设置栈指针
23    movl $(_apu_boot_tmp_stack_end - _apu_boot_base), %esp
24
25    // 计算ap处理器引导程序的基地址
26    mov %cs, %ax
27    movzx %ax, %esi
28    shll $4, %esi
29
30
31    // set gdt and 32bit/64bit code addr
32
33    leal (_apu_code32 - _apu_boot_base)(%esi), %eax
34    movl %eax, (_apu_code32_vector - _apu_boot_base)
35
36    leal (_apu_code64 - _apu_boot_base)(%esi), %eax
37    movl %eax, (_apu_code64_vector - _apu_boot_base)
38
39    leal (_apu_tmp_gdt - _apu_boot_base)(%esi), %eax
40    movl %eax, (_apu_tmp_gdt + 2 - _apu_boot_base)
41
42// 从实模式切换到保护模式
43
44    lidtl _apu_tmp_idt - _apu_boot_base
45    lgdtl _apu_tmp_gdt - _apu_boot_base
46
47    // 操作cr0控制器,使能保护模式
48    smsw %ax
49    bts $0, %ax
50    lmsw %ax
51
52    // 转到保护模式
53    ljmpl *(_apu_code32_vector - _apu_boot_base)
54
55
56.code32
57.align 0x1000
58_apu_code32:
59    # 转到长模式
60
61    mov $0x10, %ax
62    mov %ax, %ds
63    mov %ax, %es
64    mov %ax, %ss
65    mov %ax, %fs
66    mov %ax, %gs
67
68// 设置栈指针
69    leal (_apu_boot_tmp_stack_end - _apu_boot_base)(%esi), %eax
70    movl %eax, %esp
71
72    // 1. 允许 PAE
73    mov %cr4, %eax
74    or $(1<<5), %eax
75    mov %eax, %cr4
76
77    movl $enter_head_from_ap_boot, %eax
78    jmpl	*%eax
79    hlt
80
81
82
83.code64
84.align 0x1000
85_apu_code64:
86
87    hlt
88
89
90.align 0x1000
91_apu_tmp_idt:
92	.word	0
93	.word	0,0
94
95.align 0x1000
96_apu_tmp_gdt:
97    .short _apu_tmp_gdt_end - _apu_tmp_gdt -1
98    .long _apu_tmp_gdt - _apu_boot_base
99    .short 0
100    .quad	0x00cf9a000000ffff
101	.quad	0x00cf92000000ffff
102	.quad	0x0020980000000000
103	.quad	0x0000920000000000
104_apu_tmp_gdt_end:
105
106.align 0x1000
107_apu_code32_vector:
108	.long	_apu_code32 - _apu_boot_base
109	.word	0x08,0
110
111.align 0x1000
112_apu_code64_vector:
113	.long	_apu_code64 - _apu_boot_base
114	.word	0x18,0
115
116.align 0x1000
117ENTRY(_apu_boot_tmp_stack_start)
118	.skip	APU_BOOT_TMP_STACK_SIZE
119_apu_boot_tmp_stack_end:
120
121ENTRY(_apu_boot_end)
122
123