3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
11 extern EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable
[];
14 CHAR16 Name
[EDB_INSTRUCTION_NAME_MAX_LENGTH
];
15 CHAR16 Content
[EDB_INSTRUCTION_CONTENT_MAX_LENGTH
];
17 } EDB_INSTRUCTION_STRING
;
19 EDB_INSTRUCTION_STRING mInstructionString
;
20 UINTN mInstructionNameOffset
;
21 UINTN mInstructionContentOffset
;
25 Set offset for Instruction name and content.
27 @param InstructionNameOffset - Instruction name offset
28 @param InstructionContentOffset - Instruction content offset
33 IN UINTN InstructionNameOffset
,
34 IN UINTN InstructionContentOffset
37 mInstructionNameOffset
= InstructionNameOffset
;
38 mInstructionContentOffset
= InstructionContentOffset
;
45 Pre instruction string construction.
47 @return Instruction string
51 EdbPreInstructionString (
55 ZeroMem (&mInstructionString
, sizeof(mInstructionString
));
56 mInstructionNameOffset
= 0;
57 mInstructionContentOffset
= 0;
59 return (CHAR16
*)&mInstructionString
;
64 Post instruction string construction.
66 @return Instruction string
70 EdbPostInstructionString (
76 for (Char
= (CHAR16
*)&mInstructionString
; Char
< &mInstructionString
.Tail
; Char
++) {
81 mInstructionString
.Tail
= 0;
83 mInstructionNameOffset
= 0;
84 mInstructionContentOffset
= 0;
86 return (CHAR16
*)&mInstructionString
;
91 Get Sign, NaturalUnits, and ConstantUnits of the WORD data.
93 @param Data16 - WORD data
94 @param NaturalUnits - Natural Units of the WORD
95 @param ConstantUnits - Constant Units of the WORD
97 @return Sign value of WORD
101 EdbGetNaturalIndex16 (
103 OUT UINTN
*NaturalUnits
,
104 OUT UINTN
*ConstantUnits
108 UINTN NaturalUnitBit
;
110 Sign
= (BOOLEAN
)(Data16
>> 15);
111 NaturalUnitBit
= (UINTN
)((Data16
>> 12) & 0x7);
113 Data16
= Data16
& 0xFFF;
114 *NaturalUnits
= (UINTN
)(Data16
& ((1 << NaturalUnitBit
) - 1));
115 *ConstantUnits
= (UINTN
)((Data16
>> NaturalUnitBit
) & ((1 << (12 - NaturalUnitBit
)) - 1));
122 Get Sign, NaturalUnits, and ConstantUnits of the DWORD data.
124 @param Data32 - DWORD data
125 @param NaturalUnits - Natural Units of the DWORD
126 @param ConstantUnits - Constant Units of the DWORD
128 @return Sign value of DWORD
132 EdbGetNaturalIndex32 (
134 OUT UINTN
*NaturalUnits
,
135 OUT UINTN
*ConstantUnits
139 UINTN NaturalUnitBit
;
141 Sign
= (BOOLEAN
)(Data32
>> 31);
142 NaturalUnitBit
= (UINTN
)((Data32
>> 28) & 0x7);
144 Data32
= Data32
& 0xFFFFFFF;
145 *NaturalUnits
= (UINTN
)(Data32
& ((1 << NaturalUnitBit
) - 1));
146 *ConstantUnits
= (UINTN
)((Data32
>> NaturalUnitBit
) & ((1 << (28 - NaturalUnitBit
)) - 1));
153 Get Sign, NaturalUnits, and ConstantUnits of the QWORD data.
155 @param Data64 - QWORD data
156 @param NaturalUnits - Natural Units of the QWORD
157 @param ConstantUnits - Constant Units of the QWORD
159 @return Sign value of QWORD
163 EdbGetNaturalIndex64 (
165 OUT UINT64
*NaturalUnits
,
166 OUT UINT64
*ConstantUnits
170 UINTN NaturalUnitBit
;
172 Sign
= (BOOLEAN
)RShiftU64 (Data64
, 63);
173 NaturalUnitBit
= (UINTN
)(RShiftU64 (Data64
, 60) & 0x7);
175 Data64
= RShiftU64 (LShiftU64 (Data64
, 4), 4);
176 *NaturalUnits
= (UINT64
)(Data64
& (LShiftU64 (1, NaturalUnitBit
) - 1));
177 *ConstantUnits
= (UINT64
)(RShiftU64 (Data64
, NaturalUnitBit
) & (LShiftU64 (1, (60 - NaturalUnitBit
)) - 1));
184 Get Bit Width of the value.
196 if (Value
>= 10000000000000) {
198 } else if (Value
>= 1000000000000) {
200 } else if (Value
>= 100000000000) {
202 } else if (Value
>= 10000000000) {
204 } else if (Value
>= 1000000000) {
206 } else if (Value
>= 100000000) {
208 } else if (Value
>= 10000000) {
210 } else if (Value
>= 1000000) {
212 } else if (Value
>= 100000) {
214 } else if (Value
>= 10000) {
216 } else if (Value
>= 1000) {
218 } else if (Value
>= 100) {
220 } else if (Value
>= 10) {
229 Print the instruction name.
231 @param Name - instruction name
233 @return Instruction name offset
237 EdbPrintInstructionName (
241 EDBSPrintWithOffset (
242 mInstructionString
.Name
,
243 EDB_INSTRUCTION_NAME_MAX_SIZE
,
244 mInstructionNameOffset
,
248 mInstructionNameOffset
+= StrLen (Name
);
250 return mInstructionNameOffset
;
255 Print register 1 in operands.
257 @param Operands - instruction operands
259 @return Instruction content offset
267 if ((Operands
& OPERAND_M_INDIRECT1
) != 0) {
268 EDBSPrintWithOffset (
269 mInstructionString
.Content
,
270 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
271 mInstructionContentOffset
,
274 mInstructionContentOffset
+= 1;
276 EDBSPrintWithOffset (
277 mInstructionString
.Content
,
278 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
279 mInstructionContentOffset
,
281 (UINTN
)(Operands
& OPERAND_M_OP1
)
283 mInstructionContentOffset
+= 2;
285 return mInstructionContentOffset
;
290 Print register 2 in operands.
292 @param Operands - instruction operands
294 @return Instruction content offset
302 if ((Operands
& OPERAND_M_INDIRECT2
) != 0) {
303 EDBSPrintWithOffset (
304 mInstructionString
.Content
,
305 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
306 mInstructionContentOffset
,
309 mInstructionContentOffset
+= 1;
311 EDBSPrintWithOffset (
312 mInstructionString
.Content
,
313 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
314 mInstructionContentOffset
,
316 (UINTN
)((Operands
& OPERAND_M_OP2
) >> 4)
318 mInstructionContentOffset
+= 2;
320 return mInstructionContentOffset
;
325 Print dedicated register 1 in operands.
327 @param Operands - instruction operands
329 @return Instruction content offset
333 EdbPrintDedicatedRegister1 (
337 switch (Operands
& OPERAND_M_OP1
) {
339 EDBSPrintWithOffset (
340 mInstructionString
.Content
,
341 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
342 mInstructionContentOffset
,
345 mInstructionContentOffset
+= 7;
348 EDBSPrintWithOffset (
349 mInstructionString
.Content
,
350 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
351 mInstructionContentOffset
,
354 mInstructionContentOffset
+= 4;
358 return mInstructionContentOffset
;
363 Print dedicated register 2 in operands.
365 @param Operands - instruction operands
367 @return Instruction content offset
371 EdbPrintDedicatedRegister2 (
375 switch ((Operands
& OPERAND_M_OP2
) >> 4) {
377 EDBSPrintWithOffset (
378 mInstructionString
.Content
,
379 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
380 mInstructionContentOffset
,
383 mInstructionContentOffset
+= 7;
386 EDBSPrintWithOffset (
387 mInstructionString
.Content
,
388 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
389 mInstructionContentOffset
,
392 mInstructionContentOffset
+= 4;
396 return mInstructionContentOffset
;
401 Print the hexical UINTN index data to instruction content.
403 @param Sign - Signed bit of UINTN data
404 @param NaturalUnits - natural units of UINTN data
405 @param ConstantUnits - natural units of UINTN data
407 @return Instruction content offset
413 IN UINTN NaturalUnits
,
414 IN UINTN ConstantUnits
417 EDBSPrintWithOffset (
418 mInstructionString
.Content
,
419 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
420 mInstructionContentOffset
,
427 mInstructionContentOffset
= mInstructionContentOffset
+ 5 + EdbGetBitWidth (NaturalUnits
) + EdbGetBitWidth (ConstantUnits
);
429 return mInstructionContentOffset
;
434 Print the hexical QWORD index data to instruction content.
436 @param Sign - Signed bit of QWORD data
437 @param NaturalUnits - natural units of QWORD data
438 @param ConstantUnits - natural units of QWORD data
440 @return Instruction content offset
444 EdbPrintIndexData64 (
446 IN UINT64 NaturalUnits
,
447 IN UINT64 ConstantUnits
450 EDBSPrintWithOffset (
451 mInstructionString
.Content
,
452 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
453 mInstructionContentOffset
,
460 mInstructionContentOffset
= mInstructionContentOffset
+ 5 + EdbGetBitWidth (NaturalUnits
) + EdbGetBitWidth (ConstantUnits
);
462 return mInstructionContentOffset
;
467 Print the hexical WORD raw index data to instruction content.
469 @param Data16 - WORD data
471 @return Instruction content offset
475 EdbPrintRawIndexData16 (
484 Sign
= EdbGetNaturalIndex16 (Data16
, &NaturalUnits
, &ConstantUnits
);
485 Offset
= EdbPrintIndexData (Sign
, NaturalUnits
, ConstantUnits
);
492 Print the hexical DWORD raw index data to instruction content.
494 @param Data32 - DWORD data
496 @return Instruction content offset
500 EdbPrintRawIndexData32 (
509 Sign
= EdbGetNaturalIndex32 (Data32
, &NaturalUnits
, &ConstantUnits
);
510 Offset
= EdbPrintIndexData (Sign
, NaturalUnits
, ConstantUnits
);
517 Print the hexical QWORD raw index data to instruction content.
519 @param Data64 - QWORD data
521 @return Instruction content offset
525 EdbPrintRawIndexData64 (
531 UINT64 ConstantUnits
;
534 Sign
= EdbGetNaturalIndex64 (Data64
, &NaturalUnits
, &ConstantUnits
);
535 Offset
= EdbPrintIndexData64 (Sign
, NaturalUnits
, ConstantUnits
);
542 Print the hexical BYTE immediate data to instruction content.
544 @param Data - BYTE data
546 @return Instruction content offset
554 EDBSPrintWithOffset (
555 mInstructionString
.Content
,
556 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
557 mInstructionContentOffset
,
561 mInstructionContentOffset
+= 6;
563 return mInstructionContentOffset
;
568 Print the hexical WORD immediate data to instruction content.
570 @param Data - WORD data
572 @return Instruction content offset
580 EDBSPrintWithOffset (
581 mInstructionString
.Content
,
582 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
583 mInstructionContentOffset
,
587 mInstructionContentOffset
+= 8;
589 return mInstructionContentOffset
;
594 Print the hexical DWORD immediate data to instruction content.
596 @param Data - DWORD data
598 @return Instruction content offset
606 EDBSPrintWithOffset (
607 mInstructionString
.Content
,
608 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
609 mInstructionContentOffset
,
613 mInstructionContentOffset
+= 12;
615 return mInstructionContentOffset
;
620 Print the hexical QWORD immediate data to instruction content.
622 @param Data - QWORD data
624 @return Instruction content offset
632 EDBSPrintWithOffset (
633 mInstructionString
.Content
,
634 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
635 mInstructionContentOffset
,
639 mInstructionContentOffset
+= 20;
641 return mInstructionContentOffset
;
646 Print the decimal UINTN immediate data to instruction content.
648 @param Data - UINTN data
650 @return Instruction content offset
658 EDBSPrintWithOffset (
659 mInstructionString
.Content
,
660 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
661 mInstructionContentOffset
,
665 mInstructionContentOffset
= mInstructionContentOffset
+ 2 + EdbGetBitWidth (Data
);
667 return mInstructionContentOffset
;
672 Print the decimal QWORD immediate data to instruction content.
674 @param Data64 - QWORD data
676 @return Instruction content offset
684 EDBSPrintWithOffset (
685 mInstructionString
.Content
,
686 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
687 mInstructionContentOffset
,
691 mInstructionContentOffset
= mInstructionContentOffset
+ 2 + EdbGetBitWidth (Data64
);
693 return mInstructionContentOffset
;
698 Print the hexical BYTE to instruction content.
700 @param Data8 - BYTE data
702 @return Instruction content offset
710 EDBSPrintWithOffset (
711 mInstructionString
.Content
,
712 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
713 mInstructionContentOffset
,
717 mInstructionContentOffset
+= 4;
719 return mInstructionContentOffset
;
724 Print the hexical WORD to instruction content.
726 @param Data16 - WORD data
728 @return Instruction content offset
736 EDBSPrintWithOffset (
737 mInstructionString
.Content
,
738 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
739 mInstructionContentOffset
,
743 mInstructionContentOffset
+= 6;
745 return mInstructionContentOffset
;
750 Print the hexical DWORD to instruction content.
752 @param Data32 - DWORD data
754 @return Instruction content offset
762 EDBSPrintWithOffset (
763 mInstructionString
.Content
,
764 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
765 mInstructionContentOffset
,
769 mInstructionContentOffset
+= 10;
771 return mInstructionContentOffset
;
776 Print the hexical QWORD to instruction content.
778 @param Data64 - QWORD data
780 @return Instruction content offset
788 EDBSPrintWithOffset (
789 mInstructionString
.Content
,
790 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
791 mInstructionContentOffset
,
795 mInstructionContentOffset
+= 18;
797 return mInstructionContentOffset
;
802 Print the decimal unsigned UINTN to instruction content.
804 @param Data - unsigned UINTN data
806 @return Instruction content offset
814 EDBSPrintWithOffset (
815 mInstructionString
.Content
,
816 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
817 mInstructionContentOffset
,
821 mInstructionContentOffset
= mInstructionContentOffset
+ EdbGetBitWidth (Data
);
823 return mInstructionContentOffset
;
828 Print the decimal unsigned QWORD to instruction content.
830 @param Data64 - unsigned QWORD data
832 @return Instruction content offset
840 EDBSPrintWithOffset (
841 mInstructionString
.Content
,
842 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
843 mInstructionContentOffset
,
847 mInstructionContentOffset
= mInstructionContentOffset
+ EdbGetBitWidth (Data64
);
849 return mInstructionContentOffset
;
854 Print the decimal signed BYTE to instruction content.
856 @param Data8 - signed BYTE data
858 @return Instruction content offset
868 Sign
= (BOOLEAN
)(Data8
>> 7);
870 EDBSPrintWithOffset (
871 mInstructionString
.Content
,
872 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
873 mInstructionContentOffset
,
876 (UINTN
)(Data8
& 0x7F)
878 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data8
& 0x7F);
880 return mInstructionContentOffset
;
885 Print the decimal signed WORD to instruction content.
887 @param Data16 - signed WORD data
889 @return Instruction content offset
899 Sign
= (BOOLEAN
)(Data16
>> 15);
901 EDBSPrintWithOffset (
902 mInstructionString
.Content
,
903 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
904 mInstructionContentOffset
,
907 (UINTN
)(Data16
& 0x7FFF)
909 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data16
& 0x7FFF);
911 return mInstructionContentOffset
;
916 Print the decimal signed DWORD to instruction content.
918 @param Data32 - signed DWORD data
920 @return Instruction content offset
930 Sign
= (BOOLEAN
)(Data32
>> 31);
932 EDBSPrintWithOffset (
933 mInstructionString
.Content
,
934 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
935 mInstructionContentOffset
,
938 (UINTN
)(Data32
& 0x7FFFFFFF)
940 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data32
& 0x7FFFFFFF);
942 return mInstructionContentOffset
;
947 Print the decimal signed QWORD to instruction content.
949 @param Data64 - signed QWORD data
951 @return Instruction content offset
962 Sign
= (BOOLEAN
)RShiftU64 (Data64
, 63);
963 Data64s
= (INT64
)RShiftU64 (LShiftU64 (Data64
, 1), 1);
965 EDBSPrintWithOffset (
966 mInstructionString
.Content
,
967 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
968 mInstructionContentOffset
,
973 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data64s
);
975 return mInstructionContentOffset
;
980 Print the comma to instruction content.
982 @return Instruction content offset
990 EDBSPrintWithOffset (
991 mInstructionString
.Content
,
992 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
993 mInstructionContentOffset
,
996 mInstructionContentOffset
+= 2;
998 return mInstructionContentOffset
;
1003 Find the symbol string according to address, then print it.
1005 @param Address - instruction address
1007 @retval 1 - symbol string is found and printed
1008 @retval 0 - symbol string not found
1012 EdbFindAndPrintSymbol (
1018 SymbolStr
= FindSymbolStr (Address
);
1019 if (SymbolStr
!= NULL
) {
1020 EDBSPrintWithOffset (
1021 mInstructionString
.Content
,
1022 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1023 mInstructionContentOffset
,
1035 Print the EBC byte code.
1037 @param InstructionAddress - instruction address
1038 @param InstructionNumber - instruction number
1043 IN EFI_PHYSICAL_ADDRESS InstructionAddress
,
1044 IN UINTN InstructionNumber
1053 if (InstructionNumber
== 0) {
1057 LineNumber
= InstructionNumber
/ EDB_BYTECODE_NUMBER_IN_LINE
;
1058 ByteNumber
= InstructionNumber
% EDB_BYTECODE_NUMBER_IN_LINE
;
1059 if (ByteNumber
== 0) {
1061 ByteNumber
= EDB_BYTECODE_NUMBER_IN_LINE
;
1067 SymbolStr
= FindSymbolStr ((UINTN
)InstructionAddress
);
1068 if (SymbolStr
!= NULL
) {
1069 EDBPrint (L
"[%a]:\n", SymbolStr
);
1072 for (LineIndex
= 0; LineIndex
< LineNumber
; LineIndex
++) {
1073 EDBPrint (EDB_PRINT_ADDRESS_FORMAT
, (UINTN
)InstructionAddress
);
1074 for (ByteIndex
= 0; ByteIndex
< EDB_BYTECODE_NUMBER_IN_LINE
; ByteIndex
++) {
1075 EDBPrint (L
"%02x ", *(UINT8
*)(UINTN
)InstructionAddress
);
1076 InstructionAddress
+= 1;
1081 EDBPrint (EDB_PRINT_ADDRESS_FORMAT
, (UINTN
)InstructionAddress
);
1082 for (ByteIndex
= 0; ByteIndex
< ByteNumber
; ByteIndex
++) {
1083 EDBPrint (L
"%02x ", *(UINT8
*)(UINTN
)InstructionAddress
);
1084 InstructionAddress
+= 1;
1086 for (ByteIndex
= 0; ByteIndex
< EDB_BYTECODE_NUMBER_IN_LINE
- ByteNumber
; ByteIndex
++) {
1095 Print the EBC asm code.
1097 @param DebuggerPrivate - EBC Debugger private data structure
1098 @param SystemContext - EBC system context.
1100 @retval EFI_SUCCESS - show disasm successfully
1105 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
1106 IN EFI_SYSTEM_CONTEXT SystemContext
1109 EFI_PHYSICAL_ADDRESS InstructionAddress
;
1110 UINTN InstructionNumber
;
1111 UINTN InstructionLength
;
1113 CHAR16
*InstructionString
;
1116 InstructionAddress
= DebuggerPrivate
->InstructionScope
;
1117 for (InstructionNumber
= 0; InstructionNumber
< DebuggerPrivate
->InstructionNumber
; InstructionNumber
++) {
1120 // Break each 0x10 instruction
1122 if (((InstructionNumber
% EFI_DEBUGGER_LINE_NUMBER_IN_PAGE
) == 0) &&
1123 (InstructionNumber
!= 0)) {
1124 if (SetPageBreak ()) {
1129 Opcode
= GET_OPCODE(InstructionAddress
);
1130 if ((Opcode
< OPCODE_MAX
) && (mEdbDisasmInstructionTable
[Opcode
] != NULL
)) {
1131 InstructionLength
= mEdbDisasmInstructionTable
[Opcode
] (InstructionAddress
, SystemContext
, &InstructionString
);
1132 if (InstructionLength
!= 0) {
1137 // Result = EdbPrintSource ((UINTN)InstructionAddress, FALSE);
1139 if (!DebuggerPrivate
->DebuggerSymbolContext
.DisplayCodeOnly
) {
1141 EdbPrintRaw (InstructionAddress
, InstructionLength
);
1142 if (InstructionString
!= NULL
) {
1143 EDBPrint (L
"%s\n", InstructionString
);
1145 EDBPrint (L
"%s\n", L
"<Unknown Instruction>");
1149 EdbPrintSource ((UINTN
)InstructionAddress
, TRUE
);
1151 InstructionAddress
+= InstructionLength
;
1154 // Something wrong with OPCODE
1156 EdbPrintRaw (InstructionAddress
, EDB_BYTECODE_NUMBER_IN_LINE
);
1157 EDBPrint (L
"%s\n", L
"<Bad Instruction>");
1162 // Something wrong with OPCODE
1164 EdbPrintRaw (InstructionAddress
, EDB_BYTECODE_NUMBER_IN_LINE
);
1165 EDBPrint (L
"%s\n", L
"<Bad Instruction>");
1175 Get register value according to the system context, and register index.
1177 @param SystemContext - EBC system context.
1178 @param Index - EBC register index
1180 @return register value
1185 IN EFI_SYSTEM_CONTEXT SystemContext
,
1191 return SystemContext
.SystemContextEbc
->R0
;
1193 return SystemContext
.SystemContextEbc
->R1
;
1195 return SystemContext
.SystemContextEbc
->R2
;
1197 return SystemContext
.SystemContextEbc
->R3
;
1199 return SystemContext
.SystemContextEbc
->R4
;
1201 return SystemContext
.SystemContextEbc
->R5
;
1203 return SystemContext
.SystemContextEbc
->R6
;
1205 return SystemContext
.SystemContextEbc
->R7
;