]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/Ia32/EbcLowLevel.asm
sync comments, fix function header, rename variable name to follow coding style.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / Ia32 / EbcLowLevel.asm
CommitLineData
7b414b4e 1;/** @file\r
f45af90b 2; \r
3; This code provides low level routines that support the Virtual Machine\r
4; for option ROMs.\r
5; \r
7b414b4e 6; Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
7; All rights reserved. This program and the accompanying materials\r
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
f45af90b 11; \r
7b414b4e 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
f45af90b 14; \r
7b414b4e 15;**/\r
16\r
17 page ,132\r
18 title VM ASSEMBLY LANGUAGE ROUTINES\r
53c71d09 19\r
20;---------------------------------------------------------------------------\r
21; Equate files needed.\r
22;---------------------------------------------------------------------------\r
23\r
24.XLIST\r
25\r
26.LIST\r
27\r
28;---------------------------------------------------------------------------\r
29; Assembler options\r
30;---------------------------------------------------------------------------\r
31\r
32.686p\r
7b414b4e 33.model flat\r
34.code\r
53c71d09 35;---------------------------------------------------------------------------\r
36;;GenericPostSegment SEGMENT USE16\r
37;---------------------------------------------------------------------------\r
38CopyMem PROTO C Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD\r
39\r
40;****************************************************************************\r
41; EbcLLCALLEXNative\r
42;\r
43; This function is called to execute an EBC CALLEX instruction\r
7b414b4e 44; to native code.\r
53c71d09 45; This instruction requires that we thunk out to external native\r
7b414b4e 46; code. For IA32, we simply switch stacks and jump to the\r
53c71d09 47; specified function. On return, we restore the stack pointer\r
48; to its original location.\r
49;\r
50; Destroys no working registers.\r
51;****************************************************************************\r
52; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
53_EbcLLCALLEXNative PROC NEAR PUBLIC\r
54 push ebp\r
55 push ebx\r
56 mov ebp, esp ; standard function prolog\r
7b414b4e 57\r
53c71d09 58 ; Get function address in a register\r
59 ; mov ecx, FuncAddr => mov ecx, dword ptr [FuncAddr]\r
60 mov ecx, dword ptr [esp]+0Ch\r
7b414b4e 61\r
53c71d09 62 ; Set stack pointer to new value\r
63 ; mov eax, NewStackPointer => mov eax, dword ptr [NewSp]\r
64 mov eax, dword ptr [esp] + 14h\r
65 mov edx, dword ptr [esp] + 10h\r
66 sub eax, edx\r
7b414b4e 67 sub esp, eax\r
53c71d09 68 mov ebx, esp\r
69 push ecx\r
70 push eax\r
71 push edx\r
72 push ebx\r
73 call CopyMem\r
74 pop eax\r
75 pop eax\r
76 pop eax\r
77 pop ecx\r
78\r
79 ; Now call the external routine\r
80 call ecx\r
7b414b4e 81\r
53c71d09 82 ; ebp is preserved by the callee. In this function it\r
83 ; equals the original esp, so set them equal\r
84 mov esp, ebp\r
85\r
86 ; Standard function epilog\r
87 mov esp, ebp\r
88 pop ebx\r
89 pop ebp\r
90 ret\r
91_EbcLLCALLEXNative ENDP\r
92\r
93\r
94; UINTN EbcLLGetEbcEntryPoint(VOID);\r
95; Routine Description:\r
96; The VM thunk code stuffs an EBC entry point into a processor\r
97; register. Since we can't use inline assembly to get it from\r
7b414b4e 98; the interpreter C code, stuff it into the return value\r
53c71d09 99; register and return.\r
100;\r
101; Arguments:\r
102; None.\r
103;\r
104; Returns:\r
105; The contents of the register in which the entry point is passed.\r
106;\r
107_EbcLLGetEbcEntryPoint PROC NEAR PUBLIC\r
108 ret\r
109_EbcLLGetEbcEntryPoint ENDP\r
110\r
111;/*++\r
112;\r
113;Routine Description:\r
7b414b4e 114;\r
53c71d09 115; Return the caller's value of the stack pointer.\r
116;\r
117;Arguments:\r
118;\r
119; None.\r
120;\r
121;Returns:\r
122;\r
123; The current value of the stack pointer for the caller. We\r
124; adjust it by 4 here because when they called us, the return address\r
125; is put on the stack, thereby lowering it by 4 bytes.\r
126;\r
127;--*/\r
128\r
7b414b4e 129; UINTN EbcLLGetStackPointer()\r
53c71d09 130_EbcLLGetStackPointer PROC NEAR PUBLIC\r
131 mov eax, esp ; get current stack pointer\r
132 add eax, 4 ; stack adjusted by this much when we were called\r
133 ret\r
134_EbcLLGetStackPointer ENDP\r
135\r
136; UINT64 EbcLLGetReturnValue(VOID);\r
137; Routine Description:\r
138; When EBC calls native, on return the VM has to stuff the return\r
139; value into a VM register. It's assumed here that the value is still\r
140; in the register, so simply return and the caller should get the\r
141; return result properly.\r
142;\r
143; Arguments:\r
144; None.\r
145;\r
146; Returns:\r
147; The unmodified value returned by the native code.\r
148;\r
149_EbcLLGetReturnValue PROC NEAR PUBLIC\r
150 ret\r
151_EbcLLGetReturnValue ENDP\r
152\r
153END\r