diff options
Diffstat (limited to 'MdeModulePkg')
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/EbcExecute.c | 1689 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/EbcExecute.h | 75 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/EbcInt.c | 425 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/EbcInt.h | 171 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c | 65 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c | 163 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.h | 6 | ||||
-rw-r--r-- | MdeModulePkg/Universal/EbcDxe/x64/EbcSupport.c | 104 |
8 files changed, 2216 insertions, 482 deletions
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c index d44892e..c3c7b91 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c @@ -1,7 +1,7 @@ /** @file
Contains code that implements the virtual machine.
-Copyright (c) 2006, Intel Corporation
+Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -42,6 +42,28 @@ UINT64 IN UINT64 Op2
);
+/**
+ Decode a 16-bit index to determine the offset. Given an index value:
+
+ b15 - sign bit
+ b14:12 - number of bits in this index assigned to natural units (=a)
+ ba:11 - constant units = ConstUnits
+ b0:a - natural units = NaturalUnits
+
+ Given this info, the offset can be computed by:
+ offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN))
+
+ Max offset is achieved with index = 0x7FFF giving an offset of
+ 0x27B (32-bit machine) or 0x477 (64-bit machine).
+ Min offset is achieved with index =
+
+ @param VmPtr A pointer to VM context.
+ @param CodeOffset Offset from IP of the location of the 16-bit index
+ to decode.
+
+ @return The decoded offset.
+
+**/
STATIC
INT16
VmReadIndex16 (
@@ -49,6 +71,16 @@ VmReadIndex16 ( IN UINT32 CodeOffset
);
+/**
+ Decode a 32-bit index to determine the offset.
+
+ @param VmPtr A pointer to VM context.
+ @param CodeOffset Offset from IP of the location of the 32-bit index
+ to decode.
+
+ @return Converted index per EBC VM specification.
+
+**/
STATIC
INT32
VmReadIndex32 (
@@ -56,6 +88,16 @@ VmReadIndex32 ( IN UINT32 CodeOffset
);
+/**
+ Decode a 64-bit index to determine the offset.
+
+ @param VmPtr A pointer to VM context.s
+ @param CodeOffset Offset from IP of the location of the 64-bit index
+ to decode.
+
+ @return Converted index per EBC VM specification
+
+**/
STATIC
INT64
VmReadIndex64 (
@@ -63,6 +105,15 @@ VmReadIndex64 ( IN UINT32 CodeOffset
);
+/**
+ Reads 8-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 8-bit value from the memory adress.
+
+**/
STATIC
UINT8
VmReadMem8 (
@@ -70,6 +121,15 @@ VmReadMem8 ( IN UINTN Addr
);
+/**
+ Reads 16-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 16-bit value from the memory adress.
+
+**/
STATIC
UINT16
VmReadMem16 (
@@ -77,6 +137,15 @@ VmReadMem16 ( IN UINTN Addr
);
+/**
+ Reads 32-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 32-bit value from the memory adress.
+
+**/
STATIC
UINT32
VmReadMem32 (
@@ -84,6 +153,15 @@ VmReadMem32 ( IN UINTN Addr
);
+/**
+ Reads 64-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 64-bit value from the memory adress.
+
+**/
STATIC
UINT64
VmReadMem64 (
@@ -91,6 +169,15 @@ VmReadMem64 ( IN UINTN Addr
);
+/**
+ Read a natural value from memory. May or may not be aligned.
+
+ @param VmPtr current VM context
+ @param Addr the address to read from
+
+ @return The natural value at address Addr.
+
+**/
STATIC
UINTN
VmReadMemN (
@@ -98,30 +185,111 @@ VmReadMemN ( IN UINTN Addr
);
+/**
+ Writes 8-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
STATIC
EFI_STATUS
VmWriteMem8 (
IN VM_CONTEXT *VmPtr,
- UINTN Addr,
+ IN UINTN Addr,
IN UINT8 Data
);
+/**
+ Writes 16-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
STATIC
EFI_STATUS
VmWriteMem16 (
IN VM_CONTEXT *VmPtr,
- UINTN Addr,
+ IN UINTN Addr,
IN UINT16 Data
);
+/**
+ Writes 32-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
STATIC
EFI_STATUS
VmWriteMem32 (
IN VM_CONTEXT *VmPtr,
- UINTN Addr,
+ IN UINTN Addr,
IN UINT32 Data
);
+/**
+ Reads 16-bit unsinged data from the code stream.
+
+ This routine provides the ability to read raw unsigned data from the code
+ stream.
+
+ @param VmPtr A pointer to VM context
+ @param Offset Offset from current IP to the raw data to read.
+
+ @return The raw unsigned 16-bit value from the code stream.
+
+**/
STATIC
UINT16
VmReadCode16 (
@@ -129,6 +297,18 @@ VmReadCode16 ( IN UINT32 Offset
);
+/**
+ Reads 32-bit unsinged data from the code stream.
+
+ This routine provides the ability to read raw unsigned data from the code
+ stream.
+
+ @param VmPtr A pointer to VM context
+ @param Offset Offset from current IP to the raw data to read.
+
+ @return The raw unsigned 32-bit value from the code stream.
+
+**/
STATIC
UINT32
VmReadCode32 (
@@ -136,6 +316,18 @@ VmReadCode32 ( IN UINT32 Offset
);
+/**
+ Reads 64-bit unsinged data from the code stream.
+
+ This routine provides the ability to read raw unsigned data from the code
+ stream.
+
+ @param VmPtr A pointer to VM context
+ @param Offset Offset from current IP to the raw data to read.
+
+ @return The raw unsigned 64-bit value from the code stream.
+
+**/
STATIC
UINT64
VmReadCode64 (
@@ -143,6 +335,20 @@ VmReadCode64 ( IN UINT32 Offset
);
+/**
+ Reads 8-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT8
VmReadImmed8 (
@@ -150,6 +356,20 @@ VmReadImmed8 ( IN UINT32 Offset
);
+/**
+ Reads 16-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT16
VmReadImmed16 (
@@ -157,6 +377,20 @@ VmReadImmed16 ( IN UINT32 Offset
);
+/**
+ Reads 32-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT32
VmReadImmed32 (
@@ -164,6 +398,20 @@ VmReadImmed32 ( IN UINT32 Offset
);
+/**
+ Reads 64-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT64
VmReadImmed64 (
@@ -171,6 +419,25 @@ VmReadImmed64 ( IN UINT32 Offset
);
+/**
+ Given an address that EBC is going to read from or write to, return
+ an appropriate address that accounts for a gap in the stack.
+ The stack for this application looks like this (high addr on top)
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+ The EBC assumes that its arguments are at the top of its stack, which
+ is where the VM stack is really. Therefore if the EBC does memory
+ accesses into the VM stack area, then we need to convert the address
+ to point to the EBC entry point arguments area. Do this here.
+
+ @param VmPtr A Pointer to VM context.
+ @param Addr Address of interest
+
+ @return The unchanged address if it's not in the VM stack region. Otherwise,
+ adjust for the stack gap and return the modified address.
+
+**/
STATIC
UINTN
ConvertStackAddr (
@@ -178,136 +445,459 @@ ConvertStackAddr ( IN UINTN Addr
);
+/**
+ Execute all the EBC data manipulation instructions.
+ Since the EBC data manipulation instructions all have the same basic form,
+ they can share the code that does the fetch of operands and the write-back
+ of the result. This function performs the fetch of the operands (even if
+ both are not needed to be fetched, like NOT instruction), dispatches to the
+ appropriate subfunction, then writes back the returned result.
+
+ Format:
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+
+ @param VmPtr A pointer to VM context.
+ @param IsSignedOp Indicates whether the operand is signed or not.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteDataManip (
IN VM_CONTEXT *VmPtr,
- IN BOOLEAN IsSignedOperation
+ IN BOOLEAN IsSignedOp
);
//
// Functions that execute VM opcodes
//
+/**
+ Execute the EBC BREAK instruction.
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteBREAK (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the JMP instruction.
+
+ Instruction syntax:
+ JMP64{cs|cc} Immed64
+ JMP32{cs|cc} {@}R1 {Immed32|Index32}
+
+ Encoding:
+ b0.7 - immediate data present
+ b0.6 - 1 = 64 bit immediate data
+ 0 = 32 bit immediate data
+ b1.7 - 1 = conditional
+ b1.6 1 = CS (condition set)
+ 0 = CC (condition clear)
+ b1.4 1 = relative address
+ 0 = absolute address
+ b1.3 1 = operand1 indirect
+ b1.2-0 operand 1
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteJMP (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC JMP8 instruction.
+
+ Instruction syntax:
+ JMP8{cs|cc} Offset/2
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteJMP8 (
IN VM_CONTEXT *VmPtr
);
+/**
+ Implements the EBC CALL instruction.
+
+ Instruction format:
+ CALL64 Immed64
+ CALL32 {@}R1 {Immed32|Index32}
+ CALLEX64 Immed64
+ CALLEX16 {@}R1 {Immed32}
+
+ If Rx == R0, then it's a PC relative call to PC = PC + imm32.
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteCALL (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC RET instruction.
+
+ Instruction syntax:
+ RET
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteRET (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC CMP instruction.
+
+ Instruction syntax:
+ CMP[32|64][eq|lte|gte|ulte|ugte] R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteCMP (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC CMPI instruction
+
+ Instruction syntax:
+ CMPI[32|64]{w|d}[eq|lte|gte|ulte|ugte] {@}Rx {Index16}, Immed16|Immed32
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteCMPI (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the MOVxx instructions.
+
+ Instruction format:
+
+ MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}
+ MOVqq {@}R1 {Index64}, {@}R2 {Index64}
+
+ Copies contents of [R2] -> [R1], zero extending where required.
+
+ First character indicates the size of the move.
+ Second character indicates the size of the index(s).
+
+ Invalid to have R1 direct with index.
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteMOVxx (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC MOVI.
+
+ Instruction syntax:
+
+ MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64
+
+ First variable character specifies the move size
+ Second variable character specifies size of the immediate data
+
+ Sign-extend the immediate data to the size of the operation, and zero-extend
+ if storing to a register.
+
+ Operand1 direct with index/immed is invalid.
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteMOVI (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC MOV immediate natural. This instruction moves an immediate
+ index value into a register or memory location.
+
+ Instruction syntax:
+
+ MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteMOVIn (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC MOVREL instruction.
+ Dest <- Ip + ImmData
+
+ Instruction syntax:
+
+ MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteMOVREL (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC PUSHn instruction
+
+ Instruction syntax:
+ PUSHn {@}R1 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecutePUSHn (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC PUSH instruction.
+
+ Instruction syntax:
+ PUSH[32|64] {@}R1 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecutePUSH (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC POPn instruction.
+
+ Instruction syntax:
+ POPn {@}R1 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecutePOPn (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC POP instruction.
+
+ Instruction syntax:
+ POPn {@}R1 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecutePOP (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute all the EBC signed data manipulation instructions.
+ Since the EBC data manipulation instructions all have the same basic form,
+ they can share the code that does the fetch of operands and the write-back
+ of the result. This function performs the fetch of the operands (even if
+ both are not needed to be fetched, like NOT instruction), dispatches to the
+ appropriate subfunction, then writes back the returned result.
+
+ Format:
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+
+ @param VmPtr A pointer to VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteSignedDataManip (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute all the EBC unsigned data manipulation instructions.
+ Since the EBC data manipulation instructions all have the same basic form,
+ they can share the code that does the fetch of operands and the write-back
+ of the result. This function performs the fetch of the operands (even if
+ both are not needed to be fetched, like NOT instruction), dispatches to the
+ appropriate subfunction, then writes back the returned result.
+
+ Format:
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+
+ @param VmPtr A pointer to VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteUnsignedDataManip (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC LOADSP instruction.
+
+ Instruction syntax:
+ LOADSP SP1, R2
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteLOADSP (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC STORESP instruction.
+
+ Instruction syntax:
+ STORESP Rx, FLAGS|IP
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteSTORESP (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC MOVsnw instruction. This instruction loads a signed
+ natural value from memory or register to another memory or register. On
+ 32-bit machines, the value gets sign-extended to 64 bits if the destination
+ is a register.
+
+ Instruction syntax:
+
+ MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}
+
+ 0:7 1=>operand1 index present
+ 0:6 1=>operand2 index present
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteMOVsnd (
IN VM_CONTEXT *VmPtr
);
+/**
+ Execute the EBC MOVsnw instruction. This instruction loads a signed
+ natural value from memory or register to another memory or register. On
+ 32-bit machines, the value gets sign-extended to 64 bits if the destination
+ is a register.
+
+ Instruction syntax:
+
+ MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}
+
+ 0:7 1=>operand1 index present
+ 0:6 1=>operand2 index present
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteMOVsnw (
@@ -317,6 +907,19 @@ ExecuteMOVsnw ( //
// Data manipulation subfunctions
//
+/**
+ Execute the EBC NOT instruction.s
+
+ Instruction syntax:
+ NOT[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return ~Op2
+
+**/
STATIC
UINT64
ExecuteNOT (
@@ -325,6 +928,19 @@ ExecuteNOT ( IN UINT64 Op2
);
+/**
+ Execute the EBC NEG instruction.
+
+ Instruction syntax:
+ NEG[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op2 * -1
+
+**/
STATIC
UINT64
ExecuteNEG (
@@ -333,6 +949,19 @@ ExecuteNEG ( IN UINT64 Op2
);
+/**
+ Execute the EBC ADD instruction.
+
+ Instruction syntax:
+ ADD[32|64] {@}R1, {@}R2 {Index16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 + Op2
+
+**/
STATIC
UINT64
ExecuteADD (
@@ -341,6 +970,19 @@ ExecuteADD ( IN UINT64 Op2
);
+/**
+ Execute the EBC SUB instruction.
+
+ Instruction syntax:
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 - Op2
+
+**/
STATIC
UINT64
ExecuteSUB (
@@ -349,6 +991,19 @@ ExecuteSUB ( IN UINT64 Op2
);
+/**
+ Execute the EBC MUL instruction.
+
+ Instruction syntax:
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 * Op2
+
+**/
STATIC
UINT64
ExecuteMUL (
@@ -357,6 +1012,19 @@ ExecuteMUL ( IN UINT64 Op2
);
+/**
+ Execute the EBC MULU instruction
+
+ Instruction syntax:
+ MULU[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return (unsigned)Op1 * (unsigned)Op2
+
+**/
STATIC
UINT64
ExecuteMULU (
@@ -365,6 +1033,19 @@ ExecuteMULU ( IN UINT64 Op2
);
+/**
+ Execute the EBC DIV instruction.
+
+ Instruction syntax:
+ DIV[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 / Op2
+
+**/
STATIC
UINT64
ExecuteDIV (
@@ -373,6 +1054,19 @@ ExecuteDIV ( IN UINT64 Op2
);
+/**
+ Execute the EBC DIVU instruction
+
+ Instruction syntax:
+ DIVU[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return (unsigned)Op1 / (unsigned)Op2
+
+**/
STATIC
UINT64
ExecuteDIVU (
@@ -381,6 +1075,19 @@ ExecuteDIVU ( IN UINT64 Op2
);
+/**
+ Execute the EBC MOD instruction.
+
+ Instruction syntax:
+ MOD[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 MODULUS Op2
+
+**/
STATIC
UINT64
ExecuteMOD (
@@ -389,6 +1096,19 @@ ExecuteMOD ( IN UINT64 Op2
);
+/**
+ Execute the EBC MODU instruction.
+
+ Instruction syntax:
+ MODU[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 UNSIGNED_MODULUS Op2
+
+**/
STATIC
UINT64
ExecuteMODU (
@@ -397,6 +1117,19 @@ ExecuteMODU ( IN UINT64 Op2
);
+/**
+ Execute the EBC AND instruction.
+
+ Instruction syntax:
+ AND[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 AND Op2
+
+**/
STATIC
UINT64
ExecuteAND (
@@ -405,6 +1138,19 @@ ExecuteAND ( IN UINT64 Op2
);
+/**
+ Execute the EBC OR instruction.
+
+ Instruction syntax:
+ OR[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 OR Op2
+
+**/
STATIC
UINT64
ExecuteOR (
@@ -413,6 +1159,19 @@ ExecuteOR ( IN UINT64 Op2
);
+/**
+ Execute the EBC XOR instruction.
+
+ Instruction syntax:
+ XOR[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 XOR Op2
+
+**/
STATIC
UINT64
ExecuteXOR (
@@ -421,6 +1180,19 @@ ExecuteXOR ( IN UINT64 Op2
);
+/**
+ Execute the EBC SHL shift left instruction.
+
+ Instruction syntax:
+ SHL[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 << Op2
+
+**/
STATIC
UINT64
ExecuteSHL (
@@ -429,6 +1201,19 @@ ExecuteSHL ( IN UINT64 Op2
);
+/**
+ Execute the EBC SHR instruction.
+
+ Instruction syntax:
+ SHR[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 >> Op2 (unsigned operands)
+
+**/
STATIC
UINT64
ExecuteSHR (
@@ -437,6 +1222,19 @@ ExecuteSHR ( IN UINT64 Op2
);
+/**
+ Execute the EBC ASHR instruction.
+
+ Instruction syntax:
+ ASHR[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return Op1 >> Op2 (signed)
+
+**/
STATIC
UINT64
ExecuteASHR (
@@ -445,6 +1243,19 @@ ExecuteASHR ( IN UINT64 Op2
);
+/**
+ Execute the EBC EXTNDB instruction to sign-extend a byte value.
+
+ Instruction syntax:
+ EXTNDB[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return (INT64)(INT8)Op2
+
+**/
STATIC
UINT64
ExecuteEXTNDB (
@@ -453,6 +1264,19 @@ ExecuteEXTNDB ( IN UINT64 Op2
);
+/**
+ Execute the EBC EXTNDW instruction to sign-extend a 16-bit value.
+
+ Instruction syntax:
+ EXTNDW[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return (INT64)(INT16)Op2
+
+**/
STATIC
UINT64
ExecuteEXTNDW (
@@ -461,6 +1285,19 @@ ExecuteEXTNDW ( IN UINT64 Op2
);
+/**
+ Execute the EBC EXTNDD instruction to sign-extend a 32-bit value.
+
+ Instruction syntax:
+ EXTNDD[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
+ @param Op1 Operand 1 from the instruction
+ @param Op2 Operand 2 from the instruction
+
+ @return (INT64)(INT32)Op2
+
+**/
STATIC
UINT64
ExecuteEXTNDD (
@@ -473,7 +1310,7 @@ ExecuteEXTNDD ( // Once we retrieve the operands for the data manipulation instructions,
// call these functions to perform the operation.
//
-static CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {
+STATIC CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {
ExecuteNOT,
ExecuteNEG,
ExecuteADD,
@@ -495,7 +1332,7 @@ static CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = { ExecuteEXTNDD,
};
-static CONST VM_TABLE_ENTRY mVmOpcodeTable[] = {
+STATIC CONST VM_TABLE_ENTRY mVmOpcodeTable[] = {
{ ExecuteBREAK }, // opcode 0x00
{ ExecuteJMP }, // opcode 0x01
{ ExecuteJMP8 }, // opcode 0x02
@@ -559,7 +1396,7 @@ static CONST VM_TABLE_ENTRY mVmOpcodeTable[] = { //
// Length of JMP instructions, depending on upper two bits of opcode.
//
-static CONST UINT8 mJMPLen[] = { 2, 2, 6, 10 };
+STATIC CONST UINT8 mJMPLen[] = { 2, 2, 6, 10 };
//
// Simple Debugger Protocol GUID
@@ -571,12 +1408,14 @@ EFI_GUID mEbcSimpleDebuggerProtocolGuid = EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID; Given a pointer to a new VM context, execute one or more instructions. This
function is only used for test purposes via the EBC VM test protocol.
- @param This pointer to protocol interface
- @param VmPtr pointer to a VM context
- @param InstructionCount how many instructions to execute. 0 if don't count.
+ @param This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
+ @param VmPtr A pointer to a VM context.
+ @param InstructionCount A pointer to a UINTN value holding the number of
+ instructions to execute. If it holds value of 0,
+ then the instruction to be executed is 1.
- @return EFI_UNSUPPORTED
- @return EFI_SUCCESS
+ @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.
+ @retval EFI_SUCCESS All of the instructions are executed successfully.
**/
EFI_STATUS
@@ -632,9 +1471,10 @@ EbcExecuteInstructions ( /**
Execute an EBC image from an entry point or from a published protocol.
- @param VmPtr pointer to prepared VM context.
+ @param VmPtr A pointer to a VM context.
- @return Standard EBC status.
+ @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.
+ @retval EFI_SUCCESS All of the instructions are executed successfully.
**/
EFI_STATUS
@@ -755,17 +1595,22 @@ Done: /**
Execute the MOVxx instructions.
- @param VmPtr pointer to a VM context.
-
- @return EFI_UNSUPPORTED
- @return EFI_SUCCESS
- @return Instruction format:
- @return MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}
- @return MOVqq {@}R1 {Index64}, {@}R2 {Index64}
- @return Copies contents of [R2] -> [R1], zero extending where required.
- @return First character indicates the size of the move.
- @return Second character indicates the size of the index(s).
- @return Invalid to have R1 direct with index.
+ Instruction format:
+
+ MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}
+ MOVqq {@}R1 {Index64}, {@}R2 {Index64}
+
+ Copies contents of [R2] -> [R1], zero extending where required.
+
+ First character indicates the size of the move.
+ Second character indicates the size of the index(s).
+
+ Invalid to have R1 direct with index.
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1031,12 +1876,11 @@ ExecuteMOVxx ( /**
- Execute the EBC BREAK instruction
+ Execute the EBC BREAK instruction.
- @param VmPtr pointer to current VM context
+ @param VmPtr A pointer to a VM context.
- @return EFI_UNSUPPORTED
- @return EFI_SUCCESS
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1141,21 +1985,28 @@ ExecuteBREAK ( /**
- Execute the JMP instruction
-
- @param VmPtr pointer to VM context
-
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return JMP64{cs|cc} Immed64
- @return JMP32{cs|cc} {@}R1 {Immed32|Index32}
- @return Encoding:
- @retval b0.7 immediate data present
- @retval b0.6 1 = 64 bit immediate data 0 = 32 bit immediate data
- @retval b1.7 1 = conditional b1.6 1 = CS (condition set) 0 = CC
- (condition clear) b1.4 1 = relative address 0 =
- absolute address b1.3 1 = operand1 indirect b1.2-0
- operand 1
+ Execute the JMP instruction.
+
+ Instruction syntax:
+ JMP64{cs|cc} Immed64
+ JMP32{cs|cc} {@}R1 {Immed32|Index32}
+
+ Encoding:
+ b0.7 - immediate data present
+ b0.6 - 1 = 64 bit immediate data
+ 0 = 32 bit immediate data
+ b1.7 - 1 = conditional
+ b1.6 1 = CS (condition set)
+ 0 = CC (condition clear)
+ b1.4 1 = relative address
+ 0 = absolute address
+ b1.3 1 = operand1 indirect
+ b1.2-0 operand 1
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1311,13 +2162,14 @@ ExecuteJMP ( /**
- Execute the EBC JMP8 instruction
+ Execute the EBC JMP8 instruction.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ JMP8{cs|cc} Offset/2
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return JMP8{cs|cc} Offset/2
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1361,18 +2213,24 @@ ExecuteJMP8 ( /**
- Execute the EBC MOVI
+ Execute the EBC MOVI.
+
+ Instruction syntax:
+
+ MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64
+
+ First variable character specifies the move size
+ Second variable character specifies size of the immediate data
+
+ Sign-extend the immediate data to the size of the operation, and zero-extend
+ if storing to a register.
+
+ Operand1 direct with index/immed is invalid.
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64
- @return First variable character specifies the move size
- @return Second variable character specifies size of the immediate data
- @return Sign-extend the immediate data to the size of the operation, and zero-extend
- @return if storing to a register.
- @return Operand1 direct with index/immed is invalid.
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1484,11 +2342,14 @@ ExecuteMOVI ( Execute the EBC MOV immediate natural. This instruction moves an immediate
index value into a register or memory location.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+
+ MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64
+
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1584,11 +2445,14 @@ ExecuteMOVIn ( Execute the EBC MOVREL instruction.
Dest <- Ip + ImmData
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+
+ MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1685,13 +2549,17 @@ ExecuteMOVREL ( 32-bit machines, the value gets sign-extended to 64 bits if the destination
is a register.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+
+ MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}
+
+ 0:7 1=>operand1 index present
+ 0:6 1=>operand2 index present
+
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}
- @return 0:7 1=>operand1 index present
- @return 0:6 1=>operand2 index present
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1775,13 +2643,17 @@ ExecuteMOVsnw ( 32-bit machines, the value gets sign-extended to 64 bits if the destination
is a register.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+
+ MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}
+
+ 0:7 1=>operand1 index present
+ 0:6 1=>operand2 index present
+
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}
- @return 0:7 1=>operand1 index present
- @return 0:6 1=>operand2 index present
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1862,11 +2734,12 @@ ExecuteMOVsnd ( /**
Execute the EBC PUSHn instruction
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ PUSHn {@}R1 {Index16|Immed16}
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return PUSHn {@}R1 {Index16|Immed16}
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1919,13 +2792,14 @@ ExecutePUSHn ( /**
- Execute the EBC PUSH instruction
+ Execute the EBC PUSH instruction.
+
+ Instruction syntax:
+ PUSH[32|64] {@}R1 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return PUSH[32|64] {@}R1 {Index16|Immed16}
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -1995,13 +2869,14 @@ ExecutePUSH ( /**
- Execute the EBC POPn instruction
+ Execute the EBC POPn instruction.
+
+ Instruction syntax:
+ POPn {@}R1 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return POPn {@}R1 {Index16|Immed16}
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -2054,13 +2929,14 @@ ExecutePOPn ( /**
- Execute the EBC POP instruction
+ Execute the EBC POP instruction.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ POPn {@}R1 {Index16|Immed16}
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return POP {@}R1 {Index16|Immed16}
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -2134,16 +3010,18 @@ ExecutePOP ( /**
Implements the EBC CALL instruction.
+
Instruction format:
- CALL64 Immed64
- CALL32 {@}R1 {Immed32|Index32}
- CALLEX64 Immed64
- CALLEX16 {@}R1 {Immed32}
- If Rx == R0, then it's a PC relative call to PC = PC + imm32.
+ CALL64 Immed64
+ CALL32 {@}R1 {Immed32|Index32}
+ CALLEX64 Immed64
+ CALLEX16 {@}R1 {Immed32}
- @param VmPtr pointer to a VM context.
+ If Rx == R0, then it's a PC relative call to PC = PC + imm32.
- @return Standard EFI_STATUS
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -2270,13 +3148,14 @@ ExecuteCALL ( /**
- Execute the EBC RET instruction
+ Execute the EBC RET instruction.
+
+ Instruction syntax:
+ RET
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return RET
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -2317,13 +3196,15 @@ ExecuteRET ( /**
- Execute the EBC CMP instruction
+ Execute the EBC CMP instruction.
+
+ Instruction syntax:
+ CMP[32|64][eq|lte|gte|ulte|ugte] R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return CMP[32|64][eq|lte|gte|ulte|ugte] R1, {@}R2 {Index16|Immed16}
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -2479,11 +3360,13 @@ ExecuteCMP ( /**
Execute the EBC CMPI instruction
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ CMPI[32|64]{w|d}[eq|lte|gte|ulte|ugte] {@}Rx {Index16}, Immed16|Immed32
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return CMPI[32|64]{w|d}[eq|lte|gte|ulte|ugte] {@}Rx {Index16}, Immed16|Immed32
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -2655,15 +3538,16 @@ ExecuteCMPI ( /**
- Execute the EBC NOT instruction
+ Execute the EBC NOT instruction.s
+
+ Instruction syntax:
+ NOT[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return ~Op2
- @return Instruction syntax:
- @return NOT[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2679,15 +3563,16 @@ ExecuteNOT ( /**
- Execute the EBC NEG instruction
+ Execute the EBC NEG instruction.
+
+ Instruction syntax:
+ NEG[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op2 * -1
- @return Instruction syntax:
- @return NEG[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2703,15 +3588,16 @@ ExecuteNEG ( /**
- Execute the EBC ADD instruction
+ Execute the EBC ADD instruction.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ ADD[32|64] {@}R1, {@}R2 {Index16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 + Op2
- @return Instruction syntax:
- @return ADD[32|64] {@}R1, {@}R2 {Index16}
**/
STATIC
@@ -2727,15 +3613,16 @@ ExecuteADD ( /**
- Execute the EBC SUB instruction
+ Execute the EBC SUB instruction.
+
+ Instruction syntax:
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
- @retval Op1 Op2 Standard EFI_STATUS
- @return Instruction syntax:
- @return SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}
+ @return Op1 - Op2
**/
STATIC
@@ -2755,15 +3642,16 @@ ExecuteSUB ( /**
- Execute the EBC MUL instruction
+ Execute the EBC MUL instruction.
+
+ Instruction syntax:
+ SUB[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 * Op2
- @return Instruction syntax:
- @return MUL[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2785,13 +3673,14 @@ ExecuteMUL ( /**
Execute the EBC MULU instruction
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ MULU[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return (unsigned)Op1 * (unsigned)Op2
- @return Instruction syntax:
- @return MULU[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2811,15 +3700,16 @@ ExecuteMULU ( /**
- Execute the EBC DIV instruction
+ Execute the EBC DIV instruction.
+
+ Instruction syntax:
+ DIV[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
- @return Op1/Op2
- @return Instruction syntax:
- @return DIV[32|64] {@}R1, {@}R2 {Index16|Immed16}
+ @return Op1 / Op2
**/
STATIC
@@ -2856,13 +3746,14 @@ ExecuteDIV ( /**
Execute the EBC DIVU instruction
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ DIVU[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return (unsigned)Op1 / (unsigned)Op2
- @return Instruction syntax:
- @return DIVU[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2899,15 +3790,16 @@ ExecuteDIVU ( /**
- Execute the EBC MOD instruction
+ Execute the EBC MOD instruction.
+
+ Instruction syntax:
+ MOD[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 MODULUS Op2
- @return Instruction syntax:
- @return MOD[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2938,15 +3830,16 @@ ExecuteMOD ( /**
- Execute the EBC MODU instruction
+ Execute the EBC MODU instruction.
+
+ Instruction syntax:
+ MODU[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 UNSIGNED_MODULUS Op2
- @return Instruction syntax:
- @return MODU[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -2977,15 +3870,16 @@ ExecuteMODU ( /**
- Execute the EBC AND instruction
+ Execute the EBC AND instruction.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ AND[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 AND Op2
- @return Instruction syntax:
- @return AND[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3001,15 +3895,16 @@ ExecuteAND ( /**
- Execute the EBC OR instruction
+ Execute the EBC OR instruction.
+
+ Instruction syntax:
+ OR[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 OR Op2
- @return Instruction syntax:
- @return OR[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3025,15 +3920,16 @@ ExecuteOR ( /**
- Execute the EBC XOR instruction
+ Execute the EBC XOR instruction.
+
+ Instruction syntax:
+ XOR[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 XOR Op2
- @return Instruction syntax:
- @return XOR[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3049,15 +3945,16 @@ ExecuteXOR ( /**
- Execute the EBC SHL shift left instruction
+ Execute the EBC SHL shift left instruction.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ SHL[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 << Op2
- @return Instruction syntax:
- @return SHL[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3077,15 +3974,16 @@ ExecuteSHL ( /**
- Execute the EBC SHR instruction
+ Execute the EBC SHR instruction.
+
+ Instruction syntax:
+ SHR[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 >> Op2 (unsigned operands)
- @return Instruction syntax:
- @return SHR[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3105,15 +4003,16 @@ ExecuteSHR ( /**
- Execute the EBC ASHR instruction
+ Execute the EBC ASHR instruction.
+
+ Instruction syntax:
+ ASHR[32|64] {@}R1, {@}R2 {Index16|Immed16}
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return Op1 >> Op2 (signed)
- @return Instruction syntax:
- @return ASHR[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3135,13 +4034,14 @@ ExecuteASHR ( /**
Execute the EBC EXTNDB instruction to sign-extend a byte value.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ EXTNDB[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return (INT64)(INT8)Op2
- @return Instruction syntax:
- @return EXTNDB[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3168,13 +4068,14 @@ ExecuteEXTNDB ( /**
Execute the EBC EXTNDW instruction to sign-extend a 16-bit value.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ EXTNDW[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return (INT64)(INT16)Op2
- @return Instruction syntax:
- @return EXTNDW[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3208,13 +4109,14 @@ ExecuteEXTNDW ( /**
Execute the EBC EXTNDD instruction to sign-extend a 32-bit value.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ EXTNDD[32|64] {@}R1, {@}R2 {Index16|Immed16}
+
+ @param VmPtr A pointer to a VM context.
@param Op1 Operand 1 from the instruction
@param Op2 Operand 2 from the instruction
@return (INT64)(INT32)Op2
- @return Instruction syntax:
- @return EXTNDD[32|64] {@}R1, {@}R2 {Index16|Immed16}
**/
STATIC
@@ -3237,6 +4139,24 @@ ExecuteEXTNDD ( return (UINT64) Data64;
}
+
+/**
+ Execute all the EBC signed data manipulation instructions.
+ Since the EBC data manipulation instructions all have the same basic form,
+ they can share the code that does the fetch of operands and the write-back
+ of the result. This function performs the fetch of the operands (even if
+ both are not needed to be fetched, like NOT instruction), dispatches to the
+ appropriate subfunction, then writes back the returned result.
+
+ Format:
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+
+ @param VmPtr A pointer to VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteSignedDataManip (
@@ -3250,6 +4170,24 @@ ExecuteSignedDataManip ( return ExecuteDataManip (VmPtr, TRUE);
}
+
+/**
+ Execute all the EBC unsigned data manipulation instructions.
+ Since the EBC data manipulation instructions all have the same basic form,
+ they can share the code that does the fetch of operands and the write-back
+ of the result. This function performs the fetch of the operands (even if
+ both are not needed to be fetched, like NOT instruction), dispatches to the
+ appropriate subfunction, then writes back the returned result.
+
+ Format:
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+
+ @param VmPtr A pointer to VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
+
+**/
STATIC
EFI_STATUS
ExecuteUnsignedDataManip (
@@ -3272,11 +4210,14 @@ ExecuteUnsignedDataManip ( both are not needed to be fetched, like NOT instruction), dispatches to the
appropriate subfunction, then writes back the returned result.
- @param VmPtr pointer to VM context
+ Format:
+ INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+
+ @param VmPtr A pointer to VM context.
+ @param IsSignedOp Indicates whether the operand is signed or not.
- @return Standard EBC status
- @return Format:
- @return INSTRUCITON[32|64] {@}R1, {@}R2 {Immed16|Index16}
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -3418,13 +4359,15 @@ ExecuteDataManip ( /**
- Execute the EBC LOADSP instruction
+ Execute the EBC LOADSP instruction.
- @param VmPtr pointer to a VM context
+ Instruction syntax:
+ LOADSP SP1, R2
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return LOADSP SP1, R2
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -3471,13 +4414,15 @@ ExecuteLOADSP ( /**
- Execute the EBC STORESP instruction
+ Execute the EBC STORESP instruction.
+
+ Instruction syntax:
+ STORESP Rx, FLAGS|IP
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
- @return Standard EFI_STATUS
- @return Instruction syntax:
- @return STORESP Rx, FLAGS|IP
+ @retval EFI_UNSUPPORTED The opcodes/operands is not supported.
+ @retval EFI_SUCCESS The instruction is executed successfully.
**/
STATIC
@@ -3532,19 +4477,22 @@ ExecuteSTORESP ( /**
Decode a 16-bit index to determine the offset. Given an index value:
- b15 - sign bit
- b14:12 - number of bits in this index assigned to natural units (=a)
- ba:11 - constant units = C
- b0:a - natural units = N
+
+ b15 - sign bit
+ b14:12 - number of bits in this index assigned to natural units (=a)
+ ba:11 - constant units = ConstUnits
+ b0:a - natural units = NaturalUnits
+
Given this info, the offset can be computed by:
- offset = sign_bit * (C + N * sizeof(UINTN))
+ offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN))
+
Max offset is achieved with index = 0x7FFF giving an offset of
0x27B (32-bit machine) or 0x477 (64-bit machine).
- Min offset is achieved with index =
+ Min offset is achieved with index =
- @param VmPtr pointer to VM context
- @param CodeOffset offset from IP of the location of the 16-bit index to
- decode
+ @param VmPtr A pointer to VM context.
+ @param CodeOffset Offset from IP of the location of the 16-bit index
+ to decode.
@return The decoded offset.
@@ -3558,8 +4506,8 @@ VmReadIndex16 ( {
UINT16 Index;
INT16 Offset;
- INT16 C;
- INT16 N;
+ INT16 ConstUnits;
+ INT16 NaturalUnits;
INT16 NBits;
INT16 Mask;
@@ -3569,7 +4517,7 @@ VmReadIndex16 ( Index = VmReadCode16 (VmPtr, CodeOffset);
//
- // Get the mask for N. First get the number of bits from the index.
+ // Get the mask for NaturalUnits. First get the number of bits from the index.
//
NBits = (INT16) ((Index & 0x7000) >> 12);
@@ -3584,16 +4532,16 @@ VmReadIndex16 ( Mask = (INT16) ((INT16)~0 << NBits);
//
- // Now using the mask, extract N from the lower bits of the index.
+ // Now using the mask, extract NaturalUnits from the lower bits of the index.
//
- N = (INT16) (Index &~Mask);
+ NaturalUnits = (INT16) (Index &~Mask);
//
- // Now compute C
+ // Now compute ConstUnits
//
- C = (INT16) (((Index &~0xF000) & Mask) >> NBits);
+ ConstUnits = (INT16) (((Index &~0xF000) & Mask) >> NBits);
- Offset = (INT16) (N * sizeof (UINTN) + C);
+ Offset = (INT16) (NaturalUnits * sizeof (UINTN) + ConstUnits);
//
// Now set the sign
@@ -3614,11 +4562,11 @@ VmReadIndex16 ( /**
Decode a 32-bit index to determine the offset.
- @param VmPtr pointer to VM context
- @param CodeOffset offset from IP of the location of the 32-bit index to
- decode
+ @param VmPtr A pointer to VM context.
+ @param CodeOffset Offset from IP of the location of the 32-bit index
+ to decode.
- @return Converted index per EBC VM specification
+ @return Converted index per EBC VM specification.
**/
STATIC
@@ -3630,15 +4578,15 @@ VmReadIndex32 ( {
UINT32 Index;
INT32 Offset;
- INT32 C;
- INT32 N;
+ INT32 ConstUnits;
+ INT32 NaturalUnits;
INT32 NBits;
INT32 Mask;
Index = VmReadImmed32 (VmPtr, CodeOffset);
//
- // Get the mask for N. First get the number of bits from the index.
+ // Get the mask for NaturalUnits. First get the number of bits from the index.
//
NBits = (Index & 0x70000000) >> 28;
@@ -3653,16 +4601,16 @@ VmReadIndex32 ( Mask = (INT32)~0 << NBits;
//
- // Now using the mask, extract N from the lower bits of the index.
+ // Now using the mask, extract NaturalUnits from the lower bits of the index.
//
- N = Index &~Mask;
+ NaturalUnits = Index &~Mask;
//
- // Now compute C
+ // Now compute ConstUnits
//
- C = ((Index &~0xF0000000) & Mask) >> NBits;
+ ConstUnits = ((Index &~0xF0000000) & Mask) >> NBits;
- Offset = N * sizeof (UINTN) + C;
+ Offset = NaturalUnits * sizeof (UINTN) + ConstUnits;
//
// Now set the sign
@@ -3678,9 +4626,9 @@ VmReadIndex32 ( /**
Decode a 64-bit index to determine the offset.
- @param VmPtr pointer to VM context
- @param CodeOffset offset from IP of the location of the 64-bit index to
- decode
+ @param VmPtr A pointer to VM context.s
+ @param CodeOffset Offset from IP of the location of the 64-bit index
+ to decode.
@return Converted index per EBC VM specification
@@ -3694,15 +4642,15 @@ VmReadIndex64 ( {
UINT64 Index;
INT64 Offset;
- INT64 C;
- INT64 N;
+ INT64 ConstUnits;
+ INT64 NaturalUnits;
INT64 NBits;
INT64 Mask;
Index = VmReadCode64 (VmPtr, CodeOffset);
//
- // Get the mask for N. First get the number of bits from the index.
+ // Get the mask for NaturalUnits. First get the number of bits from the index.
//
NBits = RShiftU64 ((Index & 0x7000000000000000ULL), 60);
@@ -3717,16 +4665,16 @@ VmReadIndex64 ( Mask = (LShiftU64 ((UINT64)~0, (UINTN)NBits));
//
- // Now using the mask, extract N from the lower bits of the index.
+ // Now using the mask, extract NaturalUnits from the lower bits of the index.
//
- N = Index &~Mask;
+ NaturalUnits = Index &~Mask;
//
- // Now compute C
+ // Now compute ConstUnits
//
- C = ARShiftU64 (((Index &~0xF000000000000000ULL) & Mask), (UINTN)NBits);
+ ConstUnits = ARShiftU64 (((Index &~0xF000000000000000ULL) & Mask), (UINTN)NBits);
- Offset = MultU64x64 (N, sizeof (UINTN)) + C;
+ Offset = MultU64x64 (NaturalUnits, sizeof (UINTN)) + ConstUnits;
//
// Now set the sign
@@ -3740,21 +4688,26 @@ VmReadIndex64 ( /**
- The following VmWriteMem? routines are called by the EBC data
+ Writes 8-bit data to memory address.
+
+ This routine is called by the EBC data
movement instructions that write to memory. Since these writes
may be to the stack, which looks like (high address on top) this,
+
[EBC entry point arguments]
[VM stack]
[EBC stack]
+
we need to detect all attempts to write to the EBC entry point argument
- stack area and adjust the address (which will initially point into the
+ stack area and adjust the address (which will initially point into the
VM stack) to point into the EBC entry point arguments.
- @param VmPtr pointer to a VM context
- @param Addr adddress to write to
- @param Data value to write to Addr
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
- @return Standard EFI_STATUS
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
**/
STATIC
@@ -3773,6 +4726,29 @@ VmWriteMem8 ( return EFI_SUCCESS;
}
+/**
+ Writes 16-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
STATIC
EFI_STATUS
VmWriteMem16 (
@@ -3813,6 +4789,30 @@ VmWriteMem16 ( return EFI_SUCCESS;
}
+
+/**
+ Writes 32-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
STATIC
EFI_STATUS
VmWriteMem32 (
@@ -3853,6 +4853,30 @@ VmWriteMem32 ( return EFI_SUCCESS;
}
+
+/**
+ Writes 64-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
EFI_STATUS
VmWriteMem64 (
IN VM_CONTEXT *VmPtr,
@@ -3894,6 +4918,30 @@ VmWriteMem64 ( return EFI_SUCCESS;
}
+
+/**
+ Writes UINTN data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
EFI_STATUS
VmWriteMemN (
IN VM_CONTEXT *VmPtr,
@@ -3930,12 +4978,14 @@ VmWriteMemN ( /**
- The following VmReadImmed routines are called by the EBC execute
+ Reads 8-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
functions to read EBC immediate values from the code stream.
Since we can't assume alignment, each tries to read in the biggest
chunks size available, but will revert to smaller reads if necessary.
- @param VmPtr pointer to a VM context
+ @param VmPtr A pointer to a VM context.
@param Offset offset from IP of the code bytes to read.
@return Signed data of the requested size from the specified address.
@@ -3954,6 +5004,20 @@ VmReadImmed8 ( return * (INT8 *) (VmPtr->Ip + Offset);
}
+/**
+ Reads 16-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT16
VmReadImmed16 (
@@ -3982,6 +5046,21 @@ VmReadImmed16 ( return (INT16) (*(UINT8 *) (VmPtr->Ip + Offset) + (*(UINT8 *) (VmPtr->Ip + Offset + 1) << 8));
}
+
+/**
+ Reads 32-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT32
VmReadImmed32 (
@@ -4005,6 +5084,21 @@ VmReadImmed32 ( return Data;
}
+
+/**
+ Reads 64-bit immediate value at the offset.
+
+ This routine is called by the EBC execute
+ functions to read EBC immediate values from the code stream.
+ Since we can't assume alignment, each tries to read in the biggest
+ chunks size available, but will revert to smaller reads if necessary.
+
+ @param VmPtr A pointer to a VM context.
+ @param Offset offset from IP of the code bytes to read.
+
+ @return Signed data of the requested size from the specified address.
+
+**/
STATIC
INT64
VmReadImmed64 (
@@ -4036,11 +5130,13 @@ VmReadImmed64 ( /**
- The following VmReadCode() routines provide the ability to read raw
- unsigned data from the code stream.
+ Reads 16-bit unsinged data from the code stream.
+
+ This routine provides the ability to read raw unsigned data from the code
+ stream.
- @param VmPtr pointer to VM context
- @param Offset offset from current IP to the raw data to read.
+ @param VmPtr A pointer to VM context
+ @param Offset Offset from current IP to the raw data to read.
@return The raw unsigned 16-bit value from the code stream.
@@ -4073,6 +5169,19 @@ VmReadCode16 ( return (UINT16) (*(UINT8 *) (VmPtr->Ip + Offset) + (*(UINT8 *) (VmPtr->Ip + Offset + 1) << 8));
}
+
+/**
+ Reads 32-bit unsinged data from the code stream.
+
+ This routine provides the ability to read raw unsigned data from the code
+ stream.
+
+ @param VmPtr A pointer to VM context
+ @param Offset Offset from current IP to the raw data to read.
+
+ @return The raw unsigned 32-bit value from the code stream.
+
+**/
STATIC
UINT32
VmReadCode32 (
@@ -4095,6 +5204,19 @@ VmReadCode32 ( return Data;
}
+
+/**
+ Reads 64-bit unsinged data from the code stream.
+
+ This routine provides the ability to read raw unsigned data from the code
+ stream.
+
+ @param VmPtr A pointer to VM context
+ @param Offset Offset from current IP to the raw data to read.
+
+ @return The raw unsigned 64-bit value from the code stream.
+
+**/
STATIC
UINT64
VmReadCode64 (
@@ -4124,6 +5246,16 @@ VmReadCode64 ( return Data64;
}
+
+/**
+ Reads 8-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 8-bit value from the memory adress.
+
+**/
STATIC
UINT8
VmReadMem8 (
@@ -4141,6 +5273,15 @@ VmReadMem8 ( return * (UINT8 *) Addr;
}
+/**
+ Reads 16-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 16-bit value from the memory adress.
+
+**/
STATIC
UINT16
VmReadMem16 (
@@ -4164,6 +5305,15 @@ VmReadMem16 ( return (UINT16) (*(UINT8 *) Addr + (*(UINT8 *) (Addr + 1) << 8));
}
+/**
+ Reads 32-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 32-bit value from the memory adress.
+
+**/
STATIC
UINT32
VmReadMem32 (
@@ -4191,6 +5341,15 @@ VmReadMem32 ( return Data;
}
+/**
+ Reads 64-bit data form the memory address.
+
+ @param VmPtr A pointer to VM context.
+ @param Addr The memory address.
+
+ @return The 64-bit value from the memory adress.
+
+**/
STATIC
UINT64
VmReadMem64 (
@@ -4234,11 +5393,11 @@ VmReadMem64 ( accesses into the VM stack area, then we need to convert the address
to point to the EBC entry point arguments area. Do this here.
- @param VmPtr pointer to VM context
- @param Addr address of interest
+ @param VmPtr A Pointer to VM context.
+ @param Addr Address of interest
@return The unchanged address if it's not in the VM stack region. Otherwise,
- @return adjust for the stack gap and return the modified address.
+ adjust for the stack gap and return the modified address.
**/
STATIC
@@ -4299,6 +5458,12 @@ VmReadMemN ( return Data;
}
+/**
+ Returns the version of the EBC virtual machine.
+
+ @return The 64-bit version of EBC virtual machine.
+
+**/
UINT64
GetVmVersion (
VOID
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.h b/MdeModulePkg/Universal/EbcDxe/EbcExecute.h index 91aada0..13eea0c 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.h +++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.h @@ -227,6 +227,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define OPCODE_MOVIN 0x38
#define OPCODE_MOVREL 0x39
+/**
+ Execute an EBC image from an entry point or from a published protocol.
+
+ @param VmPtr A pointer to a VM context.
+
+ @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.
+ @retval EFI_SUCCESS All of the instructions are executed successfully.
+
+**/
EFI_STATUS
EbcExecute (
IN VM_CONTEXT *VmPtr
@@ -235,12 +244,41 @@ EbcExecute ( +/**
+ Returns the version of the EBC virtual machine.
+
+ @return The 64-bit version of EBC virtual machine.
+
+**/
UINT64
GetVmVersion (
VOID
)
;
+/**
+ Writes UINTN data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
EFI_STATUS
VmWriteMemN (
IN VM_CONTEXT *VmPtr,
@@ -249,6 +287,29 @@ VmWriteMemN ( )
;
+/**
+ Writes 64-bit data to memory address.
+
+ This routine is called by the EBC data
+ movement instructions that write to memory. Since these writes
+ may be to the stack, which looks like (high address on top) this,
+
+ [EBC entry point arguments]
+ [VM stack]
+ [EBC stack]
+
+ we need to detect all attempts to write to the EBC entry point argument
+ stack area and adjust the address (which will initially point into the
+ VM stack) to point into the EBC entry point arguments.
+
+ @param VmPtr A pointer to a VM context.
+ @param Addr Adddress to write to.
+ @param Data Value to write to Addr.
+
+ @retval EFI_SUCCESS The instruction is executed successfully.
+ @retval Other Some error occurs when writing data to the address.
+
+**/
EFI_STATUS
VmWriteMem64 (
IN VM_CONTEXT *VmPtr,
@@ -305,6 +366,20 @@ struct _EFI_EBC_VM_TEST_PROTOCOL { EBC_VM_TEST_DASM Disassemble;
};
+/**
+ Given a pointer to a new VM context, execute one or more instructions. This
+ function is only used for test purposes via the EBC VM test protocol.
+
+ @param This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
+ @param VmPtr A pointer to a VM context.
+ @param InstructionCount A pointer to a UINTN value holding the number of
+ instructions to execute. If it holds value of 0,
+ then the instruction to be executed is 1.
+
+ @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.
+ @retval EFI_SUCCESS All of the instructions are executed successfully.
+
+**/
EFI_STATUS
EbcExecuteInstructions (
IN EFI_EBC_VM_TEST_PROTOCOL *This,
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.c b/MdeModulePkg/Universal/EbcDxe/EbcInt.c index 37a2b7f..b3fe0d5 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.c @@ -1,9 +1,9 @@ /** @file
Top level module for the EBC virtual machine implementation.
- Provides auxilliary support routines for the VM. That is, routines
+ Provides auxiliary support routines for the VM. That is, routines
that are not particularly related to VM execution of EBC instructions.
-Copyright (c) 2006, Intel Corporation
+Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -34,6 +34,20 @@ typedef struct _EBC_IMAGE_LIST { EBC_THUNK_LIST *ThunkList;
} EBC_IMAGE_LIST;
+/**
+ This routine is called by the core when an image is being unloaded from
+ memory. Basically we now have the opportunity to do any necessary cleanup.
+ Typically this will include freeing any memory allocated for thunk-creation.
+
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param ImageHandle Handle of image for which the thunk is being
+ created.
+
+ @retval EFI_INVALID_PARAMETER The ImageHandle passed in was not found in the
+ internal list of EBC image handles.
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -42,6 +56,25 @@ EbcUnloadImage ( IN EFI_HANDLE ImageHandle
);
+/**
+ This is the top-level routine plugged into the EBC protocol. Since thunks
+ are very processor-specific, from here we dispatch directly to the very
+ processor-specific routine EbcCreateThunks().
+
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param ImageHandle Handle of image for which the thunk is being
+ created. The EBC interpreter may use this to
+ keep track of any resource allocations
+ performed in loading and executing the image.
+ @param EbcEntryPoint Address of the actual EBC entry point or
+ protocol service the thunk should call.
+ @param Thunk Returned pointer to a thunk created.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Image entry point is not 2-byte aligned.
+ @retval EFI_OUT_OF_RESOURCES Memory could not be allocated for the thunk.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -52,6 +85,17 @@ EbcCreateThunk ( OUT VOID **Thunk
);
+/**
+ Called to get the version of the interpreter.
+
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param Version Pointer to where to store the returned version
+ of the interpreter.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Version pointer is NULL.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -60,6 +104,16 @@ EbcGetVersion ( IN OUT UINT64 *Version
);
+/**
+ To install default Callback function for the VM interpreter.
+
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval Others Some error occurs when creating periodic event.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -67,6 +121,15 @@ InitializeEbcCallback ( IN EFI_DEBUG_SUPPORT_PROTOCOL *This
);
+/**
+ The default Exception Callback for the VM interpreter.
+ In this function, we report status code, and print debug information
+ about EBC_CONTEXT, then dead loop.
+
+ @param InterruptType Interrupt type.
+ @param SystemContext EBC system context.
+
+**/
STATIC
VOID
EFIAPI
@@ -75,6 +138,14 @@ CommonEbcExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext
);
+/**
+ The periodic callback function for EBC VM interpreter, which is used
+ to support the EFI debug support protocol.
+
+ @param Event The Periodic Callback Event.
+ @param Context It should be the address of VM_CONTEXT pointer.
+
+**/
STATIC
VOID
EFIAPI
@@ -83,6 +154,16 @@ EbcPeriodicNotifyFunction ( IN VOID *Context
);
+/**
+ The VM interpreter calls this function on a periodic basis to support
+ the EFI debug support protocol.
+
+ @param VmPtr Pointer to a VM context for passing info to the
+ debugger.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -94,18 +175,43 @@ EbcDebugPeriodic ( // These two functions and the GUID are used to produce an EBC test protocol.
// This functionality is definitely not required for execution.
//
+/**
+ Produces an EBC VM test protocol that can be used for regression tests.
+
+ @param IHandle Handle on which to install the protocol.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
InitEbcVmTestProtocol (
IN EFI_HANDLE *Handle
);
+/**
+ Returns the EFI_UNSUPPORTED Status.
+
+ @return EFI_UNSUPPORTED This function always return EFI_UNSUPPORTED status.
+
+**/
STATIC
EFI_STATUS
EbcVmTestUnsupported (
VOID
);
+/**
+ Registers a callback function that the EBC interpreter calls to flush the
+ processor instruction cache following creation of thunks.
+
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param Flush Pointer to a function of type EBC_ICACH_FLUSH.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -114,6 +220,17 @@ EbcRegisterICacheFlush ( IN EBC_ICACHE_FLUSH Flush
);
+/**
+ This EBC debugger protocol service is called by the debug agent
+
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the
+ maximum supported processor index is returned.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -122,6 +239,27 @@ EbcDebugGetMaximumProcessorIndex ( OUT UINTN *MaxProcessorIndex
);
+/**
+ This protocol service is called by the debug agent to register a function
+ for us to call on a periodic basis.
+
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param ProcessorIndex Specifies which processor the callback function
+ applies to.
+ @param PeriodicCallback A pointer to a function of type
+ PERIODIC_CALLBACK that is the main periodic
+ entry point of the debug agent. It receives as a
+ parameter a pointer to the full context of the
+ interrupted execution thread.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a
+ callback function was previously registered.
+ @retval EFI_INVALID_PARAMETER Null PeriodicCallback parameter when no
+ callback function was previously registered.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -131,6 +269,31 @@ EbcDebugRegisterPeriodicCallback ( IN EFI_PERIODIC_CALLBACK PeriodicCallback
);
+/**
+ This protocol service is called by the debug agent to register a function
+ for us to call when we detect an exception.
+
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param ProcessorIndex Specifies which processor the callback function
+ applies to.
+ @param ExceptionCallback A pointer to a function of type
+ EXCEPTION_CALLBACK that is called when the
+ processor exception specified by ExceptionType
+ occurs. Passing NULL unregisters any previously
+ registered function associated with
+ ExceptionType.
+ @param ExceptionType Specifies which processor exception to hook.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ALREADY_STARTED Non-NULL ExceptionCallback parameter when a
+ callback function was previously registered.
+ @retval EFI_INVALID_PARAMETER ExceptionType parameter is negative or exceeds
+ MAX_EBC_EXCEPTION.
+ @retval EFI_INVALID_PARAMETER Null ExceptionCallback parameter when no
+ callback function was previously registered.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -141,6 +304,22 @@ EbcDebugRegisterExceptionCallback ( IN EFI_EXCEPTION_TYPE ExceptionType
);
+/**
+ This EBC debugger protocol service is called by the debug agent. Required
+ for DebugSupport compliance but is only stubbed out for EBC.
+
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param ProcessorIndex Specifies which processor the callback function
+ applies to.
+ @param Start StartSpecifies the physical base of the memory
+ range to be invalidated.
+ @param Length Specifies the minimum number of bytes in the
+ processor's instruction cache to invalidate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -157,28 +336,28 @@ EbcDebugInvalidateInstructionCache ( // also be global since the execution of an EBC image does not provide
// a This pointer.
//
-static EBC_IMAGE_LIST *mEbcImageList = NULL;
+STATIC EBC_IMAGE_LIST *mEbcImageList = NULL;
//
// Callback function to flush the icache after thunk creation
//
-static EBC_ICACHE_FLUSH mEbcICacheFlush;
+STATIC EBC_ICACHE_FLUSH mEbcICacheFlush;
//
// These get set via calls by the debug agent
//
-static EFI_PERIODIC_CALLBACK mDebugPeriodicCallback = NULL;
-static EFI_EXCEPTION_CALLBACK mDebugExceptionCallback[MAX_EBC_EXCEPTION + 1] = {NULL};
-static EFI_GUID mEfiEbcVmTestProtocolGuid = EFI_EBC_VM_TEST_PROTOCOL_GUID;
+STATIC EFI_PERIODIC_CALLBACK mDebugPeriodicCallback = NULL;
+STATIC EFI_EXCEPTION_CALLBACK mDebugExceptionCallback[MAX_EBC_EXCEPTION + 1] = {NULL};
+STATIC EFI_GUID mEfiEbcVmTestProtocolGuid = EFI_EBC_VM_TEST_PROTOCOL_GUID;
-static VOID* mStackBuffer[MAX_STACK_NUM];
-static EFI_HANDLE mStackBufferIndex[MAX_STACK_NUM];
-static UINTN mStackNum = 0;
+STATIC VOID* mStackBuffer[MAX_STACK_NUM];
+STATIC EFI_HANDLE mStackBufferIndex[MAX_STACK_NUM];
+STATIC UINTN mStackNum = 0;
//
// Event for Periodic callback
//
-static EFI_EVENT mEbcPeriodicEvent;
+STATIC EFI_EVENT mEbcPeriodicEvent;
VM_CONTEXT *mVmPtr = NULL;
@@ -378,16 +557,18 @@ ErrorExit: are very processor-specific, from here we dispatch directly to the very
processor-specific routine EbcCreateThunks().
- @param This protocol instance pointer
- @param ImageHandle handle to the image. The EBC interpreter may use
- this to keep track of any resource allocations
- performed in loading and executing the image.
- @param EbcEntryPoint the entry point for the image (as defined in the
- file header)
- @param Thunk pointer to thunk pointer where the address of the
- created thunk is returned.
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param ImageHandle Handle of image for which the thunk is being
+ created. The EBC interpreter may use this to
+ keep track of any resource allocations
+ performed in loading and executing the image.
+ @param EbcEntryPoint Address of the actual EBC entry point or
+ protocol service the thunk should call.
+ @param Thunk Returned pointer to a thunk created.
- @return EFI_STATUS
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Image entry point is not 2-byte aligned.
+ @retval EFI_OUT_OF_RESOURCES Memory could not be allocated for the thunk.
**/
STATIC
@@ -415,12 +596,12 @@ EbcCreateThunk ( /**
This EBC debugger protocol service is called by the debug agent
- @param This pointer to the caller's debug support protocol
- interface
- @param MaxProcessorIndex pointer to a caller allocated UINTN in which the
- maximum processor index is returned.
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the
+ maximum supported processor index is returned.
- @return Standard EFI_STATUS
+ @retval EFI_SUCCESS The function completed successfully.
**/
STATIC
@@ -440,11 +621,21 @@ EbcDebugGetMaximumProcessorIndex ( This protocol service is called by the debug agent to register a function
for us to call on a periodic basis.
- @param This pointer to the caller's debug support protocol
- interface
- @param PeriodicCallback pointer to the function to call periodically
-
- @return Always EFI_SUCCESS
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param ProcessorIndex Specifies which processor the callback function
+ applies to.
+ @param PeriodicCallback A pointer to a function of type
+ PERIODIC_CALLBACK that is the main periodic
+ entry point of the debug agent. It receives as a
+ parameter a pointer to the full context of the
+ interrupted execution thread.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a
+ callback function was previously registered.
+ @retval EFI_INVALID_PARAMETER Null PeriodicCallback parameter when no
+ callback function was previously registered.
**/
STATIC
@@ -472,11 +663,25 @@ EbcDebugRegisterPeriodicCallback ( This protocol service is called by the debug agent to register a function
for us to call when we detect an exception.
- @param This pointer to the caller's debug support protocol
- interface
- @param ExceptionCallback pointer to the function to the exception
-
- @return Always EFI_SUCCESS
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param ProcessorIndex Specifies which processor the callback function
+ applies to.
+ @param ExceptionCallback A pointer to a function of type
+ EXCEPTION_CALLBACK that is called when the
+ processor exception specified by ExceptionType
+ occurs. Passing NULL unregisters any previously
+ registered function associated with
+ ExceptionType.
+ @param ExceptionType Specifies which processor exception to hook.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ALREADY_STARTED Non-NULL ExceptionCallback parameter when a
+ callback function was previously registered.
+ @retval EFI_INVALID_PARAMETER ExceptionType parameter is negative or exceeds
+ MAX_EBC_EXCEPTION.
+ @retval EFI_INVALID_PARAMETER Null ExceptionCallback parameter when no
+ callback function was previously registered.
**/
STATIC
@@ -507,8 +712,16 @@ EbcDebugRegisterExceptionCallback ( This EBC debugger protocol service is called by the debug agent. Required
for DebugSupport compliance but is only stubbed out for EBC.
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
+ @param ProcessorIndex Specifies which processor the callback function
+ applies to.
+ @param Start StartSpecifies the physical base of the memory
+ range to be invalidated.
+ @param Length Specifies the minimum number of bytes in the
+ processor's instruction cache to invalidate.
- @return EFI_SUCCESS
+ @retval EFI_SUCCESS The function completed successfully.
**/
STATIC
@@ -528,10 +741,12 @@ EbcDebugInvalidateInstructionCache ( /**
The VM interpreter calls this function when an exception is detected.
- @param VmPtr pointer to a VM context for passing info to the
+ @param ExceptionType Specifies the processor exception detected.
+ @param ExceptionFlags Specifies the exception context.
+ @param VmPtr Pointer to a VM context for passing info to the
EFI debugger.
- @return EFI_SUCCESS if it returns at all
+ @retval EFI_SUCCESS This function completed successfully.
**/
EFI_STATUS
@@ -605,13 +820,16 @@ EbcDebugSignalException ( /**
To install default Callback function for the VM interpreter.
- @param This pointer to the instance of DebugSupport protocol
+ @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL
+ instance.
- @return None
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval Others Some error occurs when creating periodic event.
**/
STATIC
EFI_STATUS
+EFIAPI
InitializeEbcCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This
)
@@ -666,11 +884,10 @@ InitializeEbcCallback ( @param InterruptType Interrupt type.
@param SystemContext EBC system context.
- @return None
-
**/
STATIC
VOID
+EFIAPI
CommonEbcExceptionHandler (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_SYSTEM_CONTEXT SystemContext
@@ -692,8 +909,6 @@ CommonEbcExceptionHandler ( @param Event The Periodic Callback Event.
@param Context It should be the address of VM_CONTEXT pointer.
- @return None.
-
**/
STATIC
VOID
@@ -719,14 +934,15 @@ EbcPeriodicNotifyFunction ( The VM interpreter calls this function on a periodic basis to support
the EFI debug support protocol.
- @param VmPtr pointer to a VM context for passing info to the
+ @param VmPtr Pointer to a VM context for passing info to the
debugger.
- @return Standard EFI status.
+ @retval EFI_SUCCESS The function completed successfully.
**/
STATIC
EFI_STATUS
+EFIAPI
EbcDebugPeriodic (
IN VM_CONTEXT *VmPtr
)
@@ -781,12 +997,13 @@ EbcDebugPeriodic ( memory. Basically we now have the opportunity to do any necessary cleanup.
Typically this will include freeing any memory allocated for thunk-creation.
- @param This protocol instance pointer
- @param ImageHandle handle to the image being unloaded.
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param ImageHandle Handle of image for which the thunk is being
+ created.
- @retval EFI_INVALID_PARAMETER the ImageHandle passed in was not found in the
- internal list of EBC image handles.
- @retval EFI_STATUS completed successfully
+ @retval EFI_INVALID_PARAMETER The ImageHandle passed in was not found in the
+ internal list of EBC image handles.
+ @retval EFI_SUCCESS The function completed successfully.
**/
STATIC
@@ -855,12 +1072,12 @@ EbcUnloadImage ( Also flush the instruction cache since we've written thunk code
to memory that will be executed eventually.
- @param ImageHandle the image handle to which the thunk is tied
- @param ThunkBuffer the buffer we've created/allocated
- @param ThunkSize the size of the thunk memory allocated
+ @param ImageHandle The image handle to which the thunk is tied.
+ @param ThunkBuffer The buffer that has been created/allocated.
+ @param ThunkSize The size of the thunk memory allocated.
- @retval EFI_OUT_OF_RESOURCES memory allocation failed
- @retval EFI_SUCCESS successful completion
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
@@ -925,6 +1142,16 @@ EbcAddImageThunk ( return EFI_SUCCESS;
}
+/**
+ Registers a callback function that the EBC interpreter calls to flush the
+ processor instruction cache following creation of thunks.
+
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param Flush Pointer to a function of type EBC_ICACH_FLUSH.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -937,6 +1164,17 @@ EbcRegisterICacheFlush ( return EFI_SUCCESS;
}
+/**
+ Called to get the version of the interpreter.
+
+ @param This A pointer to the EFI_EBC_PROTOCOL instance.
+ @param Version Pointer to where to store the returned version
+ of the interpreter.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Version pointer is NULL.
+
+**/
STATIC
EFI_STATUS
EFIAPI
@@ -953,11 +1191,24 @@ EbcGetVersion ( return EFI_SUCCESS;
}
+/**
+ Returns the stack index and buffer assosicated with the Handle parameter.
+
+ @param Handle The EFI handle as the index to the EBC stack.
+ @param StackBuffer A pointer to hold the returned stack buffer.
+ @param BufferIndex A pointer to hold the returned stack index.
+
+ @retval EFI_OUT_OF_RESOURCES The Handle parameter does not correspond to any
+ existing EBC stack.
+ @retval EFI_SUCCESS The stack index and buffer were found and
+ returned to the caller.
+
+**/
EFI_STATUS
GetEBCStack(
- EFI_HANDLE Handle,
- VOID **StackBuffer,
- UINTN *BufferIndex
+ IN EFI_HANDLE Handle,
+ OUT VOID **StackBuffer,
+ OUT UINTN *BufferIndex
)
{
UINTN Index;
@@ -978,18 +1229,34 @@ GetEBCStack( return EFI_SUCCESS;
}
+/**
+ Returns from the EBC stack by stack Index.
+
+ @param Index Specifies which EBC stack to return from.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
EFI_STATUS
ReturnEBCStack(
- UINTN Index
+ IN UINTN Index
)
{
- mStackBufferIndex[Index] =NULL;
+ mStackBufferIndex[Index] = NULL;
return EFI_SUCCESS;
}
+/**
+ Returns from the EBC stack associated with the Handle parameter.
+
+ @param Handle Specifies the EFI handle to find the EBC stack with.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
EFI_STATUS
ReturnEBCStackByHandle(
- EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
UINTN Index;
@@ -1005,6 +1272,13 @@ ReturnEBCStackByHandle( return EFI_SUCCESS;
}
+/**
+ Allocates memory to hold all the EBC stacks.
+
+ @retval EFI_SUCCESS The EBC stacks were allocated successfully.
+ @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.
+
+**/
EFI_STATUS
InitEBCStack (
VOID
@@ -1023,6 +1297,13 @@ InitEBCStack ( return EFI_SUCCESS;
}
+
+/**
+ Free all EBC stacks allocated before.
+
+ @retval EFI_SUCCESS All the EBC stacks were freed.
+
+**/
EFI_STATUS
FreeEBCStack(
VOID
@@ -1036,12 +1317,12 @@ FreeEBCStack( }
/**
- Produce an EBC VM test protocol that can be used for regression tests.
+ Produces an EBC VM test protocol that can be used for regression tests.
- @param IHandle handle on which to install the protocol.
+ @param IHandle Handle on which to install the protocol.
- @retval EFI_OUT_OF_RESOURCES memory allocation failed
- @retval EFI_SUCCESS successful completion
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @retval EFI_SUCCESS The function completed successfully.
**/
STATIC
@@ -1078,9 +1359,19 @@ InitEbcVmTestProtocol ( }
return Status;
}
+
+
+/**
+ Returns the EFI_UNSUPPORTED Status.
+
+ @return EFI_UNSUPPORTED This function always return EFI_UNSUPPORTED status.
+
+**/
STATIC
EFI_STATUS
-EbcVmTestUnsupported ()
+EbcVmTestUnsupported (
+ VOID
+ )
{
return EFI_UNSUPPORTED;
}
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.h b/MdeModulePkg/Universal/EbcDxe/EbcInt.h index c9f2b82..720ee26 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.h +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.h @@ -79,6 +79,23 @@ extern VM_CONTEXT *mVmPtr; //
#define VM_STACK_KEY_VALUE 0xDEADBEEF
+/**
+ Create thunks for an EBC image entry point, or an EBC protocol service.
+
+ @param ImageHandle Image handle for the EBC image. If not null, then
+ we're creating a thunk for an image entry point.
+ @param EbcEntryPoint Address of the EBC code that the thunk is to call
+ @param Thunk Returned thunk we create here
+ @param Flags Flags indicating options for creating the thunk
+
+ @retval EFI_SUCCESS The thunk was created successfully.
+ @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit
+ aligned.
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC
+ Thunk.
+ @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.
+
+**/
EFI_STATUS
EbcCreateThunks (
IN EFI_HANDLE ImageHandle,
@@ -88,6 +105,19 @@ EbcCreateThunks ( )
;
+/**
+ Add a thunk to our list of thunks for a given image handle.
+ Also flush the instruction cache since we've written thunk code
+ to memory that will be executed eventually.
+
+ @param ImageHandle The image handle to which the thunk is tied.
+ @param ThunkBuffer The buffer that has been created/allocated.
+ @param ThunkSize The size of the thunk memory allocated.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
EFI_STATUS
EbcAddImageThunk (
IN EFI_HANDLE ImageHandle,
@@ -100,6 +130,17 @@ EbcAddImageThunk ( // The interpreter calls these when an exception is detected,
// or as a periodic callback.
//
+/**
+ The VM interpreter calls this function when an exception is detected.
+
+ @param ExceptionType Specifies the processor exception detected.
+ @param ExceptionFlags Specifies the exception context.
+ @param VmPtr Pointer to a VM context for passing info to the
+ EFI debugger.
+
+ @retval EFI_SUCCESS This function completed successfully.
+
+**/
EFI_STATUS
EbcDebugSignalException (
IN EFI_EXCEPTION_TYPE ExceptionType,
@@ -117,28 +158,56 @@ EbcDebugSignalException ( #define STACK_POOL_SIZE (1024 * 1020)
#define MAX_STACK_NUM 4
-EFI_STATUS
-EbcDebugSignalPeriodic (
- IN VM_CONTEXT *VmPtr
- )
-;
-
//
// External low level functions that are native-processor dependent
-//
+//
+/**
+ The VM thunk code stuffs an EBC entry point into a processor
+ register. Since we can't use inline assembly to get it from
+ the interpreter C code, stuff it into the return value
+ register and return.
+
+ @return The contents of the register in which the entry point is passed.
+
+**/
UINTN
+EFIAPI
EbcLLGetEbcEntryPoint (
VOID
)
;
+/**
+ Returns the caller's value of the stack pointer.
+
+ We adjust it by 4 here because when they called us, the return address
+ is put on the stack, thereby lowering it by 4 bytes.
+
+ @return The current value of the stack pointer for the caller.
+
+**/
UINTN
+EFIAPI
EbcLLGetStackPointer (
VOID
)
;
+/**
+ This function is called to execute an EBC CALLEX instruction.
+ This instruction requires that we thunk out to external native
+ code. For x64, we switch stacks, copy the arguments to the stack
+ and jump to the specified function.
+ On return, we restore the stack pointer to its original location.
+ Destroys no working registers.
+
+ @param CallAddr The function address.
+ @param EbcSp The new EBC stack pointer.
+ @param FramePtr The frame pointer.
+
+**/
VOID
+EFIAPI
EbcLLCALLEXNative (
IN UINTN CallAddr,
IN UINTN EbcSp,
@@ -146,47 +215,114 @@ EbcLLCALLEXNative ( )
;
+/**
+ This function is called to execute an EBC CALLEX instruction.
+ The function check the callee's content to see whether it is common native
+ code or a thunk to another piece of EBC code.
+ If the callee is common native code, use EbcLLCAllEXASM to manipulate,
+ otherwise, set the VM->IP to target EBC code directly to avoid another VM
+ be startup which cost time and stack space.
+
+ @param VmPtr Pointer to a VM context.
+ @param FuncAddr Callee's address
+ @param NewStackPointer New stack pointer after the call
+ @param FramePtr New frame pointer after the call
+ @param Size The size of call instruction
+
+**/
VOID
EbcLLCALLEX (
IN VM_CONTEXT *VmPtr,
- IN UINTN CallAddr,
- IN UINTN EbcSp,
+ IN UINTN FuncAddr,
+ IN UINTN NewStackPointer,
IN VOID *FramePtr,
IN UINT8 Size
)
;
+/**
+ When EBC calls native, on return the VM has to stuff the return
+ value into a VM register. It's assumed here that the value is still
+ in the register, so simply return and the caller should get the
+ return result properly.
+
+ @return The unmodified value returned by the native code.
+
+**/
INT64
+EFIAPI
EbcLLGetReturnValue (
VOID
)
;
+/**
+ Returns the stack index and buffer assosicated with the Handle parameter.
+
+ @param Handle The EFI handle as the index to the EBC stack.
+ @param StackBuffer A pointer to hold the returned stack buffer.
+ @param BufferIndex A pointer to hold the returned stack index.
+
+ @retval EFI_OUT_OF_RESOURCES The Handle parameter does not correspond to any
+ existing EBC stack.
+ @retval EFI_SUCCESS The stack index and buffer were found and
+ returned to the caller.
+
+**/
EFI_STATUS
GetEBCStack(
- EFI_HANDLE Handle,
- VOID **StackBuffer,
- UINTN *BufferIndex
+ IN EFI_HANDLE Handle,
+ OUT VOID **StackBuffer,
+ OUT UINTN *BufferIndex
);
+/**
+ Returns from the EBC stack by stack Index.
+
+ @param Index Specifies which EBC stack to return from.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
EFI_STATUS
ReturnEBCStack(
- UINTN Index
+ IN UINTN Index
);
+/**
+ Allocates memory to hold all the EBC stacks.
+
+ @retval EFI_SUCCESS The EBC stacks were allocated successfully.
+ @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.
+
+**/
EFI_STATUS
InitEBCStack (
VOID
);
+/**
+ Free all EBC stacks allocated before.
+
+ @retval EFI_SUCCESS All the EBC stacks were freed.
+
+**/
EFI_STATUS
FreeEBCStack(
VOID
);
+/**
+ Returns from the EBC stack associated with the Handle parameter.
+
+ @param Handle Specifies the EFI handle to find the EBC stack with.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
EFI_STATUS
ReturnEBCStackByHandle(
- EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
);
//
// Defines for a simple EBC debugger interface
@@ -255,13 +391,6 @@ typedef struct { #define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('e', 'b', 'c', 'p')
-struct _EBC_PROTOCOL_PRIVATE_DATA {
- UINT32 Signature;
- EFI_EBC_PROTOCOL EbcProtocol;
- UINTN StackBase;
- UINTN StackTop;
- UINTN StackSize;
-} ;
#define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)
diff --git a/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c index 1d008ac..11fa4e6 100644 --- a/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c @@ -36,13 +36,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. otherwise, set the VM->IP to target EBC code directly to avoid another VM
be startup which cost time and stack space.
- @parm VmPtr Pointer to a VM context.
- @parm FuncAddr Callee's address
- @parm NewStackPointer New stack pointer after the call
- @parm FramePtr New frame pointer after the call
- @parm Size The size of call instruction
-
- @return None.
+ @param VmPtr Pointer to a VM context.
+ @param FuncAddr Callee's address
+ @param NewStackPointer New stack pointer after the call
+ @param FramePtr New frame pointer after the call
+ @param Size The size of call instruction
**/
VOID
@@ -137,9 +135,26 @@ Action: in via a processor register, so we'll need to make a call to get the
value.
- None. Since we're called from a fixed up thunk (which we want to keep
- small), our only so-called argument is the EBC entry point passed in
- to us in a processor register.
+ This is a thunk function. Microsoft x64 compiler only provide fast_call
+ calling convention, so the first four arguments are passed by rcx, rdx,
+ r8, and r9, while other arguments are passed in stack.
+
+ @param Arg1 The 1st argument.
+ @param Arg2 The 2nd argument.
+ @param Arg3 The 3rd argument.
+ @param Arg4 The 4th argument.
+ @param Arg5 The 5th argument.
+ @param Arg6 The 6th argument.
+ @param Arg7 The 7th argument.
+ @param Arg8 The 8th argument.
+ @param Arg9 The 9th argument.
+ @param Arg10 The 10th argument.
+ @param Arg11 The 11th argument.
+ @param Arg12 The 12th argument.
+ @param Arg13 The 13th argument.
+ @param Arg14 The 14th argument.
+ @param Arg15 The 15th argument.
+ @param Arg16 The 16th argument.
@return The value returned by the EBC application we're going to run.
@@ -286,8 +301,9 @@ EbcInterpret ( in via a processor register, so we'll need to make a call to get the
value.
- @param ImageHandle image handle for the EBC application we're executing
- @param SystemTable standard system table passed into an driver's entry point
+ @param ImageHandle image handle for the EBC application we're executing
+ @param SystemTable standard system table passed into an driver's entry
+ point
@return The value returned by the EBC application we're going to run.
@@ -385,13 +401,20 @@ ExecuteEbcImageEntryPoint ( /**
- Create an IA32 thunk for the given EBC entry point.
+ Create thunks for an EBC image entry point, or an EBC protocol service.
- @param ImageHandle Handle of image for which this thunk is being created
- @param EbcEntryPoint Address of the EBC code that the thunk is to call
- @param Thunk Returned thunk we create here
+ @param ImageHandle Image handle for the EBC image. If not null, then
+ we're creating a thunk for an image entry point.
+ @param EbcEntryPoint Address of the EBC code that the thunk is to call
+ @param Thunk Returned thunk we create here
+ @param Flags Flags indicating options for creating the thunk
- @return Standard EFI status.
+ @retval EFI_SUCCESS The thunk was created successfully.
+ @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit
+ aligned.
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC
+ Thunk.
+ @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.
**/
EFI_STATUS
@@ -404,7 +427,7 @@ EbcCreateThunks ( {
UINT8 *Ptr;
UINT8 *ThunkBase;
- UINT32 I;
+ UINT32 Index;
UINT32 Addr;
INT32 Size;
INT32 ThunkSize;
@@ -444,7 +467,7 @@ EbcCreateThunks ( Ptr++;
Size--;
Addr = (UINT32) 0xCA112EBC;
- for (I = 0; I < sizeof (Addr); I++) {
+ for (Index = 0; Index < sizeof (Addr); Index++) {
*Ptr = (UINT8) (UINTN) Addr;
Addr >>= 8;
Ptr++;
@@ -461,7 +484,7 @@ EbcCreateThunks ( Ptr++;
Size--;
Addr = (UINT32) EbcEntryPoint;
- for (I = 0; I < sizeof (Addr); I++) {
+ for (Index = 0; Index < sizeof (Addr); Index++) {
*Ptr = (UINT8) (UINTN) Addr;
Addr >>= 8;
Ptr++;
@@ -483,7 +506,7 @@ EbcCreateThunks ( *Ptr = 0xB9;
Ptr++;
Size--;
- for (I = 0; I < sizeof (Addr); I++) {
+ for (Index = 0; Index < sizeof (Addr); Index++) {
*Ptr = (UINT8) Addr;
Addr >>= 8;
Ptr++;
diff --git a/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c index b2cb6f6..83d596c 100644 --- a/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c @@ -17,6 +17,23 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcExecute.h"
#include "EbcSupport.h"
+/**
+ Given raw bytes of Itanium based code, format them into a bundle and
+ write them out.
+
+ @param MemPtr pointer to memory location to write the bundles
+ to.
+ @param Template 5-bit template.
+ @param Slot0 Instruction slot 0 data for the bundle.
+ @param Slot1 Instruction slot 1 data for the bundle.
+ @param Slot2 Instruction slot 2 data for the bundle.
+
+ @retval EFI_INVALID_PARAMETER Pointer is not aligned
+ @retval EFI_INVALID_PARAMETER No more than 5 bits in template
+ @retval EFI_INVALID_PARAMETER More than 41 bits used in code
+ @retval EFI_SUCCESS All data is written.
+
+**/
STATIC
EFI_STATUS
WriteBundle (
@@ -27,11 +44,18 @@ WriteBundle ( IN UINT64 Slot2
);
+/**
+ Pushes a 64 bit unsigned value to the VM stack.
+
+ @param VmPtr The pointer to current VM context.
+ @param Arg The value to be pushed.
+
+**/
STATIC
VOID
PushU64 (
- VM_CONTEXT *VmPtr,
- UINT64 Arg
+ IN VM_CONTEXT *VmPtr,
+ IN UINT64 Arg
)
{
//
@@ -42,6 +66,21 @@ PushU64 ( *(UINT64 *) VmPtr->R[0] = Arg;
}
+/**
+ Begin executing an EBC image. The address of the entry point is passed
+ in via a processor register, so we'll need to make a call to get the
+ value.
+
+ This is a thunk function. Microsoft x64 compiler only provide fast_call
+ calling convention, so the first four arguments are passed by rcx, rdx,
+ r8, and r9, while other arguments are passed in stack.
+
+ @param Arg1 The 1st argument.
+ @param ... The variable arguments list.
+
+ @return The value returned by the EBC application we're going to run.
+
+**/
STATIC
UINT64
EbcInterpret (
@@ -189,15 +228,13 @@ EbcInterpret ( /**
- IPF implementation.
Begin executing an EBC image. The address of the entry point is passed
in via a processor register, so we'll need to make a call to get the
value.
- @param ImageHandle image handle for the EBC application we're
- executing
- @param SystemTable standard system table passed into an driver's
- entry point
+ @param ImageHandle image handle for the EBC application we're executing
+ @param SystemTable standard system table passed into an driver's entry
+ point
@return The value returned by the EBC application we're going to run.
@@ -312,13 +349,18 @@ ExecuteEbcImageEntryPoint ( /**
Create thunks for an EBC image entry point, or an EBC protocol service.
- @param ImageHandle Image handle for the EBC image. If not null, then
- we're creating a thunk for an image entry point.
- @param EbcEntryPoint Address of the EBC code that the thunk is to call
- @param Thunk Returned thunk we create here
- @param Flags Flags indicating options for creating the thunk
+ @param ImageHandle Image handle for the EBC image. If not null, then
+ we're creating a thunk for an image entry point.
+ @param EbcEntryPoint Address of the EBC code that the thunk is to call
+ @param Thunk Returned thunk we create here
+ @param Flags Flags indicating options for creating the thunk
- @return Standard EFI status.
+ @retval EFI_SUCCESS The thunk was created successfully.
+ @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit
+ aligned.
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC
+ Thunk.
+ @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.
**/
EFI_STATUS
@@ -334,11 +376,11 @@ EbcCreateThunks ( UINT64 Addr;
UINT64 Code[3]; // Code in a bundle
UINT64 RegNum; // register number for MOVL
- UINT64 I; // bits of MOVL immediate data
- UINT64 Ic; // bits of MOVL immediate data
- UINT64 Imm5c; // bits of MOVL immediate data
- UINT64 Imm9d; // bits of MOVL immediate data
- UINT64 Imm7b; // bits of MOVL immediate data
+ UINT64 BitI; // bits of MOVL immediate data
+ UINT64 BitIc; // bits of MOVL immediate data
+ UINT64 BitImm5c; // bits of MOVL immediate data
+ UINT64 BitImm9d; // bits of MOVL immediate data
+ UINT64 BitImm7b; // bits of MOVL immediate data
UINT64 Br; // branch register for loading and jumping
UINT64 *Data64Ptr;
UINT32 ThunkSize;
@@ -436,23 +478,23 @@ EbcCreateThunks ( // Extract bits from the address for insertion into the instruction
// i = Addr[63:63]
//
- I = RShiftU64 (Addr, 63) & 0x01;
+ BitI = RShiftU64 (Addr, 63) & 0x01;
//
// ic = Addr[21:21]
//
- Ic = RShiftU64 (Addr, 21) & 0x01;
+ BitIc = RShiftU64 (Addr, 21) & 0x01;
//
// imm5c = Addr[20:16] for 5 bits
//
- Imm5c = RShiftU64 (Addr, 16) & 0x1F;
+ BitImm5c = RShiftU64 (Addr, 16) & 0x1F;
//
// imm9d = Addr[15:7] for 9 bits
//
- Imm9d = RShiftU64 (Addr, 7) & 0x1FF;
+ BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;
//
// imm7b = Addr[6:0] for 7 bits
//
- Imm7b = Addr & 0x7F;
+ BitImm7b = Addr & 0x7F;
//
// The EBC entry point will be put into r8, so r8 can be used here
@@ -463,12 +505,12 @@ EbcCreateThunks ( //
// Next is jumbled data, including opcode and rest of address
//
- Code[2] = LShiftU64 (Imm7b, 13);
+ Code[2] = LShiftU64 (BitImm7b, 13);
Code[2] = Code[2] | LShiftU64 (0x00, 20); // vc
- Code[2] = Code[2] | LShiftU64 (Ic, 21);
- Code[2] = Code[2] | LShiftU64 (Imm5c, 22);
- Code[2] = Code[2] | LShiftU64 (Imm9d, 27);
- Code[2] = Code[2] | LShiftU64 (I, 36);
+ Code[2] = Code[2] | LShiftU64 (BitIc, 21);
+ Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);
+ Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);
+ Code[2] = Code[2] | LShiftU64 (BitI, 36);
Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);
Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);
@@ -501,23 +543,23 @@ EbcCreateThunks ( // Extract bits from the address for insertion into the instruction
// i = Addr[63:63]
//
- I = RShiftU64 (Addr, 63) & 0x01;
+ BitI = RShiftU64 (Addr, 63) & 0x01;
//
// ic = Addr[21:21]
//
- Ic = RShiftU64 (Addr, 21) & 0x01;
+ BitIc = RShiftU64 (Addr, 21) & 0x01;
//
// imm5c = Addr[20:16] for 5 bits
//
- Imm5c = RShiftU64 (Addr, 16) & 0x1F;
+ BitImm5c = RShiftU64 (Addr, 16) & 0x1F;
//
// imm9d = Addr[15:7] for 9 bits
//
- Imm9d = RShiftU64 (Addr, 7) & 0x1FF;
+ BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;
//
// imm7b = Addr[6:0] for 7 bits
//
- Imm7b = Addr & 0x7F;
+ BitImm7b = Addr & 0x7F;
//
// Put the EBC entry point in r8, which is the location of the return value
@@ -528,12 +570,12 @@ EbcCreateThunks ( //
// Next is jumbled data, including opcode and rest of address
//
- Code[2] = LShiftU64 (Imm7b, 13);
+ Code[2] = LShiftU64 (BitImm7b, 13);
Code[2] = Code[2] | LShiftU64 (0x00, 20); // vc
- Code[2] = Code[2] | LShiftU64 (Ic, 21);
- Code[2] = Code[2] | LShiftU64 (Imm5c, 22);
- Code[2] = Code[2] | LShiftU64 (Imm9d, 27);
- Code[2] = Code[2] | LShiftU64 (I, 36);
+ Code[2] = Code[2] | LShiftU64 (BitIc, 21);
+ Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);
+ Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);
+ Code[2] = Code[2] | LShiftU64 (BitI, 36);
Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);
Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);
@@ -573,23 +615,23 @@ EbcCreateThunks ( // Extract bits from the address for insertion into the instruction
// i = Addr[63:63]
//
- I = RShiftU64 (Addr, 63) & 0x01;
+ BitI = RShiftU64 (Addr, 63) & 0x01;
//
// ic = Addr[21:21]
//
- Ic = RShiftU64 (Addr, 21) & 0x01;
+ BitIc = RShiftU64 (Addr, 21) & 0x01;
//
// imm5c = Addr[20:16] for 5 bits
//
- Imm5c = RShiftU64 (Addr, 16) & 0x1F;
+ BitImm5c = RShiftU64 (Addr, 16) & 0x1F;
//
// imm9d = Addr[15:7] for 9 bits
//
- Imm9d = RShiftU64 (Addr, 7) & 0x1FF;
+ BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;
//
// imm7b = Addr[6:0] for 7 bits
//
- Imm7b = Addr & 0x7F;
+ BitImm7b = Addr & 0x7F;
//
// Put it in r31, a scratch register
@@ -599,12 +641,12 @@ EbcCreateThunks ( //
// Next is jumbled data, including opcode and rest of address
//
- Code[2] = LShiftU64(Imm7b, 13);
+ Code[2] = LShiftU64(BitImm7b, 13);
Code[2] = Code[2] | LShiftU64 (0x00, 20); // vc
- Code[2] = Code[2] | LShiftU64 (Ic, 21);
- Code[2] = Code[2] | LShiftU64 (Imm5c, 22);
- Code[2] = Code[2] | LShiftU64 (Imm9d, 27);
- Code[2] = Code[2] | LShiftU64 (I, 36);
+ Code[2] = Code[2] | LShiftU64 (BitIc, 21);
+ Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);
+ Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);
+ Code[2] = Code[2] | LShiftU64 (BitI, 36);
Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);
Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);
@@ -667,13 +709,16 @@ EbcCreateThunks ( Given raw bytes of Itanium based code, format them into a bundle and
write them out.
- @param MemPtr pointer to memory location to write the bundles to
- @param Template 5-bit template
- @param Slot0-2 instruction slot data for the bundle
+ @param MemPtr pointer to memory location to write the bundles
+ to.
+ @param Template 5-bit template.
+ @param Slot0 Instruction slot 0 data for the bundle.
+ @param Slot1 Instruction slot 1 data for the bundle.
+ @param Slot2 Instruction slot 2 data for the bundle.
@retval EFI_INVALID_PARAMETER Pointer is not aligned
- @retval No more than 5 bits in template
- @retval More than 41 bits used in code
+ @retval EFI_INVALID_PARAMETER No more than 5 bits in template
+ @retval EFI_INVALID_PARAMETER More than 41 bits used in code
@retval EFI_SUCCESS All data is written.
**/
@@ -745,13 +790,11 @@ WriteBundle ( otherwise, set the VM->IP to target EBC code directly to avoid another VM
be startup which cost time and stack space.
- @param VmPtr Pointer to a VM context.
- @param FuncAddr Callee's address
- @param NewStackPointer New stack pointer after the call
- @param FramePtr New frame pointer after the call
- @param Size The size of call instruction
-
- @return None.
+ @param VmPtr Pointer to a VM context.
+ @param FuncAddr Callee's address
+ @param NewStackPointer New stack pointer after the call
+ @param FramePtr New frame pointer after the call
+ @param Size The size of call instruction
**/
VOID
diff --git a/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.h b/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.h index 7b554f3..9d8de3e 100644 --- a/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.h +++ b/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.h @@ -38,10 +38,4 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. //
#define MOVL_OPCODE 0x06
-VOID
-EbcAsmLLCALLEX (
- IN UINTN CallAddr,
- IN UINTN EbcSp
- );
-
#endif
diff --git a/MdeModulePkg/Universal/EbcDxe/x64/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/x64/EbcSupport.c index 90db166..d72facd 100644 --- a/MdeModulePkg/Universal/EbcDxe/x64/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/x64/EbcSupport.c @@ -27,28 +27,20 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define STACK_REMAIN_SIZE (1024 * 4)
+
+/**
+ Pushes a 64 bit unsigned value to the VM stack.
+
+ @param VmPtr The pointer to current VM context.
+ @param Arg The value to be pushed.
+
+**/
STATIC
VOID
PushU64 (
- VM_CONTEXT *VmPtr,
- UINT64 Arg
+ IN VM_CONTEXT *VmPtr,
+ IN UINT64 Arg
)
-/*++
-
-Routine Description:
-
- Push a 64 bit unsigned value to the VM stack.
-
-Arguments:
-
- VmPtr - The pointer to current VM context.
- Arg - The value to be pushed
-
-Returns:
-
- VOID
-
---*/
{
//
// Advance the VM stack down, and then copy the argument to the stack.
@@ -69,28 +61,45 @@ Returns: calling convention, so the first four arguments are passed by rcx, rdx,
r8, and r9, while other arguments are passed in stack.
+ @param Arg1 The 1st argument.
+ @param Arg2 The 2nd argument.
+ @param Arg3 The 3rd argument.
+ @param Arg4 The 4th argument.
+ @param Arg5 The 5th argument.
+ @param Arg6 The 6th argument.
+ @param Arg7 The 7th argument.
+ @param Arg8 The 8th argument.
+ @param Arg9 The 9th argument.
+ @param Arg10 The 10th argument.
+ @param Arg11 The 11th argument.
+ @param Arg12 The 12th argument.
+ @param Arg13 The 13th argument.
+ @param Arg14 The 14th argument.
+ @param Arg15 The 15th argument.
+ @param Arg16 The 16th argument.
+
@return The value returned by the EBC application we're going to run.
**/
STATIC
UINT64
EbcInterpret (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4,
- UINTN Arg5,
- UINTN Arg6,
- UINTN Arg7,
- UINTN Arg8,
- UINTN Arg9,
- UINTN Arg10,
- UINTN Arg11,
- UINTN Arg12,
- UINTN Arg13,
- UINTN Arg14,
- UINTN Arg15,
- UINTN Arg16
+ IN OUT UINTN Arg1,
+ IN OUT UINTN Arg2,
+ IN OUT UINTN Arg3,
+ IN OUT UINTN Arg4,
+ IN OUT UINTN Arg5,
+ IN OUT UINTN Arg6,
+ IN OUT UINTN Arg7,
+ IN OUT UINTN Arg8,
+ IN OUT UINTN Arg9,
+ IN OUT UINTN Arg10,
+ IN OUT UINTN Arg11,
+ IN OUT UINTN Arg12,
+ IN OUT UINTN Arg13,
+ IN OUT UINTN Arg14,
+ IN OUT UINTN Arg15,
+ IN OUT UINTN Arg16
)
{
//
@@ -328,13 +337,20 @@ ExecuteEbcImageEntryPoint ( /**
- Create an IA32 thunk for the given EBC entry point.
+ Create thunks for an EBC image entry point, or an EBC protocol service.
- @param ImageHandle Handle of image for which this thunk is being created
- @param EbcEntryPoint Address of the EBC code that the thunk is to call
- @param Thunk Returned thunk we create here
+ @param ImageHandle Image handle for the EBC image. If not null, then
+ we're creating a thunk for an image entry point.
+ @param EbcEntryPoint Address of the EBC code that the thunk is to call
+ @param Thunk Returned thunk we create here
+ @param Flags Flags indicating options for creating the thunk
- @return Standard EFI status.
+ @retval EFI_SUCCESS The thunk was created successfully.
+ @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit
+ aligned.
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC
+ Thunk.
+ @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.
**/
EFI_STATUS
@@ -347,7 +363,7 @@ EbcCreateThunks ( {
UINT8 *Ptr;
UINT8 *ThunkBase;
- UINT32 I;
+ UINT32 Index;
UINT64 Addr;
INT32 Size;
INT32 ThunkSize;
@@ -390,7 +406,7 @@ EbcCreateThunks ( Ptr++;
Size--;
Addr = (UINT64) 0xCA112EBCCA112EBCULL;
- for (I = 0; I < sizeof (Addr); I++) {
+ for (Index = 0; Index < sizeof (Addr); Index++) {
*Ptr = (UINT8) (UINTN) Addr;
Addr >>= 8;
Ptr++;
@@ -410,7 +426,7 @@ EbcCreateThunks ( Ptr++;
Size--;
Addr = (UINT64) EbcEntryPoint;
- for (I = 0; I < sizeof (Addr); I++) {
+ for (Index = 0; Index < sizeof (Addr); Index++) {
*Ptr = (UINT8) (UINTN) Addr;
Addr >>= 8;
Ptr++;
@@ -438,7 +454,7 @@ EbcCreateThunks ( *Ptr = 0xBB;
Ptr++;
Size--;
- for (I = 0; I < sizeof (Addr); I++) {
+ for (Index = 0; Index < sizeof (Addr); Index++) {
*Ptr = (UINT8) Addr;
Addr >>= 8;
Ptr++;
@@ -487,8 +503,6 @@ EbcCreateThunks ( @param FramePtr New frame pointer after the call
@param Size The size of call instruction
- @return None.
-
**/
VOID
EbcLLCALLEX (
|