source: trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp @ 137

Last change on this file since 137 was 137, checked in by simerabe, 13 years ago

replacing old ring versions with new one

  • Property svn:executable set to *
File size: 18.4 KB
Line 
1#include <systemc>
2#include <sys/time.h>
3#include <iostream>
4#include <sstream>
5#include <cstdlib>
6#include <cstdarg>
7#include <stdint.h>
8#include <fstream>
9
10#include "mapping_table.h"
11#include "mips32.h"
12#include "vci_simhelper.h"
13#include "vci_simple_ram.h"
14#include "vci_multi_tty.h"
15#include "vci_xicu.h"
16#include "vci_simple_ring_fast.h"
17#include "vci_mem_cache_v4.h"
18#include "vci_cc_xcache_wrapper_v4.h"
19#include "alloc_elems.h"
20
21#include "iss/gdbserver.h"
22
23#include "segmentation.h"
24
25//===========================================
26// Define before include
27//===========================================
28
29// Parameters
30// * Platforms
31#  define PARAM_VCI                         4,8,32,1,1,1,8,4,4,1
32
33#  define NB_PROC_MIN                       1
34#  define NB_PROC_MAX                       15
35//                                          min_latency, fifo_depth
36#  define PARAM_RING_P                      2
37#  define PARAM_RING_C                      2
38#  define PARAM_RING_X                      2
39//                                          pti    , hwi    , wti, irq
40#  define PARAM_XICU                        nb_proc, nb_proc, 0  , nb_proc
41
42// * Debug
43#  define DEBUG_TOP                         0
44#  define SOCVIEW                           0
45#  define STOP_SIMULATION_NB_FRZ_CYCLES     100000
46                                           
47// * Simulation                             
48#  define FILE_DEFAULT                      "configuration/default.cfg"
49#  define NCYCLES_DEFAULT                   0
50#  define SOFT_DEFAULT                      "soft/bin.soft"
51//===========================================
52
53void usage (char * funcname)
54{
55  std::cout << funcname << " [nb_cycle [file [soft]]] " << std::endl;
56  std::cout << " * nb_cycle : number of simulated cycle, if 0 then no stop condition. (default : " << NCYCLES_DEFAULT << " cycle(s))" << std::endl;
57  std::cout << " * file     : Configuration file : nb_proc, iways, isets, iwords, dways, dsets, dwords, wnwords, wnlines, wtimeout, memc_nways, memc_nsets, memc_words, memc_heap_size. (default : " << FILE_DEFAULT << " cycle(s))" << std::endl;
58  std::cout << " * soft     : software executed by this platforms. (default : \"" << SOFT_DEFAULT << "\")" << std::endl;
59
60  exit(1);
61}
62
63int _main(int argc, char *argv[])
64{
65        if ((argc < 1) or (argc > 4))
66          {
67            std::cout << "Invalid parameters number." << std::endl;
68            usage(argv[0]);
69          }
70
71#if not SOCVIEW
72        int  ncycles = 0;
73
74        if (argc >= 2)
75          ncycles = std::atoi(argv[1]);
76        else
77          ncycles = NCYCLES_DEFAULT;
78
79        if (ncycles == 0)
80          ncycles = -1;
81#endif
82
83        uint32_t nb_proc;
84        uint32_t iways, isets, iwords;
85        uint32_t dways, dsets, dwords;
86        uint32_t wnwords, wnlines, wtimeout;
87        uint32_t memc_nways, memc_nsets, memc_words, memc_heap_size;
88
89        std::ifstream inFile;
90        const char * filename = (argc>=3)?argv[2]:FILE_DEFAULT;
91
92        inFile.open(filename);
93       
94        if (!inFile) 
95          {
96            std::cout << "Can't open file : \"" << filename << "\"." << std::endl;
97            usage(argv[0]);
98          }
99
100        std::string str;
101        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
102        nb_proc         =std::atoi(str.c_str());
103        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
104        iways           =std::atoi(str.c_str());
105        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
106        isets           =std::atoi(str.c_str());
107        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
108        iwords          =std::atoi(str.c_str());
109        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
110        dways           =std::atoi(str.c_str());
111        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
112        dsets           =std::atoi(str.c_str());
113        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
114        dwords          =std::atoi(str.c_str());
115        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
116        wnwords         =std::atoi(str.c_str());
117        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
118        wnlines         =std::atoi(str.c_str());
119        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
120        wtimeout        =std::atoi(str.c_str());
121        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
122        memc_nways      =std::atoi(str.c_str());
123        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
124        memc_nsets      =std::atoi(str.c_str());
125        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
126        memc_words      =std::atoi(str.c_str());
127        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
128        memc_heap_size  =std::atoi(str.c_str());
129
130        if ((nb_proc<NB_PROC_MIN) or
131            (nb_proc>NB_PROC_MAX))
132          {
133            std::cout << "Parameters nb_proc is out of bound." << std::endl;
134            usage(argv[0]);
135          }
136
137        char * soft;
138
139        if (argc >= 4)
140          soft = argv[3];
141        else
142          soft = SOFT_DEFAULT;
143
144        std::cout << "  * Parameters : " << std::endl;
145        std::cout << "    * nb_proc          : " << nb_proc          << std::endl;
146        std::cout << "    * iways            : " << iways            << std::endl;
147        std::cout << "    * isets            : " << isets            << std::endl;
148        std::cout << "    * iwords           : " << iwords           << std::endl;
149        std::cout << "    * dways            : " << dways            << std::endl;
150        std::cout << "    * dsets            : " << dsets            << std::endl;
151        std::cout << "    * dwords           : " << dwords           << std::endl;
152        std::cout << "    * wnwords          : " << wnwords          << std::endl;
153        std::cout << "    * wnlines          : " << wnlines          << std::endl;
154        std::cout << "    * wtimeout         : " << wtimeout         << std::endl;
155        std::cout << "    * memc_nways       : " << memc_nways       << std::endl;
156        std::cout << "    * memc_nsets       : " << memc_nsets       << std::endl;
157        std::cout << "    * memc_words       : " << memc_words       << std::endl;
158        std::cout << "    * memc_heap_size   : " << memc_heap_size   << std::endl;
159        std::cout << "  * Simulation : " << std::endl;
160        std::cout << "    * ncycles          : " << ncycles          << std::endl;
161        std::cout << "    * soft             : " << soft             << std::endl;
162
163        using namespace sc_core;
164        // Avoid repeating these everywhere
165        using soclib::common::IntTab;
166        using soclib::common::Segment;
167
168        // Define VCI parameters
169        typedef soclib::caba::VciParams<PARAM_VCI> vci_param;
170        typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
171        // Mapping table
172
173        soclib::common::MappingTable maptabp(32, IntTab(8), IntTab(8), 0x00300000); // size, level_addr_bits, level_id_bits, cacheability_mask
174
175        maptabp.add(Segment("reset"    , RESET_BASE    , RESET_SIZE    , IntTab(2), true));
176        maptabp.add(Segment("excep"    , EXCEP_BASE    , EXCEP_SIZE    , IntTab(2), true));
177
178        maptabp.add(Segment("tty"      , TTY_BASE      , TTY_SIZE      , IntTab(1), false));
179        maptabp.add(Segment("text"     , TEXT_BASE     , TEXT_SIZE     , IntTab(2), true));
180        maptabp.add(Segment("mc_r"     , MC_R_BASE     , MC_R_SIZE     , IntTab(2), false, true, IntTab(0)));
181        maptabp.add(Segment("mc_m"     , MC_M_BASE     , MC_M_SIZE     , IntTab(2), true));
182        // maptabp.add(Segment("ptba"     , PTD_ADDR      , TAB_SIZE      , IntTab(2), true));
183        maptabp.add(Segment("xicu"     , XICU_BASE     , XICU_SIZE     , IntTab(3), false));
184        maptabp.add(Segment("simhelper", SIMHELPER_BASE, SIMHELPER_SIZE, IntTab(4), false));
185 
186        std::cout << maptabp << std::endl;
187
188        soclib::common::MappingTable maptabc(32, IntTab(8), IntTab(8), 0x00300000);
189        for (uint32_t i=0; i<nb_proc; ++i)
190        {
191          std::ostringstream str;
192          str << "c_proc_" << i;
193          maptabc.add(Segment(str.str().c_str(), C_PROC_BASE+i*C_PROC_SPAN, C_PROC_SIZE , IntTab(i), false, true, IntTab(i)));
194        }
195        maptabc.add(Segment("mc_r"    , MC_R_BASE  , MC_R_SIZE   , IntTab(nb_proc), false, false));
196        maptabc.add(Segment("mc_m"    , MC_M_BASE  , MC_M_SIZE   , IntTab(nb_proc), false, false));
197        maptabc.add(Segment("reset"   , RESET_BASE , RESET_SIZE  , IntTab(nb_proc), false, false));
198        maptabc.add(Segment("excep"   , EXCEP_BASE , EXCEP_SIZE  , IntTab(nb_proc), false, false));
199        maptabc.add(Segment("text"    , TEXT_BASE  , TEXT_SIZE   , IntTab(nb_proc), false, false));
200        // maptabc.add(Segment("ptba"    , PTD_ADDR   , TAB_SIZE    , IntTab(nb_proc), false, false));
201
202        std::cout << maptabc << std::endl;
203       
204        soclib::common::MappingTable maptabx(32, IntTab(8), IntTab(8), 0x00300000);
205        maptabx.add(Segment("xram" , MC_M_BASE , MC_M_SIZE , IntTab(0), false));
206        maptabx.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(0), false));
207        maptabx.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(0), false));
208        maptabx.add(Segment("text" , TEXT_BASE , TEXT_SIZE , IntTab(0), false));
209        // maptabx.add(Segment("ptba" , PTD_ADDR  , TAB_SIZE  , IntTab(0), false));
210       
211        std::cout << maptabx << std::endl;
212
213        // Signals
214        sc_clock        signal_clk("clk");
215        sc_signal<bool> signal_resetn("resetn");
216   
217        sc_signal<bool> ** signal_proc_it = soclib::common::alloc_elems<sc_signal<bool> >("proc_it", nb_proc, 6);
218
219        soclib::caba::VciSignals<vci_param> * signal_vci_ini_rw_proc = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("vci_ini_rw_proc", nb_proc);
220        soclib::caba::VciSignals<vci_param> * signal_vci_ini_c_proc  = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("vci_ini_c_proc" , nb_proc);
221        soclib::caba::VciSignals<vci_param> * signal_vci_tgt_proc    = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("vci_tgt_proc"   , nb_proc);
222
223        soclib::caba::VciSignals<vci_param> signal_vci_tgt_tty("vci_tgt_tty");
224
225        soclib::caba::VciSignals<vci_param> signal_vci_tgt_simhelper("signal_vci_tgt_simhelper");
226
227        soclib::caba::VciSignals<vci_param> signal_vci_tgt_rom("vci_tgt_rom");
228
229        soclib::caba::VciSignals<vci_param> signal_vci_tgt_xram("vci_tgt_xram");
230
231        soclib::caba::VciSignals<vci_param> signal_vci_tgt_xicu("vci_tgt_xicu");
232
233        soclib::caba::VciSignals<vci_param> signal_vci_ixr_memc("vci_ixr_memc");
234        soclib::caba::VciSignals<vci_param> signal_vci_ini_memc("vci_ini_memc");
235        soclib::caba::VciSignals<vci_param> signal_vci_tgt_memc("vci_tgt_memc");
236        soclib::caba::VciSignals<vci_param> signal_vci_tgt_cleanup_memc("vci_tgt_cleanup_memc");
237
238        sc_signal<bool> * signal_tty_irq = soclib::common::alloc_elems<sc_signal<bool> >("signal_tty_irq", nb_proc);
239
240        soclib::common::Loader loader(soft);
241
242        soclib::common::GdbServer<soclib::common::Mips32ElIss>::set_loader(loader);
243
244        soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > * proc [nb_proc];
245        for (uint32_t i=0; i<nb_proc; ++i)
246          {
247            std::ostringstream str;
248            str << "proc_" << i;
249
250            proc[i] = new soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > (str.str().c_str(), i, maptabp, maptabc, IntTab(i),IntTab(i),IntTab(i)
251                                                                                    ,iways, isets, iwords
252                                                                                    ,dways, dsets, dwords
253                                                                                    ,wnwords, wnlines, wtimeout
254                                                                                    );
255
256#if not USE_OLD_XCACHE
257            proc[i]->stop_simulation(STOP_SIMULATION_NB_FRZ_CYCLES);
258#endif
259          }
260
261        soclib::caba::VciSimpleRam<vci_param> 
262        rom ("rom", IntTab(0), maptabp, loader);
263
264        soclib::caba::VciSimpleRam<vci_param> 
265        xram("xram", IntTab(0), maptabx, loader);
266
267        //                                  x_init    c_init          p_tgt     c_tgt
268        soclib::caba::VciMemCacheV4<vci_param> 
269          memc("memc",maptabp,maptabc,maptabx,IntTab(0),IntTab(nb_proc),IntTab(2),IntTab(nb_proc), memc_nways, memc_nsets, memc_words, memc_heap_size);
270
271        std::vector<std::string> tty_name;
272        for (uint32_t i=0; i<nb_proc; ++i)
273          {
274            std::ostringstream str;
275            str << "tty_" << i;
276
277            tty_name.push_back(str.str());
278          }
279       
280        soclib::caba::VciMultiTty<vci_param> 
281        tty("tty",IntTab(1),maptabp,tty_name);
282
283        soclib::caba::VciXicu<vci_param> 
284        xicu("xicu", maptabp, IntTab(3), PARAM_XICU);
285
286        // soclib::caba::VciTimer<vci_param>
287        // timer("timer", IntTab(3), maptabp, nb_proc);
288
289        soclib::caba::VciSimhelper<vci_param> 
290        simhelper("simhelper", IntTab(4), maptabp);
291
292        //                  initiatior | target
293        // interconnect_p : proc       | rom, tty, memc, xicu, simhelper
294        // interconnect_c : proc, memc | proc, memc
295        // interconnect_x : memc       | xram
296
297        soclib::caba::VciSimpleRingFast<vci_param,40,33> 
298        interconnect_p("interconnect_p",maptabp, IntTab(), PARAM_RING_P,nb_proc  , 5        );
299
300        soclib::caba::VciSimpleRingFast<vci_param,40,33>
301        interconnect_c("interconnect_c",maptabc, IntTab(), PARAM_RING_C,nb_proc+1, nb_proc+1);
302
303        soclib::caba::VciSimpleRingFast<vci_param,40,33>
304        interconnect_x("interconnect_x",maptabx, IntTab(), PARAM_RING_X,1        , 1        );
305
306        // Net-List
307        for (uint32_t i=0; i<nb_proc; ++i)
308          {
309            proc[i]->p_clk(signal_clk); 
310            proc[i]->p_resetn(signal_resetn); 
311            proc[i]->p_irq[0](signal_proc_it[i][0]); 
312            proc[i]->p_irq[1](signal_proc_it[i][1]); 
313            proc[i]->p_irq[2](signal_proc_it[i][2]); 
314            proc[i]->p_irq[3](signal_proc_it[i][3]); 
315            proc[i]->p_irq[4](signal_proc_it[i][4]); 
316            proc[i]->p_irq[5](signal_proc_it[i][5]); 
317            proc[i]->p_vci_ini_rw(signal_vci_ini_rw_proc[i]);
318            proc[i]->p_vci_ini_c(signal_vci_ini_c_proc[i]);
319            proc[i]->p_vci_tgt(signal_vci_tgt_proc[i]);
320          }
321
322        rom.p_clk(signal_clk);
323        rom.p_resetn(signal_resetn);
324        rom.p_vci(signal_vci_tgt_rom);
325
326        tty.p_clk(signal_clk);
327        tty.p_resetn(signal_resetn);
328        tty.p_vci(signal_vci_tgt_tty);
329        for (uint32_t i=0; i<nb_proc; ++i)
330          tty.p_irq[i](signal_tty_irq[i]); 
331
332        xicu.p_clk(signal_clk);
333        xicu.p_resetn(signal_resetn);
334        xicu.p_vci(signal_vci_tgt_xicu);
335        for (uint32_t i=0; i<nb_proc; ++i)
336        {
337          xicu.p_hwi[i](signal_tty_irq[i]);
338          xicu.p_irq[i](signal_proc_it[i][0]); 
339        }
340
341        simhelper.p_clk(signal_clk);
342        simhelper.p_resetn(signal_resetn);
343        simhelper.p_vci(signal_vci_tgt_simhelper);
344
345        memc.p_clk(signal_clk);
346        memc.p_resetn(signal_resetn);
347        memc.p_vci_tgt(signal_vci_tgt_memc);
348        memc.p_vci_tgt_cleanup(signal_vci_tgt_cleanup_memc);
349        memc.p_vci_ini(signal_vci_ini_memc);
350        memc.p_vci_ixr(signal_vci_ixr_memc);
351
352        xram.p_clk(signal_clk);
353        xram.p_resetn(signal_resetn);
354        xram.p_vci(signal_vci_tgt_xram);
355       
356        interconnect_p.p_clk(signal_clk);
357        interconnect_p.p_resetn(signal_resetn);
358
359        for (uint32_t i=0; i<nb_proc; ++i)
360        interconnect_p.p_to_initiator[i](signal_vci_ini_rw_proc[i]);
361
362        interconnect_p.p_to_target[0](signal_vci_tgt_rom);
363        interconnect_p.p_to_target[1](signal_vci_tgt_tty);
364        interconnect_p.p_to_target[2](signal_vci_tgt_memc);
365        interconnect_p.p_to_target[3](signal_vci_tgt_xicu);
366        interconnect_p.p_to_target[4](signal_vci_tgt_simhelper);
367
368        interconnect_c.p_clk(signal_clk);
369        interconnect_c.p_resetn(signal_resetn);
370
371        for (uint32_t i=0; i<nb_proc; ++i)
372        interconnect_c.p_to_initiator[i](signal_vci_ini_c_proc[i]);
373        interconnect_c.p_to_initiator[nb_proc](signal_vci_ini_memc);
374
375        for (uint32_t i=0; i<nb_proc; ++i)
376        interconnect_c.p_to_target[i](signal_vci_tgt_proc[i]);
377        interconnect_c.p_to_target[nb_proc](signal_vci_tgt_cleanup_memc);
378
379        interconnect_x.p_clk(signal_clk);
380        interconnect_x.p_resetn(signal_resetn);
381
382        interconnect_x.p_to_initiator[0](signal_vci_ixr_memc);
383
384        interconnect_x.p_to_target[0](signal_vci_tgt_xram);
385
386        sc_start(sc_core::sc_time(0, SC_NS));
387        signal_resetn = false;
388        sc_start(sc_core::sc_time(1, SC_NS));
389        signal_resetn = true;
390
391#if SOCVIEW
392        debug();
393#elif DEBUG_TOP
394        for (int32_t i=0; i<ncycles; ++i)
395          {
396            std::cout << std::endl
397                      << std::dec << "===== [ cycle " << i << " ]======" << std::endl
398                      << std::endl;
399           
400            sc_start(sc_core::sc_time(1, SC_NS));
401           
402            // for (uint32_t i=0; i<nb_proc; ++i)
403            //   proc[i]->print_trace(1);
404          }
405#else
406        if (ncycles==-1)
407          sc_start();
408        else
409          sc_start(sc_core::sc_time(ncycles, SC_NS));
410
411        // std::cout << "Hit ENTER to end simulation" << std::endl;
412        // char buf[1];
413        // std::cin.getline(buf,1);
414#endif
415        for (uint32_t i=0; i<nb_proc; ++i)
416          proc[i]->print_cpi();
417        for (uint32_t i=0; i<nb_proc; ++i)
418          proc[i]->print_stats();
419
420        soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_tty_irq         , nb_proc);
421        soclib::common::dealloc_elems<soclib::caba::VciSignals<vci_param> >(signal_vci_tgt_proc    , nb_proc);
422        soclib::common::dealloc_elems<soclib::caba::VciSignals<vci_param> >(signal_vci_ini_c_proc  , nb_proc);
423        soclib::common::dealloc_elems<soclib::caba::VciSignals<vci_param> >(signal_vci_ini_rw_proc , nb_proc);
424        soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_proc_it         , nb_proc, 6);
425
426        for (uint32_t i=0; i<nb_proc; ++i)
427          delete proc[i];
428
429        return EXIT_SUCCESS;
430}
431
432int sc_main (int argc, char *argv[])
433{
434  try {
435    return _main(argc, argv);
436  } catch (std::exception &e) {
437    std::cout << e.what() << std::endl;
438  } catch (...) {
439    std::cout << "Unknown exception occured" << std::endl;
440    throw;
441  }
442  return 1;
443}
Note: See TracBrowser for help on using the repository browser.