]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/X64/EbcLowLevel.S
MdeModulePkg: INF/DEC file updates to EDK II packages
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / X64 / EbcLowLevel.S
1 #/** @file
2 #
3 # This code provides low level routines that support the Virtual Machine
4 # for option ROMs.
5 #
6 # Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
7 # 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 #---------------------------------------------------------------------------
18 # Equate files needed.
19 #---------------------------------------------------------------------------
20
21 ASM_GLOBAL ASM_PFX(CopyMem);
22 ASM_GLOBAL ASM_PFX(EbcInterpret);
23 ASM_GLOBAL ASM_PFX(ExecuteEbcImageEntryPoint);
24
25 #****************************************************************************
26 # EbcLLCALLEX
27 #
28 # This function is called to execute an EBC CALLEX instruction.
29 # This instruction requires that we thunk out to external native
30 # code. For x64, we switch stacks, copy the arguments to the stack
31 # and jump to the specified function.
32 # On return, we restore the stack pointer to its original location.
33 #
34 # Destroys no working registers.
35 #****************************************************************************
36 # VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
37 ASM_GLOBAL ASM_PFX(EbcLLCALLEXNative);
38 ASM_PFX(EbcLLCALLEXNative):
39 push %rbp
40 push %rbx
41 mov %rsp, %rbp
42 # Function prolog
43
44 # Copy FuncAddr to a preserved register.
45 mov %rcx, %rbx
46
47 # Set stack pointer to new value
48 sub %rdx, %r8
49 sub %r8, %rsp
50 mov %rsp, %rcx
51 sub $0x20, %rsp
52 call ASM_PFX(CopyMem)
53 add $0x20, %rsp
54
55 # Considering the worst case, load 4 potiential arguments
56 # into registers.
57 mov (%rsp), %rcx
58 mov 0x8(%rsp), %rdx
59 mov 0x10(%rsp), %r8
60 mov 0x18(%rsp), %r9
61
62 # Now call the external routine
63 call *%rbx
64
65 # Function epilog
66 mov %rbp, %rsp
67 pop %rbx
68 pop %rbp
69 ret
70
71 ASM_GLOBAL ASM_PFX(EbcLLEbcInterpret);
72 ASM_PFX(EbcLLEbcInterpret):
73 # save old parameter to stack
74 mov %rcx, 0x8(%rsp)
75 mov %rdx, 0x10(%rsp)
76 mov %r8, 0x18(%rsp)
77 mov %r9, 0x20(%rsp)
78
79 # Construct new stack
80 push %rbp
81 mov %rsp, %rbp
82 push %rsi
83 push %rdi
84 push %rbx
85 sub $0x80, %rsp
86 push %r10
87 mov %rbp, %rsi
88 add $0x10, %rsi
89 mov %rsp, %rdi
90 add $0x8, %rdi
91 mov $0x10, %rcx
92 rep movsq
93
94 # build new paramater calling convention
95 mov 0x18(%rsp), %r9
96 mov 0x10(%rsp), %r8
97 mov 0x8(%rsp), %rdx
98 mov %r10, %rcx
99
100 # call C-code
101 call ASM_PFX(EbcInterpret)
102 add $0x88, %esp
103 pop %rbx
104 pop %rdi
105 pop %rsi
106 pop %rbp
107 ret
108
109 ASM_GLOBAL ASM_PFX(EbcLLExecuteEbcImageEntryPoint);
110 ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
111 # build new paramater calling convention
112 mov %rdx, %r8
113 mov %rcx, %rdx
114 mov %r10, %rcx
115
116 # call C-code
117 sub $0x28, %rsp
118 call ASM_PFX(ExecuteEbcImageEntryPoint)
119 add $0x28, %rsp
120 ret