Make your own free website on Tripod.com
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

param.h

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2002 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
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 INFORMATION
00022   www: http://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #ifndef FILE_PARAM_H
00026 #define FILE_PARAM_H
00027 
00028 #include "registers.h"
00029 #include "relocationinfo.h"
00030 
00031 // class per paramentro
00032 // registro, costante o memoria
00033 // memoria: [costante], [reg], [reg+costante] [reg+reg*n], [reg+reg*n+costante]
00034 // se non c'e' costante mettere 0
00035 class Param
00036 {
00037 public:
00038 #ifdef DEBUG
00039   void InitInvalid();
00040   void CheckValid();
00041 #endif
00042   enum TCRegistry   { Registry };
00043   enum TCLiteral    { Literal  };
00044   enum TCFarLiteral { FarLiteral  };
00045   enum TCMemory     { Memory   };
00046   enum Types { t_registry, t_literal, t_memory, t_farliteral };
00047   typedef enum MemoryTypes {
00048 #define DEFINE_MEMTYPE(name,size) name,
00049 #define DEFINE_MEMTYPEI(name,size) name = 0,
00050 #include "memtype.h"
00051 #undef DEFINE_MEMTYPE
00052 #undef DEFINE_MEMTYPEI
00053     memTypeCount
00054   } MemoryTypes;
00055 //  std::string GetString() const;
00056   enum Types GetType() const { return type; };
00057   Param():relocation(NULL) {};
00058   // costruttori per registro
00059   Param(enum TCRegistry dummy,reg_t reg);
00060   // costruttori per letterali (costanti)
00061   Param(enum TCLiteral dummy,int _literal,unsigned char _size=0);
00062   // costruttori per letterali (costanti)
00063   Param(enum TCFarLiteral dummy,int _literal,unsigned char _size,int segment);
00064   // costruttori per memoria
00065   Param(enum TCMemory dummy,int address,MemoryTypes memType = memNone);
00066   Param(enum TCMemory dummy,reg_t reg,int address=0,MemoryTypes memType = memNone);
00067   Param(enum TCMemory dummy,reg_t reg1,reg_t reg2,int address=0,unsigned char multiplier=1,MemoryTypes memType = memNone);
00068 
00069 //protected:
00070 public:
00071   bool RegEqual(const Param& rhs) const
00072   { return type == t_registry && rhs.type == t_registry && mem_reg1 == rhs.mem_reg1; }
00073 //  bool operator==();
00074   reg_t mem_reg1; // null_reg if not present, set if type registry
00075   reg_t mem_reg2; // null_reg if not present
00076   int literal; // 0 if not present
00077   const Relocation* relocation;  // informazioni rilocazione relative a literal
00078   enum Types type;
00079   unsigned char factor; // if mem_reg2 set
00080   unsigned char GetSize() const;
00081   unsigned char GetLiteralSize() const
00082   {
00083     _PRG_ASSERT( type == t_literal || type == t_farliteral );
00084     return sm.size;
00085   };
00086   unsigned GetMemSize() const
00087   {
00088     _PRG_ASSERT( type == t_memory );
00089     _PRG_ASSERT( unsigned(sm.memType&0x7F) < memTypeCount );
00090     return memTypeSizes[sm.memType&0x7F];
00091   };
00092   void SetMemType(MemoryTypes _memType,bool bWriteSize = true)
00093   {
00094     _PRG_ASSERT( type == t_memory );
00095     _PRG_ASSERT( unsigned(_memType) < memTypeCount );
00096     _PRG_ASSERT( memTypeCount < 128 );
00097     sm.memType = (unsigned char)_memType;
00098     if (!bWriteSize)
00099       sm.memType |= 0x80;
00100   };
00101   bool MustWriteMemSize() const
00102   {
00103     _PRG_ASSERT( type == t_memory );
00104     return (sm.memType & 0x80) == 0;
00105   }
00106 private:
00107   union {
00108   unsigned char size; // 0 if unspecified
00109   unsigned char memType;
00110   } sm;
00111   static unsigned memTypeSizes[memTypeCount];
00112 };
00113 
00114 class RegParam: public Param
00115 {
00116 public:
00117   RegParam(reg_t reg);
00118 };
00119 
00120 class LiteralParam: public Param
00121 {
00122 public:
00123   LiteralParam(int _literal,unsigned char _size=0);
00124 };
00125 
00126 class MemoryParam: public Param
00127 {
00128 public:
00129   MemoryParam(int address,unsigned char size=0);
00130   MemoryParam(reg_t reg,int address=0,unsigned char size=0);
00131   MemoryParam(reg_t reg1,reg_t reg2,int address=0,unsigned char multiplier=1,unsigned char size=0);
00132 };
00133 
00134 #endif //FILE_PARAM_H

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15