]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg EbcDxe: Convert Ia32/EbcLowLevel.asm to NASM
authorJordan Justen <jordan.l.justen@intel.com>
Tue, 31 May 2016 01:52:18 +0000 (18:52 -0700)
committerLiming Gao <liming.gao@intel.com>
Tue, 28 Jun 2016 01:51:58 +0000 (09:51 +0800)
The BaseTools/Scripts/ConvertMasmToNasm.py script was used to convert
Ia32/EbcLowLevel.asm to Ia32/EbcLowLevel.nasm

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
MdeModulePkg/Universal/EbcDxe/Ia32/EbcLowLevel.nasm [new file with mode: 0644]

index 0dfe005e7bae34a41682d6cd980ac328188dfa88..44558aaf647bb32152c433b4fd10ad3616d3c9e8 100644 (file)
@@ -39,6 +39,7 @@
 \r
 [Sources.Ia32]\r
   Ia32/EbcSupport.c\r
+  Ia32/EbcLowLevel.nasm\r
   Ia32/EbcLowLevel.S\r
   Ia32/EbcLowLevel.asm\r
 \r
diff --git a/MdeModulePkg/Universal/EbcDxe/Ia32/EbcLowLevel.nasm b/MdeModulePkg/Universal/EbcDxe/Ia32/EbcLowLevel.nasm
new file mode 100644 (file)
index 0000000..29a101d
--- /dev/null
@@ -0,0 +1,197 @@
+;/** @file\r
+;\r
+;    This code provides low level routines that support the Virtual Machine\r
+;    for option ROMs.\r
+;\r
+;  Copyright (c) 2006 - 2011, 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
+;---------------------------------------------------------------------------\r
+; Equate files needed.\r
+;---------------------------------------------------------------------------\r
+\r
+;---------------------------------------------------------------------------\r
+; Assembler options\r
+;---------------------------------------------------------------------------\r
+\r
+SECTION .text\r
+extern ASM_PFX(CopyMem)\r
+extern ASM_PFX(EbcInterpret)\r
+extern ASM_PFX(ExecuteEbcImageEntryPoint)\r
+\r
+;****************************************************************************\r
+; EbcLLCALLEXNative\r
+;\r
+; This function is called to execute an EBC CALLEX instruction\r
+; to native code.\r
+; This instruction requires that we thunk out to external native\r
+; code. For IA32, we simply switch stacks and jump to the\r
+; specified function. On return, we restore the stack pointer\r
+; to its original location.\r
+;\r
+; Destroys no working registers.\r
+;****************************************************************************\r
+; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
+global ASM_PFX(EbcLLCALLEXNative)\r
+ASM_PFX(EbcLLCALLEXNative):\r
+      push   ebp\r
+      push   ebx\r
+      mov    ebp, esp              ; standard function prolog\r
+\r
+      ; Get function address in a register\r
+      ; mov ecx, FuncAddr => mov ecx, dword ptr [FuncAddr]\r
+      mov    ecx, dword [esp + 0xC]\r
+\r
+      ; Set stack pointer to new value\r
+      ; mov eax, NewStackPointer => mov eax, dword ptr [NewSp]\r
+      mov    eax, dword [esp + 0x14]\r
+      mov    edx, dword [esp + 0x10]\r
+      sub    eax, edx\r
+      sub    esp, eax\r
+      mov    ebx, esp\r
+      push   ecx\r
+      push   eax\r
+      push   edx\r
+      push   ebx\r
+      call   ASM_PFX(CopyMem)\r
+      pop    eax\r
+      pop    eax\r
+      pop    eax\r
+      pop    ecx\r
+\r
+      ; Now call the external routine\r
+      call  ecx\r
+\r
+      ; ebp is preserved by the callee. In this function it\r
+      ; equals the original esp, so set them equal\r
+      mov    esp, ebp\r
+\r
+      ; Standard function epilog\r
+      mov      esp, ebp\r
+      pop      ebx\r
+      pop      ebp\r
+      ret\r
+\r
+;****************************************************************************\r
+; EbcLLEbcInterpret\r
+;\r
+; Begin executing an EBC image.\r
+;****************************************************************************\r
+; UINT64 EbcLLEbcInterpret(VOID)\r
+global ASM_PFX(EbcLLEbcInterpret)\r
+ASM_PFX(EbcLLEbcInterpret):\r
+    ;\r
+    ;; mov eax, 0xca112ebc\r
+    ;; mov eax, EbcEntryPoint\r
+    ;; mov ecx, EbcLLEbcInterpret\r
+    ;; jmp ecx\r
+    ;\r
+    ; Caller uses above instruction to jump here\r
+    ; The stack is below:\r
+    ; +-----------+\r
+    ; |  RetAddr  |\r
+    ; +-----------+\r
+    ; |EntryPoint | (EAX)\r
+    ; +-----------+\r
+    ; |   Arg1    | <- EDI\r
+    ; +-----------+\r
+    ; |   Arg2    |\r
+    ; +-----------+\r
+    ; |   ...     |\r
+    ; +-----------+\r
+    ; |   Arg16   |\r
+    ; +-----------+\r
+    ; |   EDI     |\r
+    ; +-----------+\r
+    ; |   ESI     |\r
+    ; +-----------+\r
+    ; |   EBP     | <- EBP\r
+    ; +-----------+\r
+    ; |  RetAddr  | <- ESP is here\r
+    ; +-----------+\r
+    ; |   Arg1    | <- ESI\r
+    ; +-----------+\r
+    ; |   Arg2    |\r
+    ; +-----------+\r
+    ; |   ...     |\r
+    ; +-----------+\r
+    ; |   Arg16   |\r
+    ; +-----------+\r
+    ;\r
+\r
+    ; Construct new stack\r
+    push ebp\r
+    mov  ebp, esp\r
+    push esi\r
+    push edi\r
+    sub  esp, 0x40\r
+    push eax\r
+    mov  esi, ebp\r
+    add  esi, 8\r
+    mov  edi, esp\r
+    add  edi, 4\r
+    mov  ecx, 16\r
+    rep  movsd\r
+\r
+    ; call C-code\r
+    call ASM_PFX(EbcInterpret)\r
+    add  esp, 0x44\r
+    pop  edi\r
+    pop  esi\r
+    pop  ebp\r
+    ret\r
+\r
+;****************************************************************************\r
+; EbcLLExecuteEbcImageEntryPoint\r
+;\r
+; Begin executing an EBC image.\r
+;****************************************************************************\r
+; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)\r
+global ASM_PFX(EbcLLExecuteEbcImageEntryPoint)\r
+ASM_PFX(EbcLLExecuteEbcImageEntryPoint):\r
+    ;\r
+    ;; mov eax, 0xca112ebc\r
+    ;; mov eax, EbcEntryPoint\r
+    ;; mov ecx, EbcLLExecuteEbcImageEntryPoint\r
+    ;; jmp ecx\r
+    ;\r
+    ; Caller uses above instruction to jump here\r
+    ; The stack is below:\r
+    ; +-----------+\r
+    ; |  RetAddr  |\r
+    ; +-----------+\r
+    ; |EntryPoint | (EAX)\r
+    ; +-----------+\r
+    ; |ImageHandle|\r
+    ; +-----------+\r
+    ; |SystemTable|\r
+    ; +-----------+\r
+    ; |  RetAddr  | <- ESP is here\r
+    ; +-----------+\r
+    ; |ImageHandle|\r
+    ; +-----------+\r
+    ; |SystemTable|\r
+    ; +-----------+\r
+    ;\r
+\r
+    ; Construct new stack\r
+    mov  [esp - 0xC], eax\r
+    mov  eax, [esp + 0x4]\r
+    mov  [esp - 0x8], eax\r
+    mov  eax, [esp + 0x8]\r
+    mov  [esp - 0x4], eax\r
+\r
+    ; call C-code\r
+    sub  esp, 0xC\r
+    call ASM_PFX(ExecuteEbcImageEntryPoint)\r
+    add  esp, 0xC\r
+    ret\r
+\r