simple.cpp

Go to the documentation of this file.
00001 #define sign_extend(N,SIZE) (((int)((N) << (sizeof(unsigned)*8-(SIZE)))) >> (sizeof(unsigned)*8-(SIZE)))
00002 #include <assert.h>
00003 
00004 #line 2 "machine/hppa/simple.m"
00005 #include "global.h"
00006 #include "decoder.h"
00007 
00008 extern char _assembly[];
00009 char* astr;
00010 
00011 DWord getDword (unsigned lc)
00012 /* get4Bytes - returns next 4-Byte from image pointed to by lc.
00013    Fetch in a big-endian manner  */
00014 {
00015     return
00016       (DWord)
00017       ((((((
00018           *(Byte *)lc << 8
00019       ) + *(Byte *)(lc+1)) << 8
00020       ) + *(Byte *)(lc+2)) << 8
00021       ) + *(Byte *)(lc+3));
00022 }
00023 
00024 
00025 void NJMCDecoder::dis_faddr(ADDRESS faddr)
00026 {
00027 
00028 
00029 #line 23 "machine/hppa/simple.m"
00030 { 
00031   dword MATCH_p = 
00032     
00033     #line 23 "machine/hppa/simple.m"
00034     faddr
00035     ;
00036   unsigned MATCH_w_32_0;
00037   { 
00038     MATCH_w_32_0 = getDword(MATCH_p); 
00039     if ((MATCH_w_32_0 >> 9 & 0x1) /* addr_22 at 0 */ == 1) { 
00040       unsigned b = (MATCH_w_32_0 >> 21 & 0x1f) /* b_06 at 0 */;
00041       unsigned d = 
00042         (sign_extend((MATCH_w_32_0 >> 16 & 0x1) /* im1_15 at 0 */, 1) << 4) + 
00043         (MATCH_w_32_0 >> 17 & 0xf) /* im4_11 at 0 */;
00044       unsigned s = (MATCH_w_32_0 >> 14 & 0x3) /* s2_16 at 0 */;
00045       
00046       #line 29 "machine/hppa/simple.m"
00047        {
00048 
00049                   astr += sprintf(astr, " %d(sr%d,r%d)", d, s, b);
00050 
00051                   strcat(constrName, "sdisps_faddr ");
00052 
00053               }
00054 
00055       
00056       
00057       
00058     } /*opt-block*//*opt-block+*/
00059     else { 
00060       unsigned b = (MATCH_w_32_0 >> 21 & 0x1f) /* b_06 at 0 */;
00061       unsigned s = (MATCH_w_32_0 >> 14 & 0x3) /* s2_16 at 0 */;
00062       unsigned x = (MATCH_w_32_0 >> 16 & 0x1f) /* x_11 at 0 */;
00063       
00064       #line 25 "machine/hppa/simple.m"
00065        {
00066 
00067                   astr += sprintf(astr, " r%d(sr%d,r%d)", x, s, b);
00068 
00069                   strcat(constrName, "index_faddr ");
00070 
00071               }
00072 
00073       
00074       
00075       
00076     } /*opt-block*//*opt-block+*/
00077     
00078   }goto MATCH_finished_d; 
00079   
00080   MATCH_finished_d: (void)0; /*placeholder for label*/
00081   
00082 }
00083 
00084 #line 34 "machine/hppa/simple.m"
00085 }
00086 
00087 void NJMCDecoder::dis_c_faddr(ADDRESS c_faddr)
00088 {
00089 
00090 
00091 #line 37 "machine/hppa/simple.m"
00092 { 
00093   dword MATCH_p = 
00094     
00095     #line 37 "machine/hppa/simple.m"
00096     c_faddr
00097     ;
00098   unsigned MATCH_w_32_0;
00099   { 
00100     MATCH_w_32_0 = getDword(MATCH_p); 
00101     if ((MATCH_w_32_0 >> 12 & 0x1) /* addr_19 at 0 */ == 1) 
00102       if ((MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 1) 
00103         if ((MATCH_w_32_0 >> 13 & 0x1) /* a_18 at 0 */ == 1) 
00104           assert(0);  /* no match */ /*opt-block+*/
00105         else 
00106           
00107           #line 57 "machine/hppa/simple.m"
00108            {
00109 
00110                       astr += sprintf(astr, ",ma");
00111 
00112                       strcat(constrName, "ins_faddr_ma ");
00113 
00114                   }
00115 
00116           
00117            /*opt-block+*/ /*opt-block+*/
00118       else 
00119         if ((MATCH_w_32_0 >> 13 & 0x1) /* a_18 at 0 */ == 1) 
00120           
00121           #line 53 "machine/hppa/simple.m"
00122            {
00123 
00124                       astr += sprintf(astr, ",mb");
00125 
00126                       strcat(constrName, "ins_faddr_mb ");
00127 
00128                   }
00129 
00130           
00131            /*opt-block+*/
00132         else 
00133           
00134           #line 61 "machine/hppa/simple.m"
00135            {
00136 
00137                       strcat(constrName, "ins_faddr_si ");
00138 
00139                   }
00140 
00141           
00142            /*opt-block+*/ /*opt-block+*/ 
00143     else 
00144       if ((MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 1) 
00145         if ((MATCH_w_32_0 >> 13 & 0x1) /* u_18 at 0 */ == 1) 
00146           
00147           #line 47 "machine/hppa/simple.m"
00148            {
00149 
00150                       astr += sprintf(astr, ",sm");
00151 
00152                       strcat(constrName, "ins_faddr_sm ");
00153 
00154                   }
00155 
00156           
00157            /*opt-block+*/
00158         else 
00159           
00160           #line 43 "machine/hppa/simple.m"
00161            {
00162 
00163                       astr += sprintf(astr, ",m");
00164 
00165                       strcat(constrName, "ins_faddr_m ");
00166 
00167                   }
00168 
00169           
00170            /*opt-block+*/ /*opt-block+*/
00171       else 
00172         if ((MATCH_w_32_0 >> 13 & 0x1) /* u_18 at 0 */ == 1) 
00173           
00174           #line 39 "machine/hppa/simple.m"
00175            {
00176 
00177                       astr += sprintf(astr, ",s");
00178 
00179                       strcat(constrName, "ins_faddr_s ");
00180 
00181                   }
00182 
00183           
00184            /*opt-block+*/
00185         else 
00186           
00187           #line 50 "machine/hppa/simple.m"
00188           
00189 
00190                       strcat(constrName, "ins_faddr_x ");
00191 
00192           
00193            /*opt-block+*/ /*opt-block+*/ 
00194     
00195   }goto MATCH_finished_c; 
00196   
00197   MATCH_finished_c: (void)0; /*placeholder for label*/
00198   
00199 }
00200 
00201 #line 65 "machine/hppa/simple.m"
00202 }
00203 
00204 void NJMCDecoder::dis_flt_fmt(int fmt)
00205 {
00206     // Completer for floating point operand size
00207     switch(fmt) {
00208         case 0: astr += sprintf(astr, ",sgl"); break;
00209         case 1: astr += sprintf(astr, ",dbl"); break;
00210         case 3: astr += sprintf(astr, ",quad"); break;
00211         default:astr += sprintf(astr, ",?"); break;
00212     }
00213 }
00214 
00215 void dis_flt_c3(int& d_fmt, int& d_r1, int& d_r2, int& d_t, ADDRESS con)
00216 {
00217 
00218 
00219 #line 79 "machine/hppa/simple.m"
00220 { 
00221   dword MATCH_p = 
00222     
00223     #line 79 "machine/hppa/simple.m"
00224     con
00225     ;
00226   char *MATCH_name;
00227   unsigned MATCH_w_32_0;
00228   { 
00229     MATCH_w_32_0 = getDword(MATCH_p); 
00230     if (0 <= (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ && 
00231       (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ < 12 || 
00232       13 <= (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ && 
00233       (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ < 64 || 
00234       (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ == 12 && 
00235       (0 <= (MATCH_w_32_0 >> 9 & 0x3) /* class_21 at 0 */ && 
00236       (MATCH_w_32_0 >> 9 & 0x3) /* class_21 at 0 */ < 3) || 
00237       (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ == 12 && 
00238       (MATCH_w_32_0 >> 9 & 0x3) /* class_21 at 0 */ == 3 && 
00239       (4 <= (MATCH_w_32_0 >> 13 & 0x7) /* sub_16 at 0 */ && 
00240       (MATCH_w_32_0 >> 13 & 0x7) /* sub_16 at 0 */ < 8)) 
00241       goto MATCH_label_b0;  /*opt-block+*/
00242     else { 
00243       MATCH_name = "flt_c3.C"; 
00244       { 
00245         char *name = MATCH_name;
00246         unsigned fmt = (MATCH_w_32_0 >> 11 & 0x3) /* fmt_19 at 0 */;
00247         unsigned r1 = (MATCH_w_32_0 >> 21 & 0x1f) /* r_06 at 0 */;
00248         unsigned r2 = (MATCH_w_32_0 >> 16 & 0x1f) /* r_11 at 0 */;
00249         unsigned t = (MATCH_w_32_0 & 0x1f) /* t_27 at 0 */;
00250         
00251         #line 81 "machine/hppa/simple.m"
00252         
00253 
00254                     d_fmt = fmt; d_r1 = r1; d_r2 = r2; d_t = t;
00255 
00256         printf("Name of typed constructor is %s\n", name);
00257 
00258         
00259         
00260         
00261       }
00262       
00263     } /*opt-block*/
00264     
00265   }goto MATCH_finished_b; 
00266   
00267   MATCH_label_b0: (void)0; /*placeholder for label*/ 
00268     
00269     #line 87 "machine/hppa/simple.m"
00270     
00271                 printf("This should never happen\n");
00272 
00273                 assert(0);
00274 
00275     
00276      
00277     goto MATCH_finished_b; 
00278     
00279   MATCH_finished_b: (void)0; /*placeholder for label*/
00280   
00281 }
00282 
00283 #line 91 "machine/hppa/simple.m"
00284 }
00285 
00286 int NJMCDecoder::decodeAssemblyInstruction (ADDRESS pc, int delta)
00287 {
00288     char sCmplt[32];
00289     unsigned long r1,r2;
00290     sCmplt[0]='\0';
00291     ADDRESS hostPC = pc + delta;
00292 
00293     astr = _assembly + sprintf(_assembly, "%x: %08x  ", pc, *(unsigned*)hostPC);
00294 
00295 
00296 
00297 #line 101 "machine/hppa/simple.m"
00298 { 
00299   dword MATCH_p = 
00300     
00301     #line 101 "machine/hppa/simple.m"
00302     hostPC
00303     ;
00304   char *MATCH_name;
00305   unsigned MATCH_w_32_0;
00306   { 
00307     MATCH_w_32_0 = getDword(MATCH_p); 
00308     if (13 <= (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ && 
00309       (MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */ < 64) 
00310       goto MATCH_label_a0;  /*opt-block+*/
00311     else 
00312       switch((MATCH_w_32_0 >> 26 & 0x3f) /* op at 0 */) {
00313         case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: 
00314         case 8: case 10: 
00315           goto MATCH_label_a0; break;
00316         case 9: 
00317           if (0 <= (MATCH_w_32_0 >> 7 & 0x3) /* uid_23 at 0 */ && 
00318             (MATCH_w_32_0 >> 7 & 0x3) /* uid_23 at 0 */ < 2) 
00319             if ((MATCH_w_32_0 >> 9 & 0x1) /* addr_22 at 0 */ == 1) 
00320               if ((MATCH_w_32_0 >> 12 & 0x1) /* addr_19 at 0 */ == 1) 
00321                 if ((MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 0 || 
00322                   (MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 1 && 
00323                   (MATCH_w_32_0 >> 13 & 0x1) /* a_18 at 0 */ == 0) { 
00324                   MATCH_name = "fstws"; 
00325                   goto MATCH_label_a2; 
00326                   
00327                 } /*opt-block*/
00328                 else 
00329                   goto MATCH_label_a0;  /*opt-block+*/ /*opt-block+*/
00330               else { 
00331                 MATCH_name = "fstwx"; 
00332                 goto MATCH_label_a2; 
00333                 
00334               } /*opt-block*/ 
00335             else 
00336               if ((MATCH_w_32_0 >> 12 & 0x1) /* addr_19 at 0 */ == 1) 
00337                 if ((MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 0 || 
00338                   (MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 1 && 
00339                   (MATCH_w_32_0 >> 13 & 0x1) /* a_18 at 0 */ == 0) { 
00340                   MATCH_name = "fldws"; 
00341                   goto MATCH_label_a1; 
00342                   
00343                 } /*opt-block*/
00344                 else 
00345                   goto MATCH_label_a0;  /*opt-block+*/ /*opt-block+*/
00346               else { 
00347                 MATCH_name = "fldwx"; 
00348                 goto MATCH_label_a1; 
00349                 
00350               } /*opt-block*/  
00351           else 
00352             goto MATCH_label_a0;  /*opt-block+*/
00353           break;
00354         case 11: 
00355           if (0 <= (MATCH_w_32_0 >> 7 & 0x3) /* uid_23 at 0 */ && 
00356             (MATCH_w_32_0 >> 7 & 0x3) /* uid_23 at 0 */ < 2) 
00357             if ((MATCH_w_32_0 >> 9 & 0x1) /* addr_22 at 0 */ == 1) 
00358               if ((MATCH_w_32_0 >> 12 & 0x1) /* addr_19 at 0 */ == 1) 
00359                 if ((MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 0 || 
00360                   (MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 1 && 
00361                   (MATCH_w_32_0 >> 13 & 0x1) /* a_18 at 0 */ == 0) { 
00362                   MATCH_name = "fstds"; 
00363                   goto MATCH_label_a2; 
00364                   
00365                 } /*opt-block*/
00366                 else 
00367                   goto MATCH_label_a0;  /*opt-block+*/ /*opt-block+*/
00368               else { 
00369                 MATCH_name = "fstdx"; 
00370                 goto MATCH_label_a2; 
00371                 
00372               } /*opt-block*/ 
00373             else 
00374               if ((MATCH_w_32_0 >> 12 & 0x1) /* addr_19 at 0 */ == 1) 
00375                 if ((MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 0 || 
00376                   (MATCH_w_32_0 >> 5 & 0x1) /* m_26 at 0 */ == 1 && 
00377                   (MATCH_w_32_0 >> 13 & 0x1) /* a_18 at 0 */ == 0) { 
00378                   MATCH_name = "fldds"; 
00379                   goto MATCH_label_a1; 
00380                   
00381                 } /*opt-block*/
00382                 else 
00383                   goto MATCH_label_a0;  /*opt-block+*/ /*opt-block+*/
00384               else { 
00385                 MATCH_name = "flddx"; 
00386                 goto MATCH_label_a1; 
00387                 
00388               } /*opt-block*/  
00389           else 
00390             goto MATCH_label_a0;  /*opt-block+*/
00391           break;
00392         case 12: 
00393           if (0 <= (MATCH_w_32_0 >> 9 & 0x3) /* class_21 at 0 */ && 
00394             (MATCH_w_32_0 >> 9 & 0x3) /* class_21 at 0 */ < 3 || 
00395             (MATCH_w_32_0 >> 9 & 0x3) /* class_21 at 0 */ == 3 && 
00396             (4 <= (MATCH_w_32_0 >> 13 & 0x7) /* sub_16 at 0 */ && 
00397             (MATCH_w_32_0 >> 13 & 0x7) /* sub_16 at 0 */ < 8)) 
00398             goto MATCH_label_a0;  /*opt-block+*/
00399           else { 
00400             MATCH_name = "flt_c3"; 
00401             { 
00402               char *name = MATCH_name;
00403               unsigned con = addressToPC(MATCH_p);
00404               
00405               #line 119 "machine/hppa/simple.m"
00406                {
00407 
00408                           int fmt, r1, r2, t;
00409 
00410                           dis_flt_c3(fmt, r1, r2, t, con);
00411 
00412                           astr += sprintf(astr, "%s", name);
00413 
00414                           dis_flt_fmt(fmt);
00415 
00416                           astr += sprintf(astr, "  fr%d, fr%d, fr%d", r1, r2, t);
00417 
00418                           strcat(constrName, "flt_c3 ");
00419 
00420                       }
00421 
00422               
00423               
00424               
00425             }
00426             
00427           } /*opt-block*/
00428           
00429           break;
00430         default: assert(0);
00431       } /* (MATCH_w_32_0 >> 26 & 0x3f) -- op at 0 --*/ 
00432     
00433   }goto MATCH_finished_a; 
00434   
00435   MATCH_label_a0: (void)0; /*placeholder for label*/ 
00436     
00437     #line 127 "machine/hppa/simple.m"
00438     
00439                 // Do nothing
00440 
00441                 sprintf(astr, ".");
00442 
00443     
00444 
00445     
00446      
00447     goto MATCH_finished_a; 
00448     
00449   MATCH_label_a1: (void)0; /*placeholder for label*/ 
00450     { 
00451       char *name = MATCH_name;
00452       unsigned c_faddr = addressToPC(MATCH_p);
00453       unsigned faddr = addressToPC(MATCH_p);
00454       unsigned t_27 = (MATCH_w_32_0 & 0x1f) /* t_27 at 0 */;
00455       
00456       #line 103 "machine/hppa/simple.m"
00457        {
00458 
00459       // Floating point loads and stores
00460 
00461                   astr += sprintf(astr, "%s  ", name);
00462 
00463                   dis_c_faddr(c_faddr);
00464 
00465                   dis_faddr(faddr);
00466 
00467                   astr += sprintf(astr, ",fr%d", t_27);
00468 
00469                   strcat(constrName, "floads ");
00470 
00471               }
00472 
00473       
00474       
00475       
00476     } 
00477     goto MATCH_finished_a; 
00478     
00479   MATCH_label_a2: (void)0; /*placeholder for label*/ 
00480     { 
00481       char *name = MATCH_name;
00482       unsigned c_faddr = addressToPC(MATCH_p);
00483       unsigned faddr = addressToPC(MATCH_p);
00484       unsigned r = (MATCH_w_32_0 & 0x1f) /* t_27 at 0 */;
00485       
00486       #line 111 "machine/hppa/simple.m"
00487        {
00488 
00489                   astr += sprintf(astr, "%s", name);
00490 
00491                   dis_c_faddr(c_faddr);
00492 
00493                   astr += sprintf(astr, "  fr%d,", r);
00494 
00495                   dis_faddr(faddr);
00496 
00497                   strcat(constrName, "fstores ");
00498 
00499               }
00500 
00501       
00502 
00503       
00504       
00505       
00506     } 
00507     goto MATCH_finished_a; 
00508     
00509   MATCH_finished_a: (void)0; /*placeholder for label*/
00510   
00511 }
00512 
00513 #line 132 "machine/hppa/simple.m"
00514 
00515     return 4;
00516 }
00517 
00518 

Generated on Tue Sep 19 21:18:31 2006 for Boomerang by  doxygen 1.4.6