]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/X64/EbcLowLevel.S
Remove assumption on EAX and R10 usage for IA32 compiler and X64 compiler.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / X64 / EbcLowLevel.S
CommitLineData
f45af90b 1#/** @file\r
2# \r
3# This code provides low level routines that support the Virtual Machine\r
4# for option ROMs.\r
5# \r
fa97cbf4 6# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 7# This program and the accompanying materials\r
f45af90b 8# are licensed and made available under the terms and conditions of the BSD License\r
9# which accompanies this distribution. The full text of the license may be found at\r
10# http://opensource.org/licenses/bsd-license.php\r
11# \r
12# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14# \r
7b414b4e 15#**/\r
53c71d09 16\r
17#---------------------------------------------------------------------------\r
18# Equate files needed.\r
19#---------------------------------------------------------------------------\r
20\r
fa97cbf4 21ASM_GLOBAL ASM_PFX(CopyMem);\r
7102b199
JY
22ASM_GLOBAL ASM_PFX(EbcInterpret);\r
23ASM_GLOBAL ASM_PFX(ExecuteEbcImageEntryPoint);\r
53c71d09 24\r
25#****************************************************************************\r
26# EbcLLCALLEX\r
27#\r
7b414b4e 28# This function is called to execute an EBC CALLEX instruction.\r
53c71d09 29# This instruction requires that we thunk out to external native\r
30# code. For x64, we switch stacks, copy the arguments to the stack\r
7b414b4e 31# and jump to the specified function.\r
53c71d09 32# On return, we restore the stack pointer to its original location.\r
33#\r
34# Destroys no working registers.\r
35#****************************************************************************\r
53c71d09 36# VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
d5172f91 37ASM_GLOBAL ASM_PFX(EbcLLCALLEXNative);\r
7b23d0d8 38ASM_PFX(EbcLLCALLEXNative):\r
53c71d09 39 push %rbp\r
40 push %rbx\r
41 mov %rsp, %rbp\r
42 # Function prolog\r
43\r
44 # Copy FuncAddr to a preserved register.\r
45 mov %rcx, %rbx\r
46\r
47 # Set stack pointer to new value\r
ff8c7865 48 sub %rdx, %r8 \r
49 sub %r8, %rsp \r
53c71d09 50 mov %rsp, %rcx\r
ff8c7865 51 sub $0x20, %rsp \r
7b23d0d8 52 call ASM_PFX(CopyMem)\r
ff8c7865 53 add $0x20, %rsp\r
53c71d09 54\r
55 # Considering the worst case, load 4 potiential arguments\r
56 # into registers.\r
57 mov (%rsp), %rcx\r
ff8c7865 58 mov 0x8(%rsp), %rdx\r
59 mov 0x10(%rsp), %r8\r
60 mov 0x18(%rsp), %r9\r
53c71d09 61\r
62 # Now call the external routine\r
63 call *%rbx\r
64\r
65 # Function epilog\r
66 mov %rbp, %rsp\r
67 pop %rbx\r
68 pop %rbp\r
69 ret\r
70\r
7102b199
JY
71ASM_GLOBAL ASM_PFX(EbcLLEbcInterpret);\r
72ASM_PFX(EbcLLEbcInterpret):\r
73 # save old parameter to stack\r
74 mov %rcx, 0x8(%rsp)\r
75 mov %rdx, 0x10(%rsp)\r
76 mov %r8, 0x18(%rsp)\r
77 mov %r9, 0x20(%rsp)\r
53c71d09 78\r
7102b199
JY
79 # Construct new stack\r
80 push %rbp\r
81 mov %rsp, %rbp\r
82 push %rsi\r
83 push %rdi\r
84 push %rbx\r
85 sub $0x80, %rsp\r
86 push %r10\r
87 mov %rbp, %rsi\r
88 add $0x10, %rsi\r
89 mov %rsp, %rdi\r
90 add $0x8, %rdi\r
91 mov $0x10, %rcx\r
92 rep movsq\r
93 \r
94 # build new paramater calling convention\r
95 mov 0x18(%rsp), %r9\r
96 mov 0x10(%rsp), %r8\r
97 mov 0x8(%rsp), %rdx\r
98 mov %r10, %rcx\r
99\r
100 # call C-code\r
101 call ASM_PFX(EbcInterpret)\r
102 add $0x88, %esp\r
103 pop %rbx\r
104 pop %rdi\r
105 pop %rsi\r
106 pop %rbp\r
107 ret\r
108\r
109ASM_GLOBAL ASM_PFX(EbcLLExecuteEbcImageEntryPoint);\r
110ASM_PFX(EbcLLExecuteEbcImageEntryPoint):\r
111 # build new paramater calling convention\r
112 mov %rdx, %r8\r
113 mov %rcx, %rdx\r
114 mov %r10, %rcx\r
115\r
116 # call C-code\r
117 sub $0x28, %rsp\r
118 call ASM_PFX(ExecuteEbcImageEntryPoint)\r
119 add $0x28, %rsp\r
53c71d09 120 ret\r