TianoCore EDK2 master
Loading...
Searching...
No Matches
CcInstruction.c File Reference
#include <Base.h>
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Register/Intel/Cpuid.h>
#include <IndustryStandard/InstructionParsing.h>
#include "CcInstruction.h"

Go to the source code of this file.

Macros

#define MAX_INSTRUCTION_LENGTH   15
 

Functions

UINT64 * CcGetRegisterPointer (IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN UINT8 Register)
 
STATIC VOID UpdateForDisplacement (IN OUT CC_INSTRUCTION_DATA *InstructionData, IN UINTN Size)
 
STATIC BOOLEAN IsRipRelative (IN CC_INSTRUCTION_DATA *InstructionData)
 
STATIC UINT64 GetEffectiveMemoryAddress (IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN CC_INSTRUCTION_DATA *InstructionData)
 
VOID CcDecodeModRm (IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN OUT CC_INSTRUCTION_DATA *InstructionData)
 
STATIC EFI_STATUS DecodePrefixes (IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN OUT CC_INSTRUCTION_DATA *InstructionData)
 
UINT64 CcInstructionLength (IN CC_INSTRUCTION_DATA *InstructionData)
 
EFI_STATUS CcInitInstructionData (IN OUT CC_INSTRUCTION_DATA *InstructionData, IN GHCB *Ghcb, IN EFI_SYSTEM_CONTEXT_X64 *Regs)
 

Detailed Description

X64 Instruction function.

Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CcInstruction.c.

Macro Definition Documentation

◆ MAX_INSTRUCTION_LENGTH

#define MAX_INSTRUCTION_LENGTH   15

Definition at line 16 of file CcInstruction.c.

Function Documentation

◆ CcDecodeModRm()

VOID CcDecodeModRm ( IN EFI_SYSTEM_CONTEXT_X64 Regs,
IN OUT CC_INSTRUCTION_DATA InstructionData 
)

Decode a ModRM byte.

Examine the instruction parsing context to decode a ModRM byte and the SIB byte, if present.

Parameters
[in]Regsx64 processor context
[in,out]InstructionDataInstruction parsing context

Definition at line 245 of file CcInstruction.c.

◆ CcGetRegisterPointer()

UINT64 * CcGetRegisterPointer ( IN EFI_SYSTEM_CONTEXT_X64 Regs,
IN UINT8  Register 
)

Return a pointer to the contents of the specified register.

Based upon the input register, return a pointer to the registers contents in the x86 processor context.

Parameters
[in]Regsx64 processor context
[in]RegisterRegister to obtain pointer for
Returns
Pointer to the contents of the requested register

Definition at line 31 of file CcInstruction.c.

◆ CcInitInstructionData()

EFI_STATUS CcInitInstructionData ( IN OUT CC_INSTRUCTION_DATA InstructionData,
IN GHCB *  Ghcb,
IN EFI_SYSTEM_CONTEXT_X64 Regs 
)

Initialize the instruction parsing context.

Initialize the instruction parsing context, which includes decoding the instruction prefixes.

Parameters
[in,out]InstructionDataInstruction parsing context
[in]GhcbPointer to the Guest-Hypervisor Communication Block
[in]Regsx64 processor context
Return values
EFI_SUCCESSSuccessfully initialize InstructionData
OthersOther error as indicated

Definition at line 442 of file CcInstruction.c.

◆ CcInstructionLength()

UINT64 CcInstructionLength ( IN CC_INSTRUCTION_DATA InstructionData)

Determine instruction length

Return the total length of the parsed instruction.

Parameters
[in]InstructionDataInstruction parsing context
Returns
Length of parsed instruction

Definition at line 420 of file CcInstruction.c.

◆ DecodePrefixes()

STATIC EFI_STATUS DecodePrefixes ( IN EFI_SYSTEM_CONTEXT_X64 Regs,
IN OUT CC_INSTRUCTION_DATA InstructionData 
)

Decode instruction prefixes.

Parse the instruction data to track the instruction prefixes that have been used.

Parameters
[in]Regsx64 processor context
[in,out]InstructionDataInstruction parsing context
Return values
EFI_SUCCESSSuccessfully decode Prefixes
OthersOther error as indicated

Definition at line 307 of file CcInstruction.c.

◆ GetEffectiveMemoryAddress()

STATIC UINT64 GetEffectiveMemoryAddress ( IN EFI_SYSTEM_CONTEXT_X64 Regs,
IN CC_INSTRUCTION_DATA InstructionData 
)

Return the effective address of a memory operand.

Examine the instruction parsing context to obtain the effective memory address of a memory operand.

Parameters
[in]Regsx64 processor context
[in]InstructionDataInstruction parsing context
Returns
The memory operand effective address

Definition at line 157 of file CcInstruction.c.

◆ IsRipRelative()

STATIC BOOLEAN IsRipRelative ( IN CC_INSTRUCTION_DATA InstructionData)

Determine if an instruction address if RIP relative.

Examine the instruction parsing context to determine if the address offset is relative to the instruction pointer.

Parameters
[in]InstructionDataInstruction parsing context
Return values
TRUEInstruction addressing is RIP relative
FALSEInstruction addressing is not RIP relative

Definition at line 129 of file CcInstruction.c.

◆ UpdateForDisplacement()

STATIC VOID UpdateForDisplacement ( IN OUT CC_INSTRUCTION_DATA InstructionData,
IN UINTN  Size 
)

Update the instruction parsing context for displacement bytes.

Parameters
[in,out]InstructionDataInstruction parsing context
[in]SizeThe instruction displacement size

Definition at line 105 of file CcInstruction.c.