llvm.org GIT mirror llvm / 7360e8c
[x86] Fix 16-bit handling of OpSize bit When disassembling in 16-bit mode the meaning of the OpSize bit is inverted. Instructions found in the IC_OPSIZE context will actually *not* have the 0x66 prefix, and instructions in the IC context will have the 0x66 prefix. Make use of the existing special-case handling for the 0x66 prefix being in the wrong place, to cope with this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199650 91177308-0d34-0410-b5e6-96231b3b80d8 David Woodhouse 6 years ago
2 changed file(s) with 793 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
970970 }
971971 }
972972 else {
973 if (isPrefixAtLocation(insn, 0x66, insn->necessaryPrefixLocation))
973 if (insn->mode != MODE_16BIT && isPrefixAtLocation(insn, 0x66, insn->necessaryPrefixLocation))
974974 attrMask |= ATTR_OPSIZE;
975975 else if (isPrefixAtLocation(insn, 0x67, insn->necessaryPrefixLocation))
976976 attrMask |= ATTR_ADSIZE;
988988
989989 /* The following clauses compensate for limitations of the tables. */
990990
991 if (insn->prefixPresent[0x66] && !(attrMask & ATTR_OPSIZE)) {
991 if ((insn->mode == MODE_16BIT || insn->prefixPresent[0x66]) &&
992 !(attrMask & ATTR_OPSIZE)) {
992993 /*
993994 * The instruction tables make no distinction between instructions that
994995 * allow OpSize anywhere (i.e., 16-bit operations) and that need it in a
10201021 specWithOpSizeName =
10211022 x86DisassemblerGetInstrName(instructionIDWithOpsize, miiArg);
10221023
1023 if (is16BitEquivalent(specName, specWithOpSizeName)) {
1024 if (is16BitEquivalent(specName, specWithOpSizeName) &&
1025 (insn->mode == MODE_16BIT) ^ insn->prefixPresent[0x66]) {
10241026 insn->instructionID = instructionIDWithOpsize;
10251027 insn->spec = specifierForUID(instructionIDWithOpsize);
10261028 } else {
0 # RUN: llvm-mc --disassemble %s -triple=i686-linux-gnu-code16 | FileCheck %s
1
2 # CHECK: movl $305419896, %ebx
3 0x66 0xbb 0x78 0x56 0x34 0x12
4
5 # CHECK: pause
6 0xf3 0x90
7
8 # CHECK: sfence
9 0x0f 0xae 0xf8
10
11 # CHECK: lfence
12 0x0f 0xae 0xe8
13
14 # CHECK: mfence
15 0x0f 0xae 0xf0
16
17 # CHECK: stgi
18 0x0f 0x01 0xdc
19
20 # CHECK: clgi
21 0x0f 0x01 0xdd
22
23 # CHECK: rdtscp
24 0x0f 0x01 0xf9
25
26 # CHECK: movl %eax, 16(%ebp)
27 0x67 0x66 0x89 0x45 0x10
28
29 # CHECK: movl %eax, -16(%ebp)
30 0x67 0x66 0x89 0x45 0xf0
31
32 # CHECK: testb %bl, %cl
33 0x84 0xcb
34
35 # CHECK: cmpl %eax, %ebx
36 0x66 0x39 0xc3
37
38 # CHECK: addw %ax, %ax
39 0x01 0xc0
40
41 # CHECK: shrl %eax
42 0x66 0xd1 0xe8
43
44 # CHECK: shll %eax
45 0x66 0xd1 0xe0
46
47 # CHECK: shll %eax
48 0x66 0xd1 0xe0
49
50 # CHECK: movb 0, %al
51 0xa0 0x00 0x00
52
53 # CHECK: movw 0, %ax
54 0xa1 0x00 0x00
55
56 # CHECK: movl 0, %eax
57 0x66 0xa1 0x00 0x00
58
59 # CHECK: into
60 0xce
61
62 # CHECK: int3
63 0xcc
64
65 # CHECK: int $4
66 0xcd 0x04
67
68 # CHECK: int $127
69 0xcd 0x7f
70
71 # CHECK: pushfw
72 0x9c
73
74 # CHECK: pushfl
75 0x66 0x9c
76
77 # CHECK: popfw
78 0x9d
79
80 # CHECK: popfl
81 0x66 0x9d
82
83 # CHECK: retl
84 0x66 0xc3
85
86 # CHECK: cmoval %eax, %edx
87 0x66 0x0f 0x47 0xd0
88
89 # CHECK: cmovael %eax, %edx
90 0x66 0x0f 0x43 0xd0
91
92 # CHECK: cmovbel %eax, %edx
93 0x66 0x0f 0x46 0xd0
94
95 # CHECK: cmovbl %eax, %edx
96 0x66 0x0f 0x42 0xd0
97
98 # CHECK: cmovbw %bx, %bx
99 0x0f 0x42 0xdb
100
101 # CHECK: cmovbel %eax, %edx
102 0x66 0x0f 0x46 0xd0
103
104 # CHECK: cmovbl %eax, %edx
105 0x66 0x0f 0x42 0xd0
106
107 # CHECK: cmovel %eax, %edx
108 0x66 0x0f 0x44 0xd0
109
110 # CHECK: cmovgl %eax, %edx
111 0x66 0x0f 0x4f 0xd0
112
113 # CHECK: cmovgel %eax, %edx
114 0x66 0x0f 0x4d 0xd0
115
116 # CHECK: cmovll %eax, %edx
117 0x66 0x0f 0x4c 0xd0
118
119 # CHECK: cmovlel %eax, %edx
120 0x66 0x0f 0x4e 0xd0
121
122 # CHECK: cmovbel %eax, %edx
123 0x66 0x0f 0x46 0xd0
124
125 # CHECK: cmovnel %eax, %edx
126 0x66 0x0f 0x45 0xd0
127
128 # CHECK: cmovael %eax, %edx
129 0x66 0x0f 0x43 0xd0
130
131 # CHECK: cmoval %eax, %edx
132 0x66 0x0f 0x47 0xd0
133
134 # CHECK: cmovael %eax, %edx
135 0x66 0x0f 0x43 0xd0
136
137 # CHECK: cmovnel %eax, %edx
138 0x66 0x0f 0x45 0xd0
139
140 # CHECK: cmovlel %eax, %edx
141 0x66 0x0f 0x4e 0xd0
142
143 # CHECK: cmovgel %eax, %edx
144 0x66 0x0f 0x4d 0xd0
145
146 # CHECK: cmovnel %eax, %edx
147 0x66 0x0f 0x45 0xd0
148
149 # CHECK: cmovlel %eax, %edx
150 0x66 0x0f 0x4e 0xd0
151
152 # CHECK: cmovll %eax, %edx
153 0x66 0x0f 0x4c 0xd0
154
155 # CHECK: cmovgel %eax, %edx
156 0x66 0x0f 0x4d 0xd0
157
158 # CHECK: cmovgl %eax, %edx
159 0x66 0x0f 0x4f 0xd0
160
161 # CHECK: cmovnol %eax, %edx
162 0x66 0x0f 0x41 0xd0
163
164 # CHECK: cmovnpl %eax, %edx
165 0x66 0x0f 0x4b 0xd0
166
167 # CHECK: cmovnsl %eax, %edx
168 0x66 0x0f 0x49 0xd0
169
170 # CHECK: cmovnel %eax, %edx
171 0x66 0x0f 0x45 0xd0
172
173 # CHECK: cmovol %eax, %edx
174 0x66 0x0f 0x40 0xd0
175
176 # CHECK: cmovpl %eax, %edx
177 0x66 0x0f 0x4a 0xd0
178
179 # CHECK: cmovsl %eax, %edx
180 0x66 0x0f 0x48 0xd0
181
182 # CHECK: cmovel %eax, %edx
183 0x66 0x0f 0x44 0xd0
184
185 # CHECK: fmul %st(0)
186 0xd8 0xc8
187
188 # CHECK: fadd %st(0)
189 0xd8 0xc0
190
191 # CHECK: fsub %st(0)
192 0xd8 0xe0
193
194 # CHECK: fsubr %st(0)
195 0xd8 0xe8
196
197 # CHECK: fdivr %st(0)
198 0xd8 0xf8
199
200 # CHECK: fdiv %st(0)
201 0xd8 0xf0
202
203 # CHECK: movl %cs, %eax
204 0x66 0x8c 0xc8
205
206 # CHECK: movw %cs, %ax
207 0x8c 0xc8
208
209 # CHECK: movl %cs, (%eax)
210 0x67 0x66 0x8c 0x08
211
212 # CHECK: movw %cs, (%eax)
213 0x67 0x8c 0x08
214
215 # CHECK: movl %eax, %cs
216 0x66 0x8e 0xc8
217
218 # CHECK: movl (%eax), %cs
219 0x67 0x66 0x8e 0x08
220
221 # CHECK: movw (%eax), %cs
222 0x67 0x8e 0x08
223
224 # CHECKX: movl %cr0, %eax
225 0x0f 0x20 0xc0
226
227 # CHECKX: movl %cr1, %eax
228 0x0f 0x20 0xc8
229
230 # CHECKX: movl %cr2, %eax
231 0x0f 0x20 0xd0
232
233 # CHECKX: movl %cr3, %eax
234 0x0f 0x20 0xd8
235
236 # CHECKX: movl %cr4, %eax
237 0x0f 0x20 0xe0
238
239 # CHECKX: movl %dr0, %eax
240 0x0f 0x21 0xc0
241
242 # CHECKX: movl %dr1, %eax
243 0x0f 0x21 0xc8
244
245 # CHECKX: movl %dr1, %eax
246 0x0f 0x21 0xc8
247
248 # CHECKX: movl %dr2, %eax
249 0x0f 0x21 0xd0
250
251 # CHECKX: movl %dr3, %eax
252 0x0f 0x21 0xd8
253
254 # CHECKX: movl %dr4, %eax
255 0x0f 0x21 0xe0
256
257 # CHECKX: movl %dr5, %eax
258 0x0f 0x21 0xe8
259
260 # CHECKX: movl %dr6, %eax
261 0x0f 0x21 0xf0
262
263 # CHECKX: movl %dr7, %eax
264 0x0f 0x21 0xf8
265
266 # CHECK: wait
267 0x9b
268
269 # CHECK: movl %gs:124, %eax
270 0x65 0x66 0x8b 0x06 0x7c 0x00
271
272 # CHECK: pushaw
273 0x60
274
275 # CHECK: popaw
276 0x61
277
278 # CHECK: pushaw
279 0x60
280
281 # CHECK: popaw
282 0x61
283
284 # CHECK: pushal
285 0x66 0x60
286
287 # CHECK: popal
288 0x66 0x61
289
290 # CHECK: jmpw *8(%eax)
291 0x67 0xff 0x60 0x08
292
293 # CHECK: jmpl *8(%eax)
294 0x67 0x66 0xff 0x60 0x08
295
296 # CHECK: lcalll $2, $4660
297 0x66 0x9a 0x34 0x12 0x00 0x00 0x02 0x00
298
299 # CHECKX: jcxz
300 0xe3 0x00
301
302 # CHECKX: jecxz
303 0x67 0xe3 0x00
304
305 # CHECK: iretw
306 0xcf
307
308 # CHECK: iretw
309 0xcf
310
311 # CHECK: iretl
312 0x66 0xcf
313
314 # CHECK: sysretl
315 0x0f 0x07
316
317 # CHECK: sysretl
318 0x0f 0x07
319
320 # CHECK: testl -24(%ebp), %ecx
321 0x67 0x66 0x85 0x4d 0xe8
322
323 # CHECK: testl -24(%ebp), %ecx
324 0x67 0x66 0x85 0x4d 0xe8
325
326 # CHECK: pushw %cs
327 0x0e
328
329 # CHECK: pushw %ds
330 0x1e
331
332 # CHECK: pushw %ss
333 0x16
334
335 # CHECK: pushw %es
336 0x06
337
338 # CHECK: pushw %fs
339 0x0f 0xa0
340
341 # CHECK: pushw %gs
342 0x0f 0xa8
343
344 # CHECK: pushw %cs
345 0x0e
346
347 # CHECK: pushw %ds
348 0x1e
349
350 # CHECK: pushw %ss
351 0x16
352
353 # CHECK: pushw %es
354 0x06
355
356 # CHECK: pushw %fs
357 0x0f 0xa0
358
359 # CHECK: pushw %gs
360 0x0f 0xa8
361
362 # CHECK: pushl %cs
363 0x66 0x0e
364
365 # CHECK: pushl %ds
366 0x66 0x1e
367
368 # CHECK: pushl %ss
369 0x66 0x16
370
371 # CHECK: pushl %es
372 0x66 0x06
373
374 # CHECK: pushl %fs
375 0x66 0x0f 0xa0
376
377 # CHECK: pushl %gs
378 0x66 0x0f 0xa8
379
380 # CHECK: popw %ss
381 0x17
382
383 # CHECK: popw %ds
384 0x1f
385
386 # CHECK: popw %es
387 0x07
388
389 # CHECK: popl %ss
390 0x66 0x17
391
392 # CHECK: popl %ds
393 0x66 0x1f
394
395 # CHECK: popl %es
396 0x66 0x07
397
398 # CHECK: pushfl
399 0x66 0x9c
400
401 # CHECK: popfl
402 0x66 0x9d
403
404 # CHECK: pushfl
405 0x66 0x9c
406
407 # CHECK: popfl
408 0x66 0x9d
409
410 # CHECK: setb %bl
411 0x0f 0x92 0xc3
412
413 # CHECK: setb %bl
414 0x0f 0x92 0xc3
415
416 # CHECK: setae %bl
417 0x0f 0x93 0xc3
418
419 # CHECK: setae %bl
420 0x0f 0x93 0xc3
421
422 # CHECK: setbe %bl
423 0x0f 0x96 0xc3
424
425 # CHECK: seta %bl
426 0x0f 0x97 0xc3
427
428 # CHECK: setp %bl
429 0x0f 0x9a 0xc3
430
431 # CHECK: setnp %bl
432 0x0f 0x9b 0xc3
433
434 # CHECK: setl %bl
435 0x0f 0x9c 0xc3
436
437 # CHECK: setge %bl
438 0x0f 0x9d 0xc3
439
440 # CHECK: setle %bl
441 0x0f 0x9e 0xc3
442
443 # CHECK: setg %bl
444 0x0f 0x9f 0xc3
445
446 # CHECK: setne %cl
447 0x0f 0x95 0xc1
448
449 # CHECK: setb %bl
450 0x0f 0x92 0xc3
451
452 # CHECK: setb %bl
453 0x0f 0x92 0xc3
454
455 # CHECK: lcalll $31438, $31438
456 0x66 0x9a 0xce 0x7a 0x00 0x00 0xce 0x7a
457
458 # CHECK: lcalll $31438, $31438
459 0x66 0x9a 0xce 0x7a 0x00 0x00 0xce 0x7a
460
461 # CHECK: ljmpl $31438, $31438
462 0x66 0xea 0xce 0x7a 0x00 0x00 0xce 0x7a
463
464 # CHECK: ljmpl $31438, $31438
465 0x66 0xea 0xce 0x7a 0x00 0x00 0xce 0x7a
466
467 # CHECK: lcallw $31438, $31438
468 0x9a 0xce 0x7a 0xce 0x7a
469
470 # CHECK: lcallw $31438, $31438
471 0x9a 0xce 0x7a 0xce 0x7a
472
473 # CHECK: ljmpw $31438, $31438
474 0xea 0xce 0x7a 0xce 0x7a
475
476 # CHECK: ljmpw $31438, $31438
477 0xea 0xce 0x7a 0xce 0x7a
478
479 # CHECK: lcallw $31438, $31438
480 0x9a 0xce 0x7a 0xce 0x7a
481
482 # CHECK: lcallw $31438, $31438
483 0x9a 0xce 0x7a 0xce 0x7a
484
485 # CHECK: ljmpw $31438, $31438
486 0xea 0xce 0x7a 0xce 0x7a
487
488 # CHECK: ljmpw $31438, $31438
489 0xea 0xce 0x7a 0xce 0x7a
490
491 # CHECK: calll
492 0x66 0xe8 0x00 0x00 0x00 0x00
493
494 # CHECKX: callw
495 #0xe8 0x00 0x00
496
497 # CHECK: incb %al
498 0xfe 0xc0
499
500 # CHECK: incw %ax
501 0x40
502
503 # CHECK: incl %eax
504 0x66 0x40
505
506 # CHECK: decb %al
507 0xfe 0xc8
508
509 # CHECK: decw %ax
510 0x48
511
512 # CHECK: decl %eax
513 0x66 0x48
514
515 # CHECK: pshufw $14, %mm4, %mm0
516 0x0f 0x70 0xc4 0x0e
517
518 # CHECK: pshufw $90, %mm4, %mm0
519 0x0f 0x70 0xc4 0x5a
520
521 # CHECK: aaa
522 0x37
523
524 # CHECK: aad $1
525 0xd5 0x01
526
527 # CHECK: aad
528 0xd5 0x0a
529
530 # CHECK: aad
531 0xd5 0x0a
532
533 # CHECK: aam $2
534 0xd4 0x02
535
536 # CHECK: aam
537 0xd4 0x0a
538
539 # CHECK: aam
540 0xd4 0x0a
541
542 # CHECK: aas
543 0x3f
544
545 # CHECK: daa
546 0x27
547
548 # CHECK: das
549 0x2f
550
551 # CHECK: retw $31438
552 0xc2 0xce 0x7a
553
554 # CHECK: lretw $31438
555 0xca 0xce 0x7a
556
557 # CHECK: retw $31438
558 0xc2 0xce 0x7a
559
560 # CHECK: lretw $31438
561 0xca 0xce 0x7a
562
563 # CHECK: retl $31438
564 0x66 0xc2 0xce 0x7a
565
566 # CHECK: lretl $31438
567 0x66 0xca 0xce 0x7a
568
569 # CHECK: bound 2(%eax), %bx
570 0x67 0x62 0x58 0x02
571
572 # CHECK: bound 4(%ebx), %ecx
573 0x67 0x66 0x62 0x4b 0x04
574
575 # CHECK: arpl %bx, %bx
576 0x63 0xdb
577
578 # CHECK: arpl %bx, 6(%ecx)
579 0x67 0x63 0x59 0x06
580
581 # CHECK: lgdtw 4(%eax)
582 0x67 0x0f 0x01 0x50 0x04
583
584 # CHECK: lgdtw 4(%eax)
585 0x67 0x0f 0x01 0x50 0x04
586
587 # CHECK: lgdtl 4(%eax)
588 0x67 0x66 0x0f 0x01 0x50 0x04
589
590 # CHECK: lidtw 4(%eax)
591 0x67 0x0f 0x01 0x58 0x04
592
593 # CHECK: lidtw 4(%eax)
594 0x67 0x0f 0x01 0x58 0x04
595
596 # CHECK: lidtl 4(%eax)
597 0x67 0x66 0x0f 0x01 0x58 0x04
598
599 # CHECK: sgdtw 4(%eax)
600 0x67 0x0f 0x01 0x40 0x04
601
602 # CHECK: sgdtw 4(%eax)
603 0x67 0x0f 0x01 0x40 0x04
604
605 # CHECK: sgdtl 4(%eax)
606 0x67 0x66 0x0f 0x01 0x40 0x04
607
608 # CHECK: sidtw 4(%eax)
609 0x67 0x0f 0x01 0x48 0x04
610
611 # CHECK: sidtw 4(%eax)
612 0x67 0x0f 0x01 0x48 0x04
613
614 # CHECK: sidtl 4(%eax)
615 0x67 0x66 0x0f 0x01 0x48 0x04
616
617 # CHECK: fcompi %st(2)
618 0xdf 0xf2
619
620 # CHECK: fcompi %st(2)
621 0xdf 0xf2
622
623 # CHECK: fcompi %st(1)
624 0xdf 0xf1
625
626 # CHECK: fucompi %st(2)
627 0xdf 0xea
628
629 # CHECK: fucompi %st(2)
630 0xdf 0xea
631
632 # CHECK: fucompi %st(1)
633 0xdf 0xe9
634
635 # CHECK: fldcw 32493
636 0xd9 0x2e 0xed 0x7e
637
638 # CHECK: fldcw 32493
639 0xd9 0x2e 0xed 0x7e
640
641 # CHECK: fnstcw 32493
642 0xd9 0x3e 0xed 0x7e
643
644 # CHECK: fnstcw 32493
645 0xd9 0x3e 0xed 0x7e
646
647 # CHECK: wait
648 0x9b
649
650 # CHECK: fnstcw 32493
651 0xd9 0x3e 0xed 0x7e
652
653 # CHECK: wait
654 0x9b
655
656 # CHECK: fnstcw 32493
657 0xd9 0x3e 0xed 0x7e
658
659 # CHECK: fnstsw 32493
660 0xdd 0x3e 0xed 0x7e
661
662 # CHECK: fnstsw 32493
663 0xdd 0x3e 0xed 0x7e
664
665 # CHECK: wait
666 0x9b
667
668 # CHECK: fnstsw 32493
669 0xdd 0x3e 0xed 0x7e
670
671 # CHECK: wait
672 0x9b
673
674 # CHECK: fnstsw 32493
675 0xdd 0x3e 0xed 0x7e
676
677 # CHECK: verr 32493
678 0x0f 0x00 0x26 0xed 0x7e
679
680 # CHECK: verr 32493
681 0x0f 0x00 0x26 0xed 0x7e
682
683 # CHECK: wait
684 0x9b
685
686 # CHECK: fnclex
687 0xdb 0xe2
688
689 # CHECK: fnclex
690 0xdb 0xe2
691
692 # CHECK: ud2
693 0x0f 0x0b
694
695 # CHECK: ud2
696 0x0f 0x0b
697
698 # CHECK: ud2b
699 0x0f 0xb9
700
701 # CHECK: loope
702 0xe1 0x00
703
704 # CHECK: loopne
705 0xe0 0x00
706
707 # CHECK: outsb
708 0x6e
709
710 # CHECKX: outsw
711 0x6f
712
713 # CHECKX: outsl
714 0x66 0x6f
715
716 # CHECK: insb
717 0x6c
718
719 # CHECK: insw
720 0x6d
721
722 # CHECK: insl
723 0x66 0x6d
724
725 # CHECK: movsb
726 0xa4
727
728 # CHECKX: movsw
729 0xa5
730
731 # CHECKX: movsl
732 0x66 0xa5
733
734 # CHECKX: lodsb
735 0xac
736
737 # CHECKX: lodsw
738 0xad
739
740 # CHECKX: lodsl
741 0x66 0xad
742
743 # CHECK: stosb
744 0xaa
745
746 # CHECKX: stosw
747 0xab
748
749 # CHECKX: stosl
750 0x66 0xab
751
752 # CHECK: strw %ax
753 0x0f 0x00 0xc8
754
755 # CHECK: strl %eax
756 0x66 0x0f 0x00 0xc8
757
758 # CHECK: fsubp %st(1)
759 0xde 0xe1
760
761 # CHECK: fsubp %st(2)
762 0xde 0xe2
763
764 # CHECKX: nop
765 0x66 0x90
766
767 # CHECKX: nop
768 0x90
769
770 # CHECK: xchgl %ecx, %eax
771 0x66 0x91
772
773 # CHECK: xchgl %ecx, %eax
774 0x66 0x91
775
776 # CHECK: retw
777 0xc3
778
779 # CHECK: retl
780 0x66 0xc3
781
782 # CHECK: lretw
783 0xcb
784
785 # CHECK: lretl
786 0x66 0xcb
787