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

ac_mem.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 
00003 /*  ArchC Cache Library for 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 memory simulation class.                   */
00019 /* Author:  Pablo Viana (CIn-UFPE)                      */
00020 /* Contact: pvs@cin.ufpe.br                             */
00021 /*                                                      */
00022 /* The ArchC Team                                       */
00023 /* Computer Systems Laboratory (LSC)                    */
00024 /* IC-UNICAMP                                           */
00025 /* http://www.lsc.ic.unicamp.br                         */
00026 /********************************************************/
00028 
00032 /************************************************
00033  * Author: Pablo Viana
00034  ************************************************/
00036 
00037 
00038 #include "ac_mem.H"
00039 #include "ac_resources.H"
00040 
00042   ac_word ac_mem::read( unsigned address ) /*const*/
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 //    request_buffer = new char[block_size*(AC_WORDSIZE/8)];
00090     datum_ref = new char[4];
00091   }
00092 
00093 
00094 
00095 
00097   ac_mem::~ac_mem()
00098   {
00099 //      delete[] request_buffer;
00100       delete[] datum_ref;
00101   }
00102 
00103 //  void ac_mem::bindTo(ac_mem& lower){  //were ac_mem
00104 //       this->next_level = &lower;
00105 //       lower.previous_level = this;
00106 //  }
00107 
00108 
00109 /*
00110 ################################################################################
00111 ##############           PROCESSOR STALLING              #######################
00112 ################################################################################
00113 */
00114   void ac_mem::stall(){
00115       ac_resources::ac_wait();
00116 //       cout << "Wait "<< this->get_name() << endl;      
00117   }
00118 
00119 
00120   void ac_mem::ready(){
00121       ac_resources::ac_release();
00122 //      this->replace_status = 0;
00123 //       cout << "Ready "<< this->get_name() << endl;
00124   }
00125 
00126 
00127 /*
00128 ################################################################################
00129 ##############                 INTERFACE                 #######################
00130 ################################################################################
00131 */
00132 
00133   void ac_mem::request_block(ac_cache_if* client, unsigned address, unsigned size_bytes)
00134   {
00135 //          cout << "requesting from" << this->get_name() << endl;
00136 //          cout << "size in bytes: " << size_bytes << endl;
00137        client_global = client;
00138        request_buffer = new char[size_bytes*(AC_WORDSIZE/8)];
00139 //       cout << "request block em MEM no address: " << address << endl;
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 //           cout << " bloco requisitado" << *(ac_word *)(request_buffer + offset_word) << " from: " << (address + offset_word) << endl;
00144        }
00145        request_block_event = true;
00146        //client->response_block(request_buffer);
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 //          cout << "respondendo write_block " << this->name << endl;
00157           client_global->response_write_block();
00158        }else if (request_write_event) {
00159           request_write_event = false;
00160           client_global->response_write();
00161        }
00162        //while (true)
00163        //{
00164        //            wait(request_block_event);
00165        //      client_global->response_block(request_buffer);
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        //notify(SC_ZERO_TIME, request_write_event);
00175        //client->response_write();
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        //notify(SC_ZERO_TIME, request_write_event);
00184        //client->response_write();
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 //       cout << " mem escrita Write: " << read(address) << endl;
00193        //client->response_write();
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 //         for (unsigned offset_word = 0; offset_word < size; offset_word++)
00202            {
00203            write(address + offset_word, *(ac_word*)(datum + offset_word));
00204 //           cout << "buffer recebido em " << (int)datum << endl;
00205 //           cout << " mem escrita Block: " << read(address + offset_word) << endl;
00206 //           cout << "Data stored: " << hex << read(address + offset_word) << " Address: " << (address + offset_word) << endl;
00207        }
00208 //       cout << "Guardei o bloco no proximo nivel" << endl;
00209        request_write_block_event = true;
00210        //client->response_write_block();
00211 
00212   }
00213 
00214   void ac_mem::response_block(char* block)
00215   {
00216 /*       *(slot_tag) = address_tag;
00217        *(slot_valid) = true;
00218        *(slot_dirty) = false;
00219        for (unsigned offset_word = 0; offset_word < block_size; offset_word++)
00220        {
00221            *(ac_word *)(slot_data + offset_word*AC_WORDSIZE/8) = *(ac_word *)(block + offset_word*(AC_WORDSIZE/8));
00222        }
00223        replace_status++;
00224        if(read_access_type)
00225             this->replaceBlockRead(requested_address);
00226        else
00227             this->replaceBlockWrite();
00228 */
00229        delete[] block;
00230 
00231   }
00232 
00233 
00234   void ac_mem::response_write_byte()
00235   {
00236 //       this->ready(requested_address);
00237   }
00238 
00239   void ac_mem::response_write_half()
00240   {
00241 //       this->ready(requested_address);
00242   }
00243 
00244   void ac_mem::response_write()
00245   {
00246        this->ready();
00247   }
00248 
00249   void ac_mem::response_write_block()
00250   {
00251 /*      replace_status++;
00252        if(read_access_type)
00253             this->replaceBlockRead(requested_address);
00254        else
00255             this->replaceBlockWrite();
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 //       this->previous_level = (ac_mem&)&previous;
00271   }
00272 
00273 
00274 

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