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