NOTE: Didn't test building and running the code.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <[email protected]>
---
 UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm | 49 ++++++++++++++++++++++++++++++++++++++++
 UefiCpuPkg/CpuDxe/X64/MpAsm.asm  | 47 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm
index d476829..00e288a 100644
--- a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm
+++ b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm
@@ -16,6 +16,10 @@
 
 extern mTopOfApCommonStack:DWORD
 extern ApEntryPointInC:PROC
+extern mIndexOfProcessors:DWORD
+extern mCpuExchangeData:PTR DWORD
+extern gApStackSize:DWORD
+
 
 .code
 
@@ -72,4 +76,49 @@ lock btc    dword ptr [ApStackLock], 0
 
 AsmApDoneWithCommonStack ENDP
 
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; AsmApSwitchStack (
+;   VOID
+;   );
+;------------------------------------------------------------------------------
+AsmApSwitchStack PROC PUBLIC
+
+AsmApAquireStackLock:
+lock bts   dword ptr [ApStackLock], 0
+    pause
+    jc     AsmApAquireStackLock
+
+    ; calculate the new stack top address of each AP's:
+    ;   %rsp = NewStack + gApStackSize * mIndexOfProcessors
+    ;
+    mov     eax, [mCpuExchangeData + 04h]
+    mov     edi, [gApStackSize]
+    mov     ebx, [mIndexOfProcessors]
+    imul    ebx, edi
+    add     eax, ebx
+
+    mov     esp, eax
+    sub     esp, 8
+
+    call    [mCpuExchangeData]
+
+    ret
+AsmApSwitchStack ENDP
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; AsmApReleaseLock (
+;   VOID
+;   );
+;------------------------------------------------------------------------------
+AsmApReleaseLock PROC PUBLIC
+
+lock btc  dword ptr [ApStackLock], 0
+    ret
+
+AsmApReleaseLock ENDP
+
 END
diff --git a/UefiCpuPkg/CpuDxe/X64/MpAsm.asm b/UefiCpuPkg/CpuDxe/X64/MpAsm.asm
index 308de51..18b1dba 100644
--- a/UefiCpuPkg/CpuDxe/X64/MpAsm.asm
+++ b/UefiCpuPkg/CpuDxe/X64/MpAsm.asm
@@ -15,6 +15,9 @@
 
 extern ASM_PFX(mTopOfApCommonStack):QWORD
 extern ASM_PFX(ApEntryPointInC):PROC
+extern ASM_PFX(mIndexOfProcessors):QWORD
+extern ASM_PFX(mCpuExchangeData):PTR QWORD
+extern ASM_PFX(gApStackSize):QWORD
 
 .data
 
@@ -72,5 +75,47 @@ lock btc    dword ptr [ApStackLock], 0
 
 ASM_PFX(AsmApDoneWithCommonStack) ENDP
 
-END
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; AsmApSwitchStack (
+;   VOID
+;   );
+;------------------------------------------------------------------------------
+ASM_PFX(AsmApSwitchStack) PROC PUBLIC
+
+AsmApAquireStackLock:
+lock bts   dword ptr [ApStackLock], 0
+    pause
+    jc     AsmApAquireStackLock
+
+    ; calculate the new stack top address of each AP's:
+    ;   %rsp = NewStack + gApStackSize * mIndexOfProcessors
+    ;
+    mov     r9,  [ASM_PFX(mCpuExchangeData) + 08h]
+    mov     edi, [ASM_PFX(gApStackSize)]
+    mov     ebx, [ASM_PFX(mIndexOfProcessors)]
+    imul    ebx, edi
+    add     r9,  rbx
+
+    lea     rsp, [r9 - 20h]
+    call    [ASM_PFX(mCpuExchangeData)]
+
+    ret
+ASM_PFX(AsmApSwitchStack) ENDP
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; AsmApReleaseLock (
+;   VOID
+;   );
+;------------------------------------------------------------------------------
+ASM_PFX(AsmApReleaseLock) PROC PUBLIC
+
+lock btc  dword ptr [ApStackLock], 0
+    ret
+
+ASM_PFX(AsmApReleaseLock) ENDP
 
+END
-- 
1.9.3


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to