UefiCpuPkg/MpInitLib: Use NASM struc to avoid hardcode offset
In Windows environment, "dumpbin /disasm" is used to verify the disassembly before and after using NASM struc doesn't change. Signed-off-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Eric Dong <eric.dong@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Cc: Rahul Kumar <rahul1.kumar@intel.com>
This commit is contained in:
@@ -39,21 +39,21 @@ BITS 16
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
mov si, BufferStartLocation
|
||||
mov si, MP_CPU_EXCHANGE_INFO_FIELD (BufferStart)
|
||||
mov ebx, [si]
|
||||
|
||||
mov si, DataSegmentLocation
|
||||
mov si, MP_CPU_EXCHANGE_INFO_FIELD (DataSegment)
|
||||
mov edx, [si]
|
||||
|
||||
;
|
||||
; Get start address of 32-bit code in low memory (<1MB)
|
||||
;
|
||||
mov edi, ModeTransitionMemoryLocation
|
||||
mov edi, MP_CPU_EXCHANGE_INFO_FIELD (ModeTransitionMemory)
|
||||
|
||||
mov si, GdtrLocation
|
||||
mov si, MP_CPU_EXCHANGE_INFO_FIELD (GdtrProfile)
|
||||
o32 lgdt [cs:si]
|
||||
|
||||
mov si, IdtrLocation
|
||||
mov si, MP_CPU_EXCHANGE_INFO_FIELD (IdtrProfile)
|
||||
o32 lidt [cs:si]
|
||||
|
||||
;
|
||||
@@ -82,7 +82,7 @@ Flat32Start: ; protected mode entry point
|
||||
mov esi, ebx
|
||||
|
||||
mov edi, esi
|
||||
add edi, EnableExecuteDisableLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (EnableExecuteDisable)
|
||||
cmp byte [edi], 0
|
||||
jz SkipEnableExecuteDisable
|
||||
|
||||
@@ -96,7 +96,7 @@ Flat32Start: ; protected mode entry point
|
||||
wrmsr
|
||||
|
||||
mov edi, esi
|
||||
add edi, Cr3Location
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (Cr3)
|
||||
mov eax, dword [edi]
|
||||
mov cr3, eax
|
||||
|
||||
@@ -110,35 +110,35 @@ Flat32Start: ; protected mode entry point
|
||||
|
||||
SkipEnableExecuteDisable:
|
||||
mov edi, esi
|
||||
add edi, InitFlagLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)
|
||||
cmp dword [edi], 1 ; 1 == ApInitConfig
|
||||
jnz GetApicId
|
||||
|
||||
; Increment the number of APs executing here as early as possible
|
||||
; This is decremented in C code when AP is finished executing
|
||||
mov edi, esi
|
||||
add edi, NumApsExecutingLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (NumApsExecuting)
|
||||
lock inc dword [edi]
|
||||
|
||||
; AP init
|
||||
mov edi, esi
|
||||
add edi, LockLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (Lock)
|
||||
mov eax, NotVacantFlag
|
||||
|
||||
mov edi, esi
|
||||
add edi, ApIndexLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (ApIndex)
|
||||
mov ebx, 1
|
||||
lock xadd dword [edi], ebx ; EBX = ApIndex++
|
||||
inc ebx ; EBX is CpuNumber
|
||||
|
||||
mov edi, esi
|
||||
add edi, StackSizeLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (StackSize)
|
||||
mov eax, [edi]
|
||||
mov ecx, ebx
|
||||
inc ecx
|
||||
mul ecx ; EAX = StackSize * (CpuNumber + 1)
|
||||
mov edi, esi
|
||||
add edi, StackStartAddressLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (StackStart)
|
||||
add eax, [edi]
|
||||
mov esp, eax
|
||||
jmp CProcedureInvoke
|
||||
@@ -171,18 +171,18 @@ GetProcessorNumber:
|
||||
; Note that BSP may become an AP due to SwitchBsp()
|
||||
;
|
||||
xor ebx, ebx
|
||||
lea eax, [esi + CpuInfoLocation]
|
||||
lea eax, [esi + MP_CPU_EXCHANGE_INFO_FIELD (CpuInfo)]
|
||||
mov edi, [eax]
|
||||
|
||||
GetNextProcNumber:
|
||||
cmp [edi], edx ; APIC ID match?
|
||||
cmp dword [edi + CPU_INFO_IN_HOB.InitialApicId], edx ; APIC ID match?
|
||||
jz ProgramStack
|
||||
add edi, 20
|
||||
add edi, CPU_INFO_IN_HOB_size
|
||||
inc ebx
|
||||
jmp GetNextProcNumber
|
||||
|
||||
ProgramStack:
|
||||
mov esp, [edi + 12]
|
||||
mov esp, dword [edi + CPU_INFO_IN_HOB.ApTopOfStack]
|
||||
|
||||
CProcedureInvoke:
|
||||
push ebp ; push BIST data at top of AP stack
|
||||
@@ -195,11 +195,11 @@ CProcedureInvoke:
|
||||
|
||||
push ebx ; Push ApIndex
|
||||
mov eax, esi
|
||||
add eax, LockLocation
|
||||
add eax, MP_CPU_EXCHANGE_INFO_OFFSET
|
||||
push eax ; push address of exchange info data buffer
|
||||
|
||||
mov edi, esi
|
||||
add edi, ApProcedureLocation
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (CFunction)
|
||||
mov eax, [edi]
|
||||
|
||||
call eax ; Invoke C function
|
||||
@@ -262,17 +262,17 @@ ASM_PFX(AsmGetAddressMap):
|
||||
mov ebp,esp
|
||||
|
||||
mov ebx, [ebp + 24h]
|
||||
mov dword [ebx], RendezvousFunnelProcStart
|
||||
mov dword [ebx + 4h], Flat32Start - RendezvousFunnelProcStart
|
||||
mov dword [ebx + 8h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
|
||||
mov dword [ebx + 0Ch], AsmRelocateApLoopStart
|
||||
mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
|
||||
mov dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart
|
||||
mov dword [ebx + 18h], SwitchToRealProcEnd - SwitchToRealProcStart ; SwitchToRealSize
|
||||
mov dword [ebx + 1Ch], SwitchToRealProcStart - RendezvousFunnelProcStart ; SwitchToRealOffset
|
||||
mov dword [ebx + 20h], SwitchToRealProcStart - Flat32Start ; SwitchToRealNoNxOffset
|
||||
mov dword [ebx + 24h], 0 ; SwitchToRealPM16ModeOffset
|
||||
mov dword [ebx + 28h], 0 ; SwitchToRealPM16ModeSize
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RendezvousFunnelAddress], RendezvousFunnelProcStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.ModeEntryOffset], Flat32Start - RendezvousFunnelProcStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RendezvousFunnelSize], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddress], AsmRelocateApLoopStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset], Flat32Start - RendezvousFunnelProcStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealSize], SwitchToRealProcEnd - SwitchToRealProcStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealOffset], SwitchToRealProcStart - RendezvousFunnelProcStart
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset], SwitchToRealProcStart - Flat32Start
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOffset], 0
|
||||
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSize], 0
|
||||
|
||||
popad
|
||||
ret
|
||||
@@ -302,18 +302,18 @@ ASM_PFX(AsmExchangeRole):
|
||||
mov eax, cr0
|
||||
push eax
|
||||
|
||||
sgdt [esi + 8]
|
||||
sidt [esi + 14]
|
||||
sgdt [esi + CPU_EXCHANGE_ROLE_INFO.Gdtr]
|
||||
sidt [esi + CPU_EXCHANGE_ROLE_INFO.Idtr]
|
||||
|
||||
; Store the its StackPointer
|
||||
mov [esi + 4],esp
|
||||
mov [esi + CPU_EXCHANGE_ROLE_INFO.StackPointer],esp
|
||||
|
||||
; update its switch state to STORED
|
||||
mov byte [esi], CPU_SWITCH_STATE_STORED
|
||||
mov byte [esi + CPU_EXCHANGE_ROLE_INFO.State], CPU_SWITCH_STATE_STORED
|
||||
|
||||
WaitForOtherStored:
|
||||
; wait until the other CPU finish storing its state
|
||||
cmp byte [edi], CPU_SWITCH_STATE_STORED
|
||||
cmp byte [edi + CPU_EXCHANGE_ROLE_INFO.State], CPU_SWITCH_STATE_STORED
|
||||
jz OtherStored
|
||||
pause
|
||||
jmp WaitForOtherStored
|
||||
@@ -321,21 +321,21 @@ WaitForOtherStored:
|
||||
OtherStored:
|
||||
; Since another CPU already stored its state, load them
|
||||
; load GDTR value
|
||||
lgdt [edi + 8]
|
||||
lgdt [edi + CPU_EXCHANGE_ROLE_INFO.Gdtr]
|
||||
|
||||
; load IDTR value
|
||||
lidt [edi + 14]
|
||||
lidt [edi + CPU_EXCHANGE_ROLE_INFO.Idtr]
|
||||
|
||||
; load its future StackPointer
|
||||
mov esp, [edi + 4]
|
||||
mov esp, [edi + CPU_EXCHANGE_ROLE_INFO.StackPointer]
|
||||
|
||||
; update the other CPU's switch state to LOADED
|
||||
mov byte [edi], CPU_SWITCH_STATE_LOADED
|
||||
mov byte [edi + CPU_EXCHANGE_ROLE_INFO.State], CPU_SWITCH_STATE_LOADED
|
||||
|
||||
WaitForOtherLoaded:
|
||||
; wait until the other CPU finish loading new state,
|
||||
; otherwise the data in stack may corrupt
|
||||
cmp byte [esi], CPU_SWITCH_STATE_LOADED
|
||||
cmp byte [esi + CPU_EXCHANGE_ROLE_INFO.State], CPU_SWITCH_STATE_LOADED
|
||||
jz OtherLoaded
|
||||
pause
|
||||
jmp WaitForOtherLoaded
|
||||
|
Reference in New Issue
Block a user