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