x86_64: acpi: bring up other APs in long mode

This commit is contained in:
2023-05-01 18:13:44 +01:00
parent 223b37a113
commit 4677c881e1
6 changed files with 201 additions and 114 deletions

View File

@@ -20,18 +20,21 @@ acpi_bsp_lapic_id:
.extern __ap_stack_top
.extern __bsp_done
.extern __this_ap_ok
.extern __all_ap_ok
.extern ap_startup
.type ap_startup, @function
.global ap_trampoline_code
.global ap_trampoline
# this code will be relocated to 0x8000, sets up environment for calling a C function
.code16
ap_trampoline_code:
.align 0x100
ap_trampoline:
cli
cld
ljmp $0, $0x8040
ljmp $0, $0x8080
.align 16
_L8010_GDT_table:
.long 0, 0
@@ -43,18 +46,26 @@ _L8030_GDT_value:
.long 0x8010
.long 0, 0
.align 64
_L8040:
_L8040_GDT64_table:
.long 0, 0
.long 0x0000ffff, 0x002f9a00 # kernel code
.long 0x0000ffff, 0x002f9200 # kernel data
_L8058_GDT64_value:
.word _L8058_GDT64_value - _L8040_GDT64_table - 1
.quad 0x8040
.align 64
_L8080:
xorw %ax, %ax
movw %ax, %ds
lgdtl 0x8030
movl %cr0, %eax
orl $1, %eax
movl %eax, %cr0
ljmp $8, $0x8060
ljmp $8, $0x80a0
.align 32
.code32
_L8060:
_L80A0:
movw $16, %ax
movw %ax, %ds
movw %ax, %ss
@@ -63,20 +74,34 @@ _L8060:
cpuid
shrl $24, %ebx
movl %ebx, %edi
movl $0x9000, %eax
movl %cr4, %eax
orl $0xb0, %eax
movl %eax, %cr4
movl $0x8ff8, %eax
movl (%eax), %eax
mov %eax, %cr3
movl $0xC0000080, %ecx
rdmsr
# enable long mode and the 'syscall/sysret' instructions
orl $0x00000101, %eax
wrmsr
movl $0x8058, %eax
lgdt (%eax)
movl %cr0, %ecx
orl $0x8000002a, %ecx
movl %ecx, %cr0
ljmpl $0x08, $0x8100
.code64
.align 64
_L8100:
mov (__ap_stack_top), %rsp
movabsq $(ap_trampoline_exit), %rax
callq *%rax
hlt
# set up 32k stack, one for each core. It is important that all core must have its own stack
#shll $15, %ebx
#movl __ap_stack_top, %esp
#subl %ebx, %esp
#pushl %edi
# spinlock, wait for the BSP to finish
#1: pause
#cmpb $0, __bsp_done
#jz 1b
#lock incb aprunning
# jump into C code (should never return)
#ljmp $8, $ap_startup