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
This commit is contained in:
Jiamin Ma
2013-10-12 06:31:55 +00:00
committed by jyao1
parent 09acdc0b24
commit f66a43b26e
17 changed files with 234 additions and 62 deletions

View File

@@ -109,6 +109,16 @@ SecNt32PeCoffRelocateImage (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
);
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 (

View File

@@ -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

110
Nt32Pkg/Sec/StackX64.asm Normal file
View File

@@ -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