2008-04-11 05:36:07 +02:00
|
|
|
;/** @file
|
2008-05-21 06:03:40 +02:00
|
|
|
;
|
|
|
|
; This code provides low level routines that support the Virtual Machine
|
|
|
|
; for option ROMs.
|
|
|
|
;
|
2011-11-21 09:35:14 +01:00
|
|
|
; Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:33:45 +02:00
|
|
|
; This program and the accompanying materials
|
2008-04-11 05:36:07 +02:00
|
|
|
; 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
|
2008-05-21 06:03:40 +02:00
|
|
|
;
|
2008-04-11 05:36:07 +02:00
|
|
|
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2008-05-21 06:03:40 +02:00
|
|
|
;
|
2008-04-11 05:36:07 +02:00
|
|
|
;**/
|
|
|
|
|
|
|
|
page ,132
|
|
|
|
title VM ASSEMBLY LANGUAGE ROUTINES
|
2007-07-18 16:32:48 +02:00
|
|
|
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
; Equate files needed.
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.XLIST
|
|
|
|
|
|
|
|
.LIST
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
; Assembler options
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.686p
|
2011-11-22 09:07:30 +01:00
|
|
|
.model flat, C
|
2008-04-11 05:36:07 +02:00
|
|
|
.code
|
2011-11-22 09:07:30 +01:00
|
|
|
CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD
|
|
|
|
EbcInterpret PROTO
|
|
|
|
ExecuteEbcImageEntryPoint PROTO
|
2007-07-18 16:32:48 +02:00
|
|
|
|
|
|
|
;****************************************************************************
|
|
|
|
; EbcLLCALLEXNative
|
|
|
|
;
|
|
|
|
; This function is called to execute an EBC CALLEX instruction
|
2008-04-11 05:36:07 +02:00
|
|
|
; to native code.
|
2007-07-18 16:32:48 +02:00
|
|
|
; This instruction requires that we thunk out to external native
|
2008-04-11 05:36:07 +02:00
|
|
|
; code. For IA32, we simply switch stacks and jump to the
|
2007-07-18 16:32:48 +02:00
|
|
|
; specified function. On return, we restore the stack pointer
|
|
|
|
; to its original location.
|
|
|
|
;
|
|
|
|
; Destroys no working registers.
|
|
|
|
;****************************************************************************
|
2011-11-21 09:35:14 +01:00
|
|
|
; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
|
2011-11-22 09:07:30 +01:00
|
|
|
EbcLLCALLEXNative PROC PUBLIC
|
2007-07-18 16:32:48 +02:00
|
|
|
push ebp
|
|
|
|
push ebx
|
|
|
|
mov ebp, esp ; standard function prolog
|
2008-04-11 05:36:07 +02:00
|
|
|
|
2007-07-18 16:32:48 +02:00
|
|
|
; Get function address in a register
|
|
|
|
; mov ecx, FuncAddr => mov ecx, dword ptr [FuncAddr]
|
|
|
|
mov ecx, dword ptr [esp]+0Ch
|
2008-04-11 05:36:07 +02:00
|
|
|
|
2007-07-18 16:32:48 +02:00
|
|
|
; Set stack pointer to new value
|
|
|
|
; mov eax, NewStackPointer => mov eax, dword ptr [NewSp]
|
|
|
|
mov eax, dword ptr [esp] + 14h
|
|
|
|
mov edx, dword ptr [esp] + 10h
|
|
|
|
sub eax, edx
|
2008-04-11 05:36:07 +02:00
|
|
|
sub esp, eax
|
2007-07-18 16:32:48 +02:00
|
|
|
mov ebx, esp
|
|
|
|
push ecx
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
push ebx
|
|
|
|
call CopyMem
|
|
|
|
pop eax
|
|
|
|
pop eax
|
|
|
|
pop eax
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
; Now call the external routine
|
|
|
|
call ecx
|
2008-04-11 05:36:07 +02:00
|
|
|
|
2007-07-18 16:32:48 +02:00
|
|
|
; ebp is preserved by the callee. In this function it
|
|
|
|
; equals the original esp, so set them equal
|
|
|
|
mov esp, ebp
|
|
|
|
|
|
|
|
; Standard function epilog
|
|
|
|
mov esp, ebp
|
|
|
|
pop ebx
|
|
|
|
pop ebp
|
|
|
|
ret
|
2011-11-22 09:07:30 +01:00
|
|
|
EbcLLCALLEXNative ENDP
|
2007-07-18 16:32:48 +02:00
|
|
|
|
2011-11-22 09:07:30 +01:00
|
|
|
;****************************************************************************
|
|
|
|
; EbcLLEbcInterpret
|
2007-07-18 16:32:48 +02:00
|
|
|
;
|
2011-11-22 09:07:30 +01:00
|
|
|
; Begin executing an EBC image.
|
|
|
|
;****************************************************************************
|
|
|
|
; UINT64 EbcLLEbcInterpret(VOID)
|
|
|
|
EbcLLEbcInterpret PROC PUBLIC
|
|
|
|
;
|
|
|
|
;; mov eax, 0xca112ebc
|
|
|
|
;; mov eax, EbcEntryPoint
|
|
|
|
;; mov ecx, EbcLLEbcInterpret
|
|
|
|
;; jmp ecx
|
|
|
|
;
|
|
|
|
; Caller uses above instruction to jump here
|
|
|
|
; The stack is below:
|
|
|
|
; +-----------+
|
|
|
|
; | RetAddr |
|
|
|
|
; +-----------+
|
|
|
|
; |EntryPoint | (EAX)
|
|
|
|
; +-----------+
|
|
|
|
; | Arg1 | <- EDI
|
|
|
|
; +-----------+
|
|
|
|
; | Arg2 |
|
|
|
|
; +-----------+
|
|
|
|
; | ... |
|
|
|
|
; +-----------+
|
|
|
|
; | Arg16 |
|
|
|
|
; +-----------+
|
|
|
|
; | EDI |
|
|
|
|
; +-----------+
|
|
|
|
; | ESI |
|
|
|
|
; +-----------+
|
|
|
|
; | EBP | <- EBP
|
|
|
|
; +-----------+
|
|
|
|
; | RetAddr | <- ESP is here
|
|
|
|
; +-----------+
|
|
|
|
; | Arg1 | <- ESI
|
|
|
|
; +-----------+
|
|
|
|
; | Arg2 |
|
|
|
|
; +-----------+
|
|
|
|
; | ... |
|
|
|
|
; +-----------+
|
|
|
|
; | Arg16 |
|
|
|
|
; +-----------+
|
|
|
|
;
|
|
|
|
|
|
|
|
; Construct new stack
|
|
|
|
push ebp
|
|
|
|
mov ebp, esp
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
sub esp, 40h
|
|
|
|
push eax
|
|
|
|
mov esi, ebp
|
|
|
|
add esi, 8
|
|
|
|
mov edi, esp
|
|
|
|
add edi, 4
|
|
|
|
mov ecx, 16
|
|
|
|
rep movsd
|
|
|
|
|
|
|
|
; call C-code
|
|
|
|
call EbcInterpret
|
|
|
|
add esp, 44h
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebp
|
|
|
|
ret
|
|
|
|
EbcLLEbcInterpret ENDP
|
|
|
|
|
|
|
|
;****************************************************************************
|
|
|
|
; EbcLLExecuteEbcImageEntryPoint
|
2007-07-18 16:32:48 +02:00
|
|
|
;
|
2011-11-22 09:07:30 +01:00
|
|
|
; Begin executing an EBC image.
|
|
|
|
;****************************************************************************
|
|
|
|
; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)
|
|
|
|
EbcLLExecuteEbcImageEntryPoint PROC PUBLIC
|
|
|
|
;
|
|
|
|
;; mov eax, 0xca112ebc
|
|
|
|
;; mov eax, EbcEntryPoint
|
|
|
|
;; mov ecx, EbcLLExecuteEbcImageEntryPoint
|
|
|
|
;; jmp ecx
|
|
|
|
;
|
|
|
|
; Caller uses above instruction to jump here
|
|
|
|
; The stack is below:
|
|
|
|
; +-----------+
|
|
|
|
; | RetAddr |
|
|
|
|
; +-----------+
|
|
|
|
; |EntryPoint | (EAX)
|
|
|
|
; +-----------+
|
|
|
|
; |ImageHandle|
|
|
|
|
; +-----------+
|
|
|
|
; |SystemTable|
|
|
|
|
; +-----------+
|
|
|
|
; | RetAddr | <- ESP is here
|
|
|
|
; +-----------+
|
|
|
|
; |ImageHandle|
|
|
|
|
; +-----------+
|
|
|
|
; |SystemTable|
|
|
|
|
; +-----------+
|
|
|
|
;
|
|
|
|
|
|
|
|
; Construct new stack
|
|
|
|
mov [esp - 0Ch], eax
|
|
|
|
mov eax, [esp + 04h]
|
|
|
|
mov [esp - 08h], eax
|
|
|
|
mov eax, [esp + 08h]
|
|
|
|
mov [esp - 04h], eax
|
|
|
|
|
|
|
|
; call C-code
|
|
|
|
sub esp, 0Ch
|
|
|
|
call ExecuteEbcImageEntryPoint
|
|
|
|
add esp, 0Ch
|
2007-07-18 16:32:48 +02:00
|
|
|
ret
|
2011-11-22 09:07:30 +01:00
|
|
|
EbcLLExecuteEbcImageEntryPoint ENDP
|
2007-07-18 16:32:48 +02:00
|
|
|
|
|
|
|
END
|