]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S
MdeModulePkg/EbcDxe: Add AARCH64 EBC VM support
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / AArch64 / 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) 2015, The Linux Foundation. All rights reserved.
7 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
8 # This program and the accompanying materials
9 # are licensed and made available under the terms and conditions of the BSD License
10 # which accompanies this distribution. The full text of the license may be found at
11 # http://opensource.org/licenses/bsd-license.php
12 #
13 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #
16 #**/
17
18 #---------------------------------------------------------------------------
19 # Equate files needed.
20 #---------------------------------------------------------------------------
21
22 ASM_GLOBAL ASM_PFX(CopyMem);
23 ASM_GLOBAL ASM_PFX(EbcInterpret);
24 ASM_GLOBAL ASM_PFX(ExecuteEbcImageEntryPoint);
25
26 #****************************************************************************
27 # EbcLLCALLEX
28 #
29 # This function is called to execute an EBC CALLEX instruction.
30 # This instruction requires that we thunk out to external native
31 # code. For AArch64, we copy the VM stack into the main stack and then pop
32 # the first 8 arguments off according to the AArch64 Procedure Call Standard
33 # On return, we restore the stack pointer to its original location.
34 #
35 #****************************************************************************
36 # UINTN EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
37 ASM_GLOBAL ASM_PFX(EbcLLCALLEXNative);
38 ASM_PFX(EbcLLCALLEXNative):
39 stp x19, x20, [sp, #-16]!
40 stp x29, x30, [sp, #-16]!
41
42 mov x19, x0
43 mov x20, sp
44 sub x2, x2, x1 // Length = NewStackPointer-FramePtr
45 sub sp, sp, x2
46 sub sp, sp, #64 // Make sure there is room for at least 8 args in the new stack
47 mov x0, sp
48
49 bl CopyMem // Sp, NewStackPointer, Length
50
51 ldp x0, x1, [sp], #16
52 ldp x2, x3, [sp], #16
53 ldp x4, x5, [sp], #16
54 ldp x6, x7, [sp], #16
55
56 blr x19
57
58 mov sp, x20
59 ldp x29, x30, [sp], #16
60 ldp x19, x20, [sp], #16
61
62 ret
63
64 #****************************************************************************
65 # EbcLLEbcInterpret
66 #
67 # This function is called by the thunk code to handle an Native to EBC call
68 # This can handle up to 16 arguments (1-8 on in x0-x7, 9-16 are on the stack)
69 # x9 contains the Entry point that will be the first argument when
70 # EBCInterpret is called.
71 #
72 #****************************************************************************
73 ASM_GLOBAL ASM_PFX(EbcLLEbcInterpret);
74 ASM_PFX(EbcLLEbcInterpret):
75 stp x29, x30, [sp, #-16]!
76
77 // copy the current arguments 9-16 from old location and add arg 7 to stack
78 // keeping 16 byte stack alignment
79 sub sp, sp, #80
80 str x7, [sp]
81 ldr x11, [sp, #96]
82 str x11, [sp, #8]
83 ldr x11, [sp, #104]
84 str x11, [sp, #16]
85 ldr x11, [sp, #112]
86 str x11, [sp, #24]
87 ldr x11, [sp, #120]
88 str x11, [sp, #32]
89 ldr x11, [sp, #128]
90 str x11, [sp, #40]
91 ldr x11, [sp, #136]
92 str x11, [sp, #48]
93 ldr x11, [sp, #144]
94 str x11, [sp, #56]
95 ldr x11, [sp, #152]
96 str x11, [sp, #64]
97
98 // Shift arguments and add entry point and as argument 1
99 mov x7, x6
100 mov x6, x5
101 mov x5, x4
102 mov x4, x3
103 mov x3, x2
104 mov x2, x1
105 mov x1, x0
106 mov x0, x9
107
108 # call C-code
109 bl ASM_PFX(EbcInterpret)
110 add sp, sp, #80
111
112 ldp x29, x30, [sp], #16
113
114 ret
115
116 #****************************************************************************
117 # EbcLLExecuteEbcImageEntryPoint
118 #
119 # This function is called by the thunk code to handle the image entry point
120 # x9 contains the Entry point that will be the first argument when
121 # ExecuteEbcImageEntryPoint is called.
122 #
123 #****************************************************************************
124 ASM_GLOBAL ASM_PFX(EbcLLExecuteEbcImageEntryPoint);
125 ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
126 stp x29, x30, [sp, #-16]!
127 # build new paramater calling convention
128 mov x2, x1
129 mov x1, x0
130 mov x0, x9
131
132 # call C-code
133 bl ASM_PFX(ExecuteEbcImageEntryPoint)
134 ldp x29, x30, [sp], #16
135 ret