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