]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/x64/EbcLowLevel.S
1. add public functions header.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / x64 / EbcLowLevel.S
1 ##/**@file
2 # This code provides low level routines that support the Virtual Machine
3 # for option ROMs.
4 #
5 # Copyright (c) 2007 - 2008, 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 #---------------------------------------------------------------------------
17 # Equate files needed.
18 #---------------------------------------------------------------------------
19
20 #---------------------------------------------------------------------------
21 ##GenericPostSegment SEGMENT USE16
22 #---------------------------------------------------------------------------
23
24 #****************************************************************************
25 # EbcLLCALLEX
26 #
27 # This function is called to execute an EBC CALLEX instruction.
28 # This instruction requires that we thunk out to external native
29 # code. For x64, we switch stacks, copy the arguments to the stack
30 # and jump to the specified function.
31 # On return, we restore the stack pointer to its original location.
32 #
33 # Destroys no working registers.
34 #****************************************************************************
35 .global _CopyMem;
36
37 # VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
38 .global _EbcLLCALLEXNative;
39 _EbcLLCALLEXNative:
40 push %rbp
41 push %rbx
42 mov %rsp, %rbp
43 # Function prolog
44
45 # Copy FuncAddr to a preserved register.
46 mov %rcx, %rbx
47
48 # Set stack pointer to new value
49 sub %r8, %rdx
50 sub %rsp, %r8
51 mov %rsp, %rcx
52 sub %rsp, 0x20
53 call _CopyMem
54 add %rsp, 0x20
55
56 # Considering the worst case, load 4 potiential arguments
57 # into registers.
58 mov (%rsp), %rcx
59 mov 8(%rsp), %rdx
60 mov 10(%rsp), %r8
61 mov 18(%rsp), %r9
62
63 # Now call the external routine
64 call *%rbx
65
66 # Function epilog
67 mov %rbp, %rsp
68 pop %rbx
69 pop %rbp
70 ret
71
72
73 # UINTN EbcLLGetEbcEntryPoint(VOID);
74 # Routine Description:
75 # The VM thunk code stuffs an EBC entry point into a processor
76 # register. Since we can't use inline assembly to get it from
77 # the interpreter C code, stuff it into the return value
78 # register and return.
79 #
80 # Arguments:
81 # None.
82 #
83 # Returns:
84 # The contents of the register in which the entry point is passed.
85 #
86 .global _EbcLLGetEbcEntryPoint;
87 _EbcLLGetEbcEntryPoint:
88 ret
89
90 #/*++
91 #
92 #Routine Description:
93 #
94 # Return the caller's value of the stack pointer.
95 #
96 #Arguments:
97 #
98 # None.
99 #
100 #Returns:
101 #
102 # The current value of the stack pointer for the caller. We
103 # adjust it by 4 here because when they called us, the return address
104 # is put on the stack, thereby lowering it by 4 bytes.
105 #
106 #--*/
107
108 # UINTN EbcLLGetStackPointer()
109 .global _EbcLLGetStackPointer;
110 _EbcLLGetStackPointer:
111 mov %rsp, %rax
112 # Stack adjusted by this much when we were called,
113 # For this function, it's 4.
114 add $4, %rax
115 ret
116
117 .global _EbcLLGetReturnValue;
118 _EbcLLGetReturnValue:
119 # UINT64 EbcLLGetReturnValue(VOID);
120 # Routine Description:
121 # When EBC calls native, on return the VM has to stuff the return
122 # value into a VM register. It's assumed here that the value is still
123 # in the register, so simply return and the caller should get the
124 # return result properly.
125 #
126 # Arguments:
127 # None.
128 #
129 # Returns:
130 # The unmodified value returned by the native code.
131 #
132 ret