/** @file\r
Contains code that implements the virtual machine.\r
\r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 2008, 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
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Decode a 16-bit index to determine the offset. Given an index value:\r
+\r
+ b15 - sign bit\r
+ b14:12 - number of bits in this index assigned to natural units (=a)\r
+ ba:11 - constant units = ConstUnits\r
+ b0:a - natural units = NaturalUnits\r
+ \r
+ Given this info, the offset can be computed by:\r
+ offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN))\r
+\r
+ Max offset is achieved with index = 0x7FFF giving an offset of\r
+ 0x27B (32-bit machine) or 0x477 (64-bit machine).\r
+ Min offset is achieved with index = \r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param CodeOffset Offset from IP of the location of the 16-bit index\r
+ to decode.\r
+\r
+ @return The decoded offset.\r
+\r
+**/\r
STATIC\r
INT16\r
VmReadIndex16 (\r
IN UINT32 CodeOffset\r
);\r
\r
+/**\r
+ Decode a 32-bit index to determine the offset.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param CodeOffset Offset from IP of the location of the 32-bit index\r
+ to decode.\r
+\r
+ @return Converted index per EBC VM specification.\r
+\r
+**/\r
STATIC\r
INT32\r
VmReadIndex32 (\r
IN UINT32 CodeOffset\r
);\r
\r
+/**\r
+ Decode a 64-bit index to determine the offset.\r
+\r
+ @param VmPtr A pointer to VM context.s\r
+ @param CodeOffset Offset from IP of the location of the 64-bit index\r
+ to decode.\r
+\r
+ @return Converted index per EBC VM specification\r
+\r
+**/\r
STATIC\r
INT64\r
VmReadIndex64 (\r
IN UINT32 CodeOffset\r
);\r
\r
+/**\r
+ Reads 8-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 8-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT8\r
VmReadMem8 (\r
IN UINTN Addr\r
);\r
\r
+/**\r
+ Reads 16-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 16-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT16\r
VmReadMem16 (\r
IN UINTN Addr\r
);\r
\r
+/**\r
+ Reads 32-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 32-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT32\r
VmReadMem32 (\r
IN UINTN Addr\r
);\r
\r
+/**\r
+ Reads 64-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 64-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT64\r
VmReadMem64 (\r
IN UINTN Addr\r
);\r
\r
+/**\r
+ Read a natural value from memory. May or may not be aligned.\r
+\r
+ @param VmPtr current VM context\r
+ @param Addr the address to read from\r
+\r
+ @return The natural value at address Addr.\r
+\r
+**/\r
STATIC\r
UINTN\r
VmReadMemN (\r
IN UINTN Addr\r
);\r
\r
+/**\r
+ Writes 8-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
VmWriteMem8 (\r
IN VM_CONTEXT *VmPtr,\r
- UINTN Addr,\r
+ IN UINTN Addr,\r
IN UINT8 Data\r
);\r
\r
+/**\r
+ Writes 16-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
VmWriteMem16 (\r
IN VM_CONTEXT *VmPtr,\r
- UINTN Addr,\r
+ IN UINTN Addr,\r
IN UINT16 Data\r
);\r
\r
+/**\r
+ Writes 32-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
VmWriteMem32 (\r
IN VM_CONTEXT *VmPtr,\r
- UINTN Addr,\r
+ IN UINTN Addr,\r
IN UINT32 Data\r
);\r
\r
+/**\r
+ Reads 16-bit unsinged data from the code stream.\r
+\r
+ This routine provides the ability to read raw unsigned data from the code\r
+ stream.\r
+\r
+ @param VmPtr A pointer to VM context\r
+ @param Offset Offset from current IP to the raw data to read.\r
+\r
+ @return The raw unsigned 16-bit value from the code stream.\r
+\r
+**/\r
STATIC\r
UINT16\r
VmReadCode16 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Reads 32-bit unsinged data from the code stream.\r
+\r
+ This routine provides the ability to read raw unsigned data from the code\r
+ stream.\r
+\r
+ @param VmPtr A pointer to VM context\r
+ @param Offset Offset from current IP to the raw data to read.\r
+\r
+ @return The raw unsigned 32-bit value from the code stream.\r
+\r
+**/\r
STATIC\r
UINT32\r
VmReadCode32 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Reads 64-bit unsinged data from the code stream.\r
+\r
+ This routine provides the ability to read raw unsigned data from the code\r
+ stream.\r
+\r
+ @param VmPtr A pointer to VM context\r
+ @param Offset Offset from current IP to the raw data to read.\r
+\r
+ @return The raw unsigned 64-bit value from the code stream.\r
+\r
+**/\r
STATIC\r
UINT64\r
VmReadCode64 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Reads 8-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT8\r
VmReadImmed8 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Reads 16-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT16\r
VmReadImmed16 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Reads 32-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT32\r
VmReadImmed32 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Reads 64-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT64\r
VmReadImmed64 (\r
IN UINT32 Offset\r
);\r
\r
+/**\r
+ Given an address that EBC is going to read from or write to, return\r
+ an appropriate address that accounts for a gap in the stack.\r
+ The stack for this application looks like this (high addr on top)\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+ The EBC assumes that its arguments are at the top of its stack, which\r
+ is where the VM stack is really. Therefore if the EBC does memory\r
+ accesses into the VM stack area, then we need to convert the address\r
+ to point to the EBC entry point arguments area. Do this here.\r
+\r
+ @param VmPtr A Pointer to VM context.\r
+ @param Addr Address of interest\r
+\r
+ @return The unchanged address if it's not in the VM stack region. Otherwise,\r
+ adjust for the stack gap and return the modified address.\r
+\r
+**/\r
STATIC\r
UINTN\r
ConvertStackAddr (\r
IN UINTN Addr\r
);\r
\r
+/**\r
+ Execute all the EBC data manipulation instructions.\r
+ Since the EBC data manipulation instructions all have the same basic form,\r
+ they can share the code that does the fetch of operands and the write-back\r
+ of the result. This function performs the fetch of the operands (even if\r
+ both are not needed to be fetched, like NOT instruction), dispatches to the\r
+ appropriate subfunction, then writes back the returned result.\r
+\r
+ Format:\r
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param IsSignedOp Indicates whether the operand is signed or not.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteDataManip (\r
IN VM_CONTEXT *VmPtr,\r
- IN BOOLEAN IsSignedOperation\r
+ IN BOOLEAN IsSignedOp\r
);\r
\r
//\r
// Functions that execute VM opcodes\r
//\r
+/**\r
+ Execute the EBC BREAK instruction.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteBREAK (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the JMP instruction.\r
+\r
+ Instruction syntax:\r
+ JMP64{cs|cc} Immed64\r
+ JMP32{cs|cc} {@}R1 {Immed32|Index32}\r
+ \r
+ Encoding:\r
+ b0.7 - immediate data present\r
+ b0.6 - 1 = 64 bit immediate data\r
+ 0 = 32 bit immediate data\r
+ b1.7 - 1 = conditional\r
+ b1.6 1 = CS (condition set)\r
+ 0 = CC (condition clear)\r
+ b1.4 1 = relative address\r
+ 0 = absolute address\r
+ b1.3 1 = operand1 indirect\r
+ b1.2-0 operand 1\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteJMP (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC JMP8 instruction.\r
+\r
+ Instruction syntax:\r
+ JMP8{cs|cc} Offset/2\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteJMP8 (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Implements the EBC CALL instruction.\r
+\r
+ Instruction format:\r
+ CALL64 Immed64\r
+ CALL32 {@}R1 {Immed32|Index32}\r
+ CALLEX64 Immed64\r
+ CALLEX16 {@}R1 {Immed32}\r
+\r
+ If Rx == R0, then it's a PC relative call to PC = PC + imm32.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteCALL (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC RET instruction.\r
+\r
+ Instruction syntax:\r
+ RET\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteRET (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC CMP instruction.\r
+\r
+ Instruction syntax:\r
+ CMP[32|64][eq|lte|gte|ulte|ugte] R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteCMP (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC CMPI instruction\r
+\r
+ Instruction syntax:\r
+ CMPI[32|64]{w|d}[eq|lte|gte|ulte|ugte] {@}Rx {Index16}, Immed16|Immed32\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteCMPI (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the MOVxx instructions.\r
+\r
+ Instruction format:\r
+ \r
+ MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}\r
+ MOVqq {@}R1 {Index64}, {@}R2 {Index64}\r
+ \r
+ Copies contents of [R2] -> [R1], zero extending where required.\r
+ \r
+ First character indicates the size of the move.\r
+ Second character indicates the size of the index(s).\r
+ \r
+ Invalid to have R1 direct with index.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteMOVxx (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC MOVI.\r
+\r
+ Instruction syntax:\r
+ \r
+ MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
+ \r
+ First variable character specifies the move size\r
+ Second variable character specifies size of the immediate data\r
+ \r
+ Sign-extend the immediate data to the size of the operation, and zero-extend\r
+ if storing to a register.\r
+ \r
+ Operand1 direct with index/immed is invalid.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteMOVI (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC MOV immediate natural. This instruction moves an immediate\r
+ index value into a register or memory location.\r
+\r
+ Instruction syntax:\r
+ \r
+ MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteMOVIn (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC MOVREL instruction.\r
+ Dest <- Ip + ImmData\r
+\r
+ Instruction syntax:\r
+ \r
+ MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteMOVREL (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC PUSHn instruction\r
+\r
+ Instruction syntax:\r
+ PUSHn {@}R1 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecutePUSHn (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC PUSH instruction.\r
+\r
+ Instruction syntax:\r
+ PUSH[32|64] {@}R1 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecutePUSH (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC POPn instruction.\r
+\r
+ Instruction syntax:\r
+ POPn {@}R1 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecutePOPn (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC POP instruction.\r
+\r
+ Instruction syntax:\r
+ POPn {@}R1 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecutePOP (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute all the EBC signed data manipulation instructions.\r
+ Since the EBC data manipulation instructions all have the same basic form,\r
+ they can share the code that does the fetch of operands and the write-back\r
+ of the result. This function performs the fetch of the operands (even if\r
+ both are not needed to be fetched, like NOT instruction), dispatches to the\r
+ appropriate subfunction, then writes back the returned result.\r
+\r
+ Format:\r
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
+\r
+ @param VmPtr A pointer to VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteSignedDataManip (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute all the EBC unsigned data manipulation instructions.\r
+ Since the EBC data manipulation instructions all have the same basic form,\r
+ they can share the code that does the fetch of operands and the write-back\r
+ of the result. This function performs the fetch of the operands (even if\r
+ both are not needed to be fetched, like NOT instruction), dispatches to the\r
+ appropriate subfunction, then writes back the returned result.\r
+\r
+ Format:\r
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
+\r
+ @param VmPtr A pointer to VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteUnsignedDataManip (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC LOADSP instruction.\r
+\r
+ Instruction syntax:\r
+ LOADSP SP1, R2\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteLOADSP (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC STORESP instruction.\r
+\r
+ Instruction syntax:\r
+ STORESP Rx, FLAGS|IP\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteSTORESP (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC MOVsnw instruction. This instruction loads a signed\r
+ natural value from memory or register to another memory or register. On\r
+ 32-bit machines, the value gets sign-extended to 64 bits if the destination\r
+ is a register.\r
+\r
+ Instruction syntax:\r
+ \r
+ MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}\r
+ \r
+ 0:7 1=>operand1 index present\r
+ 0:6 1=>operand2 index present\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteMOVsnd (\r
IN VM_CONTEXT *VmPtr\r
);\r
\r
+/**\r
+ Execute the EBC MOVsnw instruction. This instruction loads a signed\r
+ natural value from memory or register to another memory or register. On\r
+ 32-bit machines, the value gets sign-extended to 64 bits if the destination\r
+ is a register.\r
+\r
+ Instruction syntax:\r
+ \r
+ MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}\r
+ \r
+ 0:7 1=>operand1 index present\r
+ 0:6 1=>operand2 index present\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteMOVsnw (\r
//\r
// Data manipulation subfunctions\r
//\r
+/**\r
+ Execute the EBC NOT instruction.s\r
+\r
+ Instruction syntax:\r
+ NOT[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return ~Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteNOT (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC NEG instruction.\r
+\r
+ Instruction syntax:\r
+ NEG[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op2 * -1\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteNEG (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC ADD instruction.\r
+\r
+ Instruction syntax:\r
+ ADD[32|64] {@}R1, {@}R2 {Index16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 + Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteADD (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC SUB instruction.\r
+\r
+ Instruction syntax:\r
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 - Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteSUB (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC MUL instruction.\r
+\r
+ Instruction syntax:\r
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 * Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteMUL (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC MULU instruction\r
+\r
+ Instruction syntax:\r
+ MULU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return (unsigned)Op1 * (unsigned)Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteMULU (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC DIV instruction.\r
+\r
+ Instruction syntax:\r
+ DIV[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 / Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteDIV (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC DIVU instruction\r
+\r
+ Instruction syntax:\r
+ DIVU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return (unsigned)Op1 / (unsigned)Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteDIVU (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC MOD instruction.\r
+\r
+ Instruction syntax:\r
+ MOD[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 MODULUS Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteMOD (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC MODU instruction.\r
+\r
+ Instruction syntax:\r
+ MODU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 UNSIGNED_MODULUS Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteMODU (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC AND instruction.\r
+\r
+ Instruction syntax:\r
+ AND[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 AND Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteAND (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC OR instruction.\r
+\r
+ Instruction syntax:\r
+ OR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 OR Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteOR (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC XOR instruction.\r
+\r
+ Instruction syntax:\r
+ XOR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 XOR Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteXOR (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC SHL shift left instruction.\r
+\r
+ Instruction syntax:\r
+ SHL[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 << Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteSHL (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC SHR instruction.\r
+\r
+ Instruction syntax:\r
+ SHR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 >> Op2 (unsigned operands)\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteSHR (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC ASHR instruction.\r
+\r
+ Instruction syntax:\r
+ ASHR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return Op1 >> Op2 (signed)\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteASHR (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC EXTNDB instruction to sign-extend a byte value.\r
+\r
+ Instruction syntax:\r
+ EXTNDB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return (INT64)(INT8)Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteEXTNDB (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC EXTNDW instruction to sign-extend a 16-bit value.\r
+\r
+ Instruction syntax:\r
+ EXTNDW[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return (INT64)(INT16)Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteEXTNDW (\r
IN UINT64 Op2\r
);\r
\r
+/**\r
+ Execute the EBC EXTNDD instruction to sign-extend a 32-bit value.\r
+\r
+ Instruction syntax:\r
+ EXTNDD[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Op1 Operand 1 from the instruction\r
+ @param Op2 Operand 2 from the instruction\r
+\r
+ @return (INT64)(INT32)Op2\r
+\r
+**/\r
STATIC\r
UINT64\r
ExecuteEXTNDD (\r
// Once we retrieve the operands for the data manipulation instructions,\r
// call these functions to perform the operation.\r
//\r
-static CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {\r
+STATIC CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {\r
ExecuteNOT,\r
ExecuteNEG,\r
ExecuteADD,\r
ExecuteEXTNDD,\r
};\r
\r
-static CONST VM_TABLE_ENTRY mVmOpcodeTable[] = {\r
+STATIC CONST VM_TABLE_ENTRY mVmOpcodeTable[] = {\r
{ ExecuteBREAK }, // opcode 0x00\r
{ ExecuteJMP }, // opcode 0x01\r
{ ExecuteJMP8 }, // opcode 0x02\r
//\r
// Length of JMP instructions, depending on upper two bits of opcode.\r
//\r
-static CONST UINT8 mJMPLen[] = { 2, 2, 6, 10 };\r
+STATIC CONST UINT8 mJMPLen[] = { 2, 2, 6, 10 };\r
\r
//\r
// Simple Debugger Protocol GUID\r
Given a pointer to a new VM context, execute one or more instructions. This\r
function is only used for test purposes via the EBC VM test protocol.\r
\r
- @param This pointer to protocol interface\r
- @param VmPtr pointer to a VM context\r
- @param InstructionCount how many instructions to execute. 0 if don't count.\r
+ @param This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.\r
+ @param VmPtr A pointer to a VM context.\r
+ @param InstructionCount A pointer to a UINTN value holding the number of\r
+ instructions to execute. If it holds value of 0,\r
+ then the instruction to be executed is 1.\r
\r
- @return EFI_UNSUPPORTED\r
- @return EFI_SUCCESS\r
+ @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.\r
+ @retval EFI_SUCCESS All of the instructions are executed successfully.\r
\r
**/\r
EFI_STATUS\r
/**\r
Execute an EBC image from an entry point or from a published protocol.\r
\r
- @param VmPtr pointer to prepared VM context.\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EBC status.\r
+ @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.\r
+ @retval EFI_SUCCESS All of the instructions are executed successfully.\r
\r
**/\r
EFI_STATUS\r
/**\r
Execute the MOVxx instructions.\r
\r
- @param VmPtr pointer to a VM context.\r
-\r
- @return EFI_UNSUPPORTED\r
- @return EFI_SUCCESS\r
- @return Instruction format:\r
- @return MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}\r
- @return MOVqq {@}R1 {Index64}, {@}R2 {Index64}\r
- @return Copies contents of [R2] -> [R1], zero extending where required.\r
- @return First character indicates the size of the move.\r
- @return Second character indicates the size of the index(s).\r
- @return Invalid to have R1 direct with index.\r
+ Instruction format:\r
+ \r
+ MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}\r
+ MOVqq {@}R1 {Index64}, {@}R2 {Index64}\r
+ \r
+ Copies contents of [R2] -> [R1], zero extending where required.\r
+ \r
+ First character indicates the size of the move.\r
+ Second character indicates the size of the index(s).\r
+ \r
+ Invalid to have R1 direct with index.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC BREAK instruction\r
+ Execute the EBC BREAK instruction.\r
\r
- @param VmPtr pointer to current VM context\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return EFI_UNSUPPORTED\r
- @return EFI_SUCCESS\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the JMP instruction\r
-\r
- @param VmPtr pointer to VM context\r
-\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return JMP64{cs|cc} Immed64\r
- @return JMP32{cs|cc} {@}R1 {Immed32|Index32}\r
- @return Encoding:\r
- @retval b0.7 immediate data present\r
- @retval b0.6 1 = 64 bit immediate data 0 = 32 bit immediate data\r
- @retval b1.7 1 = conditional b1.6 1 = CS (condition set) 0 = CC\r
- (condition clear) b1.4 1 = relative address 0 =\r
- absolute address b1.3 1 = operand1 indirect b1.2-0\r
- operand 1\r
+ Execute the JMP instruction.\r
+\r
+ Instruction syntax:\r
+ JMP64{cs|cc} Immed64\r
+ JMP32{cs|cc} {@}R1 {Immed32|Index32}\r
+ \r
+ Encoding:\r
+ b0.7 - immediate data present\r
+ b0.6 - 1 = 64 bit immediate data\r
+ 0 = 32 bit immediate data\r
+ b1.7 - 1 = conditional\r
+ b1.6 1 = CS (condition set)\r
+ 0 = CC (condition clear)\r
+ b1.4 1 = relative address\r
+ 0 = absolute address\r
+ b1.3 1 = operand1 indirect\r
+ b1.2-0 operand 1\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC JMP8 instruction\r
+ Execute the EBC JMP8 instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ JMP8{cs|cc} Offset/2\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return JMP8{cs|cc} Offset/2\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC MOVI\r
+ Execute the EBC MOVI.\r
+\r
+ Instruction syntax:\r
+ \r
+ MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
+ \r
+ First variable character specifies the move size\r
+ Second variable character specifies size of the immediate data\r
+ \r
+ Sign-extend the immediate data to the size of the operation, and zero-extend\r
+ if storing to a register.\r
+ \r
+ Operand1 direct with index/immed is invalid.\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
- @return First variable character specifies the move size\r
- @return Second variable character specifies size of the immediate data\r
- @return Sign-extend the immediate data to the size of the operation, and zero-extend\r
- @return if storing to a register.\r
- @return Operand1 direct with index/immed is invalid.\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
Execute the EBC MOV immediate natural. This instruction moves an immediate\r
index value into a register or memory location.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ \r
+ MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
Execute the EBC MOVREL instruction.\r
Dest <- Ip + ImmData\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ \r
+ MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
+\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
32-bit machines, the value gets sign-extended to 64 bits if the destination\r
is a register.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ \r
+ MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}\r
+ \r
+ 0:7 1=>operand1 index present\r
+ 0:6 1=>operand2 index present\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}\r
- @return 0:7 1=>operand1 index present\r
- @return 0:6 1=>operand2 index present\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
32-bit machines, the value gets sign-extended to 64 bits if the destination\r
is a register.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ \r
+ MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}\r
+ \r
+ 0:7 1=>operand1 index present\r
+ 0:6 1=>operand2 index present\r
+\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}\r
- @return 0:7 1=>operand1 index present\r
- @return 0:6 1=>operand2 index present\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC PUSHn instruction\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ PUSHn {@}R1 {Index16|Immed16}\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return PUSHn {@}R1 {Index16|Immed16}\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC PUSH instruction\r
+ Execute the EBC PUSH instruction.\r
+\r
+ Instruction syntax:\r
+ PUSH[32|64] {@}R1 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return PUSH[32|64] {@}R1 {Index16|Immed16}\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC POPn instruction\r
+ Execute the EBC POPn instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ POPn {@}R1 {Index16|Immed16}\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return POPn {@}R1 {Index16|Immed16}\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC POP instruction\r
+ Execute the EBC POP instruction.\r
+\r
+ Instruction syntax:\r
+ POPn {@}R1 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return POP {@}R1 {Index16|Immed16}\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
/**\r
Implements the EBC CALL instruction.\r
+\r
Instruction format:\r
- CALL64 Immed64\r
- CALL32 {@}R1 {Immed32|Index32}\r
- CALLEX64 Immed64\r
- CALLEX16 {@}R1 {Immed32}\r
- If Rx == R0, then it's a PC relative call to PC = PC + imm32.\r
+ CALL64 Immed64\r
+ CALL32 {@}R1 {Immed32|Index32}\r
+ CALLEX64 Immed64\r
+ CALLEX16 {@}R1 {Immed32}\r
+\r
+ If Rx == R0, then it's a PC relative call to PC = PC + imm32.\r
\r
- @param VmPtr pointer to a VM context.\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC RET instruction\r
+ Execute the EBC RET instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ RET\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return RET\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC CMP instruction\r
+ Execute the EBC CMP instruction.\r
+\r
+ Instruction syntax:\r
+ CMP[32|64][eq|lte|gte|ulte|ugte] R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return CMP[32|64][eq|lte|gte|ulte|ugte] R1, {@}R2 {Index16|Immed16}\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC CMPI instruction\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ CMPI[32|64]{w|d}[eq|lte|gte|ulte|ugte] {@}Rx {Index16}, Immed16|Immed32\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return CMPI[32|64]{w|d}[eq|lte|gte|ulte|ugte] {@}Rx {Index16}, Immed16|Immed32\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC NOT instruction\r
+ Execute the EBC NOT instruction.s\r
+\r
+ Instruction syntax:\r
+ NOT[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return ~Op2\r
- @return Instruction syntax:\r
- @return NOT[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC NEG instruction\r
+ Execute the EBC NEG instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ NEG[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op2 * -1\r
- @return Instruction syntax:\r
- @return NEG[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC ADD instruction\r
+ Execute the EBC ADD instruction.\r
+\r
+ Instruction syntax:\r
+ ADD[32|64] {@}R1, {@}R2 {Index16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 + Op2\r
- @return Instruction syntax:\r
- @return ADD[32|64] {@}R1, {@}R2 {Index16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC SUB instruction\r
+ Execute the EBC SUB instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
- @retval Op1 Op2 Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+ @return Op1 - Op2\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC MUL instruction\r
+ Execute the EBC MUL instruction.\r
+\r
+ Instruction syntax:\r
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 * Op2\r
- @return Instruction syntax:\r
- @return MUL[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC MULU instruction\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ MULU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return (unsigned)Op1 * (unsigned)Op2\r
- @return Instruction syntax:\r
- @return MULU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC DIV instruction\r
+ Execute the EBC DIV instruction.\r
+\r
+ Instruction syntax:\r
+ DIV[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
- @return Op1/Op2\r
- @return Instruction syntax:\r
- @return DIV[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+ @return Op1 / Op2\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC DIVU instruction\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ DIVU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return (unsigned)Op1 / (unsigned)Op2\r
- @return Instruction syntax:\r
- @return DIVU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC MOD instruction\r
+ Execute the EBC MOD instruction.\r
+\r
+ Instruction syntax:\r
+ MOD[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 MODULUS Op2\r
- @return Instruction syntax:\r
- @return MOD[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC MODU instruction\r
+ Execute the EBC MODU instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ MODU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 UNSIGNED_MODULUS Op2\r
- @return Instruction syntax:\r
- @return MODU[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC AND instruction\r
+ Execute the EBC AND instruction.\r
+\r
+ Instruction syntax:\r
+ AND[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 AND Op2\r
- @return Instruction syntax:\r
- @return AND[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC OR instruction\r
+ Execute the EBC OR instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ OR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 OR Op2\r
- @return Instruction syntax:\r
- @return OR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC XOR instruction\r
+ Execute the EBC XOR instruction.\r
+\r
+ Instruction syntax:\r
+ XOR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 XOR Op2\r
- @return Instruction syntax:\r
- @return XOR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC SHL shift left instruction\r
+ Execute the EBC SHL shift left instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ SHL[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 << Op2\r
- @return Instruction syntax:\r
- @return SHL[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC SHR instruction\r
+ Execute the EBC SHR instruction.\r
+\r
+ Instruction syntax:\r
+ SHR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 >> Op2 (unsigned operands)\r
- @return Instruction syntax:\r
- @return SHR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC ASHR instruction\r
+ Execute the EBC ASHR instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ ASHR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return Op1 >> Op2 (signed)\r
- @return Instruction syntax:\r
- @return ASHR[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC EXTNDB instruction to sign-extend a byte value.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ EXTNDB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return (INT64)(INT8)Op2\r
- @return Instruction syntax:\r
- @return EXTNDB[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC EXTNDW instruction to sign-extend a 16-bit value.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ EXTNDW[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return (INT64)(INT16)Op2\r
- @return Instruction syntax:\r
- @return EXTNDW[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
/**\r
Execute the EBC EXTNDD instruction to sign-extend a 32-bit value.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ EXTNDD[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
+\r
+ @param VmPtr A pointer to a VM context.\r
@param Op1 Operand 1 from the instruction\r
@param Op2 Operand 2 from the instruction\r
\r
@return (INT64)(INT32)Op2\r
- @return Instruction syntax:\r
- @return EXTNDD[32|64] {@}R1, {@}R2 {Index16|Immed16}\r
\r
**/\r
STATIC\r
return (UINT64) Data64;\r
}\r
\r
+\r
+/**\r
+ Execute all the EBC signed data manipulation instructions.\r
+ Since the EBC data manipulation instructions all have the same basic form,\r
+ they can share the code that does the fetch of operands and the write-back\r
+ of the result. This function performs the fetch of the operands (even if\r
+ both are not needed to be fetched, like NOT instruction), dispatches to the\r
+ appropriate subfunction, then writes back the returned result.\r
+\r
+ Format:\r
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
+\r
+ @param VmPtr A pointer to VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteSignedDataManip (\r
return ExecuteDataManip (VmPtr, TRUE);\r
}\r
\r
+\r
+/**\r
+ Execute all the EBC unsigned data manipulation instructions.\r
+ Since the EBC data manipulation instructions all have the same basic form,\r
+ they can share the code that does the fetch of operands and the write-back\r
+ of the result. This function performs the fetch of the operands (even if\r
+ both are not needed to be fetched, like NOT instruction), dispatches to the\r
+ appropriate subfunction, then writes back the returned result.\r
+\r
+ Format:\r
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
+\r
+ @param VmPtr A pointer to VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
ExecuteUnsignedDataManip (\r
both are not needed to be fetched, like NOT instruction), dispatches to the\r
appropriate subfunction, then writes back the returned result.\r
\r
- @param VmPtr pointer to VM context\r
+ Format:\r
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
\r
- @return Standard EBC status\r
- @return Format:\r
- @return INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}\r
+ @param VmPtr A pointer to VM context.\r
+ @param IsSignedOp Indicates whether the operand is signed or not.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC LOADSP instruction\r
+ Execute the EBC LOADSP instruction.\r
+\r
+ Instruction syntax:\r
+ LOADSP SP1, R2\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return LOADSP SP1, R2\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
\r
/**\r
- Execute the EBC STORESP instruction\r
+ Execute the EBC STORESP instruction.\r
\r
- @param VmPtr pointer to a VM context\r
+ Instruction syntax:\r
+ STORESP Rx, FLAGS|IP\r
\r
- @return Standard EFI_STATUS\r
- @return Instruction syntax:\r
- @return STORESP Rx, FLAGS|IP\r
+ @param VmPtr A pointer to a VM context.\r
+\r
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported. \r
+ @retval EFI_SUCCESS The instruction is executed successfully.\r
\r
**/\r
STATIC\r
\r
/**\r
Decode a 16-bit index to determine the offset. Given an index value:\r
- b15 - sign bit\r
- b14:12 - number of bits in this index assigned to natural units (=a)\r
- ba:11 - constant units = C\r
- b0:a - natural units = N\r
+\r
+ b15 - sign bit\r
+ b14:12 - number of bits in this index assigned to natural units (=a)\r
+ ba:11 - constant units = ConstUnits\r
+ b0:a - natural units = NaturalUnits\r
+ \r
Given this info, the offset can be computed by:\r
- offset = sign_bit * (C + N * sizeof(UINTN))\r
+ offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN))\r
+\r
Max offset is achieved with index = 0x7FFF giving an offset of\r
0x27B (32-bit machine) or 0x477 (64-bit machine).\r
- Min offset is achieved with index =\r
+ Min offset is achieved with index = \r
\r
- @param VmPtr pointer to VM context\r
- @param CodeOffset offset from IP of the location of the 16-bit index to\r
- decode\r
+ @param VmPtr A pointer to VM context.\r
+ @param CodeOffset Offset from IP of the location of the 16-bit index\r
+ to decode.\r
\r
@return The decoded offset.\r
\r
{\r
UINT16 Index;\r
INT16 Offset;\r
- INT16 C;\r
- INT16 N;\r
+ INT16 ConstUnits;\r
+ INT16 NaturalUnits;\r
INT16 NBits;\r
INT16 Mask;\r
\r
Index = VmReadCode16 (VmPtr, CodeOffset);\r
\r
//\r
- // Get the mask for N. First get the number of bits from the index.\r
+ // Get the mask for NaturalUnits. First get the number of bits from the index.\r
//\r
NBits = (INT16) ((Index & 0x7000) >> 12);\r
\r
Mask = (INT16) ((INT16)~0 << NBits);\r
\r
//\r
- // Now using the mask, extract N from the lower bits of the index.\r
+ // Now using the mask, extract NaturalUnits from the lower bits of the index.\r
//\r
- N = (INT16) (Index &~Mask);\r
+ NaturalUnits = (INT16) (Index &~Mask);\r
\r
//\r
- // Now compute C\r
+ // Now compute ConstUnits\r
//\r
- C = (INT16) (((Index &~0xF000) & Mask) >> NBits);\r
+ ConstUnits = (INT16) (((Index &~0xF000) & Mask) >> NBits);\r
\r
- Offset = (INT16) (N * sizeof (UINTN) + C);\r
+ Offset = (INT16) (NaturalUnits * sizeof (UINTN) + ConstUnits);\r
\r
//\r
// Now set the sign\r
/**\r
Decode a 32-bit index to determine the offset.\r
\r
- @param VmPtr pointer to VM context\r
- @param CodeOffset offset from IP of the location of the 32-bit index to\r
- decode\r
+ @param VmPtr A pointer to VM context.\r
+ @param CodeOffset Offset from IP of the location of the 32-bit index\r
+ to decode.\r
\r
- @return Converted index per EBC VM specification\r
+ @return Converted index per EBC VM specification.\r
\r
**/\r
STATIC\r
{\r
UINT32 Index;\r
INT32 Offset;\r
- INT32 C;\r
- INT32 N;\r
+ INT32 ConstUnits;\r
+ INT32 NaturalUnits;\r
INT32 NBits;\r
INT32 Mask;\r
\r
Index = VmReadImmed32 (VmPtr, CodeOffset);\r
\r
//\r
- // Get the mask for N. First get the number of bits from the index.\r
+ // Get the mask for NaturalUnits. First get the number of bits from the index.\r
//\r
NBits = (Index & 0x70000000) >> 28;\r
\r
Mask = (INT32)~0 << NBits;\r
\r
//\r
- // Now using the mask, extract N from the lower bits of the index.\r
+ // Now using the mask, extract NaturalUnits from the lower bits of the index.\r
//\r
- N = Index &~Mask;\r
+ NaturalUnits = Index &~Mask;\r
\r
//\r
- // Now compute C\r
+ // Now compute ConstUnits\r
//\r
- C = ((Index &~0xF0000000) & Mask) >> NBits;\r
+ ConstUnits = ((Index &~0xF0000000) & Mask) >> NBits;\r
\r
- Offset = N * sizeof (UINTN) + C;\r
+ Offset = NaturalUnits * sizeof (UINTN) + ConstUnits;\r
\r
//\r
// Now set the sign\r
/**\r
Decode a 64-bit index to determine the offset.\r
\r
- @param VmPtr pointer to VM context\r
- @param CodeOffset offset from IP of the location of the 64-bit index to\r
- decode\r
+ @param VmPtr A pointer to VM context.s\r
+ @param CodeOffset Offset from IP of the location of the 64-bit index\r
+ to decode.\r
\r
@return Converted index per EBC VM specification\r
\r
{\r
UINT64 Index;\r
INT64 Offset;\r
- INT64 C;\r
- INT64 N;\r
+ INT64 ConstUnits;\r
+ INT64 NaturalUnits;\r
INT64 NBits;\r
INT64 Mask;\r
\r
Index = VmReadCode64 (VmPtr, CodeOffset);\r
\r
//\r
- // Get the mask for N. First get the number of bits from the index.\r
+ // Get the mask for NaturalUnits. First get the number of bits from the index.\r
//\r
NBits = RShiftU64 ((Index & 0x7000000000000000ULL), 60);\r
\r
Mask = (LShiftU64 ((UINT64)~0, (UINTN)NBits));\r
\r
//\r
- // Now using the mask, extract N from the lower bits of the index.\r
+ // Now using the mask, extract NaturalUnits from the lower bits of the index.\r
//\r
- N = Index &~Mask;\r
+ NaturalUnits = Index &~Mask;\r
\r
//\r
- // Now compute C\r
+ // Now compute ConstUnits\r
//\r
- C = ARShiftU64 (((Index &~0xF000000000000000ULL) & Mask), (UINTN)NBits);\r
+ ConstUnits = ARShiftU64 (((Index &~0xF000000000000000ULL) & Mask), (UINTN)NBits);\r
\r
- Offset = MultU64x64 (N, sizeof (UINTN)) + C;\r
+ Offset = MultU64x64 (NaturalUnits, sizeof (UINTN)) + ConstUnits;\r
\r
//\r
// Now set the sign\r
\r
\r
/**\r
- The following VmWriteMem? routines are called by the EBC data\r
+ Writes 8-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
movement instructions that write to memory. Since these writes\r
may be to the stack, which looks like (high address on top) this,\r
+\r
[EBC entry point arguments]\r
[VM stack]\r
[EBC stack]\r
+\r
we need to detect all attempts to write to the EBC entry point argument\r
- stack area and adjust the address (which will initially point into the\r
+ stack area and adjust the address (which will initially point into the \r
VM stack) to point into the EBC entry point arguments.\r
\r
- @param VmPtr pointer to a VM context\r
- @param Addr adddress to write to\r
- @param Data value to write to Addr\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
\r
- @return Standard EFI_STATUS\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
\r
**/\r
STATIC\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Writes 16-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
VmWriteMem16 (\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ Writes 32-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
VmWriteMem32 (\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ Writes 64-bit data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
EFI_STATUS\r
VmWriteMem64 (\r
IN VM_CONTEXT *VmPtr,\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ Writes UINTN data to memory address.\r
+ \r
+ This routine is called by the EBC data\r
+ movement instructions that write to memory. Since these writes\r
+ may be to the stack, which looks like (high address on top) this,\r
+\r
+ [EBC entry point arguments]\r
+ [VM stack]\r
+ [EBC stack]\r
+\r
+ we need to detect all attempts to write to the EBC entry point argument\r
+ stack area and adjust the address (which will initially point into the \r
+ VM stack) to point into the EBC entry point arguments.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Addr Adddress to write to.\r
+ @param Data Value to write to Addr.\r
+\r
+ @retval EFI_SUCCESS The instruction is executed successfully. \r
+ @retval Other Some error occurs when writing data to the address.\r
+\r
+**/\r
EFI_STATUS\r
VmWriteMemN (\r
IN VM_CONTEXT *VmPtr,\r
\r
\r
/**\r
- The following VmReadImmed routines are called by the EBC execute\r
+ Reads 8-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
functions to read EBC immediate values from the code stream.\r
Since we can't assume alignment, each tries to read in the biggest\r
chunks size available, but will revert to smaller reads if necessary.\r
\r
- @param VmPtr pointer to a VM context\r
+ @param VmPtr A pointer to a VM context.\r
@param Offset offset from IP of the code bytes to read.\r
\r
@return Signed data of the requested size from the specified address.\r
return * (INT8 *) (VmPtr->Ip + Offset);\r
}\r
\r
+/**\r
+ Reads 16-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT16\r
VmReadImmed16 (\r
return (INT16) (*(UINT8 *) (VmPtr->Ip + Offset) + (*(UINT8 *) (VmPtr->Ip + Offset + 1) << 8));\r
}\r
\r
+\r
+/**\r
+ Reads 32-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT32\r
VmReadImmed32 (\r
return Data;\r
}\r
\r
+\r
+/**\r
+ Reads 64-bit immediate value at the offset.\r
+\r
+ This routine is called by the EBC execute\r
+ functions to read EBC immediate values from the code stream.\r
+ Since we can't assume alignment, each tries to read in the biggest\r
+ chunks size available, but will revert to smaller reads if necessary.\r
+\r
+ @param VmPtr A pointer to a VM context.\r
+ @param Offset offset from IP of the code bytes to read.\r
+\r
+ @return Signed data of the requested size from the specified address.\r
+\r
+**/\r
STATIC\r
INT64\r
VmReadImmed64 (\r
\r
\r
/**\r
- The following VmReadCode() routines provide the ability to read raw\r
- unsigned data from the code stream.\r
+ Reads 16-bit unsinged data from the code stream.\r
+\r
+ This routine provides the ability to read raw unsigned data from the code\r
+ stream.\r
\r
- @param VmPtr pointer to VM context\r
- @param Offset offset from current IP to the raw data to read.\r
+ @param VmPtr A pointer to VM context\r
+ @param Offset Offset from current IP to the raw data to read.\r
\r
@return The raw unsigned 16-bit value from the code stream.\r
\r
return (UINT16) (*(UINT8 *) (VmPtr->Ip + Offset) + (*(UINT8 *) (VmPtr->Ip + Offset + 1) << 8));\r
}\r
\r
+\r
+/**\r
+ Reads 32-bit unsinged data from the code stream.\r
+\r
+ This routine provides the ability to read raw unsigned data from the code\r
+ stream.\r
+\r
+ @param VmPtr A pointer to VM context\r
+ @param Offset Offset from current IP to the raw data to read.\r
+\r
+ @return The raw unsigned 32-bit value from the code stream.\r
+\r
+**/\r
STATIC\r
UINT32\r
VmReadCode32 (\r
return Data;\r
}\r
\r
+\r
+/**\r
+ Reads 64-bit unsinged data from the code stream.\r
+\r
+ This routine provides the ability to read raw unsigned data from the code\r
+ stream.\r
+\r
+ @param VmPtr A pointer to VM context\r
+ @param Offset Offset from current IP to the raw data to read.\r
+\r
+ @return The raw unsigned 64-bit value from the code stream.\r
+\r
+**/\r
STATIC\r
UINT64\r
VmReadCode64 (\r
return Data64;\r
}\r
\r
+\r
+/**\r
+ Reads 8-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 8-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT8\r
VmReadMem8 (\r
return * (UINT8 *) Addr;\r
}\r
\r
+/**\r
+ Reads 16-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 16-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT16\r
VmReadMem16 (\r
return (UINT16) (*(UINT8 *) Addr + (*(UINT8 *) (Addr + 1) << 8));\r
}\r
\r
+/**\r
+ Reads 32-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 32-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT32\r
VmReadMem32 (\r
return Data;\r
}\r
\r
+/**\r
+ Reads 64-bit data form the memory address.\r
+\r
+ @param VmPtr A pointer to VM context.\r
+ @param Addr The memory address.\r
+\r
+ @return The 64-bit value from the memory adress.\r
+\r
+**/\r
STATIC\r
UINT64\r
VmReadMem64 (\r
accesses into the VM stack area, then we need to convert the address\r
to point to the EBC entry point arguments area. Do this here.\r
\r
- @param VmPtr pointer to VM context\r
- @param Addr address of interest\r
+ @param VmPtr A Pointer to VM context.\r
+ @param Addr Address of interest\r
\r
@return The unchanged address if it's not in the VM stack region. Otherwise,\r
- @return adjust for the stack gap and return the modified address.\r
+ adjust for the stack gap and return the modified address.\r
\r
**/\r
STATIC\r
return Data;\r
}\r
\r
+/**\r
+ Returns the version of the EBC virtual machine.\r
+ \r
+ @return The 64-bit version of EBC virtual machine.\r
+\r
+**/\r
UINT64\r
GetVmVersion (\r
VOID\r
/** @file\r
Top level module for the EBC virtual machine implementation.\r
- Provides auxilliary support routines for the VM. That is, routines\r
+ Provides auxiliary support routines for the VM. That is, routines\r
that are not particularly related to VM execution of EBC instructions.\r
\r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 2008, 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
EBC_THUNK_LIST *ThunkList;\r
} EBC_IMAGE_LIST;\r
\r
+/**\r
+ This routine is called by the core when an image is being unloaded from\r
+ memory. Basically we now have the opportunity to do any necessary cleanup.\r
+ Typically this will include freeing any memory allocated for thunk-creation.\r
+\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param ImageHandle Handle of image for which the thunk is being\r
+ created.\r
+\r
+ @retval EFI_INVALID_PARAMETER The ImageHandle passed in was not found in the\r
+ internal list of EBC image handles.\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
IN EFI_HANDLE ImageHandle\r
);\r
\r
+/**\r
+ This is the top-level routine plugged into the EBC protocol. Since thunks\r
+ are very processor-specific, from here we dispatch directly to the very\r
+ processor-specific routine EbcCreateThunks().\r
+\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param ImageHandle Handle of image for which the thunk is being\r
+ created. The EBC interpreter may use this to\r
+ keep track of any resource allocations\r
+ performed in loading and executing the image.\r
+ @param EbcEntryPoint Address of the actual EBC entry point or\r
+ protocol service the thunk should call.\r
+ @param Thunk Returned pointer to a thunk created.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_INVALID_PARAMETER Image entry point is not 2-byte aligned.\r
+ @retval EFI_OUT_OF_RESOURCES Memory could not be allocated for the thunk.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
OUT VOID **Thunk\r
);\r
\r
+/**\r
+ Called to get the version of the interpreter.\r
+\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param Version Pointer to where to store the returned version\r
+ of the interpreter.\r
+ \r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_INVALID_PARAMETER Version pointer is NULL.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
IN OUT UINT64 *Version\r
);\r
\r
+/**\r
+ To install default Callback function for the VM interpreter.\r
+\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval Others Some error occurs when creating periodic event.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
IN EFI_DEBUG_SUPPORT_PROTOCOL *This\r
);\r
\r
+/**\r
+ The default Exception Callback for the VM interpreter.\r
+ In this function, we report status code, and print debug information\r
+ about EBC_CONTEXT, then dead loop.\r
+\r
+ @param InterruptType Interrupt type.\r
+ @param SystemContext EBC system context.\r
+\r
+**/\r
STATIC\r
VOID\r
EFIAPI\r
IN EFI_SYSTEM_CONTEXT SystemContext\r
);\r
\r
+/**\r
+ The periodic callback function for EBC VM interpreter, which is used\r
+ to support the EFI debug support protocol.\r
+\r
+ @param Event The Periodic Callback Event.\r
+ @param Context It should be the address of VM_CONTEXT pointer.\r
+\r
+**/\r
STATIC\r
VOID\r
EFIAPI\r
IN VOID *Context\r
);\r
\r
+/**\r
+ The VM interpreter calls this function on a periodic basis to support\r
+ the EFI debug support protocol.\r
+\r
+ @param VmPtr Pointer to a VM context for passing info to the\r
+ debugger.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
// These two functions and the GUID are used to produce an EBC test protocol.\r
// This functionality is definitely not required for execution.\r
//\r
+/**\r
+ Produces an EBC VM test protocol that can be used for regression tests.\r
+\r
+ @param IHandle Handle on which to install the protocol.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
InitEbcVmTestProtocol (\r
IN EFI_HANDLE *Handle\r
);\r
\r
+/**\r
+ Returns the EFI_UNSUPPORTED Status.\r
+ \r
+ @return EFI_UNSUPPORTED This function always return EFI_UNSUPPORTED status.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EbcVmTestUnsupported (\r
VOID\r
);\r
\r
+/**\r
+ Registers a callback function that the EBC interpreter calls to flush the\r
+ processor instruction cache following creation of thunks. \r
+\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param Flush Pointer to a function of type EBC_ICACH_FLUSH.\r
+ \r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
IN EBC_ICACHE_FLUSH Flush\r
);\r
\r
+/**\r
+ This EBC debugger protocol service is called by the debug agent\r
+\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the\r
+ maximum supported processor index is returned.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
OUT UINTN *MaxProcessorIndex\r
);\r
\r
+/**\r
+ This protocol service is called by the debug agent to register a function\r
+ for us to call on a periodic basis.\r
+\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param ProcessorIndex Specifies which processor the callback function\r
+ applies to.\r
+ @param PeriodicCallback A pointer to a function of type\r
+ PERIODIC_CALLBACK that is the main periodic\r
+ entry point of the debug agent. It receives as a\r
+ parameter a pointer to the full context of the\r
+ interrupted execution thread.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a\r
+ callback function was previously registered.\r
+ @retval EFI_INVALID_PARAMETER Null PeriodicCallback parameter when no\r
+ callback function was previously registered.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
IN EFI_PERIODIC_CALLBACK PeriodicCallback\r
);\r
\r
+/**\r
+ This protocol service is called by the debug agent to register a function\r
+ for us to call when we detect an exception.\r
+\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param ProcessorIndex Specifies which processor the callback function\r
+ applies to.\r
+ @param ExceptionCallback A pointer to a function of type\r
+ EXCEPTION_CALLBACK that is called when the\r
+ processor exception specified by ExceptionType\r
+ occurs. Passing NULL unregisters any previously\r
+ registered function associated with\r
+ ExceptionType.\r
+ @param ExceptionType Specifies which processor exception to hook.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_ALREADY_STARTED Non-NULL ExceptionCallback parameter when a\r
+ callback function was previously registered.\r
+ @retval EFI_INVALID_PARAMETER ExceptionType parameter is negative or exceeds\r
+ MAX_EBC_EXCEPTION.\r
+ @retval EFI_INVALID_PARAMETER Null ExceptionCallback parameter when no\r
+ callback function was previously registered.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
IN EFI_EXCEPTION_TYPE ExceptionType\r
);\r
\r
+/**\r
+ This EBC debugger protocol service is called by the debug agent. Required\r
+ for DebugSupport compliance but is only stubbed out for EBC.\r
+\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param ProcessorIndex Specifies which processor the callback function\r
+ applies to.\r
+ @param Start StartSpecifies the physical base of the memory\r
+ range to be invalidated.\r
+ @param Length Specifies the minimum number of bytes in the\r
+ processor's instruction cache to invalidate. \r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
// also be global since the execution of an EBC image does not provide\r
// a This pointer.\r
//\r
-static EBC_IMAGE_LIST *mEbcImageList = NULL;\r
+STATIC EBC_IMAGE_LIST *mEbcImageList = NULL;\r
\r
//\r
// Callback function to flush the icache after thunk creation\r
//\r
-static EBC_ICACHE_FLUSH mEbcICacheFlush;\r
+STATIC EBC_ICACHE_FLUSH mEbcICacheFlush;\r
\r
//\r
// These get set via calls by the debug agent\r
//\r
-static EFI_PERIODIC_CALLBACK mDebugPeriodicCallback = NULL;\r
-static EFI_EXCEPTION_CALLBACK mDebugExceptionCallback[MAX_EBC_EXCEPTION + 1] = {NULL};\r
-static EFI_GUID mEfiEbcVmTestProtocolGuid = EFI_EBC_VM_TEST_PROTOCOL_GUID;\r
+STATIC EFI_PERIODIC_CALLBACK mDebugPeriodicCallback = NULL;\r
+STATIC EFI_EXCEPTION_CALLBACK mDebugExceptionCallback[MAX_EBC_EXCEPTION + 1] = {NULL};\r
+STATIC EFI_GUID mEfiEbcVmTestProtocolGuid = EFI_EBC_VM_TEST_PROTOCOL_GUID;\r
\r
-static VOID* mStackBuffer[MAX_STACK_NUM];\r
-static EFI_HANDLE mStackBufferIndex[MAX_STACK_NUM];\r
-static UINTN mStackNum = 0;\r
+STATIC VOID* mStackBuffer[MAX_STACK_NUM];\r
+STATIC EFI_HANDLE mStackBufferIndex[MAX_STACK_NUM];\r
+STATIC UINTN mStackNum = 0;\r
\r
//\r
// Event for Periodic callback\r
//\r
-static EFI_EVENT mEbcPeriodicEvent;\r
+STATIC EFI_EVENT mEbcPeriodicEvent;\r
VM_CONTEXT *mVmPtr = NULL;\r
\r
\r
are very processor-specific, from here we dispatch directly to the very\r
processor-specific routine EbcCreateThunks().\r
\r
- @param This protocol instance pointer\r
- @param ImageHandle handle to the image. The EBC interpreter may use\r
- this to keep track of any resource allocations\r
- performed in loading and executing the image.\r
- @param EbcEntryPoint the entry point for the image (as defined in the\r
- file header)\r
- @param Thunk pointer to thunk pointer where the address of the\r
- created thunk is returned.\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param ImageHandle Handle of image for which the thunk is being\r
+ created. The EBC interpreter may use this to\r
+ keep track of any resource allocations\r
+ performed in loading and executing the image.\r
+ @param EbcEntryPoint Address of the actual EBC entry point or\r
+ protocol service the thunk should call.\r
+ @param Thunk Returned pointer to a thunk created.\r
\r
- @return EFI_STATUS\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_INVALID_PARAMETER Image entry point is not 2-byte aligned.\r
+ @retval EFI_OUT_OF_RESOURCES Memory could not be allocated for the thunk.\r
\r
**/\r
STATIC\r
/**\r
This EBC debugger protocol service is called by the debug agent\r
\r
- @param This pointer to the caller's debug support protocol\r
- interface\r
- @param MaxProcessorIndex pointer to a caller allocated UINTN in which the\r
- maximum processor index is returned.\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the\r
+ maximum supported processor index is returned.\r
\r
- @return Standard EFI_STATUS\r
+ @retval EFI_SUCCESS The function completed successfully.\r
\r
**/\r
STATIC\r
This protocol service is called by the debug agent to register a function\r
for us to call on a periodic basis.\r
\r
- @param This pointer to the caller's debug support protocol\r
- interface\r
- @param PeriodicCallback pointer to the function to call periodically\r
-\r
- @return Always EFI_SUCCESS\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param ProcessorIndex Specifies which processor the callback function\r
+ applies to.\r
+ @param PeriodicCallback A pointer to a function of type\r
+ PERIODIC_CALLBACK that is the main periodic\r
+ entry point of the debug agent. It receives as a\r
+ parameter a pointer to the full context of the\r
+ interrupted execution thread.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a\r
+ callback function was previously registered.\r
+ @retval EFI_INVALID_PARAMETER Null PeriodicCallback parameter when no\r
+ callback function was previously registered.\r
\r
**/\r
STATIC\r
This protocol service is called by the debug agent to register a function\r
for us to call when we detect an exception.\r
\r
- @param This pointer to the caller's debug support protocol\r
- interface\r
- @param ExceptionCallback pointer to the function to the exception\r
-\r
- @return Always EFI_SUCCESS\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param ProcessorIndex Specifies which processor the callback function\r
+ applies to.\r
+ @param ExceptionCallback A pointer to a function of type\r
+ EXCEPTION_CALLBACK that is called when the\r
+ processor exception specified by ExceptionType\r
+ occurs. Passing NULL unregisters any previously\r
+ registered function associated with\r
+ ExceptionType.\r
+ @param ExceptionType Specifies which processor exception to hook.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_ALREADY_STARTED Non-NULL ExceptionCallback parameter when a\r
+ callback function was previously registered.\r
+ @retval EFI_INVALID_PARAMETER ExceptionType parameter is negative or exceeds\r
+ MAX_EBC_EXCEPTION.\r
+ @retval EFI_INVALID_PARAMETER Null ExceptionCallback parameter when no\r
+ callback function was previously registered.\r
\r
**/\r
STATIC\r
This EBC debugger protocol service is called by the debug agent. Required\r
for DebugSupport compliance but is only stubbed out for EBC.\r
\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
+ @param ProcessorIndex Specifies which processor the callback function\r
+ applies to.\r
+ @param Start StartSpecifies the physical base of the memory\r
+ range to be invalidated.\r
+ @param Length Specifies the minimum number of bytes in the\r
+ processor's instruction cache to invalidate. \r
\r
- @return EFI_SUCCESS\r
+ @retval EFI_SUCCESS The function completed successfully.\r
\r
**/\r
STATIC\r
/**\r
The VM interpreter calls this function when an exception is detected.\r
\r
- @param VmPtr pointer to a VM context for passing info to the\r
+ @param ExceptionType Specifies the processor exception detected.\r
+ @param ExceptionFlags Specifies the exception context. \r
+ @param VmPtr Pointer to a VM context for passing info to the\r
EFI debugger.\r
\r
- @return EFI_SUCCESS if it returns at all\r
+ @retval EFI_SUCCESS This function completed successfully.\r
\r
**/\r
EFI_STATUS\r
/**\r
To install default Callback function for the VM interpreter.\r
\r
- @param This pointer to the instance of DebugSupport protocol\r
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL\r
+ instance.\r
\r
- @return None\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval Others Some error occurs when creating periodic event.\r
\r
**/\r
STATIC\r
EFI_STATUS\r
+EFIAPI\r
InitializeEbcCallback (\r
IN EFI_DEBUG_SUPPORT_PROTOCOL *This\r
)\r
@param InterruptType Interrupt type.\r
@param SystemContext EBC system context.\r
\r
- @return None\r
-\r
**/\r
STATIC\r
VOID\r
+EFIAPI\r
CommonEbcExceptionHandler (\r
IN EFI_EXCEPTION_TYPE InterruptType,\r
IN EFI_SYSTEM_CONTEXT SystemContext\r
@param Event The Periodic Callback Event.\r
@param Context It should be the address of VM_CONTEXT pointer.\r
\r
- @return None.\r
-\r
**/\r
STATIC\r
VOID\r
The VM interpreter calls this function on a periodic basis to support\r
the EFI debug support protocol.\r
\r
- @param VmPtr pointer to a VM context for passing info to the\r
+ @param VmPtr Pointer to a VM context for passing info to the\r
debugger.\r
\r
- @return Standard EFI status.\r
+ @retval EFI_SUCCESS The function completed successfully.\r
\r
**/\r
STATIC\r
EFI_STATUS\r
+EFIAPI\r
EbcDebugPeriodic (\r
IN VM_CONTEXT *VmPtr\r
)\r
memory. Basically we now have the opportunity to do any necessary cleanup.\r
Typically this will include freeing any memory allocated for thunk-creation.\r
\r
- @param This protocol instance pointer\r
- @param ImageHandle handle to the image being unloaded.\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param ImageHandle Handle of image for which the thunk is being\r
+ created.\r
\r
- @retval EFI_INVALID_PARAMETER the ImageHandle passed in was not found in the\r
- internal list of EBC image handles.\r
- @retval EFI_STATUS completed successfully\r
+ @retval EFI_INVALID_PARAMETER The ImageHandle passed in was not found in the\r
+ internal list of EBC image handles.\r
+ @retval EFI_SUCCESS The function completed successfully.\r
\r
**/\r
STATIC\r
Also flush the instruction cache since we've written thunk code\r
to memory that will be executed eventually.\r
\r
- @param ImageHandle the image handle to which the thunk is tied\r
- @param ThunkBuffer the buffer we've created/allocated\r
- @param ThunkSize the size of the thunk memory allocated\r
+ @param ImageHandle The image handle to which the thunk is tied.\r
+ @param ThunkBuffer The buffer that has been created/allocated.\r
+ @param ThunkSize The size of the thunk memory allocated.\r
\r
- @retval EFI_OUT_OF_RESOURCES memory allocation failed\r
- @retval EFI_SUCCESS successful completion\r
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+ @retval EFI_SUCCESS The function completed successfully.\r
\r
**/\r
EFI_STATUS\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Registers a callback function that the EBC interpreter calls to flush the\r
+ processor instruction cache following creation of thunks. \r
+\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param Flush Pointer to a function of type EBC_ICACH_FLUSH.\r
+ \r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Called to get the version of the interpreter.\r
+\r
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.\r
+ @param Version Pointer to where to store the returned version\r
+ of the interpreter.\r
+ \r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_INVALID_PARAMETER Version pointer is NULL.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Returns the stack index and buffer assosicated with the Handle parameter.\r
+\r
+ @param Handle The EFI handle as the index to the EBC stack. \r
+ @param StackBuffer A pointer to hold the returned stack buffer.\r
+ @param BufferIndex A pointer to hold the returned stack index.\r
+ \r
+ @retval EFI_OUT_OF_RESOURCES The Handle parameter does not correspond to any\r
+ existing EBC stack.\r
+ @retval EFI_SUCCESS The stack index and buffer were found and\r
+ returned to the caller.\r
+\r
+**/\r
EFI_STATUS\r
GetEBCStack(\r
- EFI_HANDLE Handle,\r
- VOID **StackBuffer,\r
- UINTN *BufferIndex\r
+ IN EFI_HANDLE Handle,\r
+ OUT VOID **StackBuffer,\r
+ OUT UINTN *BufferIndex\r
)\r
{\r
UINTN Index;\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Returns from the EBC stack by stack Index. \r
+ \r
+ @param Index Specifies which EBC stack to return from.\r
+ \r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
EFI_STATUS\r
ReturnEBCStack(\r
- UINTN Index\r
+ IN UINTN Index\r
)\r
{\r
- mStackBufferIndex[Index] =NULL;\r
+ mStackBufferIndex[Index] = NULL;\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Returns from the EBC stack associated with the Handle parameter. \r
+ \r
+ @param Handle Specifies the EFI handle to find the EBC stack with.\r
+ \r
+ @retval EFI_SUCCESS The function completed successfully.\r
+\r
+**/\r
EFI_STATUS\r
ReturnEBCStackByHandle(\r
- EFI_HANDLE Handle\r
+ IN EFI_HANDLE Handle\r
)\r
{\r
UINTN Index;\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Allocates memory to hold all the EBC stacks.\r
+\r
+ @retval EFI_SUCCESS The EBC stacks were allocated successfully. \r
+ @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.\r
+\r
+**/\r
EFI_STATUS\r
InitEBCStack (\r
VOID\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ Free all EBC stacks allocated before.\r
+\r
+ @retval EFI_SUCCESS All the EBC stacks were freed.\r
+\r
+**/\r
EFI_STATUS\r
FreeEBCStack(\r
VOID\r
}\r
\r
/**\r
- Produce an EBC VM test protocol that can be used for regression tests.\r
+ Produces an EBC VM test protocol that can be used for regression tests.\r
\r
- @param IHandle handle on which to install the protocol.\r
+ @param IHandle Handle on which to install the protocol.\r
\r
- @retval EFI_OUT_OF_RESOURCES memory allocation failed\r
- @retval EFI_SUCCESS successful completion\r
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+ @retval EFI_SUCCESS The function completed successfully.\r
\r
**/\r
STATIC\r
}\r
return Status;\r
}\r
+\r
+\r
+/**\r
+ Returns the EFI_UNSUPPORTED Status.\r
+ \r
+ @return EFI_UNSUPPORTED This function always return EFI_UNSUPPORTED status.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
-EbcVmTestUnsupported ()\r
+EbcVmTestUnsupported (\r
+ VOID\r
+ )\r
{\r
return EFI_UNSUPPORTED;\r
}\r