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