Print this page
3317 dis(1) should support cross-target disassembly

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdisasm/sparc/dis_sparc_fmt.c
          +++ new/usr/src/lib/libdisasm/common/dis_sparc_fmt.c
↓ open down ↓ 19 lines elided ↑ open up ↑
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27   27  /*
  28   28   * Copyright 2009 Jason King.  All rights reserved.
  29   29   * Use is subject to license terms.
       30 + * Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
  30   31   */
  31   32  
  32   33  
  33   34  #include <sys/byteorder.h>
  34   35  #include <stdarg.h>
  35   36  
  36   37  #if !defined(DIS_STANDALONE)
  37   38  #include <stdio.h>
  38   39  #endif /* DIS_STANDALONE */
  39   40  
↓ open down ↓ 651 lines elided ↑ open up ↑
 691  692  
 692  693  
 693  694  /*
 694  695   * print out a call instruction
 695  696   * format: call address  <name>
 696  697   */
 697  698  /* ARGSUSED1 */
 698  699  int
 699  700  fmt_call(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
 700  701  {
      702 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
 701  703          ifmt_t *f = (ifmt_t *)&instr;
 702  704  
 703  705          int32_t disp;
 704  706          size_t curlen;
 705  707  
 706  708          int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
 707  709  
 708      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
      710 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
 709  711                  prt_field("op", f->f1.op, 2);
 710  712                  prt_field("disp30", f->f1.disp30, 30);
 711  713          }
 712  714  
 713  715          disp = sign_extend(f->f1.disp30, 30) * 4;
 714  716  
 715  717          prt_name(dhp, inp->in_data.in_def.in_name, 1);
 716  718  
 717  719          bprintf(dhp, (octal != 0) ? "%s0%-11lo" : "%s0x%-10lx",
 718  720              (disp < 0) ? "-" : "+",
 719  721              (disp < 0) ? (-disp) : disp);
 720  722  
 721      -        (void) strlcat(dhp->dh_buf, " <", dhp->dh_buflen);
      723 +        (void) strlcat(dhx->dhx_buf, " <", dhx->dhx_buflen);
 722  724  
 723      -        curlen = strlen(dhp->dh_buf);
      725 +        curlen = strlen(dhx->dhx_buf);
 724  726          dhp->dh_lookup(dhp->dh_data, dhp->dh_addr + (int64_t)disp,
 725      -            dhp->dh_buf + curlen, dhp->dh_buflen - curlen - 1, NULL,
      727 +            dhx->dhx_buf + curlen, dhx->dhx_buflen - curlen - 1, NULL,
 726  728              NULL);
 727      -        (void) strlcat(dhp->dh_buf, ">", dhp->dh_buflen);
      729 +        (void) strlcat(dhx->dhx_buf, ">", dhx->dhx_buflen);
 728  730  
 729  731  
 730  732          return (0);
 731  733  }
 732  734  
 733  735  int
 734  736  fmt_sethi(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
 735  737  {
      738 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
 736  739          ifmt_t *f = (ifmt_t *)&instr;
 737  740  
 738      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
      741 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
 739  742                  prt_field("op", f->f2.op, 2);
 740  743                  prt_field("op2", f->f2.op2, 3);
 741  744                  prt_field("rd", f->f2.rd, 5);
 742  745                  prt_field("imm22", f->f2.imm22, 22);
 743  746          }
 744  747  
 745  748          if (idx == 0) {
 746  749                  /* unimp / illtrap */
 747  750                  prt_name(dhp, inp->in_data.in_def.in_name, 1);
 748  751                  prt_imm(dhp, f->f2.imm22, 0);
↓ open down ↓ 15 lines elided ↑ open up ↑
 764  767              f->f2.imm22 << 10,
 765  768              reg_names[f->f2.rd]);
 766  769  
 767  770          return (0);
 768  771  }
 769  772  
 770  773  /* ARGSUSED3 */
 771  774  int
 772  775  fmt_branch(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
 773  776  {
      777 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
 774  778          const char *name = inp->in_data.in_def.in_name;
 775  779          const char *r = NULL;
 776  780          const char *annul = "";
 777  781          const char *pred  = "";
 778  782  
 779  783          char buf[15];
 780  784  
 781  785          ifmt_t *f = (ifmt_t *)&instr;
 782  786  
 783  787          size_t curlen;
 784  788          int32_t disp;
 785  789          uint32_t flags = inp->in_data.in_def.in_flags;
 786  790          int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
 787  791  
 788      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
      792 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
 789  793                  prt_field("op", f->f2.op, 2);
 790  794                  prt_field("op2", f->f2.op2, 3);
 791  795  
 792  796                  switch (FLG_DISP_VAL(flags)) {
 793  797                  case DISP22:
 794  798                          prt_field("cond", f->f2a.cond, 4);
 795  799                          prt_field("a", f->f2a.a, 1);
 796  800                          prt_field("disp22", f->f2a.disp22, 22);
 797  801                          break;
 798  802  
↓ open down ↓ 10 lines elided ↑ open up ↑
 809  813                          prt_field("rcond", f->f2c.cond, 3);
 810  814                          prt_field("p", f->f2c.p, 1);
 811  815                          prt_field("rs1", f->f2c.rs1, 5);
 812  816                          prt_field("d16hi", f->f2c.d16hi, 2);
 813  817                          prt_field("d16lo", f->f2c.d16lo, 14);
 814  818                          break;
 815  819                  }
 816  820          }
 817  821  
 818  822          if (f->f2b.op2 == 0x01 && idx == 0x00 && f->f2b.p == 1 &&
 819      -            f->f2b.cc == 0x02 && ((dhp->dh_debug & DIS_DEBUG_SYN_ALL) != 0)) {
      823 +            f->f2b.cc == 0x02 && ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) != 0)) {
 820  824                  name = "iprefetch";
 821  825                  flags = FLG_RS1(REG_NONE)|FLG_DISP(DISP19);
 822  826          }
 823  827  
 824  828  
 825  829          switch (FLG_DISP_VAL(flags)) {
 826  830          case DISP22:
 827  831                  disp = sign_extend(f->f2a.disp22, 22);
 828  832                  break;
 829  833  
↓ open down ↓ 17 lines elided ↑ open up ↑
 847  851          if (r == NULL)
 848  852                  return (-1);
 849  853  
 850  854          if (f->f2a.a == 1)
 851  855                  annul = ",a";
 852  856  
 853  857          if ((flags & FLG_PRED) != 0) {
 854  858                  if (f->f2b.p == 0) {
 855  859                          pred = ",pn";
 856  860                  } else {
 857      -                        if ((dhp->dh_debug & DIS_DEBUG_COMPAT) != 0)
      861 +                        if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0)
 858  862                                  pred = ",pt";
 859  863                  }
 860  864          }
 861  865  
 862  866          (void) snprintf(buf, sizeof (buf), "%s%s%s", name, annul, pred);
 863  867          prt_name(dhp, buf, 1);
 864  868  
 865  869  
 866  870          switch (FLG_DISP_VAL(flags)) {
 867  871          case DISP22:
↓ open down ↓ 13 lines elided ↑ open up ↑
 881  885  
 882  886          case DISP16:
 883  887                  bprintf(dhp,
 884  888                      (octal != 0) ? "%s, %s0%-6lo <" : "%s, %s0x%-5lx <",
 885  889                      r,
 886  890                      (disp < 0) ? "-" : "+",
 887  891                      (disp < 0) ? (-disp) : disp);
 888  892                  break;
 889  893          }
 890  894  
 891      -        curlen = strlen(dhp->dh_buf);
      895 +        curlen = strlen(dhx->dhx_buf);
 892  896          dhp->dh_lookup(dhp->dh_data, dhp->dh_addr + (int64_t)disp,
 893      -            dhp->dh_buf + curlen, dhp->dh_buflen - curlen - 1, NULL, NULL);
      897 +            dhx->dhx_buf + curlen, dhx->dhx_buflen - curlen - 1, NULL, NULL);
 894  898  
 895      -        (void) strlcat(dhp->dh_buf, ">", dhp->dh_buflen);
      899 +        (void) strlcat(dhx->dhx_buf, ">", dhx->dhx_buflen);
 896  900  
 897  901          return (0);
 898  902  }
 899  903  
 900  904  
 901  905  
 902  906  /*
 903  907   * print out the compare and swap instructions (casa/casxa)
 904  908   * format: casa/casxa [%rs1] imm_asi, %rs2, %rd
 905  909   *          casa/casxa [%rs1] %asi, %rs2, %rd
↓ open down ↓ 2 lines elided ↑ open up ↑
 908  912   * when an immediate ASI value is given as follows:
 909  913   *
 910  914   * casa  [%rs1]#ASI_P, %rs2, %rd    -> cas   [%rs1], %rs2, %rd
 911  915   * casa  [%rs1]#ASI_P_L, %rs2, %rd  -> casl  [%rs1], %rs2, %rd
 912  916   * casxa [%rs1]#ASI_P, %rs2, %rd    -> casx  [%rs1], %rs2, %rd
 913  917   * casxa [%rs1]#ASI_P_L, %rs2, %rd  -> casxl [%rs1], %rs2, %rd
 914  918   */
 915  919  static int
 916  920  fmt_cas(dis_handle_t *dhp, uint32_t instr, const char *name)
 917  921  {
      922 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
 918  923          ifmt_t *f = (ifmt_t *)&instr;
 919  924          const char *asistr = NULL;
 920  925          int noasi = 0;
 921  926  
 922  927          asistr = get_asi_name(f->f3.asi);
 923  928  
 924      -        if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT)) != 0) {
      929 +        if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT)) != 0) {
 925  930                  if (f->f3.op3 == 0x3c && f->f3.i == 0) {
 926  931                          if (f->f3.asi == 0x80) {
 927  932                                  noasi = 1;
 928  933                                  name = "cas";
 929  934                          }
 930  935  
 931  936                          if (f->f3.asi == 0x88) {
 932  937                                  noasi = 1;
 933  938                                  name = "casl";
 934  939                          }
↓ open down ↓ 10 lines elided ↑ open up ↑
 945  950                                  name = "casxl";
 946  951                          }
 947  952                  }
 948  953          }
 949  954  
 950  955          prt_name(dhp, name, 1);
 951  956  
 952  957          bprintf(dhp, "[%s]", reg_names[f->f3.rs1]);
 953  958  
 954  959          if (noasi == 0) {
 955      -                (void) strlcat(dhp->dh_buf, " ", dhp->dh_buflen);
      960 +                (void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
 956  961                  prt_asi(dhp, instr);
 957  962          }
 958  963  
 959  964          bprintf(dhp, ", %s, %s", reg_names[f->f3.rs2], reg_names[f->f3.rd]);
 960  965  
 961  966          if (noasi == 0 && asistr != NULL)
 962  967                  bprintf(dhp, "\t<%s>", asistr);
 963  968  
 964  969          return (0);
 965  970  }
↓ open down ↓ 26 lines elided ↑ open up ↑
 992  997   *
 993  998   * If DIS_DEBUG_COMPAT is set, the following substitutions also take place
 994  999   *      lduw -> ld
 995 1000   *      ldtw -> ld
 996 1001   *      stuw -> st
 997 1002   *      sttw -> st
 998 1003   */
 999 1004  int
1000 1005  fmt_ls(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1001 1006  {
     1007 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1002 1008          ifmt_t *f = (ifmt_t *)&instr;
1003 1009          const char *regstr = NULL;
1004 1010          const char *asistr = NULL;
1005 1011  
1006 1012          const char *iname = inp->in_data.in_def.in_name;
1007 1013          uint32_t flags = inp->in_data.in_def.in_flags;
1008 1014  
1009      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     1015 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1010 1016                  prt_field("op", f->f3.op, 2);
1011 1017                  prt_field("op3", f->f3.op3, 6);
1012 1018                  prt_field("rs1", f->f3.rs1, 5);
1013 1019                  prt_field("i", f->f3.i, 1);
1014 1020                  if (f->f3.i != 0) {
1015 1021                          prt_field("simm13", f->f3a.simm13, 13);
1016 1022                  } else {
1017 1023                          if ((flags & FLG_ASI) != 0)
1018 1024                                  prt_field("imm_asi", f->f3.asi, 8);
1019 1025                          prt_field("rs2", f->f3.rs2, 5);
↓ open down ↓ 2 lines elided ↑ open up ↑
1022 1028          }
1023 1029  
1024 1030          if (idx == 0x2d || idx == 0x3d) {
1025 1031                  /* prefetch / prefetcha */
1026 1032  
1027 1033                  prt_name(dhp, iname, 1);
1028 1034  
1029 1035                  prt_address(dhp, instr, 0);
1030 1036  
1031 1037                  if (idx == 0x3d) {
1032      -                        (void) strlcat(dhp->dh_buf, " ", dhp->dh_buflen);
     1038 +                        (void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
1033 1039                          prt_asi(dhp, instr);
1034 1040                  }
1035 1041  
1036      -                (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     1042 +                (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1037 1043  
1038 1044                  /* fcn field is the same as rd */
1039 1045                  if (prefetch_str[f->f3.rd] != NULL)
1040      -                        (void) strlcat(dhp->dh_buf, prefetch_str[f->f3.rd],
1041      -                            dhp->dh_buflen);
     1046 +                        (void) strlcat(dhx->dhx_buf, prefetch_str[f->f3.rd],
     1047 +                            dhx->dhx_buflen);
1042 1048                  else
1043 1049                          prt_imm(dhp, f->f3.rd, 0);
1044 1050  
1045 1051                  if (idx == 0x3d && f->f3.i == 0) {
1046 1052                          asistr = get_asi_name(f->f3.asi);
1047 1053                          if (asistr != NULL)
1048 1054                                  bprintf(dhp, "\t<%s>", asistr);
1049 1055                  }
1050 1056  
1051 1057                  return (0);
1052 1058          }
1053 1059  
1054 1060          /* casa / casxa */
1055 1061          if (idx == 0x3c || idx == 0x3e)
1056 1062                  return (fmt_cas(dhp, instr, iname));
1057 1063  
1058 1064          /* synthetic instructions & special cases */
1059 1065          switch (idx) {
1060 1066          case 0x00:
1061 1067                  /* ld */
1062      -                if ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0)
     1068 +                if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1063 1069                          iname = "lduw";
1064 1070                  break;
1065 1071  
1066 1072          case 0x03:
1067      -                if ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0)
     1073 +                if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1068 1074                          iname = "ldtw";
1069 1075                  break;
1070 1076  
1071 1077          case 0x04:
1072 1078                  /* stw */
1073      -                if ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0)
     1079 +                if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1074 1080                          iname = "stuw";
1075 1081  
1076 1082                  if ((dhp->dh_flags & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1077 1083                      == 0)
1078 1084                          break;
1079 1085  
1080 1086                  if (f->f3.rd == 0) {
1081 1087                          iname = "clr";
1082 1088                          flags = FLG_RD(REG_NONE);
1083 1089                  }
↓ open down ↓ 17 lines elided ↑ open up ↑
1101 1107                      == 0)
1102 1108                          break;
1103 1109  
1104 1110                  if (f->f3.rd == 0) {
1105 1111                          iname = "clrh";
1106 1112                          flags = FLG_RD(REG_NONE);
1107 1113                  }
1108 1114                  break;
1109 1115  
1110 1116          case 0x07:
1111      -                if ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0)
     1117 +                if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1112 1118                          iname = "sttw";
1113 1119                  break;
1114 1120  
1115 1121          case 0x0e:
1116 1122                  /* stx */
1117 1123  
1118 1124                  if ((dhp->dh_flags & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1119 1125                      == 0)
1120 1126                          break;
1121 1127  
1122 1128                  if (f->f3.rd == 0) {
1123 1129                          iname = "clrx";
1124 1130                          flags = FLG_RD(REG_NONE);
1125 1131                  }
1126 1132                  break;
1127 1133  
1128 1134          case 0x13:
1129 1135                  /* ldtwa */
1130      -                if (((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0) &&
     1136 +                if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0) &&
1131 1137                      ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0))
1132 1138                          iname = "ldtwa";
1133 1139                  break;
1134 1140  
1135 1141          case 0x17:
1136 1142                  /* sttwa */
1137      -                if (((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0) &&
     1143 +                if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0) &&
1138 1144                      ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0))
1139 1145                          iname = "sttwa";
1140 1146                  break;
1141 1147  
1142 1148          case 0x21:
1143 1149          case 0x25:
1144 1150                  /*
1145 1151                   * on sparcv8 it merely says that rd != 1 should generate an
1146 1152                   * exception, on v9, it is illegal
1147 1153                   */
↓ open down ↓ 57 lines elided ↑ open up ↑
1205 1211  
1206 1212          regstr = get_regname(dhp, FLG_RD_VAL(flags), f->f3.rd);
1207 1213  
1208 1214          if (f->f3.i == 0)
1209 1215                  asistr = get_asi_name(f->f3.asi);
1210 1216  
1211 1217          prt_name(dhp, iname, 1);
1212 1218  
1213 1219          if ((flags & FLG_STORE) != 0) {
1214 1220                  if (regstr[0] != '\0') {
1215      -                        (void) strlcat(dhp->dh_buf, regstr, dhp->dh_buflen);
1216      -                        (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     1221 +                        (void) strlcat(dhx->dhx_buf, regstr, dhx->dhx_buflen);
     1222 +                        (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1217 1223                  }
1218 1224  
1219 1225                  prt_address(dhp, instr, 0);
1220 1226                  if ((flags & FLG_ASI) != 0) {
1221      -                        (void) strlcat(dhp->dh_buf, " ", dhp->dh_buflen);
     1227 +                        (void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
1222 1228                          prt_asi(dhp, instr);
1223 1229                  }
1224 1230          } else {
1225 1231                  prt_address(dhp, instr, 0);
1226 1232                  if ((flags & FLG_ASI) != 0) {
1227      -                        (void) strlcat(dhp->dh_buf, " ", dhp->dh_buflen);
     1233 +                        (void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
1228 1234                          prt_asi(dhp, instr);
1229 1235                  }
1230 1236  
1231 1237                  if (regstr[0] != '\0') {
1232      -                        (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
1233      -                        (void) strlcat(dhp->dh_buf, regstr, dhp->dh_buflen);
     1238 +                        (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
     1239 +                        (void) strlcat(dhx->dhx_buf, regstr, dhx->dhx_buflen);
1234 1240                  }
1235 1241          }
1236 1242  
1237 1243          if ((flags & FLG_ASI) != 0 && asistr != NULL)
1238 1244                  bprintf(dhp, "\t<%s>", asistr);
1239 1245  
1240 1246          return (0);
1241 1247  }
1242 1248  
1243 1249  static int
1244 1250  fmt_cpop(dis_handle_t *dhp, uint32_t instr, const inst_t *inp)
1245 1251  {
     1252 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1246 1253          ifmt_t *f = (ifmt_t *)&instr;
1247 1254          int flags = FLG_P1(REG_CP)|FLG_P2(REG_CP)|FLG_NOIMM|FLG_P3(REG_CP);
1248 1255  
1249      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     1256 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1250 1257                  prt_field("op", f->fcp.op, 2);
1251 1258                  prt_field("op3", f->fcp.op3, 6);
1252 1259                  prt_field("opc", f->fcp.opc, 9);
1253 1260                  prt_field("rs1", f->fcp.rs1, 5);
1254 1261                  prt_field("rs2", f->fcp.rs2, 5);
1255 1262                  prt_field("rd", f->fcp.rd, 5);
1256 1263          }
1257 1264  
1258 1265          prt_name(dhp, inp->in_data.in_def.in_name, 1);
1259 1266          prt_imm(dhp, f->fcp.opc, 0);
1260 1267  
1261      -        (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     1268 +        (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1262 1269          (void) prt_aluargs(dhp, instr, flags);
1263 1270  
1264 1271          return (0);
1265 1272  }
1266 1273  
1267 1274  static int
1268 1275  dis_fmt_rdwr(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1269 1276  {
     1277 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1270 1278          const char *psr_str = "%psr";
1271 1279          const char *wim_str = "%wim";
1272 1280          const char *tbr_str = "%tbr";
1273 1281  
1274 1282          const char *name = inp->in_data.in_def.in_name;
1275 1283          const char *regstr = NULL;
1276 1284  
1277 1285          ifmt_t *f = (ifmt_t *)&instr;
1278 1286  
1279 1287          int rd = (idx < 0x30);
↓ open down ↓ 105 lines elided ↑ open up ↑
1385 1393                   */
1386 1394                  if (v9 != 0 && f->f3.rd == 15 && f->f3.rs1 == 0 &&
1387 1395                      f->f3.i == 1) {
1388 1396                          prt_name(dhp, "sir", 1);
1389 1397                          prt_imm(dhp, sign_extend(f->f3a.simm13, 13),
1390 1398                              IMM_SIGNED);
1391 1399                          return (0);
1392 1400                  }
1393 1401  
1394 1402                  /* synth: mov */
1395      -                if ((dhp->dh_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
     1403 +                if ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1396 1404                      == 0)
1397 1405                          break;
1398 1406  
1399 1407                  if (v9 == 0) {
1400 1408                          if (f->f3.rs1 == 0) {
1401 1409                                  name = "mov";
1402 1410                                  pr_rs1 = 0;
1403 1411                          }
1404 1412  
1405 1413                          if ((f->f3.i == 0 && f->f3.rs2 == 0) ||
↓ open down ↓ 51 lines elided ↑ open up ↑
1457 1465                  bprintf(dhp, "%s, %s", regstr, reg_names[f->f3.rd]);
1458 1466          } else {
1459 1467                  if (pr_rs1 == 1)
1460 1468                          bprintf(dhp, "%s, ", reg_names[f->f3.rs1]);
1461 1469  
1462 1470                  if (pr_rs2 != 0) {
1463 1471                          if (f->f3.i == 1)
1464 1472                                  prt_imm(dhp, sign_extend(f->f3a.simm13, 13),
1465 1473                                      IMM_SIGNED);
1466 1474                          else
1467      -                                (void) strlcat(dhp->dh_buf,
1468      -                                    reg_names[f->f3.rs2], dhp->dh_buflen);
1469      -                        (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     1475 +                                (void) strlcat(dhx->dhx_buf,
     1476 +                                    reg_names[f->f3.rs2], dhx->dhx_buflen);
     1477 +                        (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1470 1478                  }
1471 1479  
1472      -                (void) strlcat(dhp->dh_buf, regstr, dhp->dh_buflen);
     1480 +                (void) strlcat(dhx->dhx_buf, regstr, dhx->dhx_buflen);
1473 1481          }
1474 1482  
1475 1483          return (0);
1476 1484  }
1477 1485  
1478 1486  /* ARGSUSED3 */
1479 1487  int
1480 1488  fmt_trap(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1481 1489  {
     1490 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1482 1491          ifmt_t *f = (ifmt_t *)&instr;
1483 1492  
1484 1493          int v9 = ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0);
1485 1494          int p_rs1, p_t;
1486 1495  
1487 1496          if (f->ftcc.undef != 0)
1488 1497                  return (-1);
1489 1498  
1490 1499          if (icc_names[f->ftcc.cc] == NULL)
1491 1500                  return (-1);
1492 1501  
1493 1502          if (f->ftcc.i == 1 && f->ftcc.undef2 != 0)
1494 1503                  return (-1);
1495 1504  
1496 1505          if (f->ftcc2.i == 0 && f->ftcc2.undef2 != 0)
1497 1506                  return (-1);
1498 1507  
1499 1508          p_rs1 = ((f->ftcc.rs1 != 0) ||
1500      -            ((dhp->dh_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0));
     1509 +            ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0));
1501 1510  
1502 1511          if (f->ftcc.i == 0) {
1503 1512                  p_t = (f->f3.rs2 != 0 || p_rs1 == 0);
1504 1513  
1505 1514                  bprintf(dhp, "%-9s %s%s%s%s%s", inp->in_data.in_def.in_name,
1506 1515                      (v9 != 0) ? icc_names[f->ftcc2.cc] : "",
1507 1516                      (v9 != 0) ? ", " : "",
1508 1517                      (p_rs1 != 0) ? reg_names[f->ftcc2.rs1] : "",
1509 1518                      (p_rs1 != 0) ? " + " : "",
1510 1519                      (p_t != 0) ? reg_names[f->f3.rs2] : "");
↓ open down ↓ 37 lines elided ↑ open up ↑
1548 1557                  bprintf(dhp, "%s, %s, %s", reg_names[f->f3.rs1],
1549 1558                      reg_names[f->f3.rs2], reg_names[f->f3.rd]);
1550 1559  
1551 1560          return (0);
1552 1561  }
1553 1562  
1554 1563  /* ARGSUSED3 */
1555 1564  static int
1556 1565  prt_jmpl(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1557 1566  {
     1567 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1558 1568          const char *name = inp->in_data.in_def.in_name;
1559 1569          ifmt_t *f = (ifmt_t *)&instr;
1560 1570  
1561      -        if (f->f3.rd == 15 && ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0))
     1571 +        if (f->f3.rd == 15 && ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0))
1562 1572                  name = "call";
1563 1573  
1564 1574          if (f->f3.rd == 0) {
1565 1575                  if (f->f3.i == 1 && f->f3a.simm13 == 8) {
1566 1576                          if (f->f3.rs1 == 15) {
1567 1577                                  prt_name(dhp, "retl", 0);
1568 1578                                  return (0);
1569 1579                          }
1570 1580  
1571 1581                          if (f->f3.rs1 == 31) {
↓ open down ↓ 4 lines elided ↑ open up ↑
1576 1586  
1577 1587                  name = "jmp";
1578 1588          }
1579 1589  
1580 1590          prt_name(dhp, name, 1);
1581 1591          prt_address(dhp, instr, 1);
1582 1592  
1583 1593          if (f->f3.rd == 0)
1584 1594                  return (0);
1585 1595  
1586      -        if (f->f3.rd == 15 && ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0))
     1596 +        if (f->f3.rd == 15 && ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0))
1587 1597                  return (0);
1588 1598  
1589 1599          bprintf(dhp, ", %s", reg_names[f->f3.rd]);
1590 1600  
1591 1601          return (0);
1592 1602  }
1593 1603  
1594 1604  int
1595 1605  fmt_alu(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1596 1606  {
     1607 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1597 1608          ifmt_t *f = (ifmt_t *)&instr;
1598 1609  
1599 1610          const char *name = inp->in_data.in_def.in_name;
1600 1611          int flags = inp->in_data.in_def.in_flags;
1601 1612          int arg = 0;
1602 1613  
1603      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     1614 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1604 1615                  prt_field("op", f->f3.op, 2);
1605 1616                  prt_field("op3", f->f3.op3, 6);
1606 1617                  prt_field("rs1", f->f3.rs1, 5);
1607 1618  
1608 1619                  switch (idx) {
1609 1620                          /* TODO: more formats */
1610 1621  
1611 1622                  default:
1612 1623                          if (f->f3.i == 0)
1613 1624                                  prt_field("rs2", f->f3.rs2, 5);
↓ open down ↓ 2 lines elided ↑ open up ↑
1616 1627  
1617 1628                          prt_field("rd", f->f3.rd, 5);
1618 1629                  }
1619 1630  
1620 1631          }
1621 1632  
1622 1633          switch (idx) {
1623 1634          case 0x00:
1624 1635                  /* add */
1625 1636  
1626      -                if ((dhp->dh_debug & DIS_DEBUG_SYN_ALL) == 0)
     1637 +                if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) == 0)
1627 1638                          break;
1628 1639  
1629 1640                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1630 1641                      f->f3a.simm13 == 1) {
1631 1642                          name = "inc";
1632 1643                          flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1633 1644                          break;
1634 1645                  }
1635 1646  
1636 1647                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1637 1648                      f->f3a.simm13 != 1) {
1638 1649                          name = "inc";
1639 1650                          flags = FLG_P1(REG_NONE);
1640 1651                          break;
1641 1652                  }
1642 1653                  break;
1643 1654  
1644 1655          case 0x02:
1645 1656                  /* or */
1646 1657  
1647      -                if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
     1658 +                if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1648 1659                      == 0)
1649 1660                          break;
1650 1661  
1651      -                if ((dhp->dh_debug & DIS_DEBUG_SYN_ALL) != 0) {
     1662 +                if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) != 0) {
1652 1663                          if (f->f3.rs1 == f->f3.rd) {
1653 1664                                  name = "bset";
1654 1665                                  flags = FLG_P1(REG_NONE);
1655 1666                                  break;
1656 1667                          }
1657 1668                  }
1658 1669  
1659 1670                  if (((f->f3.i == 0 && f->f3.rs2 == 0) ||
1660 1671                      (f->f3.i == 1 && f->f3a.simm13 == 0)) &&
1661 1672                      (f->f3.rs1 == 0)) {
↓ open down ↓ 5 lines elided ↑ open up ↑
1667 1678                  if (f->f3.rs1 == 0) {
1668 1679                          name = "mov";
1669 1680                          flags = FLG_P1(REG_NONE);
1670 1681                          break;
1671 1682                  }
1672 1683                  break;
1673 1684  
1674 1685          case 0x04:
1675 1686                  /* sub */
1676 1687  
1677      -                if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
     1688 +                if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1678 1689                      == 0)
1679 1690                          break;
1680 1691  
1681 1692                  if (f->f3.rs1 == 0 && f->f3.i == 0 && f->f3.rs2 == f->f3.rd) {
1682 1693                          name = "neg";
1683 1694                          flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE);
1684 1695                          break;
1685 1696                  }
1686 1697  
1687 1698                  if (f->f3.rs1 == 0 && f->f3.i == 0 && f->f3.rs2 != f->f3.rd) {
1688 1699                          name = "neg";
1689 1700                          flags = FLG_P1(REG_NONE);
1690 1701                          break;
1691 1702                  }
1692 1703  
1693      -                if ((dhp->dh_debug & DIS_DEBUG_SYN_ALL) == 0)
     1704 +                if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) == 0)
1694 1705                          break;
1695 1706  
1696 1707                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1697 1708                      f->f3a.simm13 == 1) {
1698 1709                          name = "dec";
1699 1710                          flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1700 1711                          break;
1701 1712                  }
1702 1713  
1703 1714                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1704 1715                      f->f3a.simm13 != 1) {
1705 1716                          name = "dec";
1706 1717                          flags = FLG_P1(REG_NONE);
1707 1718                          break;
1708 1719                  }
1709 1720                  break;
1710 1721  
1711 1722          case 0x07:
1712 1723                  /* xnor */
1713 1724  
1714      -                if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
     1725 +                if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1715 1726                      == 0)
1716 1727                          break;
1717 1728  
1718 1729                  /*
1719 1730                   * xnor -> not when you have:
1720 1731                   *       xnor %rs1, 0x0 or %g0, %rd
1721 1732                   */
1722 1733                  if ((f->f3.i == 0 && f->f3.rs2 != 0) ||
1723 1734                      (f->f3.i == 1 && f->f3a.simm13 != 0))
1724 1735                          break;
↓ open down ↓ 5 lines elided ↑ open up ↑
1730 1741                              FLG_P3(REG_INT);
1731 1742                  else
1732 1743                          flags = FLG_P1(REG_INT)|FLG_P2(REG_NONE)|FLG_NOIMM|
1733 1744                              FLG_P3(REG_INT);
1734 1745  
1735 1746                  break;
1736 1747  
1737 1748          case 0x10:
1738 1749                  /* addcc */
1739 1750  
1740      -                if ((dhp->dh_debug & DIS_DEBUG_SYN_ALL) == 0)
     1751 +                if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) == 0)
1741 1752                          break;
1742 1753  
1743 1754                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1744 1755                      f->f3a.simm13 == 1) {
1745 1756                          name = "inccc";
1746 1757                          flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1747 1758                          break;
1748 1759                  }
1749 1760  
1750 1761                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
↓ open down ↓ 3 lines elided ↑ open up ↑
1754 1765                          break;
1755 1766                  }
1756 1767                  break;
1757 1768  
1758 1769          case 0x11:
1759 1770                  /* andcc */
1760 1771  
1761 1772                  if (f->f3.rd != 0)
1762 1773                          break;
1763 1774  
1764      -                if ((dhp->dh_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
     1775 +                if ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1765 1776                      == 0)
1766 1777                          break;
1767 1778  
1768      -                if (((dhp->dh_debug & DIS_DEBUG_COMPAT) != 0) &&
     1779 +                if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0) &&
1769 1780                      ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) == 0))
1770 1781                          break;
1771 1782  
1772 1783                  name = "btst";
1773 1784                  flags = FLG_P1(REG_NONE);
1774 1785                  f->f3.rd = f->f3.rs1;
1775 1786                  break;
1776 1787  
1777 1788          case 0x12:
1778 1789                  /* orcc */
1779 1790  
1780      -                if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
     1791 +                if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1781 1792                      == 0)
1782 1793                          break;
1783 1794  
1784 1795                  if (f->f3.rs1 == 0 && f->f3.rd == 0 && f->f3.i == 0) {
1785 1796                          name = "tst";
1786 1797                          flags = FLG_P1(REG_NONE)|FLG_P3(REG_NONE);
1787 1798                          break;
1788 1799                  }
1789 1800  
1790 1801                  if (f->f3.rs2 == 0 && f->f3.rd == 0 && f->f3.i == 0) {
1791 1802                          name = "tst";
1792 1803                          flags = FLG_P2(REG_NONE)|FLG_P3(REG_NONE);
1793 1804                          break;
1794 1805                  }
1795 1806  
1796 1807                  break;
1797 1808  
1798 1809          case 0x14:
1799 1810                  /* subcc */
1800 1811  
1801      -                if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
     1812 +                if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1802 1813                      == 0)
1803 1814                          break;
1804 1815  
1805 1816                  if (f->f3.rd == 0) {
1806 1817                          name = "cmp";
1807 1818                          flags = FLG_P3(REG_NONE);
1808 1819                          break;
1809 1820                  }
1810 1821  
1811      -                if ((dhp->dh_debug & DIS_DEBUG_COMPAT) != 0)
     1822 +                if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0)
1812 1823                          break;
1813 1824  
1814 1825                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1815 1826                      f->f3a.simm13 == 1) {
1816 1827                          name = "deccc";
1817 1828                          flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1818 1829                          break;
1819 1830                  }
1820 1831  
1821 1832                  if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
↓ open down ↓ 39 lines elided ↑ open up ↑
1861 1872  
1862 1873          case 0x3b:
1863 1874                  /* flush */
1864 1875                  prt_name(dhp, name, 1);
1865 1876                  prt_address(dhp, instr, 0);
1866 1877                  return (0);
1867 1878  
1868 1879          case 0x3c:
1869 1880          case 0x3d:
1870 1881                  /* save / restore */
1871      -                if ((dhp->dh_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
     1882 +                if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1872 1883                      == 0)
1873 1884                          break;
1874 1885  
1875 1886                  if (f->f3.rs1 != 0 || f->f3.rs2 != 0 || f->f3.rd != 0)
1876 1887                          break;
1877 1888  
1878      -                if (f->f3.i != 0 && ((dhp->dh_debug & DIS_DEBUG_COMPAT) != 0))
     1889 +                if (f->f3.i != 0 && ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0))
1879 1890                          break;
1880 1891  
1881 1892                  prt_name(dhp, name, 0);
1882 1893                  return (0);
1883 1894          }
1884 1895  
1885 1896          if (FLG_P1_VAL(flags) != REG_NONE || FLG_P2_VAL(flags) != REG_NONE ||
1886 1897              FLG_P3_VAL(flags) != REG_NONE)
1887 1898                  arg = 1;
1888 1899  
↓ open down ↓ 23 lines elided ↑ open up ↑
1912 1923                  prt_address(dhp, instr, 1);
1913 1924          }
1914 1925  
1915 1926          return (0);
1916 1927  }
1917 1928  
1918 1929  /* ARGSUSED3 */
1919 1930  int
1920 1931  fmt_movcc(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1921 1932  {
     1933 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1922 1934          ifmt_t *f = (ifmt_t *)&instr;
1923 1935          const char **regs = NULL;
1924 1936  
1925      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     1937 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1926 1938                  prt_field("op", f->f3c.op, 2);
1927 1939                  prt_field("op3", f->f3c.op3, 6);
1928 1940                  prt_field("cond", f->f3c.cond, 4);
1929 1941                  prt_field("cc2", f->f3c.cc2, 1);
1930 1942                  prt_field("cc", f->f3c.cc, 2);
1931 1943                  prt_field("i", f->f3c.i, 1);
1932 1944  
1933 1945                  if (f->f3c.i == 0)
1934 1946                          prt_field("rs2", f->f3.rs2, 5);
1935 1947                  else
↓ open down ↓ 10 lines elided ↑ open up ↑
1946 1958                          return (-1);
1947 1959          }
1948 1960  
1949 1961          prt_name(dhp, inp->in_data.in_def.in_name, 1);
1950 1962  
1951 1963          bprintf(dhp, "%s, ", regs[f->f3c.cc]);
1952 1964  
1953 1965          if (f->f3c.i == 1)
1954 1966                  prt_imm(dhp, sign_extend(f->f3c.simm11, 11), IMM_SIGNED);
1955 1967          else
1956      -                (void) strlcat(dhp->dh_buf, reg_names[f->f3.rs2],
1957      -                    dhp->dh_buflen);
     1968 +                (void) strlcat(dhx->dhx_buf, reg_names[f->f3.rs2],
     1969 +                    dhx->dhx_buflen);
1958 1970  
1959 1971          bprintf(dhp, ", %s", reg_names[f->f3.rd]);
1960 1972  
1961 1973          return (0);
1962 1974  }
1963 1975  
1964 1976  /* ARGSUSED3 */
1965 1977  int
1966 1978  fmt_movr(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1967 1979  {
     1980 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1968 1981          ifmt_t *f = (ifmt_t *)&instr;
1969 1982  
1970 1983          prt_name(dhp, inp->in_data.in_def.in_name, 1);
1971 1984  
1972 1985          bprintf(dhp, "%s, ", reg_names[f->f3d.rs1]);
1973 1986  
1974 1987          if (f->f3d.i == 1)
1975 1988                  prt_imm(dhp, sign_extend(f->f3d.simm10, 10), IMM_SIGNED);
1976 1989          else
1977      -                (void) strlcat(dhp->dh_buf, reg_names[f->f3.rs2],
1978      -                    dhp->dh_buflen);
     1990 +                (void) strlcat(dhx->dhx_buf, reg_names[f->f3.rs2],
     1991 +                    dhx->dhx_buflen);
1979 1992  
1980 1993          bprintf(dhp, ", %s", reg_names[f->f3.rd]);
1981 1994  
1982 1995          return (0);
1983 1996  }
1984 1997  
1985 1998  /* ARGSUSED3 */
1986 1999  int
1987 2000  fmt_fpop1(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1988 2001  {
     2002 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1989 2003          ifmt_t *f = (ifmt_t *)&instr;
1990 2004          int flags = inp->in_data.in_def.in_flags;
1991 2005  
1992 2006          flags |= FLG_NOIMM;
1993 2007  
1994      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     2008 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1995 2009                  prt_field("op", f->f3.op, 2);
1996 2010                  prt_field("op3", f->f3.op3, 6);
1997 2011                  prt_field("opf", f->fcmp.opf, 9);
1998 2012                  prt_field("rs1", f->f3.rs1, 5);
1999 2013                  prt_field("rs2", f->f3.rs2, 5);
2000 2014                  prt_field("rd", f->f3.rd, 5);
2001 2015          }
2002 2016  
2003 2017          prt_name(dhp, inp->in_data.in_def.in_name, 1);
2004 2018          prt_aluargs(dhp, instr, flags);
↓ open down ↓ 7 lines elided ↑ open up ↑
2012 2026          static const char *condstr_icc[16] = {
2013 2027                  "n", "e",  "le", "l",  "leu", "lu",  "neg", "vs",
2014 2028                  "a", "nz", "g",  "ge", "gu",  "geu", "pos", "vc"
2015 2029          };
2016 2030  
2017 2031          static const char *condstr_fcc[16] = {
2018 2032                  "n", "nz", "lg", "ul", "l",   "ug", "g",   "u",
2019 2033                  "a", "e",  "ue", "ge", "uge", "le", "ule", "o"
2020 2034          };
2021 2035  
     2036 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2022 2037          ifmt_t *f = (ifmt_t *)&instr;
2023 2038          const char *ccstr = "";
2024 2039          char name[15];
2025 2040  
2026 2041          int flags = inp->in_data.in_def.in_flags;
2027 2042          int is_cmp = (idx == 0x51 || idx == 0x52 || idx == 0x53 ||
2028 2043              idx == 0x55 || idx == 0x56 || idx == 0x57);
2029 2044          int is_fmov = (idx & 0x3f);
2030 2045          int is_v9 = ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0);
2031      -        int is_compat = ((dhp->dh_debug & DIS_DEBUG_COMPAT) != 0);
     2046 +        int is_compat = ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0);
2032 2047  
2033 2048          int p_cc = 0;
2034 2049  
2035 2050          is_fmov = (is_fmov == 0x1 || is_fmov == 0x2 || is_fmov == 0x3);
2036 2051  
2037      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     2052 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
2038 2053                  prt_field("op", f->f3.op, 2);
2039 2054                  prt_field("op3", f->f3.op3, 6);
2040 2055                  prt_field("opf", f->fcmp.opf, 9);
2041 2056  
2042 2057                  switch (idx & 0x3f) {
2043 2058                  case 0x51:
2044 2059                  case 0x52:
2045 2060                  case 0x53:
2046 2061                  case 0x55:
2047 2062                  case 0x56:
↓ open down ↓ 49 lines elided ↑ open up ↑
2097 2112                  bprintf(dhp, "%s, ", ccstr);
2098 2113  
2099 2114          prt_aluargs(dhp, instr, flags);
2100 2115  
2101 2116          return (0);
2102 2117  }
2103 2118  
2104 2119  int
2105 2120  fmt_vis(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
2106 2121  {
     2122 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2107 2123          ifmt_t *f = (ifmt_t *)&instr;
2108 2124          int flags = inp->in_data.in_def.in_flags;
2109 2125  
2110      -        if ((dhp->dh_debug & DIS_DEBUG_PRTFMT) != 0) {
     2126 +        if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
2111 2127                  prt_field("op", f->f3.op, 2);
2112 2128                  prt_field("op3", f->f3.op3, 6);
2113 2129                  prt_field("opf", f->fcmp.opf, 9);
2114 2130  
2115 2131                  if (idx == 0x081) {
2116 2132                          prt_field("mode", instr & 02L, 2);
2117 2133                  } else {
2118 2134                          prt_field("rs1", f->f3.rs1, 5);
2119 2135                          prt_field("rs2", f->f3.rs2, 5);
2120 2136                          prt_field("rd", f->f3.rd, 5);
↓ open down ↓ 123 lines elided ↑ open up ↑
2244 2260   * such as integer, floating point, etc.
2245 2261   * idx is the numeric value of the register
2246 2262   *
2247 2263   * If regset is REG_NONE, an empty, but non-NULL string is returned
2248 2264   * NULL may be returned if the index indicates an invalid register value
2249 2265   * such as with the %icc/%xcc sets
2250 2266   */
2251 2267  static const char *
2252 2268  get_regname(dis_handle_t *dhp, int regset, uint32_t idx)
2253 2269  {
     2270 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2254 2271          const char *regname = NULL;
2255 2272  
2256 2273          switch (regset) {
2257 2274          case REG_INT:
2258 2275                  regname = reg_names[idx];
2259 2276                  break;
2260 2277  
2261 2278          case REG_FP:
2262 2279                  regname = freg_names[idx];
2263 2280                  break;
2264 2281  
2265 2282          case REG_FPD:
2266      -                if (((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0) ||
     2283 +                if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0) ||
2267 2284                      ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0))
2268 2285                          regname = fdreg_names[idx];
2269 2286                  else
2270 2287                          regname = compat_fdreg_names[idx];
2271 2288  
2272 2289                  break;
2273 2290  
2274 2291          case REG_FPQ:
2275      -                if ((dhp->dh_debug & DIS_DEBUG_COMPAT) == 0)
     2292 +                if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
2276 2293                          regname = fqreg_names[idx];
2277 2294                  else
2278 2295                          regname = freg_names[idx];
2279 2296  
2280 2297                  break;
2281 2298  
2282 2299          case REG_CP:
2283 2300                  regname = cpreg_names[idx];
2284 2301                  break;
2285 2302  
↓ open down ↓ 57 lines elided ↑ open up ↑
2343 2360   * %g0 or 0x0 appears in the address
2344 2361   *
2345 2362   * If DIS_DEBUG_SYN_ALL or DIS_DEBUG_COMPAT are set, when %g0 or 0x0
2346 2363   * appear in the address, they are not output.  If the wierd (and probably
2347 2364   * shouldn't happen) address of [%g0 + %g0] or [%g0 + 0x0] is encountered,
2348 2365   * [%g0] is output
2349 2366   */
2350 2367  static void
2351 2368  prt_address(dis_handle_t *dhp, uint32_t instr, int nobrackets)
2352 2369  {
     2370 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2353 2371          ifmt_t *f = (ifmt_t *)&instr;
2354 2372          int32_t simm13;
2355 2373          int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
2356      -        int p1 = ((dhp->dh_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0);
2357      -        int p2 = ((dhp->dh_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0);
     2374 +        int p1 = ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0);
     2375 +        int p2 = ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0);
2358 2376  
2359 2377          if (f->f3a.i == 0) {
2360 2378                  p1 |= ((f->f3a.rs1 != 0) || f->f3.rs2 == 0);
2361 2379                  p2 |= (f->f3.rs2 != 0);
2362 2380  
2363 2381                  bprintf(dhp, "%s%s%s%s%s",
2364 2382                      (nobrackets == 0) ? "[" : "",
2365 2383                      (p1 != 0) ? reg_names[f->f3a.rs1] : "",
2366 2384                      (p1 != 0 && p2 != 0) ? " + " : "",
2367 2385                      (p2 != 0) ? reg_names[f->f3.rs2] : "",
↓ open down ↓ 46 lines elided ↑ open up ↑
2414 2432   * flags indicates the register set to use for each position (p1, p2, p3)
2415 2433   * as well as if immediate values (i == 1) are allowed
2416 2434   *
2417 2435   * if flags indicates a specific position has REG_NONE set as it's register
2418 2436   * set, it is omitted from the output.  This is primarly used for certain
2419 2437   * floating point operations
2420 2438   */
2421 2439  static void
2422 2440  prt_aluargs(dis_handle_t *dhp, uint32_t instr, uint32_t flags)
2423 2441  {
     2442 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2424 2443          ifmt_t *f = (ifmt_t *)&instr;
2425 2444          const char *r1, *r2, *r3;
2426 2445          int p1, p2, p3;
2427 2446          unsigned int opf = 0;
2428 2447  
2429 2448          r1 = get_regname(dhp, FLG_P1_VAL(flags), f->f3.rs1);
2430 2449          r2 = get_regname(dhp, FLG_P2_VAL(flags), f->f3.rs2);
2431 2450          r3 = get_regname(dhp, FLG_P3_VAL(flags), f->f3.rd);
2432 2451  
2433 2452          p1 = (FLG_P1_VAL(flags) != REG_NONE);
↓ open down ↓ 6 lines elided ↑ open up ↑
2440 2459          if (f->f3a.i == 0 && (r2 == NULL || r2[0] == '\0'))
2441 2460                  p2 = 0;
2442 2461  
2443 2462          if (r3 == NULL || r3[0] == '\0')
2444 2463                  p3 = 0;
2445 2464  
2446 2465          if ((f->fcmp.op == 2) && (f->fcmp.op3 == 0x36) && (f->fcmp.cc != 0))
2447 2466                  opf = f->fcmp.opf;
2448 2467  
2449 2468          if ((opf == 0x151) || (opf == 0x152)) {
2450      -                (void) strlcat(dhp->dh_buf, r3, dhp->dh_buflen);
2451      -                (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     2469 +                (void) strlcat(dhx->dhx_buf, r3, dhx->dhx_buflen);
     2470 +                (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
2452 2471                  p3 = 0;
2453 2472          }
2454 2473  
2455 2474          if (p1 != 0) {
2456      -                (void) strlcat(dhp->dh_buf, r1, dhp->dh_buflen);
     2475 +                (void) strlcat(dhx->dhx_buf, r1, dhx->dhx_buflen);
2457 2476                  if (p2 != 0 || p3 != 0)
2458      -                        (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     2477 +                        (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
2459 2478          }
2460 2479  
2461 2480          if (p2 != 0) {
2462 2481                  if (f->f3.i == 0 || ((flags & FLG_NOIMM) != 0))
2463      -                        (void) strlcat(dhp->dh_buf, r2, dhp->dh_buflen);
     2482 +                        (void) strlcat(dhx->dhx_buf, r2, dhx->dhx_buflen);
2464 2483                  else
2465 2484                          prt_imm(dhp, sign_extend(f->f3a.simm13, 13),
2466 2485                              IMM_SIGNED);
2467 2486  
2468 2487                  if (p3 != 0)
2469      -                        (void) strlcat(dhp->dh_buf, ", ", dhp->dh_buflen);
     2488 +                        (void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
2470 2489          }
2471 2490  
2472 2491          if (p3 != 0)
2473      -                (void) strlcat(dhp->dh_buf, r3, dhp->dh_buflen);
     2492 +                (void) strlcat(dhx->dhx_buf, r3, dhx->dhx_buflen);
2474 2493  }
2475 2494  
2476 2495  static const char *
2477 2496  get_asi_name(uint8_t asi)
2478 2497  {
2479 2498          switch (asi) {
2480 2499                  case 0x04:
2481 2500                          return ("ASI_N");
2482 2501  
2483 2502                  case 0x0c:
↓ open down ↓ 251 lines elided ↑ open up ↑
2735 2754   * just a handy function that takes care of managing the buffer length
2736 2755   * w/ printf
2737 2756   */
2738 2757  
2739 2758  /*
2740 2759   * PRINTF LIKE 1
2741 2760   */
2742 2761  static void
2743 2762  bprintf(dis_handle_t *dhp, const char *fmt, ...)
2744 2763  {
     2764 +        dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2745 2765          size_t curlen;
2746 2766          va_list ap;
2747 2767  
2748      -        curlen = strlen(dhp->dh_buf);
     2768 +        curlen = strlen(dhx->dhx_buf);
2749 2769  
2750 2770          va_start(ap, fmt);
2751      -        (void) vsnprintf(dhp->dh_buf + curlen, dhp->dh_buflen - curlen, fmt,
     2771 +        (void) vsnprintf(dhx->dhx_buf + curlen, dhx->dhx_buflen - curlen, fmt,
2752 2772              ap);
2753 2773          va_end(ap);
2754 2774  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX