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