simple.m

Go to the documentation of this file.
00001 #include "global.h"
00002 #include "decoder.h"
00003 
00004 extern char _assembly;
00005 char* astr;
00006 
00007 DWord getDword (unsigned lc)
00008 /* get4Bytes - returns next 4-Byte from image pointed to by lc.
00009    Fetch in a big-endian manner  */
00010 {
00011     return
00012       (DWord)
00013       ((((((
00014           *(Byte *)lc << 8
00015       ) + *(Byte *)(lc+1)) << 8
00016       ) + *(Byte *)(lc+2)) << 8
00017       ) + *(Byte *)(lc+3));
00018 }
00019 
00020 
00021 void NJMCDecoder::dis_faddr(ADDRESS faddr)
00022 {
00023     match faddr to
00024         | index_faddr (x, s, b) => {
00025             astr += sprintf(astr, " r%d(sr%d,r%d)", x, s, b);
00026             strcat(constrName, "index_faddr ");
00027         }
00028         | sdisps_faddr(d, s, b) => {
00029             astr += sprintf(astr, " %d(sr%d,r%d)", d, s, b);
00030             strcat(constrName, "sdisps_faddr ");
00031         }
00032     endmatch
00033 }
00034 
00035 void NJMCDecoder::dis_c_faddr(ADDRESS c_faddr)
00036 {
00037     match c_faddr to
00038         | ins_faddr_s  => {
00039             astr += sprintf(astr, ",s");
00040             strcat(constrName, "ins_faddr_s ");
00041         }
00042         | ins_faddr_m  => {
00043             astr += sprintf(astr, ",m");
00044             strcat(constrName, "ins_faddr_m ");
00045         }
00046         | ins_faddr_sm => {
00047             astr += sprintf(astr, ",sm");
00048             strcat(constrName, "ins_faddr_sm ");
00049         }
00050         | ins_faddr_x =>
00051             strcat(constrName, "ins_faddr_x ");
00052         | ins_faddr_mb => {
00053             astr += sprintf(astr, ",mb");
00054             strcat(constrName, "ins_faddr_mb ");
00055         }
00056         | ins_faddr_ma => {
00057             astr += sprintf(astr, ",ma");
00058             strcat(constrName, "ins_faddr_ma ");
00059         }
00060         | ins_faddr_si => {
00061             strcat(constrName, "ins_faddr_si ");
00062         }
00063     endmatch
00064 }
00065 
00066 void NJMCDecoder::dis_flt_fmt(int fmt)
00067 {
00068     // Completer for floating point operand size
00069     switch(fmt) {
00070         case 0: astr += sprintf(astr, ",sgl"); break;
00071         case 1: astr += sprintf(astr, ",dbl"); break;
00072         case 3: astr += sprintf(astr, ",quad"); break;
00073         default:astr += sprintf(astr, ",?"); break;
00074     }
00075 }
00076 
00077 void dis_flt_c3(int& d_fmt, int& d_r1, int& d_r2, int& d_t, ADDRESS con)
00078 {
00079     match con to
00080         | flt_c3.C(fmt, r1, r2, t) =>
00081             d_fmt = fmt; d_r1 = r1; d_r2 = r2; d_t = t;
00082 printf("Name of typed constructor is %s\n", name);
00083         | flt_c3.E(fmt, r1, r2, t) =>
00084             d_fmt = fmt; d_r1 = r1; d_r2 = r2; d_t = t;
00085 printf("Name of typed constructor is %s\n", name);
00086         else
00087             printf("This should never happen\n");
00088             assert(0);
00089     endmatch
00090 }
00091 
00092 int NJMCDecoder::decodeAssemblyInstruction (ADDRESS pc, int delta)
00093 {
00094     char sCmplt;
00095     unsigned long r1,r2;
00096     sCmplt='\0';
00097     ADDRESS hostPC = pc + delta;
00098 
00099     astr = _assembly + sprintf(_assembly, "%x: %08x  ", pc, *(unsigned*)hostPC);
00100 
00101     match hostPC to
00102         | floads(c_faddr, faddr, t_27) => {
00103 // Floating point loads and stores
00104             astr += sprintf(astr, "%s  ", name);
00105             dis_c_faddr(c_faddr);
00106             dis_faddr(faddr);
00107             astr += sprintf(astr, ",fr%d", t_27);
00108             strcat(constrName, "floads ");
00109         }
00110         | fstores(c_faddr, r, faddr) => {
00111             astr += sprintf(astr, "%s", name);
00112             dis_c_faddr(c_faddr);
00113             astr += sprintf(astr, "  fr%d,", r);
00114             dis_faddr(faddr);
00115             strcat(constrName, "fstores ");
00116         }
00117 
00118         | flt_c3(con) => {
00119             int fmt, r1, r2, t;
00120             dis_flt_c3(fmt, r1, r2, t, con);
00121             astr += sprintf(astr, "%s", name);
00122             dis_flt_fmt(fmt);
00123             astr += sprintf(astr, "  fr%d, fr%d, fr%d", r1, r2, t);
00124             strcat(constrName, "flt_c3 ");
00125         }
00126         else
00127             // Do nothing
00128             sprintf(astr, ".");
00129 
00130     endmatch
00131 
00132     return 4;
00133 }

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