dyn_regs.C

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 #define DYN_DEFINE_REGS
00032 #include "dynutil/h/dyn_regs.h"
00033 
00034 #include "external/rose/rose-compat.h"
00035 #include "external/rose/powerpcInstructionEnum.h"
00036 
00037 #include <iostream>
00038 
00039 using namespace Dyninst;
00040 
00041 boost::shared_ptr<MachRegister::NameMap> MachRegister::names()
00042 {
00043     static boost::shared_ptr<MachRegister::NameMap> store = 
00044        boost::shared_ptr<MachRegister::NameMap>(new MachRegister::NameMap);
00045     return store;
00046 }
00047 
00048 MachRegister::MachRegister() :
00049    reg(0)
00050 { 
00051 }
00052 
00053 MachRegister::MachRegister(signed int r) :
00054    reg(r)
00055 {
00056 }
00057  
00058 MachRegister::MachRegister(signed int r, const char *n) :
00059    reg(r)
00060 {
00061     (*names())[r] = std::string(n);
00062 }
00063 
00064 MachRegister::MachRegister(signed int r, std::string n) :
00065 reg(r)
00066 {
00067     (*names())[r] = n;
00068 }
00069 
00070 unsigned int MachRegister::regClass() const
00071 {
00072     return reg & 0x00ff0000;
00073 }
00074 
00075 MachRegister MachRegister::getBaseRegister() const { 
00076    switch (getArchitecture()) {
00077       case Arch_x86:
00078          if (reg & x86::GPR) return MachRegister(reg & 0xfffff0ff);
00079          else return *this;
00080       case Arch_x86_64:
00081          if (reg & x86_64::GPR) return MachRegister(reg & 0xfffff0ff);
00082          else return *this;
00083       case Arch_ppc32:
00084       case Arch_ppc64:
00085       case Arch_none:
00086          return *this;
00087    }
00088    return InvalidReg;
00089 }
00090    
00091 Architecture MachRegister::getArchitecture() const { 
00092    return (Architecture) (reg & 0xff000000);
00093 }
00094 
00095 bool MachRegister::isValid() const {
00096    return (reg != InvalidReg.reg);
00097 }
00098 
00099 MachRegisterVal MachRegister::getSubRegValue(const MachRegister& subreg, 
00100                                              MachRegisterVal &orig) const
00101 {
00102    if (subreg.reg == reg || 
00103        getArchitecture() == Arch_ppc32 ||
00104        getArchitecture() == Arch_ppc64)
00105       return orig;
00106 
00107    assert(subreg.getBaseRegister() == getBaseRegister());
00108    switch ((subreg.reg & 0x00000f00) >> 8) {
00109       case 0x0: return orig;
00110       case 0x1: return (orig & 0xff);
00111       case 0x2: return (orig & 0xff00) >> 8;              
00112       case 0x3: return (orig & 0xffff);
00113       case 0xf: return (orig & 0xffffffff);
00114       default: assert(0); return orig;
00115    }
00116 }
00117 
00118 std::string MachRegister::name() const { 
00119     assert(names() != NULL);
00120     NameMap::const_iterator iter = names()->find(reg);
00121     if (iter != names()->end()) {
00122         return iter->second;
00123     }
00124     return std::string("<INVALID_REG>");
00125 }
00126 
00127 unsigned int MachRegister::size() const {
00128    switch (getArchitecture())
00129    {
00130       case Arch_x86:
00131          switch (reg & 0x0000ff00) {
00132             case x86::L_REG: //L_REG
00133             case x86::H_REG: //H_REG
00134                return 1;
00135             case x86::W_REG: //W_REG
00136                return 2;
00137             case x86::FULL: //FULL
00138                return 4;
00139             case x86::QUAD:
00140                return 8;
00141             case x86::OCT:
00142                return 16;
00143             case x86::FPDBL:
00144                return 10;
00145             case x86::BIT:
00146                return 0;
00147             default:
00148                return 0;//KEVINTODO: removed sanity-check assert because of asprotect fuzz testing, could use this as a sign that the parse has gone into junk
00149                assert(0);
00150          }
00151       case Arch_x86_64:
00152          switch (reg & 0x0000ff00) {
00153             case x86_64::L_REG: //L_REG
00154             case x86_64::H_REG: //H_REG
00155                 return 1;
00156             case x86_64::W_REG: //W_REG
00157                 return 2;
00158             case x86_64::FULL: //FULL
00159                 return 8;
00160             case x86_64::D_REG:
00161                return 4;
00162             case x86_64::OCT:
00163                return 16;
00164             case x86_64::FPDBL:
00165                return 10;
00166             case x86_64::BIT:
00167                return 0;
00168             default:
00169                assert(0);
00170          }
00171       case Arch_ppc32: {
00172          int reg_class = reg & 0x00ff0000;
00173          if (reg_class == ppc32::FPR || reg_class == ppc32::FSR)
00174             return 8;
00175          return 4;
00176       }
00177       case Arch_ppc64:
00178          return 8;
00179       case Arch_none:
00180          return 0;
00181    }
00182    return 0; //Unreachable, but disable warnings
00183 }
00184    
00185 bool MachRegister::operator<(const MachRegister &a) const { 
00186    return (reg < a.reg);
00187 }
00188  
00189 bool MachRegister::operator==(const MachRegister &a) const { 
00190    return (reg == a.reg);
00191 }
00192  
00193 MachRegister::operator signed int() const {
00194    return reg;
00195 }
00196 
00197 signed int MachRegister::val() const {
00198    return reg;
00199 }
00200 
00201 
00202 MachRegister MachRegister::getPC(Dyninst::Architecture arch)
00203 {
00204    switch (arch)
00205    {
00206       case Arch_x86:
00207          return x86::eip;
00208       case Arch_x86_64:
00209          return x86_64::rip;
00210       case Arch_ppc32:
00211          return ppc32::pc;
00212       case Arch_ppc64:
00213          return ppc64::pc;
00214       case Arch_none:
00215          return InvalidReg;
00216    }
00217    return InvalidReg;
00218 }
00219 
00220 MachRegister MachRegister::getFramePointer(Dyninst::Architecture arch)
00221 {
00222    switch (arch)
00223    {
00224       case Arch_x86:
00225          return x86::ebp;
00226       case Arch_x86_64:
00227          return x86_64::rbp;
00228       case Arch_ppc32:
00229          return ppc32::r1;
00230       case Arch_ppc64:
00231          return ppc64::r1;
00232       case Arch_none:
00233          return InvalidReg;
00234    }
00235    return InvalidReg;
00236 }
00237 
00238 MachRegister MachRegister::getStackPointer(Dyninst::Architecture arch)
00239 {
00240    switch (arch)
00241    {
00242       case Arch_x86:
00243          return x86::esp;
00244       case Arch_x86_64:
00245          return x86_64::rsp;
00246       case Arch_ppc32:
00247          return ppc32::r1;
00248       case Arch_ppc64:
00249          return ppc64::r1;
00250       case Arch_none:
00251          return InvalidReg;
00252    }
00253    return InvalidReg;
00254 }
00255 
00256 bool MachRegister::isPC() const
00257 {
00258    return (*this == x86_64::rip || *this == x86::eip ||
00259            *this == ppc32::pc || *this == ppc64::pc);
00260 }
00261 
00262 bool MachRegister::isFramePointer() const
00263 {
00264    return (*this == x86_64::rbp || *this == x86::ebp ||
00265            *this == FrameBase);
00266 }
00267 
00268 bool MachRegister::isStackPointer() const
00269 {
00270    return (*this == x86_64::rsp || *this == x86::esp ||
00271            *this == ppc32::r1 || *this == ppc64::r1);
00272 }
00273 
00274 COMMON_EXPORT bool Dyninst::isSegmentRegister(int regClass)
00275 {
00276    return 0 != (regClass & x86::SEG);
00277 }
00278 
00279 void MachRegister::getROSERegister(int &c, int &n, int &p)
00280 {
00281    // Rose: class, number, position
00282    // Dyninst: category, base id, subrange
00283 
00284    signed int category = (reg & 0x00ff0000);
00285    signed int subrange = (reg & 0x0000ff00);
00286    signed int baseID =   (reg & 0x000000ff);
00287 
00288    switch (getArchitecture()) {
00289       case Arch_x86:
00290       case Arch_x86_64: // 64-bit not supported in ROSE
00291          switch (category) {
00292             case x86::GPR:
00293                c = x86_regclass_gpr;
00294                switch (baseID) {
00295                   case x86::BASEA:
00296                      n = x86_gpr_ax;
00297                      break;
00298                   case x86::BASEC:
00299                      n = x86_gpr_cx;
00300                      break;
00301                   case x86::BASED:
00302                      n = x86_gpr_dx;
00303                      break;
00304                   case x86::BASEB:
00305                      n = x86_gpr_bx;
00306                      break;
00307                   case x86::BASESP:
00308                      n = x86_gpr_sp;
00309                      break;
00310                   case x86::BASEBP:
00311                      n = x86_gpr_bp;
00312                      break;
00313                   case x86::BASESI:
00314                      n = x86_gpr_si;
00315                      break;
00316                   case x86::BASEDI:
00317                      n = x86_gpr_di;
00318                      break;
00319                   default:
00320                      n = 0;
00321                      break;
00322                }
00323                break;
00324             case x86::SEG:
00325                c = x86_regclass_segment;
00326                switch (baseID) {
00327                   case 0x0:
00328                      n = x86_segreg_ds;
00329                      break;
00330                   case 0x1:
00331                      n = x86_segreg_es;
00332                      break;
00333                   case 0x2:
00334                      n = x86_segreg_fs;
00335                      break;
00336                   case 0x3:
00337                      n = x86_segreg_gs;
00338                      break;
00339                   case 0x4:
00340                      n = x86_segreg_cs;
00341                      break;
00342                   case 0x5:
00343                      n = x86_segreg_ss;
00344                      break;
00345                   default:
00346                      n = 0;
00347                      break;
00348                }
00349                break;
00350             case x86::FLAG:
00351                c = x86_regclass_flags;
00352            switch(baseID) {
00353            case x86::CF:
00354          n = x86_flag_cf;
00355          break;
00356            case x86::PF:
00357          n = x86_flag_pf;
00358          break;
00359            case x86::AF:
00360          n = x86_flag_af;
00361          break;
00362            case x86::ZF:
00363          n = x86_flag_zf;
00364          break;
00365            case x86::SF:
00366          n = x86_flag_sf;
00367          break;
00368            case x86::TF:
00369          n = x86_flag_tf;
00370          break;
00371            case x86::IF:
00372          n = x86_flag_if;
00373          break;
00374            case x86::DF:
00375          n = x86_flag_df;
00376          break;
00377            case x86::OF:
00378          n = x86_flag_of;
00379          break;
00380            default:
00381          assert(0);
00382          break;
00383            }
00384                break;
00385             case x86::MISC:
00386                c = x86_regclass_unknown;
00387                break;
00388             case x86::XMM:
00389                c = x86_regclass_xmm;
00390                n = baseID;
00391                break;
00392             case x86::MMX:
00393                c = x86_regclass_mm;
00394                n = baseID;
00395                break;
00396             case x86::CTL:
00397                c = x86_regclass_cr;
00398                n = baseID;
00399                break;
00400             case x86::DBG:
00401                c = x86_regclass_dr;
00402                n = baseID;
00403                break;
00404             case x86::TST:
00405                c = x86_regclass_unknown;
00406                break;
00407             case 0:
00408                switch (baseID) {
00409                   case 0x10:
00410                      c = x86_regclass_ip;
00411                      n = 0;
00412                      break;
00413                   default:
00414                      c = x86_regclass_unknown;
00415                      break;
00416                }
00417                break;
00418          }
00419          break;
00420        case Arch_ppc32:
00421        case Arch_ppc64: // 64-bit not supported in ROSE
00422        {
00423      baseID = reg & 0x0000FFFF;
00424            n = baseID;
00425            switch(category)
00426            {
00427                case ppc32::GPR:
00428                    c = powerpc_regclass_gpr;
00429                    break;
00430                case ppc32::FPR:
00431                case ppc32::FSR:
00432                    c = powerpc_regclass_fpr;
00433                    break;
00434                case ppc32::SPR:
00435                {
00436                    if(baseID < 613) {
00437                        c = powerpc_regclass_spr;
00438                    } else if(baseID < 621 ) {
00439                        c = powerpc_regclass_sr; 
00440                    } else {
00441                        c = powerpc_regclass_cr;
00442                        n = baseID - 621;
00443                if(n > 7) {
00444              n = 0;
00445              p = powerpc_condreggranularity_whole;
00446                } else {
00447              p = powerpc_condreggranularity_field;
00448                }
00449 
00450                    }
00451                }
00452                break;
00453                default:
00454                    assert(!"unknown register type!");
00455                    break;
00456            }
00457            return;
00458        }
00459        default:
00460          c = x86_regclass_unknown;
00461          n = 0;
00462          break;
00463    }
00464 
00465    switch (getArchitecture()) {
00466       case Arch_x86:
00467       case Arch_x86_64:
00468          switch (subrange) {
00469             case x86::FULL:
00470             case x86::OCT:
00471             case x86::FPDBL:
00472                p = x86_regpos_all;
00473                break;
00474             case x86::H_REG:
00475                p = x86_regpos_high_byte;
00476                break;
00477             case x86::L_REG:
00478                p = x86_regpos_low_byte;
00479                break;
00480             case x86::W_REG:
00481                p = x86_regpos_word;
00482                break;
00483             case x86_64::D_REG:
00484                p = x86_regpos_dword;
00485                break;
00486         case x86::BIT:
00487                p = x86_regpos_all;
00488            break;
00489          }
00490          break;
00491       default:
00492         p = x86_regpos_unknown;
00493    }
00494 }
00495 
00496 MachRegister MachRegister::DwarfEncToReg(int encoding, Dyninst::Architecture arch)
00497 {
00498    switch (arch)
00499    {
00500       case Arch_x86:
00501          switch (encoding) {
00502             case 0: return Dyninst::x86::eax;
00503             case 1: return Dyninst::x86::ecx;
00504             case 2: return Dyninst::x86::edx;
00505             case 3: return Dyninst::x86::ebx;
00506             case 4: return Dyninst::x86::esp;
00507             case 5: return Dyninst::x86::ebp;
00508             case 6: return Dyninst::x86::esi;
00509             case 7: return Dyninst::x86::edi;
00510             case 8: return Dyninst::x86::eip;
00511             case 9: return Dyninst::x86::flags;
00512             case 10: return Dyninst::InvalidReg;
00513             case 11: return Dyninst::x86::st0;
00514             case 12: return Dyninst::x86::st1;
00515             case 13: return Dyninst::x86::st2;
00516             case 14: return Dyninst::x86::st3;
00517             case 15: return Dyninst::x86::st4;
00518             case 16: return Dyninst::x86::st5;
00519             case 17: return Dyninst::x86::st6;
00520             case 18: return Dyninst::x86::st7;
00521             case 19: return Dyninst::InvalidReg;
00522             case 20: return Dyninst::InvalidReg;
00523             case 21: return Dyninst::x86::xmm0;
00524             case 22: return Dyninst::x86::xmm1;
00525             case 23: return Dyninst::x86::xmm2;
00526             case 24: return Dyninst::x86::xmm3;
00527             case 25: return Dyninst::x86::xmm4;
00528             case 26: return Dyninst::x86::xmm5;
00529             case 27: return Dyninst::x86::xmm6;
00530             case 28: return Dyninst::x86::xmm7;
00531             case 29: return Dyninst::x86::mm0;
00532             case 30: return Dyninst::x86::mm1;
00533             case 31: return Dyninst::x86::mm2;
00534             case 32: return Dyninst::x86::mm3;
00535             case 33: return Dyninst::x86::mm4;
00536             case 34: return Dyninst::x86::mm5;
00537             case 35: return Dyninst::x86::mm6;
00538             case 36: return Dyninst::x86::mm7;
00539             case 37: return Dyninst::InvalidReg; //fcw
00540             case 38: return Dyninst::InvalidReg; //fsw
00541             case 39: return Dyninst::InvalidReg; //mxcsr
00542             case 40: return Dyninst::x86::es;
00543             case 41: return Dyninst::x86::cs;
00544             case 42: return Dyninst::x86::ss;
00545             case 43: return Dyninst::x86::ds;
00546             case 44: return Dyninst::x86::fs;
00547             case 45: return Dyninst::x86::gs;
00548             case 46: return Dyninst::InvalidReg;
00549             case 47: return Dyninst::InvalidReg;
00550             case 48: return Dyninst::InvalidReg; //tr
00551             case 49: return Dyninst::InvalidReg; //ldtr
00552             default: return Dyninst::InvalidReg;
00553          }
00554          break;
00555       case Arch_x86_64:
00556          switch (encoding) {
00557             case 0: return Dyninst::x86_64::rax;
00558             case 1: return Dyninst::x86_64::rdx;
00559             case 2: return Dyninst::x86_64::rcx;
00560             case 3: return Dyninst::x86_64::rbx;
00561             case 4: return Dyninst::x86_64::rsi;
00562             case 5: return Dyninst::x86_64::rdi;
00563             case 6: return Dyninst::x86_64::rbp;
00564             case 7: return Dyninst::x86_64::rsp;
00565             case 8: return Dyninst::x86_64::r8;
00566             case 9: return Dyninst::x86_64::r9;
00567             case 10: return Dyninst::x86_64::r10;
00568             case 11: return Dyninst::x86_64::r11;
00569             case 12: return Dyninst::x86_64::r12;
00570             case 13: return Dyninst::x86_64::r13;
00571             case 14: return Dyninst::x86_64::r14;
00572             case 15: return Dyninst::x86_64::r15;
00573             case 16: return Dyninst::x86_64::rip;
00574             case 17: return Dyninst::x86_64::xmm0;
00575             case 18: return Dyninst::x86_64::xmm1;
00576             case 19: return Dyninst::x86_64::xmm2;
00577             case 20: return Dyninst::x86_64::xmm3;
00578             case 21: return Dyninst::x86_64::xmm4;
00579             case 22: return Dyninst::x86_64::xmm5;
00580             case 23: return Dyninst::x86_64::xmm6;
00581             case 24: return Dyninst::x86_64::xmm7;
00582             case 25: return Dyninst::x86_64::xmm8;
00583             case 26: return Dyninst::x86_64::xmm9;
00584             case 27: return Dyninst::x86_64::xmm10;
00585             case 28: return Dyninst::x86_64::xmm11;
00586             case 29: return Dyninst::x86_64::xmm12;
00587             case 30: return Dyninst::x86_64::xmm13;
00588             case 31: return Dyninst::x86_64::xmm14;
00589             case 32: return Dyninst::x86_64::xmm15;
00590             case 33: return Dyninst::x86_64::st0;
00591             case 34: return Dyninst::x86_64::st1;
00592             case 35: return Dyninst::x86_64::st2;
00593             case 36: return Dyninst::x86_64::st3;
00594             case 37: return Dyninst::x86_64::st4;
00595             case 38: return Dyninst::x86_64::st5;
00596             case 39: return Dyninst::x86_64::st6;
00597             case 40: return Dyninst::x86_64::st7;
00598             case 41: return Dyninst::x86_64::mm0;
00599             case 42: return Dyninst::x86_64::mm1;
00600             case 43: return Dyninst::x86_64::mm2;
00601             case 44: return Dyninst::x86_64::mm3;
00602             case 45: return Dyninst::x86_64::mm4;
00603             case 46: return Dyninst::x86_64::mm5;
00604             case 47: return Dyninst::x86_64::mm6;
00605             case 48: return Dyninst::x86_64::mm7;
00606             case 49: return Dyninst::x86_64::flags;
00607             case 50: return Dyninst::x86_64::es;
00608             case 51: return Dyninst::x86_64::cs;
00609             case 52: return Dyninst::x86_64::ss;
00610             case 53: return Dyninst::x86_64::ds;
00611             case 54: return Dyninst::x86_64::fs;
00612             case 55: return Dyninst::x86_64::gs;
00613             case 56: return Dyninst::InvalidReg;
00614             case 57: return Dyninst::InvalidReg;
00615             case 58: return Dyninst::x86_64::fsbase;
00616             case 59: return Dyninst::x86_64::gsbase;
00617             case 60: return Dyninst::InvalidReg; 
00618             case 61: return Dyninst::InvalidReg; 
00619             case 62: return Dyninst::InvalidReg; //tr
00620             case 63: return Dyninst::InvalidReg; //ldtr
00621             case 64: return Dyninst::InvalidReg; //mxcsr
00622             case 65: return Dyninst::InvalidReg; //fcw
00623             case 66: return Dyninst::InvalidReg; //fsw
00624          }
00625          break;
00626       case Arch_ppc32:
00627          switch (encoding) {
00628             case 0: return Dyninst::ppc32::r0;
00629             case 1: return Dyninst::ppc32::r1;
00630             case 2: return Dyninst::ppc32::r2;
00631             case 3: return Dyninst::ppc32::r3;
00632             case 4: return Dyninst::ppc32::r4;
00633             case 5: return Dyninst::ppc32::r5;
00634             case 6: return Dyninst::ppc32::r6;
00635             case 7: return Dyninst::ppc32::r7;
00636             case 8: return Dyninst::ppc32::r8;
00637             case 9: return Dyninst::ppc32::r9;
00638             case 10: return Dyninst::ppc32::r10;
00639             case 11: return Dyninst::ppc32::r11;
00640             case 12: return Dyninst::ppc32::r12;
00641             case 13: return Dyninst::ppc32::r13;
00642             case 14: return Dyninst::ppc32::r14;
00643             case 15: return Dyninst::ppc32::r15;
00644             case 16: return Dyninst::ppc32::r16;
00645             case 17: return Dyninst::ppc32::r17;
00646             case 18: return Dyninst::ppc32::r18;
00647             case 19: return Dyninst::ppc32::r19;
00648             case 20: return Dyninst::ppc32::r20;
00649             case 21: return Dyninst::ppc32::r21;
00650             case 22: return Dyninst::ppc32::r22;
00651             case 23: return Dyninst::ppc32::r23;
00652             case 24: return Dyninst::ppc32::r24;
00653             case 25: return Dyninst::ppc32::r25;
00654             case 26: return Dyninst::ppc32::r26;
00655             case 27: return Dyninst::ppc32::r27;
00656             case 28: return Dyninst::ppc32::r28;
00657             case 29: return Dyninst::ppc32::r29;
00658             case 30: return Dyninst::ppc32::r30;
00659             case 31: return Dyninst::ppc32::r31;
00660             case 32: return Dyninst::ppc32::fpr0;
00661             case 33: return Dyninst::ppc32::fpr1;
00662             case 34: return Dyninst::ppc32::fpr2;
00663             case 35: return Dyninst::ppc32::fpr3;
00664             case 36: return Dyninst::ppc32::fpr4;
00665             case 37: return Dyninst::ppc32::fpr5;
00666             case 38: return Dyninst::ppc32::fpr6;
00667             case 39: return Dyninst::ppc32::fpr7;
00668             case 40: return Dyninst::ppc32::fpr8;
00669             case 41: return Dyninst::ppc32::fpr9;
00670             case 42: return Dyninst::ppc32::fpr10;
00671             case 43: return Dyninst::ppc32::fpr11;
00672             case 44: return Dyninst::ppc32::fpr12;
00673             case 45: return Dyninst::ppc32::fpr13;
00674             case 46: return Dyninst::ppc32::fpr14;
00675             case 47: return Dyninst::ppc32::fpr15;
00676             case 48: return Dyninst::ppc32::fpr16;
00677             case 49: return Dyninst::ppc32::fpr17;
00678             case 50: return Dyninst::ppc32::fpr18;
00679             case 51: return Dyninst::ppc32::fpr19;
00680             case 52: return Dyninst::ppc32::fpr20;
00681             case 53: return Dyninst::ppc32::fpr21;
00682             case 54: return Dyninst::ppc32::fpr22;
00683             case 55: return Dyninst::ppc32::fpr23;
00684             case 56: return Dyninst::ppc32::fpr24;
00685             case 57: return Dyninst::ppc32::fpr25;
00686             case 58: return Dyninst::ppc32::fpr26;
00687             case 59: return Dyninst::ppc32::fpr27;
00688             case 60: return Dyninst::ppc32::fpr28;
00689             case 61: return Dyninst::ppc32::fpr29;
00690             case 62: return Dyninst::ppc32::fpr30;
00691             case 63: return Dyninst::ppc32::fpr31;
00692             case 64: return Dyninst::ppc32::cr;
00693             case 65: return Dyninst::InvalidReg; //FPSCR
00694          }
00695          //Seperate switch statements to give compilers an easier time of 
00696          // optimizing
00697          switch (encoding) {
00698             case 100: return Dyninst::ppc32::mq;
00699             case 101: return Dyninst::ppc32::xer;
00700             case 102: return Dyninst::InvalidReg;
00701             case 103: return Dyninst::InvalidReg;
00702             case 104: return Dyninst::InvalidReg; //RTCU
00703             case 105: return Dyninst::InvalidReg; //RTCL
00704             case 106: return Dyninst::InvalidReg;
00705             case 107: return Dyninst::InvalidReg;
00706             case 108: return Dyninst::ppc32::lr;
00707             case 109: return Dyninst::ppc32::ctr;
00708             default: return Dyninst::InvalidReg;
00709          }
00710          break;
00711       case Arch_ppc64:
00712          switch (encoding) {
00713             case 0: return Dyninst::ppc64::r0;
00714             case 1: return Dyninst::ppc64::r1;
00715             case 2: return Dyninst::ppc64::r2;
00716             case 3: return Dyninst::ppc64::r3;
00717             case 4: return Dyninst::ppc64::r4;
00718             case 5: return Dyninst::ppc64::r5;
00719             case 6: return Dyninst::ppc64::r6;
00720             case 7: return Dyninst::ppc64::r7;
00721             case 8: return Dyninst::ppc64::r8;
00722             case 9: return Dyninst::ppc64::r9;
00723             case 10: return Dyninst::ppc64::r10;
00724             case 11: return Dyninst::ppc64::r11;
00725             case 12: return Dyninst::ppc64::r12;
00726             case 13: return Dyninst::ppc64::r13;
00727             case 14: return Dyninst::ppc64::r14;
00728             case 15: return Dyninst::ppc64::r15;
00729             case 16: return Dyninst::ppc64::r16;
00730             case 17: return Dyninst::ppc64::r17;
00731             case 18: return Dyninst::ppc64::r18;
00732             case 19: return Dyninst::ppc64::r19;
00733             case 20: return Dyninst::ppc64::r20;
00734             case 21: return Dyninst::ppc64::r21;
00735             case 22: return Dyninst::ppc64::r22;
00736             case 23: return Dyninst::ppc64::r23;
00737             case 24: return Dyninst::ppc64::r24;
00738             case 25: return Dyninst::ppc64::r25;
00739             case 26: return Dyninst::ppc64::r26;
00740             case 27: return Dyninst::ppc64::r27;
00741             case 28: return Dyninst::ppc64::r28;
00742             case 29: return Dyninst::ppc64::r29;
00743             case 30: return Dyninst::ppc64::r30;
00744             case 31: return Dyninst::ppc64::r31;
00745             case 32: return Dyninst::ppc64::fpr0;
00746             case 33: return Dyninst::ppc64::fpr1;
00747             case 34: return Dyninst::ppc64::fpr2;
00748             case 35: return Dyninst::ppc64::fpr3;
00749             case 36: return Dyninst::ppc64::fpr4;
00750             case 37: return Dyninst::ppc64::fpr5;
00751             case 38: return Dyninst::ppc64::fpr6;
00752             case 39: return Dyninst::ppc64::fpr7;
00753             case 40: return Dyninst::ppc64::fpr8;
00754             case 41: return Dyninst::ppc64::fpr9;
00755             case 42: return Dyninst::ppc64::fpr10;
00756             case 43: return Dyninst::ppc64::fpr11;
00757             case 44: return Dyninst::ppc64::fpr12;
00758             case 45: return Dyninst::ppc64::fpr13;
00759             case 46: return Dyninst::ppc64::fpr14;
00760             case 47: return Dyninst::ppc64::fpr15;
00761             case 48: return Dyninst::ppc64::fpr16;
00762             case 49: return Dyninst::ppc64::fpr17;
00763             case 50: return Dyninst::ppc64::fpr18;
00764             case 51: return Dyninst::ppc64::fpr19;
00765             case 52: return Dyninst::ppc64::fpr20;
00766             case 53: return Dyninst::ppc64::fpr21;
00767             case 54: return Dyninst::ppc64::fpr22;
00768             case 55: return Dyninst::ppc64::fpr23;
00769             case 56: return Dyninst::ppc64::fpr24;
00770             case 57: return Dyninst::ppc64::fpr25;
00771             case 58: return Dyninst::ppc64::fpr26;
00772             case 59: return Dyninst::ppc64::fpr27;
00773             case 60: return Dyninst::ppc64::fpr28;
00774             case 61: return Dyninst::ppc64::fpr29;
00775             case 62: return Dyninst::ppc64::fpr30;
00776             case 63: return Dyninst::ppc64::fpr31;
00777             case 64: return Dyninst::ppc64::cr;
00778             case 65: return Dyninst::InvalidReg; //FPSCR
00779          }
00780          //Seperate switch statements to give compilers an easier time of 
00781          // optimizing
00782          switch (encoding) {
00783             case 100: return Dyninst::ppc64::mq;
00784             case 101: return Dyninst::ppc64::xer;
00785             case 102: return Dyninst::InvalidReg;
00786             case 103: return Dyninst::InvalidReg;
00787             case 104: return Dyninst::InvalidReg; //RTCU
00788             case 105: return Dyninst::InvalidReg; //RTCL
00789             case 106: return Dyninst::InvalidReg;
00790             case 107: return Dyninst::InvalidReg;
00791             case 108: return Dyninst::ppc64::lr;
00792             case 109: return Dyninst::ppc64::ctr;
00793             default: return Dyninst::InvalidReg;
00794          }
00795          break;
00796       case Arch_none:
00797          return Dyninst::InvalidReg;
00798          break;
00799    }
00800    //Invalid Architecture passed
00801    return Dyninst::InvalidReg;
00802 
00803 }
00804 
00805 int MachRegister::getDwarfEnc() const
00806 {
00807    switch (getArchitecture())
00808    {
00809       case Arch_x86:
00810          switch (val()) {
00811             case Dyninst::x86::ieax: return 0;
00812             case Dyninst::x86::iecx: return 1;
00813             case Dyninst::x86::iedx: return 2;
00814             case Dyninst::x86::iebx: return 3;
00815             case Dyninst::x86::iesp: return 4;
00816             case Dyninst::x86::iebp: return 5;
00817             case Dyninst::x86::iesi: return 6;
00818             case Dyninst::x86::iedi: return 7;
00819             case Dyninst::x86::ieip: return 8;
00820             case Dyninst::x86::iflags: return 9;
00821             case Dyninst::x86::ixmm0: return 21;
00822             case Dyninst::x86::ixmm1: return 22;
00823             case Dyninst::x86::ixmm2: return 23;
00824             case Dyninst::x86::ixmm3: return 24;
00825             case Dyninst::x86::ixmm4: return 25;
00826             case Dyninst::x86::ixmm5: return 26;
00827             case Dyninst::x86::ixmm6: return 27;
00828             case Dyninst::x86::ixmm7: return 28;
00829             case Dyninst::x86::imm0: return 29;
00830             case Dyninst::x86::imm1: return 30;
00831             case Dyninst::x86::imm2: return 31;
00832             case Dyninst::x86::imm3: return 32;
00833             case Dyninst::x86::imm4: return 33;
00834             case Dyninst::x86::imm5: return 34;
00835             case Dyninst::x86::imm6: return 35;
00836             case Dyninst::x86::imm7: return 36;
00837             case Dyninst::x86::ies: return 40;
00838             case Dyninst::x86::ics: return 41;
00839             case Dyninst::x86::iss: return 42;
00840             case Dyninst::x86::ids: return 43;
00841             case Dyninst::x86::ifs: return 44;
00842             case Dyninst::x86::igs: return 45;
00843             default: return -1;
00844          }
00845          break;
00846       case Arch_x86_64:
00847          switch (val()) {
00848             case Dyninst::x86_64::irax: return 0;
00849             case Dyninst::x86_64::irdx: return 1;
00850             case Dyninst::x86_64::ircx: return 2;
00851             case Dyninst::x86_64::irbx: return 3;
00852             case Dyninst::x86_64::irsi: return 4;
00853             case Dyninst::x86_64::irdi: return 5;
00854             case Dyninst::x86_64::irbp: return 6;
00855             case Dyninst::x86_64::irsp: return 7;
00856             case Dyninst::x86_64::ir8: return 8;
00857             case Dyninst::x86_64::ir9: return 9;
00858             case Dyninst::x86_64::ir10: return 10;
00859             case Dyninst::x86_64::ir11: return 11;
00860             case Dyninst::x86_64::ir12: return 12;
00861             case Dyninst::x86_64::ir13: return 13;
00862             case Dyninst::x86_64::ir14: return 14;
00863             case Dyninst::x86_64::ir15: return 15;
00864             case Dyninst::x86_64::irip: return 16;
00865             case Dyninst::x86_64::ixmm0: return 17;
00866             case Dyninst::x86_64::ixmm1: return 18;
00867             case Dyninst::x86_64::ixmm2: return 19;
00868             case Dyninst::x86_64::ixmm3: return 20;
00869             case Dyninst::x86_64::ixmm4: return 21;
00870             case Dyninst::x86_64::ixmm5: return 22;
00871             case Dyninst::x86_64::ixmm6: return 23;
00872             case Dyninst::x86_64::ixmm7: return 24;
00873             case Dyninst::x86_64::ixmm8: return 25;
00874             case Dyninst::x86_64::ixmm9: return 26;
00875             case Dyninst::x86_64::ixmm10: return 27;
00876             case Dyninst::x86_64::ixmm11: return 28;
00877             case Dyninst::x86_64::ixmm12: return 29;
00878             case Dyninst::x86_64::ixmm13: return 30;
00879             case Dyninst::x86_64::ixmm14: return 31;
00880             case Dyninst::x86_64::ixmm15: return 32;
00881             case Dyninst::x86_64::imm0: return 41;
00882             case Dyninst::x86_64::imm1: return 42;
00883             case Dyninst::x86_64::imm2: return 43;
00884             case Dyninst::x86_64::imm3: return 44;
00885             case Dyninst::x86_64::imm4: return 45;
00886             case Dyninst::x86_64::imm5: return 46;
00887             case Dyninst::x86_64::imm6: return 47;
00888             case Dyninst::x86_64::imm7: return 48;
00889             case Dyninst::x86_64::iflags: return 49;
00890             case Dyninst::x86_64::ies: return 50;
00891             case Dyninst::x86_64::ics: return 51;
00892             case Dyninst::x86_64::iss: return 52;
00893             case Dyninst::x86_64::ids: return 53;
00894             case Dyninst::x86_64::ifs: return 54;
00895             case Dyninst::x86_64::igs: return 55;
00896             case Dyninst::x86_64::ifsbase: return 58;
00897             case Dyninst::x86_64::igsbase: return 59;
00898             default: return -1;
00899          }
00900          break;
00901       case Arch_ppc32:
00902          switch (val()) {
00903             case Dyninst::ppc32::ir0: return 0;
00904             case Dyninst::ppc32::ir1: return 1;
00905             case Dyninst::ppc32::ir2: return 2;
00906             case Dyninst::ppc32::ir3: return 3;
00907             case Dyninst::ppc32::ir4: return 4;
00908             case Dyninst::ppc32::ir5: return 5;
00909             case Dyninst::ppc32::ir6: return 6;
00910             case Dyninst::ppc32::ir7: return 7;
00911             case Dyninst::ppc32::ir8: return 8;
00912             case Dyninst::ppc32::ir9: return 9;
00913             case Dyninst::ppc32::ir10: return 10;
00914             case Dyninst::ppc32::ir11: return 11;
00915             case Dyninst::ppc32::ir12: return 12;
00916             case Dyninst::ppc32::ir13: return 13;
00917             case Dyninst::ppc32::ir14: return 14;
00918             case Dyninst::ppc32::ir15: return 15;
00919             case Dyninst::ppc32::ir16: return 16;
00920             case Dyninst::ppc32::ir17: return 17;
00921             case Dyninst::ppc32::ir18: return 18;
00922             case Dyninst::ppc32::ir19: return 19;
00923             case Dyninst::ppc32::ir20: return 20;
00924             case Dyninst::ppc32::ir21: return 21;
00925             case Dyninst::ppc32::ir22: return 22;
00926             case Dyninst::ppc32::ir23: return 23;
00927             case Dyninst::ppc32::ir24: return 24;
00928             case Dyninst::ppc32::ir25: return 25;
00929             case Dyninst::ppc32::ir26: return 26;
00930             case Dyninst::ppc32::ir27: return 27;
00931             case Dyninst::ppc32::ir28: return 28;
00932             case Dyninst::ppc32::ir29: return 29;
00933             case Dyninst::ppc32::ir30: return 30;
00934             case Dyninst::ppc32::ir31: return 31;
00935             case Dyninst::ppc32::ifpr0: return 32;
00936             case Dyninst::ppc32::ifpr1: return 33;
00937             case Dyninst::ppc32::ifpr2: return 34;
00938             case Dyninst::ppc32::ifpr3: return 35;
00939             case Dyninst::ppc32::ifpr4: return 36;
00940             case Dyninst::ppc32::ifpr5: return 37;
00941             case Dyninst::ppc32::ifpr6: return 38;
00942             case Dyninst::ppc32::ifpr7: return 39;
00943             case Dyninst::ppc32::ifpr8: return 40;
00944             case Dyninst::ppc32::ifpr9: return 41;
00945             case Dyninst::ppc32::ifpr10: return 42;
00946             case Dyninst::ppc32::ifpr11: return 43;
00947             case Dyninst::ppc32::ifpr12: return 44;
00948             case Dyninst::ppc32::ifpr13: return 45;
00949             case Dyninst::ppc32::ifpr14: return 46;
00950             case Dyninst::ppc32::ifpr15: return 47;
00951             case Dyninst::ppc32::ifpr16: return 48;
00952             case Dyninst::ppc32::ifpr17: return 49;
00953             case Dyninst::ppc32::ifpr18: return 50;
00954             case Dyninst::ppc32::ifpr19: return 51;
00955             case Dyninst::ppc32::ifpr20: return 52;
00956             case Dyninst::ppc32::ifpr21: return 53;
00957             case Dyninst::ppc32::ifpr22: return 54;
00958             case Dyninst::ppc32::ifpr23: return 55;
00959             case Dyninst::ppc32::ifpr24: return 56;
00960             case Dyninst::ppc32::ifpr25: return 57;
00961             case Dyninst::ppc32::ifpr26: return 58;
00962             case Dyninst::ppc32::ifpr27: return 59;
00963             case Dyninst::ppc32::ifpr28: return 60;
00964             case Dyninst::ppc32::ifpr29: return 61;
00965             case Dyninst::ppc32::ifpr30: return 62;
00966             case Dyninst::ppc32::ifpr31: return 63;
00967             case Dyninst::ppc32::icr: return 64;
00968             case Dyninst::ppc32::imq: return 100;
00969             case Dyninst::ppc32::ixer: return 101;
00970             case Dyninst::ppc32::ilr: return 108;
00971             case Dyninst::ppc32::ictr: return 109;
00972             default: return -1;
00973          }
00974       case Arch_ppc64:
00975          switch (val()) {
00976             case Dyninst::ppc64::ir0: return 0;
00977             case Dyninst::ppc64::ir1: return 1;
00978             case Dyninst::ppc64::ir2: return 2;
00979             case Dyninst::ppc64::ir3: return 3;
00980             case Dyninst::ppc64::ir4: return 4;
00981             case Dyninst::ppc64::ir5: return 5;
00982             case Dyninst::ppc64::ir6: return 6;
00983             case Dyninst::ppc64::ir7: return 7;
00984             case Dyninst::ppc64::ir8: return 8;
00985             case Dyninst::ppc64::ir9: return 9;
00986             case Dyninst::ppc64::ir10: return 10;
00987             case Dyninst::ppc64::ir11: return 11;
00988             case Dyninst::ppc64::ir12: return 12;
00989             case Dyninst::ppc64::ir13: return 13;
00990             case Dyninst::ppc64::ir14: return 14;
00991             case Dyninst::ppc64::ir15: return 15;
00992             case Dyninst::ppc64::ir16: return 16;
00993             case Dyninst::ppc64::ir17: return 17;
00994             case Dyninst::ppc64::ir18: return 18;
00995             case Dyninst::ppc64::ir19: return 19;
00996             case Dyninst::ppc64::ir20: return 20;
00997             case Dyninst::ppc64::ir21: return 21;
00998             case Dyninst::ppc64::ir22: return 22;
00999             case Dyninst::ppc64::ir23: return 23;
01000             case Dyninst::ppc64::ir24: return 24;
01001             case Dyninst::ppc64::ir25: return 25;
01002             case Dyninst::ppc64::ir26: return 26;
01003             case Dyninst::ppc64::ir27: return 27;
01004             case Dyninst::ppc64::ir28: return 28;
01005             case Dyninst::ppc64::ir29: return 29;
01006             case Dyninst::ppc64::ir30: return 30;
01007             case Dyninst::ppc64::ir31: return 31;
01008             case Dyninst::ppc64::ifpr0: return 32;
01009             case Dyninst::ppc64::ifpr1: return 33;
01010             case Dyninst::ppc64::ifpr2: return 34;
01011             case Dyninst::ppc64::ifpr3: return 35;
01012             case Dyninst::ppc64::ifpr4: return 36;
01013             case Dyninst::ppc64::ifpr5: return 37;
01014             case Dyninst::ppc64::ifpr6: return 38;
01015             case Dyninst::ppc64::ifpr7: return 39;
01016             case Dyninst::ppc64::ifpr8: return 40;
01017             case Dyninst::ppc64::ifpr9: return 41;
01018             case Dyninst::ppc64::ifpr10: return 42;
01019             case Dyninst::ppc64::ifpr11: return 43;
01020             case Dyninst::ppc64::ifpr12: return 44;
01021             case Dyninst::ppc64::ifpr13: return 45;
01022             case Dyninst::ppc64::ifpr14: return 46;
01023             case Dyninst::ppc64::ifpr15: return 47;
01024             case Dyninst::ppc64::ifpr16: return 48;
01025             case Dyninst::ppc64::ifpr17: return 49;
01026             case Dyninst::ppc64::ifpr18: return 50;
01027             case Dyninst::ppc64::ifpr19: return 51;
01028             case Dyninst::ppc64::ifpr20: return 52;
01029             case Dyninst::ppc64::ifpr21: return 53;
01030             case Dyninst::ppc64::ifpr22: return 54;
01031             case Dyninst::ppc64::ifpr23: return 55;
01032             case Dyninst::ppc64::ifpr24: return 56;
01033             case Dyninst::ppc64::ifpr25: return 57;
01034             case Dyninst::ppc64::ifpr26: return 58;
01035             case Dyninst::ppc64::ifpr27: return 59;
01036             case Dyninst::ppc64::ifpr28: return 60;
01037             case Dyninst::ppc64::ifpr29: return 61;
01038             case Dyninst::ppc64::ifpr30: return 62;
01039             case Dyninst::ppc64::ifpr31: return 63;
01040             case Dyninst::ppc64::icr: return 64;
01041             case Dyninst::ppc64::imq: return 100;
01042             case Dyninst::ppc64::ixer: return 101;
01043             case Dyninst::ppc64::ilr: return 108;
01044             case Dyninst::ppc64::ictr: return 109;
01045             default: return -1;
01046          }
01047          break;
01048       case Arch_none:
01049          return -1;
01050    }
01051    //Invalid register passed
01052    return -1;
01053 }
01054 
01055 unsigned Dyninst::getArchAddressWidth(Dyninst::Architecture arch)
01056 {
01057    switch (arch) {
01058       case Arch_none: 
01059          return 0;
01060       case Arch_x86:
01061       case Arch_ppc32:
01062          return 4;
01063       case Arch_x86_64:
01064       case Arch_ppc64:
01065          return 8;
01066    }
01067    return 0;
01068 }
01069 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1