TianoCore EDK2 master
Loading...
Searching...
No Matches
X86PatchInstruction.c
Go to the documentation of this file.
1
10#include "BaseLibInternals.h"
11
46VOID
47EFIAPI
49 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,
50 IN UINT64 PatchValue,
51 IN UINTN ValueSize
52 )
53{
54 //
55 // The equality ((UINTN)InstructionEnd == ValueSize) would assume a zero-size
56 // instruction at address 0; forbid it.
57 //
58 ASSERT ((UINTN)InstructionEnd > ValueSize);
59
60 switch (ValueSize) {
61 case 1:
62 ASSERT (PatchValue <= MAX_UINT8);
63 *((UINT8 *)(UINTN)InstructionEnd - 1) = (UINT8)PatchValue;
64 break;
65
66 case 2:
67 ASSERT (PatchValue <= MAX_UINT16);
68 WriteUnaligned16 ((UINT16 *)(UINTN)InstructionEnd - 1, (UINT16)PatchValue);
69 break;
70
71 case 4:
72 ASSERT (PatchValue <= MAX_UINT32);
73 WriteUnaligned32 ((UINT32 *)(UINTN)InstructionEnd - 1, (UINT32)PatchValue);
74 break;
75
76 case 8:
77 WriteUnaligned64 ((UINT64 *)(UINTN)InstructionEnd - 1, PatchValue);
78 break;
79
80 default:
81 ASSERT (FALSE);
82 }
83}
UINT64 UINTN
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:177
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
Definition: Unaligned.c:61
UINT64 EFIAPI WriteUnaligned64(OUT UINT64 *Buffer, IN UINT64 Value)
Definition: Unaligned.c:236
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID EFIAPI PatchInstructionX86(OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd, IN UINT64 PatchValue, IN UINTN ValueSize)