#define VM_STACK_SIZE (1024 * 4)\r
#define EBC_THUNK_SIZE 32\r
\r
+#define STACK_REMAIN_SIZE (1024 * 4)\r
VOID\r
EbcLLCALLEX (\r
IN VM_CONTEXT *VmPtr,\r
IN OUT UINTN Arg5,\r
IN OUT UINTN Arg6,\r
IN OUT UINTN Arg7,\r
- IN OUT UINTN Arg8\r
+ IN OUT UINTN Arg8,\r
+ IN OUT UINTN Arg9,\r
+ IN OUT UINTN Arg10,\r
+ IN OUT UINTN Arg11,\r
+ IN OUT UINTN Arg12,\r
+ IN OUT UINTN Arg13,\r
+ IN OUT UINTN Arg14,\r
+ IN OUT UINTN Arg15,\r
+ IN OUT UINTN Arg16\r
)\r
/*++\r
\r
//\r
VM_CONTEXT VmContext;\r
UINTN Addr;\r
+ EFI_STATUS Status;\r
+ UINTN StackIndex;\r
\r
//\r
// Get the EBC entry point from the processor register.\r
// Set the VM instruction pointer to the correct location in memory.\r
//\r
VmContext.Ip = (VMIP) Addr;\r
-\r
//\r
// Initialize the stack pointer for the EBC. Get the current system stack\r
// pointer and adjust it down by the max needed for the interpreter.\r
//\r
- Addr = EbcLLGetStackPointer ();\r
-\r
- VmContext.R[0] = (UINT64) Addr;\r
- VmContext.R[0] -= VM_STACK_SIZE;\r
\r
//\r
// Align the stack on a natural boundary\r
//\r
+\r
+ //\r
+ // Allocate stack pool\r
+ //\r
+ Status = GetEBCStack((EFI_HANDLE)-1, &VmContext.StackPool, &StackIndex);\r
+ if (EFI_ERROR(Status)) {\r
+ return Status;\r
+ }\r
+ VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
+ VmContext.R[0] = (UINT64)(UINTN) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
+ VmContext.HighStackBottom = (UINTN)VmContext.R[0];\r
VmContext.R[0] &= ~(sizeof (UINTN) - 1);\r
+ VmContext.R[0] -= sizeof (UINTN);\r
\r
//\r
// Put a magic value in the stack gap, then adjust down again\r
//\r
*(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) VM_STACK_KEY_VALUE;\r
VmContext.StackMagicPtr = (UINTN *) (UINTN) VmContext.R[0];\r
- VmContext.R[0] -= sizeof (UINTN);\r
+ VmContext.LowStackTop = (UINTN) VmContext.R[0];\r
\r
//\r
// For IA32, this is where we say our return address is\r
//\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg16;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg15;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg14;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg13;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg12;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg11;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg10;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg9;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg8;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg7;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg6;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg5;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg4;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg3;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg2;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg1;\r
+ VmContext.R[0] -= 16;\r
VmContext.StackRetAddr = (UINT64) VmContext.R[0];\r
- VmContext.LowStackTop = (UINTN) VmContext.R[0];\r
\r
//\r
// We need to keep track of where the EBC stack starts. This way, if the EBC\r
// the stack too, so adjust accordingly.\r
// VmContext.HighStackBottom = (UINTN)(Addr + sizeof (VmContext) + sizeof (Addr));\r
//\r
- VmContext.HighStackBottom = (UINTN) &Arg1 - 16;\r
+\r
//\r
// Begin executing the EBC code\r
//\r
//\r
// Return the value in R[7] unless there was an error\r
//\r
+ ReturnEBCStack(StackIndex);\r
return (UINT64) VmContext.R[7];\r
}\r
\r
//\r
VM_CONTEXT VmContext;\r
UINTN Addr;\r
+ EFI_STATUS Status;\r
+ UINTN StackIndex;\r
\r
//\r
// Get the EBC entry point from the processor register. Make sure you don't\r
// Initialize the stack pointer for the EBC. Get the current system stack\r
// pointer and adjust it down by the max needed for the interpreter.\r
//\r
- Addr = EbcLLGetStackPointer ();\r
- VmContext.R[0] = (UINT64) Addr;\r
- VmContext.R[0] -= VM_STACK_SIZE;\r
+\r
+ //\r
+ // Allocate stack pool\r
+ //\r
+ Status = GetEBCStack(ImageHandle, &VmContext.StackPool, &StackIndex);\r
+ if (EFI_ERROR(Status)) {\r
+ return Status;\r
+ }\r
+ VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
+ VmContext.R[0] = (UINT64)(UINTN) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
+ VmContext.HighStackBottom = (UINTN)VmContext.R[0];\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ \r
//\r
// Put a magic value in the stack gap, then adjust down again\r
//\r
*(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) VM_STACK_KEY_VALUE;\r
VmContext.StackMagicPtr = (UINTN *) (UINTN) VmContext.R[0];\r
- VmContext.R[0] -= sizeof (UINTN);\r
\r
//\r
// Align the stack on a natural boundary\r
// VmContext.R[0] &= ~(sizeof(UINTN) - 1);\r
//\r
- VmContext.StackRetAddr = (UINT64) VmContext.R[0];\r
VmContext.LowStackTop = (UINTN) VmContext.R[0];\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) SystemTable;\r
+ VmContext.R[0] -= sizeof (UINTN);\r
+ *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) ImageHandle;\r
+\r
+ VmContext.R[0] -= 16; \r
+ VmContext.StackRetAddr = (UINT64) VmContext.R[0];\r
//\r
// VM pushes 16-bytes for return address. Simulate that here.\r
//\r
- VmContext.HighStackBottom = (UINTN) &ImageHandle - 16;\r
\r
//\r
// Begin executing the EBC code\r