00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00029
00035
00036 #ifndef _AC_REGBANK_H
00037 #define _AC_REGBANK_H
00038
00039 #include "ac_storage.H"
00040
00041 class ac_resources;
00042
00045 template<class T>class ac_regbank: public ac_storage {
00046 public:
00047
00049 T read( unsigned address ){
00050
00051 #ifdef AC_STATS
00052 ac_resources::ac_sim_stats.add_access(name);
00053 #endif
00054
00055 return *((T *)(Data+((address)*sizeof(T))));
00056 }
00057
00059 ac_Dword read_double( unsigned address ){
00060
00061 #ifdef AC_STATS
00062 ac_resources::ac_sim_stats.add_access(name);
00063 #endif
00064
00065 return *((ac_Dword *)(Data+((address)*sizeof(ac_word)*2)));
00066 }
00067
00068
00070 void write( unsigned address , T datum ){
00071 #ifdef AC_MEM_HIERARCHY
00072 if(ac_resources::ac_wait_sig)
00073 return;
00074 #endif
00075
00076 #ifdef AC_UPDATE_LOG
00077 changes.push_back( change_log(address, datum , sc_simulation_time()));
00078 #endif
00079
00080 *((T *)(Data+((address)*sizeof(T)))) = datum;
00081
00082 #ifdef AC_STATS
00083 ac_resources::ac_sim_stats.add_access(name);
00084 #endif
00085 }
00086
00087
00088 #ifdef AC_DELAY
00089
00090 void write( unsigned address , T datum, unsigned time ){
00091 delays.push_back( change_log( address, datum, (time * ac_resources::time_step) + ac_resources::time_step + sc_simulation_time()));
00092 }
00093 #endif
00094
00096 ac_regbank( char* name, unsigned size=sizeof(T) ):ac_storage(name,size*sizeof(T)){}
00097
00099 void load( char* file ){
00100
00101 ifstream input;
00102 string read;
00103 string word;
00104 T data;
00105 istringstream line;
00106
00107 bool is_addr;
00108
00109 int addr=0;
00110
00111
00112 input.open(file);
00113 if(!input){
00114 AC_ERROR("Could not open input file:" << file);
00115 }
00116 else{
00117
00118 while( !input.eof() ){
00119
00120 line.clear();
00121 getline(input, read);
00122 line.str(read);
00123
00124 is_addr = 1;
00125
00126
00127 while(line >> word){
00128
00129 if( word == ".text" ){
00130 AC_ERROR("Should not load code into the register bank: " << name);
00131 return;
00132 }
00133
00134 if( word == ".data" ){
00135 continue;
00136 }
00137
00138
00139 if( is_addr ){
00140 addr = strtol(word.c_str(), NULL, 16);
00141 is_addr = 0;
00142 }
00143 else{
00144 data = (T)strtol( word.c_str(), NULL, 16);
00145 write(addr,data);
00146 addr+= sizeof(T);
00147 }
00148 }
00149 }
00150 }
00151 }
00152 };
00153
00154 #endif //_AC_REGBANK_H
00155
00156
00157
00158