From: Jordan Justen <[email protected]>
TODO: Port to MASM
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 <[email protected]>
---
UefiCpuPkg/CpuDxe/CpuDxe.inf | 2 ++
UefiCpuPkg/CpuDxe/CpuMp.c | 4 +++
UefiCpuPkg/CpuDxe/CpuMp.h | 6 ++++
UefiCpuPkg/CpuDxe/Ia32/MpAsm.S | 62 ++++++++++++++++++++++++++++++++++++++++++
UefiCpuPkg/CpuDxe/X64/MpAsm.S | 62 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 136 insertions(+)
create mode 100644 UefiCpuPkg/CpuDxe/Ia32/MpAsm.S
create mode 100644 UefiCpuPkg/CpuDxe/X64/MpAsm.S
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index f582cfb..77ce607 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -53,11 +53,13 @@
Ia32/CpuAsm.asm | MSFT
Ia32/CpuAsm.asm | INTEL
Ia32/CpuAsm.S | GCC
+ Ia32/MpAsm.S | GCC
[Sources.X64]
X64/CpuAsm.asm | MSFT
X64/CpuAsm.asm | INTEL
X64/CpuAsm.S | GCC
+ X64/MpAsm.S | GCC
[Protocols]
gEfiCpuArchProtocolGuid
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index 53b2377..cb63b24 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -15,6 +15,10 @@
#include "CpuDxe.h"
#include "CpuMp.h"
+VOID *mCommonStack = 0;
+VOID *mTopOfApCommonStack = 0;
+
+
VOID
EFIAPI
ApEntryPointInC (
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h
index 9402854..94a1ece 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.h
+++ b/UefiCpuPkg/CpuDxe/CpuMp.h
@@ -19,5 +19,11 @@ VOID InitializeMpSupport (
VOID
);
+VOID
+EFIAPI
+AsmApEntryPoint (
+ VOID
+ );
+
#endif // _CPU_MP_H_
diff --git a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S
new file mode 100644
index 0000000..2b3d298
--- /dev/null
+++ b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S
@@ -0,0 +1,62 @@
+#
+#
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD
License
+# which accompanies this distribution. The full text of the license may be
found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+
+#
+# point to the external interrupt vector table
+#
+ApStackLock:
+ .long 0
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmApEntryPoint (
+# VOID
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(AsmApEntryPoint)
+ASM_PFX(AsmApEntryPoint):
+ cli
+AsmApEntryPointAcquireLock:
+lock btsl $0, ApStackLock
+ pause
+ jc AsmApEntryPointAcquireLock
+
+ movl (ASM_PFX(mTopOfApCommonStack)), %esp
+ call ASM_PFX(ApEntryPointInC)
+
+ cli
+
+lock btcl $0, ApStackLock
+
+ movl $0x100, %eax
+AsmApEntryPointShareLock:
+ pause
+ decl %eax
+ jnz AsmApEntryPointShareLock
+
+ jmp ASM_PFX(AsmApEntryPoint)
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmApDoneWithCommonStack (
+# VOID
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(AsmApDoneWithCommonStack)
+ASM_PFX(AsmApDoneWithCommonStack):
+lock btcl $0, ApStackLock
+ ret
+
diff --git a/UefiCpuPkg/CpuDxe/X64/MpAsm.S b/UefiCpuPkg/CpuDxe/X64/MpAsm.S
new file mode 100644
index 0000000..cfad551
--- /dev/null
+++ b/UefiCpuPkg/CpuDxe/X64/MpAsm.S
@@ -0,0 +1,62 @@
+#
+#
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD
License
+# which accompanies this distribution. The full text of the license may be
found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+
+#
+# point to the external interrupt vector table
+#
+ApStackLock:
+ .long 0
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmApEntryPoint (
+# VOID
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(AsmApEntryPoint)
+ASM_PFX(AsmApEntryPoint):
+ cli
+AsmApEntryPointAcquireLock:
+lock btsl $0, ApStackLock
+ pause
+ jc AsmApEntryPointAcquireLock
+
+ movq (ASM_PFX(mTopOfApCommonStack)), %rsp
+ call ASM_PFX(ApEntryPointInC)
+
+ cli
+
+lock btcl $0, ApStackLock
+
+ movl $0x100, %eax
+AsmApEntryPointShareLock:
+ pause
+ decl %eax
+ jnz AsmApEntryPointShareLock
+
+ jmp ASM_PFX(AsmApEntryPoint)
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmApDoneWithCommonStack (
+# VOID
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(AsmApDoneWithCommonStack)
+ASM_PFX(AsmApDoneWithCommonStack):
+lock btcl $0, ApStackLock
+ ret
+
--
1.9.3
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel