3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 extern EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable
[];
26 CHAR16 Name
[EDB_INSTRUCTION_NAME_MAX_LENGTH
];
27 CHAR16 Content
[EDB_INSTRUCTION_CONTENT_MAX_LENGTH
];
29 } EDB_INSTRUCTION_STRING
;
31 EDB_INSTRUCTION_STRING mInstructionString
;
32 UINTN mInstructionNameOffset
;
33 UINTN mInstructionContentOffset
;
37 IN UINTN InstructionNameOffset
,
38 IN UINTN InstructionContentOffset
44 Set offset for Instruction name and content
48 InstructionNameOffset - Instruction name offset
49 InstructionContentOffset - Instruction content offset
57 mInstructionNameOffset
= InstructionNameOffset
;
58 mInstructionContentOffset
= InstructionContentOffset
;
64 EdbPreInstructionString (
71 Pre instruction string construction
83 ZeroMem (&mInstructionString
, sizeof(mInstructionString
));
84 mInstructionNameOffset
= 0;
85 mInstructionContentOffset
= 0;
87 return (CHAR16
*)&mInstructionString
;
91 EdbPostInstructionString (
98 Post instruction string construction
112 for (Char
= (CHAR16
*)&mInstructionString
; Char
< &mInstructionString
.Tail
; Char
++) {
117 mInstructionString
.Tail
= 0;
119 mInstructionNameOffset
= 0;
120 mInstructionContentOffset
= 0;
122 return (CHAR16
*)&mInstructionString
;
126 EdbGetNaturalIndex16 (
128 OUT UINTN
*NaturalUnits
,
129 OUT UINTN
*ConstantUnits
135 Get Sign, NaturalUnits, and ConstantUnits of the WORD data
140 NaturalUnits - Natural Units of the WORD
141 ConstantUnits - Constant Units of the WORD
150 UINTN NaturalUnitBit
;
152 Sign
= (BOOLEAN
)(Data16
>> 15);
153 NaturalUnitBit
= (UINTN
)((Data16
>> 12) & 0x7);
155 Data16
= Data16
& 0xFFF;
156 *NaturalUnits
= (UINTN
)(Data16
& ((1 << NaturalUnitBit
) - 1));
157 *ConstantUnits
= (UINTN
)((Data16
>> NaturalUnitBit
) & ((1 << (12 - NaturalUnitBit
)) - 1));
163 EdbGetNaturalIndex32 (
165 OUT UINTN
*NaturalUnits
,
166 OUT UINTN
*ConstantUnits
172 Get Sign, NaturalUnits, and ConstantUnits of the DWORD data
177 NaturalUnits - Natural Units of the DWORD
178 ConstantUnits - Constant Units of the DWORD
187 UINTN NaturalUnitBit
;
189 Sign
= (BOOLEAN
)(Data32
>> 31);
190 NaturalUnitBit
= (UINTN
)((Data32
>> 28) & 0x7);
192 Data32
= Data32
& 0xFFFFFFF;
193 *NaturalUnits
= (UINTN
)(Data32
& ((1 << NaturalUnitBit
) - 1));
194 *ConstantUnits
= (UINTN
)((Data32
>> NaturalUnitBit
) & ((1 << (28 - NaturalUnitBit
)) - 1));
200 EdbGetNaturalIndex64 (
202 OUT UINT64
*NaturalUnits
,
203 OUT UINT64
*ConstantUnits
209 Get Sign, NaturalUnits, and ConstantUnits of the QWORD data
214 NaturalUnits - Natural Units of the QWORD
215 ConstantUnits - Constant Units of the QWORD
224 UINTN NaturalUnitBit
;
226 Sign
= (BOOLEAN
)RShiftU64 (Data64
, 63);
227 NaturalUnitBit
= (UINTN
)(RShiftU64 (Data64
, 60) & 0x7);
229 Data64
= RShiftU64 (LShiftU64 (Data64
, 4), 4);
230 *NaturalUnits
= (UINT64
)(Data64
& (LShiftU64 (1, NaturalUnitBit
) - 1));
231 *ConstantUnits
= (UINT64
)(RShiftU64 (Data64
, NaturalUnitBit
) & (LShiftU64 (1, (60 - NaturalUnitBit
)) - 1));
244 Get Bit Width of the value
256 if (Value
>= 10000000000000) {
258 } else if (Value
>= 1000000000000) {
260 } else if (Value
>= 100000000000) {
262 } else if (Value
>= 10000000000) {
264 } else if (Value
>= 1000000000) {
266 } else if (Value
>= 100000000) {
268 } else if (Value
>= 10000000) {
270 } else if (Value
>= 1000000) {
272 } else if (Value
>= 100000) {
274 } else if (Value
>= 10000) {
276 } else if (Value
>= 1000) {
278 } else if (Value
>= 100) {
280 } else if (Value
>= 10) {
288 EdbPrintInstructionName (
295 Print the instruction name
299 Name - instruction name
303 Instruction name offset
307 EDBSPrintWithOffset (
308 mInstructionString
.Name
,
309 EDB_INSTRUCTION_NAME_MAX_SIZE
,
310 mInstructionNameOffset
,
314 mInstructionNameOffset
+= StrLen (Name
);
316 return mInstructionNameOffset
;
327 Print register 1 in operands
331 Operands - instruction operands
335 Instruction content offset
339 if (Operands
& OPERAND_M_INDIRECT1
) {
340 EDBSPrintWithOffset (
341 mInstructionString
.Content
,
342 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
343 mInstructionContentOffset
,
346 mInstructionContentOffset
+= 1;
348 EDBSPrintWithOffset (
349 mInstructionString
.Content
,
350 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
351 mInstructionContentOffset
,
353 (UINTN
)(Operands
& OPERAND_M_OP1
)
355 mInstructionContentOffset
+= 2;
357 return mInstructionContentOffset
;
368 Print register 2 in operands
372 Operands - instruction operands
376 Instruction content offset
380 if (Operands
& OPERAND_M_INDIRECT2
) {
381 EDBSPrintWithOffset (
382 mInstructionString
.Content
,
383 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
384 mInstructionContentOffset
,
387 mInstructionContentOffset
+= 1;
389 EDBSPrintWithOffset (
390 mInstructionString
.Content
,
391 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
392 mInstructionContentOffset
,
394 (UINTN
)((Operands
& OPERAND_M_OP2
) >> 4)
396 mInstructionContentOffset
+= 2;
398 return mInstructionContentOffset
;
402 EdbPrintDedicatedRegister1 (
409 Print dedicated register 1 in operands
413 Operands - instruction operands
417 Instruction content offset
421 switch (Operands
& OPERAND_M_OP1
) {
423 EDBSPrintWithOffset (
424 mInstructionString
.Content
,
425 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
426 mInstructionContentOffset
,
429 mInstructionContentOffset
+= 7;
432 EDBSPrintWithOffset (
433 mInstructionString
.Content
,
434 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
435 mInstructionContentOffset
,
438 mInstructionContentOffset
+= 4;
442 return mInstructionContentOffset
;
446 EdbPrintDedicatedRegister2 (
453 Print dedicated register 2 in operands
457 Operands - instruction operands
461 Instruction content offset
465 switch ((Operands
& OPERAND_M_OP2
) >> 4) {
467 EDBSPrintWithOffset (
468 mInstructionString
.Content
,
469 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
470 mInstructionContentOffset
,
473 mInstructionContentOffset
+= 7;
476 EDBSPrintWithOffset (
477 mInstructionString
.Content
,
478 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
479 mInstructionContentOffset
,
482 mInstructionContentOffset
+= 4;
486 return mInstructionContentOffset
;
492 IN UINTN NaturalUnits
,
493 IN UINTN ConstantUnits
499 Print the hexical UINTN index data to instruction content
503 Sign - Signed bit of UINTN data
504 NaturalUnits - natural units of UINTN data
505 ConstantUnits - natural units of UINTN data
509 Instruction content offset
513 EDBSPrintWithOffset (
514 mInstructionString
.Content
,
515 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
516 mInstructionContentOffset
,
523 mInstructionContentOffset
= mInstructionContentOffset
+ 5 + EdbGetBitWidth (NaturalUnits
) + EdbGetBitWidth (ConstantUnits
);
525 return mInstructionContentOffset
;
529 EdbPrintIndexData64 (
531 IN UINT64 NaturalUnits
,
532 IN UINT64 ConstantUnits
538 Print the hexical QWORD index data to instruction content
542 Sign - Signed bit of QWORD data
543 NaturalUnits - natural units of QWORD data
544 ConstantUnits - natural units of QWORD data
548 Instruction content offset
552 EDBSPrintWithOffset (
553 mInstructionString
.Content
,
554 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
555 mInstructionContentOffset
,
562 mInstructionContentOffset
= mInstructionContentOffset
+ 5 + EdbGetBitWidth (NaturalUnits
) + EdbGetBitWidth (ConstantUnits
);
564 return mInstructionContentOffset
;
568 EdbPrintRawIndexData16 (
575 Print the hexical WORD raw index data to instruction content
583 Instruction content offset
592 Sign
= EdbGetNaturalIndex16 (Data16
, &NaturalUnits
, &ConstantUnits
);
593 Offset
= EdbPrintIndexData (Sign
, NaturalUnits
, ConstantUnits
);
599 EdbPrintRawIndexData32 (
606 Print the hexical DWORD raw index data to instruction content
614 Instruction content offset
623 Sign
= EdbGetNaturalIndex32 (Data32
, &NaturalUnits
, &ConstantUnits
);
624 Offset
= EdbPrintIndexData (Sign
, NaturalUnits
, ConstantUnits
);
630 EdbPrintRawIndexData64 (
637 Print the hexical QWORD raw index data to instruction content
645 Instruction content offset
651 UINT64 ConstantUnits
;
654 Sign
= EdbGetNaturalIndex64 (Data64
, &NaturalUnits
, &ConstantUnits
);
655 Offset
= EdbPrintIndexData64 (Sign
, NaturalUnits
, ConstantUnits
);
668 Print the hexical BYTE immediate data to instruction content
676 Instruction content offset
680 EDBSPrintWithOffset (
681 mInstructionString
.Content
,
682 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
683 mInstructionContentOffset
,
687 mInstructionContentOffset
+= 6;
689 return mInstructionContentOffset
;
700 Print the hexical WORD immediate data to instruction content
708 Instruction content offset
712 EDBSPrintWithOffset (
713 mInstructionString
.Content
,
714 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
715 mInstructionContentOffset
,
719 mInstructionContentOffset
+= 8;
721 return mInstructionContentOffset
;
732 Print the hexical DWORD immediate data to instruction content
740 Instruction content offset
744 EDBSPrintWithOffset (
745 mInstructionString
.Content
,
746 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
747 mInstructionContentOffset
,
751 mInstructionContentOffset
+= 12;
753 return mInstructionContentOffset
;
764 Print the hexical QWORD immediate data to instruction content
772 Instruction content offset
776 EDBSPrintWithOffset (
777 mInstructionString
.Content
,
778 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
779 mInstructionContentOffset
,
783 mInstructionContentOffset
+= 20;
785 return mInstructionContentOffset
;
796 Print the decimal UINTN immediate data to instruction content
804 Instruction content offset
808 EDBSPrintWithOffset (
809 mInstructionString
.Content
,
810 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
811 mInstructionContentOffset
,
815 mInstructionContentOffset
= mInstructionContentOffset
+ 2 + EdbGetBitWidth (Data
);
817 return mInstructionContentOffset
;
828 Print the decimal QWORD immediate data to instruction content
836 Instruction content offset
840 EDBSPrintWithOffset (
841 mInstructionString
.Content
,
842 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
843 mInstructionContentOffset
,
847 mInstructionContentOffset
= mInstructionContentOffset
+ 2 + EdbGetBitWidth (Data64
);
849 return mInstructionContentOffset
;
860 Print the hexical BYTE to instruction content
868 Instruction content offset
872 EDBSPrintWithOffset (
873 mInstructionString
.Content
,
874 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
875 mInstructionContentOffset
,
879 mInstructionContentOffset
+= 4;
881 return mInstructionContentOffset
;
892 Print the hexical WORD to instruction content
900 Instruction content offset
904 EDBSPrintWithOffset (
905 mInstructionString
.Content
,
906 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
907 mInstructionContentOffset
,
911 mInstructionContentOffset
+= 6;
913 return mInstructionContentOffset
;
924 Print the hexical DWORD to instruction content
932 Instruction content offset
936 EDBSPrintWithOffset (
937 mInstructionString
.Content
,
938 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
939 mInstructionContentOffset
,
943 mInstructionContentOffset
+= 10;
945 return mInstructionContentOffset
;
956 Print the hexical QWORD to instruction content
964 Instruction content offset
968 EDBSPrintWithOffset (
969 mInstructionString
.Content
,
970 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
971 mInstructionContentOffset
,
975 mInstructionContentOffset
+= 18;
977 return mInstructionContentOffset
;
988 Print the decimal unsigned UINTN to instruction content
992 Data - unsigned UINTN data
996 Instruction content offset
1000 EDBSPrintWithOffset (
1001 mInstructionString
.Content
,
1002 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1003 mInstructionContentOffset
,
1007 mInstructionContentOffset
= mInstructionContentOffset
+ EdbGetBitWidth (Data
);
1009 return mInstructionContentOffset
;
1018 Routine Description:
1020 Print the decimal unsigned QWORD to instruction content
1024 Data64 - unsigned QWORD data
1028 Instruction content offset
1032 EDBSPrintWithOffset (
1033 mInstructionString
.Content
,
1034 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1035 mInstructionContentOffset
,
1039 mInstructionContentOffset
= mInstructionContentOffset
+ EdbGetBitWidth (Data64
);
1041 return mInstructionContentOffset
;
1050 Routine Description:
1052 Print the decimal signed BYTE to instruction content
1056 Data8 - signed BYTE data
1060 Instruction content offset
1066 Sign
= (BOOLEAN
)(Data8
>> 7);
1068 EDBSPrintWithOffset (
1069 mInstructionString
.Content
,
1070 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1071 mInstructionContentOffset
,
1074 (UINTN
)(Data8
& 0x7F)
1076 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data8
& 0x7F);
1078 return mInstructionContentOffset
;
1087 Routine Description:
1089 Print the decimal signed WORD to instruction content
1093 Data16 - signed WORD data
1097 Instruction content offset
1103 Sign
= (BOOLEAN
)(Data16
>> 15);
1105 EDBSPrintWithOffset (
1106 mInstructionString
.Content
,
1107 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1108 mInstructionContentOffset
,
1111 (UINTN
)(Data16
& 0x7FFF)
1113 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data16
& 0x7FFF);
1115 return mInstructionContentOffset
;
1124 Routine Description:
1126 Print the decimal signed DWORD to instruction content
1130 Data32 - signed DWORD data
1134 Instruction content offset
1140 Sign
= (BOOLEAN
)(Data32
>> 31);
1142 EDBSPrintWithOffset (
1143 mInstructionString
.Content
,
1144 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1145 mInstructionContentOffset
,
1148 (UINTN
)(Data32
& 0x7FFFFFFF)
1150 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data32
& 0x7FFFFFFF);
1152 return mInstructionContentOffset
;
1161 Routine Description:
1163 Print the decimal signed QWORD to instruction content
1167 Data64 - signed QWORD data
1171 Instruction content offset
1178 Sign
= (BOOLEAN
)RShiftU64 (Data64
, 63);
1179 Data64s
= (INT64
)RShiftU64 (LShiftU64 (Data64
, 1), 1);
1181 EDBSPrintWithOffset (
1182 mInstructionString
.Content
,
1183 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1184 mInstructionContentOffset
,
1189 mInstructionContentOffset
= mInstructionContentOffset
+ 1 + EdbGetBitWidth (Data64s
);
1191 return mInstructionContentOffset
;
1200 Routine Description:
1202 Print the comma to instruction content
1210 Instruction content offset
1214 EDBSPrintWithOffset (
1215 mInstructionString
.Content
,
1216 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1217 mInstructionContentOffset
,
1220 mInstructionContentOffset
+= 2;
1222 return mInstructionContentOffset
;
1226 EdbFindAndPrintSymbol (
1231 Routine Description:
1233 Find the symbol string according to address, then print it
1237 Address - instruction address
1241 1 - symbol string is found and printed
1242 0 - symbol string not found
1248 SymbolStr
= FindSymbolStr (Address
);
1249 if (SymbolStr
!= NULL
) {
1250 EDBSPrintWithOffset (
1251 mInstructionString
.Content
,
1252 EDB_INSTRUCTION_CONTENT_MAX_SIZE
,
1253 mInstructionContentOffset
,
1265 IN EFI_PHYSICAL_ADDRESS InstructionAddress
,
1266 IN UINTN InstructionNumber
1270 Routine Description:
1272 Print the EBC byte code
1276 InstructionAddress - instruction address
1277 InstructionNumber - instruction number
1291 if (InstructionNumber
== 0) {
1295 LineNumber
= InstructionNumber
/ EDB_BYTECODE_NUMBER_IN_LINE
;
1296 ByteNumber
= InstructionNumber
% EDB_BYTECODE_NUMBER_IN_LINE
;
1297 if (ByteNumber
== 0) {
1299 ByteNumber
= EDB_BYTECODE_NUMBER_IN_LINE
;
1305 SymbolStr
= FindSymbolStr ((UINTN
)InstructionAddress
);
1306 if (SymbolStr
!= NULL
) {
1307 EDBPrint (L
"[%a]:\n", SymbolStr
);
1310 for (LineIndex
= 0; LineIndex
< LineNumber
; LineIndex
++) {
1311 EDBPrint (EDB_PRINT_ADDRESS_FORMAT
, (UINTN
)InstructionAddress
);
1312 for (ByteIndex
= 0; ByteIndex
< EDB_BYTECODE_NUMBER_IN_LINE
; ByteIndex
++) {
1313 EDBPrint (L
"%02x ", *(UINT8
*)(UINTN
)InstructionAddress
);
1314 InstructionAddress
+= 1;
1319 EDBPrint (EDB_PRINT_ADDRESS_FORMAT
, (UINTN
)InstructionAddress
);
1320 for (ByteIndex
= 0; ByteIndex
< ByteNumber
; ByteIndex
++) {
1321 EDBPrint (L
"%02x ", *(UINT8
*)(UINTN
)InstructionAddress
);
1322 InstructionAddress
+= 1;
1324 for (ByteIndex
= 0; ByteIndex
< EDB_BYTECODE_NUMBER_IN_LINE
- ByteNumber
; ByteIndex
++) {
1333 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
1334 IN EFI_SYSTEM_CONTEXT SystemContext
1338 Routine Description:
1340 Print the EBC asm code
1344 DebuggerPrivate - EBC Debugger private data structure
1345 SystemContext - EBC system context.
1349 EFI_SUCCESS - show disasm successfully
1353 EFI_PHYSICAL_ADDRESS InstructionAddress
;
1354 UINTN InstructionNumber
;
1355 UINTN InstructionLength
;
1357 CHAR16
*InstructionString
;
1360 InstructionAddress
= DebuggerPrivate
->InstructionScope
;
1361 for (InstructionNumber
= 0; InstructionNumber
< DebuggerPrivate
->InstructionNumber
; InstructionNumber
++) {
1364 // Break each 0x10 instruction
1366 if (((InstructionNumber
% EFI_DEBUGGER_LINE_NUMBER_IN_PAGE
) == 0) &&
1367 (InstructionNumber
!= 0)) {
1368 if (SetPageBreak ()) {
1373 Opcode
= GET_OPCODE(InstructionAddress
);
1374 if ((Opcode
< OPCODE_MAX
) && (mEdbDisasmInstructionTable
[Opcode
] != NULL
)) {
1375 InstructionLength
= mEdbDisasmInstructionTable
[Opcode
] (InstructionAddress
, SystemContext
, &InstructionString
);
1376 if (InstructionLength
!= 0) {
1381 // Result = EdbPrintSource ((UINTN)InstructionAddress, FALSE);
1383 if (!DebuggerPrivate
->DebuggerSymbolContext
.DisplayCodeOnly
) {
1385 EdbPrintRaw (InstructionAddress
, InstructionLength
);
1386 if (InstructionString
!= NULL
) {
1387 EDBPrint (L
"%s\n", InstructionString
);
1389 EDBPrint (L
"%s\n", L
"<Unknown Instruction>");
1393 EdbPrintSource ((UINTN
)InstructionAddress
, TRUE
);
1395 InstructionAddress
+= InstructionLength
;
1398 // Something wrong with OPCODE
1400 EdbPrintRaw (InstructionAddress
, EDB_BYTECODE_NUMBER_IN_LINE
);
1401 EDBPrint (L
"%s\n", L
"<Bad Instruction>");
1406 // Something wrong with OPCODE
1408 EdbPrintRaw (InstructionAddress
, EDB_BYTECODE_NUMBER_IN_LINE
);
1409 EDBPrint (L
"%s\n", L
"<Bad Instruction>");
1419 IN EFI_SYSTEM_CONTEXT SystemContext
,
1424 Routine Description:
1426 Get register value accroding to the system context, and register index
1430 SystemContext - EBC system context.
1431 Index - EBC register index
1441 return SystemContext
.SystemContextEbc
->R0
;
1443 return SystemContext
.SystemContextEbc
->R1
;
1445 return SystemContext
.SystemContextEbc
->R2
;
1447 return SystemContext
.SystemContextEbc
->R3
;
1449 return SystemContext
.SystemContextEbc
->R4
;
1451 return SystemContext
.SystemContextEbc
->R5
;
1453 return SystemContext
.SystemContextEbc
->R6
;
1455 return SystemContext
.SystemContextEbc
->R7
;