summaryrefslogtreecommitdiffstats
path: root/Nt32Pkg/Sec
diff options
context:
space:
mode:
authorJiamin Ma <mjmthy@gmail.com>2013-10-12 06:31:55 +0000
committerjyao1 <jyao1@6f19259b-4bc3-4df7-8a09-765794883524>2013-10-12 06:31:55 +0000
commitf66a43b26e6e0f4c1e5871dd3a88f2970b3abf87 (patch)
treef381d6fe0136f2949e4afa2367ec9b31a2e6e367 /Nt32Pkg/Sec
parent09acdc0b24ac50f8623609d67ccc52a785b4fe57 (diff)
downloadedk2-f66a43b26e6e0f4c1e5871dd3a88f2970b3abf87.tar.gz
edk2-f66a43b26e6e0f4c1e5871dd3a88f2970b3abf87.tar.bz2
edk2-f66a43b26e6e0f4c1e5871dd3a88f2970b3abf87.zip
We enabled X64 native version NT32, and made it works on Windows 7 X64 OS.
Signed-off-by: Jiamin Ma <mjmthy@gmail.com> Reviewed by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed by: Liming Gao <liming.gao@intel.com> Reviewed by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14766 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Nt32Pkg/Sec')
-rw-r--r--Nt32Pkg/Sec/SecMain.c14
-rw-r--r--Nt32Pkg/Sec/SecMain.inf11
-rw-r--r--Nt32Pkg/Sec/StackX64.asm110
3 files changed, 134 insertions, 1 deletions
diff --git a/Nt32Pkg/Sec/SecMain.c b/Nt32Pkg/Sec/SecMain.c
index a1d43d2eba..602cca9b1b 100644
--- a/Nt32Pkg/Sec/SecMain.c
+++ b/Nt32Pkg/Sec/SecMain.c
@@ -110,6 +110,16 @@ SecNt32PeCoffRelocateImage (
);
VOID
+EFIAPI
+PeiSwitchStacks (
+ IN SWITCH_STACK_ENTRY_POINT EntryPoint,
+ IN VOID *Context1, OPTIONAL
+ IN VOID *Context2, OPTIONAL
+ IN VOID *Context3, OPTIONAL
+ IN VOID *NewStack
+ );
+
+VOID
SecPrint (
CHAR8 *Format,
...
@@ -129,7 +139,7 @@ SecPrint (
WriteFile (
GetStdHandle (STD_OUTPUT_HANDLE),
Buffer,
- CharCount,
+ (DWORD)CharCount,
(LPDWORD)&CharCount,
NULL
);
@@ -505,6 +515,7 @@ Returns:
return EFI_SUCCESS;
}
+#if defined (MDE_CPU_IA32)
/**
Transfers control to a function starting with a new stack.
@@ -562,6 +573,7 @@ PeiSwitchStacks (
//
ASSERT (FALSE);
}
+#endif
VOID
SecLoadFromCore (
diff --git a/Nt32Pkg/Sec/SecMain.inf b/Nt32Pkg/Sec/SecMain.inf
index e9596b9b13..fee68e0952 100644
--- a/Nt32Pkg/Sec/SecMain.inf
+++ b/Nt32Pkg/Sec/SecMain.inf
@@ -31,8 +31,13 @@
WinNtThunk.c
FwVol.c
SecMain.c
+
+[Sources.ia32]
Stack.asm
+[Sources.x64]
+ StackX64.asm
+
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
@@ -68,6 +73,12 @@
MSFT:*_*_IA32_ASM_FLAGS == /nologo /W3 /WX /c /coff /Cx /Zd /W0 /Zi
MSFT:*_*_IA32_ASMLINK_FLAGS == /link /nologo /tiny
+ MSFT:*_*_X64_DLINK_FLAGS == /out:"$(BIN_DIR)\SecMain.exe" /base:0x10000000 /pdb:"$(BIN_DIR)\SecMain.pdb" /LIBPATH:"$(VCINSTALLDIR)\Lib\AMD64" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib\AMD64" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:AMD64 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib Advapi32.lib
+ MSFT:*_*_X64_CC_FLAGS == /nologo /W4 /WX /Gy /c /D UNICODE /Od /FIAutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE
+ MSFT:*_*_X64_PP_FLAGS == /nologo /E /TC /FIAutoGen.h
+ MSFT:*_*_X64_ASM_FLAGS == /nologo /W3 /WX /c /Cx /Zd /W0 /Zi
+ MSFT:*_*_X64_ASMLINK_FLAGS == /link /nologo
+
INTEL:*_*_IA32_DLINK_FLAGS == /out:"$(BIN_DIR)\SecMain.exe" /base:0x10000000 /pdb:"$(BIN_DIR)\SecMain.pdb" /LIBPATH:"C:\Program Files\Intel\Compiler\C++\9.1\IA32\Lib" /LIBPATH:"$(VCINSTALLDIR)\Lib" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib
INTEL:*_*_IA32_CC_FLAGS == /nologo /W4 /WX /Gy /c /D UNICODE /Od /FIAutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE
INTEL:*_*_IA32_PP_FLAGS == /nologo /E /TC /FIAutoGen.h
diff --git a/Nt32Pkg/Sec/StackX64.asm b/Nt32Pkg/Sec/StackX64.asm
new file mode 100644
index 0000000000..2327e2eeac
--- /dev/null
+++ b/Nt32Pkg/Sec/StackX64.asm
@@ -0,0 +1,110 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2013, 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.
+;
+; Module Name:
+;
+; Stack.asm
+;
+; Abstract:
+;
+; Switch the stack from temporary memory to permenent memory.
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; SecSwitchStack (
+; UINT32 TemporaryMemoryBase,
+; UINT32 PermenentMemoryBase
+; );
+;------------------------------------------------------------------------------
+SecSwitchStack PROC
+ mov [rsp + 08h], rcx
+ mov [rsp + 10h], rdx
+
+ ;
+ ; Save three register: eax, ebx, ecx
+ ;
+ push rax
+ push rbx
+ push rcx
+ push rdx
+
+ ;
+ ; !!CAUTION!! this function address's is pushed into stack after
+ ; migration of whole temporary memory, so need save it to permenent
+ ; memory at first!
+ ;
+
+ mov rbx, [rsp + 28h] ; Save the first parameter
+ mov rcx, [rsp + 30h] ; Save the second parameter
+
+ ;
+ ; Save this function's return address into permenent memory at first.
+ ; Then, Fixup the esp point to permenent memory
+ ;
+ mov rax, rsp
+ sub rax, rbx
+ add rax, rcx
+ mov rdx, qword ptr [rsp] ; copy pushed register's value to permenent memory
+ mov qword ptr [rax], rdx
+ mov rdx, qword ptr [rsp + 8]
+ mov qword ptr [rax + 8], rdx
+ mov rdx, qword ptr [rsp + 10h]
+ mov qword ptr [rax + 10h], rdx
+ mov rdx, qword ptr [rsp + 18h]
+ mov qword ptr [rax + 18h], rdx
+ mov rdx, qword ptr [rsp + 20h] ; Update this function's return address into permenent memory
+ mov qword ptr [rax + 20h], rdx
+ mov rsp, rax ; From now, esp is pointed to permenent memory
+
+ ;
+ ; Fixup the ebp point to permenent memory
+ ;
+ mov rax, rbp
+ sub rax, rbx
+ add rax, rcx
+ mov rbp, rax ; From now, ebp is pointed to permenent memory
+
+ pop rdx
+ pop rcx
+ pop rbx
+ pop rax
+ ret
+SecSwitchStack ENDP
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; PeiSwitchStacks (
+; IN SWITCH_STACK_ENTRY_POINT EntryPoint,
+; IN VOID *Context1, OPTIONAL
+; IN VOID *Context2, OPTIONAL
+; IN VOID *Context3, OPTIONAL
+; IN VOID *NewStack
+; )
+;------------------------------------------------------------------------------
+PeiSwitchStacks PROC
+ mov rax, rcx
+ mov rcx, rdx
+ mov rdx, r8
+ mov r8, r9
+ mov rsp, [rsp + 28h]
+ sub rsp, 20h
+ call rax
+ jmp $
+ ret
+PeiSwitchStacks ENDP
+
+ END