]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Ebc/Dxe/Ia32/EbcLowLevel.asm
Initial import.
[mirror_edk2.git] / EdkModulePkg / Universal / Ebc / Dxe / Ia32 / EbcLowLevel.asm
1 page ,132
2 title VM ASSEMBLY LANGUAGE ROUTINES
3 ;****************************************************************************
4 ;*
5 ;* Copyright (c) 2006, Intel Corporation
6 ;* All rights reserved. This program and the accompanying materials
7 ;* are licensed and made available under the terms and conditions of the BSD License
8 ;* which accompanies this distribution. The full text of the license may be found at
9 ;* http://opensource.org/licenses/bsd-license.php
10 ;*
11 ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 ;*
14 ;****************************************************************************
15 ;****************************************************************************
16 ; REV 1.0
17 ;****************************************************************************
18 ;
19 ; Rev Date Description
20 ; --- -------- ------------------------------------------------------------
21 ; 1.0 03/14/01 Initial creation of file.
22 ;
23 ;****************************************************************************
24
25 ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
26 ; This code provides low level routines that support the Virtual Machine
27 ; for option ROMs.
28 ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29
30 ;---------------------------------------------------------------------------
31 ; Equate files needed.
32 ;---------------------------------------------------------------------------
33
34 .XLIST
35
36 .LIST
37
38 ;---------------------------------------------------------------------------
39 ; Assembler options
40 ;---------------------------------------------------------------------------
41
42 .686p
43 .model flat
44 .code
45 ;---------------------------------------------------------------------------
46 ;;GenericPostSegment SEGMENT USE16
47 ;---------------------------------------------------------------------------
48
49 ;****************************************************************************
50 ; EbcLLCALLEXNative
51 ;
52 ; This function is called to execute an EBC CALLEX instruction
53 ; to native code.
54 ; This instruction requires that we thunk out to external native
55 ; code. For IA32, we simply switch stacks and jump to the
56 ; specified function. On return, we restore the stack pointer
57 ; to its original location.
58 ;
59 ; Destroys no working registers.
60 ;****************************************************************************
61 ; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
62 _EbcLLCALLEXNative PROC NEAR PUBLIC
63 push ebp
64 mov ebp, esp ; standard function prolog
65
66 ; Get function address in a register
67 ; mov ecx, FuncAddr => mov ecx, dword ptr [FuncAddr]
68 mov ecx, dword ptr [esp]+8
69
70 ; Set stack pointer to new value
71 ; mov eax, NewStackPointer => mov eax, dword ptr [NewSp]
72 mov eax, dword ptr [esp] + 0Ch
73 mov esp, eax
74
75 ; Now call the external routine
76 call ecx
77
78 ; ebp is preserved by the callee. In this function it
79 ; equals the original esp, so set them equal
80 mov esp, ebp
81
82 ; Standard function epilog
83 mov esp, ebp
84 pop ebp
85 ret
86 _EbcLLCALLEXNative ENDP
87
88
89 ; UINTN EbcLLGetEbcEntryPoint(VOID);
90 ; Routine Description:
91 ; The VM thunk code stuffs an EBC entry point into a processor
92 ; register. Since we can't use inline assembly to get it from
93 ; the interpreter C code, stuff it into the return value
94 ; register and return.
95 ;
96 ; Arguments:
97 ; None.
98 ;
99 ; Returns:
100 ; The contents of the register in which the entry point is passed.
101 ;
102 _EbcLLGetEbcEntryPoint PROC NEAR PUBLIC
103 ret
104 _EbcLLGetEbcEntryPoint ENDP
105
106 ;/*++
107 ;
108 ;Routine Description:
109 ;
110 ; Return the caller's value of the stack pointer.
111 ;
112 ;Arguments:
113 ;
114 ; None.
115 ;
116 ;Returns:
117 ;
118 ; The current value of the stack pointer for the caller. We
119 ; adjust it by 4 here because when they called us, the return address
120 ; is put on the stack, thereby lowering it by 4 bytes.
121 ;
122 ;--*/
123
124 ; UINTN EbcLLGetStackPointer()
125 _EbcLLGetStackPointer PROC NEAR PUBLIC
126 mov eax, esp ; get current stack pointer
127 add eax, 4 ; stack adjusted by this much when we were called
128 ret
129 _EbcLLGetStackPointer ENDP
130
131 ; UINT64 EbcLLGetReturnValue(VOID);
132 ; Routine Description:
133 ; When EBC calls native, on return the VM has to stuff the return
134 ; value into a VM register. It's assumed here that the value is still
135 ; in the register, so simply return and the caller should get the
136 ; return result properly.
137 ;
138 ; Arguments:
139 ; None.
140 ;
141 ; Returns:
142 ; The unmodified value returned by the native code.
143 ;
144 _EbcLLGetReturnValue PROC NEAR PUBLIC
145 ret
146 _EbcLLGetReturnValue ENDP
147
148 END