mov ss, ax\r
\r
mov esi, ebx\r
+ lea edi, [esi + InitFlagLocation]\r
+ cmp qword [edi], 1 ; ApInitConfig\r
+ jnz GetApicId\r
+\r
+ ; AP init\r
mov edi, esi\r
add edi, LockLocation\r
mov rax, NotVacantFlag\r
cmp rax, NotVacantFlag\r
jz TestLock\r
\r
- mov edi, esi\r
- add edi, NumApsExecutingLocation\r
- inc dword [edi]\r
- mov ebx, [edi]\r
+ lea ecx, [esi + NumApsExecutingLocation]\r
+ inc dword [ecx]\r
+ mov ebx, [ecx]\r
\r
-ProgramStack:\r
+Releaselock:\r
+ mov rax, VacantFlag\r
+ xchg qword [edi], rax\r
+ ; program stack\r
mov edi, esi\r
add edi, StackSizeLocation\r
- mov rax, qword [edi]\r
+ mov eax, dword [edi]\r
+ mov ecx, ebx\r
+ inc ecx\r
+ mul ecx ; EAX = StackSize * (CpuNumber + 1)\r
mov edi, esi\r
add edi, StackStartAddressLocation\r
add rax, qword [edi]\r
mov rsp, rax\r
- mov qword [edi], rax\r
+ jmp CProcedureInvoke\r
+\r
+GetApicId:\r
+ mov eax, 0\r
+ cpuid\r
+ cmp eax, 0bh\r
+ jnb X2Apic\r
+ ; Processor is not x2APIC capable, so get 8-bit APIC ID\r
+ mov eax, 1\r
+ cpuid\r
+ shr ebx, 24\r
+ mov edx, ebx\r
+ jmp GetProcessorNumber\r
+\r
+X2Apic:\r
+ ; Processor is x2APIC capable, so get 32-bit x2APIC ID\r
+ mov eax, 0bh\r
+ xor ecx, ecx\r
+ cpuid \r
+ ; edx save x2APIC ID\r
+ \r
+GetProcessorNumber:\r
+ ;\r
+ ; Get processor number for this AP\r
+ ; Note that BSP may become an AP due to SwitchBsp()\r
+ ;\r
+ xor ebx, ebx\r
+ lea eax, [esi + CpuInfoLocation]\r
+ mov edi, [eax]\r
\r
-Releaselock:\r
- mov rax, VacantFlag\r
- mov edi, esi\r
- add edi, LockLocation\r
- xchg qword [edi], rax\r
+GetNextProcNumber:\r
+ cmp dword [edi], edx ; APIC ID match?\r
+ jz ProgramStack\r
+ add edi, 20\r
+ inc ebx\r
+ jmp GetNextProcNumber \r
+\r
+ProgramStack:\r
+ mov rsp, qword [edi + 12]\r
\r
CProcedureInvoke:\r
push rbp ; Push BIST data at top of AP stack\r
mov qword [rcx], rax\r
mov qword [rcx + 8h], LongModeStart - RendezvousFunnelProcStart\r
mov qword [rcx + 10h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
+ mov rax, ASM_PFX(AsmRelocateApLoop)\r
+ mov qword [rcx + 18h], rax\r
+ mov qword [rcx + 20h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart\r
ret\r
\r
;-------------------------------------------------------------------------------------\r