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
00028
00032
00033
00034
00036
00037
00038 #include "ac_mem.H"
00039 #include "ac_resources.H"
00040
00042 ac_word ac_mem::read( unsigned address )
00043 {
00044 return (ac_storage::read(address));
00045 }
00046
00048 unsigned char ac_mem::read_byte( unsigned address )
00049 {
00050 return (ac_storage::read_byte(address));
00051 }
00052
00054 ac_Hword ac_mem::read_half( unsigned address )
00055 {
00056 return (ac_storage::read_half(address));
00057 }
00058
00059
00061 void ac_mem::write( unsigned address, ac_word datum )
00062 {
00063 this->ac_storage::write(address, datum);
00064 }
00065
00066
00068 void ac_mem::write_byte( unsigned address, unsigned char datum )
00069 {
00070 this->ac_storage::write_byte(address, datum);
00071 }
00072
00073
00075 void ac_mem::write_half( unsigned address, unsigned short datum )
00076 {
00077 this->ac_storage::write_half(address, datum);
00078 }
00079
00080
00081 ac_mem::ac_mem( char *n, unsigned s) :
00082 ac_storage(n, s)
00083 {
00084 request_block_event = false;
00085 request_write_block_event = false;
00086 request_write_event = false;
00087 next_level = NULL;
00088 previous_level = NULL;
00089
00090 datum_ref = new char[4];
00091 }
00092
00093
00094
00095
00097 ac_mem::~ac_mem()
00098 {
00099
00100 delete[] datum_ref;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void ac_mem::stall(){
00115 ac_resources::ac_wait();
00116
00117 }
00118
00119
00120 void ac_mem::ready(){
00121 ac_resources::ac_release();
00122
00123
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133 void ac_mem::request_block(ac_cache_if* client, unsigned address, unsigned size_bytes)
00134 {
00135
00136
00137 client_global = client;
00138 request_buffer = new char[size_bytes*(AC_WORDSIZE/8)];
00139
00140 for (unsigned offset_word = 0; offset_word < size_bytes; offset_word+=AC_WORDSIZE/8)
00141 {
00142 *(ac_word *)(request_buffer + offset_word) = this->read(address + offset_word);
00143
00144 }
00145 request_block_event = true;
00146
00147
00148 }
00149
00150 void ac_mem::process_request() {
00151 if (request_block_event) {
00152 request_block_event = false;
00153 client_global->response_block(request_buffer);
00154 }else if (request_write_block_event) {
00155 request_write_block_event = false;
00156
00157 client_global->response_write_block();
00158 }else if (request_write_event) {
00159 request_write_event = false;
00160 client_global->response_write();
00161 }
00162
00163
00164
00165
00166
00167 }
00168
00169 void ac_mem::request_write_byte(ac_cache_if* client, unsigned address, unsigned char datum)
00170 {
00171 client_global = client;
00172 ac_mem::write_byte(address, datum);
00173 request_write_event = true;
00174
00175
00176 }
00177
00178 void ac_mem::request_write_half(ac_cache_if* client, unsigned address, unsigned short datum)
00179 {
00180 client_global = client;
00181 ac_mem::write_half(address, datum);
00182 request_write_event = true;
00183
00184
00185 }
00186
00187 void ac_mem::request_write(ac_cache_if* client, unsigned address, ac_word datum)
00188 {
00189 client_global = client;
00190 ac_mem::write(address, datum);
00191 request_write_event = true;
00192
00193
00194 }
00195
00196 void ac_mem::request_write_block(ac_cache_if* client, unsigned address, char* datum, unsigned size_bytes)
00197 {
00198
00199 client_global = client;
00200 for (unsigned offset_word = 0; offset_word < size_bytes; offset_word+=AC_WORDSIZE/8)
00201
00202 {
00203 write(address + offset_word, *(ac_word*)(datum + offset_word));
00204
00205
00206
00207 }
00208
00209 request_write_block_event = true;
00210
00211
00212 }
00213
00214 void ac_mem::response_block(char* block)
00215 {
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 delete[] block;
00230
00231 }
00232
00233
00234 void ac_mem::response_write_byte()
00235 {
00236
00237 }
00238
00239 void ac_mem::response_write_half()
00240 {
00241
00242 }
00243
00244 void ac_mem::response_write()
00245 {
00246 this->ready();
00247 }
00248
00249 void ac_mem::response_write_block()
00250 {
00251
00252
00253
00254
00255
00256
00257 }
00258
00259
00260
00261
00262
00263 void ac_mem::bindToNext(ac_cache_if& next)
00264 {
00265 this->next_level = &next;
00266 }
00267
00268 void ac_mem::bindToPrevious(ac_cache_if& previous)
00269 {
00270
00271 }
00272
00273
00274