This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
i386-dis.c
4143 lines (3927 loc) · 97.1 KB
/
i386-dis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Print i386 instructions for GDB, the GNU debugger.
Copyright 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2001
Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
* 80386 instruction printer by Pace Willisson ([email protected])
* July 1988
* modified by John Hassey ([email protected])
* x86-64 support added by Jan Hubicka ([email protected])
*/
/*
* The main tables describing the instructions is essentially a copy
* of the "Opcode Map" chapter (Appendix A) of the Intel 80386
* Programmers Manual. Usually, there is a capital letter, followed
* by a small letter. The capital letter tell the addressing mode,
* and the small letter tells about the operand size. Refer to
* the Intel manual for details.
*/
#include <stdlib.h>
#include "dis-asm.h"
#define MAXLEN 20
#include <setjmp.h>
#ifndef UNIXWARE_COMPAT
/* Set non-zero for broken, compatible instructions. Set to zero for
non-broken opcodes. */
#define UNIXWARE_COMPAT 1
#endif
static int fetch_data PARAMS ((struct disassemble_info *, bfd_byte *));
static void ckprefix PARAMS ((void));
static const char *prefix_name PARAMS ((int, int));
static int print_insn PARAMS ((bfd_vma, disassemble_info *));
static void dofloat PARAMS ((int));
static void OP_ST PARAMS ((int, int));
static void OP_STi PARAMS ((int, int));
static int putop PARAMS ((const char *, int));
static void oappend PARAMS ((const char *));
static void append_seg PARAMS ((void));
static void OP_indirE PARAMS ((int, int));
static void print_operand_value PARAMS ((char *, int, bfd_vma));
static void OP_E PARAMS ((int, int));
static void OP_G PARAMS ((int, int));
static bfd_vma get64 PARAMS ((void));
static bfd_signed_vma get32 PARAMS ((void));
static bfd_signed_vma get32s PARAMS ((void));
static int get16 PARAMS ((void));
static void set_op PARAMS ((bfd_vma, int));
static void OP_REG PARAMS ((int, int));
static void OP_IMREG PARAMS ((int, int));
static void OP_I PARAMS ((int, int));
static void OP_I64 PARAMS ((int, int));
static void OP_sI PARAMS ((int, int));
static void OP_J PARAMS ((int, int));
static void OP_SEG PARAMS ((int, int));
static void OP_DIR PARAMS ((int, int));
static void OP_OFF PARAMS ((int, int));
static void OP_OFF64 PARAMS ((int, int));
static void ptr_reg PARAMS ((int, int));
static void OP_ESreg PARAMS ((int, int));
static void OP_DSreg PARAMS ((int, int));
static void OP_C PARAMS ((int, int));
static void OP_D PARAMS ((int, int));
static void OP_T PARAMS ((int, int));
static void OP_Rd PARAMS ((int, int));
static void OP_MMX PARAMS ((int, int));
static void OP_XMM PARAMS ((int, int));
static void OP_EM PARAMS ((int, int));
static void OP_EX PARAMS ((int, int));
static void OP_MS PARAMS ((int, int));
static void OP_XS PARAMS ((int, int));
static void OP_3DNowSuffix PARAMS ((int, int));
static void OP_SIMD_Suffix PARAMS ((int, int));
static void SIMD_Fixup PARAMS ((int, int));
static void BadOp PARAMS ((void));
struct dis_private {
/* Points to first byte not fetched. */
bfd_byte *max_fetched;
bfd_byte the_buffer[MAXLEN];
bfd_vma insn_start;
int orig_sizeflag;
jmp_buf bailout;
};
/* The opcode for the fwait instruction, which we treat as a prefix
when we can. */
#define FWAIT_OPCODE (0x9b)
/* Set to 1 for 64bit mode disassembly. */
static int mode_64bit;
/* Flags for the prefixes for the current instruction. See below. */
static int prefixes;
/* REX prefix the current instruction. See below. */
static int rex;
/* Bits of REX we've already used. */
static int rex_used;
#define REX_MODE64 8
#define REX_EXTX 4
#define REX_EXTY 2
#define REX_EXTZ 1
/* Mark parts used in the REX prefix. When we are testing for
empty prefix (for 8bit register REX extension), just mask it
out. Otherwise test for REX bit is excuse for existence of REX
only in case value is nonzero. */
#define USED_REX(value) \
{ \
if (value) \
rex_used |= (rex & value) ? (value) | 0x40 : 0; \
else \
rex_used |= 0x40; \
}
/* Flags for prefixes which we somehow handled when printing the
current instruction. */
static int used_prefixes;
/* Flags stored in PREFIXES. */
#define PREFIX_REPZ 1
#define PREFIX_REPNZ 2
#define PREFIX_LOCK 4
#define PREFIX_CS 8
#define PREFIX_SS 0x10
#define PREFIX_DS 0x20
#define PREFIX_ES 0x40
#define PREFIX_FS 0x80
#define PREFIX_GS 0x100
#define PREFIX_DATA 0x200
#define PREFIX_ADDR 0x400
#define PREFIX_FWAIT 0x800
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
to ADDR (exclusive) are valid. Returns 1 for success, longjmps
on error. */
#define FETCH_DATA(info, addr) \
((addr) <= ((struct dis_private *) (info->private_data))->max_fetched \
? 1 : fetch_data ((info), (addr)))
static int
fetch_data (info, addr)
struct disassemble_info *info;
bfd_byte *addr;
{
int status;
struct dis_private *priv = (struct dis_private *) info->private_data;
bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
status = (*info->read_memory_func) (start,
priv->max_fetched,
addr - priv->max_fetched,
info);
if (status != 0)
{
/* If we did manage to read at least one byte, then
print_insn_i386 will do something sensible. Otherwise, print
an error. We do that here because this is where we know
STATUS. */
if (priv->max_fetched == priv->the_buffer)
(*info->memory_error_func) (status, start, info);
longjmp (priv->bailout, 1);
}
else
priv->max_fetched = addr;
return 1;
}
#define XX NULL, 0
#define Eb OP_E, b_mode
#define Ev OP_E, v_mode
#define Ed OP_E, d_mode
#define indirEb OP_indirE, b_mode
#define indirEv OP_indirE, v_mode
#define Ew OP_E, w_mode
#define Ma OP_E, v_mode
#define M OP_E, 0 /* lea, lgdt, etc. */
#define Mp OP_E, 0 /* 32 or 48 bit memory operand for LDS, LES etc */
#define Gb OP_G, b_mode
#define Gv OP_G, v_mode
#define Gd OP_G, d_mode
#define Gw OP_G, w_mode
#define Rd OP_Rd, d_mode
#define Rm OP_Rd, m_mode
#define Ib OP_I, b_mode
#define sIb OP_sI, b_mode /* sign extened byte */
#define Iv OP_I, v_mode
#define Iq OP_I, q_mode
#define Iv64 OP_I64, v_mode
#define Iw OP_I, w_mode
#define Jb OP_J, b_mode
#define Jv OP_J, v_mode
#define Cm OP_C, m_mode
#define Dm OP_D, m_mode
#define Td OP_T, d_mode
#define RMeAX OP_REG, eAX_reg
#define RMeBX OP_REG, eBX_reg
#define RMeCX OP_REG, eCX_reg
#define RMeDX OP_REG, eDX_reg
#define RMeSP OP_REG, eSP_reg
#define RMeBP OP_REG, eBP_reg
#define RMeSI OP_REG, eSI_reg
#define RMeDI OP_REG, eDI_reg
#define RMrAX OP_REG, rAX_reg
#define RMrBX OP_REG, rBX_reg
#define RMrCX OP_REG, rCX_reg
#define RMrDX OP_REG, rDX_reg
#define RMrSP OP_REG, rSP_reg
#define RMrBP OP_REG, rBP_reg
#define RMrSI OP_REG, rSI_reg
#define RMrDI OP_REG, rDI_reg
#define RMAL OP_REG, al_reg
#define RMAL OP_REG, al_reg
#define RMCL OP_REG, cl_reg
#define RMDL OP_REG, dl_reg
#define RMBL OP_REG, bl_reg
#define RMAH OP_REG, ah_reg
#define RMCH OP_REG, ch_reg
#define RMDH OP_REG, dh_reg
#define RMBH OP_REG, bh_reg
#define RMAX OP_REG, ax_reg
#define RMDX OP_REG, dx_reg
#define eAX OP_IMREG, eAX_reg
#define eBX OP_IMREG, eBX_reg
#define eCX OP_IMREG, eCX_reg
#define eDX OP_IMREG, eDX_reg
#define eSP OP_IMREG, eSP_reg
#define eBP OP_IMREG, eBP_reg
#define eSI OP_IMREG, eSI_reg
#define eDI OP_IMREG, eDI_reg
#define AL OP_IMREG, al_reg
#define AL OP_IMREG, al_reg
#define CL OP_IMREG, cl_reg
#define DL OP_IMREG, dl_reg
#define BL OP_IMREG, bl_reg
#define AH OP_IMREG, ah_reg
#define CH OP_IMREG, ch_reg
#define DH OP_IMREG, dh_reg
#define BH OP_IMREG, bh_reg
#define AX OP_IMREG, ax_reg
#define DX OP_IMREG, dx_reg
#define indirDX OP_IMREG, indir_dx_reg
#define Sw OP_SEG, w_mode
#define Ap OP_DIR, 0
#define Ob OP_OFF, b_mode
#define Ob64 OP_OFF64, b_mode
#define Ov OP_OFF, v_mode
#define Ov64 OP_OFF64, v_mode
#define Xb OP_DSreg, eSI_reg
#define Xv OP_DSreg, eSI_reg
#define Yb OP_ESreg, eDI_reg
#define Yv OP_ESreg, eDI_reg
#define DSBX OP_DSreg, eBX_reg
#define es OP_REG, es_reg
#define ss OP_REG, ss_reg
#define cs OP_REG, cs_reg
#define ds OP_REG, ds_reg
#define fs OP_REG, fs_reg
#define gs OP_REG, gs_reg
#define MX OP_MMX, 0
#define XM OP_XMM, 0
#define EM OP_EM, v_mode
#define EX OP_EX, v_mode
#define MS OP_MS, v_mode
#define XS OP_XS, v_mode
#define None OP_E, 0
#define OPSUF OP_3DNowSuffix, 0
#define OPSIMD OP_SIMD_Suffix, 0
#define cond_jump_flag NULL, cond_jump_mode
#define loop_jcxz_flag NULL, loop_jcxz_mode
/* bits in sizeflag */
#define SUFFIX_ALWAYS 4
#define AFLAG 2
#define DFLAG 1
#define b_mode 1 /* byte operand */
#define v_mode 2 /* operand size depends on prefixes */
#define w_mode 3 /* word operand */
#define d_mode 4 /* double word operand */
#define q_mode 5 /* quad word operand */
#define x_mode 6
#define m_mode 7 /* d_mode in 32bit, q_mode in 64bit mode. */
#define cond_jump_mode 8
#define loop_jcxz_mode 9
#define es_reg 100
#define cs_reg 101
#define ss_reg 102
#define ds_reg 103
#define fs_reg 104
#define gs_reg 105
#define eAX_reg 108
#define eCX_reg 109
#define eDX_reg 110
#define eBX_reg 111
#define eSP_reg 112
#define eBP_reg 113
#define eSI_reg 114
#define eDI_reg 115
#define al_reg 116
#define cl_reg 117
#define dl_reg 118
#define bl_reg 119
#define ah_reg 120
#define ch_reg 121
#define dh_reg 122
#define bh_reg 123
#define ax_reg 124
#define cx_reg 125
#define dx_reg 126
#define bx_reg 127
#define sp_reg 128
#define bp_reg 129
#define si_reg 130
#define di_reg 131
#define rAX_reg 132
#define rCX_reg 133
#define rDX_reg 134
#define rBX_reg 135
#define rSP_reg 136
#define rBP_reg 137
#define rSI_reg 138
#define rDI_reg 139
#define indir_dx_reg 150
#define FLOATCODE 1
#define USE_GROUPS 2
#define USE_PREFIX_USER_TABLE 3
#define X86_64_SPECIAL 4
#define FLOAT NULL, NULL, FLOATCODE, NULL, 0, NULL, 0
#define GRP1b NULL, NULL, USE_GROUPS, NULL, 0, NULL, 0
#define GRP1S NULL, NULL, USE_GROUPS, NULL, 1, NULL, 0
#define GRP1Ss NULL, NULL, USE_GROUPS, NULL, 2, NULL, 0
#define GRP2b NULL, NULL, USE_GROUPS, NULL, 3, NULL, 0
#define GRP2S NULL, NULL, USE_GROUPS, NULL, 4, NULL, 0
#define GRP2b_one NULL, NULL, USE_GROUPS, NULL, 5, NULL, 0
#define GRP2S_one NULL, NULL, USE_GROUPS, NULL, 6, NULL, 0
#define GRP2b_cl NULL, NULL, USE_GROUPS, NULL, 7, NULL, 0
#define GRP2S_cl NULL, NULL, USE_GROUPS, NULL, 8, NULL, 0
#define GRP3b NULL, NULL, USE_GROUPS, NULL, 9, NULL, 0
#define GRP3S NULL, NULL, USE_GROUPS, NULL, 10, NULL, 0
#define GRP4 NULL, NULL, USE_GROUPS, NULL, 11, NULL, 0
#define GRP5 NULL, NULL, USE_GROUPS, NULL, 12, NULL, 0
#define GRP6 NULL, NULL, USE_GROUPS, NULL, 13, NULL, 0
#define GRP7 NULL, NULL, USE_GROUPS, NULL, 14, NULL, 0
#define GRP8 NULL, NULL, USE_GROUPS, NULL, 15, NULL, 0
#define GRP9 NULL, NULL, USE_GROUPS, NULL, 16, NULL, 0
#define GRP10 NULL, NULL, USE_GROUPS, NULL, 17, NULL, 0
#define GRP11 NULL, NULL, USE_GROUPS, NULL, 18, NULL, 0
#define GRP12 NULL, NULL, USE_GROUPS, NULL, 19, NULL, 0
#define GRP13 NULL, NULL, USE_GROUPS, NULL, 20, NULL, 0
#define GRP14 NULL, NULL, USE_GROUPS, NULL, 21, NULL, 0
#define GRPAMD NULL, NULL, USE_GROUPS, NULL, 22, NULL, 0
#define PREGRP0 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 0, NULL, 0
#define PREGRP1 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 1, NULL, 0
#define PREGRP2 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 2, NULL, 0
#define PREGRP3 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 3, NULL, 0
#define PREGRP4 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 4, NULL, 0
#define PREGRP5 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 5, NULL, 0
#define PREGRP6 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 6, NULL, 0
#define PREGRP7 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 7, NULL, 0
#define PREGRP8 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 8, NULL, 0
#define PREGRP9 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 9, NULL, 0
#define PREGRP10 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 10, NULL, 0
#define PREGRP11 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 11, NULL, 0
#define PREGRP12 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 12, NULL, 0
#define PREGRP13 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 13, NULL, 0
#define PREGRP14 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 14, NULL, 0
#define PREGRP15 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 15, NULL, 0
#define PREGRP16 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 16, NULL, 0
#define PREGRP17 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 17, NULL, 0
#define PREGRP18 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 18, NULL, 0
#define PREGRP19 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 19, NULL, 0
#define PREGRP20 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 20, NULL, 0
#define PREGRP21 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 21, NULL, 0
#define PREGRP22 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 22, NULL, 0
#define PREGRP23 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 23, NULL, 0
#define PREGRP24 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 24, NULL, 0
#define PREGRP25 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 25, NULL, 0
#define PREGRP26 NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 26, NULL, 0
#define X86_64_0 NULL, NULL, X86_64_SPECIAL, NULL, 0, NULL, 0
typedef void (*op_rtn) PARAMS ((int bytemode, int sizeflag));
struct dis386 {
const char *name;
op_rtn op1;
int bytemode1;
op_rtn op2;
int bytemode2;
op_rtn op3;
int bytemode3;
};
/* Upper case letters in the instruction names here are macros.
'A' => print 'b' if no register operands or suffix_always is true
'B' => print 'b' if suffix_always is true
'E' => print 'e' if 32-bit form of jcxz
'F' => print 'w' or 'l' depending on address size prefix (loop insns)
'H' => print ",pt" or ",pn" branch hint
'L' => print 'l' if suffix_always is true
'N' => print 'n' if instruction has no wait "prefix"
'O' => print 'd', or 'o'
'P' => print 'w', 'l' or 'q' if instruction has an operand size prefix,
. or suffix_always is true. print 'q' if rex prefix is present.
'Q' => print 'w', 'l' or 'q' if no register operands or suffix_always
. is true
'R' => print 'w', 'l' or 'q' ("wd" or "dq" in intel mode)
'S' => print 'w', 'l' or 'q' if suffix_always is true
'T' => print 'q' in 64bit mode and behave as 'P' otherwise
'U' => print 'q' in 64bit mode and behave as 'Q' otherwise
'X' => print 's', 'd' depending on data16 prefix (for XMM)
'W' => print 'b' or 'w' ("w" or "de" in intel mode)
'Y' => 'q' if instruction has an REX 64bit overwrite prefix
Many of the above letters print nothing in Intel mode. See "putop"
for the details.
Braces '{' and '}', and vertical bars '|', indicate alternative
mnemonic strings for AT&T, Intel, X86_64 AT&T, and X86_64 Intel
modes. In cases where there are only two alternatives, the X86_64
instruction is reserved, and "(bad)" is printed.
*/
static const struct dis386 dis386[] = {
/* 00 */
{ "addB", Eb, Gb, XX },
{ "addS", Ev, Gv, XX },
{ "addB", Gb, Eb, XX },
{ "addS", Gv, Ev, XX },
{ "addB", AL, Ib, XX },
{ "addS", eAX, Iv, XX },
{ "push{T|}", es, XX, XX },
{ "pop{T|}", es, XX, XX },
/* 08 */
{ "orB", Eb, Gb, XX },
{ "orS", Ev, Gv, XX },
{ "orB", Gb, Eb, XX },
{ "orS", Gv, Ev, XX },
{ "orB", AL, Ib, XX },
{ "orS", eAX, Iv, XX },
{ "push{T|}", cs, XX, XX },
{ "(bad)", XX, XX, XX }, /* 0x0f extended opcode escape */
/* 10 */
{ "adcB", Eb, Gb, XX },
{ "adcS", Ev, Gv, XX },
{ "adcB", Gb, Eb, XX },
{ "adcS", Gv, Ev, XX },
{ "adcB", AL, Ib, XX },
{ "adcS", eAX, Iv, XX },
{ "push{T|}", ss, XX, XX },
{ "popT|}", ss, XX, XX },
/* 18 */
{ "sbbB", Eb, Gb, XX },
{ "sbbS", Ev, Gv, XX },
{ "sbbB", Gb, Eb, XX },
{ "sbbS", Gv, Ev, XX },
{ "sbbB", AL, Ib, XX },
{ "sbbS", eAX, Iv, XX },
{ "push{T|}", ds, XX, XX },
{ "pop{T|}", ds, XX, XX },
/* 20 */
{ "andB", Eb, Gb, XX },
{ "andS", Ev, Gv, XX },
{ "andB", Gb, Eb, XX },
{ "andS", Gv, Ev, XX },
{ "andB", AL, Ib, XX },
{ "andS", eAX, Iv, XX },
{ "(bad)", XX, XX, XX }, /* SEG ES prefix */
{ "daa{|}", XX, XX, XX },
/* 28 */
{ "subB", Eb, Gb, XX },
{ "subS", Ev, Gv, XX },
{ "subB", Gb, Eb, XX },
{ "subS", Gv, Ev, XX },
{ "subB", AL, Ib, XX },
{ "subS", eAX, Iv, XX },
{ "(bad)", XX, XX, XX }, /* SEG CS prefix */
{ "das{|}", XX, XX, XX },
/* 30 */
{ "xorB", Eb, Gb, XX },
{ "xorS", Ev, Gv, XX },
{ "xorB", Gb, Eb, XX },
{ "xorS", Gv, Ev, XX },
{ "xorB", AL, Ib, XX },
{ "xorS", eAX, Iv, XX },
{ "(bad)", XX, XX, XX }, /* SEG SS prefix */
{ "aaa{|}", XX, XX, XX },
/* 38 */
{ "cmpB", Eb, Gb, XX },
{ "cmpS", Ev, Gv, XX },
{ "cmpB", Gb, Eb, XX },
{ "cmpS", Gv, Ev, XX },
{ "cmpB", AL, Ib, XX },
{ "cmpS", eAX, Iv, XX },
{ "(bad)", XX, XX, XX }, /* SEG DS prefix */
{ "aas{|}", XX, XX, XX },
/* 40 */
{ "inc{S|}", RMeAX, XX, XX },
{ "inc{S|}", RMeCX, XX, XX },
{ "inc{S|}", RMeDX, XX, XX },
{ "inc{S|}", RMeBX, XX, XX },
{ "inc{S|}", RMeSP, XX, XX },
{ "inc{S|}", RMeBP, XX, XX },
{ "inc{S|}", RMeSI, XX, XX },
{ "inc{S|}", RMeDI, XX, XX },
/* 48 */
{ "dec{S|}", RMeAX, XX, XX },
{ "dec{S|}", RMeCX, XX, XX },
{ "dec{S|}", RMeDX, XX, XX },
{ "dec{S|}", RMeBX, XX, XX },
{ "dec{S|}", RMeSP, XX, XX },
{ "dec{S|}", RMeBP, XX, XX },
{ "dec{S|}", RMeSI, XX, XX },
{ "dec{S|}", RMeDI, XX, XX },
/* 50 */
{ "pushS", RMrAX, XX, XX },
{ "pushS", RMrCX, XX, XX },
{ "pushS", RMrDX, XX, XX },
{ "pushS", RMrBX, XX, XX },
{ "pushS", RMrSP, XX, XX },
{ "pushS", RMrBP, XX, XX },
{ "pushS", RMrSI, XX, XX },
{ "pushS", RMrDI, XX, XX },
/* 58 */
{ "popS", RMrAX, XX, XX },
{ "popS", RMrCX, XX, XX },
{ "popS", RMrDX, XX, XX },
{ "popS", RMrBX, XX, XX },
{ "popS", RMrSP, XX, XX },
{ "popS", RMrBP, XX, XX },
{ "popS", RMrSI, XX, XX },
{ "popS", RMrDI, XX, XX },
/* 60 */
{ "pusha{P|}", XX, XX, XX },
{ "popa{P|}", XX, XX, XX },
{ "bound{S|}", Gv, Ma, XX },
{ X86_64_0 },
{ "(bad)", XX, XX, XX }, /* seg fs */
{ "(bad)", XX, XX, XX }, /* seg gs */
{ "(bad)", XX, XX, XX }, /* op size prefix */
{ "(bad)", XX, XX, XX }, /* adr size prefix */
/* 68 */
{ "pushT", Iq, XX, XX },
{ "imulS", Gv, Ev, Iv },
{ "pushT", sIb, XX, XX },
{ "imulS", Gv, Ev, sIb },
{ "ins{b||b|}", Yb, indirDX, XX },
{ "ins{R||R|}", Yv, indirDX, XX },
{ "outs{b||b|}", indirDX, Xb, XX },
{ "outs{R||R|}", indirDX, Xv, XX },
/* 70 */
{ "joH", Jb, XX, cond_jump_flag },
{ "jnoH", Jb, XX, cond_jump_flag },
{ "jbH", Jb, XX, cond_jump_flag },
{ "jaeH", Jb, XX, cond_jump_flag },
{ "jeH", Jb, XX, cond_jump_flag },
{ "jneH", Jb, XX, cond_jump_flag },
{ "jbeH", Jb, XX, cond_jump_flag },
{ "jaH", Jb, XX, cond_jump_flag },
/* 78 */
{ "jsH", Jb, XX, cond_jump_flag },
{ "jnsH", Jb, XX, cond_jump_flag },
{ "jpH", Jb, XX, cond_jump_flag },
{ "jnpH", Jb, XX, cond_jump_flag },
{ "jlH", Jb, XX, cond_jump_flag },
{ "jgeH", Jb, XX, cond_jump_flag },
{ "jleH", Jb, XX, cond_jump_flag },
{ "jgH", Jb, XX, cond_jump_flag },
/* 80 */
{ GRP1b },
{ GRP1S },
{ "(bad)", XX, XX, XX },
{ GRP1Ss },
{ "testB", Eb, Gb, XX },
{ "testS", Ev, Gv, XX },
{ "xchgB", Eb, Gb, XX },
{ "xchgS", Ev, Gv, XX },
/* 88 */
{ "movB", Eb, Gb, XX },
{ "movS", Ev, Gv, XX },
{ "movB", Gb, Eb, XX },
{ "movS", Gv, Ev, XX },
{ "movQ", Ev, Sw, XX },
{ "leaS", Gv, M, XX },
{ "movQ", Sw, Ev, XX },
{ "popU", Ev, XX, XX },
/* 90 */
{ "nop", XX, XX, XX },
/* FIXME: NOP with REPz prefix is called PAUSE. */
{ "xchgS", RMeCX, eAX, XX },
{ "xchgS", RMeDX, eAX, XX },
{ "xchgS", RMeBX, eAX, XX },
{ "xchgS", RMeSP, eAX, XX },
{ "xchgS", RMeBP, eAX, XX },
{ "xchgS", RMeSI, eAX, XX },
{ "xchgS", RMeDI, eAX, XX },
/* 98 */
{ "cW{tR||tR|}", XX, XX, XX },
{ "cR{tO||tO|}", XX, XX, XX },
{ "lcall{T|}", Ap, XX, XX },
{ "(bad)", XX, XX, XX }, /* fwait */
{ "pushfT", XX, XX, XX },
{ "popfT", XX, XX, XX },
{ "sahf{|}", XX, XX, XX },
{ "lahf{|}", XX, XX, XX },
/* a0 */
{ "movB", AL, Ob64, XX },
{ "movS", eAX, Ov64, XX },
{ "movB", Ob64, AL, XX },
{ "movS", Ov64, eAX, XX },
{ "movs{b||b|}", Yb, Xb, XX },
{ "movs{R||R|}", Yv, Xv, XX },
{ "cmps{b||b|}", Xb, Yb, XX },
{ "cmps{R||R|}", Xv, Yv, XX },
/* a8 */
{ "testB", AL, Ib, XX },
{ "testS", eAX, Iv, XX },
{ "stosB", Yb, AL, XX },
{ "stosS", Yv, eAX, XX },
{ "lodsB", AL, Xb, XX },
{ "lodsS", eAX, Xv, XX },
{ "scasB", AL, Yb, XX },
{ "scasS", eAX, Yv, XX },
/* b0 */
{ "movB", RMAL, Ib, XX },
{ "movB", RMCL, Ib, XX },
{ "movB", RMDL, Ib, XX },
{ "movB", RMBL, Ib, XX },
{ "movB", RMAH, Ib, XX },
{ "movB", RMCH, Ib, XX },
{ "movB", RMDH, Ib, XX },
{ "movB", RMBH, Ib, XX },
/* b8 */
{ "movS", RMeAX, Iv64, XX },
{ "movS", RMeCX, Iv64, XX },
{ "movS", RMeDX, Iv64, XX },
{ "movS", RMeBX, Iv64, XX },
{ "movS", RMeSP, Iv64, XX },
{ "movS", RMeBP, Iv64, XX },
{ "movS", RMeSI, Iv64, XX },
{ "movS", RMeDI, Iv64, XX },
/* c0 */
{ GRP2b },
{ GRP2S },
{ "retT", Iw, XX, XX },
{ "retT", XX, XX, XX },
{ "les{S|}", Gv, Mp, XX },
{ "ldsS", Gv, Mp, XX },
{ "movA", Eb, Ib, XX },
{ "movQ", Ev, Iv, XX },
/* c8 */
{ "enterT", Iw, Ib, XX },
{ "leaveT", XX, XX, XX },
{ "lretP", Iw, XX, XX },
{ "lretP", XX, XX, XX },
{ "int3", XX, XX, XX },
{ "int", Ib, XX, XX },
{ "into{|}", XX, XX, XX },
{ "iretP", XX, XX, XX },
/* d0 */
{ GRP2b_one },
{ GRP2S_one },
{ GRP2b_cl },
{ GRP2S_cl },
{ "aam{|}", sIb, XX, XX },
{ "aad{|}", sIb, XX, XX },
{ "(bad)", XX, XX, XX },
{ "xlat", DSBX, XX, XX },
/* d8 */
{ FLOAT },
{ FLOAT },
{ FLOAT },
{ FLOAT },
{ FLOAT },
{ FLOAT },
{ FLOAT },
{ FLOAT },
/* e0 */
{ "loopneFH", Jb, XX, loop_jcxz_flag },
{ "loopeFH", Jb, XX, loop_jcxz_flag },
{ "loopFH", Jb, XX, loop_jcxz_flag },
{ "jEcxzH", Jb, XX, loop_jcxz_flag },
{ "inB", AL, Ib, XX },
{ "inS", eAX, Ib, XX },
{ "outB", Ib, AL, XX },
{ "outS", Ib, eAX, XX },
/* e8 */
{ "callT", Jv, XX, XX },
{ "jmpT", Jv, XX, XX },
{ "ljmp{T|}", Ap, XX, XX },
{ "jmp", Jb, XX, XX },
{ "inB", AL, indirDX, XX },
{ "inS", eAX, indirDX, XX },
{ "outB", indirDX, AL, XX },
{ "outS", indirDX, eAX, XX },
/* f0 */
{ "(bad)", XX, XX, XX }, /* lock prefix */
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX }, /* repne */
{ "(bad)", XX, XX, XX }, /* repz */
{ "hlt", XX, XX, XX },
{ "cmc", XX, XX, XX },
{ GRP3b },
{ GRP3S },
/* f8 */
{ "clc", XX, XX, XX },
{ "stc", XX, XX, XX },
{ "cli", XX, XX, XX },
{ "sti", XX, XX, XX },
{ "cld", XX, XX, XX },
{ "std", XX, XX, XX },
{ GRP4 },
{ GRP5 },
};
static const struct dis386 dis386_twobyte[] = {
/* 00 */
{ GRP6 },
{ GRP7 },
{ "larS", Gv, Ew, XX },
{ "lslS", Gv, Ew, XX },
{ "(bad)", XX, XX, XX },
{ "syscall", XX, XX, XX },
{ "clts", XX, XX, XX },
{ "sysretP", XX, XX, XX },
/* 08 */
{ "invd", XX, XX, XX },
{ "wbinvd", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "ud2a", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ GRPAMD },
{ "femms", XX, XX, XX },
{ "", MX, EM, OPSUF }, /* See OP_3DNowSuffix. */
/* 10 */
{ PREGRP8 },
{ PREGRP9 },
{ "movlpX", XM, EX, SIMD_Fixup, 'h' }, /* really only 2 operands */
{ "movlpX", EX, XM, SIMD_Fixup, 'h' },
{ "unpcklpX", XM, EX, XX },
{ "unpckhpX", XM, EX, XX },
{ "movhpX", XM, EX, SIMD_Fixup, 'l' },
{ "movhpX", EX, XM, SIMD_Fixup, 'l' },
/* 18 */
{ GRP14 },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
/* 20 */
{ "movL", Rm, Cm, XX },
{ "movL", Rm, Dm, XX },
{ "movL", Cm, Rm, XX },
{ "movL", Dm, Rm, XX },
{ "movL", Rd, Td, XX },
{ "(bad)", XX, XX, XX },
{ "movL", Td, Rd, XX },
{ "(bad)", XX, XX, XX },
/* 28 */
{ "movapX", XM, EX, XX },
{ "movapX", EX, XM, XX },
{ PREGRP2 },
{ "movntpX", Ev, XM, XX },
{ PREGRP4 },
{ PREGRP3 },
{ "ucomisX", XM,EX, XX },
{ "comisX", XM,EX, XX },
/* 30 */
{ "wrmsr", XX, XX, XX },
{ "rdtsc", XX, XX, XX },
{ "rdmsr", XX, XX, XX },
{ "rdpmc", XX, XX, XX },
{ "sysenter", XX, XX, XX },
{ "sysexit", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
/* 38 */
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
/* 40 */
{ "cmovo", Gv, Ev, XX },
{ "cmovno", Gv, Ev, XX },
{ "cmovb", Gv, Ev, XX },
{ "cmovae", Gv, Ev, XX },
{ "cmove", Gv, Ev, XX },
{ "cmovne", Gv, Ev, XX },
{ "cmovbe", Gv, Ev, XX },
{ "cmova", Gv, Ev, XX },
/* 48 */
{ "cmovs", Gv, Ev, XX },
{ "cmovns", Gv, Ev, XX },
{ "cmovp", Gv, Ev, XX },
{ "cmovnp", Gv, Ev, XX },
{ "cmovl", Gv, Ev, XX },
{ "cmovge", Gv, Ev, XX },
{ "cmovle", Gv, Ev, XX },
{ "cmovg", Gv, Ev, XX },
/* 50 */
{ "movmskpX", Gd, XS, XX },
{ PREGRP13 },
{ PREGRP12 },
{ PREGRP11 },
{ "andpX", XM, EX, XX },
{ "andnpX", XM, EX, XX },
{ "orpX", XM, EX, XX },
{ "xorpX", XM, EX, XX },
/* 58 */
{ PREGRP0 },
{ PREGRP10 },
{ PREGRP17 },
{ PREGRP16 },
{ PREGRP14 },
{ PREGRP7 },
{ PREGRP5 },
{ PREGRP6 },
/* 60 */
{ "punpcklbw", MX, EM, XX },
{ "punpcklwd", MX, EM, XX },
{ "punpckldq", MX, EM, XX },
{ "packsswb", MX, EM, XX },
{ "pcmpgtb", MX, EM, XX },
{ "pcmpgtw", MX, EM, XX },
{ "pcmpgtd", MX, EM, XX },
{ "packuswb", MX, EM, XX },
/* 68 */
{ "punpckhbw", MX, EM, XX },
{ "punpckhwd", MX, EM, XX },
{ "punpckhdq", MX, EM, XX },
{ "packssdw", MX, EM, XX },
{ PREGRP26 },
{ PREGRP24 },
{ "movd", MX, Ed, XX },
{ PREGRP19 },
/* 70 */
{ PREGRP22 },
{ GRP10 },
{ GRP11 },
{ GRP12 },
{ "pcmpeqb", MX, EM, XX },
{ "pcmpeqw", MX, EM, XX },
{ "pcmpeqd", MX, EM, XX },
{ "emms", XX, XX, XX },
/* 78 */
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
{ PREGRP23 },
{ PREGRP20 },
/* 80 */
{ "joH", Jv, XX, cond_jump_flag },
{ "jnoH", Jv, XX, cond_jump_flag },
{ "jbH", Jv, XX, cond_jump_flag },
{ "jaeH", Jv, XX, cond_jump_flag },
{ "jeH", Jv, XX, cond_jump_flag },
{ "jneH", Jv, XX, cond_jump_flag },
{ "jbeH", Jv, XX, cond_jump_flag },
{ "jaH", Jv, XX, cond_jump_flag },
/* 88 */
{ "jsH", Jv, XX, cond_jump_flag },
{ "jnsH", Jv, XX, cond_jump_flag },
{ "jpH", Jv, XX, cond_jump_flag },
{ "jnpH", Jv, XX, cond_jump_flag },
{ "jlH", Jv, XX, cond_jump_flag },
{ "jgeH", Jv, XX, cond_jump_flag },
{ "jleH", Jv, XX, cond_jump_flag },
{ "jgH", Jv, XX, cond_jump_flag },
/* 90 */
{ "seto", Eb, XX, XX },
{ "setno", Eb, XX, XX },
{ "setb", Eb, XX, XX },
{ "setae", Eb, XX, XX },
{ "sete", Eb, XX, XX },
{ "setne", Eb, XX, XX },
{ "setbe", Eb, XX, XX },
{ "seta", Eb, XX, XX },
/* 98 */
{ "sets", Eb, XX, XX },
{ "setns", Eb, XX, XX },
{ "setp", Eb, XX, XX },
{ "setnp", Eb, XX, XX },
{ "setl", Eb, XX, XX },
{ "setge", Eb, XX, XX },
{ "setle", Eb, XX, XX },
{ "setg", Eb, XX, XX },
/* a0 */
{ "pushT", fs, XX, XX },
{ "popT", fs, XX, XX },
{ "cpuid", XX, XX, XX },
{ "btS", Ev, Gv, XX },
{ "shldS", Ev, Gv, Ib },
{ "shldS", Ev, Gv, CL },
{ "(bad)", XX, XX, XX },
{ "(bad)", XX, XX, XX },
/* a8 */
{ "pushT", gs, XX, XX },
{ "popT", gs, XX, XX },
{ "rsm", XX, XX, XX },
{ "btsS", Ev, Gv, XX },
{ "shrdS", Ev, Gv, Ib },
{ "shrdS", Ev, Gv, CL },
{ GRP13 },
{ "imulS", Gv, Ev, XX },
/* b0 */
{ "cmpxchgB", Eb, Gb, XX },
{ "cmpxchgS", Ev, Gv, XX },
{ "lssS", Gv, Mp, XX },
{ "btrS", Ev, Gv, XX },
{ "lfsS", Gv, Mp, XX },
{ "lgsS", Gv, Mp, XX },
{ "movz{bR|x|bR|x}", Gv, Eb, XX },
{ "movz{wR|x|wR|x}", Gv, Ew, XX }, /* yes, there really is movzww ! */
/* b8 */
{ "(bad)", XX, XX, XX },
{ "ud2b", XX, XX, XX },
{ GRP8 },
{ "btcS", Ev, Gv, XX },
{ "bsfS", Gv, Ev, XX },
{ "bsrS", Gv, Ev, XX },
{ "movs{bR|x|bR|x}", Gv, Eb, XX },
{ "movs{wR|x|wR|x}", Gv, Ew, XX }, /* yes, there really is movsww ! */
/* c0 */
{ "xaddB", Eb, Gb, XX },
{ "xaddS", Ev, Gv, XX },
{ PREGRP1 },
{ "movntiS", Ev, Gv, XX },
{ "pinsrw", MX, Ed, Ib },
{ "pextrw", Gd, MS, Ib },
{ "shufpX", XM, EX, Ib },
{ GRP9 },
/* c8 */
{ "bswap", RMeAX, XX, XX },
{ "bswap", RMeCX, XX, XX },
{ "bswap", RMeDX, XX, XX },
{ "bswap", RMeBX, XX, XX },
{ "bswap", RMeSP, XX, XX },
{ "bswap", RMeBP, XX, XX },
{ "bswap", RMeSI, XX, XX },
{ "bswap", RMeDI, XX, XX },
/* d0 */
{ "(bad)", XX, XX, XX },
{ "psrlw", MX, EM, XX },
{ "psrld", MX, EM, XX },
{ "psrlq", MX, EM, XX },
{ "paddq", MX, EM, XX },
{ "pmullw", MX, EM, XX },
{ PREGRP21 },
{ "pmovmskb", Gd, MS, XX },
/* d8 */
{ "psubusb", MX, EM, XX },