]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Ebc/Dxe/x64/EbcLowLevel.asm
Add EBC, FTW, Crc32SectionExtract, NullMemoryTest modules.
[mirror_edk2.git] / MdeModulePkg / Universal / Ebc / Dxe / x64 / 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 05/09/12 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 text SEGMENT
35
36 ;---------------------------------------------------------------------------
37 ;;GenericPostSegment SEGMENT USE16
38 ;---------------------------------------------------------------------------
39
40 ;****************************************************************************
41 ; EbcLLCALLEX
42 ;
43 ; This function is called to execute an EBC CALLEX instruction.
44 ; This instruction requires that we thunk out to external native
45 ; code. For x64, we switch stacks, copy the arguments to the stack
46 ; and jump to the specified function.
47 ; On return, we restore the stack pointer to its original location.
48 ;
49 ; Destroys no working registers.
50 ;****************************************************************************
51 ; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
52
53 CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD
54
55
56 EbcLLCALLEXNative PROC NEAR PUBLIC
57 push rbp
58 push rbx
59 mov rbp, rsp
60 ; Function prolog
61
62 ; Copy FuncAddr to a preserved register.
63 mov rbx, rcx
64
65 ; Set stack pointer to new value
66 sub r8, rdx
67 sub rsp, r8
68 mov rcx, rsp
69 sub rsp, 20h
70 call CopyMem
71 add rsp, 20h
72
73 ; Considering the worst case, load 4 potiential arguments
74 ; into registers.
75 mov rcx, qword ptr [rsp]
76 mov rdx, qword ptr [rsp+8h]
77 mov r8, qword ptr [rsp+10h]
78 mov r9, qword ptr [rsp+18h]
79
80 ; Now call the external routine
81 call rbx
82
83 ; Function epilog
84 mov rsp, rbp
85 pop rbx
86 pop rbp
87 ret
88 EbcLLCALLEXNative ENDP
89
90
91 ; UINTN EbcLLGetEbcEntryPoint(VOID);
92 ; Routine Description:
93 ; The VM thunk code stuffs an EBC entry point into a processor
94 ; register. Since we can't use inline assembly to get it from
95 ; the interpreter C code, stuff it into the return value
96 ; register and return.
97 ;
98 ; Arguments:
99 ; None.
100 ;
101 ; Returns:
102 ; The contents of the register in which the entry point is passed.
103 ;
104 EbcLLGetEbcEntryPoint PROC NEAR PUBLIC
105 ret
106 EbcLLGetEbcEntryPoint ENDP
107
108 ;/*++
109 ;
110 ;Routine Description:
111 ;
112 ; Return the caller's value of the stack pointer.
113 ;
114 ;Arguments:
115 ;
116 ; None.
117 ;
118 ;Returns:
119 ;
120 ; The current value of the stack pointer for the caller. We
121 ; adjust it by 4 here because when they called us, the return address
122 ; is put on the stack, thereby lowering it by 4 bytes.
123 ;
124 ;--*/
125
126 ; UINTN EbcLLGetStackPointer()
127 EbcLLGetStackPointer PROC NEAR PUBLIC
128 mov rax, rsp ; get current stack pointer
129 ; Stack adjusted by this much when we were called,
130 ; For this function, it's 4.
131 add rax, 4
132 ret
133 EbcLLGetStackPointer ENDP
134
135 ; UINT64 EbcLLGetReturnValue(VOID);
136 ; Routine Description:
137 ; When EBC calls native, on return the VM has to stuff the return
138 ; value into a VM register. It's assumed here that the value is still
139 ; in the register, so simply return and the caller should get the
140 ; return result properly.
141 ;
142 ; Arguments:
143 ; None.
144 ;
145 ; Returns:
146 ; The unmodified value returned by the native code.
147 ;
148 EbcLLGetReturnValue PROC NEAR PUBLIC
149 ret
150 EbcLLGetReturnValue ENDP
151
152 text ENDS
153 END
154