3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 This module contains EBC support routines that are customized based on
24 #include "EbcExecute.h"
26 #define VM_STACK_SIZE (1024 * 32)
28 #define EBC_THUNK_SIZE 128
31 // For code execution, thunks must be aligned on 16-byte boundary
33 #define EBC_THUNK_ALIGNMENT 16
36 // Opcodes for IPF instructions. We'll need to hand-create thunk code (stuffing
37 // bits) to insert a jump to the interpreter.
39 #define OPCODE_NOP (UINT64) 0x00008000000
40 #define OPCODE_BR_COND_SPTK_FEW (UINT64) 0x00100000000
41 #define OPCODE_MOV_BX_RX (UINT64) 0x00E00100000
44 // Opcode for MOVL instruction
46 #define MOVL_OPCODE 0x06
72 // Advance the VM stack down, and then copy the argument to the stack.
75 VmPtr
->R
[0] -= sizeof (UINT64
);
76 *(UINT64
*) VmPtr
->R
[0] = Arg
;
87 // Create a new VM context on the stack
101 // Get the EBC entry point from the processor register. Make sure you don't
102 // call any functions before this or you could mess up the register the
103 // entry point is passed in.
105 Addr
= EbcLLGetEbcEntryPoint ();
107 // Need the args off the stack.
109 VA_START (List
, Arg1
);
110 Arg2
= VA_ARG (List
, UINT64
);
111 Arg3
= VA_ARG (List
, UINT64
);
112 Arg4
= VA_ARG (List
, UINT64
);
113 Arg5
= VA_ARG (List
, UINT64
);
114 Arg6
= VA_ARG (List
, UINT64
);
115 Arg7
= VA_ARG (List
, UINT64
);
116 Arg8
= VA_ARG (List
, UINT64
);
117 Arg9Addr
= (UINTN
) List
;
119 // Now clear out our context
121 ZeroMem ((VOID
*) &VmContext
, sizeof (VM_CONTEXT
));
123 // Set the VM instruction pointer to the correct location in memory.
125 VmContext
.Ip
= (VMIP
) Addr
;
127 // Initialize the stack pointer for the EBC. Get the current system stack
128 // pointer and adjust it down by the max needed for the interpreter.
130 Addr
= (UINTN
) Arg9Addr
;
132 // NOTE: Eventually we should have the interpreter allocate memory
133 // for stack space which it will use during its execution. This
134 // would likely improve performance because the interpreter would
135 // no longer be required to test each memory access and adjust
136 // those reading from the stack gap.
138 // For IPF, the stack looks like (assuming 10 args passed)
140 // arg9 (Bottom of high stack)
141 // [ stack gap for interpreter execution ]
142 // [ magic value for detection of stack corruption ]
143 // arg8 (Top of low stack)
146 // [ 64-bit return address ]
148 // If the EBC accesses memory in the stack gap, then we assume that it's
149 // actually trying to access args9 and greater. Therefore we need to
150 // adjust memory accesses in this region to point above the stack gap.
152 VmContext
.HighStackBottom
= (UINTN
) Addr
;
154 // Now adjust the EBC stack pointer down to leave a gap for interpreter
155 // execution. Then stuff a magic value there.
157 VmContext
.R
[0] = (UINT64
) Addr
;
158 VmContext
.R
[0] -= VM_STACK_SIZE
;
159 PushU64 (&VmContext
, (UINT64
) VM_STACK_KEY_VALUE
);
160 VmContext
.StackMagicPtr
= (UINTN
*) VmContext
.R
[0];
161 VmContext
.LowStackTop
= (UINTN
) VmContext
.R
[0];
163 // Push the EBC arguments on the stack. Does not matter that they may not
166 PushU64 (&VmContext
, Arg8
);
167 PushU64 (&VmContext
, Arg7
);
168 PushU64 (&VmContext
, Arg6
);
169 PushU64 (&VmContext
, Arg5
);
170 PushU64 (&VmContext
, Arg4
);
171 PushU64 (&VmContext
, Arg3
);
172 PushU64 (&VmContext
, Arg2
);
173 PushU64 (&VmContext
, Arg1
);
175 // Push a bogus return address on the EBC stack because the
176 // interpreter expects one there. For stack alignment purposes on IPF,
177 // EBC return addresses are always 16 bytes. Push a bogus value as well.
179 PushU64 (&VmContext
, 0);
180 PushU64 (&VmContext
, 0xDEADBEEFDEADBEEF);
181 VmContext
.StackRetAddr
= (UINT64
) VmContext
.R
[0];
183 // Begin executing the EBC code
185 EbcExecute (&VmContext
);
187 // Return the value in R[7] unless there was an error
189 return (UINT64
) VmContext
.R
[7];
194 ExecuteEbcImageEntryPoint (
195 IN EFI_HANDLE ImageHandle
,
196 IN EFI_SYSTEM_TABLE
*SystemTable
204 Begin executing an EBC image. The address of the entry point is passed
205 in via a processor register, so we'll need to make a call to get the
210 ImageHandle - image handle for the EBC application we're executing
211 SystemTable - standard system table passed into an driver's entry point
215 The value returned by the EBC application we're going to run.
220 // Create a new VM context on the stack
222 VM_CONTEXT VmContext
;
226 // Get the EBC entry point from the processor register. Make sure you don't
227 // call any functions before this or you could mess up the register the
228 // entry point is passed in.
230 Addr
= EbcLLGetEbcEntryPoint ();
233 // Now clear out our context
235 ZeroMem ((VOID
*) &VmContext
, sizeof (VM_CONTEXT
));
238 // Save the image handle so we can track the thunks created for this image
240 VmContext
.ImageHandle
= ImageHandle
;
241 VmContext
.SystemTable
= SystemTable
;
244 // Set the VM instruction pointer to the correct location in memory.
246 VmContext
.Ip
= (VMIP
) Addr
;
249 // Get the stack pointer. This is the bottom of the upper stack.
251 Addr
= EbcLLGetStackPointer ();
252 VmContext
.HighStackBottom
= (UINTN
) Addr
;
253 VmContext
.R
[0] = (INT64
) Addr
;
256 // Allocate stack space for the interpreter. Then put a magic value
257 // at the bottom so we can detect stack corruption.
259 VmContext
.R
[0] -= VM_STACK_SIZE
;
260 PushU64 (&VmContext
, (UINT64
) VM_STACK_KEY_VALUE
);
261 VmContext
.StackMagicPtr
= (UINTN
*) (UINTN
) VmContext
.R
[0];
264 // When we thunk to external native code, we copy the last 8 qwords from
265 // the EBC stack into the processor registers, and adjust the stack pointer
266 // up. If the caller is not passing 8 parameters, then we've moved the
267 // stack pointer up into the stack gap. If this happens, then the caller
268 // can mess up the stack gap contents (in particular our magic value).
269 // Therefore, leave another gap below the magic value. Pick 10 qwords down,
270 // just as a starting point.
272 VmContext
.R
[0] -= 10 * sizeof (UINT64
);
275 // Align the stack pointer such that after pushing the system table,
276 // image handle, and return address on the stack, it's aligned on a 16-byte
277 // boundary as required for IPF.
279 VmContext
.R
[0] &= (INT64
)~0x0f;
280 VmContext
.LowStackTop
= (UINTN
) VmContext
.R
[0];
282 // Simply copy the image handle and system table onto the EBC stack.
283 // Greatly simplifies things by not having to spill the args
285 PushU64 (&VmContext
, (UINT64
) SystemTable
);
286 PushU64 (&VmContext
, (UINT64
) ImageHandle
);
289 // Interpreter assumes 64-bit return address is pushed on the stack.
290 // IPF does not do this so pad the stack accordingly. Also, a
291 // "return address" is 16 bytes as required for IPF stack alignments.
293 PushU64 (&VmContext
, (UINT64
) 0);
294 PushU64 (&VmContext
, (UINT64
) 0x1234567887654321);
295 VmContext
.StackRetAddr
= (UINT64
) VmContext
.R
[0];
298 // Begin executing the EBC code
300 EbcExecute (&VmContext
);
303 // Return the value in R[7] unless there was an error
305 return (UINT64
) VmContext
.R
[7];
310 IN EFI_HANDLE ImageHandle
,
311 IN VOID
*EbcEntryPoint
,
319 Create thunks for an EBC image entry point, or an EBC protocol service.
323 ImageHandle - Image handle for the EBC image. If not null, then we're
324 creating a thunk for an image entry point.
325 EbcEntryPoint - Address of the EBC code that the thunk is to call
326 Thunk - Returned thunk we create here
327 Flags - Flags indicating options for creating the thunk
338 UINT64 Code
[3]; // Code in a bundle
339 UINT64 RegNum
; // register number for MOVL
340 UINT64 I
; // bits of MOVL immediate data
341 UINT64 Ic
; // bits of MOVL immediate data
342 UINT64 Imm5c
; // bits of MOVL immediate data
343 UINT64 Imm9d
; // bits of MOVL immediate data
344 UINT64 Imm7b
; // bits of MOVL immediate data
345 UINT64 Br
; // branch register for loading and jumping
352 // Check alignment of pointer to EBC code, which must always be aligned
353 // on a 2-byte boundary.
355 if ((UINT32
) (UINTN
) EbcEntryPoint
& 0x01) {
356 return EFI_INVALID_PARAMETER
;
359 // Allocate memory for the thunk. Make the (most likely incorrect) assumption
360 // that the returned buffer is not aligned, so round up to the next
363 Size
= EBC_THUNK_SIZE
+ EBC_THUNK_ALIGNMENT
- 1;
365 Status
= gBS
->AllocatePool (
370 if (Status
!= EFI_SUCCESS
) {
371 return EFI_OUT_OF_RESOURCES
;
374 // Save the start address of the buffer.
379 // Make sure it's aligned for code execution. If not, then
382 if ((UINT32
) (UINTN
) Ptr
& (EBC_THUNK_ALIGNMENT
- 1)) {
383 Ptr
= (UINT8
*) (((UINTN
) Ptr
+ (EBC_THUNK_ALIGNMENT
- 1)) &~ (UINT64
) (EBC_THUNK_ALIGNMENT
- 1));
386 // Return the pointer to the thunk to the caller to user as the
387 // image entry point.
389 *Thunk
= (VOID
*) Ptr
;
392 // Clear out the thunk entry
393 // ZeroMem(Ptr, Size);
395 // For IPF, when you do a call via a function pointer, the function pointer
396 // actually points to a function descriptor which consists of a 64-bit
397 // address of the function, followed by a 64-bit gp for the function being
398 // called. See the the Software Conventions and Runtime Architecture Guide
400 // So first off in our thunk, create a descriptor for our actual thunk code.
401 // This means we need to create a pointer to the thunk code (which follows
402 // the descriptor we're going to create), followed by the gp of the Vm
403 // interpret function we're going to eventually execute.
405 Data64Ptr
= (UINT64
*) Ptr
;
408 // Write the function's entry point (which is our thunk code that follows
409 // this descriptor we're creating).
411 *Data64Ptr
= (UINT64
) (Data64Ptr
+ 2);
413 // Get the gp from the descriptor for EbcInterpret and stuff it in our thunk
416 *(Data64Ptr
+ 1) = *(UINT64
*) ((UINT64
*) (UINTN
) EbcInterpret
+ 1);
418 // Advance our thunk data pointer past the descriptor. Since the
419 // descriptor consists of 16 bytes, the pointer is still aligned for
420 // IPF code execution (on 16-byte boundary).
422 Ptr
+= sizeof (UINT64
) * 2;
425 // *************************** MAGIC BUNDLE ********************************
427 // Write magic code bundle for: movl r8 = 0xca112ebcca112ebc to help the VM
428 // to recognize it is a thunk.
430 Addr
= (UINT64
) 0xCA112EBCCA112EBC;
433 // Now generate the code bytes. First is nop.m 0x0
435 Code
[0] = OPCODE_NOP
;
438 // Next is simply Addr[62:22] (41 bits) of the address
440 Code
[1] = RShiftU64 (Addr
, 22) & 0x1ffffffffff;
443 // Extract bits from the address for insertion into the instruction
446 I
= RShiftU64 (Addr
, 63) & 0x01;
450 Ic
= RShiftU64 (Addr
, 21) & 0x01;
452 // imm5c = Addr[20:16] for 5 bits
454 Imm5c
= RShiftU64 (Addr
, 16) & 0x1F;
456 // imm9d = Addr[15:7] for 9 bits
458 Imm9d
= RShiftU64 (Addr
, 7) & 0x1FF;
460 // imm7b = Addr[6:0] for 7 bits
465 // The EBC entry point will be put into r8, so r8 can be used here
466 // temporary. R8 is general register and is auto-serialized.
471 // Next is jumbled data, including opcode and rest of address
473 Code
[2] = LShiftU64 (Imm7b
, 13);
474 Code
[2] = Code
[2] | LShiftU64 (0x00, 20); // vc
475 Code
[2] = Code
[2] | LShiftU64 (Ic
, 21);
476 Code
[2] = Code
[2] | LShiftU64 (Imm5c
, 22);
477 Code
[2] = Code
[2] | LShiftU64 (Imm9d
, 27);
478 Code
[2] = Code
[2] | LShiftU64 (I
, 36);
479 Code
[2] = Code
[2] | LShiftU64 ((UINT64
)MOVL_OPCODE
, 37);
480 Code
[2] = Code
[2] | LShiftU64 ((RegNum
& 0x7F), 6);
482 WriteBundle ((VOID
*) Ptr
, 0x05, Code
[0], Code
[1], Code
[2]);
485 // *************************** FIRST BUNDLE ********************************
487 // Write code bundle for: movl r8 = EBC_ENTRY_POINT so we pass
488 // the ebc entry point in to the interpreter function via a processor
490 // Note -- we could easily change this to pass in a pointer to a structure
491 // that contained, among other things, the EBC image's entry point. But
492 // for now pass it directly.
495 Addr
= (UINT64
) EbcEntryPoint
;
498 // Now generate the code bytes. First is nop.m 0x0
500 Code
[0] = OPCODE_NOP
;
503 // Next is simply Addr[62:22] (41 bits) of the address
505 Code
[1] = RShiftU64 (Addr
, 22) & 0x1ffffffffff;
508 // Extract bits from the address for insertion into the instruction
511 I
= RShiftU64 (Addr
, 63) & 0x01;
515 Ic
= RShiftU64 (Addr
, 21) & 0x01;
517 // imm5c = Addr[20:16] for 5 bits
519 Imm5c
= RShiftU64 (Addr
, 16) & 0x1F;
521 // imm9d = Addr[15:7] for 9 bits
523 Imm9d
= RShiftU64 (Addr
, 7) & 0x1FF;
525 // imm7b = Addr[6:0] for 7 bits
530 // Put the EBC entry point in r8, which is the location of the return value
536 // Next is jumbled data, including opcode and rest of address
538 Code
[2] = LShiftU64 (Imm7b
, 13);
539 Code
[2] = Code
[2] | LShiftU64 (0x00, 20); // vc
540 Code
[2] = Code
[2] | LShiftU64 (Ic
, 21);
541 Code
[2] = Code
[2] | LShiftU64 (Imm5c
, 22);
542 Code
[2] = Code
[2] | LShiftU64 (Imm9d
, 27);
543 Code
[2] = Code
[2] | LShiftU64 (I
, 36);
544 Code
[2] = Code
[2] | LShiftU64 ((UINT64
)MOVL_OPCODE
, 37);
545 Code
[2] = Code
[2] | LShiftU64 ((RegNum
& 0x7F), 6);
547 WriteBundle ((VOID
*) Ptr
, 0x05, Code
[0], Code
[1], Code
[2]);
550 // *************************** NEXT BUNDLE *********************************
552 // Write code bundle for:
553 // movl rx = offset_of(EbcInterpret|ExecuteEbcImageEntryPoint)
555 // Advance pointer to next bundle, then compute the offset from this bundle
556 // to the address of the entry point of the interpreter.
559 if (Flags
& FLAG_THUNK_ENTRY_POINT
) {
560 Addr
= (UINT64
) ExecuteEbcImageEntryPoint
;
562 Addr
= (UINT64
) EbcInterpret
;
565 // Indirection on Itanium-based systems
567 Addr
= *(UINT64
*) Addr
;
570 // Now write the code to load the offset into a register
572 Code
[0] = OPCODE_NOP
;
575 // Next is simply Addr[62:22] (41 bits) of the address
577 Code
[1] = RShiftU64 (Addr
, 22) & 0x1ffffffffff;
580 // Extract bits from the address for insertion into the instruction
583 I
= RShiftU64 (Addr
, 63) & 0x01;
587 Ic
= RShiftU64 (Addr
, 21) & 0x01;
589 // imm5c = Addr[20:16] for 5 bits
591 Imm5c
= RShiftU64 (Addr
, 16) & 0x1F;
593 // imm9d = Addr[15:7] for 9 bits
595 Imm9d
= RShiftU64 (Addr
, 7) & 0x1FF;
597 // imm7b = Addr[6:0] for 7 bits
602 // Put it in r31, a scratch register
607 // Next is jumbled data, including opcode and rest of address
609 Code
[2] = LShiftU64(Imm7b
, 13);
610 Code
[2] = Code
[2] | LShiftU64 (0x00, 20); // vc
611 Code
[2] = Code
[2] | LShiftU64 (Ic
, 21);
612 Code
[2] = Code
[2] | LShiftU64 (Imm5c
, 22);
613 Code
[2] = Code
[2] | LShiftU64 (Imm9d
, 27);
614 Code
[2] = Code
[2] | LShiftU64 (I
, 36);
615 Code
[2] = Code
[2] | LShiftU64 ((UINT64
)MOVL_OPCODE
, 37);
616 Code
[2] = Code
[2] | LShiftU64 ((RegNum
& 0x7F), 6);
618 WriteBundle ((VOID
*) Ptr
, 0x05, Code
[0], Code
[1], Code
[2]);
621 // *************************** NEXT BUNDLE *********************************
623 // Load branch register with EbcInterpret() function offset from the bundle
624 // address: mov b6 = RegNum
626 // See volume 3 page 4-29 of the Arch. Software Developer's Manual.
628 // Advance pointer to next bundle
631 Code
[0] = OPCODE_NOP
;
632 Code
[1] = OPCODE_NOP
;
633 Code
[2] = OPCODE_MOV_BX_RX
;
636 // Pick a branch register to use. Then fill in the bits for the branch
637 // register and user register (same user register as previous bundle).
640 Code
[2] |= LShiftU64 (Br
, 6);
641 Code
[2] |= LShiftU64 (RegNum
, 13);
642 WriteBundle ((VOID
*) Ptr
, 0x0d, Code
[0], Code
[1], Code
[2]);
645 // *************************** NEXT BUNDLE *********************************
647 // Now do the branch: (p0) br.cond.sptk.few b6
649 // Advance pointer to next bundle.
650 // Fill in the bits for the branch register (same reg as previous bundle)
653 Code
[0] = OPCODE_NOP
;
654 Code
[1] = OPCODE_NOP
;
655 Code
[2] = OPCODE_BR_COND_SPTK_FEW
;
656 Code
[2] |= LShiftU64 (Br
, 13);
657 WriteBundle ((VOID
*) Ptr
, 0x1d, Code
[0], Code
[1], Code
[2]);
660 // Add the thunk to our list of allocated thunks so we can do some cleanup
661 // when the image is unloaded. Do this last since the Add function flushes
662 // the instruction cache for us.
664 EbcAddImageThunk (ImageHandle
, (VOID
*) ThunkBase
, ThunkSize
);
685 Given raw bytes of Itanium based code, format them into a bundle and
690 MemPtr - pointer to memory location to write the bundles to
691 Template - 5-bit template
692 Slot0-2 - instruction slot data for the bundle
696 EFI_INVALID_PARAMETER - Pointer is not aligned
697 - No more than 5 bits in template
698 - More than 41 bits used in code
699 EFI_SUCCESS - All data is written.
709 // Verify pointer is aligned
711 if ((UINT64
) MemPtr
& 0xF) {
712 return EFI_INVALID_PARAMETER
;
715 // Verify no more than 5 bits in template
717 if (Template
&~0x1F) {
718 return EFI_INVALID_PARAMETER
;
721 // Verify max of 41 bits used in code
723 if ((Slot0
| Slot1
| Slot2
) &~0x1ffffffffff) {
724 return EFI_INVALID_PARAMETER
;
727 Low64
= LShiftU64 (Slot1
, 46);
728 Low64
= Low64
| LShiftU64 (Slot0
, 5) | Template
;
730 High64
= RShiftU64 (Slot1
, 18);
731 High64
= High64
| LShiftU64 (Slot2
, 23);
734 // Now write it all out
736 BPtr
= (UINT8
*) MemPtr
;
737 for (Index
= 0; Index
< 8; Index
++) {
738 *BPtr
= (UINT8
) Low64
;
739 Low64
= RShiftU64 (Low64
, 8);
743 for (Index
= 0; Index
< 8; Index
++) {
744 *BPtr
= (UINT8
) High64
;
745 High64
= RShiftU64 (High64
, 8);
754 IN VM_CONTEXT
*VmPtr
,
756 IN UINTN NewStackPointer
,
764 This function is called to execute an EBC CALLEX instruction.
765 The function check the callee's content to see whether it is common native
766 code or a thunk to another piece of EBC code.
767 If the callee is common native code, use EbcLLCAllEXASM to manipulate,
768 otherwise, set the VM->IP to target EBC code directly to avoid another VM
769 be startup which cost time and stack space.
773 VmPtr - Pointer to a VM context.
774 FuncAddr - Callee's address
775 NewStackPointer - New stack pointer after the call
776 FramePtr - New frame pointer after the call
777 Size - The size of call instruction
800 // FuncAddr points to the descriptor of the target instructions.
802 CalleeAddr
= *((UINT64
*)FuncAddr
);
805 // Processor specific code to check whether the callee is a thunk to EBC.
807 if (*((UINT64
*)CalleeAddr
) != 0xBCCA000100000005) {
811 if (*((UINT64
*)CalleeAddr
+ 1) != 0x697623C1004A112E) {
816 CodeOne18
= RShiftU64 (*((UINT64
*)CalleeAddr
+ 2), 46) & 0x3FFFF;
817 CodeOne23
= (*((UINT64
*)CalleeAddr
+ 3)) & 0x7FFFFF;
818 CodeTwoI
= RShiftU64 (*((UINT64
*)CalleeAddr
+ 3), 59) & 0x1;
819 CodeTwoIc
= RShiftU64 (*((UINT64
*)CalleeAddr
+ 3), 44) & 0x1;
820 CodeTwo7b
= RShiftU64 (*((UINT64
*)CalleeAddr
+ 3), 36) & 0x7F;
821 CodeTwo5c
= RShiftU64 (*((UINT64
*)CalleeAddr
+ 3), 45) & 0x1F;
822 CodeTwo9d
= RShiftU64 (*((UINT64
*)CalleeAddr
+ 3), 50) & 0x1FF;
824 TargetEbcAddr
= CodeTwo7b
;
825 TargetEbcAddr
= TargetEbcAddr
| LShiftU64 (CodeTwo9d
, 7);
826 TargetEbcAddr
= TargetEbcAddr
| LShiftU64 (CodeTwo5c
, 16);
827 TargetEbcAddr
= TargetEbcAddr
| LShiftU64 (CodeTwoIc
, 21);
828 TargetEbcAddr
= TargetEbcAddr
| LShiftU64 (CodeOne18
, 22);
829 TargetEbcAddr
= TargetEbcAddr
| LShiftU64 (CodeOne23
, 40);
830 TargetEbcAddr
= TargetEbcAddr
| LShiftU64 (CodeTwoI
, 63);
835 // The callee is a thunk to EBC, adjust the stack pointer down 16 bytes and
836 // put our return address and frame pointer on the VM stack.
837 // Then set the VM's IP to new EBC code.
840 VmWriteMemN (VmPtr
, (UINTN
) VmPtr
->R
[0], (UINTN
) FramePtr
);
841 VmPtr
->FramePtr
= (VOID
*) (UINTN
) VmPtr
->R
[0];
843 VmWriteMem64 (VmPtr
, (UINTN
) VmPtr
->R
[0], (UINT64
) (VmPtr
->Ip
+ Size
));
845 VmPtr
->Ip
= (VMIP
) (UINTN
) TargetEbcAddr
;
848 // The callee is not a thunk to EBC, call native code.
850 EbcLLCALLEXNative (FuncAddr
, NewStackPointer
, FramePtr
);
853 // Get return value and advance the IP.
855 VmPtr
->R
[7] = EbcLLGetReturnValue ();
869 Implements the EBC CALLEX instruction to call an external function, which
870 seems to be native code.
872 We'll copy the entire EBC stack frame down below itself in memory and use
873 that copy for passing parameters.
876 CallAddr - address (function pointer) of function to call
877 EbcSp - current EBC stack pointer
878 FramePtr - current EBC frame pointer.
889 // The stack for an EBC function looks like this:
893 // Stack for passing args (m)
895 // Pad the frame size with 64 bytes because the low-level code we call
896 // will move the stack pointer up assuming worst-case 8 args in registers.
898 FrameSize
= (UINTN
) FramePtr
- (UINTN
) EbcSp
+ 64;
899 Source
= (VOID
*) EbcSp
;
900 Destination
= (VOID
*) ((UINT8
*) EbcSp
- FrameSize
- CPU_STACK_ALIGNMENT
);
901 Destination
= (VOID
*) ((UINTN
) ((UINTN
) Destination
+ CPU_STACK_ALIGNMENT
- 1) &~((UINTN
) CPU_STACK_ALIGNMENT
- 1));
902 gBS
->CopyMem (Destination
, Source
, FrameSize
);
903 EbcAsmLLCALLEX ((UINTN
) CallAddr
, (UINTN
) Destination
);