-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
-\r
- EbcSupport.c\r
-\r
-Abstract:\r
-\r
+/** @file\r
This module contains EBC support routines that are customized based on\r
the target processor.\r
\r
---*/\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
\r
#include "EbcInt.h"\r
#include "EbcExecute.h"\r
#include "EbcSupport.h"\r
\r
+/**\r
+ Given raw bytes of Itanium based code, format them into a bundle and\r
+ write them out.\r
+\r
+ @param MemPtr pointer to memory location to write the bundles\r
+ to.\r
+ @param Template 5-bit template.\r
+ @param Slot0 Instruction slot 0 data for the bundle.\r
+ @param Slot1 Instruction slot 1 data for the bundle.\r
+ @param Slot2 Instruction slot 2 data for the bundle.\r
+\r
+ @retval EFI_INVALID_PARAMETER Pointer is not aligned\r
+ @retval EFI_INVALID_PARAMETER No more than 5 bits in template\r
+ @retval EFI_INVALID_PARAMETER More than 41 bits used in code\r
+ @retval EFI_SUCCESS All data is written.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
WriteBundle (\r
IN UINT64 Slot2\r
);\r
\r
+/**\r
+ Pushes a 64 bit unsigned value to the VM stack.\r
+\r
+ @param VmPtr The pointer to current VM context.\r
+ @param Arg The value to be pushed.\r
+\r
+**/\r
STATIC\r
VOID\r
PushU64 (\r
- VM_CONTEXT *VmPtr,\r
- UINT64 Arg\r
+ IN VM_CONTEXT *VmPtr,\r
+ IN UINT64 Arg\r
)\r
{\r
//\r
*(UINT64 *) VmPtr->R[0] = Arg;\r
}\r
\r
+/**\r
+ Begin executing an EBC image. The address of the entry point is passed\r
+ in via a processor register, so we'll need to make a call to get the\r
+ value.\r
+\r
+ This is a thunk function. Microsoft x64 compiler only provide fast_call\r
+ calling convention, so the first four arguments are passed by rcx, rdx,\r
+ r8, and r9, while other arguments are passed in stack.\r
+\r
+ @param Arg1 The 1st argument.\r
+ @param ... The variable arguments list.\r
+\r
+ @return The value returned by the EBC application we're going to run.\r
+\r
+**/\r
STATIC\r
UINT64\r
EbcInterpret (\r
// Now adjust the EBC stack pointer down to leave a gap for interpreter\r
// execution. Then stuff a magic value there.\r
//\r
- \r
+\r
Status = GetEBCStack((EFI_HANDLE)(UINTN)-1, &VmContext.StackPool, &StackIndex);\r
if (EFI_ERROR(Status)) {\r
return Status;\r
VmContext.HighStackBottom = (UINTN) VmContext.R[0];\r
VmContext.R[0] -= sizeof (UINTN);\r
\r
- \r
+\r
PushU64 (&VmContext, (UINT64) VM_STACK_KEY_VALUE);\r
VmContext.StackMagicPtr = (UINTN *) VmContext.R[0];\r
VmContext.LowStackTop = (UINTN) VmContext.R[0];\r
return (UINT64) VmContext.R[7];\r
}\r
\r
-STATIC\r
-UINT64\r
-ExecuteEbcImageEntryPoint (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- IPF implementation.\r
\r
+/**\r
Begin executing an EBC image. The address of the entry point is passed\r
in via a processor register, so we'll need to make a call to get the\r
value.\r
- \r
-Arguments:\r
-\r
- ImageHandle - image handle for the EBC application we're executing\r
- SystemTable - standard system table passed into an driver's entry point\r
\r
-Returns:\r
+ @param ImageHandle image handle for the EBC application we're executing\r
+ @param SystemTable standard system table passed into an driver's entry\r
+ point\r
\r
- The value returned by the EBC application we're going to run.\r
+ @return The value returned by the EBC application we're going to run.\r
\r
---*/\r
+**/\r
+STATIC\r
+UINT64\r
+ExecuteEbcImageEntryPoint (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
{\r
//\r
// Create a new VM context on the stack\r
// Get the stack pointer. This is the bottom of the upper stack.\r
//\r
Addr = EbcLLGetStackPointer ();\r
- \r
+\r
Status = GetEBCStack(ImageHandle, &VmContext.StackPool, &StackIndex);\r
if (EFI_ERROR(Status)) {\r
return Status;\r
VmContext.HighStackBottom = (UINTN) VmContext.R[0];\r
VmContext.R[0] -= sizeof (UINTN);\r
\r
- \r
+\r
//\r
// Allocate stack space for the interpreter. Then put a magic value\r
// at the bottom so we can detect stack corruption.\r
return (UINT64) VmContext.R[7];\r
}\r
\r
+\r
+/**\r
+ Create thunks for an EBC image entry point, or an EBC protocol service.\r
+\r
+ @param ImageHandle Image handle for the EBC image. If not null, then\r
+ we're creating a thunk for an image entry point.\r
+ @param EbcEntryPoint Address of the EBC code that the thunk is to call\r
+ @param Thunk Returned thunk we create here\r
+ @param Flags Flags indicating options for creating the thunk\r
+\r
+ @retval EFI_SUCCESS The thunk was created successfully.\r
+ @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit\r
+ aligned.\r
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC\r
+ Thunk.\r
+ @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.\r
+\r
+**/\r
EFI_STATUS\r
EbcCreateThunks (\r
IN EFI_HANDLE ImageHandle,\r
OUT VOID **Thunk,\r
IN UINT32 Flags\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Create thunks for an EBC image entry point, or an EBC protocol service.\r
- \r
-Arguments:\r
-\r
- ImageHandle - Image handle for the EBC image. If not null, then we're\r
- creating a thunk for an image entry point.\r
- EbcEntryPoint - Address of the EBC code that the thunk is to call\r
- Thunk - Returned thunk we create here\r
- Flags - Flags indicating options for creating the thunk\r
- \r
-Returns:\r
-\r
- Standard EFI status.\r
- \r
---*/\r
{\r
UINT8 *Ptr;\r
UINT8 *ThunkBase;\r
UINT64 Addr;\r
UINT64 Code[3]; // Code in a bundle\r
UINT64 RegNum; // register number for MOVL\r
- UINT64 I; // bits of MOVL immediate data\r
- UINT64 Ic; // bits of MOVL immediate data\r
- UINT64 Imm5c; // bits of MOVL immediate data\r
- UINT64 Imm9d; // bits of MOVL immediate data\r
- UINT64 Imm7b; // bits of MOVL immediate data\r
+ UINT64 BitI; // bits of MOVL immediate data\r
+ UINT64 BitIc; // bits of MOVL immediate data\r
+ UINT64 BitImm5c; // bits of MOVL immediate data\r
+ UINT64 BitImm9d; // bits of MOVL immediate data\r
+ UINT64 BitImm7b; // bits of MOVL immediate data\r
UINT64 Br; // branch register for loading and jumping\r
UINT64 *Data64Ptr;\r
UINT32 ThunkSize;\r
// Extract bits from the address for insertion into the instruction\r
// i = Addr[63:63]\r
//\r
- I = RShiftU64 (Addr, 63) & 0x01;\r
+ BitI = RShiftU64 (Addr, 63) & 0x01;\r
//\r
// ic = Addr[21:21]\r
//\r
- Ic = RShiftU64 (Addr, 21) & 0x01;\r
+ BitIc = RShiftU64 (Addr, 21) & 0x01;\r
//\r
// imm5c = Addr[20:16] for 5 bits\r
//\r
- Imm5c = RShiftU64 (Addr, 16) & 0x1F;\r
+ BitImm5c = RShiftU64 (Addr, 16) & 0x1F;\r
//\r
// imm9d = Addr[15:7] for 9 bits\r
//\r
- Imm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
+ BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
//\r
// imm7b = Addr[6:0] for 7 bits\r
//\r
- Imm7b = Addr & 0x7F;\r
+ BitImm7b = Addr & 0x7F;\r
\r
//\r
// The EBC entry point will be put into r8, so r8 can be used here\r
//\r
// Next is jumbled data, including opcode and rest of address\r
//\r
- Code[2] = LShiftU64 (Imm7b, 13);\r
+ Code[2] = LShiftU64 (BitImm7b, 13);\r
Code[2] = Code[2] | LShiftU64 (0x00, 20); // vc\r
- Code[2] = Code[2] | LShiftU64 (Ic, 21);\r
- Code[2] = Code[2] | LShiftU64 (Imm5c, 22);\r
- Code[2] = Code[2] | LShiftU64 (Imm9d, 27);\r
- Code[2] = Code[2] | LShiftU64 (I, 36);\r
+ Code[2] = Code[2] | LShiftU64 (BitIc, 21);\r
+ Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);\r
+ Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);\r
+ Code[2] = Code[2] | LShiftU64 (BitI, 36);\r
Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);\r
Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);\r
\r
// Extract bits from the address for insertion into the instruction\r
// i = Addr[63:63]\r
//\r
- I = RShiftU64 (Addr, 63) & 0x01;\r
+ BitI = RShiftU64 (Addr, 63) & 0x01;\r
//\r
// ic = Addr[21:21]\r
//\r
- Ic = RShiftU64 (Addr, 21) & 0x01;\r
+ BitIc = RShiftU64 (Addr, 21) & 0x01;\r
//\r
// imm5c = Addr[20:16] for 5 bits\r
//\r
- Imm5c = RShiftU64 (Addr, 16) & 0x1F;\r
+ BitImm5c = RShiftU64 (Addr, 16) & 0x1F;\r
//\r
// imm9d = Addr[15:7] for 9 bits\r
//\r
- Imm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
+ BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
//\r
// imm7b = Addr[6:0] for 7 bits\r
//\r
- Imm7b = Addr & 0x7F;\r
+ BitImm7b = Addr & 0x7F;\r
\r
//\r
// Put the EBC entry point in r8, which is the location of the return value\r
//\r
// Next is jumbled data, including opcode and rest of address\r
//\r
- Code[2] = LShiftU64 (Imm7b, 13);\r
+ Code[2] = LShiftU64 (BitImm7b, 13);\r
Code[2] = Code[2] | LShiftU64 (0x00, 20); // vc\r
- Code[2] = Code[2] | LShiftU64 (Ic, 21);\r
- Code[2] = Code[2] | LShiftU64 (Imm5c, 22);\r
- Code[2] = Code[2] | LShiftU64 (Imm9d, 27);\r
- Code[2] = Code[2] | LShiftU64 (I, 36);\r
+ Code[2] = Code[2] | LShiftU64 (BitIc, 21);\r
+ Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);\r
+ Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);\r
+ Code[2] = Code[2] | LShiftU64 (BitI, 36);\r
Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);\r
Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);\r
\r
// Extract bits from the address for insertion into the instruction\r
// i = Addr[63:63]\r
//\r
- I = RShiftU64 (Addr, 63) & 0x01;\r
+ BitI = RShiftU64 (Addr, 63) & 0x01;\r
//\r
// ic = Addr[21:21]\r
//\r
- Ic = RShiftU64 (Addr, 21) & 0x01;\r
+ BitIc = RShiftU64 (Addr, 21) & 0x01;\r
//\r
// imm5c = Addr[20:16] for 5 bits\r
//\r
- Imm5c = RShiftU64 (Addr, 16) & 0x1F;\r
+ BitImm5c = RShiftU64 (Addr, 16) & 0x1F;\r
//\r
// imm9d = Addr[15:7] for 9 bits\r
//\r
- Imm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
+ BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
//\r
// imm7b = Addr[6:0] for 7 bits\r
//\r
- Imm7b = Addr & 0x7F;\r
+ BitImm7b = Addr & 0x7F;\r
\r
//\r
// Put it in r31, a scratch register\r
//\r
// Next is jumbled data, including opcode and rest of address\r
//\r
- Code[2] = LShiftU64(Imm7b, 13);\r
+ Code[2] = LShiftU64(BitImm7b, 13);\r
Code[2] = Code[2] | LShiftU64 (0x00, 20); // vc\r
- Code[2] = Code[2] | LShiftU64 (Ic, 21);\r
- Code[2] = Code[2] | LShiftU64 (Imm5c, 22);\r
- Code[2] = Code[2] | LShiftU64 (Imm9d, 27);\r
- Code[2] = Code[2] | LShiftU64 (I, 36);\r
+ Code[2] = Code[2] | LShiftU64 (BitIc, 21);\r
+ Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);\r
+ Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);\r
+ Code[2] = Code[2] | LShiftU64 (BitI, 36);\r
Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);\r
Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);\r
\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ Given raw bytes of Itanium based code, format them into a bundle and\r
+ write them out.\r
+\r
+ @param MemPtr pointer to memory location to write the bundles\r
+ to.\r
+ @param Template 5-bit template.\r
+ @param Slot0 Instruction slot 0 data for the bundle.\r
+ @param Slot1 Instruction slot 1 data for the bundle.\r
+ @param Slot2 Instruction slot 2 data for the bundle.\r
+\r
+ @retval EFI_INVALID_PARAMETER Pointer is not aligned\r
+ @retval EFI_INVALID_PARAMETER No more than 5 bits in template\r
+ @retval EFI_INVALID_PARAMETER More than 41 bits used in code\r
+ @retval EFI_SUCCESS All data is written.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
WriteBundle (\r
IN UINT64 Slot1,\r
IN UINT64 Slot2\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Given raw bytes of Itanium based code, format them into a bundle and\r
- write them out.\r
- \r
-Arguments:\r
-\r
- MemPtr - pointer to memory location to write the bundles to\r
- Template - 5-bit template\r
- Slot0-2 - instruction slot data for the bundle\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Pointer is not aligned\r
- - No more than 5 bits in template\r
- - More than 41 bits used in code\r
- EFI_SUCCESS - All data is written.\r
-\r
---*/\r
{\r
UINT8 *BPtr;\r
UINT32 Index;\r
return EFI_SUCCESS;\r
}\r
\r
-VOID\r
-EbcLLCALLEX (\r
- IN VM_CONTEXT *VmPtr,\r
- IN UINTN FuncAddr,\r
- IN UINTN NewStackPointer,\r
- IN VOID *FramePtr,\r
- IN UINT8 Size\r
- )\r
-/*++\r
-\r
-Routine Description:\r
\r
- This function is called to execute an EBC CALLEX instruction. \r
+/**\r
+ This function is called to execute an EBC CALLEX instruction.\r
The function check the callee's content to see whether it is common native\r
code or a thunk to another piece of EBC code.\r
If the callee is common native code, use EbcLLCAllEXASM to manipulate,\r
otherwise, set the VM->IP to target EBC code directly to avoid another VM\r
be startup which cost time and stack space.\r
- \r
-Arguments:\r
-\r
- VmPtr - Pointer to a VM context.\r
- FuncAddr - Callee's address\r
- NewStackPointer - New stack pointer after the call\r
- FramePtr - New frame pointer after the call\r
- Size - The size of call instruction\r
\r
-Returns:\r
+ @param VmPtr Pointer to a VM context.\r
+ @param FuncAddr Callee's address\r
+ @param NewStackPointer New stack pointer after the call\r
+ @param FramePtr New frame pointer after the call\r
+ @param Size The size of call instruction\r
\r
- None.\r
- \r
---*/\r
+**/\r
+VOID\r
+EbcLLCALLEX (\r
+ IN VM_CONTEXT *VmPtr,\r
+ IN UINTN FuncAddr,\r
+ IN UINTN NewStackPointer,\r
+ IN VOID *FramePtr,\r
+ IN UINT8 Size\r
+ )\r
{\r
UINTN IsThunk;\r
UINTN TargetEbcAddr;\r