]>
Commit | Line | Data |
---|---|---|
e8a5ac7c | 1 | /** @file\r |
748edcd5 | 2 | \r |
f42f22f5 | 3 | Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r |
e8a5ac7c | 4 | This program and the accompanying materials\r |
748edcd5 PB |
5 | are licensed and made available under the terms and conditions of the BSD License\r |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
748edcd5 | 12 | \r |
e8a5ac7c | 13 | **/\r |
748edcd5 PB |
14 | \r |
15 | #include "Edb.h"\r | |
16 | \r | |
17 | extern EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable[];\r | |
18 | \r | |
19 | typedef 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 | |
25 | EDB_INSTRUCTION_STRING mInstructionString;\r | |
26 | UINTN mInstructionNameOffset;\r | |
27 | UINTN mInstructionContentOffset;\r | |
28 | \r | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
37 | VOID\r |
38 | EdbSetOffset (\r | |
39 | IN UINTN InstructionNameOffset,\r | |
40 | IN UINTN InstructionContentOffset\r | |
41 | )\r | |
748edcd5 PB |
42 | {\r |
43 | mInstructionNameOffset = InstructionNameOffset;\r | |
44 | mInstructionContentOffset = InstructionContentOffset;\r | |
45 | \r | |
46 | return ;\r | |
47 | }\r | |
48 | \r | |
e8a5ac7c DB |
49 | /**\r |
50 | \r | |
51 | Pre instruction string construction.\r | |
52 | \r | |
53 | @return Instruction string\r | |
54 | \r | |
55 | **/\r | |
748edcd5 PB |
56 | CHAR16 *\r |
57 | EdbPreInstructionString (\r | |
58 | VOID\r | |
59 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
68 | /**\r |
69 | \r | |
70 | Post instruction string construction.\r | |
71 | \r | |
72 | @return Instruction string\r | |
73 | \r | |
74 | **/\r | |
748edcd5 PB |
75 | CHAR16 *\r |
76 | EdbPostInstructionString (\r | |
77 | VOID\r | |
78 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
106 | BOOLEAN\r |
107 | EdbGetNaturalIndex16 (\r | |
108 | IN UINT16 Data16,\r | |
109 | OUT UINTN *NaturalUnits,\r | |
110 | OUT UINTN *ConstantUnits\r | |
111 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
137 | BOOLEAN\r |
138 | EdbGetNaturalIndex32 (\r | |
139 | IN UINT32 Data32,\r | |
140 | OUT UINTN *NaturalUnits,\r | |
141 | OUT UINTN *ConstantUnits\r | |
142 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
168 | BOOLEAN\r |
169 | EdbGetNaturalIndex64 (\r | |
170 | IN UINT64 Data64,\r | |
171 | OUT UINT64 *NaturalUnits,\r | |
172 | OUT UINT64 *ConstantUnits\r | |
173 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 188 | /**\r |
748edcd5 | 189 | \r |
e8a5ac7c | 190 | Get Bit Width of the value.\r |
748edcd5 | 191 | \r |
e8a5ac7c | 192 | @param Value - data\r |
748edcd5 | 193 | \r |
e8a5ac7c | 194 | @return Bit width\r |
748edcd5 | 195 | \r |
e8a5ac7c DB |
196 | **/\r |
197 | UINT8\r | |
198 | EdbGetBitWidth (\r | |
199 | IN UINT64 Value\r | |
200 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 233 | /**\r |
748edcd5 | 234 | \r |
e8a5ac7c | 235 | Print the instruction name.\r |
748edcd5 | 236 | \r |
e8a5ac7c | 237 | @param Name - instruction name\r |
748edcd5 | 238 | \r |
e8a5ac7c | 239 | @return Instruction name offset\r |
748edcd5 | 240 | \r |
e8a5ac7c DB |
241 | **/\r |
242 | UINTN\r | |
243 | EdbPrintInstructionName (\r | |
244 | IN CHAR16 *Name\r | |
245 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 259 | /**\r |
748edcd5 | 260 | \r |
e8a5ac7c | 261 | Print register 1 in operands.\r |
748edcd5 | 262 | \r |
e8a5ac7c | 263 | @param Operands - instruction operands\r |
748edcd5 | 264 | \r |
e8a5ac7c | 265 | @return Instruction content offset\r |
748edcd5 | 266 | \r |
e8a5ac7c DB |
267 | **/\r |
268 | UINTN\r | |
269 | EdbPrintRegister1 (\r | |
270 | IN UINT8 Operands\r | |
271 | )\r | |
748edcd5 | 272 | {\r |
532daaed | 273 | if ((Operands & OPERAND_M_INDIRECT1) != 0) {\r |
748edcd5 PB |
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 | |
e8a5ac7c | 294 | /**\r |
748edcd5 | 295 | \r |
e8a5ac7c | 296 | Print register 2 in operands.\r |
748edcd5 | 297 | \r |
e8a5ac7c | 298 | @param Operands - instruction operands\r |
748edcd5 | 299 | \r |
e8a5ac7c | 300 | @return Instruction content offset\r |
748edcd5 | 301 | \r |
e8a5ac7c DB |
302 | **/\r |
303 | UINTN\r | |
304 | EdbPrintRegister2 (\r | |
305 | IN UINT8 Operands\r | |
306 | )\r | |
748edcd5 | 307 | {\r |
532daaed | 308 | if ((Operands & OPERAND_M_INDIRECT2) != 0) {\r |
748edcd5 PB |
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 | |
e8a5ac7c | 329 | /**\r |
748edcd5 | 330 | \r |
e8a5ac7c | 331 | Print dedicated register 1 in operands.\r |
748edcd5 | 332 | \r |
e8a5ac7c | 333 | @param Operands - instruction operands\r |
748edcd5 | 334 | \r |
e8a5ac7c | 335 | @return Instruction content offset\r |
748edcd5 | 336 | \r |
e8a5ac7c DB |
337 | **/\r |
338 | UINTN\r | |
339 | EdbPrintDedicatedRegister1 (\r | |
340 | IN UINT8 Operands\r | |
341 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 367 | /**\r |
748edcd5 | 368 | \r |
e8a5ac7c | 369 | Print dedicated register 2 in operands.\r |
748edcd5 | 370 | \r |
e8a5ac7c | 371 | @param Operands - instruction operands\r |
748edcd5 | 372 | \r |
e8a5ac7c | 373 | @return Instruction content offset\r |
748edcd5 | 374 | \r |
e8a5ac7c DB |
375 | **/\r |
376 | UINTN\r | |
377 | EdbPrintDedicatedRegister2 (\r | |
378 | IN UINT8 Operands\r | |
379 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
416 | UINTN\r |
417 | EdbPrintIndexData (\r | |
418 | IN BOOLEAN Sign,\r | |
419 | IN UINTN NaturalUnits,\r | |
420 | IN UINTN ConstantUnits\r | |
421 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
449 | UINTN\r |
450 | EdbPrintIndexData64 (\r | |
451 | IN BOOLEAN Sign,\r | |
452 | IN UINT64 NaturalUnits,\r | |
453 | IN UINT64 ConstantUnits\r | |
454 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 471 | /**\r |
748edcd5 | 472 | \r |
e8a5ac7c | 473 | Print the hexical WORD raw index data to instruction content.\r |
748edcd5 | 474 | \r |
e8a5ac7c | 475 | @param Data16 - WORD data\r |
748edcd5 | 476 | \r |
e8a5ac7c | 477 | @return Instruction content offset\r |
748edcd5 | 478 | \r |
e8a5ac7c DB |
479 | **/\r |
480 | UINTN\r | |
481 | EdbPrintRawIndexData16 (\r | |
482 | IN UINT16 Data16\r | |
483 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 496 | /**\r |
748edcd5 | 497 | \r |
e8a5ac7c | 498 | Print the hexical DWORD raw index data to instruction content.\r |
748edcd5 | 499 | \r |
e8a5ac7c | 500 | @param Data32 - DWORD data\r |
748edcd5 | 501 | \r |
e8a5ac7c | 502 | @return Instruction content offset\r |
748edcd5 | 503 | \r |
e8a5ac7c DB |
504 | **/\r |
505 | UINTN\r | |
506 | EdbPrintRawIndexData32 (\r | |
507 | IN UINT32 Data32\r | |
508 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 521 | /**\r |
748edcd5 | 522 | \r |
e8a5ac7c | 523 | Print the hexical QWORD raw index data to instruction content.\r |
748edcd5 | 524 | \r |
e8a5ac7c | 525 | @param Data64 - QWORD data\r |
748edcd5 | 526 | \r |
e8a5ac7c | 527 | @return Instruction content offset\r |
748edcd5 | 528 | \r |
e8a5ac7c DB |
529 | **/\r |
530 | UINTN\r | |
531 | EdbPrintRawIndexData64 (\r | |
532 | IN UINT64 Data64\r | |
533 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 546 | /**\r |
748edcd5 | 547 | \r |
e8a5ac7c | 548 | Print the hexical BYTE immediate data to instruction content.\r |
748edcd5 | 549 | \r |
e8a5ac7c | 550 | @param Data - BYTE data\r |
748edcd5 | 551 | \r |
e8a5ac7c | 552 | @return Instruction content offset\r |
748edcd5 | 553 | \r |
e8a5ac7c DB |
554 | **/\r |
555 | UINTN\r | |
556 | EdbPrintImmData8 (\r | |
557 | IN UINT8 Data\r | |
558 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 572 | /**\r |
748edcd5 | 573 | \r |
e8a5ac7c | 574 | Print the hexical WORD immediate data to instruction content.\r |
748edcd5 | 575 | \r |
e8a5ac7c | 576 | @param Data - WORD data\r |
748edcd5 | 577 | \r |
e8a5ac7c | 578 | @return Instruction content offset\r |
748edcd5 | 579 | \r |
e8a5ac7c DB |
580 | **/\r |
581 | UINTN\r | |
582 | EdbPrintImmData16 (\r | |
583 | IN UINT16 Data\r | |
584 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 598 | /**\r |
748edcd5 | 599 | \r |
e8a5ac7c | 600 | Print the hexical DWORD immediate data to instruction content.\r |
748edcd5 | 601 | \r |
e8a5ac7c | 602 | @param Data - DWORD data\r |
748edcd5 | 603 | \r |
e8a5ac7c | 604 | @return Instruction content offset\r |
748edcd5 | 605 | \r |
e8a5ac7c DB |
606 | **/\r |
607 | UINTN\r | |
608 | EdbPrintImmData32 (\r | |
609 | IN UINT32 Data\r | |
610 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 624 | /**\r |
748edcd5 | 625 | \r |
e8a5ac7c | 626 | Print the hexical QWORD immediate data to instruction content.\r |
748edcd5 | 627 | \r |
e8a5ac7c | 628 | @param Data - QWORD data\r |
748edcd5 | 629 | \r |
e8a5ac7c | 630 | @return Instruction content offset\r |
748edcd5 | 631 | \r |
e8a5ac7c DB |
632 | **/\r |
633 | UINTN\r | |
634 | EdbPrintImmData64 (\r | |
635 | IN UINT64 Data\r | |
636 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 650 | /**\r |
748edcd5 | 651 | \r |
e8a5ac7c | 652 | Print the decimal UINTN immediate data to instruction content.\r |
748edcd5 | 653 | \r |
e8a5ac7c | 654 | @param Data - UINTN data\r |
748edcd5 | 655 | \r |
e8a5ac7c | 656 | @return Instruction content offset\r |
748edcd5 | 657 | \r |
e8a5ac7c DB |
658 | **/\r |
659 | UINTN\r | |
660 | EdbPrintImmDatan (\r | |
661 | IN UINTN Data\r | |
662 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 676 | /**\r |
748edcd5 | 677 | \r |
e8a5ac7c | 678 | Print the decimal QWORD immediate data to instruction content.\r |
748edcd5 | 679 | \r |
e8a5ac7c | 680 | @param Data64 - QWORD data\r |
748edcd5 | 681 | \r |
e8a5ac7c | 682 | @return Instruction content offset\r |
748edcd5 | 683 | \r |
e8a5ac7c DB |
684 | **/\r |
685 | UINTN\r | |
686 | EdbPrintImmData64n (\r | |
687 | IN UINT64 Data64\r | |
688 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 702 | /**\r |
748edcd5 | 703 | \r |
e8a5ac7c | 704 | Print the hexical BYTE to instruction content.\r |
748edcd5 | 705 | \r |
e8a5ac7c | 706 | @param Data8 - BYTE data\r |
748edcd5 | 707 | \r |
e8a5ac7c | 708 | @return Instruction content offset\r |
748edcd5 | 709 | \r |
e8a5ac7c DB |
710 | **/\r |
711 | UINTN\r | |
712 | EdbPrintData8 (\r | |
713 | IN UINT8 Data8\r | |
714 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 728 | /**\r |
748edcd5 | 729 | \r |
e8a5ac7c | 730 | Print the hexical WORD to instruction content.\r |
748edcd5 | 731 | \r |
e8a5ac7c | 732 | @param Data16 - WORD data\r |
748edcd5 | 733 | \r |
e8a5ac7c | 734 | @return Instruction content offset\r |
748edcd5 | 735 | \r |
e8a5ac7c DB |
736 | **/\r |
737 | UINTN\r | |
738 | EdbPrintData16 (\r | |
739 | IN UINT16 Data16\r | |
740 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 754 | /**\r |
748edcd5 | 755 | \r |
e8a5ac7c | 756 | Print the hexical DWORD to instruction content.\r |
748edcd5 | 757 | \r |
e8a5ac7c | 758 | @param Data32 - DWORD data\r |
748edcd5 | 759 | \r |
e8a5ac7c | 760 | @return Instruction content offset\r |
748edcd5 | 761 | \r |
e8a5ac7c DB |
762 | **/\r |
763 | UINTN\r | |
764 | EdbPrintData32 (\r | |
765 | IN UINT32 Data32\r | |
766 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 780 | /**\r |
748edcd5 | 781 | \r |
e8a5ac7c | 782 | Print the hexical QWORD to instruction content.\r |
748edcd5 | 783 | \r |
e8a5ac7c | 784 | @param Data64 - QWORD data\r |
748edcd5 | 785 | \r |
e8a5ac7c | 786 | @return Instruction content offset\r |
748edcd5 | 787 | \r |
e8a5ac7c DB |
788 | **/\r |
789 | UINTN\r | |
790 | EdbPrintData64 (\r | |
791 | IN UINT64 Data64\r | |
792 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 806 | /**\r |
748edcd5 | 807 | \r |
e8a5ac7c | 808 | Print the decimal unsigned UINTN to instruction content.\r |
748edcd5 | 809 | \r |
e8a5ac7c | 810 | @param Data - unsigned UINTN data\r |
748edcd5 | 811 | \r |
e8a5ac7c | 812 | @return Instruction content offset\r |
748edcd5 | 813 | \r |
e8a5ac7c DB |
814 | **/\r |
815 | UINTN\r | |
816 | EdbPrintDatan (\r | |
817 | IN UINTN Data\r | |
818 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 832 | /**\r |
748edcd5 | 833 | \r |
e8a5ac7c | 834 | Print the decimal unsigned QWORD to instruction content.\r |
748edcd5 | 835 | \r |
e8a5ac7c | 836 | @param Data64 - unsigned QWORD data\r |
748edcd5 | 837 | \r |
e8a5ac7c | 838 | @return Instruction content offset\r |
748edcd5 | 839 | \r |
e8a5ac7c DB |
840 | **/\r |
841 | UINTN\r | |
842 | EdbPrintData64n (\r | |
843 | IN UINT64 Data64\r | |
844 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 858 | /**\r |
748edcd5 | 859 | \r |
e8a5ac7c | 860 | Print the decimal signed BYTE to instruction content.\r |
748edcd5 | 861 | \r |
e8a5ac7c | 862 | @param Data8 - signed BYTE data\r |
748edcd5 | 863 | \r |
e8a5ac7c | 864 | @return Instruction content offset\r |
748edcd5 | 865 | \r |
e8a5ac7c DB |
866 | **/\r |
867 | UINTN\r | |
868 | EdbPrintData8s (\r | |
869 | IN UINT8 Data8\r | |
870 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 889 | /**\r |
748edcd5 | 890 | \r |
e8a5ac7c | 891 | Print the decimal signed WORD to instruction content.\r |
748edcd5 | 892 | \r |
e8a5ac7c | 893 | @param Data16 - signed WORD data\r |
748edcd5 | 894 | \r |
e8a5ac7c | 895 | @return Instruction content offset\r |
748edcd5 | 896 | \r |
e8a5ac7c DB |
897 | **/\r |
898 | UINTN\r | |
899 | EdbPrintData16s (\r | |
900 | IN UINT16 Data16\r | |
901 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 920 | /**\r |
748edcd5 | 921 | \r |
e8a5ac7c | 922 | Print the decimal signed DWORD to instruction content.\r |
748edcd5 | 923 | \r |
e8a5ac7c | 924 | @param Data32 - signed DWORD data\r |
748edcd5 | 925 | \r |
e8a5ac7c | 926 | @return Instruction content offset\r |
748edcd5 | 927 | \r |
e8a5ac7c DB |
928 | **/\r |
929 | UINTN\r | |
930 | EdbPrintData32s (\r | |
931 | IN UINT32 Data32\r | |
932 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 951 | /**\r |
748edcd5 | 952 | \r |
e8a5ac7c | 953 | Print the decimal signed QWORD to instruction content.\r |
748edcd5 | 954 | \r |
e8a5ac7c | 955 | @param Data64 - signed QWORD data\r |
748edcd5 | 956 | \r |
e8a5ac7c | 957 | @return Instruction content offset\r |
748edcd5 | 958 | \r |
e8a5ac7c DB |
959 | **/\r |
960 | UINTN\r | |
961 | EdbPrintData64s (\r | |
962 | IN UINT64 Data64\r | |
963 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
984 | /**\r |
985 | \r | |
986 | Print the comma to instruction content.\r | |
987 | \r | |
988 | @return Instruction content offset\r | |
989 | \r | |
990 | **/\r | |
748edcd5 PB |
991 | UINTN\r |
992 | EdbPrintComma (\r | |
993 | VOID\r | |
994 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c | 1007 | /**\r |
748edcd5 | 1008 | \r |
e8a5ac7c | 1009 | Find the symbol string according to address, then print it.\r |
748edcd5 | 1010 | \r |
e8a5ac7c | 1011 | @param Address - instruction address\r |
748edcd5 | 1012 | \r |
e8a5ac7c DB |
1013 | @retval 1 - symbol string is found and printed\r |
1014 | @retval 0 - symbol string not found\r | |
748edcd5 | 1015 | \r |
e8a5ac7c DB |
1016 | **/\r |
1017 | UINTN\r | |
1018 | EdbFindAndPrintSymbol (\r | |
1019 | IN UINTN Address\r | |
1020 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
1047 | VOID\r |
1048 | EdbPrintRaw (\r | |
1049 | IN EFI_PHYSICAL_ADDRESS InstructionAddress,\r | |
1050 | IN UINTN InstructionNumber\r | |
1051 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
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 | |
748edcd5 PB |
1109 | EFI_STATUS\r |
1110 | EdbShowDisasm (\r | |
1111 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
1112 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
1113 | )\r | |
748edcd5 PB |
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 | |
e8a5ac7c DB |
1179 | /**\r |
1180 | \r | |
24648548 | 1181 | Get register value according to the system context, and register index.\r |
e8a5ac7c DB |
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 | |
748edcd5 PB |
1189 | UINT64\r |
1190 | GetRegisterValue (\r | |
1191 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
1192 | IN UINT8 Index\r | |
1193 | )\r | |
748edcd5 PB |
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 |