1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
/*
* HT Editor
* flt_analy.cc
*
* Copyright (C) 1999-2003 Sebastian Biallas (sb@biallas.net)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "analy.h"
#include "analy_alpha.h"
#include "analy_names.h"
#include "analy_ppc.h"
#include "analy_register.h"
#include "analy_x86.h"
#include "flt_analy.h"
#include "htctrl.h"
#include "htdebug.h"
#include "htiobox.h"
#include "htflt.h"
#include "strtools.h"
#include "pestruct.h"
#include "snprintf.h"
//#include "x86asm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*
*/
void FLTAnalyser::init(ht_flt_shared_data *Flt_shared, File *File)
{
flt_shared = Flt_shared;
file = File;
validarea = new Area();
validarea->init();
Analyser::init();
}
void FLTAnalyser::beginAnalysis()
{
setLocationTreeOptimizeThreshold(100);
setSymbolTreeOptimizeThreshold(100);
/*
* give all sections a descriptive comment:
*/
Address *secaddr;
secaddr = createAddress32(flt_shared->code_start);
if (validAddress(secaddr, scvalid)) {
addComment(secaddr, 0, "");
addComment(secaddr, 0, ";******************************************************************");
addComment(secaddr, 0, "; start of code");
addComment(secaddr, 0, ";******************************************************************");
}
delete secaddr;
secaddr = createAddress32(flt_shared->data_start);
if (validAddress(secaddr, scvalid)) {
addComment(secaddr, 0, "");
addComment(secaddr, 0, ";******************************************************************");
addComment(secaddr, 0, "; start of data");
addComment(secaddr, 0, ";******************************************************************");
}
delete secaddr;
secaddr = createAddress32(flt_shared->bss_start);
if (validAddress(secaddr, scvalid)) {
addComment(secaddr, 0, "");
addComment(secaddr, 0, ";******************************************************************");
addComment(secaddr, 0, "; start of bss");
addComment(secaddr, 0, ";******************************************************************");
}
delete secaddr;
Address *secaddr1, *secaddr2;
secaddr1 = createAddress32(flt_shared->code_start);
secaddr2 = createAddress32(flt_shared->bss_end);
validarea->add(secaddr1, secaddr2);
delete secaddr1;
delete secaddr2;
/*
* entrypoint
*/
Address *entry;
entry = createAddress32(flt_shared->header.entry);
pushAddress(entry, entry);
assignSymbol(entry, "entrypoint", label_func);
addComment(entry, 0, "");
addComment(entry, 0, ";****************************");
addComment(entry, 0, "; entrypoint");
addComment(entry, 0, ";****************************");
delete entry;
setLocationTreeOptimizeThreshold(1000);
setSymbolTreeOptimizeThreshold(1000);
Analyser::beginAnalysis();
}
/*
*
*/
void FLTAnalyser::load(ObjectStream &f)
{
GET_OBJECT(f, validarea);
Analyser::load(f);
}
/*
*
*/
void FLTAnalyser::done()
{
validarea->done();
delete validarea;
Analyser::done();
}
ObjectID FLTAnalyser::getObjectID() const
{
return ATOM_FLT_ANALYSER;
}
/*
*
*/
uint FLTAnalyser::bufPtr(Address *Addr, byte *buf, int size)
{
FileOfs ofs = addressToFileofs(Addr);
/* if (ofs == INVALID_FILE_OFS) {
int as = 1;
}*/
assert(ofs != INVALID_FILE_OFS);
file->seek(ofs);
return file->read(buf, size);
}
bool FLTAnalyser::convertAddressToFLTAddress(Address *addr, FLTAddress *r)
{
if (addr->getObjectID()==ATOM_ADDRESS_FLAT_32) {
*r = ((AddressFlat32*)addr)->addr;
return true;
} else {
return false;
}
}
Address *FLTAnalyser::createAddress()
{
return new AddressFlat32();
}
Address *FLTAnalyser::createAddress32(uint32 addr)
{
return new AddressFlat32(addr);
}
/*
*
*/
Assembler *FLTAnalyser::createAssembler()
{
return NULL;
}
/*
*
*/
FileOfs FLTAnalyser::addressToFileofs(Address *Addr)
{
if (validAddress(Addr, scinitialized)) {
FLTAddress ea;
if (!convertAddressToFLTAddress(Addr, &ea)) return INVALID_FILE_OFS;
return (FileOfs)ea;
} else {
return INVALID_FILE_OFS;
}
}
/*
*
*/
const char *FLTAnalyser::getSegmentNameByAddress(Address *Addr)
{
FLTAddress ea;
if (!convertAddressToFLTAddress(Addr, &ea)) return NULL;
if (ea >= flt_shared->code_start) {
if (ea >= flt_shared->data_start) {
if (ea >= flt_shared->bss_start) {
if (ea >= flt_shared->bss_end) {
return NULL;
}
return "bss";
}
return "data";
}
return "code";
}
return NULL;
}
/*
*
*/
String &FLTAnalyser::getName(String &res)
{
return file->getDesc(res);
}
/*
*
*/
const char *FLTAnalyser::getType()
{
return "FLAT/Analyser";
}
/*
*
*/
void FLTAnalyser::initCodeAnalyser()
{
Analyser::initCodeAnalyser();
}
/*
*
*/
void FLTAnalyser::initUnasm()
{
DPRINTF("flt_analy: ");
// DPRINTF("initing analy_ppc_disassembler\n");
analy_disasm = NULL;
// ((AnalyPPCDisassembler*)analy_disasm)->init(this);
}
/*
*
*/
void FLTAnalyser::log(const char *msg)
{
/*
* log() does to much traffic so dont log
* perhaps we reactivate this later
*
*/
/* LOG(msg);*/
}
/*
*
*/
Address *FLTAnalyser::nextValid(Address *Addr)
{
return (Address *)validarea->findNext(Addr);
}
/*
*
*/
void FLTAnalyser::store(ObjectStream &f) const
{
PUT_OBJECT(f, validarea);
Analyser::store(f);
}
/*
*
*/
int FLTAnalyser::queryConfig(int mode)
{
switch (mode) {
case Q_DO_ANALYSIS:
case Q_ENGAGE_CODE_ANALYSER:
case Q_ENGAGE_DATA_ANALYSER:
return true;
default:
return 0;
}
}
/*
*
*/
Address *FLTAnalyser::fileofsToAddress(FileOfs fileofs)
{
FLTAddress ea = (FLTAddress)fileofs;
if (ea >= flt_shared->code_start && ea < flt_shared->data_end) {
return createAddress32(ea);
} else {
return new InvalidAddress();
}
}
/*
*
*/
bool FLTAnalyser::validAddress(Address *Addr, tsectype action)
{
FLTAddress ea;
if (!convertAddressToFLTAddress(Addr, &ea)) return false;
if (ea >= flt_shared->code_start) {
if (ea >= flt_shared->data_start) {
if (ea >= flt_shared->bss_start) {
if (ea >= flt_shared->bss_end) {
return false;
}
switch (action) {
case scvalid:
case scread:
case scwrite:
case screadwrite:
return true;
case sccode:
case scinitialized:
return false;
}
}
switch (action) {
case scvalid:
case scread:
case scwrite:
case screadwrite:
case scinitialized:
return true;
case sccode:
return false;
}
}
switch (action) {
case scvalid:
case scread:
case scinitialized:
return true;
case scwrite:
case screadwrite:
case sccode:
return false;
}
}
return false;
}
|