]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.c
MdeModulePkg/EbcDxe: add EBC Debugger
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbDisasmSupport.c
CommitLineData
748edcd5
PB
1/*++\r
2\r
3Copyright (c) 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 EdbDisasmSupport.c\r
15\r
16Abstract:\r
17\r
18\r
19--*/\r
20\r
21#include "Edb.h"\r
22\r
23extern EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable[];\r
24\r
25typedef struct {\r
26 CHAR16 Name[EDB_INSTRUCTION_NAME_MAX_LENGTH];\r
27 CHAR16 Content[EDB_INSTRUCTION_CONTENT_MAX_LENGTH];\r
28 CHAR16 Tail;\r
29} EDB_INSTRUCTION_STRING;\r
30\r
31EDB_INSTRUCTION_STRING mInstructionString;\r
32UINTN mInstructionNameOffset;\r
33UINTN mInstructionContentOffset;\r
34\r
35VOID\r
36EdbSetOffset (\r
37 IN UINTN InstructionNameOffset,\r
38 IN UINTN InstructionContentOffset\r
39 )\r
40/*++\r
41\r
42Routine Description:\r
43\r
44 Set offset for Instruction name and content\r
45\r
46Arguments:\r
47\r
48 InstructionNameOffset - Instruction name offset\r
49 InstructionContentOffset - Instruction content offset\r
50\r
51Returns:\r
52\r
53 None\r
54\r
55--*/\r
56{\r
57 mInstructionNameOffset = InstructionNameOffset;\r
58 mInstructionContentOffset = InstructionContentOffset;\r
59\r
60 return ;\r
61}\r
62\r
63CHAR16 *\r
64EdbPreInstructionString (\r
65 VOID\r
66 )\r
67/*++\r
68\r
69Routine Description:\r
70\r
71 Pre instruction string construction\r
72\r
73Arguments:\r
74\r
75 None\r
76\r
77Returns:\r
78\r
79 Instruction string\r
80\r
81--*/\r
82{\r
83 ZeroMem (&mInstructionString, sizeof(mInstructionString));\r
84 mInstructionNameOffset = 0;\r
85 mInstructionContentOffset = 0;\r
86\r
87 return (CHAR16 *)&mInstructionString;\r
88}\r
89\r
90CHAR16 *\r
91EdbPostInstructionString (\r
92 VOID\r
93 )\r
94/*++\r
95\r
96Routine Description:\r
97\r
98 Post instruction string construction\r
99\r
100Arguments:\r
101\r
102 None\r
103\r
104Returns:\r
105\r
106 Instruction string\r
107\r
108--*/\r
109{\r
110 CHAR16 *Char;\r
111\r
112 for (Char = (CHAR16 *)&mInstructionString; Char < &mInstructionString.Tail; Char++) {\r
113 if (*Char == 0) {\r
114 *Char = L' ';\r
115 }\r
116 }\r
117 mInstructionString.Tail = 0;\r
118\r
119 mInstructionNameOffset = 0;\r
120 mInstructionContentOffset = 0;\r
121\r
122 return (CHAR16 *)&mInstructionString;\r
123}\r
124\r
125BOOLEAN\r
126EdbGetNaturalIndex16 (\r
127 IN UINT16 Data16,\r
128 OUT UINTN *NaturalUnits,\r
129 OUT UINTN *ConstantUnits\r
130 )\r
131/*++\r
132\r
133Routine Description:\r
134\r
135 Get Sign, NaturalUnits, and ConstantUnits of the WORD data\r
136\r
137Arguments:\r
138\r
139 Data16 - WORD data\r
140 NaturalUnits - Natural Units of the WORD\r
141 ConstantUnits - Constant Units of the WORD\r
142\r
143Returns:\r
144\r
145 Sign value of WORD\r
146\r
147--*/\r
148{\r
149 BOOLEAN Sign;\r
150 UINTN NaturalUnitBit;\r
151\r
152 Sign = (BOOLEAN)(Data16 >> 15);\r
153 NaturalUnitBit = (UINTN)((Data16 >> 12) & 0x7);\r
154 NaturalUnitBit *= 2;\r
155 Data16 = Data16 & 0xFFF;\r
156 *NaturalUnits = (UINTN)(Data16 & ((1 << NaturalUnitBit) - 1));\r
157 *ConstantUnits = (UINTN)((Data16 >> NaturalUnitBit) & ((1 << (12 - NaturalUnitBit)) - 1));\r
158\r
159 return Sign;\r
160}\r
161\r
162BOOLEAN\r
163EdbGetNaturalIndex32 (\r
164 IN UINT32 Data32,\r
165 OUT UINTN *NaturalUnits,\r
166 OUT UINTN *ConstantUnits\r
167 )\r
168/*++\r
169\r
170Routine Description:\r
171\r
172 Get Sign, NaturalUnits, and ConstantUnits of the DWORD data\r
173\r
174Arguments:\r
175\r
176 Data32 - DWORD data\r
177 NaturalUnits - Natural Units of the DWORD\r
178 ConstantUnits - Constant Units of the DWORD\r
179\r
180Returns:\r
181\r
182 Sign value of DWORD\r
183\r
184--*/\r
185{\r
186 BOOLEAN Sign;\r
187 UINTN NaturalUnitBit;\r
188\r
189 Sign = (BOOLEAN)(Data32 >> 31);\r
190 NaturalUnitBit = (UINTN)((Data32 >> 28) & 0x7);\r
191 NaturalUnitBit *= 4;\r
192 Data32 = Data32 & 0xFFFFFFF;\r
193 *NaturalUnits = (UINTN)(Data32 & ((1 << NaturalUnitBit) - 1));\r
194 *ConstantUnits = (UINTN)((Data32 >> NaturalUnitBit) & ((1 << (28 - NaturalUnitBit)) - 1));\r
195\r
196 return Sign;\r
197}\r
198\r
199BOOLEAN\r
200EdbGetNaturalIndex64 (\r
201 IN UINT64 Data64,\r
202 OUT UINT64 *NaturalUnits,\r
203 OUT UINT64 *ConstantUnits\r
204 )\r
205/*++\r
206\r
207Routine Description:\r
208\r
209 Get Sign, NaturalUnits, and ConstantUnits of the QWORD data\r
210\r
211Arguments:\r
212\r
213 Data64 - QWORD data\r
214 NaturalUnits - Natural Units of the QWORD\r
215 ConstantUnits - Constant Units of the QWORD\r
216\r
217Returns:\r
218\r
219 Sign value of QWORD\r
220\r
221--*/\r
222{\r
223 BOOLEAN Sign;\r
224 UINTN NaturalUnitBit;\r
225\r
226 Sign = (BOOLEAN)RShiftU64 (Data64, 63);\r
227 NaturalUnitBit = (UINTN)(RShiftU64 (Data64, 60) & 0x7);\r
228 NaturalUnitBit *= 8;\r
229 Data64 = RShiftU64 (LShiftU64 (Data64, 4), 4);\r
230 *NaturalUnits = (UINT64)(Data64 & (LShiftU64 (1, NaturalUnitBit) - 1));\r
231 *ConstantUnits = (UINT64)(RShiftU64 (Data64, NaturalUnitBit) & (LShiftU64 (1, (60 - NaturalUnitBit)) - 1));\r
232\r
233 return Sign;\r
234}\r
235\r
236UINT8\r
237EdbGetBitWidth (\r
238 IN UINT64 Value\r
239 )\r
240/*++\r
241\r
242Routine Description:\r
243\r
244 Get Bit Width of the value\r
245\r
246Arguments:\r
247\r
248 Value - data\r
249\r
250Returns:\r
251\r
252 Bit width\r
253\r
254--*/\r
255{\r
256 if (Value >= 10000000000000) {\r
257 return 14;\r
258 } else if (Value >= 1000000000000) {\r
259 return 13;\r
260 } else if (Value >= 100000000000) {\r
261 return 12;\r
262 } else if (Value >= 10000000000) {\r
263 return 11;\r
264 } else if (Value >= 1000000000) {\r
265 return 10;\r
266 } else if (Value >= 100000000) {\r
267 return 9;\r
268 } else if (Value >= 10000000) {\r
269 return 8;\r
270 } else if (Value >= 1000000) {\r
271 return 7;\r
272 } else if (Value >= 100000) {\r
273 return 6;\r
274 } else if (Value >= 10000) {\r
275 return 5;\r
276 } else if (Value >= 1000) {\r
277 return 4;\r
278 } else if (Value >= 100) {\r
279 return 3;\r
280 } else if (Value >= 10) {\r
281 return 2;\r
282 } else {\r
283 return 1;\r
284 }\r
285}\r
286\r
287UINTN\r
288EdbPrintInstructionName (\r
289 IN CHAR16 *Name\r
290 )\r
291/*++\r
292\r
293Routine Description:\r
294\r
295 Print the instruction name\r
296\r
297Arguments:\r
298\r
299 Name - instruction name\r
300\r
301Returns:\r
302\r
303 Instruction name offset\r
304\r
305--*/\r
306{\r
307 EDBSPrintWithOffset (\r
308 mInstructionString.Name,\r
309 EDB_INSTRUCTION_NAME_MAX_SIZE,\r
310 mInstructionNameOffset,\r
311 L"%s",\r
312 Name\r
313 );\r
314 mInstructionNameOffset += StrLen (Name);\r
315\r
316 return mInstructionNameOffset;\r
317}\r
318\r
319UINTN\r
320EdbPrintRegister1 (\r
321 IN UINT8 Operands\r
322 )\r
323/*++\r
324\r
325Routine Description:\r
326\r
327 Print register 1 in operands\r
328\r
329Arguments:\r
330\r
331 Operands - instruction operands\r
332\r
333Returns:\r
334\r
335 Instruction content offset\r
336\r
337--*/\r
338{\r
339 if (Operands & OPERAND_M_INDIRECT1) {\r
340 EDBSPrintWithOffset (\r
341 mInstructionString.Content,\r
342 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
343 mInstructionContentOffset,\r
344 L"@"\r
345 );\r
346 mInstructionContentOffset += 1;\r
347 }\r
348 EDBSPrintWithOffset (\r
349 mInstructionString.Content,\r
350 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
351 mInstructionContentOffset,\r
352 L"R%d",\r
353 (UINTN)(Operands & OPERAND_M_OP1)\r
354 );\r
355 mInstructionContentOffset += 2;\r
356\r
357 return mInstructionContentOffset;\r
358}\r
359\r
360UINTN\r
361EdbPrintRegister2 (\r
362 IN UINT8 Operands\r
363 )\r
364/*++\r
365\r
366Routine Description:\r
367\r
368 Print register 2 in operands\r
369\r
370Arguments:\r
371\r
372 Operands - instruction operands\r
373\r
374Returns:\r
375\r
376 Instruction content offset\r
377\r
378--*/\r
379{\r
380 if (Operands & OPERAND_M_INDIRECT2) {\r
381 EDBSPrintWithOffset (\r
382 mInstructionString.Content,\r
383 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
384 mInstructionContentOffset,\r
385 L"@"\r
386 );\r
387 mInstructionContentOffset += 1;\r
388 }\r
389 EDBSPrintWithOffset (\r
390 mInstructionString.Content,\r
391 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
392 mInstructionContentOffset,\r
393 L"R%d",\r
394 (UINTN)((Operands & OPERAND_M_OP2) >> 4)\r
395 );\r
396 mInstructionContentOffset += 2;\r
397\r
398 return mInstructionContentOffset;\r
399}\r
400\r
401UINTN\r
402EdbPrintDedicatedRegister1 (\r
403 IN UINT8 Operands\r
404 )\r
405/*++\r
406\r
407Routine Description:\r
408\r
409 Print dedicated register 1 in operands\r
410\r
411Arguments:\r
412\r
413 Operands - instruction operands\r
414\r
415Returns:\r
416\r
417 Instruction content offset\r
418\r
419--*/\r
420{\r
421 switch (Operands & OPERAND_M_OP1) {\r
422 case 0:\r
423 EDBSPrintWithOffset (\r
424 mInstructionString.Content,\r
425 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
426 mInstructionContentOffset,\r
427 L"[FLAGS]"\r
428 );\r
429 mInstructionContentOffset += 7;\r
430 break;\r
431 case 1:\r
432 EDBSPrintWithOffset (\r
433 mInstructionString.Content,\r
434 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
435 mInstructionContentOffset,\r
436 L"[IP]"\r
437 );\r
438 mInstructionContentOffset += 4;\r
439 break;\r
440 }\r
441\r
442 return mInstructionContentOffset;\r
443}\r
444\r
445UINTN\r
446EdbPrintDedicatedRegister2 (\r
447 IN UINT8 Operands\r
448 )\r
449/*++\r
450\r
451Routine Description:\r
452\r
453 Print dedicated register 2 in operands\r
454\r
455Arguments:\r
456\r
457 Operands - instruction operands\r
458\r
459Returns:\r
460\r
461 Instruction content offset\r
462\r
463--*/\r
464{\r
465 switch ((Operands & OPERAND_M_OP2) >> 4) {\r
466 case 0:\r
467 EDBSPrintWithOffset (\r
468 mInstructionString.Content,\r
469 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
470 mInstructionContentOffset,\r
471 L"[FLAGS]"\r
472 );\r
473 mInstructionContentOffset += 7;\r
474 break;\r
475 case 1:\r
476 EDBSPrintWithOffset (\r
477 mInstructionString.Content,\r
478 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
479 mInstructionContentOffset,\r
480 L"[IP]"\r
481 );\r
482 mInstructionContentOffset += 4;\r
483 break;\r
484 }\r
485\r
486 return mInstructionContentOffset;\r
487}\r
488\r
489UINTN\r
490EdbPrintIndexData (\r
491 IN BOOLEAN Sign,\r
492 IN UINTN NaturalUnits,\r
493 IN UINTN ConstantUnits\r
494 )\r
495/*++\r
496\r
497Routine Description:\r
498\r
499 Print the hexical UINTN index data to instruction content\r
500\r
501Arguments:\r
502\r
503 Sign - Signed bit of UINTN data\r
504 NaturalUnits - natural units of UINTN data\r
505 ConstantUnits - natural units of UINTN data\r
506\r
507Returns:\r
508\r
509 Instruction content offset\r
510\r
511--*/\r
512{\r
513 EDBSPrintWithOffset (\r
514 mInstructionString.Content,\r
515 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
516 mInstructionContentOffset,\r
517 L"(%s%d,%s%d)",\r
518 Sign ? L"-" : L"+",\r
519 NaturalUnits,\r
520 Sign ? L"-" : L"+",\r
521 ConstantUnits\r
522 );\r
523 mInstructionContentOffset = mInstructionContentOffset + 5 + EdbGetBitWidth (NaturalUnits) + EdbGetBitWidth (ConstantUnits);\r
524\r
525 return mInstructionContentOffset;\r
526}\r
527\r
528UINTN\r
529EdbPrintIndexData64 (\r
530 IN BOOLEAN Sign,\r
531 IN UINT64 NaturalUnits,\r
532 IN UINT64 ConstantUnits\r
533 )\r
534/*++\r
535\r
536Routine Description:\r
537\r
538 Print the hexical QWORD index data to instruction content\r
539\r
540Arguments:\r
541\r
542 Sign - Signed bit of QWORD data\r
543 NaturalUnits - natural units of QWORD data\r
544 ConstantUnits - natural units of QWORD data\r
545\r
546Returns:\r
547\r
548 Instruction content offset\r
549\r
550--*/\r
551{\r
552 EDBSPrintWithOffset (\r
553 mInstructionString.Content,\r
554 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
555 mInstructionContentOffset,\r
556 L"(%s%ld,%s%ld)",\r
557 Sign ? L"-" : L"+",\r
558 NaturalUnits,\r
559 Sign ? L"-" : L"+",\r
560 ConstantUnits\r
561 );\r
562 mInstructionContentOffset = mInstructionContentOffset + 5 + EdbGetBitWidth (NaturalUnits) + EdbGetBitWidth (ConstantUnits);\r
563\r
564 return mInstructionContentOffset;\r
565}\r
566\r
567UINTN\r
568EdbPrintRawIndexData16 (\r
569 IN UINT16 Data16\r
570 )\r
571/*++\r
572\r
573Routine Description:\r
574\r
575 Print the hexical WORD raw index data to instruction content\r
576\r
577Arguments:\r
578\r
579 Data16 - WORD data\r
580\r
581Returns:\r
582\r
583 Instruction content offset\r
584\r
585--*/\r
586{\r
587 BOOLEAN Sign;\r
588 UINTN NaturalUnits;\r
589 UINTN ConstantUnits;\r
590 UINTN Offset;\r
591\r
592 Sign = EdbGetNaturalIndex16 (Data16, &NaturalUnits, &ConstantUnits);\r
593 Offset = EdbPrintIndexData (Sign, NaturalUnits, ConstantUnits);\r
594\r
595 return Offset;\r
596}\r
597\r
598UINTN\r
599EdbPrintRawIndexData32 (\r
600 IN UINT32 Data32\r
601 )\r
602/*++\r
603\r
604Routine Description:\r
605\r
606 Print the hexical DWORD raw index data to instruction content\r
607\r
608Arguments:\r
609\r
610 Data32 - DWORD data\r
611\r
612Returns:\r
613\r
614 Instruction content offset\r
615\r
616--*/\r
617{\r
618 BOOLEAN Sign;\r
619 UINTN NaturalUnits;\r
620 UINTN ConstantUnits;\r
621 UINTN Offset;\r
622\r
623 Sign = EdbGetNaturalIndex32 (Data32, &NaturalUnits, &ConstantUnits);\r
624 Offset = EdbPrintIndexData (Sign, NaturalUnits, ConstantUnits);\r
625\r
626 return Offset;\r
627}\r
628\r
629UINTN\r
630EdbPrintRawIndexData64 (\r
631 IN UINT64 Data64\r
632 )\r
633/*++\r
634\r
635Routine Description:\r
636\r
637 Print the hexical QWORD raw index data to instruction content\r
638\r
639Arguments:\r
640\r
641 Data64 - QWORD data\r
642\r
643Returns:\r
644\r
645 Instruction content offset\r
646\r
647--*/\r
648{\r
649 BOOLEAN Sign;\r
650 UINT64 NaturalUnits;\r
651 UINT64 ConstantUnits;\r
652 UINTN Offset;\r
653\r
654 Sign = EdbGetNaturalIndex64 (Data64, &NaturalUnits, &ConstantUnits);\r
655 Offset = EdbPrintIndexData64 (Sign, NaturalUnits, ConstantUnits);\r
656\r
657 return Offset;\r
658}\r
659\r
660UINTN\r
661EdbPrintImmData8 (\r
662 IN UINT8 Data\r
663 )\r
664/*++\r
665\r
666Routine Description:\r
667\r
668 Print the hexical BYTE immediate data to instruction content\r
669\r
670Arguments:\r
671\r
672 Data - BYTE data\r
673\r
674Returns:\r
675\r
676 Instruction content offset\r
677\r
678--*/\r
679{\r
680 EDBSPrintWithOffset (\r
681 mInstructionString.Content,\r
682 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
683 mInstructionContentOffset,\r
684 L"(0x%02x)",\r
685 (UINTN)Data\r
686 );\r
687 mInstructionContentOffset += 6;\r
688\r
689 return mInstructionContentOffset;\r
690}\r
691\r
692UINTN\r
693EdbPrintImmData16 (\r
694 IN UINT16 Data\r
695 )\r
696/*++\r
697\r
698Routine Description:\r
699\r
700 Print the hexical WORD immediate data to instruction content\r
701\r
702Arguments:\r
703\r
704 Data - WORD data\r
705\r
706Returns:\r
707\r
708 Instruction content offset\r
709\r
710--*/\r
711{\r
712 EDBSPrintWithOffset (\r
713 mInstructionString.Content,\r
714 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
715 mInstructionContentOffset,\r
716 L"(0x%04x)",\r
717 (UINTN)Data\r
718 );\r
719 mInstructionContentOffset += 8;\r
720\r
721 return mInstructionContentOffset;\r
722}\r
723\r
724UINTN\r
725EdbPrintImmData32 (\r
726 IN UINT32 Data\r
727 )\r
728/*++\r
729\r
730Routine Description:\r
731\r
732 Print the hexical DWORD immediate data to instruction content\r
733\r
734Arguments:\r
735\r
736 Data - DWORD data\r
737\r
738Returns:\r
739\r
740 Instruction content offset\r
741\r
742--*/\r
743{\r
744 EDBSPrintWithOffset (\r
745 mInstructionString.Content,\r
746 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
747 mInstructionContentOffset,\r
748 L"(0x%08x)",\r
749 (UINTN)Data\r
750 );\r
751 mInstructionContentOffset += 12;\r
752\r
753 return mInstructionContentOffset;\r
754}\r
755\r
756UINTN\r
757EdbPrintImmData64 (\r
758 IN UINT64 Data\r
759 )\r
760/*++\r
761\r
762Routine Description:\r
763\r
764 Print the hexical QWORD immediate data to instruction content\r
765\r
766Arguments:\r
767\r
768 Data - QWORD data\r
769\r
770Returns:\r
771\r
772 Instruction content offset\r
773\r
774--*/\r
775{\r
776 EDBSPrintWithOffset (\r
777 mInstructionString.Content,\r
778 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
779 mInstructionContentOffset,\r
780 L"(0x%016lx)",\r
781 Data\r
782 );\r
783 mInstructionContentOffset += 20;\r
784\r
785 return mInstructionContentOffset;\r
786}\r
787\r
788UINTN\r
789EdbPrintImmDatan (\r
790 IN UINTN Data\r
791 )\r
792/*++\r
793\r
794Routine Description:\r
795\r
796 Print the decimal UINTN immediate data to instruction content\r
797\r
798Arguments:\r
799\r
800 Data - UINTN data\r
801\r
802Returns:\r
803\r
804 Instruction content offset\r
805\r
806--*/\r
807{\r
808 EDBSPrintWithOffset (\r
809 mInstructionString.Content,\r
810 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
811 mInstructionContentOffset,\r
812 L"(%d)",\r
813 (UINTN)Data\r
814 );\r
815 mInstructionContentOffset = mInstructionContentOffset + 2 + EdbGetBitWidth (Data);\r
816\r
817 return mInstructionContentOffset;\r
818}\r
819\r
820UINTN\r
821EdbPrintImmData64n (\r
822 IN UINT64 Data64\r
823 )\r
824/*++\r
825\r
826Routine Description:\r
827\r
828 Print the decimal QWORD immediate data to instruction content\r
829\r
830Arguments:\r
831\r
832 Data64 - QWORD data\r
833\r
834Returns:\r
835\r
836 Instruction content offset\r
837\r
838--*/\r
839{\r
840 EDBSPrintWithOffset (\r
841 mInstructionString.Content,\r
842 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
843 mInstructionContentOffset,\r
844 L"(%ld)",\r
845 Data64\r
846 );\r
847 mInstructionContentOffset = mInstructionContentOffset + 2 + EdbGetBitWidth (Data64);\r
848\r
849 return mInstructionContentOffset;\r
850}\r
851\r
852UINTN\r
853EdbPrintData8 (\r
854 IN UINT8 Data8\r
855 )\r
856/*++\r
857\r
858Routine Description:\r
859\r
860 Print the hexical BYTE to instruction content\r
861\r
862Arguments:\r
863\r
864 Data8 - BYTE data\r
865\r
866Returns:\r
867\r
868 Instruction content offset\r
869\r
870--*/\r
871{\r
872 EDBSPrintWithOffset (\r
873 mInstructionString.Content,\r
874 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
875 mInstructionContentOffset,\r
876 L"0x%02x",\r
877 (UINTN)Data8\r
878 );\r
879 mInstructionContentOffset += 4;\r
880\r
881 return mInstructionContentOffset;\r
882}\r
883\r
884UINTN\r
885EdbPrintData16 (\r
886 IN UINT16 Data16\r
887 )\r
888/*++\r
889\r
890Routine Description:\r
891\r
892 Print the hexical WORD to instruction content\r
893\r
894Arguments:\r
895\r
896 Data16 - WORD data\r
897\r
898Returns:\r
899\r
900 Instruction content offset\r
901\r
902--*/\r
903{\r
904 EDBSPrintWithOffset (\r
905 mInstructionString.Content,\r
906 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
907 mInstructionContentOffset,\r
908 L"0x%04x",\r
909 (UINTN)Data16\r
910 );\r
911 mInstructionContentOffset += 6;\r
912\r
913 return mInstructionContentOffset;\r
914}\r
915\r
916UINTN\r
917EdbPrintData32 (\r
918 IN UINT32 Data32\r
919 )\r
920/*++\r
921\r
922Routine Description:\r
923\r
924 Print the hexical DWORD to instruction content\r
925\r
926Arguments:\r
927\r
928 Data32 - DWORD data\r
929\r
930Returns:\r
931\r
932 Instruction content offset\r
933\r
934--*/\r
935{\r
936 EDBSPrintWithOffset (\r
937 mInstructionString.Content,\r
938 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
939 mInstructionContentOffset,\r
940 L"0x%08x",\r
941 (UINTN)Data32\r
942 );\r
943 mInstructionContentOffset += 10;\r
944\r
945 return mInstructionContentOffset;\r
946}\r
947\r
948UINTN\r
949EdbPrintData64 (\r
950 IN UINT64 Data64\r
951 )\r
952/*++\r
953\r
954Routine Description:\r
955\r
956 Print the hexical QWORD to instruction content\r
957\r
958Arguments:\r
959\r
960 Data64 - QWORD data\r
961\r
962Returns:\r
963\r
964 Instruction content offset\r
965\r
966--*/\r
967{\r
968 EDBSPrintWithOffset (\r
969 mInstructionString.Content,\r
970 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
971 mInstructionContentOffset,\r
972 L"0x%016lx",\r
973 (UINT64)Data64\r
974 );\r
975 mInstructionContentOffset += 18;\r
976\r
977 return mInstructionContentOffset;\r
978}\r
979\r
980UINTN\r
981EdbPrintDatan (\r
982 IN UINTN Data\r
983 )\r
984/*++\r
985\r
986Routine Description:\r
987\r
988 Print the decimal unsigned UINTN to instruction content\r
989\r
990Arguments:\r
991\r
992 Data - unsigned UINTN data\r
993\r
994Returns:\r
995\r
996 Instruction content offset\r
997\r
998--*/\r
999{\r
1000 EDBSPrintWithOffset (\r
1001 mInstructionString.Content,\r
1002 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1003 mInstructionContentOffset,\r
1004 L"%d",\r
1005 (UINTN)Data\r
1006 );\r
1007 mInstructionContentOffset = mInstructionContentOffset + EdbGetBitWidth (Data);\r
1008\r
1009 return mInstructionContentOffset;\r
1010}\r
1011\r
1012UINTN\r
1013EdbPrintData64n (\r
1014 IN UINT64 Data64\r
1015 )\r
1016/*++\r
1017\r
1018Routine Description:\r
1019\r
1020 Print the decimal unsigned QWORD to instruction content\r
1021\r
1022Arguments:\r
1023\r
1024 Data64 - unsigned QWORD data\r
1025\r
1026Returns:\r
1027\r
1028 Instruction content offset\r
1029\r
1030--*/\r
1031{\r
1032 EDBSPrintWithOffset (\r
1033 mInstructionString.Content,\r
1034 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1035 mInstructionContentOffset,\r
1036 L"%ld",\r
1037 Data64\r
1038 );\r
1039 mInstructionContentOffset = mInstructionContentOffset + EdbGetBitWidth (Data64);\r
1040\r
1041 return mInstructionContentOffset;\r
1042}\r
1043\r
1044UINTN\r
1045EdbPrintData8s (\r
1046 IN UINT8 Data8\r
1047 )\r
1048/*++\r
1049\r
1050Routine Description:\r
1051\r
1052 Print the decimal signed BYTE to instruction content\r
1053\r
1054Arguments:\r
1055\r
1056 Data8 - signed BYTE data\r
1057\r
1058Returns:\r
1059\r
1060 Instruction content offset\r
1061\r
1062--*/\r
1063{\r
1064 BOOLEAN Sign;\r
1065\r
1066 Sign = (BOOLEAN)(Data8 >> 7);\r
1067\r
1068 EDBSPrintWithOffset (\r
1069 mInstructionString.Content,\r
1070 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1071 mInstructionContentOffset,\r
1072 L"%s%d",\r
1073 Sign ? L"-" : L"+",\r
1074 (UINTN)(Data8 & 0x7F)\r
1075 );\r
1076 mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data8 & 0x7F);\r
1077\r
1078 return mInstructionContentOffset;\r
1079}\r
1080\r
1081UINTN\r
1082EdbPrintData16s (\r
1083 IN UINT16 Data16\r
1084 )\r
1085/*++\r
1086\r
1087Routine Description:\r
1088\r
1089 Print the decimal signed WORD to instruction content\r
1090\r
1091Arguments:\r
1092\r
1093 Data16 - signed WORD data\r
1094\r
1095Returns:\r
1096\r
1097 Instruction content offset\r
1098\r
1099--*/\r
1100{\r
1101 BOOLEAN Sign;\r
1102\r
1103 Sign = (BOOLEAN)(Data16 >> 15);\r
1104\r
1105 EDBSPrintWithOffset (\r
1106 mInstructionString.Content,\r
1107 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1108 mInstructionContentOffset,\r
1109 L"%s%d",\r
1110 Sign ? L"-" : L"+",\r
1111 (UINTN)(Data16 & 0x7FFF)\r
1112 );\r
1113 mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data16 & 0x7FFF);\r
1114\r
1115 return mInstructionContentOffset;\r
1116}\r
1117\r
1118UINTN\r
1119EdbPrintData32s (\r
1120 IN UINT32 Data32\r
1121 )\r
1122/*++\r
1123\r
1124Routine Description:\r
1125\r
1126 Print the decimal signed DWORD to instruction content\r
1127\r
1128Arguments:\r
1129\r
1130 Data32 - signed DWORD data\r
1131\r
1132Returns:\r
1133\r
1134 Instruction content offset\r
1135\r
1136--*/\r
1137{\r
1138 BOOLEAN Sign;\r
1139\r
1140 Sign = (BOOLEAN)(Data32 >> 31);\r
1141\r
1142 EDBSPrintWithOffset (\r
1143 mInstructionString.Content,\r
1144 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1145 mInstructionContentOffset,\r
1146 L"%s%d",\r
1147 Sign ? L"-" : L"+",\r
1148 (UINTN)(Data32 & 0x7FFFFFFF)\r
1149 );\r
1150 mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data32 & 0x7FFFFFFF);\r
1151\r
1152 return mInstructionContentOffset;\r
1153}\r
1154\r
1155UINTN\r
1156EdbPrintData64s (\r
1157 IN UINT64 Data64\r
1158 )\r
1159/*++\r
1160\r
1161Routine Description:\r
1162\r
1163 Print the decimal signed QWORD to instruction content\r
1164\r
1165Arguments:\r
1166\r
1167 Data64 - signed QWORD data\r
1168\r
1169Returns:\r
1170\r
1171 Instruction content offset\r
1172\r
1173--*/\r
1174{\r
1175 BOOLEAN Sign;\r
1176 INT64 Data64s;\r
1177\r
1178 Sign = (BOOLEAN)RShiftU64 (Data64, 63);\r
1179 Data64s = (INT64)RShiftU64 (LShiftU64 (Data64, 1), 1);\r
1180\r
1181 EDBSPrintWithOffset (\r
1182 mInstructionString.Content,\r
1183 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1184 mInstructionContentOffset,\r
1185 L"%s%ld",\r
1186 Sign ? L"-" : L"+",\r
1187 (UINT64)Data64s\r
1188 );\r
1189 mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data64s);\r
1190\r
1191 return mInstructionContentOffset;\r
1192}\r
1193\r
1194UINTN\r
1195EdbPrintComma (\r
1196 VOID\r
1197 )\r
1198/*++\r
1199\r
1200Routine Description:\r
1201\r
1202 Print the comma to instruction content\r
1203\r
1204Arguments:\r
1205\r
1206 None\r
1207\r
1208Returns:\r
1209\r
1210 Instruction content offset\r
1211\r
1212--*/\r
1213{\r
1214 EDBSPrintWithOffset (\r
1215 mInstructionString.Content,\r
1216 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1217 mInstructionContentOffset,\r
1218 L", "\r
1219 );\r
1220 mInstructionContentOffset += 2;\r
1221\r
1222 return mInstructionContentOffset;\r
1223}\r
1224\r
1225UINTN\r
1226EdbFindAndPrintSymbol (\r
1227 IN UINTN Address\r
1228 )\r
1229/*++\r
1230\r
1231Routine Description:\r
1232\r
1233 Find the symbol string according to address, then print it\r
1234\r
1235Arguments:\r
1236\r
1237 Address - instruction address\r
1238\r
1239Returns:\r
1240\r
1241 1 - symbol string is found and printed\r
1242 0 - symbol string not found\r
1243\r
1244--*/\r
1245{\r
1246 CHAR8 *SymbolStr;\r
1247\r
1248 SymbolStr = FindSymbolStr (Address);\r
1249 if (SymbolStr != NULL) {\r
1250 EDBSPrintWithOffset (\r
1251 mInstructionString.Content,\r
1252 EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
1253 mInstructionContentOffset,\r
1254 L"[%a]",\r
1255 SymbolStr\r
1256 );\r
1257 return 1;\r
1258 }\r
1259\r
1260 return 0;\r
1261}\r
1262\r
1263VOID\r
1264EdbPrintRaw (\r
1265 IN EFI_PHYSICAL_ADDRESS InstructionAddress,\r
1266 IN UINTN InstructionNumber\r
1267 )\r
1268/*++\r
1269\r
1270Routine Description:\r
1271\r
1272 Print the EBC byte code\r
1273\r
1274Arguments:\r
1275\r
1276 InstructionAddress - instruction address\r
1277 InstructionNumber - instruction number\r
1278\r
1279Returns:\r
1280\r
1281 None\r
1282\r
1283--*/\r
1284{\r
1285 UINTN LineNumber;\r
1286 UINTN ByteNumber;\r
1287 UINTN LineIndex;\r
1288 UINTN ByteIndex;\r
1289 CHAR8 *SymbolStr;\r
1290\r
1291 if (InstructionNumber == 0) {\r
1292 return ;\r
1293 }\r
1294\r
1295 LineNumber = InstructionNumber / EDB_BYTECODE_NUMBER_IN_LINE;\r
1296 ByteNumber = InstructionNumber % EDB_BYTECODE_NUMBER_IN_LINE;\r
1297 if (ByteNumber == 0) {\r
1298 LineNumber -= 1;\r
1299 ByteNumber = EDB_BYTECODE_NUMBER_IN_LINE;\r
1300 }\r
1301\r
1302 //\r
1303 // Print Symbol\r
1304 //\r
1305 SymbolStr = FindSymbolStr ((UINTN)InstructionAddress);\r
1306 if (SymbolStr != NULL) {\r
1307 EDBPrint (L"[%a]:\n", SymbolStr);\r
1308 }\r
1309\r
1310 for (LineIndex = 0; LineIndex < LineNumber; LineIndex++) {\r
1311 EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)InstructionAddress);\r
1312 for (ByteIndex = 0; ByteIndex < EDB_BYTECODE_NUMBER_IN_LINE; ByteIndex++) {\r
1313 EDBPrint (L"%02x ", *(UINT8 *)(UINTN)InstructionAddress);\r
1314 InstructionAddress += 1;\r
1315 }\r
1316 EDBPrint (L"\n");\r
1317 }\r
1318\r
1319 EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)InstructionAddress);\r
1320 for (ByteIndex = 0; ByteIndex < ByteNumber; ByteIndex++) {\r
1321 EDBPrint (L"%02x ", *(UINT8 *)(UINTN)InstructionAddress);\r
1322 InstructionAddress += 1;\r
1323 }\r
1324 for (ByteIndex = 0; ByteIndex < EDB_BYTECODE_NUMBER_IN_LINE - ByteNumber; ByteIndex++) {\r
1325 EDBPrint (L" ");\r
1326 }\r
1327\r
1328 return ;\r
1329}\r
1330\r
1331EFI_STATUS\r
1332EdbShowDisasm (\r
1333 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
1334 IN EFI_SYSTEM_CONTEXT SystemContext\r
1335 )\r
1336/*++\r
1337\r
1338Routine Description:\r
1339\r
1340 Print the EBC asm code\r
1341\r
1342Arguments:\r
1343\r
1344 DebuggerPrivate - EBC Debugger private data structure\r
1345 SystemContext - EBC system context.\r
1346\r
1347Returns:\r
1348\r
1349 EFI_SUCCESS - show disasm successfully\r
1350\r
1351--*/\r
1352{\r
1353 EFI_PHYSICAL_ADDRESS InstructionAddress;\r
1354 UINTN InstructionNumber;\r
1355 UINTN InstructionLength;\r
1356 UINT8 Opcode;\r
1357 CHAR16 *InstructionString;\r
1358// UINTN Result;\r
1359\r
1360 InstructionAddress = DebuggerPrivate->InstructionScope;\r
1361 for (InstructionNumber = 0; InstructionNumber < DebuggerPrivate->InstructionNumber; InstructionNumber++) {\r
1362\r
1363 //\r
1364 // Break each 0x10 instruction\r
1365 //\r
1366 if (((InstructionNumber % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&\r
1367 (InstructionNumber != 0)) {\r
1368 if (SetPageBreak ()) {\r
1369 break;\r
1370 }\r
1371 }\r
1372\r
1373 Opcode = GET_OPCODE(InstructionAddress);\r
1374 if ((Opcode < OPCODE_MAX) && (mEdbDisasmInstructionTable[Opcode] != NULL)) {\r
1375 InstructionLength = mEdbDisasmInstructionTable [Opcode] (InstructionAddress, SystemContext, &InstructionString);\r
1376 if (InstructionLength != 0) {\r
1377\r
1378 //\r
1379 // Print Source\r
1380 //\r
1381// Result = EdbPrintSource ((UINTN)InstructionAddress, FALSE);\r
1382\r
1383 if (!DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly) {\r
1384\r
1385 EdbPrintRaw (InstructionAddress, InstructionLength);\r
1386 if (InstructionString != NULL) {\r
1387 EDBPrint (L"%s\n", InstructionString);\r
1388 } else {\r
1389 EDBPrint (L"%s\n", L"<Unknown Instruction>");\r
1390 }\r
1391 }\r
1392\r
1393 EdbPrintSource ((UINTN)InstructionAddress, TRUE);\r
1394\r
1395 InstructionAddress += InstructionLength;\r
1396 } else {\r
1397 //\r
1398 // Something wrong with OPCODE\r
1399 //\r
1400 EdbPrintRaw (InstructionAddress, EDB_BYTECODE_NUMBER_IN_LINE);\r
1401 EDBPrint (L"%s\n", L"<Bad Instruction>");\r
1402 break;\r
1403 }\r
1404 } else {\r
1405 //\r
1406 // Something wrong with OPCODE\r
1407 //\r
1408 EdbPrintRaw (InstructionAddress, EDB_BYTECODE_NUMBER_IN_LINE);\r
1409 EDBPrint (L"%s\n", L"<Bad Instruction>");\r
1410 break;\r
1411 }\r
1412 }\r
1413\r
1414 return EFI_SUCCESS;\r
1415}\r
1416\r
1417UINT64\r
1418GetRegisterValue (\r
1419 IN EFI_SYSTEM_CONTEXT SystemContext,\r
1420 IN UINT8 Index\r
1421 )\r
1422/*++\r
1423\r
1424Routine Description:\r
1425\r
1426 Get register value accroding to the system context, and register index\r
1427\r
1428Arguments:\r
1429\r
1430 SystemContext - EBC system context.\r
1431 Index - EBC register index\r
1432\r
1433Returns:\r
1434\r
1435 register value\r
1436\r
1437--*/\r
1438{\r
1439 switch (Index) {\r
1440 case 0:\r
1441 return SystemContext.SystemContextEbc->R0;\r
1442 case 1:\r
1443 return SystemContext.SystemContextEbc->R1;\r
1444 case 2:\r
1445 return SystemContext.SystemContextEbc->R2;\r
1446 case 3:\r
1447 return SystemContext.SystemContextEbc->R3;\r
1448 case 4:\r
1449 return SystemContext.SystemContextEbc->R4;\r
1450 case 5:\r
1451 return SystemContext.SystemContextEbc->R5;\r
1452 case 6:\r
1453 return SystemContext.SystemContextEbc->R6;\r
1454 case 7:\r
1455 return SystemContext.SystemContextEbc->R7;\r
1456 default:\r
1457 ASSERT (FALSE);\r
1458 break;\r
1459 }\r
1460 return 0;\r
1461}\r