]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuDxe: Add stackless assembly AP entry points
authorJordan Justen <jordan.l.justen@intel.com>
Thu, 13 Nov 2014 18:24:59 +0000 (18:24 +0000)
committerjljusten <jljusten@Edk2>
Thu, 13 Nov 2014 18:24:59 +0000 (18:24 +0000)
The AP startup code simply jumps into this code with the CpuDxe driver
without setting up a stack for the processor.

Therefore, this code must setup the stack before calling into C code.

This is the basic flow:
* AP enters CpuDxe driver code (AsmApEntryPoint) without stack
  - AP grabs a lock
  - AP sets up stack
  - AP calls CpuMp.c:ApEntryPointInC
  - If ApEntryPointInC returns, the lock is freed, and another AP may
    run
  - The AP C code may call AsmApDoneWithCommonStack to indicate that
    the AP is no longer using the stack, and another may therefore
    proceed to use the stack and then call ApEntryPointInC

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16347 6f19259b-4bc3-4df7-8a09-765794883524

UefiCpuPkg/CpuDxe/CpuDxe.inf
UefiCpuPkg/CpuDxe/CpuMp.c
UefiCpuPkg/CpuDxe/CpuMp.h
UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm [new file with mode: 0644]
UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm [new file with mode: 0644]
UefiCpuPkg/CpuDxe/X64/MpAsm.asm [new file with mode: 0644]
UefiCpuPkg/CpuDxe/X64/MpAsm.nasm [new file with mode: 0644]

index e49548f40b1550354b58b8361faa44901f939356..9952eb7007ab801787cdaf920877f0a2ad563d96 100644 (file)
   Ia32/CpuAsm.asm | MSFT\r
   Ia32/CpuAsm.asm | INTEL\r
   Ia32/CpuAsm.S   | GCC\r
+  Ia32/MpAsm.asm  | MSFT\r
+  Ia32/MpAsm.asm  | INTEL\r
+  Ia32/MpAsm.nasm | GCC\r
 \r
 [Sources.X64]\r
   X64/CpuAsm.asm | MSFT\r
   X64/CpuAsm.asm | INTEL\r
   X64/CpuAsm.S   | GCC\r
+  X64/MpAsm.asm  | MSFT\r
+  X64/MpAsm.asm  | INTEL\r
+  X64/MpAsm.nasm | GCC\r
 \r
 [Protocols]\r
   gEfiCpuArchProtocolGuid                       ## PRODUCES\r
index aa564c1f93cdaebf00c78bd39510855f78c49dd6..ea403e8e124310853343f212825fe911fc223e75 100644 (file)
 #include "CpuDxe.h"\r
 #include "CpuMp.h"\r
 \r
+VOID *mCommonStack = 0;\r
+VOID *mTopOfApCommonStack = 0;\r
+\r
+\r
 /**\r
   Application Processor C code entry point.\r
 \r
index 93d054002a3931bfe8a34303f2a4d3365dd7b093..dd2d0e1200ca7b4274eb6b868a5ec126634e5b0b 100644 (file)
@@ -24,5 +24,32 @@ InitializeMpSupport (
   VOID\r
   );\r
 \r
+/**\r
+  The AP entry point that the Startup-IPI target code will jump to.\r
+\r
+  The processor jumps to this code in flat mode, but the processor's\r
+  stack is not initialized.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+AsmApEntryPoint (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Releases the lock preventing other APs from using the shared AP\r
+  stack.\r
+\r
+  Once the AP has transitioned to using a new stack, it can call this\r
+  function to allow another AP to proceed with using the shared stack.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+AsmApDoneWithCommonStack (\r
+  VOID\r
+  );\r
+\r
 #endif // _CPU_MP_H_\r
 \r
diff --git a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm
new file mode 100644 (file)
index 0000000..d476829
--- /dev/null
@@ -0,0 +1,75 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+.586p\r
+.model flat, C\r
+\r
+extern mTopOfApCommonStack:DWORD\r
+extern ApEntryPointInC:PROC\r
+\r
+.code\r
+\r
+;\r
+; This lock only allows one AP to use the mTopOfApCommonStack stack at a time\r
+;\r
+ApStackLock dd      0\r
+\r
+;.code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApEntryPoint (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+AsmApEntryPoint PROC\r
+\r
+    cli\r
+AsmApEntryPointAcquireLock:\r
+lock bts    dword ptr [ApStackLock], 0\r
+    pause\r
+    jc      AsmApEntryPointAcquireLock\r
+\r
+    mov     esp, [mTopOfApCommonStack]\r
+    call    ApEntryPointInC\r
+\r
+    cli\r
+\r
+lock btc    dword ptr [ApStackLock], 0\r
+\r
+    mov     eax, 100h\r
+AsmApEntryPointShareLock:\r
+    pause\r
+    dec     eax\r
+    jnz     AsmApEntryPointShareLock\r
+\r
+    jmp     AsmApEntryPoint\r
+\r
+AsmApEntryPoint ENDP\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApDoneWithCommonStack (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+AsmApDoneWithCommonStack PROC PUBLIC\r
+\r
+lock btc    dword ptr [ApStackLock], 0\r
+    ret\r
+\r
+AsmApDoneWithCommonStack ENDP\r
+\r
+END\r
diff --git a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm
new file mode 100644 (file)
index 0000000..c47cdce
--- /dev/null
@@ -0,0 +1,68 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+extern ASM_PFX(mTopOfApCommonStack)\r
+extern ASM_PFX(ApEntryPointInC)\r
+\r
+SECTION .data\r
+\r
+;\r
+; This lock only allows one AP to use the mTopOfApCommonStack stack at a time\r
+;\r
+ApStackLock:\r
+    dd      0\r
+\r
+SECTION .text\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApEntryPoint (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(AsmApEntryPoint)\r
+ASM_PFX(AsmApEntryPoint):\r
+    cli\r
+AsmApEntryPointAcquireLock:\r
+lock bts    dword [ApStackLock], 0\r
+    pause\r
+    jc      AsmApEntryPointAcquireLock\r
+\r
+    mov     esp, [ASM_PFX(mTopOfApCommonStack)]\r
+    call    ASM_PFX(ApEntryPointInC)\r
+\r
+    cli\r
+\r
+lock btc    dword [ApStackLock], 0\r
+\r
+    mov     eax, 0x100\r
+AsmApEntryPointShareLock:\r
+    pause\r
+    dec     eax\r
+    jnz     AsmApEntryPointShareLock\r
+\r
+    jmp     ASM_PFX(AsmApEntryPoint)\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApDoneWithCommonStack (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(AsmApDoneWithCommonStack)\r
+ASM_PFX(AsmApDoneWithCommonStack):\r
+lock btc    dword [ApStackLock], 0\r
+    ret\r
+\r
diff --git a/UefiCpuPkg/CpuDxe/X64/MpAsm.asm b/UefiCpuPkg/CpuDxe/X64/MpAsm.asm
new file mode 100644 (file)
index 0000000..308de51
--- /dev/null
@@ -0,0 +1,76 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+#include <Base.h>\r
+\r
+extern ASM_PFX(mTopOfApCommonStack):QWORD\r
+extern ASM_PFX(ApEntryPointInC):PROC\r
+\r
+.data\r
+\r
+;\r
+; This lock only allows one AP to use the mTopOfApCommonStack stack at a time\r
+;\r
+ApStackLock:\r
+    dd      0\r
+\r
+.code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApEntryPoint (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+ASM_PFX(AsmApEntryPoint) PROC PUBLIC\r
+\r
+    cli\r
+AsmApEntryPointAcquireLock:\r
+lock bts    dword ptr [ApStackLock], 0\r
+    pause\r
+    jc      AsmApEntryPointAcquireLock\r
+\r
+    mov     rsp, [ASM_PFX(mTopOfApCommonStack)]\r
+    call    ASM_PFX(ApEntryPointInC)\r
+\r
+    cli\r
+\r
+lock btc    dword ptr [ApStackLock], 0\r
+\r
+    mov     eax, 100h\r
+AsmApEntryPointShareLock:\r
+    pause\r
+    dec     eax\r
+    jnz     AsmApEntryPointShareLock\r
+\r
+    jmp     ASM_PFX(AsmApEntryPoint)\r
+\r
+ASM_PFX(AsmApEntryPoint) ENDP\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApDoneWithCommonStack (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+ASM_PFX(AsmApDoneWithCommonStack) PROC PUBLIC\r
+\r
+lock btc    dword ptr [ApStackLock], 0\r
+    ret\r
+\r
+ASM_PFX(AsmApDoneWithCommonStack) ENDP\r
+\r
+END\r
+\r
diff --git a/UefiCpuPkg/CpuDxe/X64/MpAsm.nasm b/UefiCpuPkg/CpuDxe/X64/MpAsm.nasm
new file mode 100644 (file)
index 0000000..e3dc248
--- /dev/null
@@ -0,0 +1,70 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+extern ASM_PFX(mTopOfApCommonStack)\r
+extern ASM_PFX(ApEntryPointInC)\r
+\r
+DEFAULT REL\r
+\r
+SECTION .data\r
+\r
+;\r
+; This lock only allows one AP to use the mTopOfApCommonStack stack at a time\r
+;\r
+ApStackLock:\r
+    dd      0\r
+\r
+SECTION .text\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApEntryPoint (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(AsmApEntryPoint)\r
+ASM_PFX(AsmApEntryPoint):\r
+    cli\r
+AsmApEntryPointAcquireLock:\r
+lock bts    dword [ApStackLock], 0\r
+    pause\r
+    jc      AsmApEntryPointAcquireLock\r
+\r
+    mov     rsp, [ASM_PFX(mTopOfApCommonStack)]\r
+    call    ASM_PFX(ApEntryPointInC)\r
+\r
+    cli\r
+\r
+lock btc    dword [ApStackLock], 0\r
+\r
+    mov     eax, 0x100\r
+AsmApEntryPointShareLock:\r
+    pause\r
+    dec     eax\r
+    jnz     AsmApEntryPointShareLock\r
+\r
+    jmp     ASM_PFX(AsmApEntryPoint)\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmApDoneWithCommonStack (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(AsmApDoneWithCommonStack)\r
+ASM_PFX(AsmApDoneWithCommonStack):\r
+lock btc    dword [ApStackLock], 0\r
+    ret\r
+\r