parse_x64.c (63012B)
1 #include "../../../config.h" 2 3 #include "arch.h" 4 #include "parse_asm.h" 5 6 #include <assert.h> 7 #include <ctype.h> 8 #include <stddef.h> 9 #include <string.h> 10 #include <strings.h> 11 12 #include "inst.h" 13 #include "tcutil.h" 14 15 enum RawOpcode { 16 R_NOOP, 17 R_MOV, 18 R_MOVB, 19 R_MOVW, 20 R_MOVL, 21 R_MOVQ, 22 R_MOVSX, 23 R_MOVZX, 24 R_LEA, 25 26 R_ADD, 27 R_ADDQ, 28 R_SUB, 29 R_SUBQ, 30 R_MUL, 31 R_DIV, 32 R_IDIV, 33 R_NEG, 34 R_NOT, 35 R_INC, 36 R_INCB, 37 R_INCW, 38 R_INCL, 39 R_INCQ, 40 R_DEC, 41 R_DECB, 42 R_DECW, 43 R_DECL, 44 R_DECQ, 45 R_AND, 46 R_OR, 47 R_XOR, 48 R_SHL, 49 R_SHR, 50 R_SAR, 51 R_CMP, 52 R_TEST, 53 R_CWTL, 54 R_CLTD, 55 R_CQTO, 56 R_BSR, 57 R_LZCNT, 58 R_TZCNT, 59 R_POPCNT, 60 61 R_SETO, 62 R_SETNO, 63 R_SETB, 64 R_SETAE, 65 R_SETE, 66 R_SETNE, 67 R_SETBE, 68 R_SETA, 69 R_SETS, 70 R_SETNS, 71 R_SETP, 72 R_SETNP, 73 R_SETL, 74 R_SETGE, 75 R_SETLE, 76 R_SETG, 77 78 R_JMP, 79 R_JO, 80 R_JNO, 81 R_JB, 82 R_JAE, 83 R_JE, 84 R_JNE, 85 R_JBE, 86 R_JA, 87 R_JS, 88 R_JNS, 89 R_JP, 90 R_JNP, 91 R_JL, 92 R_JGE, 93 R_JLE, 94 R_JG, 95 R_CALL, 96 R_RET, 97 R_PUSH, 98 R_POP, 99 100 R_INT, 101 R_SYSCALL, 102 103 R_MOVSD, 104 R_ADDSD, 105 R_SUBSD, 106 R_MULSD, 107 R_DIVSD, 108 R_XORPD, 109 R_COMISD, 110 R_UCOMISD, 111 R_CVTSI2SD, 112 R_CVTTSD2SI, 113 R_SQRTSD, 114 115 R_MOVSS, 116 R_ADDSS, 117 R_SUBSS, 118 R_MULSS, 119 R_DIVSS, 120 R_XORPS, 121 R_COMISS, 122 R_UCOMISS, 123 R_CVTSI2SS, 124 R_CVTTSS2SI, 125 R_CVTSD2SS, 126 R_CVTSS2SD, 127 128 R_ENDBR64, 129 130 /* no-operand instructions */ 131 R_NOP, 132 R_PUSHFQ, 133 R_POPFQ, 134 R_PUSHF, 135 R_POPF, 136 R_CPUID, 137 R_RDTSC, 138 R_UD2, 139 R_PAUSE, 140 R_HLT, 141 R_CMC, 142 R_CLC, 143 R_STC, 144 R_CLI, 145 R_STI, 146 R_CLD, 147 R_STD, 148 R_CLTS, 149 R_WBINVD, 150 R_MFENCE, 151 R_LFENCE, 152 R_SFENCE, 153 154 /* register instructions */ 155 R_IMUL, 156 R_BSF, 157 R_BSWAP, 158 R_XADD, 159 R_CMPXCHG, 160 R_LEAVE, 161 R_ENTER, 162 R_XCHG, 163 164 /* bit test */ 165 R_BT, 166 R_BTS, 167 R_BTR, 168 R_BTC, 169 170 /* conditional move */ 171 R_CMOVO, 172 R_CMOVNO, 173 R_CMOVB, 174 R_CMOVAE, 175 R_CMOVE, 176 R_CMOVNE, 177 R_CMOVBE, 178 R_CMOVA, 179 R_CMOVS, 180 R_CMOVNS, 181 R_CMOVP, 182 R_CMOVNP, 183 R_CMOVL, 184 R_CMOVGE, 185 R_CMOVLE, 186 R_CMOVG, 187 188 /* string operations */ 189 R_MOVSB, 190 R_MOVSW, 191 R_MOVSL, 192 R_MOVSQ, 193 R_STOSB, 194 R_STOSW, 195 R_STOSL, 196 R_STOSQ, 197 R_LODSB, 198 R_LODSW, 199 R_LODSL, 200 R_LODSQ, 201 R_SCASB, 202 R_SCASW, 203 R_SCASL, 204 R_SCASQ, 205 R_CMPSB, 206 R_CMPSW, 207 R_CMPSL, 208 R_CMPSQ, 209 210 /* gas conversion aliases */ 211 R_CBW, 212 R_CDQE, 213 R_CWD, 214 215 /* condition code aliases accepted by gas */ 216 R_JC, 217 R_JNAE, 218 R_JNB, 219 R_JZ, 220 R_JNZ, 221 R_JNA, 222 R_JNBE, 223 R_JNGE, 224 R_JNL, 225 R_JNG, 226 R_JNLE, 227 R_JPE, 228 R_JPO, 229 R_CMOVZ, 230 R_CMOVNZ, 231 232 /* gas-style explicit size suffixes that qbe's amd64_sysv backend 233 * emits, which this table otherwise only has for mov/inc/dec. 234 * appended instead of inserted next to their unsuffixed siblings, 235 * because kRawOpTable's array position is the enum value (see 236 * find_raw_opcode's i + 1 return) and an insertion would shift every 237 * later opcode */ 238 R_MOVSLQ, 239 R_MOVSBW, 240 R_MOVSBL, 241 R_MOVSBQ, 242 R_MOVSWL, 243 R_MOVSWQ, 244 R_MOVZBW, 245 R_MOVZBL, 246 R_MOVZBQ, 247 R_MOVZWL, 248 R_MOVZWQ, 249 R_LEAQ, 250 R_ADDL, 251 R_SUBL, 252 R_IDIVL, 253 R_ANDL, 254 R_ANDQ, 255 R_ORL, 256 R_ORQ, 257 R_SHLL, 258 R_SHLQ, 259 R_SHRL, 260 R_SHRQ, 261 R_SARL, 262 R_SARQ, 263 R_CMPL, 264 R_CMPQ, 265 R_CALLQ, 266 R_PUSHQ, 267 R_POPQ, 268 R_CVTTSD2SIL, 269 R_CVTTSD2SIQ, 270 R_CVTTSS2SIL, 271 R_CVTTSS2SIQ, 272 R_XCHGL, 273 R_XCHGQ, 274 R_SETZ, 275 R_SETNZ, 276 R_XORL, 277 R_XORQ, 278 R_NEGL, 279 R_NEGQ, 280 }; 281 282 const char *kRawOpTable[] = { 283 "mov", 284 "movb", 285 "movw", 286 "movl", 287 "movq", 288 "movsx", 289 "movzx", 290 "lea", 291 292 "add", 293 "addq", 294 "sub", 295 "subq", 296 "mul", 297 "div", 298 "idiv", 299 "neg", 300 "not", 301 "inc", 302 "incb", 303 "incw", 304 "incl", 305 "incq", 306 "dec", 307 "decb", 308 "decw", 309 "decl", 310 "decq", 311 "and", 312 "or", 313 "xor", 314 "shl", 315 "shr", 316 "sar", 317 "cmp", 318 "test", 319 "cwtl", 320 "cltd", 321 "cqto", 322 "bsr", 323 "lzcnt", 324 "tzcnt", 325 "popcnt", 326 327 "seto", 328 "setno", 329 "setb", 330 "setae", 331 "sete", 332 "setne", 333 "setbe", 334 "seta", 335 "sets", 336 "setns", 337 "setp", 338 "setnp", 339 "setl", 340 "setge", 341 "setle", 342 "setg", 343 344 "jmp", 345 "jo", 346 "jno", 347 "jb", 348 "jae", 349 "je", 350 "jne", 351 "jbe", 352 "ja", 353 "js", 354 "jns", 355 "jp", 356 "jnp", 357 "jl", 358 "jge", 359 "jle", 360 "jg", 361 "call", 362 "ret", 363 "push", 364 "pop", 365 366 "int", 367 "syscall", 368 369 "movsd", 370 "addsd", 371 "subsd", 372 "mulsd", 373 "divsd", 374 "xorpd", 375 "comisd", 376 "ucomisd", 377 "cvtsi2sd", 378 "cvttsd2si", 379 "sqrtsd", 380 381 "movss", 382 "addss", 383 "subss", 384 "mulss", 385 "divss", 386 "xorps", 387 "comiss", 388 "ucomiss", 389 "cvtsi2ss", 390 "cvttss2si", 391 "cvtsd2ss", 392 "cvtss2sd", 393 394 "endbr64", 395 396 /* no-operand */ 397 "nop", 398 "pushfq", 399 "popfq", 400 "pushf", 401 "popf", 402 "cpuid", 403 "rdtsc", 404 "ud2", 405 "pause", 406 "hlt", 407 "cmc", 408 "clc", 409 "stc", 410 "cli", 411 "sti", 412 "cld", 413 "std", 414 "clts", 415 "wbinvd", 416 "mfence", 417 "lfence", 418 "sfence", 419 420 /* register instructions */ 421 "imul", 422 "bsf", 423 "bswap", 424 "xadd", 425 "cmpxchg", 426 "leave", 427 "enter", 428 "xchg", 429 430 /* bit test */ 431 "bt", 432 "bts", 433 "btr", 434 "btc", 435 436 /* conditional move */ 437 "cmovo", 438 "cmovno", 439 "cmovb", 440 "cmovae", 441 "cmove", 442 "cmovne", 443 "cmovbe", 444 "cmova", 445 "cmovs", 446 "cmovns", 447 "cmovp", 448 "cmovnp", 449 "cmovl", 450 "cmovge", 451 "cmovle", 452 "cmovg", 453 454 /* string operations */ 455 "movsb", 456 "movsw", 457 "movsl", 458 "movsq", 459 "stosb", 460 "stosw", 461 "stosl", 462 "stosq", 463 "lodsb", 464 "lodsw", 465 "lodsl", 466 "lodsq", 467 "scasb", 468 "scasw", 469 "scasl", 470 "scasq", 471 "cmpsb", 472 "cmpsw", 473 "cmpsl", 474 "cmpsq", 475 476 /* gas conversion aliases */ 477 "cbw", 478 "cdqe", 479 "cwd", 480 481 /* condition code aliases */ 482 "jc", 483 "jnae", 484 "jnb", 485 "jz", 486 "jnz", 487 "jna", 488 "jnbe", 489 "jnge", 490 "jnl", 491 "jng", 492 "jnle", 493 "jpe", 494 "jpo", 495 "cmovz", 496 "cmovnz", 497 498 /* must stay in the same order as the R_* additions appended to 499 * enum RawOpcode above, this array's position doubles as that 500 * enum's value */ 501 "movslq", 502 "movsbw", 503 "movsbl", 504 "movsbq", 505 "movswl", 506 "movswq", 507 "movzbw", 508 "movzbl", 509 "movzbq", 510 "movzwl", 511 "movzwq", 512 "leaq", 513 "addl", 514 "subl", 515 "idivl", 516 "andl", 517 "andq", 518 "orl", 519 "orq", 520 "shll", 521 "shlq", 522 "shrl", 523 "shrq", 524 "sarl", 525 "sarq", 526 "cmpl", 527 "cmpq", 528 "callq", 529 "pushq", 530 "popq", 531 "cvttsd2sil", 532 "cvttsd2siq", 533 "cvttss2sil", 534 "cvttss2siq", 535 "xchgl", 536 "xchgq", 537 "setz", 538 "setnz", 539 "xorl", 540 "xorq", 541 "negl", 542 "negq", 543 NULL, 544 }; 545 546 static const struct { 547 const char *name; 548 enum RegType reg; 549 } kRegisters[] = { 550 /* 8bit */ 551 {"al", AL}, 552 {"cl", CL}, 553 {"dl", DL}, 554 {"bl", BL}, 555 {"ah", AH}, 556 {"ch", CH}, 557 {"dh", DH}, 558 {"bh", BH}, 559 {"r8b", R8B}, 560 {"r9b", R9B}, 561 {"r10b", R10B}, 562 {"r11b", R11B}, 563 {"r12b", R12B}, 564 {"r13b", R13B}, 565 {"r14b", R14B}, 566 {"r15b", R15B}, 567 {"spl", SPL}, 568 {"bpl", BPL}, 569 {"sil", SIL}, 570 {"dil", DIL}, 571 572 /* 16bit */ 573 {"ax", AX}, 574 {"cx", CX}, 575 {"dx", DX}, 576 {"bx", BX}, 577 {"sp", SP}, 578 {"bp", BP}, 579 {"si", SI}, 580 {"di", DI}, 581 {"r8w", R8W}, 582 {"r9w", R9W}, 583 {"r10w", R10W}, 584 {"r11w", R11W}, 585 {"r12w", R12W}, 586 {"r13w", R13W}, 587 {"r14w", R14W}, 588 {"r15w", R15W}, 589 590 /* 32bit */ 591 {"eax", EAX}, 592 {"ecx", ECX}, 593 {"edx", EDX}, 594 {"ebx", EBX}, 595 {"esp", ESP}, 596 {"ebp", EBP}, 597 {"esi", ESI}, 598 {"edi", EDI}, 599 {"r8d", R8D}, 600 {"r9d", R9D}, 601 {"r10d", R10D}, 602 {"r11d", R11D}, 603 {"r12d", R12D}, 604 {"r13d", R13D}, 605 {"r14d", R14D}, 606 {"r15d", R15D}, 607 608 /* 64bit */ 609 {"rax", RAX}, 610 {"rcx", RCX}, 611 {"rdx", RDX}, 612 {"rbx", RBX}, 613 {"rsp", RSP}, 614 {"rbp", RBP}, 615 {"rsi", RSI}, 616 {"rdi", RDI}, 617 {"r8", R8}, 618 {"r9", R9}, 619 {"r10", R10}, 620 {"r11", R11}, 621 {"r12", R12}, 622 {"r13", R13}, 623 {"r14", R14}, 624 {"r15", R15}, 625 {"rip", RIP}, 626 627 /* segment register */ 628 {"cs", CS}, 629 {"ds", DS}, 630 {"es", ES}, 631 {"fs", FS}, 632 {"gs", GS}, 633 {"ss", SS}, 634 }; 635 636 static const char kXmmRegisters[][6] = { 637 "xmm0", 638 "xmm1", 639 "xmm2", 640 "xmm3", 641 "xmm4", 642 "xmm5", 643 "xmm6", 644 "xmm7", 645 "xmm8", 646 "xmm9", 647 "xmm10", 648 "xmm11", 649 "xmm12", 650 "xmm13", 651 "xmm14", 652 "xmm15", 653 }; 654 655 static inline int 656 is_reg8(enum RegType reg) 657 { 658 return reg >= AL && reg <= DIL; 659 } 660 661 static inline int 662 is_reg16(enum RegType reg) 663 { 664 return reg >= AX && reg <= R15W; 665 } 666 667 static inline int 668 is_reg32(enum RegType reg) 669 { 670 return reg >= EAX && reg <= R15D; 671 } 672 673 static inline int 674 is_reg64(enum RegType reg) 675 { 676 return reg >= RAX && reg <= R15; 677 } 678 679 static inline int 680 is_segment(enum RegType reg) 681 { 682 return reg >= CS && reg <= SS; 683 } 684 685 #define R8 (1 << 0) 686 #define R16 (1 << 1) 687 #define R32 (1 << 2) 688 #define R64 (1 << 3) 689 #define R8CL (1 << 4) 690 #define IMM (1 << 5) 691 #define EXP (1 << 6) 692 #define IND (1 << 7) 693 #define IIND (1 << 8) 694 #define DER (1 << 9) /* deref reg64 */ 695 #define DEI (1 << 10) /* deref indirect */ 696 #define DEII (1 << 11) /* deref indirect with index */ 697 #define XMM (1 << 12) 698 #define SEG (1 << 13) 699 #define YMM (1 << 14) 700 701 /* scan for x86 instruction prefix keywords */ 702 unsigned char 703 x64_scan_prefix(struct ParseInfo *info) 704 { 705 static const struct { 706 const char *name; 707 unsigned char flag; 708 } prefixes[] = { 709 {"lock", PREFIX_LOCK}, 710 {"rep", PREFIX_REP}, 711 {"repe", PREFIX_REP}, 712 {"repz", PREFIX_REP}, 713 {"repne", PREFIX_REPNE}, 714 {"repnz", PREFIX_REPNE}, 715 }; 716 const char *p = info->p; 717 const char *start = p; 718 while (isalnum(*p) || *p == '.') 719 ++p; 720 size_t n = p - start; 721 if (n > 0 && (*p == '\0' || isspace(*p))) { 722 for (int i = 0; i < (int)ARRAY_SIZE(prefixes); ++i) { 723 if (n == strlen(prefixes[i].name) && strncasecmp(start, prefixes[i].name, n) == 0) { 724 info->p = skip_whitespaces(p); 725 return prefixes[i].flag; 726 } 727 } 728 } 729 return 0; 730 } 731 732 static enum RegType 733 find_register(const char **pp) 734 { 735 const char *p = *pp; 736 for (int i = 0; i < (int)ARRAY_SIZE(kRegisters); ++i) { 737 const char *name = kRegisters[i].name; 738 size_t n = strlen(name); 739 if (strncasecmp(p, name, n) == 0 && !is_label_chr(p[n])) { 740 *pp = p + n; 741 return kRegisters[i].reg; 742 } 743 } 744 return NOREG; 745 } 746 747 static enum RegXmmType 748 find_xmm_register(const char **pp) 749 { 750 const char *p = *pp; 751 const char *q; 752 for (q = p; isalnum(*q); ++q) 753 ; 754 size_t l = q - p; 755 756 for (int i = 0; i < (int)ARRAY_SIZE(kXmmRegisters); ++i) { 757 const char *name = kXmmRegisters[i]; 758 size_t n = strlen(name); 759 if (l == n && strncasecmp(p, name, n) == 0) { 760 *pp = p + n; 761 return i + XMM0; 762 } 763 } 764 return NOREGXMM; 765 } 766 767 static unsigned int 768 parse_direct_register(struct ParseInfo *info, struct Operand *operand) 769 { 770 { 771 enum RegXmmType regxmm = find_xmm_register(&info->p); 772 if (regxmm != NOREGXMM) { 773 operand->type = REG_XMM; 774 operand->u.regxmm = regxmm; 775 return XMM; 776 } 777 } 778 779 enum RegType reg = find_register(&info->p); 780 if (is_segment(reg)) { 781 struct Expr *offset = NULL; 782 int flag = 0; 783 if (*info->p == ':') { 784 ++info->p; 785 offset = parse_expr(info); 786 if (strncasecmp(info->p, "@tpoff", 6) == 0 && !is_label_chr(info->p[6])) { 787 info->p += 6; 788 flag = LF_TPOFF; 789 } 790 } 791 operand->type = SEGMENT_OFFSET; 792 operand->u.segment.reg = reg; 793 operand->u.segment.offset.expr = offset; 794 operand->u.segment.offset.flag = flag; 795 return SEG; 796 } 797 798 enum RegSize size; 799 int no; 800 if (is_reg8(reg)) { 801 size = REG8; 802 no = reg - AL; 803 } else if (is_reg16(reg)) { 804 size = REG16; 805 no = reg - AX; 806 } else if (is_reg32(reg)) { 807 size = REG32; 808 no = reg - EAX; 809 } else if (is_reg64(reg)) { 810 size = REG64; 811 no = reg - RAX; 812 } else { 813 parse_error(info, "illegal register"); 814 return 0; 815 } 816 817 operand->type = REG; 818 operand->u.reg.size = size; 819 operand->u.reg.no = no & 7; 820 operand->u.reg.x = no >> 3; 821 return (R8 << (size - REG8)) | (reg == CL ? R8CL : 0); 822 } 823 824 #if TC_TARGET_PLATFORM == TC_PLATFORM_APPLE 825 static int 826 parse_label_postfix(struct ParseInfo *info) 827 { 828 static struct { 829 const char *name; 830 int flag; 831 } const kPostfixes[] = { 832 {"@gotpcrel", LF_GOTPCREL}, 833 }; 834 const char *p = info->p; 835 for (size_t i = 0; i < ARRAY_SIZE(kPostfixes); ++i) { 836 const char *name = kPostfixes[i].name; 837 size_t n = strlen(name); 838 if (strncasecmp(p, name, n) == 0 && !is_label_chr(p[n])) { 839 info->p = p + n; 840 return kPostfixes[i].flag; 841 } 842 } 843 return 0; 844 } 845 #endif 846 847 static struct ExprWithFlag 848 parse_expr_with_flag(struct ParseInfo *info) 849 { 850 /* expr = label + nn */ 851 #if TC_TARGET_PLATFORM == TC_PLATFORM_APPLE 852 /* expr@page */ 853 /* expr@pageoff */ 854 /* expr@gotpage */ 855 /* expr@gotpageoff */ 856 struct Expr *expr = parse_expr(info); 857 int flag = parse_label_postfix(info); 858 #else 859 int flag = 0; 860 struct Expr *expr = parse_expr(info); 861 #endif 862 return (struct ExprWithFlag){expr, flag}; 863 } 864 865 static unsigned int 866 parse_indirect_register( 867 struct ParseInfo *info, struct ExprWithFlag *offset, struct Operand *operand 868 ) 869 { 870 enum RegType index_reg = NOREG; 871 struct Expr *scale = NULL; 872 /* already read "(%" */ 873 enum RegType base_reg = find_register(&info->p); 874 875 info->p = skip_whitespaces(info->p); 876 if (*info->p == ',') { 877 info->p = skip_whitespaces(info->p + 1); 878 if (*info->p != '%' || (++info->p, index_reg = find_register(&info->p), !is_reg64(index_reg))) 879 parse_error(info, "register expected"); 880 info->p = skip_whitespaces(info->p); 881 if (*info->p == ',') { 882 info->p = skip_whitespaces(info->p + 1); 883 scale = parse_expr(info); 884 if (scale->kind != EX_FIXNUM) 885 parse_error(info, "constant value expected"); 886 info->p = skip_whitespaces(info->p); 887 } 888 } 889 if (*info->p != ')') 890 parse_error(info, "`)' expected"); 891 else 892 ++info->p; 893 894 if (!(is_reg64(base_reg) || (base_reg == RIP && index_reg == NOREG))) 895 parse_error(info, "register expected"); 896 897 if (index_reg == NOREG) { 898 char no = base_reg - RAX; 899 operand->type = INDIRECT; 900 operand->u.indirect.reg.size = REG64; 901 operand->u.indirect.reg.no = base_reg != RIP ? no & 7 : RIP; 902 operand->u.indirect.reg.x = (no & 8) >> 3; 903 operand->u.indirect.offset = *offset; 904 return IND; 905 } else { 906 if (!is_reg64(index_reg)) 907 parse_error(info, "register expected"); 908 909 operand->type = INDIRECT_WITH_INDEX; 910 operand->u.indirect_with_index.offset = offset->expr; 911 operand->u.indirect_with_index.scale = scale; 912 char base_no = base_reg - RAX; 913 operand->u.indirect_with_index.base_reg.size = REG64; 914 operand->u.indirect_with_index.base_reg.no = base_no & 7; 915 operand->u.indirect_with_index.base_reg.x = (base_no & 8) >> 3; 916 char index_no = index_reg - RAX; 917 operand->u.indirect_with_index.index_reg.size = REG64; 918 operand->u.indirect_with_index.index_reg.no = index_no & 7; 919 operand->u.indirect_with_index.index_reg.x = (index_no & 8) >> 3; 920 return IIND; 921 } 922 } 923 924 static enum RegType 925 parse_deref_register(struct ParseInfo *info, struct Operand *operand) 926 { 927 enum RegType reg = find_register(&info->p); 928 if (!is_reg64(reg)) 929 parse_error(info, "illegal register"); 930 931 char no = reg - RAX; 932 operand->type = DEREF_REG; 933 operand->u.reg.size = REG64; 934 operand->u.reg.no = no & 7; 935 operand->u.reg.x = (no & 8) >> 3; 936 return 1; 937 } 938 939 static unsigned int 940 parse_deref_indirect(struct ParseInfo *info, struct Operand *operand) 941 { 942 struct Expr *offset = parse_expr(info); 943 info->p = skip_whitespaces(info->p); 944 if (*info->p != '(') { 945 parse_error(info, "direct number not implemented"); 946 return 0; 947 } 948 if (info->p[1] != '%') { 949 parse_error(info, "register expected"); 950 return 0; 951 } 952 info->p += 2; 953 954 enum RegType index_reg = NOREG; 955 struct Expr *scale = NULL; 956 /* already read "(%" */ 957 enum RegType base_reg = find_register(&info->p); 958 959 info->p = skip_whitespaces(info->p); 960 if (*info->p == ',') { 961 info->p = skip_whitespaces(info->p + 1); 962 if (*info->p != '%' || (++info->p, index_reg = find_register(&info->p), !is_reg64(index_reg))) 963 parse_error(info, "register expected"); 964 info->p = skip_whitespaces(info->p); 965 if (*info->p == ',') { 966 info->p = skip_whitespaces(info->p + 1); 967 scale = parse_expr(info); 968 if (scale->kind != EX_FIXNUM) 969 parse_error(info, "constant value expected"); 970 info->p = skip_whitespaces(info->p); 971 } 972 } 973 if (*info->p != ')') 974 parse_error(info, "`)' expected"); 975 else 976 ++info->p; 977 978 if (!is_reg64(base_reg) || (index_reg != NOREG && !is_reg64(index_reg))) 979 parse_error(info, "register expected"); 980 981 if (index_reg == NOREG) { 982 operand->type = DEREF_INDIRECT; 983 operand->u.indirect.offset.expr = offset; 984 operand->u.indirect.offset.flag = 0; 985 char reg_no = base_reg - RAX; 986 operand->u.indirect.reg.size = REG64; 987 operand->u.indirect.reg.no = reg_no & 7; 988 operand->u.indirect.reg.x = (reg_no & 8) >> 3; 989 return DEI; 990 } else { 991 operand->type = DEREF_INDIRECT_WITH_INDEX; 992 operand->u.indirect_with_index.offset = offset; 993 operand->u.indirect_with_index.scale = scale; 994 char base_no = base_reg - RAX; 995 operand->u.indirect_with_index.base_reg.size = REG64; 996 operand->u.indirect_with_index.base_reg.no = base_no & 7; 997 operand->u.indirect_with_index.base_reg.x = (base_no & 8) >> 3; 998 operand->u.indirect_with_index.index_reg.size = REG64; 999 char index_no = index_reg - RAX; 1000 operand->u.indirect_with_index.index_reg.size = REG64; 1001 operand->u.indirect_with_index.index_reg.no = index_no & 7; 1002 operand->u.indirect_with_index.index_reg.x = (index_no & 8) >> 3; 1003 return DEII; 1004 } 1005 } 1006 1007 unsigned int 1008 parse_operand(struct ParseInfo *info, unsigned int opr_flag, struct Operand *operand) 1009 { 1010 const char *p = info->p; 1011 if (opr_flag & (R8 | R16 | R32 | R64 | R8CL | XMM)) { 1012 if (*p == '%') { 1013 info->p = p + 1; 1014 return parse_direct_register(info, operand) & opr_flag; 1015 } 1016 } 1017 1018 if (opr_flag & (DER | DEI)) { 1019 if (*p == '*') { 1020 if (opr_flag & DER) { 1021 if (p[1] == '%') { 1022 info->p = p + 2; 1023 if (parse_deref_register(info, operand)) 1024 return DER; 1025 } 1026 } 1027 if (opr_flag & DEI) { 1028 info->p = p + 1; 1029 return parse_deref_indirect(info, operand); 1030 } 1031 } 1032 } 1033 1034 if (opr_flag & IMM) { 1035 if (*p == '$') { 1036 info->p = p + 1; 1037 if (!immediate(&info->p, &operand->u.immediate)) 1038 parse_error(info, "syntax error"); 1039 operand->type = IMMEDIATE; 1040 return IMM; 1041 } 1042 } 1043 1044 struct ExprWithFlag expr_with_flag = parse_expr_with_flag(info); 1045 if (*info->p == '@') { 1046 /* relocation suffix (@plt, @got, @gotpcrel, @gottpoff, ...): this 1047 * toolchain is static-only, so a direct call/jump target needs 1048 * nothing beyond the bare symbol. @gottpoff is the exception: an 1049 * initial-exec tls load through (%rip) is still a got lookup in a 1050 * static binary, so it is kept as a flag */ 1051 if (strncasecmp(info->p, "@gottpoff", 9) == 0 && !is_label_chr(info->p[9])) { 1052 expr_with_flag.flag |= LF_GOTTPOFF; 1053 info->p += 9; 1054 } else { 1055 const char *q = info->p + 1; 1056 while (isalpha((unsigned char)*q) || isdigit((unsigned char)*q)) 1057 ++q; 1058 info->p = q; 1059 } 1060 } 1061 info->p = skip_whitespaces(info->p); 1062 if (*info->p != '(') { 1063 if (expr_with_flag.expr != NULL) { 1064 if (expr_with_flag.expr->kind == EX_LABEL || expr_with_flag.expr->kind == EX_FIXNUM 1065 || expr_with_flag.expr->kind == EX_ADD || expr_with_flag.expr->kind == EX_SUB) { 1066 operand->type = DIRECT; 1067 operand->u.direct.expr = expr_with_flag.expr; 1068 return EXP; 1069 } 1070 parse_error(info, "direct number not implemented"); 1071 } 1072 } else { 1073 if (info->p[1] == '%') { 1074 info->p += 2; 1075 if (expr_with_flag.expr == NULL) { 1076 struct Expr *expr = calloc_or_die(sizeof(*expr)); 1077 expr->kind = EX_FIXNUM; 1078 expr->u.fixnum = 0; 1079 expr_with_flag.expr = expr; 1080 } 1081 return parse_indirect_register(info, &expr_with_flag, operand); 1082 } 1083 } 1084 1085 return 0; 1086 } 1087 1088 const struct ParseInstTable kParseInstTable[] = { 1089 [R_MOV] = 1090 {11, 1091 (const struct ParseOpArray *[]){ 1092 &(struct ParseOpArray){MOV_RR, {R8, R8}}, 1093 &(struct ParseOpArray){MOV_RR, {R16, R16}}, 1094 &(struct ParseOpArray){MOV_RR, {R32, R32}}, 1095 &(struct ParseOpArray){MOV_RR, {R64, R64}}, 1096 &(struct ParseOpArray){MOV_IMR, {IMM, R8 | R16 | R32 | R64}}, 1097 &(struct ParseOpArray){MOV_IR, {IND, R8 | R16 | R32 | R64}}, 1098 &(struct ParseOpArray){MOV_RI, {R8 | R16 | R32 | R64, IND}}, 1099 &(struct ParseOpArray){MOV_IIR, {IIND, R8 | R16 | R32 | R64}}, 1100 &(struct ParseOpArray){MOV_DR, {EXP, R8 | R16 | R32 | R64}}, 1101 &(struct ParseOpArray){MOV_RD, {R8 | R16 | R32 | R64, EXP}}, 1102 &(struct ParseOpArray){MOV_SR, {SEG, R32 | R64}}, 1103 }}, 1104 [R_MOVB] = 1105 {7, 1106 (const struct ParseOpArray *[]){ 1107 &(struct ParseOpArray){MOVB_IMI, {IMM, IND}}, 1108 &(struct ParseOpArray){MOVB_IMD, {IMM, EXP}}, 1109 &(struct ParseOpArray){MOV_IR, {IND, R8}}, 1110 &(struct ParseOpArray){MOV_RI, {R8, IND}}, 1111 &(struct ParseOpArray){MOV_RR, {R8, R8}}, 1112 &(struct ParseOpArray){MOV_IMR, {IMM, R8}}, 1113 &(struct ParseOpArray){MOV_IIR, {IIND, R8}}, 1114 }}, 1115 [R_MOVW] = 1116 {7, 1117 (const struct ParseOpArray *[]){ 1118 &(struct ParseOpArray){MOVW_IMI, {IMM, IND}}, 1119 &(struct ParseOpArray){MOVW_IMD, {IMM, EXP}}, 1120 &(struct ParseOpArray){MOV_IR, {IND, R16}}, 1121 &(struct ParseOpArray){MOV_RI, {R16, IND}}, 1122 &(struct ParseOpArray){MOV_RR, {R16, R16}}, 1123 &(struct ParseOpArray){MOV_IMR, {IMM, R16}}, 1124 &(struct ParseOpArray){MOV_IIR, {IIND, R16}}, 1125 }}, 1126 [R_MOVL] = 1127 {8, 1128 (const struct ParseOpArray *[]){ 1129 &(struct ParseOpArray){MOVL_IMI, {IMM, IND}}, 1130 &(struct ParseOpArray){MOVL_IMD, {IMM, EXP}}, 1131 &(struct ParseOpArray){MOV_IR, {IND, R32}}, 1132 &(struct ParseOpArray){MOV_RI, {R32, IND}}, 1133 &(struct ParseOpArray){MOV_RR, {R32, R32}}, 1134 &(struct ParseOpArray){MOV_IMR, {IMM, R32}}, 1135 &(struct ParseOpArray){MOV_IIR, {IIND, R32}}, 1136 &(struct ParseOpArray){MOV_SR, {SEG, R32}}, 1137 }}, 1138 [R_MOVQ] = 1139 {12, 1140 (const struct ParseOpArray *[]){ 1141 &(struct ParseOpArray){MOVQ_IMI, {IMM, IND}}, 1142 &(struct ParseOpArray){MOVQ_IMD, {IMM, EXP}}, 1143 &(struct ParseOpArray){MOV_IR, {IND, R64}}, 1144 &(struct ParseOpArray){MOV_RI, {R64, IND}}, 1145 &(struct ParseOpArray){MOV_RR, {R64, R64}}, 1146 &(struct ParseOpArray){MOV_IMR, {IMM, R64}}, 1147 &(struct ParseOpArray){MOV_IIR, {IIND, R64}}, 1148 &(struct ParseOpArray){MOV_SR, {SEG, R64}}, 1149 /* bitwise gp<->xmm move, qbe's idiom for spilling a 1150 * float through a gp register and for float negate's 1151 * sign-bit xor against a constant */ 1152 &(struct ParseOpArray){MOVQ_GP_XMM, {R64, XMM}}, 1153 &(struct ParseOpArray){MOVQ_XMM_GP, {XMM, R64}}, 1154 &(struct ParseOpArray){MOVQ_MEM_XMM, {IND, XMM}}, 1155 &(struct ParseOpArray){MOVQ_XMM_MEM, {XMM, IND}}, 1156 }}, 1157 [R_MOVSX] = 1158 {6, 1159 (const struct ParseOpArray *[]){ 1160 &(struct ParseOpArray){MOVSX, {R8, R16}}, 1161 &(struct ParseOpArray){MOVSX, {R8, R32}}, 1162 &(struct ParseOpArray){MOVSX, {R8, R64}}, 1163 &(struct ParseOpArray){MOVSX, {R16, R32}}, 1164 &(struct ParseOpArray){MOVSX, {R16, R64}}, 1165 &(struct ParseOpArray){MOVSX, {R32, R64}}, 1166 }}, 1167 [R_MOVZX] = 1168 {6, 1169 (const struct ParseOpArray *[]){ 1170 &(struct ParseOpArray){MOVZX, {R8, R16}}, 1171 &(struct ParseOpArray){MOVZX, {R8, R32}}, 1172 &(struct ParseOpArray){MOVZX, {R8, R64}}, 1173 &(struct ParseOpArray){MOVZX, {R16, R32}}, 1174 &(struct ParseOpArray){MOVZX, {R16, R64}}, 1175 &(struct ParseOpArray){MOVZX, {R32, R64}}, 1176 }}, 1177 [R_LEA] = 1178 {2, 1179 (const struct ParseOpArray *[]){ 1180 &(struct ParseOpArray){LEA_IR, {IND, R64}}, 1181 &(struct ParseOpArray){LEA_IIR, {IIND, R64}}, 1182 }}, 1183 [R_ADD] = 1184 {7, 1185 (const struct ParseOpArray *[]){ 1186 &(struct ParseOpArray){ADD_RR, {R8, R8}}, 1187 &(struct ParseOpArray){ADD_RR, {R16, R16}}, 1188 &(struct ParseOpArray){ADD_RR, {R32, R32}}, 1189 &(struct ParseOpArray){ADD_RR, {R64, R64}}, 1190 &(struct ParseOpArray){ADD_IMR, {IMM, R8 | R16 | R32 | R64}}, 1191 &(struct ParseOpArray){ADD_IR, {IND, R8 | R16 | R32 | R64}}, 1192 &(struct ParseOpArray){ADD_IIR, {IIND, R8 | R16 | R32 | R64}}, 1193 }}, 1194 [R_ADDQ] = 1195 {7, 1196 (const struct ParseOpArray *[]){ 1197 &(struct ParseOpArray){ADDQ, {IMM, IND}}, 1198 &(struct ParseOpArray){ADD_RR, {R8, R8}}, 1199 &(struct ParseOpArray){ADD_RR, {R16, R16}}, 1200 &(struct ParseOpArray){ADD_RR, {R32, R32}}, 1201 &(struct ParseOpArray){ADD_RR, {R64, R64}}, 1202 &(struct ParseOpArray){ADD_IMR, {IMM, R8 | R16 | R32 | R64}}, 1203 &(struct ParseOpArray){ADD_IR, {IND, R64}}, 1204 }}, 1205 [R_SUB] = 1206 {7, 1207 (const struct ParseOpArray *[]){ 1208 &(struct ParseOpArray){SUB_RR, {R8, R8}}, 1209 &(struct ParseOpArray){SUB_RR, {R16, R16}}, 1210 &(struct ParseOpArray){SUB_RR, {R32, R32}}, 1211 &(struct ParseOpArray){SUB_RR, {R64, R64}}, 1212 &(struct ParseOpArray){SUB_IMR, {IMM, R8 | R16 | R32 | R64}}, 1213 &(struct ParseOpArray){SUB_IR, {IND, R8 | R16 | R32 | R64}}, 1214 &(struct ParseOpArray){SUB_IIR, {IIND, R8 | R16 | R32 | R64}}, 1215 }}, 1216 [R_SUBQ] = 1217 {6, 1218 (const struct ParseOpArray *[]){ 1219 &(struct ParseOpArray){SUBQ, {IMM, IND}}, 1220 &(struct ParseOpArray){SUB_RR, {R8, R8}}, 1221 &(struct ParseOpArray){SUB_RR, {R16, R16}}, 1222 &(struct ParseOpArray){SUB_RR, {R32, R32}}, 1223 &(struct ParseOpArray){SUB_RR, {R64, R64}}, 1224 &(struct ParseOpArray){SUB_IMR, {IMM, R8 | R16 | R32 | R64}}, 1225 }}, 1226 [R_MUL] = 1227 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MUL, {R8 | R16 | R32 | R64}}}}, 1228 [R_DIV] = 1229 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){DIV, {R8 | R16 | R32 | R64}}}}, 1230 [R_IDIV] = 1231 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){IDIV, {R8 | R16 | R32 | R64}}}}, 1232 [R_NEG] = 1233 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){NEG, {R8 | R16 | R32 | R64}}}}, 1234 [R_NOT] = 1235 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){NOT, {R8 | R16 | R32 | R64}}}}, 1236 [R_INC] = 1237 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){INC, {R8 | R16 | R32 | R64}}}}, 1238 [R_INCB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){INCB, {IND}}}}, 1239 [R_INCW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){INCW, {IND}}}}, 1240 [R_INCL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){INCL, {IND}}}}, 1241 [R_INCQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){INCQ, {IND}}}}, 1242 [R_DEC] = 1243 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){DEC, {R8 | R16 | R32 | R64}}}}, 1244 [R_DECB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){DECB, {IND}}}}, 1245 [R_DECW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){DECW, {IND}}}}, 1246 [R_DECL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){DECL, {IND}}}}, 1247 [R_DECQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){DECQ, {IND}}}}, 1248 [R_AND] = 1249 {5, 1250 (const struct ParseOpArray *[]){ 1251 &(struct ParseOpArray){AND_RR, {R8, R8}}, 1252 &(struct ParseOpArray){AND_RR, {R16, R16}}, 1253 &(struct ParseOpArray){AND_RR, {R32, R32}}, 1254 &(struct ParseOpArray){AND_RR, {R64, R64}}, 1255 &(struct ParseOpArray){AND_IMR, {IMM, R8 | R16 | R32 | R64}}, 1256 }}, 1257 [R_OR] = 1258 {5, 1259 (const struct ParseOpArray *[]){ 1260 &(struct ParseOpArray){OR_RR, {R8, R8}}, 1261 &(struct ParseOpArray){OR_RR, {R16, R16}}, 1262 &(struct ParseOpArray){OR_RR, {R32, R32}}, 1263 &(struct ParseOpArray){OR_RR, {R64, R64}}, 1264 &(struct ParseOpArray){OR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1265 }}, 1266 [R_XOR] = 1267 {5, 1268 (const struct ParseOpArray *[]){ 1269 &(struct ParseOpArray){XOR_RR, {R8, R8}}, 1270 &(struct ParseOpArray){XOR_RR, {R16, R16}}, 1271 &(struct ParseOpArray){XOR_RR, {R32, R32}}, 1272 &(struct ParseOpArray){XOR_RR, {R64, R64}}, 1273 &(struct ParseOpArray){XOR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1274 }}, 1275 [R_SHL] = 1276 {2, 1277 (const struct ParseOpArray *[]){ 1278 &(struct ParseOpArray){SHL_RR, {R8CL, R8 | R16 | R32 | R64}}, /* %cl, %reg */ 1279 &(struct ParseOpArray){SHL_IMR, {IMM, R8 | R16 | R32 | R64}}, 1280 }}, 1281 [R_SHR] = 1282 {2, 1283 (const struct ParseOpArray *[]){ 1284 &(struct ParseOpArray){SHR_RR, {R8CL, R8 | R16 | R32 | R64}}, /* %cl, %reg */ 1285 &(struct ParseOpArray){SHR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1286 }}, 1287 [R_SAR] = 1288 {2, 1289 (const struct ParseOpArray *[]){ 1290 &(struct ParseOpArray){SAR_RR, {R8CL, R8 | R16 | R32 | R64}}, /* %cl, %reg */ 1291 &(struct ParseOpArray){SAR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1292 }}, 1293 [R_CMP] = 1294 {5, 1295 (const struct ParseOpArray *[]){ 1296 &(struct ParseOpArray){CMP_RR, {R8, R8}}, 1297 &(struct ParseOpArray){CMP_RR, {R16, R16}}, 1298 &(struct ParseOpArray){CMP_RR, {R32, R32}}, 1299 &(struct ParseOpArray){CMP_RR, {R64, R64}}, 1300 &(struct ParseOpArray){CMP_IMR, {IMM, R8 | R16 | R32 | R64}}, 1301 }}, 1302 [R_TEST] = 1303 {4, 1304 (const struct ParseOpArray *[]){ 1305 &(struct ParseOpArray){TEST, {R8, R8}}, 1306 &(struct ParseOpArray){TEST, {R16, R16}}, 1307 &(struct ParseOpArray){TEST, {R32, R32}}, 1308 &(struct ParseOpArray){TEST, {R64, R64}}, 1309 }}, 1310 [R_CWTL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CWTL, {0}}}}, 1311 [R_CLTD] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CLTD, {0}}}}, 1312 [R_CQTO] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CQTO, {0}}}}, 1313 [R_BSR] = 1314 {3, 1315 (const struct ParseOpArray *[]){ 1316 &(struct ParseOpArray){BSR, {R16, R16}}, 1317 &(struct ParseOpArray){BSR, {R32, R32}}, 1318 &(struct ParseOpArray){BSR, {R64, R64}}, 1319 }}, 1320 [R_LZCNT] = 1321 {3, 1322 (const struct ParseOpArray *[]){ 1323 &(struct ParseOpArray){LZCNT, {R16, R16}}, 1324 &(struct ParseOpArray){LZCNT, {R32, R32}}, 1325 &(struct ParseOpArray){LZCNT, {R64, R64}}, 1326 }}, 1327 [R_TZCNT] = 1328 {3, 1329 (const struct ParseOpArray *[]){ 1330 &(struct ParseOpArray){TZCNT, {R16, R16}}, 1331 &(struct ParseOpArray){TZCNT, {R32, R32}}, 1332 &(struct ParseOpArray){TZCNT, {R64, R64}}, 1333 }}, 1334 [R_POPCNT] = 1335 {3, 1336 (const struct ParseOpArray *[]){ 1337 &(struct ParseOpArray){POPCNT, {R16, R16}}, 1338 &(struct ParseOpArray){POPCNT, {R32, R32}}, 1339 &(struct ParseOpArray){POPCNT, {R64, R64}}, 1340 }}, 1341 [R_SETO] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETO, {R8}}}}, 1342 [R_SETNO] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETNO, {R8}}}}, 1343 [R_SETB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETB, {R8}}}}, 1344 [R_SETAE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETAE, {R8}}}}, 1345 [R_SETE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETE, {R8}}}}, 1346 [R_SETNE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETNE, {R8}}}}, 1347 /* setz/setnz: same encoding as sete/setne, gcc/qbe just prefer 1348 * this spelling for a zero-flag test not read as an equality */ 1349 [R_SETZ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETE, {R8}}}}, 1350 [R_SETNZ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETNE, {R8}}}}, 1351 [R_SETBE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETBE, {R8}}}}, 1352 [R_SETA] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETA, {R8}}}}, 1353 [R_SETS] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETS, {R8}}}}, 1354 [R_SETNS] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETNS, {R8}}}}, 1355 [R_SETP] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETP, {R8}}}}, 1356 [R_SETNP] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETNP, {R8}}}}, 1357 [R_SETL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETL, {R8}}}}, 1358 [R_SETGE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETGE, {R8}}}}, 1359 [R_SETLE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETLE, {R8}}}}, 1360 [R_SETG] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SETG, {R8}}}}, 1361 [R_JMP] = 1362 {4, 1363 (const struct ParseOpArray *[]){ 1364 &(struct ParseOpArray){JMP_D, {EXP}}, 1365 &(struct ParseOpArray){JMP_DER, {DER}}, 1366 &(struct ParseOpArray){JMP_DEI, {DEI}}, 1367 &(struct ParseOpArray){JMP_DEII, {DEII}}, 1368 }}, 1369 [R_JO] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JO, {EXP}}}}, 1370 [R_JNO] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JNO, {EXP}}}}, 1371 [R_JB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JB, {EXP}}}}, 1372 [R_JAE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JAE, {EXP}}}}, 1373 [R_JE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JE, {EXP}}}}, 1374 [R_JNE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JNE, {EXP}}}}, 1375 [R_JBE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JBE, {EXP}}}}, 1376 [R_JA] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JA, {EXP}}}}, 1377 [R_JS] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JS, {EXP}}}}, 1378 [R_JNS] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JNS, {EXP}}}}, 1379 [R_JP] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JP, {EXP}}}}, 1380 [R_JNP] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JNP, {EXP}}}}, 1381 [R_JL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JL, {EXP}}}}, 1382 [R_JGE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JGE, {EXP}}}}, 1383 [R_JLE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JLE, {EXP}}}}, 1384 [R_JG] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JG, {EXP}}}}, 1385 [R_CALL] = 1386 {2, 1387 (const struct ParseOpArray *[]){ 1388 &(struct ParseOpArray){CALL_D, {EXP}}, 1389 &(struct ParseOpArray){CALL_DER, {DER}}, 1390 }}, 1391 [R_RET] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){RET, {0}}}}, 1392 [R_PUSH] = 1393 {2, 1394 (const struct ParseOpArray *[]){ 1395 &(struct ParseOpArray){PUSH_R, {R64}}, 1396 &(struct ParseOpArray){PUSH_IM, {IMM}}, 1397 }}, 1398 [R_POP] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){POP, {R64}}}}, 1399 [R_INT] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){INT, {IMM}}}}, 1400 [R_SYSCALL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SYSCALL, {0}}}}, 1401 1402 [R_MOVSD] = 1403 {3, 1404 (const struct ParseOpArray *[]){ 1405 &(struct ParseOpArray){MOVSD_XX, {XMM, XMM}}, 1406 &(struct ParseOpArray){MOVSD_IX, {IND, XMM}}, 1407 &(struct ParseOpArray){MOVSD_XI, {XMM, IND}}, 1408 }}, 1409 [R_MOVSS] = 1410 {3, 1411 (const struct ParseOpArray *[]){ 1412 &(struct ParseOpArray){MOVSS_XX, {XMM, XMM}}, 1413 &(struct ParseOpArray){MOVSS_IX, {IND, XMM}}, 1414 &(struct ParseOpArray){MOVSS_XI, {XMM, IND}}, 1415 }}, 1416 [R_ADDSD] = 1417 {1, 1418 (const struct ParseOpArray *[]){ 1419 &(struct ParseOpArray){ADDSD, {XMM, XMM}}, 1420 }}, 1421 [R_ADDSS] = 1422 {1, 1423 (const struct ParseOpArray *[]){ 1424 &(struct ParseOpArray){ADDSS, {XMM, XMM}}, 1425 }}, 1426 [R_SUBSD] = 1427 {1, 1428 (const struct ParseOpArray *[]){ 1429 &(struct ParseOpArray){SUBSD, {XMM, XMM}}, 1430 }}, 1431 [R_SUBSS] = 1432 {1, 1433 (const struct ParseOpArray *[]){ 1434 &(struct ParseOpArray){SUBSS, {XMM, XMM}}, 1435 }}, 1436 [R_MULSD] = 1437 {1, 1438 (const struct ParseOpArray *[]){ 1439 &(struct ParseOpArray){MULSD, {XMM, XMM}}, 1440 }}, 1441 [R_MULSS] = 1442 {1, 1443 (const struct ParseOpArray *[]){ 1444 &(struct ParseOpArray){MULSS, {XMM, XMM}}, 1445 }}, 1446 [R_DIVSD] = 1447 {1, 1448 (const struct ParseOpArray *[]){ 1449 &(struct ParseOpArray){DIVSD, {XMM, XMM}}, 1450 }}, 1451 [R_DIVSS] = 1452 {1, 1453 (const struct ParseOpArray *[]){ 1454 &(struct ParseOpArray){DIVSS, {XMM, XMM}}, 1455 }}, 1456 [R_XORPD] = 1457 {2, 1458 (const struct ParseOpArray *[]){ 1459 &(struct ParseOpArray){XORPD, {XMM, XMM}}, 1460 &(struct ParseOpArray){XORPD_IX, {IND, XMM}}, 1461 }}, 1462 [R_XORPS] = 1463 {2, 1464 (const struct ParseOpArray *[]){ 1465 &(struct ParseOpArray){XORPS, {XMM, XMM}}, 1466 &(struct ParseOpArray){XORPS_IX, {IND, XMM}}, 1467 }}, 1468 [R_COMISD] = 1469 {2, 1470 (const struct ParseOpArray *[]){ 1471 &(struct ParseOpArray){COMISD, {XMM, XMM}}, 1472 &(struct ParseOpArray){COMISD_IX, {IND, XMM}}, 1473 }}, 1474 [R_UCOMISD] = 1475 {2, 1476 (const struct ParseOpArray *[]){ 1477 &(struct ParseOpArray){UCOMISD, {XMM, XMM}}, 1478 &(struct ParseOpArray){UCOMISD_IX, {IND, XMM}}, 1479 }}, 1480 [R_COMISS] = 1481 {2, 1482 (const struct ParseOpArray *[]){ 1483 &(struct ParseOpArray){COMISS, {XMM, XMM}}, 1484 &(struct ParseOpArray){COMISS_IX, {IND, XMM}}, 1485 }}, 1486 [R_UCOMISS] = 1487 {2, 1488 (const struct ParseOpArray *[]){ 1489 &(struct ParseOpArray){UCOMISS, {XMM, XMM}}, 1490 &(struct ParseOpArray){UCOMISS_IX, {IND, XMM}}, 1491 }}, 1492 [R_CVTSI2SD] = 1493 {1, 1494 (const struct ParseOpArray *[]){ 1495 &(struct ParseOpArray){CVTSI2SD, {R32 | R64, XMM}}, 1496 }}, 1497 [R_CVTSI2SS] = 1498 {1, 1499 (const struct ParseOpArray *[]){ 1500 &(struct ParseOpArray){CVTSI2SS, {R32 | R64, XMM}}, 1501 }}, 1502 [R_CVTTSD2SI] = 1503 {1, 1504 (const struct ParseOpArray *[]){ 1505 &(struct ParseOpArray){CVTTSD2SI, {XMM, R32 | R64}}, 1506 }}, 1507 [R_CVTTSS2SI] = 1508 {1, 1509 (const struct ParseOpArray *[]){ 1510 &(struct ParseOpArray){CVTTSS2SI, {XMM, R32 | R64}}, 1511 }}, 1512 [R_CVTSD2SS] = 1513 {1, 1514 (const struct ParseOpArray *[]){ 1515 &(struct ParseOpArray){CVTSD2SS, {XMM, XMM}}, 1516 }}, 1517 [R_CVTSS2SD] = 1518 {1, 1519 (const struct ParseOpArray *[]){ 1520 &(struct ParseOpArray){CVTSS2SD, {XMM, XMM}}, 1521 }}, 1522 [R_SQRTSD] = 1523 {1, 1524 (const struct ParseOpArray *[]){ 1525 &(struct ParseOpArray){SQRTSD, {XMM, XMM}}, 1526 }}, 1527 1528 [R_ENDBR64] = 1529 {1, 1530 (const struct ParseOpArray *[]){ 1531 &(struct ParseOpArray){ENDBR64, {0}}, 1532 }}, 1533 1534 /* no-operand instructions */ 1535 [R_NOP] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){NOP, {0}}}}, 1536 [R_PUSHFQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){PUSHFQ, {0}}}}, 1537 [R_POPFQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){POPFQ, {0}}}}, 1538 [R_PUSHF] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){PUSHF, {0}}}}, 1539 [R_POPF] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){POPF, {0}}}}, 1540 [R_CPUID] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CPUID, {0}}}}, 1541 [R_RDTSC] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){RDTSC, {0}}}}, 1542 [R_UD2] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){UD2, {0}}}}, 1543 [R_PAUSE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){PAUSE, {0}}}}, 1544 [R_HLT] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){HLT, {0}}}}, 1545 [R_CMC] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CMC, {0}}}}, 1546 [R_CLC] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CLC, {0}}}}, 1547 [R_STC] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STC, {0}}}}, 1548 [R_CLI] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CLI, {0}}}}, 1549 [R_STI] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STI, {0}}}}, 1550 [R_CLD] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CLD, {0}}}}, 1551 [R_STD] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STD, {0}}}}, 1552 [R_CLTS] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CLTS, {0}}}}, 1553 [R_WBINVD] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){WBINVD, {0}}}}, 1554 [R_MFENCE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MFENCE, {0}}}}, 1555 [R_LFENCE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){LFENCE, {0}}}}, 1556 [R_SFENCE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SFENCE, {0}}}}, 1557 1558 /* register instructions */ 1559 [R_IMUL] = 1560 {3, 1561 (const struct ParseOpArray *[]){ 1562 &(struct ParseOpArray){IMUL, {R8 | R16 | R32 | R64}}, 1563 &(struct ParseOpArray){IMUL_RR, {R8 | R16 | R32 | R64, R8 | R16 | R32 | R64}}, 1564 &(struct ParseOpArray){IMUL_IRR, {IMM, R16 | R32 | R64}}, 1565 }}, 1566 [R_BSF] = 1567 {3, 1568 (const struct ParseOpArray *[]){ 1569 &(struct ParseOpArray){BSF, {R16, R16}}, 1570 &(struct ParseOpArray){BSF, {R32, R32}}, 1571 &(struct ParseOpArray){BSF, {R64, R64}}, 1572 }}, 1573 [R_BSWAP] = 1574 {2, 1575 (const struct ParseOpArray *[]){ 1576 &(struct ParseOpArray){BSWAP, {R32}}, 1577 &(struct ParseOpArray){BSWAP, {R64}}, 1578 }}, 1579 [R_XADD] = 1580 {5, 1581 (const struct ParseOpArray *[]){ 1582 &(struct ParseOpArray){XADD_RR, {R8, R8}}, 1583 &(struct ParseOpArray){XADD_RR, {R16, R16}}, 1584 &(struct ParseOpArray){XADD_RR, {R32, R32}}, 1585 &(struct ParseOpArray){XADD_RR, {R64, R64}}, 1586 &(struct ParseOpArray){XADD_RI, {R32 | R64, IND}}, 1587 }}, 1588 [R_CMPXCHG] = 1589 {5, 1590 (const struct ParseOpArray *[]){ 1591 &(struct ParseOpArray){CMPXCHG_RR, {R8, R8}}, 1592 &(struct ParseOpArray){CMPXCHG_RR, {R16, R16}}, 1593 &(struct ParseOpArray){CMPXCHG_RR, {R32, R32}}, 1594 &(struct ParseOpArray){CMPXCHG_RR, {R64, R64}}, 1595 &(struct ParseOpArray){CMPXCHG_RI, {R32 | R64, IND}}, 1596 }}, 1597 [R_LEAVE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){LEAVE, {0}}}}, 1598 [R_ENTER] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){ENTER, {IMM, IMM}}}}, 1599 [R_XCHG] = 1600 {5, 1601 (const struct ParseOpArray *[]){ 1602 &(struct ParseOpArray){XCHG_RR, {R8, R8}}, 1603 &(struct ParseOpArray){XCHG_RR, {R16, R16}}, 1604 &(struct ParseOpArray){XCHG_RR, {R32, R32}}, 1605 &(struct ParseOpArray){XCHG_RR, {R64, R64}}, 1606 &(struct ParseOpArray){XCHG_RI, {R32 | R64, IND}}, 1607 }}, 1608 1609 /* bit test */ 1610 [R_BT] = 1611 {4, 1612 (const struct ParseOpArray *[]){ 1613 &(struct ParseOpArray){BT_RR, {R16, R16}}, 1614 &(struct ParseOpArray){BT_RR, {R32, R32}}, 1615 &(struct ParseOpArray){BT_RR, {R64, R64}}, 1616 &(struct ParseOpArray){BT_RR, {IMM, R16 | R32 | R64}}, 1617 }}, 1618 [R_BTS] = 1619 {4, 1620 (const struct ParseOpArray *[]){ 1621 &(struct ParseOpArray){BTS_RR, {R16, R16}}, 1622 &(struct ParseOpArray){BTS_RR, {R32, R32}}, 1623 &(struct ParseOpArray){BTS_RR, {R64, R64}}, 1624 &(struct ParseOpArray){BTS_RR, {IMM, R16 | R32 | R64}}, 1625 }}, 1626 [R_BTR] = 1627 {4, 1628 (const struct ParseOpArray *[]){ 1629 &(struct ParseOpArray){BTR_RR, {R16, R16}}, 1630 &(struct ParseOpArray){BTR_RR, {R32, R32}}, 1631 &(struct ParseOpArray){BTR_RR, {R64, R64}}, 1632 &(struct ParseOpArray){BTR_RR, {IMM, R16 | R32 | R64}}, 1633 }}, 1634 [R_BTC] = 1635 {4, 1636 (const struct ParseOpArray *[]){ 1637 &(struct ParseOpArray){BTC_RR, {R16, R16}}, 1638 &(struct ParseOpArray){BTC_RR, {R32, R32}}, 1639 &(struct ParseOpArray){BTC_RR, {R64, R64}}, 1640 &(struct ParseOpArray){BTC_RR, {IMM, R16 | R32 | R64}}, 1641 }}, 1642 1643 /* conditional move */ 1644 [R_CMOVO] = 1645 {3, 1646 (const struct ParseOpArray *[]){ 1647 &(struct ParseOpArray){CMOVO, {R16, R16}}, 1648 &(struct ParseOpArray){CMOVO, {R32, R32}}, 1649 &(struct ParseOpArray){CMOVO, {R64, R64}} 1650 }}, 1651 [R_CMOVNO] = 1652 {3, 1653 (const struct ParseOpArray *[]){ 1654 &(struct ParseOpArray){CMOVNO, {R16, R16}}, 1655 &(struct ParseOpArray){CMOVNO, {R32, R32}}, 1656 &(struct ParseOpArray){CMOVNO, {R64, R64}} 1657 }}, 1658 [R_CMOVB] = 1659 {3, 1660 (const struct ParseOpArray *[]){ 1661 &(struct ParseOpArray){CMOVB, {R16, R16}}, 1662 &(struct ParseOpArray){CMOVB, {R32, R32}}, 1663 &(struct ParseOpArray){CMOVB, {R64, R64}} 1664 }}, 1665 [R_CMOVAE] = 1666 {3, 1667 (const struct ParseOpArray *[]){ 1668 &(struct ParseOpArray){CMOVAE, {R16, R16}}, 1669 &(struct ParseOpArray){CMOVAE, {R32, R32}}, 1670 &(struct ParseOpArray){CMOVAE, {R64, R64}} 1671 }}, 1672 [R_CMOVE] = 1673 {3, 1674 (const struct ParseOpArray *[]){ 1675 &(struct ParseOpArray){CMOVE, {R16, R16}}, 1676 &(struct ParseOpArray){CMOVE, {R32, R32}}, 1677 &(struct ParseOpArray){CMOVE, {R64, R64}} 1678 }}, 1679 [R_CMOVNE] = 1680 {3, 1681 (const struct ParseOpArray *[]){ 1682 &(struct ParseOpArray){CMOVNE, {R16, R16}}, 1683 &(struct ParseOpArray){CMOVNE, {R32, R32}}, 1684 &(struct ParseOpArray){CMOVNE, {R64, R64}} 1685 }}, 1686 [R_CMOVBE] = 1687 {3, 1688 (const struct ParseOpArray *[]){ 1689 &(struct ParseOpArray){CMOVBE, {R16, R16}}, 1690 &(struct ParseOpArray){CMOVBE, {R32, R32}}, 1691 &(struct ParseOpArray){CMOVBE, {R64, R64}} 1692 }}, 1693 [R_CMOVA] = 1694 {3, 1695 (const struct ParseOpArray *[]){ 1696 &(struct ParseOpArray){CMOVA, {R16, R16}}, 1697 &(struct ParseOpArray){CMOVA, {R32, R32}}, 1698 &(struct ParseOpArray){CMOVA, {R64, R64}} 1699 }}, 1700 [R_CMOVS] = 1701 {3, 1702 (const struct ParseOpArray *[]){ 1703 &(struct ParseOpArray){CMOVS, {R16, R16}}, 1704 &(struct ParseOpArray){CMOVS, {R32, R32}}, 1705 &(struct ParseOpArray){CMOVS, {R64, R64}} 1706 }}, 1707 [R_CMOVNS] = 1708 {3, 1709 (const struct ParseOpArray *[]){ 1710 &(struct ParseOpArray){CMOVNS, {R16, R16}}, 1711 &(struct ParseOpArray){CMOVNS, {R32, R32}}, 1712 &(struct ParseOpArray){CMOVNS, {R64, R64}} 1713 }}, 1714 [R_CMOVP] = 1715 {3, 1716 (const struct ParseOpArray *[]){ 1717 &(struct ParseOpArray){CMOVP, {R16, R16}}, 1718 &(struct ParseOpArray){CMOVP, {R32, R32}}, 1719 &(struct ParseOpArray){CMOVP, {R64, R64}} 1720 }}, 1721 [R_CMOVNP] = 1722 {3, 1723 (const struct ParseOpArray *[]){ 1724 &(struct ParseOpArray){CMOVNP, {R16, R16}}, 1725 &(struct ParseOpArray){CMOVNP, {R32, R32}}, 1726 &(struct ParseOpArray){CMOVNP, {R64, R64}} 1727 }}, 1728 [R_CMOVL] = 1729 {3, 1730 (const struct ParseOpArray *[]){ 1731 &(struct ParseOpArray){CMOVL, {R16, R16}}, 1732 &(struct ParseOpArray){CMOVL, {R32, R32}}, 1733 &(struct ParseOpArray){CMOVL, {R64, R64}} 1734 }}, 1735 [R_CMOVGE] = 1736 {3, 1737 (const struct ParseOpArray *[]){ 1738 &(struct ParseOpArray){CMOVGE, {R16, R16}}, 1739 &(struct ParseOpArray){CMOVGE, {R32, R32}}, 1740 &(struct ParseOpArray){CMOVGE, {R64, R64}} 1741 }}, 1742 [R_CMOVLE] = 1743 {3, 1744 (const struct ParseOpArray *[]){ 1745 &(struct ParseOpArray){CMOVLE, {R16, R16}}, 1746 &(struct ParseOpArray){CMOVLE, {R32, R32}}, 1747 &(struct ParseOpArray){CMOVLE, {R64, R64}} 1748 }}, 1749 [R_CMOVG] = 1750 {3, 1751 (const struct ParseOpArray *[]){ 1752 &(struct ParseOpArray){CMOVG, {R16, R16}}, 1753 &(struct ParseOpArray){CMOVG, {R32, R32}}, 1754 &(struct ParseOpArray){CMOVG, {R64, R64}} 1755 }}, 1756 1757 /* string operations */ 1758 [R_MOVSB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSB, {0}}}}, 1759 [R_MOVSW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSW, {0}}}}, 1760 [R_MOVSL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSL, {0}}}}, 1761 [R_MOVSQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSQ, {0}}}}, 1762 [R_STOSB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STOSB, {0}}}}, 1763 [R_STOSW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STOSW, {0}}}}, 1764 [R_STOSL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STOSL, {0}}}}, 1765 [R_STOSQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){STOSQ, {0}}}}, 1766 [R_LODSB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){LODSB, {0}}}}, 1767 [R_LODSW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){LODSW, {0}}}}, 1768 [R_LODSL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){LODSL, {0}}}}, 1769 [R_LODSQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){LODSQ, {0}}}}, 1770 [R_SCASB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SCASB, {0}}}}, 1771 [R_SCASW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SCASW, {0}}}}, 1772 [R_SCASL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SCASL, {0}}}}, 1773 [R_SCASQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){SCASQ, {0}}}}, 1774 [R_CMPSB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CMPSB, {0}}}}, 1775 [R_CMPSW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CMPSW, {0}}}}, 1776 [R_CMPSL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CMPSL, {0}}}}, 1777 [R_CMPSQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CMPSQ, {0}}}}, 1778 1779 /* gas conversion aliases */ 1780 [R_CBW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CBW, {0}}}}, 1781 [R_CDQE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CDQE, {0}}}}, 1782 [R_CWD] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){CWD, {0}}}}, 1783 1784 /* condition code aliases */ 1785 [R_JC] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JB, {EXP}}}}, 1786 [R_JNAE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JB, {EXP}}}}, 1787 [R_JNB] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JAE, {EXP}}}}, 1788 [R_JZ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JE, {EXP}}}}, 1789 [R_JNZ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JNE, {EXP}}}}, 1790 [R_JNA] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JBE, {EXP}}}}, 1791 [R_JNBE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JA, {EXP}}}}, 1792 [R_JNGE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JL, {EXP}}}}, 1793 [R_JNL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JGE, {EXP}}}}, 1794 [R_JNG] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JLE, {EXP}}}}, 1795 [R_JNLE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JG, {EXP}}}}, 1796 [R_JPE] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JP, {EXP}}}}, 1797 [R_JPO] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){JNP, {EXP}}}}, 1798 1799 [R_CMOVZ] = 1800 {3, 1801 (const struct ParseOpArray *[]){ 1802 &(struct ParseOpArray){CMOVE, {R16, R16}}, 1803 &(struct ParseOpArray){CMOVE, {R32, R32}}, 1804 &(struct ParseOpArray){CMOVE, {R64, R64}} 1805 }}, 1806 [R_CMOVNZ] = 1807 {3, 1808 (const struct ParseOpArray *[]){ 1809 &(struct ParseOpArray){CMOVNE, {R16, R16}}, 1810 &(struct ParseOpArray){CMOVNE, {R32, R32}}, 1811 &(struct ParseOpArray){CMOVNE, {R64, R64}} 1812 }}, 1813 1814 /* explicit-size gas mnemonics qbe's amd64_sysv backend emits: the 1815 * suffix only disambiguates operand width when its unsuffixed 1816 * sibling above cannot infer it from a register operand, so these 1817 * accept exactly the same operand patterns as that sibling */ 1818 [R_LEAQ] = 1819 {2, 1820 (const struct ParseOpArray *[]){ 1821 &(struct ParseOpArray){LEA_IR, {IND, R64}}, 1822 &(struct ParseOpArray){LEA_IIR, {IIND, R64}}, 1823 }}, 1824 [R_ADDL] = 1825 {7, 1826 (const struct ParseOpArray *[]){ 1827 &(struct ParseOpArray){ADD_RR, {R8, R8}}, 1828 &(struct ParseOpArray){ADD_RR, {R16, R16}}, 1829 &(struct ParseOpArray){ADD_RR, {R32, R32}}, 1830 &(struct ParseOpArray){ADD_RR, {R64, R64}}, 1831 &(struct ParseOpArray){ADD_IMR, {IMM, R8 | R16 | R32 | R64}}, 1832 &(struct ParseOpArray){ADD_IR, {IND, R8 | R16 | R32 | R64}}, 1833 &(struct ParseOpArray){ADD_IIR, {IIND, R8 | R16 | R32 | R64}}, 1834 }}, 1835 [R_SUBL] = 1836 {7, 1837 (const struct ParseOpArray *[]){ 1838 &(struct ParseOpArray){SUB_RR, {R8, R8}}, 1839 &(struct ParseOpArray){SUB_RR, {R16, R16}}, 1840 &(struct ParseOpArray){SUB_RR, {R32, R32}}, 1841 &(struct ParseOpArray){SUB_RR, {R64, R64}}, 1842 &(struct ParseOpArray){SUB_IMR, {IMM, R8 | R16 | R32 | R64}}, 1843 &(struct ParseOpArray){SUB_IR, {IND, R8 | R16 | R32 | R64}}, 1844 &(struct ParseOpArray){SUB_IIR, {IIND, R8 | R16 | R32 | R64}}, 1845 }}, 1846 [R_IDIVL] = 1847 {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){IDIV, {R8 | R16 | R32 | R64}}}}, 1848 [R_ANDL] = 1849 {5, 1850 (const struct ParseOpArray *[]){ 1851 &(struct ParseOpArray){AND_RR, {R8, R8}}, 1852 &(struct ParseOpArray){AND_RR, {R16, R16}}, 1853 &(struct ParseOpArray){AND_RR, {R32, R32}}, 1854 &(struct ParseOpArray){AND_RR, {R64, R64}}, 1855 &(struct ParseOpArray){AND_IMR, {IMM, R8 | R16 | R32 | R64}}, 1856 }}, 1857 [R_ANDQ] = 1858 {5, 1859 (const struct ParseOpArray *[]){ 1860 &(struct ParseOpArray){AND_RR, {R8, R8}}, 1861 &(struct ParseOpArray){AND_RR, {R16, R16}}, 1862 &(struct ParseOpArray){AND_RR, {R32, R32}}, 1863 &(struct ParseOpArray){AND_RR, {R64, R64}}, 1864 &(struct ParseOpArray){AND_IMR, {IMM, R8 | R16 | R32 | R64}}, 1865 }}, 1866 [R_ORL] = 1867 {5, 1868 (const struct ParseOpArray *[]){ 1869 &(struct ParseOpArray){OR_RR, {R8, R8}}, 1870 &(struct ParseOpArray){OR_RR, {R16, R16}}, 1871 &(struct ParseOpArray){OR_RR, {R32, R32}}, 1872 &(struct ParseOpArray){OR_RR, {R64, R64}}, 1873 &(struct ParseOpArray){OR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1874 }}, 1875 [R_ORQ] = 1876 {5, 1877 (const struct ParseOpArray *[]){ 1878 &(struct ParseOpArray){OR_RR, {R8, R8}}, 1879 &(struct ParseOpArray){OR_RR, {R16, R16}}, 1880 &(struct ParseOpArray){OR_RR, {R32, R32}}, 1881 &(struct ParseOpArray){OR_RR, {R64, R64}}, 1882 &(struct ParseOpArray){OR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1883 }}, 1884 [R_SHLL] = 1885 {2, 1886 (const struct ParseOpArray *[]){ 1887 &(struct ParseOpArray){SHL_RR, {R8CL, R8 | R16 | R32 | R64}}, 1888 &(struct ParseOpArray){SHL_IMR, {IMM, R8 | R16 | R32 | R64}}, 1889 }}, 1890 [R_SHLQ] = 1891 {2, 1892 (const struct ParseOpArray *[]){ 1893 &(struct ParseOpArray){SHL_RR, {R8CL, R8 | R16 | R32 | R64}}, 1894 &(struct ParseOpArray){SHL_IMR, {IMM, R8 | R16 | R32 | R64}}, 1895 }}, 1896 [R_SHRL] = 1897 {2, 1898 (const struct ParseOpArray *[]){ 1899 &(struct ParseOpArray){SHR_RR, {R8CL, R8 | R16 | R32 | R64}}, 1900 &(struct ParseOpArray){SHR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1901 }}, 1902 [R_SHRQ] = 1903 {2, 1904 (const struct ParseOpArray *[]){ 1905 &(struct ParseOpArray){SHR_RR, {R8CL, R8 | R16 | R32 | R64}}, 1906 &(struct ParseOpArray){SHR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1907 }}, 1908 [R_SARL] = 1909 {2, 1910 (const struct ParseOpArray *[]){ 1911 &(struct ParseOpArray){SAR_RR, {R8CL, R8 | R16 | R32 | R64}}, 1912 &(struct ParseOpArray){SAR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1913 }}, 1914 [R_SARQ] = 1915 {2, 1916 (const struct ParseOpArray *[]){ 1917 &(struct ParseOpArray){SAR_RR, {R8CL, R8 | R16 | R32 | R64}}, 1918 &(struct ParseOpArray){SAR_IMR, {IMM, R8 | R16 | R32 | R64}}, 1919 }}, 1920 [R_CMPL] = 1921 {5, 1922 (const struct ParseOpArray *[]){ 1923 &(struct ParseOpArray){CMP_RR, {R8, R8}}, 1924 &(struct ParseOpArray){CMP_RR, {R16, R16}}, 1925 &(struct ParseOpArray){CMP_RR, {R32, R32}}, 1926 &(struct ParseOpArray){CMP_RR, {R64, R64}}, 1927 &(struct ParseOpArray){CMP_IMR, {IMM, R8 | R16 | R32 | R64}}, 1928 }}, 1929 [R_CMPQ] = 1930 {5, 1931 (const struct ParseOpArray *[]){ 1932 &(struct ParseOpArray){CMP_RR, {R8, R8}}, 1933 &(struct ParseOpArray){CMP_RR, {R16, R16}}, 1934 &(struct ParseOpArray){CMP_RR, {R32, R32}}, 1935 &(struct ParseOpArray){CMP_RR, {R64, R64}}, 1936 &(struct ParseOpArray){CMP_IMR, {IMM, R8 | R16 | R32 | R64}}, 1937 }}, 1938 [R_CALLQ] = 1939 {2, 1940 (const struct ParseOpArray *[]){ 1941 &(struct ParseOpArray){CALL_D, {EXP}}, 1942 &(struct ParseOpArray){CALL_DER, {DER}}, 1943 }}, 1944 [R_PUSHQ] = 1945 {2, 1946 (const struct ParseOpArray *[]){ 1947 &(struct ParseOpArray){PUSH_R, {R64}}, 1948 &(struct ParseOpArray){PUSH_IM, {IMM}}, 1949 }}, 1950 [R_POPQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){POP, {R64}}}}, 1951 [R_CVTTSD2SIL] = 1952 {1, 1953 (const struct ParseOpArray *[]){ 1954 &(struct ParseOpArray){CVTTSD2SI, {XMM, R32 | R64}}, 1955 }}, 1956 [R_CVTTSD2SIQ] = 1957 {1, 1958 (const struct ParseOpArray *[]){ 1959 &(struct ParseOpArray){CVTTSD2SI, {XMM, R32 | R64}}, 1960 }}, 1961 [R_CVTTSS2SIL] = 1962 {1, 1963 (const struct ParseOpArray *[]){ 1964 &(struct ParseOpArray){CVTTSS2SI, {XMM, R32 | R64}}, 1965 }}, 1966 [R_CVTTSS2SIQ] = 1967 {1, 1968 (const struct ParseOpArray *[]){ 1969 &(struct ParseOpArray){CVTTSS2SI, {XMM, R32 | R64}}, 1970 }}, 1971 [R_XCHGL] = 1972 {4, 1973 (const struct ParseOpArray *[]){ 1974 &(struct ParseOpArray){XCHG_RR, {R8, R8}}, 1975 &(struct ParseOpArray){XCHG_RR, {R16, R16}}, 1976 &(struct ParseOpArray){XCHG_RR, {R32, R32}}, 1977 &(struct ParseOpArray){XCHG_RR, {R64, R64}}, 1978 }}, 1979 [R_XCHGQ] = 1980 {4, 1981 (const struct ParseOpArray *[]){ 1982 &(struct ParseOpArray){XCHG_RR, {R8, R8}}, 1983 &(struct ParseOpArray){XCHG_RR, {R16, R16}}, 1984 &(struct ParseOpArray){XCHG_RR, {R32, R32}}, 1985 &(struct ParseOpArray){XCHG_RR, {R64, R64}}, 1986 }}, 1987 /* qbe emits the explicit-size spelling for both of these, not the 1988 * bare mnemonic, for reg-reg xor/neg, and also for xor against an 1989 * immediate (a boolean-negate idiom, `xorq $1, %reg`) */ 1990 [R_XORL] = 1991 {2, 1992 (const struct ParseOpArray *[]){ 1993 &(struct ParseOpArray){XOR_RR, {R32, R32}}, 1994 &(struct ParseOpArray){XOR_IMR, {IMM, R32}}, 1995 }}, 1996 [R_XORQ] = 1997 {2, 1998 (const struct ParseOpArray *[]){ 1999 &(struct ParseOpArray){XOR_RR, {R64, R64}}, 2000 &(struct ParseOpArray){XOR_IMR, {IMM, R64}}, 2001 }}, 2002 [R_NEGL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){NEG, {R32}}}}, 2003 [R_NEGQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){NEG, {R64}}}}, 2004 /* asm_movszx_rr already handles every one of these size pairs, it 2005 was just never reachable: no raw opcode dispatched to it */ 2006 [R_MOVSLQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSX, {R32, R64}}}}, 2007 [R_MOVSBW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSX, {R8, R16}}}}, 2008 [R_MOVSBL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSX, {R8, R32}}}}, 2009 [R_MOVSBQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSX, {R8, R64}}}}, 2010 [R_MOVSWL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSX, {R16, R32}}}}, 2011 [R_MOVSWQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVSX, {R16, R64}}}}, 2012 [R_MOVZBW] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVZX, {R8, R16}}}}, 2013 [R_MOVZBL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVZX, {R8, R32}}}}, 2014 [R_MOVZBQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVZX, {R8, R64}}}}, 2015 [R_MOVZWL] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVZX, {R16, R32}}}}, 2016 [R_MOVZWQ] = {1, (const struct ParseOpArray *[]){&(struct ParseOpArray){MOVZX, {R16, R64}}}}, 2017 };