Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

ac_storage.H

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 
00003 /*  ArchC Storage Library for the ArchC architecture simulators
00004     Copyright (C) 2002-2004  The ArchC Team
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library 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 GNU
00014     Lesser General Public License for more details.
00015 */
00016 
00017 /********************************************************/
00018 /* The ArchC storage device base class.                 */
00019 /* Author:  Sandro Rigo                                 */
00020 /*                                                      */
00021 /*                                                      */
00022 /* The ArchC Team                                       */
00023 /* Computer Systems Laboratory (LSC)                    */
00024 /* IC-UNICAMP                                           */
00025 /* http://www.lsc.ic.unicamp.br                         */
00026 /********************************************************/
00027 
00029 
00035 
00036 #ifndef _AC_STORAGE_H
00037 #define _AC_STORAGE_H
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <systemc.h>
00042 #include <list>
00043 #include <fstream>
00044 #include "archc.H"
00045 #include "ac_parms.H"
00046 
00047 using std::string;
00048 using std::istringstream;
00049 
00051 
00052 
00053 class ac_storage { 
00054 
00055 protected:
00056   char *Data;                       
00057   char *name;                       
00058   unsigned size;                    
00059 
00060 #ifdef AC_UPDATE_LOG
00061   log_list changes;                 
00062   fstream update_file;              
00063 #endif
00064 
00065 
00066 #ifdef AC_DELAY
00067   log_list delays;                  
00068 #endif
00069 
00070 public:
00071   
00073   virtual ac_word read( unsigned address );
00074 
00076   virtual unsigned char read_byte( unsigned address );
00077 
00079   virtual ac_Hword read_half( unsigned address );
00080 
00081 
00083   virtual void write( unsigned address, ac_word datum );
00084 
00086   virtual void write_byte( unsigned address, unsigned char datum );
00087 
00089   virtual void write_half( unsigned address, ac_Hword datum );
00090 
00091 #ifdef AC_DELAY
00092 
00093   virtual void write( unsigned address, ac_word datum, unsigned time );
00094 
00096   virtual void write_byte( unsigned address, unsigned char datum, unsigned time );
00097 
00099   virtual void write_half( unsigned address, ac_Hword  datum, unsigned time  );
00100 #endif
00101 
00102 #ifdef AC_UPDATE_LOG
00103 
00105   void reset_log();
00106   
00108   int change_dump( ostream& output);
00109 
00110 
00112   void change_save( );
00113 #endif
00114       
00116   ac_storage( char *n, unsigned s ){
00117       
00118     //Initializing members
00119     Data = (char*) new char[ s ];
00120     name = n;
00121     size = s;
00122 
00123 #ifdef AC_UPDATE_LOG
00124 
00125     char filename[strlen(n)+ 16];
00126 
00127                 sprintf(filename, "ac_storage.%s.log",n);
00128                 update_file.open(filename, ios::out|ios::binary);
00129 #endif
00130 
00131   }    
00132   
00134 
00135   ac_storage( char *n ):name(n){};
00136 
00138   virtual ~ac_storage(){
00139 
00140 #ifdef AC_UPDATE_LOG
00141     update_file.close();
00142 #endif
00143 
00144     //Freeing Memory.
00145     delete[] Data;
00146   }    
00147 
00149   ac_storage& operator =(ac_storage& src ){
00150     
00151     Data = src.Data;
00152     name = src.name;
00153     size = src.size;
00154     
00155 #ifdef AC_UPDATE_LOG
00156     changes = src.changes;
00157 #endif
00158     return *this;
00159   }
00160 
00162   void initialize( char* n, unsigned s ){
00163     name = n;
00164     Data = (char*) new char[ s ];
00165     size = s;
00166   }
00167 
00169   char* get_name( ){
00170     return name;
00171   }
00172 
00174   unsigned get_size( ){
00175     return size;
00176   }
00177 
00178 #ifdef AC_UPDATE_LOG
00179 
00180   log_list* get_changes( ){
00181     return &changes;
00182   }
00183 #endif
00184 
00186   void load( char* file );
00187 
00189   void load_array( const unsigned char* d, const unsigned s );
00190 
00191 
00192 #ifdef AC_DELAY
00193 
00195   virtual void commit_delays( double time );
00196 
00197 #endif
00198     
00199 };
00200 
00201 
00205 // unsigned operator = ( unsigned d, ac_reg r){ 
00206 
00207 //      unsigned u = d;
00208     
00209 //      u = r.read();
00210 
00211 //      return u;
00212 // }
00213 
00214 
00215 #endif /*_AC_STORAGE_H*/

Generated on Thu Jun 24 08:30:05 2004 for ArchC by doxygen 1.3.4