]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.c
MdeModulePkg/EbcDxe: add EBC Debugger
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbDisasm.c
1 /*++
2
3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EdbDisasm.c
15
16 Abstract:
17
18
19 --*/
20
21 #include "Edb.h"
22
23 //
24 // Debugger Disasm definition
25 //
26 #define EDB_DISASM_DEFINE(func) \
27 UINTN \
28 func ( \
29 IN EFI_PHYSICAL_ADDRESS InstructionAddress, \
30 IN EFI_SYSTEM_CONTEXT SystemContext, \
31 OUT CHAR16 **DisasmString \
32 )
33
34 EDB_DISASM_DEFINE (EdbDisasmBREAK);
35 EDB_DISASM_DEFINE (EdbDisasmJMP);
36 EDB_DISASM_DEFINE (EdbDisasmJMP8);
37 EDB_DISASM_DEFINE (EdbDisasmCALL);
38 EDB_DISASM_DEFINE (EdbDisasmRET);
39 EDB_DISASM_DEFINE (EdbDisasmCMP);
40 EDB_DISASM_DEFINE (EdbDisasmUnsignedDataManip);
41 EDB_DISASM_DEFINE (EdbDisasmSignedDataManip);
42 EDB_DISASM_DEFINE (EdbDisasmMOVxx);
43 EDB_DISASM_DEFINE (EdbDisasmMOVsnw);
44 EDB_DISASM_DEFINE (EdbDisasmMOVsnd);
45 EDB_DISASM_DEFINE (EdbDisasmLOADSP);
46 EDB_DISASM_DEFINE (EdbDisasmSTORESP);
47 EDB_DISASM_DEFINE (EdbDisasmPUSH);
48 EDB_DISASM_DEFINE (EdbDisasmPOP);
49 EDB_DISASM_DEFINE (EdbDisasmCMPI);
50 EDB_DISASM_DEFINE (EdbDisasmPUSHn);
51 EDB_DISASM_DEFINE (EdbDisasmPOPn);
52 EDB_DISASM_DEFINE (EdbDisasmMOVI);
53 EDB_DISASM_DEFINE (EdbDisasmMOVIn);
54 EDB_DISASM_DEFINE (EdbDisasmMOVREL);
55
56 //
57 // Debugger Disasm Table
58 //
59 EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable[] = {
60 EdbDisasmBREAK, // opcode 0x00 BREAK
61 EdbDisasmJMP, // opcode 0x01 JMP
62 EdbDisasmJMP8, // opcode 0x02 JMP8
63 EdbDisasmCALL, // opcode 0x03 CALL
64 EdbDisasmRET, // opcode 0x04 RET
65 EdbDisasmCMP, // opcode 0x05 CMPEQ
66 EdbDisasmCMP, // opcode 0x06 CMPLTE
67 EdbDisasmCMP, // opcode 0x07 CMPGTE
68 EdbDisasmCMP, // opcode 0x08 CMPULTE
69 EdbDisasmCMP, // opcode 0x09 CMPUGTE
70 EdbDisasmUnsignedDataManip, // opcode 0x0A NOT
71 EdbDisasmSignedDataManip, // opcode 0x0B NEG
72 EdbDisasmSignedDataManip, // opcode 0x0C ADD
73 EdbDisasmSignedDataManip, // opcode 0x0D SUB
74 EdbDisasmSignedDataManip, // opcode 0x0E MUL
75 EdbDisasmUnsignedDataManip, // opcode 0x0F MULU
76 EdbDisasmSignedDataManip, // opcode 0x10 DIV
77 EdbDisasmUnsignedDataManip, // opcode 0x11 DIVU
78 EdbDisasmSignedDataManip, // opcode 0x12 MOD
79 EdbDisasmUnsignedDataManip, // opcode 0x13 MODU
80 EdbDisasmUnsignedDataManip, // opcode 0x14 AND
81 EdbDisasmUnsignedDataManip, // opcode 0x15 OR
82 EdbDisasmUnsignedDataManip, // opcode 0x16 XOR
83 EdbDisasmUnsignedDataManip, // opcode 0x17 SHL
84 EdbDisasmUnsignedDataManip, // opcode 0x18 SHR
85 EdbDisasmSignedDataManip, // opcode 0x19 ASHR
86 EdbDisasmUnsignedDataManip, // opcode 0x1A EXTNDB
87 EdbDisasmUnsignedDataManip, // opcode 0x1B EXTNDW
88 EdbDisasmUnsignedDataManip, // opcode 0x1C EXTNDD
89 EdbDisasmMOVxx, // opcode 0x1D MOVBW
90 EdbDisasmMOVxx, // opcode 0x1E MOVWW
91 EdbDisasmMOVxx, // opcode 0x1F MOVDW
92 EdbDisasmMOVxx, // opcode 0x20 MOVQW
93 EdbDisasmMOVxx, // opcode 0x21 MOVBD
94 EdbDisasmMOVxx, // opcode 0x22 MOVWD
95 EdbDisasmMOVxx, // opcode 0x23 MOVDD
96 EdbDisasmMOVxx, // opcode 0x24 MOVQD
97 EdbDisasmMOVsnw, // opcode 0x25 MOVSNW
98 EdbDisasmMOVsnd, // opcode 0x26 MOVSND
99 NULL, // opcode 0x27
100 EdbDisasmMOVxx, // opcode 0x28 MOVQQ
101 EdbDisasmLOADSP, // opcode 0x29 LOADSP
102 EdbDisasmSTORESP, // opcode 0x2A STORESP
103 EdbDisasmPUSH, // opcode 0x2B PUSH
104 EdbDisasmPOP, // opcode 0x2C POP
105 EdbDisasmCMPI, // opcode 0x2D CMPIEQ
106 EdbDisasmCMPI, // opcode 0x2E CMPILTE
107 EdbDisasmCMPI, // opcode 0x2F CMPIGTE
108 EdbDisasmCMPI, // opcode 0x30 CMPIULTE
109 EdbDisasmCMPI, // opcode 0x31 CMPIUGTE
110 EdbDisasmMOVxx, // opcode 0x32 MOVNW
111 EdbDisasmMOVxx, // opcode 0x33 MOVND
112 NULL, // opcode 0x34
113 EdbDisasmPUSHn, // opcode 0x35 PUSHN
114 EdbDisasmPOPn, // opcode 0x36 POPN
115 EdbDisasmMOVI, // opcode 0x37 MOVI
116 EdbDisasmMOVIn, // opcode 0x38 MOVIN
117 EdbDisasmMOVREL, // opcode 0x39 MOVREL
118 };
119
120 UINTN
121 EdbDisasmBREAK (
122 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
123 IN EFI_SYSTEM_CONTEXT SystemContext,
124 OUT CHAR16 **DisasmString
125 )
126 /*++
127
128 Routine Description:
129
130 Disasm instruction - BREAK
131
132 Arguments:
133
134 InstructionAddress - The instruction address
135 SystemContext - EBC system context.
136 DisasmString - The instruction string
137
138 Returns:
139
140 Instruction length
141
142 --*/
143 {
144 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_BREAK);
145
146 if (*(UINT8 *)(UINTN)(InstructionAddress + 1) > 6) {
147 return 0;
148 }
149
150 //
151 // Construct Disasm String
152 //
153 if (DisasmString != NULL) {
154 *DisasmString = EdbPreInstructionString ();
155
156 EdbPrintInstructionName (L"BREAK");
157 EdbPrintDatan (*(UINT8 *)(UINTN)(InstructionAddress + 1));
158
159 EdbPostInstructionString ();
160 }
161
162 return 2;
163 }
164
165 extern CONST UINT8 mJMPLen[];
166
167 UINTN
168 EdbDisasmJMP (
169 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
170 IN EFI_SYSTEM_CONTEXT SystemContext,
171 OUT CHAR16 **DisasmString
172 )
173 /*++
174
175 Routine Description:
176
177 Disasm instruction - JMP
178
179 Arguments:
180
181 InstructionAddress - The instruction address
182 SystemContext - EBC system context.
183 DisasmString - The instruction string
184
185 Returns:
186
187 Instruction length
188
189 --*/
190 {
191 UINT8 Modifiers;
192 UINT8 Operands;
193 UINTN Size;
194 UINT32 Data32;
195 UINT64 Data64;
196
197 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_JMP);
198
199 Modifiers = GET_MODIFIERS (InstructionAddress);
200 Operands = GET_OPERANDS (InstructionAddress);
201 Size = (UINTN)mJMPLen[(Modifiers >> 6) & 0x03];
202
203 //
204 // Construct Disasm String
205 //
206 if (DisasmString != NULL) {
207 *DisasmString = EdbPreInstructionString ();
208
209 EdbPrintInstructionName (L"JMP");
210 // if (Modifiers & OPCODE_M_IMMDATA64) {
211 // EdbPrintInstructionName (L"64");
212 // } else {
213 // EdbPrintInstructionName (L"32");
214 // }
215 if (Modifiers & CONDITION_M_CONDITIONAL) {
216 if (Modifiers & JMP_M_CS) {
217 EdbPrintInstructionName (L"cs");
218 } else {
219 EdbPrintInstructionName (L"cc");
220 }
221 }
222
223 InstructionAddress += 2;
224 if (Modifiers & OPCODE_M_IMMDATA64) {
225 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
226 if (Modifiers & OPCODE_M_IMMDATA) {
227 EdbPrintData64 (Data64);
228 } else {
229 return 0;
230 }
231 } else {
232 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
233 EdbPrintRegister1 (Operands);
234
235 if ((Operands & OPERAND_M_INDIRECT1) == 0) {
236 if ((Modifiers & OPCODE_M_IMMDATA) == 0) {
237 Data32 = 0;
238 }
239 EdbPrintImmDatan (Data32);
240 } else {
241 EdbPrintRawIndexData32 (Data32);
242 }
243 }
244
245 EdbPostInstructionString ();
246 }
247
248 return Size;
249 }
250
251 UINTN
252 EdbDisasmJMP8 (
253 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
254 IN EFI_SYSTEM_CONTEXT SystemContext,
255 OUT CHAR16 **DisasmString
256 )
257 /*++
258
259 Routine Description:
260
261 Disasm instruction - JMP8
262
263 Arguments:
264
265 InstructionAddress - The instruction address
266 SystemContext - EBC system context.
267 DisasmString - The instruction string
268
269 Returns:
270
271 Instruction length
272
273 --*/
274 {
275 UINT8 Modifiers;
276
277 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_JMP8);
278 Modifiers = GET_MODIFIERS (InstructionAddress);
279
280 //
281 // Construct Disasm String
282 //
283 if (DisasmString != NULL) {
284 *DisasmString = EdbPreInstructionString ();
285
286 EdbPrintInstructionName (L"JMP8");
287 if (Modifiers & CONDITION_M_CONDITIONAL) {
288 if (Modifiers & JMP_M_CS) {
289 EdbPrintInstructionName (L"cs");
290 } else {
291 EdbPrintInstructionName (L"cc");
292 }
293 }
294
295 EdbPrintData8 (*(UINT8 *)(UINTN)(InstructionAddress + 1));
296
297 EdbPostInstructionString ();
298 }
299
300 return 2;
301 }
302
303 UINTN
304 EdbDisasmCALL (
305 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
306 IN EFI_SYSTEM_CONTEXT SystemContext,
307 OUT CHAR16 **DisasmString
308 )
309 /*++
310
311 Routine Description:
312
313 Disasm instruction - CALL
314
315 Arguments:
316
317 InstructionAddress - The instruction address
318 SystemContext - EBC system context.
319 DisasmString - The instruction string
320
321 Returns:
322
323 Instruction length
324
325 --*/
326 {
327 UINT8 Modifiers;
328 UINT8 Operands;
329 UINTN Size;
330 UINT32 Data32;
331 UINT64 Data64;
332 UINT64 Ip;
333 UINTN Result;
334 EFI_PHYSICAL_ADDRESS SavedInstructionAddress;
335
336 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_CALL);
337 SavedInstructionAddress = InstructionAddress;
338
339 Modifiers = GET_MODIFIERS (InstructionAddress);
340 Operands = GET_OPERANDS (InstructionAddress);
341 Size = (UINTN)mJMPLen[(Modifiers >> 6) & 0x03];
342
343 //
344 // Construct Disasm String
345 //
346 if (DisasmString != NULL) {
347 *DisasmString = EdbPreInstructionString ();
348
349 EdbPrintInstructionName (L"CALL");
350 // if (Modifiers & OPCODE_M_IMMDATA64) {
351 // EdbPrintInstructionName (L"64");
352 // } else {
353 // EdbPrintInstructionName (L"32");
354 // }
355 if (Operands & OPERAND_M_NATIVE_CALL) {
356 EdbPrintInstructionName (L"EX");
357 }
358 // if ((Operands & OPERAND_M_RELATIVE_ADDR) == 0) {
359 // EdbPrintInstructionName (L"a");
360 // }
361
362 InstructionAddress += 2;
363 if (Modifiers & OPCODE_M_IMMDATA64) {
364 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
365 Ip = Data64;
366 if (Modifiers & OPCODE_M_IMMDATA) {
367 Result = EdbFindAndPrintSymbol ((UINTN)Ip);
368 if (Result == 0) {
369 EdbPrintData64 (Data64);
370 }
371 } else {
372 return 0;
373 }
374 } else {
375 if (Modifiers & OPCODE_M_IMMDATA) {
376 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
377 } else {
378 Data32 = 0;
379 }
380
381 if ((Operands & OPERAND_M_OP1) == 0) {
382 Ip = (UINT64)Data32;
383 } else {
384 Ip = GetRegisterValue (SystemContext, (Operands & OPERAND_M_OP1));
385 }
386
387 if ((Operands & OPERAND_M_INDIRECT1) == 0) {
388 if (Operands & OPERAND_M_RELATIVE_ADDR) {
389 Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Ip + Size));
390 } else {
391 Result = EdbFindAndPrintSymbol ((UINTN)Ip);
392 }
393 if (Result == 0) {
394 EdbPrintRegister1 (Operands);
395 if (Modifiers & OPCODE_M_IMMDATA) {
396 EdbPrintImmData32 (Data32);
397 }
398 }
399 } else {
400 EdbPrintRegister1 (Operands);
401 if (Modifiers & OPCODE_M_IMMDATA) {
402 EdbPrintRawIndexData32 (Data32);
403 }
404 }
405 }
406
407 EdbPostInstructionString ();
408 }
409
410 return Size;
411 }
412
413 UINTN
414 EdbDisasmRET (
415 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
416 IN EFI_SYSTEM_CONTEXT SystemContext,
417 OUT CHAR16 **DisasmString
418 )
419 /*++
420
421 Routine Description:
422
423 Disasm instruction - RET
424
425 Arguments:
426
427 InstructionAddress - The instruction address
428 SystemContext - EBC system context.
429 DisasmString - The instruction string
430
431 Returns:
432
433 Instruction length
434
435 --*/
436 {
437 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_RET);
438
439 if (*(UINT8 *)(UINTN)(InstructionAddress + 1) != 0) {
440 return 0;
441 }
442
443 //
444 // Construct Disasm String
445 //
446 if (DisasmString != NULL) {
447 *DisasmString = EdbPreInstructionString ();
448
449 EdbPrintInstructionName (L"RET");
450
451 EdbPostInstructionString ();
452 }
453
454 return 2;
455 }
456
457 UINTN
458 EdbDisasmCMP (
459 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
460 IN EFI_SYSTEM_CONTEXT SystemContext,
461 OUT CHAR16 **DisasmString
462 )
463 /*++
464
465 Routine Description:
466
467 Disasm instruction - CMP
468
469 Arguments:
470
471 InstructionAddress - The instruction address
472 SystemContext - EBC system context.
473 DisasmString - The instruction string
474
475 Returns:
476
477 Instruction length
478
479 --*/
480 {
481 UINT8 Opcode;
482 UINT8 Modifiers;
483 UINT8 Operands;
484 UINT16 Data16;
485 UINTN Size;
486
487 ASSERT (
488 (GET_OPCODE(InstructionAddress) == OPCODE_CMPEQ) ||
489 (GET_OPCODE(InstructionAddress) == OPCODE_CMPLTE) ||
490 (GET_OPCODE(InstructionAddress) == OPCODE_CMPGTE) ||
491 (GET_OPCODE(InstructionAddress) == OPCODE_CMPULTE) ||
492 (GET_OPCODE(InstructionAddress) == OPCODE_CMPUGTE)
493 );
494
495 Opcode = GET_OPCODE (InstructionAddress);
496 Modifiers = GET_MODIFIERS (InstructionAddress);
497 Operands = GET_OPERANDS (InstructionAddress);
498 if (Modifiers & OPCODE_M_IMMDATA) {
499 Size = 4;
500 } else {
501 Size = 2;
502 }
503
504 //
505 // Construct Disasm String
506 //
507 if (DisasmString != NULL) {
508 *DisasmString = EdbPreInstructionString ();
509
510 EdbPrintInstructionName (L"CMP");
511 // if (Modifiers & OPCODE_M_64BIT) {
512 // EdbPrintInstructionName (L"64");
513 // } else {
514 // EdbPrintInstructionName (L"32");
515 // }
516 switch (Opcode) {
517 case OPCODE_CMPEQ:
518 EdbPrintInstructionName (L"eq");
519 break;
520 case OPCODE_CMPLTE:
521 EdbPrintInstructionName (L"lte");
522 break;
523 case OPCODE_CMPGTE:
524 EdbPrintInstructionName (L"gte");
525 break;
526 case OPCODE_CMPULTE:
527 EdbPrintInstructionName (L"ulte");
528 break;
529 case OPCODE_CMPUGTE:
530 EdbPrintInstructionName (L"ugte");
531 break;
532 }
533
534 EdbPrintRegister1 (Operands);
535 InstructionAddress += 2;
536
537 EdbPrintComma ();
538 EdbPrintRegister2 (Operands);
539
540 if (Modifiers & OPCODE_M_IMMDATA) {
541 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
542 if (Operands & OPERAND_M_INDIRECT2) {
543 EdbPrintRawIndexData16 (Data16);
544 } else {
545 EdbPrintImmDatan (Data16);
546 }
547 }
548
549 EdbPostInstructionString ();
550 }
551
552 return Size;
553 }
554
555 UINTN
556 EdbDisasmUnsignedDataManip (
557 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
558 IN EFI_SYSTEM_CONTEXT SystemContext,
559 OUT CHAR16 **DisasmString
560 )
561 /*++
562
563 Routine Description:
564
565 Disasm instruction - Unsigned Data Manipulate
566
567 Arguments:
568
569 InstructionAddress - The instruction address
570 SystemContext - EBC system context.
571 DisasmString - The instruction string
572
573 Returns:
574
575 Instruction length
576
577 --*/
578 {
579 UINT8 Modifiers;
580 UINT8 Opcode;
581 UINT8 Operands;
582 UINTN Size;
583 UINT16 Data16;
584
585 ASSERT (
586 (GET_OPCODE(InstructionAddress) == OPCODE_NOT) ||
587 (GET_OPCODE(InstructionAddress) == OPCODE_MULU) ||
588 (GET_OPCODE(InstructionAddress) == OPCODE_DIVU) ||
589 (GET_OPCODE(InstructionAddress) == OPCODE_MODU) ||
590 (GET_OPCODE(InstructionAddress) == OPCODE_AND) ||
591 (GET_OPCODE(InstructionAddress) == OPCODE_OR) ||
592 (GET_OPCODE(InstructionAddress) == OPCODE_XOR) ||
593 (GET_OPCODE(InstructionAddress) == OPCODE_SHL) ||
594 (GET_OPCODE(InstructionAddress) == OPCODE_SHR) ||
595 (GET_OPCODE(InstructionAddress) == OPCODE_EXTNDB) ||
596 (GET_OPCODE(InstructionAddress) == OPCODE_EXTNDW) ||
597 (GET_OPCODE(InstructionAddress) == OPCODE_EXTNDD)
598 );
599
600 Opcode = GET_OPCODE (InstructionAddress);
601 Operands = GET_OPERANDS (InstructionAddress);
602 Modifiers = GET_MODIFIERS (InstructionAddress);
603 if (Modifiers & DATAMANIP_M_IMMDATA) {
604 Size = 4;
605 } else {
606 Size = 2;
607 }
608
609 //
610 // Construct Disasm String
611 //
612 if (DisasmString != NULL) {
613 *DisasmString = EdbPreInstructionString ();
614
615 switch (Opcode) {
616 case OPCODE_NOT:
617 EdbPrintInstructionName (L"NOT");
618 break;
619 case OPCODE_MULU:
620 EdbPrintInstructionName (L"MULU");
621 break;
622 case OPCODE_DIVU:
623 EdbPrintInstructionName (L"DIVU");
624 break;
625 case OPCODE_MODU:
626 EdbPrintInstructionName (L"MODU");
627 break;
628 case OPCODE_AND:
629 EdbPrintInstructionName (L"AND");
630 break;
631 case OPCODE_OR:
632 EdbPrintInstructionName (L"OR");
633 break;
634 case OPCODE_XOR:
635 EdbPrintInstructionName (L"XOR");
636 break;
637 case OPCODE_SHL:
638 EdbPrintInstructionName (L"SHL");
639 break;
640 case OPCODE_SHR:
641 EdbPrintInstructionName (L"SHR");
642 break;
643 case OPCODE_EXTNDB:
644 EdbPrintInstructionName (L"EXTNDB");
645 break;
646 case OPCODE_EXTNDW:
647 EdbPrintInstructionName (L"EXTNDW");
648 break;
649 case OPCODE_EXTNDD:
650 EdbPrintInstructionName (L"EXTNDD");
651 break;
652 }
653 // if (Modifiers & DATAMANIP_M_64) {
654 // EdbPrintInstructionName (L"64");
655 // } else {
656 // EdbPrintInstructionName (L"32");
657 // }
658
659 EdbPrintRegister1 (Operands);
660 EdbPrintComma ();
661 EdbPrintRegister2 (Operands);
662
663 InstructionAddress += 2;
664 if (Modifiers & DATAMANIP_M_IMMDATA) {
665 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
666 if (Operands & OPERAND_M_INDIRECT2) {
667 EdbPrintRawIndexData16 (Data16);
668 } else {
669 EdbPrintImmDatan (Data16);
670 }
671 }
672
673 EdbPostInstructionString ();
674 }
675
676 return Size;
677 }
678
679 UINTN
680 EdbDisasmSignedDataManip (
681 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
682 IN EFI_SYSTEM_CONTEXT SystemContext,
683 OUT CHAR16 **DisasmString
684 )
685 /*++
686
687 Routine Description:
688
689 Disasm instruction - Signed Data Manipulate
690
691 Arguments:
692
693 InstructionAddress - The instruction address
694 SystemContext - EBC system context.
695 DisasmString - The instruction string
696
697 Returns:
698
699 Instruction length
700
701 --*/
702 {
703 UINT8 Modifiers;
704 UINT8 Opcode;
705 UINT8 Operands;
706 UINTN Size;
707 UINT16 Data16;
708
709 ASSERT (
710 (GET_OPCODE(InstructionAddress) == OPCODE_NEG) ||
711 (GET_OPCODE(InstructionAddress) == OPCODE_ADD) ||
712 (GET_OPCODE(InstructionAddress) == OPCODE_SUB) ||
713 (GET_OPCODE(InstructionAddress) == OPCODE_MUL) ||
714 (GET_OPCODE(InstructionAddress) == OPCODE_DIV) ||
715 (GET_OPCODE(InstructionAddress) == OPCODE_MOD) ||
716 (GET_OPCODE(InstructionAddress) == OPCODE_ASHR)
717 );
718
719 Opcode = GET_OPCODE (InstructionAddress);
720 Operands = GET_OPERANDS (InstructionAddress);
721 Modifiers = GET_MODIFIERS (InstructionAddress);
722 if (Modifiers & DATAMANIP_M_IMMDATA) {
723 Size = 4;
724 } else {
725 Size = 2;
726 }
727
728 //
729 // Construct Disasm String
730 //
731 if (DisasmString != NULL) {
732 *DisasmString = EdbPreInstructionString ();
733
734 switch (Opcode) {
735 case OPCODE_NEG:
736 EdbPrintInstructionName (L"NEG");
737 break;
738 case OPCODE_ADD:
739 EdbPrintInstructionName (L"ADD");
740 break;
741 case OPCODE_SUB:
742 EdbPrintInstructionName (L"SUB");
743 break;
744 case OPCODE_MUL:
745 EdbPrintInstructionName (L"MUL");
746 break;
747 case OPCODE_DIV:
748 EdbPrintInstructionName (L"DIV");
749 break;
750 case OPCODE_MOD:
751 EdbPrintInstructionName (L"MOD");
752 break;
753 case OPCODE_ASHR:
754 EdbPrintInstructionName (L"ASHR");
755 break;
756 }
757 // if (Modifiers & DATAMANIP_M_64) {
758 // EdbPrintInstructionName (L"64");
759 // } else {
760 // EdbPrintInstructionName (L"32");
761 // }
762
763 EdbPrintRegister1 (Operands);
764 EdbPrintComma ();
765 EdbPrintRegister2 (Operands);
766
767 InstructionAddress += 2;
768 if (Modifiers & DATAMANIP_M_IMMDATA) {
769 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
770 if (Operands & OPERAND_M_INDIRECT2) {
771 EdbPrintRawIndexData16 (Data16);
772 } else {
773 EdbPrintImmDatan (Data16);
774 }
775 }
776
777 EdbPostInstructionString ();
778 }
779
780 return Size;
781 }
782
783 UINTN
784 EdbDisasmMOVxx (
785 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
786 IN EFI_SYSTEM_CONTEXT SystemContext,
787 OUT CHAR16 **DisasmString
788 )
789 /*++
790
791 Routine Description:
792
793 Disasm instruction - MOVxx
794
795 Arguments:
796
797 InstructionAddress - The instruction address
798 SystemContext - EBC system context.
799 DisasmString - The instruction string
800
801 Returns:
802
803 Instruction length
804
805 --*/
806 {
807 UINT8 Modifiers;
808 UINT8 Opcode;
809 UINT8 Operands;
810 UINTN Size;
811 UINT16 Data16;
812 UINT32 Data32;
813 UINT64 Data64;
814
815 ASSERT (
816 (GET_OPCODE(InstructionAddress) == OPCODE_MOVBW) ||
817 (GET_OPCODE(InstructionAddress) == OPCODE_MOVWW) ||
818 (GET_OPCODE(InstructionAddress) == OPCODE_MOVDW) ||
819 (GET_OPCODE(InstructionAddress) == OPCODE_MOVQW) ||
820 (GET_OPCODE(InstructionAddress) == OPCODE_MOVBD) ||
821 (GET_OPCODE(InstructionAddress) == OPCODE_MOVWD) ||
822 (GET_OPCODE(InstructionAddress) == OPCODE_MOVDD) ||
823 (GET_OPCODE(InstructionAddress) == OPCODE_MOVQD) ||
824 (GET_OPCODE(InstructionAddress) == OPCODE_MOVQQ) ||
825 (GET_OPCODE(InstructionAddress) == OPCODE_MOVNW) ||
826 (GET_OPCODE(InstructionAddress) == OPCODE_MOVND)
827 );
828
829 Opcode = GET_OPCODE (InstructionAddress);
830 Modifiers = GET_MODIFIERS (InstructionAddress);
831 Operands = GET_OPERANDS (InstructionAddress);
832 Size = 2;
833 if (Modifiers & (OPCODE_M_IMMED_OP1 | OPCODE_M_IMMED_OP2)) {
834 if ((Opcode <= OPCODE_MOVQW) || (Opcode == OPCODE_MOVNW)) {
835 if (Modifiers & OPCODE_M_IMMED_OP1) {
836 Size += 2;
837 }
838 if (Modifiers & OPCODE_M_IMMED_OP2) {
839 Size += 2;
840 }
841 } else if ((Opcode <= OPCODE_MOVQD) || (Opcode == OPCODE_MOVND)) {
842 if (Modifiers & OPCODE_M_IMMED_OP1) {
843 Size += 4;
844 }
845 if (Modifiers & OPCODE_M_IMMED_OP2) {
846 Size += 4;
847 }
848 } else if (Opcode == OPCODE_MOVQQ) {
849 if (Modifiers & OPCODE_M_IMMED_OP1) {
850 Size += 8;
851 }
852 if (Modifiers & OPCODE_M_IMMED_OP2) {
853 Size += 8;
854 }
855 }
856 }
857
858 //
859 // Construct Disasm String
860 //
861 if (DisasmString != NULL) {
862 *DisasmString = EdbPreInstructionString ();
863
864 EdbPrintInstructionName (L"MOV");
865 switch (Opcode) {
866 case OPCODE_MOVBW:
867 EdbPrintInstructionName (L"bw");
868 break;
869 case OPCODE_MOVWW:
870 EdbPrintInstructionName (L"ww");
871 break;
872 case OPCODE_MOVDW:
873 EdbPrintInstructionName (L"dw");
874 break;
875 case OPCODE_MOVQW:
876 EdbPrintInstructionName (L"qw");
877 break;
878 case OPCODE_MOVBD:
879 EdbPrintInstructionName (L"bd");
880 break;
881 case OPCODE_MOVWD:
882 EdbPrintInstructionName (L"wd");
883 break;
884 case OPCODE_MOVDD:
885 EdbPrintInstructionName (L"dd");
886 break;
887 case OPCODE_MOVQD:
888 EdbPrintInstructionName (L"qd");
889 break;
890 case OPCODE_MOVQQ:
891 EdbPrintInstructionName (L"qq");
892 break;
893 case OPCODE_MOVNW:
894 EdbPrintInstructionName (L"nw");
895 break;
896 case OPCODE_MOVND:
897 EdbPrintInstructionName (L"nd");
898 break;
899 }
900
901 EdbPrintRegister1 (Operands);
902
903 InstructionAddress += 2;
904 if (Modifiers & OPCODE_M_IMMED_OP1) {
905 if ((Opcode <= OPCODE_MOVQW) || (Opcode == OPCODE_MOVNW)) {
906 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
907 InstructionAddress += 2;
908 EdbPrintRawIndexData16 (Data16);
909 } else if ((Opcode <= OPCODE_MOVQD) || (Opcode == OPCODE_MOVND)) {
910 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
911 InstructionAddress += 4;
912 EdbPrintRawIndexData32 (Data32);
913 } else if (Opcode == OPCODE_MOVQQ) {
914 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
915 InstructionAddress += 8;
916 EdbPrintRawIndexData64 (Data64);
917 }
918 }
919
920 EdbPrintComma ();
921 EdbPrintRegister2 (Operands);
922
923 if (Modifiers & OPCODE_M_IMMED_OP2) {
924 if ((Opcode <= OPCODE_MOVQW) || (Opcode == OPCODE_MOVNW)) {
925 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
926 EdbPrintRawIndexData16 (Data16);
927 } else if ((Opcode <= OPCODE_MOVQD) || (Opcode == OPCODE_MOVND)) {
928 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
929 EdbPrintRawIndexData32 (Data32);
930 } else if (Opcode == OPCODE_MOVQQ) {
931 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
932 EdbPrintRawIndexData64 (Data64);
933 }
934 }
935
936 EdbPostInstructionString ();
937 }
938
939 return Size;
940 }
941
942 UINTN
943 EdbDisasmMOVsnw (
944 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
945 IN EFI_SYSTEM_CONTEXT SystemContext,
946 OUT CHAR16 **DisasmString
947 )
948 /*++
949
950 Routine Description:
951
952 Disasm instruction - MOVsnw
953
954 Arguments:
955
956 InstructionAddress - The instruction address
957 SystemContext - EBC system context.
958 DisasmString - The instruction string
959
960 Returns:
961
962 Instruction length
963
964 --*/
965 {
966 UINT8 Modifiers;
967 UINT8 Operands;
968 UINTN Size;
969 UINT16 Data16;
970
971 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVSNW);
972
973 Modifiers = GET_MODIFIERS (InstructionAddress);
974 Operands = GET_OPERANDS (InstructionAddress);
975 Size = 2;
976 if (Modifiers & OPCODE_M_IMMED_OP1) {
977 Size += 2;
978 }
979 if (Modifiers & OPCODE_M_IMMED_OP2) {
980 Size += 2;
981 }
982
983 //
984 // Construct Disasm String
985 //
986 if (DisasmString != NULL) {
987 *DisasmString = EdbPreInstructionString ();
988
989 EdbPrintInstructionName (L"MOVsnw");
990
991 EdbPrintRegister1 (Operands);
992
993 InstructionAddress += 2;
994 if (Modifiers & OPCODE_M_IMMED_OP1) {
995 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
996 InstructionAddress += 2;
997 EdbPrintRawIndexData16 (Data16);
998 }
999
1000 EdbPrintComma ();
1001 EdbPrintRegister2 (Operands);
1002
1003 if (Modifiers & OPCODE_M_IMMED_OP2) {
1004 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1005 if (Operands & OPERAND_M_INDIRECT2) {
1006 EdbPrintRawIndexData16 (Data16);
1007 } else {
1008 EdbPrintImmDatan (Data16);
1009 }
1010 }
1011
1012 EdbPostInstructionString ();
1013 }
1014
1015 return Size;
1016 }
1017
1018 UINTN
1019 EdbDisasmMOVsnd (
1020 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1021 IN EFI_SYSTEM_CONTEXT SystemContext,
1022 OUT CHAR16 **DisasmString
1023 )
1024 /*++
1025
1026 Routine Description:
1027
1028 Disasm instruction - MOVsnd
1029
1030 Arguments:
1031
1032 InstructionAddress - The instruction address
1033 SystemContext - EBC system context.
1034 DisasmString - The instruction string
1035
1036 Returns:
1037
1038 Instruction length
1039
1040 --*/
1041 {
1042 UINT8 Modifiers;
1043 UINT8 Operands;
1044 UINTN Size;
1045 UINT32 Data32;
1046
1047 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVSND);
1048
1049 Modifiers = GET_MODIFIERS (InstructionAddress);
1050 Operands = GET_OPERANDS (InstructionAddress);
1051 Size = 2;
1052 if (Modifiers & OPCODE_M_IMMED_OP1) {
1053 Size += 4;
1054 }
1055 if (Modifiers & OPCODE_M_IMMED_OP2) {
1056 Size += 4;
1057 }
1058
1059 //
1060 // Construct Disasm String
1061 //
1062 if (DisasmString != NULL) {
1063 *DisasmString = EdbPreInstructionString ();
1064
1065 EdbPrintInstructionName (L"MOVsnd");
1066
1067 EdbPrintRegister1 (Operands);
1068
1069 InstructionAddress += 2;
1070 if (Modifiers & OPCODE_M_IMMED_OP1) {
1071 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
1072 InstructionAddress += 4;
1073 EdbPrintRawIndexData32 (Data32);
1074 }
1075
1076 EdbPrintComma ();
1077 EdbPrintRegister2 (Operands);
1078
1079 if (Modifiers & OPCODE_M_IMMED_OP2) {
1080 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
1081 if (Operands & OPERAND_M_INDIRECT2) {
1082 EdbPrintRawIndexData32 (Data32);
1083 } else {
1084 EdbPrintImmDatan (Data32);
1085 }
1086 }
1087
1088 EdbPostInstructionString ();
1089 }
1090
1091 return Size;
1092 }
1093
1094 UINTN
1095 EdbDisasmLOADSP (
1096 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1097 IN EFI_SYSTEM_CONTEXT SystemContext,
1098 OUT CHAR16 **DisasmString
1099 )
1100 /*++
1101
1102 Routine Description:
1103
1104 Disasm instruction - LOADSP
1105
1106 Arguments:
1107
1108 InstructionAddress - The instruction address
1109 SystemContext - EBC system context.
1110 DisasmString - The instruction string
1111
1112 Returns:
1113
1114 Instruction length
1115
1116 --*/
1117 {
1118 UINT8 Operands;
1119
1120 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_LOADSP);
1121
1122 Operands = GET_OPERANDS (InstructionAddress);
1123
1124 //
1125 // Construct Disasm String
1126 //
1127 if (DisasmString != NULL) {
1128 *DisasmString = EdbPreInstructionString ();
1129
1130 EdbPrintInstructionName (L"LOADSP");
1131
1132 EdbPrintDedicatedRegister1 (Operands);
1133
1134 EdbPrintRegister2 (Operands);
1135
1136 EdbPostInstructionString ();
1137 }
1138
1139 return 2;
1140 }
1141
1142 UINTN
1143 EdbDisasmSTORESP (
1144 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1145 IN EFI_SYSTEM_CONTEXT SystemContext,
1146 OUT CHAR16 **DisasmString
1147 )
1148 /*++
1149
1150 Routine Description:
1151
1152 Disasm instruction - STORESP
1153
1154 Arguments:
1155
1156 InstructionAddress - The instruction address
1157 SystemContext - EBC system context.
1158 DisasmString - The instruction string
1159
1160 Returns:
1161
1162 Instruction length
1163
1164 --*/
1165 {
1166 UINT8 Operands;
1167
1168 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_STORESP);
1169
1170 Operands = GET_OPERANDS (InstructionAddress);
1171
1172 //
1173 // Construct Disasm String
1174 //
1175 if (DisasmString != NULL) {
1176 *DisasmString = EdbPreInstructionString ();
1177
1178 EdbPrintInstructionName (L"STORESP");
1179
1180 EdbPrintRegister1 (Operands);
1181
1182 EdbPrintDedicatedRegister2 (Operands);
1183
1184 EdbPostInstructionString ();
1185 }
1186
1187 return 2;
1188 }
1189
1190 UINTN
1191 EdbDisasmPUSH (
1192 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1193 IN EFI_SYSTEM_CONTEXT SystemContext,
1194 OUT CHAR16 **DisasmString
1195 )
1196 /*++
1197
1198 Routine Description:
1199
1200 Disasm instruction - PUSH
1201
1202 Arguments:
1203
1204 InstructionAddress - The instruction address
1205 SystemContext - EBC system context.
1206 DisasmString - The instruction string
1207
1208 Returns:
1209
1210 Instruction length
1211
1212 --*/
1213 {
1214 UINT8 Modifiers;
1215 UINT8 Operands;
1216 UINTN Size;
1217 UINT16 Data16;
1218
1219 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_PUSH);
1220
1221 Operands = GET_OPERANDS (InstructionAddress);
1222 Modifiers = GET_MODIFIERS (InstructionAddress);
1223 if (Modifiers & PUSHPOP_M_IMMDATA) {
1224 Size = 4;
1225 } else {
1226 Size = 2;
1227 }
1228
1229 //
1230 // Construct Disasm String
1231 //
1232 if (DisasmString != NULL) {
1233 *DisasmString = EdbPreInstructionString ();
1234
1235 EdbPrintInstructionName (L"PUSH");
1236 // if (Modifiers & PUSHPOP_M_64) {
1237 // EdbPrintInstructionName (L"64");
1238 // } else {
1239 // EdbPrintInstructionName (L"32");
1240 // }
1241
1242 EdbPrintRegister1 (Operands);
1243
1244 InstructionAddress += 2;
1245 if (Modifiers & PUSHPOP_M_IMMDATA) {
1246 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1247 if (Operands & OPERAND_M_INDIRECT1) {
1248 EdbPrintRawIndexData16 (Data16);
1249 } else {
1250 EdbPrintImmDatan (Data16);
1251 }
1252 }
1253
1254 EdbPostInstructionString ();
1255 }
1256
1257 return Size;
1258 }
1259
1260 UINTN
1261 EdbDisasmPOP (
1262 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1263 IN EFI_SYSTEM_CONTEXT SystemContext,
1264 OUT CHAR16 **DisasmString
1265 )
1266 /*++
1267
1268 Routine Description:
1269
1270 Disasm instruction - POP
1271
1272 Arguments:
1273
1274 InstructionAddress - The instruction address
1275 SystemContext - EBC system context.
1276 DisasmString - The instruction string
1277
1278 Returns:
1279
1280 Instruction length
1281
1282 --*/
1283 {
1284 UINT8 Modifiers;
1285 UINT8 Operands;
1286 UINTN Size;
1287 UINT16 Data16;
1288
1289 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_POP);
1290
1291 Operands = GET_OPERANDS (InstructionAddress);
1292 Modifiers = GET_MODIFIERS (InstructionAddress);
1293 if (Modifiers & PUSHPOP_M_IMMDATA) {
1294 Size = 4;
1295 } else {
1296 Size = 2;
1297 }
1298
1299 //
1300 // Construct Disasm String
1301 //
1302 if (DisasmString != NULL) {
1303 *DisasmString = EdbPreInstructionString ();
1304
1305 EdbPrintInstructionName (L"POP");
1306 // if (Modifiers & PUSHPOP_M_64) {
1307 // EdbPrintInstructionName (L"64");
1308 // } else {
1309 // EdbPrintInstructionName (L"32");
1310 // }
1311
1312 EdbPrintRegister1 (Operands);
1313
1314 InstructionAddress += 2;
1315 if (Modifiers & PUSHPOP_M_IMMDATA) {
1316 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1317 if (Operands & OPERAND_M_INDIRECT1) {
1318 EdbPrintRawIndexData16 (Data16);
1319 } else {
1320 EdbPrintImmDatan (Data16);
1321 }
1322 }
1323
1324 EdbPostInstructionString ();
1325 }
1326
1327 return Size;
1328 }
1329
1330 UINTN
1331 EdbDisasmCMPI (
1332 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1333 IN EFI_SYSTEM_CONTEXT SystemContext,
1334 OUT CHAR16 **DisasmString
1335 )
1336 /*++
1337
1338 Routine Description:
1339
1340 Disasm instruction - CMPI
1341
1342 Arguments:
1343
1344 InstructionAddress - The instruction address
1345 SystemContext - EBC system context.
1346 DisasmString - The instruction string
1347
1348 Returns:
1349
1350 Instruction length
1351
1352 --*/
1353 {
1354 UINT8 Modifiers;
1355 UINT8 Opcode;
1356 UINT8 Operands;
1357 UINT16 Data16;
1358 UINT32 Data32;
1359 UINTN Size;
1360
1361 ASSERT (
1362 (GET_OPCODE(InstructionAddress) == OPCODE_CMPIEQ) ||
1363 (GET_OPCODE(InstructionAddress) == OPCODE_CMPILTE) ||
1364 (GET_OPCODE(InstructionAddress) == OPCODE_CMPIGTE) ||
1365 (GET_OPCODE(InstructionAddress) == OPCODE_CMPIULTE) ||
1366 (GET_OPCODE(InstructionAddress) == OPCODE_CMPIUGTE)
1367 );
1368
1369 Modifiers = GET_MODIFIERS (InstructionAddress);
1370 Opcode = GET_OPCODE (InstructionAddress);
1371 Operands = GET_OPERANDS (InstructionAddress);
1372
1373 if ((Operands & 0xE0) != 0) {
1374 return 0;
1375 }
1376
1377 Size = 2;
1378 if (Operands & OPERAND_M_CMPI_INDEX) {
1379 Size += 2;
1380 }
1381 if (Modifiers & OPCODE_M_CMPI32_DATA) {
1382 Size += 4;
1383 } else {
1384 Size += 2;
1385 }
1386
1387 //
1388 // Construct Disasm String
1389 //
1390 if (DisasmString != NULL) {
1391 *DisasmString = EdbPreInstructionString ();
1392
1393 EdbPrintInstructionName (L"CMPI");
1394 // if (Modifiers & OPCODE_M_CMPI64) {
1395 // EdbPrintInstructionName (L"64");
1396 // } else {
1397 // EdbPrintInstructionName (L"32");
1398 // }
1399 if (Modifiers & OPCODE_M_CMPI32_DATA) {
1400 EdbPrintInstructionName (L"d");
1401 } else {
1402 EdbPrintInstructionName (L"w");
1403 }
1404 switch (Opcode) {
1405 case OPCODE_CMPIEQ:
1406 EdbPrintInstructionName (L"eq");
1407 break;
1408 case OPCODE_CMPILTE:
1409 EdbPrintInstructionName (L"lte");
1410 break;
1411 case OPCODE_CMPIGTE:
1412 EdbPrintInstructionName (L"gte");
1413 break;
1414 case OPCODE_CMPIULTE:
1415 EdbPrintInstructionName (L"ulte");
1416 break;
1417 case OPCODE_CMPIUGTE:
1418 EdbPrintInstructionName (L"ugte");
1419 break;
1420 }
1421
1422 EdbPrintRegister1 (Operands);
1423
1424 InstructionAddress += 2;
1425 if (Operands & OPERAND_M_CMPI_INDEX) {
1426 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1427 InstructionAddress += 2;
1428 EdbPrintRawIndexData16 (Data16);
1429 }
1430
1431 EdbPrintComma ();
1432
1433 if (Modifiers & OPCODE_M_CMPI32_DATA) {
1434 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
1435 EdbPrintDatan (Data32);
1436 } else {
1437 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1438 EdbPrintDatan (Data16);
1439 }
1440
1441 EdbPostInstructionString ();
1442 }
1443
1444 return Size;
1445 }
1446
1447 UINTN
1448 EdbDisasmPUSHn (
1449 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1450 IN EFI_SYSTEM_CONTEXT SystemContext,
1451 OUT CHAR16 **DisasmString
1452 )
1453 /*++
1454
1455 Routine Description:
1456
1457 Disasm instruction - PUSHn
1458
1459 Arguments:
1460
1461 InstructionAddress - The instruction address
1462 SystemContext - EBC system context.
1463 DisasmString - The instruction string
1464
1465 Returns:
1466
1467 Instruction length
1468
1469 --*/
1470 {
1471 UINT8 Modifiers;
1472 UINT8 Operands;
1473 UINTN Size;
1474 UINT16 Data16;
1475
1476 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_PUSHN);
1477
1478 Operands = GET_OPERANDS (InstructionAddress);
1479 Modifiers = GET_MODIFIERS (InstructionAddress);
1480 if (Modifiers & PUSHPOP_M_IMMDATA) {
1481 Size = 4;
1482 } else {
1483 Size = 2;
1484 }
1485
1486 //
1487 // Construct Disasm String
1488 //
1489 if (DisasmString != NULL) {
1490 *DisasmString = EdbPreInstructionString ();
1491
1492 EdbPrintInstructionName (L"PUSHn");
1493
1494 EdbPrintRegister1 (Operands);
1495
1496 InstructionAddress += 2;
1497 if (Modifiers & PUSHPOP_M_IMMDATA) {
1498 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1499 if (Operands & OPERAND_M_INDIRECT1) {
1500 EdbPrintRawIndexData16 (Data16);
1501 } else {
1502 EdbPrintImmDatan (Data16);
1503 }
1504 }
1505
1506 EdbPostInstructionString ();
1507 }
1508
1509 return Size;
1510 }
1511
1512 UINTN
1513 EdbDisasmPOPn (
1514 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1515 IN EFI_SYSTEM_CONTEXT SystemContext,
1516 OUT CHAR16 **DisasmString
1517 )
1518 /*++
1519
1520 Routine Description:
1521
1522 Disasm instruction - POPn
1523
1524 Arguments:
1525
1526 InstructionAddress - The instruction address
1527 SystemContext - EBC system context.
1528 DisasmString - The instruction string
1529
1530 Returns:
1531
1532 Instruction length
1533
1534 --*/
1535 {
1536 UINT8 Modifiers;
1537 UINT8 Operands;
1538 UINTN Size;
1539 UINT16 Data16;
1540
1541 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_POPN);
1542
1543 Operands = GET_OPERANDS (InstructionAddress);
1544 Modifiers = GET_MODIFIERS (InstructionAddress);
1545 if (Modifiers & PUSHPOP_M_IMMDATA) {
1546 Size = 4;
1547 } else {
1548 Size = 2;
1549 }
1550
1551 //
1552 // Construct Disasm String
1553 //
1554 if (DisasmString != NULL) {
1555 *DisasmString = EdbPreInstructionString ();
1556
1557 EdbPrintInstructionName (L"POPn");
1558
1559 EdbPrintRegister1 (Operands);
1560
1561 InstructionAddress += 2;
1562 if (Modifiers & PUSHPOP_M_IMMDATA) {
1563 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1564 if (Operands & OPERAND_M_INDIRECT1) {
1565 EdbPrintRawIndexData16 (Data16);
1566 } else {
1567 EdbPrintImmDatan (Data16);
1568 }
1569 }
1570
1571 EdbPostInstructionString ();
1572 }
1573
1574 return Size;
1575 }
1576
1577 UINTN
1578 EdbDisasmMOVI (
1579 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1580 IN EFI_SYSTEM_CONTEXT SystemContext,
1581 OUT CHAR16 **DisasmString
1582 )
1583 /*++
1584
1585 Routine Description:
1586
1587 Disasm instruction - MOVI
1588
1589 Arguments:
1590
1591 InstructionAddress - The instruction address
1592 SystemContext - EBC system context.
1593 DisasmString - The instruction string
1594
1595 Returns:
1596
1597 Instruction length
1598
1599 --*/
1600 {
1601 UINT8 Modifiers;
1602 UINT8 Operands;
1603 UINTN Size;
1604 UINT16 Data16;
1605 UINT32 Data32;
1606 UINT64 Data64;
1607
1608 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVI);
1609
1610 Modifiers = GET_MODIFIERS (InstructionAddress);
1611 Operands = GET_OPERANDS (InstructionAddress);
1612
1613 if (Operands & MOVI_M_IMMDATA) {
1614 Size = 4;
1615 } else {
1616 Size = 2;
1617 }
1618 if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {
1619 Size += 2;
1620 } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {
1621 Size += 4;
1622 } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {
1623 Size += 8;
1624 }
1625
1626 //
1627 // Construct Disasm String
1628 //
1629 if (DisasmString != NULL) {
1630 *DisasmString = EdbPreInstructionString ();
1631
1632 EdbPrintInstructionName (L"MOVI");
1633 switch (Operands & MOVI_M_MOVEWIDTH) {
1634 case MOVI_MOVEWIDTH8:
1635 EdbPrintInstructionName (L"b");
1636 break;
1637 case MOVI_MOVEWIDTH16:
1638 EdbPrintInstructionName (L"w");
1639 break;
1640 case MOVI_MOVEWIDTH32:
1641 EdbPrintInstructionName (L"d");
1642 break;
1643 case MOVI_MOVEWIDTH64:
1644 EdbPrintInstructionName (L"q");
1645 break;
1646 }
1647 switch (Modifiers & MOVI_M_DATAWIDTH) {
1648 case MOVI_DATAWIDTH16:
1649 EdbPrintInstructionName (L"w");
1650 break;
1651 case MOVI_DATAWIDTH32:
1652 EdbPrintInstructionName (L"d");
1653 break;
1654 case MOVI_DATAWIDTH64:
1655 EdbPrintInstructionName (L"q");
1656 break;
1657 }
1658
1659 EdbPrintRegister1 (Operands);
1660
1661 InstructionAddress += 2;
1662 if (Operands & MOVI_M_IMMDATA) {
1663 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1664 InstructionAddress += 2;
1665 EdbPrintRawIndexData16 (Data16);
1666 }
1667
1668 EdbPrintComma ();
1669
1670 switch (Modifiers & MOVI_M_DATAWIDTH) {
1671 case MOVI_DATAWIDTH16:
1672 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1673 EdbPrintDatan (Data16);
1674 break;
1675 case MOVI_DATAWIDTH32:
1676 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
1677 EdbPrintDatan (Data32);
1678 break;
1679 case MOVI_DATAWIDTH64:
1680 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
1681 EdbPrintData64n (Data64);
1682 break;
1683 }
1684
1685 EdbPostInstructionString ();
1686 }
1687
1688 return Size;
1689 }
1690
1691 UINTN
1692 EdbDisasmMOVIn (
1693 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1694 IN EFI_SYSTEM_CONTEXT SystemContext,
1695 OUT CHAR16 **DisasmString
1696 )
1697 /*++
1698
1699 Routine Description:
1700
1701 Disasm instruction - MOVIn
1702
1703 Arguments:
1704
1705 InstructionAddress - The instruction address
1706 SystemContext - EBC system context.
1707 DisasmString - The instruction string
1708
1709 Returns:
1710
1711 Instruction length
1712
1713 --*/
1714 {
1715 UINT8 Modifiers;
1716 UINT8 Operands;
1717 UINTN Size;
1718 UINT16 Data16;
1719 UINT32 Data32;
1720 UINT64 Data64;
1721
1722 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVIN);
1723
1724 Modifiers = GET_MODIFIERS (InstructionAddress);
1725 Operands = GET_OPERANDS (InstructionAddress);
1726
1727 if (Operands & MOVI_M_IMMDATA) {
1728 Size = 4;
1729 } else {
1730 Size = 2;
1731 }
1732 if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {
1733 Size += 2;
1734 } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {
1735 Size += 4;
1736 } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {
1737 Size += 8;
1738 }
1739
1740 //
1741 // Construct Disasm String
1742 //
1743 if (DisasmString != NULL) {
1744 *DisasmString = EdbPreInstructionString ();
1745
1746 EdbPrintInstructionName (L"MOVIn");
1747 switch (Modifiers & MOVI_M_DATAWIDTH) {
1748 case MOVI_DATAWIDTH16:
1749 EdbPrintInstructionName (L"w");
1750 break;
1751 case MOVI_DATAWIDTH32:
1752 EdbPrintInstructionName (L"d");
1753 break;
1754 case MOVI_DATAWIDTH64:
1755 EdbPrintInstructionName (L"q");
1756 break;
1757 }
1758
1759 EdbPrintRegister1 (Operands);
1760
1761 InstructionAddress += 2;
1762 if (Operands & MOVI_M_IMMDATA) {
1763 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1764 InstructionAddress += 2;
1765 EdbPrintRawIndexData16 (Data16);
1766 }
1767
1768 EdbPrintComma ();
1769
1770 switch (Modifiers & MOVI_M_DATAWIDTH) {
1771 case MOVI_DATAWIDTH16:
1772 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1773 EdbPrintRawIndexData16 (Data16);
1774 break;
1775 case MOVI_DATAWIDTH32:
1776 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
1777 EdbPrintRawIndexData32 (Data32);
1778 break;
1779 case MOVI_DATAWIDTH64:
1780 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
1781 EdbPrintRawIndexData64 (Data64);
1782 break;
1783 }
1784
1785 EdbPostInstructionString ();
1786 }
1787
1788 return Size;
1789 }
1790
1791 UINTN
1792 EdbDisasmMOVREL (
1793 IN EFI_PHYSICAL_ADDRESS InstructionAddress,
1794 IN EFI_SYSTEM_CONTEXT SystemContext,
1795 OUT CHAR16 **DisasmString
1796 )
1797 /*++
1798
1799 Routine Description:
1800
1801 Disasm instruction - MOVREL
1802
1803 Arguments:
1804
1805 InstructionAddress - The instruction address
1806 SystemContext - EBC system context.
1807 DisasmString - The instruction string
1808
1809 Returns:
1810
1811 Instruction length
1812
1813 --*/
1814 {
1815 UINT8 Modifiers;
1816 UINT8 Operands;
1817 UINTN Size;
1818 UINT16 Data16;
1819 UINT32 Data32;
1820 UINT64 Data64;
1821 UINTN Result;
1822 EFI_PHYSICAL_ADDRESS SavedInstructionAddress;
1823
1824 ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVREL);
1825 SavedInstructionAddress = InstructionAddress;
1826
1827 Modifiers = GET_MODIFIERS (InstructionAddress);
1828 Operands = GET_OPERANDS (InstructionAddress);
1829
1830 if (Operands & MOVI_M_IMMDATA) {
1831 Size = 4;
1832 } else {
1833 Size = 2;
1834 }
1835 if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {
1836 Size += 2;
1837 } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {
1838 Size += 4;
1839 } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {
1840 Size += 8;
1841 } else {
1842 return 0;
1843 }
1844
1845 //
1846 // Construct Disasm String
1847 //
1848 if (DisasmString != NULL) {
1849 *DisasmString = EdbPreInstructionString ();
1850
1851 EdbPrintInstructionName (L"MOVrel");
1852 switch (Modifiers & MOVI_M_DATAWIDTH) {
1853 case MOVI_DATAWIDTH16:
1854 EdbPrintInstructionName (L"w");
1855 break;
1856 case MOVI_DATAWIDTH32:
1857 EdbPrintInstructionName (L"d");
1858 break;
1859 case MOVI_DATAWIDTH64:
1860 EdbPrintInstructionName (L"q");
1861 break;
1862 }
1863
1864 EdbPrintRegister1 (Operands);
1865
1866 InstructionAddress += 2;
1867 if (Operands & MOVI_M_IMMDATA) {
1868 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1869 InstructionAddress += 2;
1870 EdbPrintRawIndexData16 (Data16);
1871 }
1872
1873 EdbPrintComma ();
1874
1875 switch (Modifiers & MOVI_M_DATAWIDTH) {
1876 case MOVI_DATAWIDTH16:
1877 CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));
1878 Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Size + (INT16)Data16));
1879 if (Result == 0) {
1880 EdbPrintData16 (Data16);
1881 }
1882 break;
1883 case MOVI_DATAWIDTH32:
1884 CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));
1885 Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Size + (INT32)Data32));
1886 if (Result == 0) {
1887 EdbPrintData32 (Data32);
1888 }
1889 break;
1890 case MOVI_DATAWIDTH64:
1891 CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));
1892 if (sizeof(UINTN) == sizeof(UINT64)) {
1893 Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Size + (INT64)Data64));
1894 } else {
1895 Result = 0;
1896 }
1897 if (Result == 0) {
1898 EdbPrintData64 (Data64);
1899 }
1900 break;
1901 }
1902
1903 EdbPostInstructionString ();
1904 }
1905
1906 return Size;
1907 }