1 /// Types and constants of System z architecture 2 module capstone.sysz; 3 4 import std.variant; 5 import std.exception: enforce; 6 import std.conv: to; 7 8 import capstone.internal; 9 import capstone.utils; 10 11 /** Instruction's operand referring to memory 12 13 This is associated with the `SyszOpType.mem` operand type 14 */ 15 struct SyszOpMem { 16 SyszRegister base; /// Base register 17 SyszRegister index; /// Index register 18 ulong length; /// BDLAddr operand 19 long disp; /// Displacement/offset value 20 21 this(sysz_op_mem internal){ 22 base = internal.base.to!SyszRegister; 23 index = internal.index.to!SyszRegister; 24 length = internal.length; 25 disp = internal.disp; 26 } 27 } 28 29 /// Tagged union of possible operand types 30 alias SyszOpValue = TaggedUnion!(SyszRegister, "reg", long, "imm", SyszOpMem, "mem"); 31 32 /// Instruction's operand 33 struct SyszOp { 34 SyszOpType type; /// Operand type 35 SyszOpValue value; /// Operand value of type `type` 36 alias value this; /// Convenient access to value (as in original bindings) 37 38 package this(cs_sysz_op internal){ 39 type = internal.type; 40 final switch(internal.type) { 41 case SyszOpType.invalid: 42 break; 43 case SyszOpType.reg, SyszOpType.acreg: 44 value.reg = internal.reg; 45 break; 46 case SyszOpType.imm: 47 value.imm = internal.imm; 48 break; 49 case SyszOpType.mem: 50 value.mem = SyszOpMem(internal.mem); 51 break; 52 } 53 } 54 } 55 56 /// System z-specific information about an instruction 57 struct SyszInstructionDetail { 58 SyszCc cc; /// Code condition 59 SyszOp[] operands; /// Operands for this instruction. 60 61 package this(cs_arch_detail arch_detail){ 62 this(arch_detail.sysz); 63 } 64 package this(cs_sysz internal){ 65 cc = internal.cc; 66 foreach(op; internal.operands[0..internal.op_count]) 67 operands ~= SyszOp(op); 68 } 69 } 70 71 //============================================================================= 72 // Constants 73 //============================================================================= 74 75 /// Operand type for instruction's operands 76 enum SyszOpType { 77 invalid = 0, /// Uninitialized 78 reg, /// Register operand 79 imm, /// Immediate operand 80 mem, /// Memory operand 81 acreg = 64, /// Access register operand 82 } 83 84 /// Enums corresponding to SystemZ condition codes 85 enum SyszCc { 86 invalid = 0, 87 88 o, 89 h, 90 nle, 91 l, 92 nhe, 93 lh, 94 ne, 95 e, 96 nlh, 97 he, 98 nl, 99 le, 100 nh, 101 no, 102 } 103 104 /** SystemZ registers 105 106 Note that the registers 0..15 are prefixed by r, i.e. the are named r0..r15 107 */ 108 enum SyszRegister { 109 invalid = 0, 110 111 r0, 112 r1, 113 r2, 114 r3, 115 r4, 116 r5, 117 r6, 118 r7, 119 r8, 120 r9, 121 r10, 122 r11, 123 r12, 124 r13, 125 r14, 126 r15, 127 cc, 128 f0, 129 f1, 130 f2, 131 f3, 132 f4, 133 f5, 134 f6, 135 f7, 136 f8, 137 f9, 138 f10, 139 f11, 140 f12, 141 f13, 142 f14, 143 f15, 144 145 r0l, 146 } 147 148 /// SystemZ instruction 149 enum SyszInstructionId { 150 invalid = 0, 151 152 a, 153 adb, 154 adbr, 155 aeb, 156 aebr, 157 afi, 158 ag, 159 agf, 160 agfi, 161 agfr, 162 aghi, 163 aghik, 164 agr, 165 agrk, 166 agsi, 167 ah, 168 ahi, 169 ahik, 170 ahy, 171 aih, 172 al, 173 alc, 174 alcg, 175 alcgr, 176 alcr, 177 alfi, 178 alg, 179 algf, 180 algfi, 181 algfr, 182 alghsik, 183 algr, 184 algrk, 185 alhsik, 186 alr, 187 alrk, 188 aly, 189 ar, 190 ark, 191 asi, 192 axbr, 193 ay, 194 bcr, 195 brc, 196 brcl, 197 cgij, 198 cgrj, 199 cij, 200 clgij, 201 clgrj, 202 clij, 203 clrj, 204 crj, 205 ber, 206 je, 207 jge, 208 loce, 209 locge, 210 locgre, 211 locre, 212 stoce, 213 stocge, 214 bhr, 215 bher, 216 jhe, 217 jghe, 218 loche, 219 locghe, 220 locgrhe, 221 locrhe, 222 stoche, 223 stocghe, 224 jh, 225 jgh, 226 loch, 227 locgh, 228 locgrh, 229 locrh, 230 stoch, 231 stocgh, 232 cgijnlh, 233 cgrjnlh, 234 cijnlh, 235 clgijnlh, 236 clgrjnlh, 237 clijnlh, 238 clrjnlh, 239 crjnlh, 240 cgije, 241 cgrje, 242 cije, 243 clgije, 244 clgrje, 245 clije, 246 clrje, 247 crje, 248 cgijnle, 249 cgrjnle, 250 cijnle, 251 clgijnle, 252 clgrjnle, 253 clijnle, 254 clrjnle, 255 crjnle, 256 cgijh, 257 cgrjh, 258 cijh, 259 clgijh, 260 clgrjh, 261 clijh, 262 clrjh, 263 crjh, 264 cgijnl, 265 cgrjnl, 266 cijnl, 267 clgijnl, 268 clgrjnl, 269 clijnl, 270 clrjnl, 271 crjnl, 272 cgijhe, 273 cgrjhe, 274 cijhe, 275 clgijhe, 276 clgrjhe, 277 clijhe, 278 clrjhe, 279 crjhe, 280 cgijnhe, 281 cgrjnhe, 282 cijnhe, 283 clgijnhe, 284 clgrjnhe, 285 clijnhe, 286 clrjnhe, 287 crjnhe, 288 cgijl, 289 cgrjl, 290 cijl, 291 clgijl, 292 clgrjl, 293 clijl, 294 clrjl, 295 crjl, 296 cgijnh, 297 cgrjnh, 298 cijnh, 299 clgijnh, 300 clgrjnh, 301 clijnh, 302 clrjnh, 303 crjnh, 304 cgijle, 305 cgrjle, 306 cijle, 307 clgijle, 308 clgrjle, 309 clijle, 310 clrjle, 311 crjle, 312 cgijne, 313 cgrjne, 314 cijne, 315 clgijne, 316 clgrjne, 317 clijne, 318 clrjne, 319 crjne, 320 cgijlh, 321 cgrjlh, 322 cijlh, 323 clgijlh, 324 clgrjlh, 325 clijlh, 326 clrjlh, 327 crjlh, 328 blr, 329 bler, 330 jle, 331 jgle, 332 locle, 333 locgle, 334 locgrle, 335 locrle, 336 stocle, 337 stocgle, 338 blhr, 339 jlh, 340 jglh, 341 loclh, 342 locglh, 343 locgrlh, 344 locrlh, 345 stoclh, 346 stocglh, 347 jl, 348 jgl, 349 locl, 350 locgl, 351 locgrl, 352 locrl, 353 loc, 354 locg, 355 locgr, 356 locr, 357 stocl, 358 stocgl, 359 bner, 360 jne, 361 jgne, 362 locne, 363 locgne, 364 locgrne, 365 locrne, 366 stocne, 367 stocgne, 368 bnhr, 369 bnher, 370 jnhe, 371 jgnhe, 372 locnhe, 373 locgnhe, 374 locgrnhe, 375 locrnhe, 376 stocnhe, 377 stocgnhe, 378 jnh, 379 jgnh, 380 locnh, 381 locgnh, 382 locgrnh, 383 locrnh, 384 stocnh, 385 stocgnh, 386 bnlr, 387 bnler, 388 jnle, 389 jgnle, 390 locnle, 391 locgnle, 392 locgrnle, 393 locrnle, 394 stocnle, 395 stocgnle, 396 bnlhr, 397 jnlh, 398 jgnlh, 399 locnlh, 400 locgnlh, 401 locgrnlh, 402 locrnlh, 403 stocnlh, 404 stocgnlh, 405 jnl, 406 jgnl, 407 locnl, 408 locgnl, 409 locgrnl, 410 locrnl, 411 stocnl, 412 stocgnl, 413 bnor, 414 jno, 415 jgno, 416 locno, 417 locgno, 418 locgrno, 419 locrno, 420 stocno, 421 stocgno, 422 bor, 423 jo, 424 jgo, 425 loco, 426 locgo, 427 locgro, 428 locro, 429 stoco, 430 stocgo, 431 stoc, 432 stocg, 433 basr, 434 br, 435 bras, 436 brasl, 437 j, 438 jg, 439 brct, 440 brctg, 441 c, 442 cdb, 443 cdbr, 444 cdfbr, 445 cdgbr, 446 cdlfbr, 447 cdlgbr, 448 ceb, 449 cebr, 450 cefbr, 451 cegbr, 452 celfbr, 453 celgbr, 454 cfdbr, 455 cfebr, 456 cfi, 457 cfxbr, 458 cg, 459 cgdbr, 460 cgebr, 461 cgf, 462 cgfi, 463 cgfr, 464 cgfrl, 465 cgh, 466 cghi, 467 cghrl, 468 cghsi, 469 cgr, 470 cgrl, 471 cgxbr, 472 ch, 473 chf, 474 chhsi, 475 chi, 476 chrl, 477 chsi, 478 chy, 479 cih, 480 cl, 481 clc, 482 clfdbr, 483 clfebr, 484 clfhsi, 485 clfi, 486 clfxbr, 487 clg, 488 clgdbr, 489 clgebr, 490 clgf, 491 clgfi, 492 clgfr, 493 clgfrl, 494 clghrl, 495 clghsi, 496 clgr, 497 clgrl, 498 clgxbr, 499 clhf, 500 clhhsi, 501 clhrl, 502 cli, 503 clih, 504 cliy, 505 clr, 506 clrl, 507 clst, 508 cly, 509 cpsdr, 510 cr, 511 crl, 512 cs, 513 csg, 514 csy, 515 cxbr, 516 cxfbr, 517 cxgbr, 518 cxlfbr, 519 cxlgbr, 520 cy, 521 ddb, 522 ddbr, 523 deb, 524 debr, 525 dl, 526 dlg, 527 dlgr, 528 dlr, 529 dsg, 530 dsgf, 531 dsgfr, 532 dsgr, 533 dxbr, 534 ear, 535 fidbr, 536 fidbra, 537 fiebr, 538 fiebra, 539 fixbr, 540 fixbra, 541 flogr, 542 ic, 543 icy, 544 iihf, 545 iihh, 546 iihl, 547 iilf, 548 iilh, 549 iill, 550 ipm, 551 l, 552 la, 553 laa, 554 laag, 555 laal, 556 laalg, 557 lan, 558 lang, 559 lao, 560 laog, 561 larl, 562 lax, 563 laxg, 564 lay, 565 lb, 566 lbh, 567 lbr, 568 lcdbr, 569 lcebr, 570 lcgfr, 571 lcgr, 572 lcr, 573 lcxbr, 574 ld, 575 ldeb, 576 ldebr, 577 ldgr, 578 ldr, 579 ldxbr, 580 ldxbra, 581 ldy, 582 le, 583 ledbr, 584 ledbra, 585 ler, 586 lexbr, 587 lexbra, 588 ley, 589 lfh, 590 lg, 591 lgb, 592 lgbr, 593 lgdr, 594 lgf, 595 lgfi, 596 lgfr, 597 lgfrl, 598 lgh, 599 lghi, 600 lghr, 601 lghrl, 602 lgr, 603 lgrl, 604 lh, 605 lhh, 606 lhi, 607 lhr, 608 lhrl, 609 lhy, 610 llc, 611 llch, 612 llcr, 613 llgc, 614 llgcr, 615 llgf, 616 llgfr, 617 llgfrl, 618 llgh, 619 llghr, 620 llghrl, 621 llh, 622 llhh, 623 llhr, 624 llhrl, 625 llihf, 626 llihh, 627 llihl, 628 llilf, 629 llilh, 630 llill, 631 lmg, 632 lndbr, 633 lnebr, 634 lngfr, 635 lngr, 636 lnr, 637 lnxbr, 638 lpdbr, 639 lpebr, 640 lpgfr, 641 lpgr, 642 lpr, 643 lpxbr, 644 lr, 645 lrl, 646 lrv, 647 lrvg, 648 lrvgr, 649 lrvr, 650 lt, 651 ltdbr, 652 ltebr, 653 ltg, 654 ltgf, 655 ltgfr, 656 ltgr, 657 ltr, 658 ltxbr, 659 lxdb, 660 lxdbr, 661 lxeb, 662 lxebr, 663 lxr, 664 ly, 665 lzdr, 666 lzer, 667 lzxr, 668 madb, 669 madbr, 670 maeb, 671 maebr, 672 mdb, 673 mdbr, 674 mdeb, 675 mdebr, 676 meeb, 677 meebr, 678 mghi, 679 mh, 680 mhi, 681 mhy, 682 mlg, 683 mlgr, 684 ms, 685 msdb, 686 msdbr, 687 mseb, 688 msebr, 689 msfi, 690 msg, 691 msgf, 692 msgfi, 693 msgfr, 694 msgr, 695 msr, 696 msy, 697 mvc, 698 mvghi, 699 mvhhi, 700 mvhi, 701 mvi, 702 mviy, 703 mvst, 704 mxbr, 705 mxdb, 706 mxdbr, 707 n, 708 nc, 709 ng, 710 ngr, 711 ngrk, 712 ni, 713 nihf, 714 nihh, 715 nihl, 716 nilf, 717 nilh, 718 nill, 719 niy, 720 nr, 721 nrk, 722 ny, 723 o, 724 oc, 725 og, 726 ogr, 727 ogrk, 728 oi, 729 oihf, 730 oihh, 731 oihl, 732 oilf, 733 oilh, 734 oill, 735 oiy, 736 or, 737 ork, 738 oy, 739 pfd, 740 pfdrl, 741 risbg, 742 risbhg, 743 risblg, 744 rll, 745 rllg, 746 rnsbg, 747 rosbg, 748 rxsbg, 749 s, 750 sdb, 751 sdbr, 752 seb, 753 sebr, 754 sg, 755 sgf, 756 sgfr, 757 sgr, 758 sgrk, 759 sh, 760 shy, 761 sl, 762 slb, 763 slbg, 764 slbr, 765 slfi, 766 slg, 767 slbgr, 768 slgf, 769 slgfi, 770 slgfr, 771 slgr, 772 slgrk, 773 sll, 774 sllg, 775 sllk, 776 slr, 777 slrk, 778 sly, 779 sqdb, 780 sqdbr, 781 sqeb, 782 sqebr, 783 sqxbr, 784 sr, 785 sra, 786 srag, 787 srak, 788 srk, 789 srl, 790 srlg, 791 srlk, 792 srst, 793 st, 794 stc, 795 stch, 796 stcy, 797 std, 798 stdy, 799 ste, 800 stey, 801 stfh, 802 stg, 803 stgrl, 804 sth, 805 sthh, 806 sthrl, 807 sthy, 808 stmg, 809 strl, 810 strv, 811 strvg, 812 sty, 813 sxbr, 814 sy, 815 tm, 816 tmhh, 817 tmhl, 818 tmlh, 819 tmll, 820 tmy, 821 x, 822 xc, 823 xg, 824 xgr, 825 xgrk, 826 xi, 827 xihf, 828 xilf, 829 xiy, 830 xr, 831 xrk, 832 xy, 833 } 834 835 /// Group of SystemZ instructions 836 enum SyszInstructionGroup { 837 invalid = 0, 838 839 // Generic groups 840 // All jump instructions (conditional+direct+indirect jumps) 841 jump, 842 843 // Architecture-specific groups 844 distinctops = 128, 845 fpextension, 846 highword, 847 interlockedaccess1, 848 loadstoreoncond, 849 }