Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

flt_analy.cc

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      flt_analy.cc
00004  *
00005  *      Copyright (C) 1999-2003 Sebastian Biallas (sb@biallas.net)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "analy.h"
00022 #include "analy_alpha.h"
00023 #include "analy_names.h"
00024 #include "analy_ia64.h"
00025 #include "analy_ppc.h"
00026 #include "analy_register.h"
00027 #include "analy_x86.h"
00028 #include "global.h"
00029 #include "flt_analy.h"
00030 
00031 #include "htctrl.h"
00032 #include "htdebug.h"
00033 #include "htiobox.h"
00034 #include "htflt.h"
00035 #include "htstring.h"
00036 #include "pestruct.h"
00037 #include "snprintf.h"
00038 //#include "x86asm.h"
00039 
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043 
00044 /*
00045  *
00046  */
00047  
00048 void FLTAnalyser::init(ht_flt_shared_data *Flt_shared, ht_streamfile *File)
00049 {
00050         flt_shared = Flt_shared;
00051         file = File;
00052 
00053         validarea = new Area();
00054         validarea->init();
00055 
00056         Analyser::init();
00057 }
00058 
00059 void FLTAnalyser::beginAnalysis()
00060 {
00061         setLocationTreeOptimizeThreshold(100);
00062         setSymbolTreeOptimizeThreshold(100);
00063         
00064         /*
00065          *      give all sections a descriptive comment:
00066          */
00067 
00068         Address *secaddr;
00069         secaddr = createAddress32(flt_shared->code_start);
00070         if (validAddress(secaddr, scvalid)) {
00071                 addComment(secaddr, 0, "");
00072                 addComment(secaddr, 0, ";******************************************************************");
00073                 addComment(secaddr, 0, "; start of code");
00074                 addComment(secaddr, 0, ";******************************************************************");
00075         }
00076         delete secaddr;
00077         secaddr = createAddress32(flt_shared->data_start);
00078         if (validAddress(secaddr, scvalid)) {
00079                 addComment(secaddr, 0, "");
00080                 addComment(secaddr, 0, ";******************************************************************");
00081                 addComment(secaddr, 0, "; start of data");
00082                 addComment(secaddr, 0, ";******************************************************************");
00083         }
00084         delete secaddr;
00085         secaddr = createAddress32(flt_shared->bss_start);
00086         if (validAddress(secaddr, scvalid)) {
00087                 addComment(secaddr, 0, "");
00088                 addComment(secaddr, 0, ";******************************************************************");
00089                 addComment(secaddr, 0, "; start of bss");
00090                 addComment(secaddr, 0, ";******************************************************************");
00091         }
00092         delete secaddr;
00093         Address *secaddr1, *secaddr2;
00094         secaddr1 = createAddress32(flt_shared->code_start);
00095         secaddr2 = createAddress32(flt_shared->bss_end);
00096         validarea->add(secaddr1, secaddr2);
00097         delete secaddr1;
00098         delete secaddr2;
00099 
00100         /*
00101          *      entrypoint
00102          */
00103          
00104         Address *entry;
00105         entry = createAddress32(flt_shared->header.entry);
00106         pushAddress(entry, entry);
00107         assignSymbol(entry, "entrypoint", label_func);
00108         addComment(entry, 0, "");
00109         addComment(entry, 0, ";****************************");
00110         addComment(entry, 0, "; entrypoint");
00111         addComment(entry, 0, ";****************************");
00112         delete entry;
00113 
00114         setLocationTreeOptimizeThreshold(1000);
00115         setSymbolTreeOptimizeThreshold(1000);
00116         
00117         Analyser::beginAnalysis();
00118 }
00119 
00120 /*
00121  *
00122  */
00123 int FLTAnalyser::load(ht_object_stream *f)
00124 {
00125         GET_OBJECT(f, validarea);
00126         return Analyser::load(f);
00127 }
00128 
00129 /*
00130  *
00131  */
00132 void FLTAnalyser::done()
00133 {
00134         validarea->done();
00135         delete validarea;
00136         Analyser::done();
00137 }
00138 
00139 OBJECT_ID FLTAnalyser::object_id() const
00140 {
00141         return ATOM_FLT_ANALYSER;
00142 }
00143 
00144 /*
00145  *
00146  */
00147 UINT FLTAnalyser::bufPtr(Address *Addr, byte *buf, int size)
00148 {
00149         FILEOFS ofs = addressToFileofs(Addr);
00150 /*     if (ofs == INVALID_FILE_OFS) {
00151                 int as = 1;
00152         }*/
00153         assert(ofs != INVALID_FILE_OFS);
00154         file->seek(ofs);
00155         return file->read(buf, size);
00156 }
00157 
00158 bool FLTAnalyser::convertAddressToFLTAddress(Address *addr, FLTAddress *r)
00159 {
00160         if (addr->object_id()==ATOM_ADDRESS_FLAT_32) {
00161                 *r = ((AddressFlat32*)addr)->addr;
00162                 return true;
00163         } else {
00164                 return false;
00165         }
00166 }
00167 
00168 Address *FLTAnalyser::createAddress()
00169 {
00170         return new AddressFlat32();
00171 }
00172 
00173 Address *FLTAnalyser::createAddress32(dword addr)
00174 {
00175         return new AddressFlat32(addr);
00176 }
00177 
00178 /*
00179  *
00180  */
00181 Assembler *FLTAnalyser::createAssembler()
00182 {
00183         return NULL;
00184 }
00185 
00186 /*
00187  *
00188  */
00189 FILEOFS FLTAnalyser::addressToFileofs(Address *Addr)
00190 {
00191         if (validAddress(Addr, scinitialized)) {
00192                 FLTAddress ea;
00193                 if (!convertAddressToFLTAddress(Addr, &ea)) return INVALID_FILE_OFS;
00194                 return (FILEOFS)ea;
00195         } else {
00196                 return INVALID_FILE_OFS;
00197         }
00198 }
00199 
00200 /*
00201  *
00202  */
00203 char *FLTAnalyser::getSegmentNameByAddress(Address *Addr)
00204 {
00205         FLTAddress ea;
00206         if (!convertAddressToFLTAddress(Addr, &ea)) return NULL;
00207         if (ea >= flt_shared->code_start) {
00208         if (ea >= flt_shared->data_start) {
00209                         if (ea >= flt_shared->bss_start) {
00210                                 if (ea >= flt_shared->bss_end) {
00211                                         return NULL;
00212                                 }
00213                                 return "bss";
00214                         }
00215                         return "data";
00216                 }
00217                 return "code";
00218         }
00219         return NULL;
00220 }
00221 
00222 /*
00223  *
00224  */
00225 const char *FLTAnalyser::getName()
00226 {
00227         return file->get_desc();
00228 }
00229 
00230 /*
00231  *
00232  */
00233 const char *FLTAnalyser::getType()
00234 {
00235         return "FLAT/Analyser";
00236 }
00237 
00238 /*
00239  *
00240  */
00241 void FLTAnalyser::initCodeAnalyser()
00242 {
00243         Analyser::initCodeAnalyser();
00244 }
00245 
00246 /*
00247  *
00248  */
00249 void FLTAnalyser::initUnasm()
00250 {
00251         DPRINTF("flt_analy: ");
00252 //      DPRINTF("initing analy_ppc_disassembler\n");
00253         analy_disasm = NULL;
00254 //      ((AnalyPPCDisassembler*)analy_disasm)->init(this);
00255 }
00256 
00257 /*
00258  *
00259  */
00260 void FLTAnalyser::log(const char *msg)
00261 {
00262         /*
00263          *      log() does to much traffic so dont log
00264          *   perhaps we reactivate this later
00265          *
00266          */
00267 /*      LOG(msg);*/
00268 }
00269 
00270 /*
00271  *
00272  */
00273 Address *FLTAnalyser::nextValid(Address *Addr)
00274 {
00275         return (Address *)validarea->findNext(Addr);
00276 }
00277 
00278 /*
00279  *
00280  */
00281 void FLTAnalyser::store(ht_object_stream *f)
00282 {
00283         PUT_OBJECT(f, validarea);
00284         Analyser::store(f);
00285 }
00286 
00287 /*
00288  *
00289  */
00290 int FLTAnalyser::queryConfig(int mode)
00291 {
00292         switch (mode) {
00293                 case Q_DO_ANALYSIS:
00294                 case Q_ENGAGE_CODE_ANALYSER:
00295                 case Q_ENGAGE_DATA_ANALYSER:
00296                         return true;
00297                 default:
00298                         return 0;
00299         }
00300 }
00301 
00302 /*
00303  *
00304  */
00305 Address *FLTAnalyser::fileofsToAddress(FILEOFS fileofs)
00306 {
00307         FLTAddress ea = (FLTAddress)fileofs;
00308         if (ea >= flt_shared->code_start && ea < flt_shared->data_end) {
00309                 return createAddress32(ea);
00310         } else {
00311                 return new InvalidAddress();
00312         }
00313 }
00314 
00315 /*
00316  *
00317  */
00318 bool FLTAnalyser::validAddress(Address *Addr, tsectype action)
00319 {
00320         FLTAddress ea;
00321         if (!convertAddressToFLTAddress(Addr, &ea)) return false;
00322         if (ea >= flt_shared->code_start) {
00323         if (ea >= flt_shared->data_start) {
00324                         if (ea >= flt_shared->bss_start) {
00325                                 if (ea >= flt_shared->bss_end) {
00326                                         return false;
00327                                 }
00328                                 switch (action) {
00329                                 case scvalid:
00330                                 case scread:
00331                                 case scwrite:
00332                                 case screadwrite:
00333                                         return true;
00334                                 case sccode:
00335                                 case scinitialized:
00336                                         return false;
00337                                 }
00338                         }
00339                         switch (action) {
00340                         case scvalid:
00341                         case scread:
00342                         case scwrite:
00343                         case screadwrite:
00344                         case scinitialized:
00345                                 return true;
00346                         case sccode:
00347                                 return false;
00348                         }
00349                 }
00350                 switch (action) {
00351                 case scvalid:
00352                 case scread:
00353                 case scinitialized:
00354                         return true;
00355                 case scwrite:
00356                 case screadwrite:
00357                 case sccode:
00358                         return false;
00359           }
00360         }
00361         return false;
00362 }
00363 
00364 

Generated on Fri May 7 21:15:30 2004 by doxygen 1.3.5