source: branches/reconfiguration/platforms/tsar_generic_iob/top.cpp @ 778

Last change on this file since 778 was 778, checked in by cfuguet, 10 years ago

reconfiguration/tsar_generic_iob: fixing python version incompatibility issues

File size: 69.8 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2// File: top.cpp  (for tsar_generic_iob platform)
3// Author: Alain Greiner
4// Copyright: UPMC/LIP6
5// Date : august 2013
6// This program is released under the GNU public license
7///////////////////////////////////////////////////////////////////////////////
8// This file define a generic TSAR architecture with an IO network emulating
9// an external bus (i.e. Hypertransport) to access 7 external peripherals:
10//
11// - FBUF : Frame Buffer
12// - MTTY : multi TTY (one channel)
13// - MNIC : Network controller (up to 2 channels)
14// - CDMA : Chained Buffer DMA controller (up to 4 channels)
15// - BDEV : Dlock Device controler (one channel)
16// - IOPI : HWI to SWI translator.
17//
18// The internal physical address space is 40 bits, and the cluster index
19// is defined by the 8 MSB bits, using a fixed format: X is encoded on 4 bits,
20// Y is encodes on 4 bits, whatever the actual mesh size.
21// => at most 16 * 16 clusters. Each cluster contains up to 4 processors.
22//
23// It contains 3 networks:
24//
25// 1) the "INT" network supports Read/Write transactions
26//    between processors and L2 caches or peripherals.
27//    (VCI ADDDRESS = 40 bits / VCI DATA width = 32 bits)
28//    It supports also coherence transactions between L1 & L2 caches.
29// 3) the "RAM" network emulates the 3D network between L2 caches
30//    and L3 caches, and is implemented as a 2D mesh between the L2 caches,
31//    the two IO bridges and the physical RAMs disributed in all clusters.
32//    (VCI ADDRESS = 40 bits / VCI DATA = 64 bits)
33// 4) the IOX network connects the two IO bridge components to the
34//    7 external peripheral controllers.
35//    (VCI ADDDRESS = 40 bits / VCI DATA width = 64 bits)
36//
37// The external peripherals HWI IRQs are translated to WTI IRQs by the
38// external IOPIC component, that must be configured by the OS to route
39// these WTI ITQS to one or several internal XICU components.
40// - IOPIC HWI[1:0]     connected to IRQ_NIC_RX[1:0]
41// - IOPIC HWI[3:2]     connected to IRQ_NIC_TX[1:0]
42// - IOPIC HWI[7:4]     connected to IRQ_CMA_TX[3:0]]
43// - IOPIC HWI[8]       connected to IRQ_BDEV
44// - IOPIC HWI[9]       connected to IRQ_TTY_RX[0]
45// - IOPIC HWI[31:9]    unused       (grounded)
46//
47// Besides the external peripherals, each cluster contains one XICU component,
48// and one multi channels DMA component.
49// The XICU component is mainly used to handle WTI IRQs, as only 5 HWI IRQs
50// are connected to XICU in each cluster:
51// - IRQ_IN[0] : MMC
52// - IRQ_IN[1] : DMA channel 0
53// - IRQ_IN[2] : DMA channel 1
54// - IRQ_IN[3] : DMA channel 2
55// - IRQ_IN[4] : DMA channel 3
56//
57// All clusters are identical, but cluster(0,0) and cluster(XMAX-1,YMAX-1)
58// contain an extra IO bridge component. These IOB0 & IOB1 components are
59// connected to the three networks (INT, RAM, IOX).
60//
61// - It uses two dspin_local_crossbar per cluster to implement the
62//   local interconnect correponding to the INT network.
63// - It uses three dspin_local_crossbar per cluster to implement the
64//   local interconnect correponding to the coherence INT network.
65// - It uses two virtual_dspin_router per cluster to implement
66//   the INT network (routing both the direct and coherence trafic).
67// - It uses two dspin_router per cluster to implement the RAM network.
68// - It uses the vci_cc_vcache_wrapper.
69// - It uses the vci_mem_cache.
70// - It contains one vci_xicu and one vci_multi_dma per cluster.
71// - It contains one vci_simple ram per cluster to model the L3 cache.
72//
73// The TsarIobCluster component is defined in files
74// tsar_iob_cluster.* (with * = cpp, h, sd)
75//
76// The main hardware parameters must be defined in the hard_config.h file :
77// - X_SIZE           : number of clusters in a row
78// - Y_SIZE           : number of clusters in a column
79// - NB_PROCS_MAX     : number of processors per cluster (power of 2)
80// - NB_TTY_CHANNELS  : number of TTY channels in I/O network (must be 1)
81// - NB_NIC_CHANNELS  : number of NIC channels in I/O network (up to 2)
82// - NB_CMA_CHANNELS  : number of CMA channels in I/O network (up to 4)
83// - FBUF_X_SIZE      : width of frame buffer (pixels)
84// - FBUF_Y_SIZE      : heigth of frame buffer (lines)
85// - XCU_NB_INPUTS    : number of HWIs = number of WTIs = number of PTIs
86//
87// Some secondary hardware parameters must be defined in this top.cpp file:
88// - XRAM_LATENCY     : external ram latency
89// - MEMC_WAYS        : L2 cache number of ways
90// - MEMC_SETS        : L2 cache number of sets
91// - L1_IWAYS
92// - L1_ISETS
93// - L1_DWAYS
94// - L1_DSETS
95// - BDEV_IMAGE_NAME  : file pathname for block device
96// - NIC_RX_NAME      : file pathname for NIC received packets
97// - NIC_TX_NAME      : file pathname for NIC transmited packets
98// - NIC_TIMEOUT      : max number of cycles before closing a container
99//
100// General policy for 40 bits physical address decoding:
101// All physical segments base addresses are multiple of 1 Mbytes
102// (=> the 24 LSB bits = 0, and the 16 MSB bits define the target)
103// The (x_width + y_width) MSB bits (left aligned) define
104// the cluster index, and the LADR bits define the local index:
105//      |X_ID|Y_ID|  LADR  |     OFFSET          |
106//      |  4 |  4 |   8    |       24            |
107//
108// General policy for 14 bits SRCID decoding:
109// Each component is identified by (x_id, y_id, l_id) tuple.
110//      |X_ID|Y_ID| L_ID |
111//      |  4 |  4 |  6   |
112/////////////////////////////////////////////////////////////////////////
113
114#include <systemc>
115#include <sys/time.h>
116#include <iostream>
117#include <sstream>
118#include <cstdlib>
119#include <cstdarg>
120#include <climits>
121#include <stdint.h>
122
123#include "gdbserver.h"
124#include "mapping_table.h"
125
126#include "tsar_iob_cluster.h"
127#include "vci_chbuf_dma.h"
128#include "vci_multi_tty.h"
129#include "vci_multi_nic.h"
130#include "vci_simple_rom.h"
131#include "vci_block_device_tsar.h"
132#include "vci_framebuffer.h"
133#include "vci_iox_network.h"
134#include "vci_iox_network.h"
135#include "vci_iopic.h"
136#include "vci_simhelper.h"
137
138#include "alloc_elems.h"
139
140///////////////////////////////////////////////////
141//      OS
142///////////////////////////////////////////////////
143#define USE_ALMOS 0
144
145#define almos_bootloader_pathname "bootloader.bin"
146#define almos_kernel_pathname     "kernel-soclib.bin@0xbfc10000:D"
147#define almos_archinfo_pathname   "arch-info.bin@0xBFC08000:D"
148
149///////////////////////////////////////////////////
150//               Parallelisation
151///////////////////////////////////////////////////
152#if USE_OPENMP
153#include <omp.h>
154#endif
155
156///////////////////////////////////////////////////////////
157//          DSPIN parameters
158///////////////////////////////////////////////////////////
159
160#define dspin_int_cmd_width   39
161#define dspin_int_rsp_width   32
162
163#define dspin_ram_cmd_width   64
164#define dspin_ram_rsp_width   64
165
166///////////////////////////////////////////////////////////
167//         VCI fields width  for the 3 VCI networks
168///////////////////////////////////////////////////////////
169
170#define vci_cell_width_int    4
171#define vci_cell_width_ext    8
172
173#define vci_plen_width        8
174#define vci_address_width     40
175#define vci_rerror_width      1
176#define vci_clen_width        1
177#define vci_rflag_width       1
178#define vci_srcid_width       14
179#define vci_pktid_width       4
180#define vci_trdid_width       4
181#define vci_wrplen_width      1
182
183////////////////////////////////////////////////////////////
184//    Main Hardware Parameters values
185//////////////////////i/////////////////////////////////////
186
187#include "hard_config.h"
188
189////////////////////////////////////////////////////////////
190//    Secondary Hardware Parameters values
191//////////////////////i/////////////////////////////////////
192
193#define XMAX                  X_SIZE
194#define YMAX                  Y_SIZE
195
196#define XRAM_LATENCY          0
197
198#define MEMC_WAYS             16
199#define MEMC_SETS             256
200
201#define L1_IWAYS              4
202#define L1_ISETS              64
203
204#define L1_DWAYS              4
205#define L1_DSETS              64
206
207#define BDEV_IMAGE_NAME       "../../../giet_vm/hdd/virt_hdd.dmg"
208
209#define NIC_RX_NAME           "/dev/null"
210#define NIC_TX_NAME           "/dev/null"
211#define NIC_TIMEOUT           10000
212
213#define NORTH                 0
214#define SOUTH                 1
215#define EAST                  2
216#define WEST                  3
217
218#define cluster(x,y)   ((y) + ((x) << 4))
219
220////////////////////////////////////////////////////////////
221//    Software to be loaded in ROM & RAM
222//////////////////////i/////////////////////////////////////
223
224#define BOOT_SOFT_NAME        "../../softs/tsar_boot/preloader.elf"
225
226////////////////////////////////////////////////////////////
227//     DEBUG Parameters default values
228//////////////////////i/////////////////////////////////////
229
230#define MAX_FROZEN_CYCLES     200000
231
232/////////////////////////////////////////////////////////
233//    Physical segments definition
234/////////////////////////////////////////////////////////
235
236// All physical segments base addresses and sizes are defined
237// in the hard_config.h file. For replicated segments, the
238// base address is incremented by a cluster offset:
239// offset  = cluster(x,y) << (address_width-x_width-y_width);
240
241////////////////////////////////////////////////////////////////////////
242//          SRCID definition
243////////////////////////////////////////////////////////////////////////
244// All initiators are in the same indexing space (14 bits).
245// The SRCID is structured in two fields:
246// - The 10 MSB bits define the cluster index (left aligned)
247// - The 4  LSB bits define the local index.
248// Two different initiators cannot have the same SRCID, but a given
249// initiator can have two alias SRCIDs:
250// - Internal initiators (procs, mdma) are replicated in all clusters,
251//   and each initiator has one single SRCID.
252// - External initiators (bdev, cdma) are not replicated, but can be
253//   accessed in 2 clusters : cluster_iob0 and cluster_iob1.
254//   They have the same local index, but two different cluster indexes.
255//
256// As cluster_iob0 and cluster_iob1 contain both internal initiators
257// and external initiators, they must have different local indexes.
258// Consequence: For a local interconnect, the INI_ID port index
259// is NOT equal to the SRCID local index, and the local interconnect
260// must make a translation: SRCID => INI_ID
261////////////////////////////////////////////////////////////////////////
262
263#define PROC_LOCAL_SRCID             0x0    // from 0 to 7
264#define MDMA_LOCAL_SRCID             0x8
265#define IOBX_LOCAL_SRCID             0x9
266#define MEMC_LOCAL_SRCID             0xA
267#define CDMA_LOCAL_SRCID             0xB
268#define BDEV_LOCAL_SRCID             0xC
269#define IOPI_LOCAL_SRCID             0xD
270
271///////////////////////////////////////////////////////////////////////
272//     TGT_ID and INI_ID port indexing for INT local interconnect
273///////////////////////////////////////////////////////////////////////
274
275#define INT_MEMC_TGT_ID              0
276#define INT_XICU_TGT_ID              1
277#define INT_MDMA_TGT_ID              2
278#define INT_BROM_TGT_ID              3
279#define INT_IOBX_TGT_ID              4
280
281#define INT_PROC_INI_ID              0   // from 0 to (NB_PROCS_MAX-1)
282#define INT_MDMA_INI_ID              (NB_PROCS_MAX)
283#define INT_IOBX_INI_ID              (NB_PROCS_MAX+1)
284
285///////////////////////////////////////////////////////////////////////
286//     TGT_ID and INI_ID port indexing for RAM local interconnect
287///////////////////////////////////////////////////////////////////////
288
289#define RAM_XRAM_TGT_ID              0
290
291#define RAM_MEMC_INI_ID              0
292#define RAM_IOBX_INI_ID              1
293
294///////////////////////////////////////////////////////////////////////
295//     TGT_ID and INI_ID port indexing for I0X local interconnect
296///////////////////////////////////////////////////////////////////////
297
298#define IOX_FBUF_TGT_ID              0
299#define IOX_BDEV_TGT_ID              1
300#define IOX_MNIC_TGT_ID              2
301#define IOX_CDMA_TGT_ID              3
302#define IOX_MTTY_TGT_ID              4
303#define IOX_IOPI_TGT_ID              5
304#define IOX_SIMH_TGT_ID              6
305#define IOX_IOB0_TGT_ID              7
306#define IOX_IOB1_TGT_ID              8
307
308#define IOX_BDEV_INI_ID              0
309#define IOX_CDMA_INI_ID              1
310#define IOX_IOPI_INI_ID              2
311#define IOX_IOB0_INI_ID              3
312#define IOX_IOB1_INI_ID              4
313
314////////////////////////////////////////////////////////////////////////
315int _main(int argc, char *argv[])
316////////////////////////////////////////////////////////////////////////
317{
318   using namespace sc_core;
319   using namespace soclib::caba;
320   using namespace soclib::common;
321
322
323   char     soft_name[256]   = BOOT_SOFT_NAME;             // pathname: binary code
324   size_t   ncycles          = UINT_MAX;                   // simulated cycles
325   char     disk_name[256]   = BDEV_IMAGE_NAME;            // pathname: disk image
326   char     nic_rx_name[256] = NIC_RX_NAME;                // pathname: rx packets file
327   char     nic_tx_name[256] = NIC_TX_NAME;                // pathname: tx packets file
328   ssize_t  threads_nr       = 1;                          // simulator's threads number
329   bool     debug_ok         = false;                      // trace activated
330   size_t   debug_period     = 1;                          // trace period
331   size_t   debug_memc_id    = 0xFFFFFFFF;                 // index of traced memc
332   size_t   debug_proc_id    = 0xFFFFFFFF;                 // index of traced proc
333   size_t   debug_xram_id    = 0xFFFFFFFF;                 // index of traced xram
334   bool     debug_iob        = false;                      // trace iob0 & iob1 when true
335   uint32_t debug_from       = 0;                          // trace start cycle
336   uint32_t frozen_cycles    = MAX_FROZEN_CYCLES;          // monitoring frozen processor
337   size_t   cluster_iob0     = cluster(0,0);               // cluster containing IOB0
338   size_t   cluster_iob1     = cluster(XMAX-1,YMAX-1);     // cluster containing IOB1
339   size_t   x_width          = 4;                          // at most 256 clusters
340   size_t   y_width          = 4;                          // at most 256 clusters
341
342   assert( (X_WIDTH == 4) and (Y_WIDTH == 4) and
343   "ERROR: we must have X_WIDTH == Y_WIDTH == 4");
344
345   ////////////// command line arguments //////////////////////
346   if (argc > 1)
347   {
348      for (int n = 1; n < argc; n = n + 2)
349      {
350         if ((strcmp(argv[n],"-NCYCLES") == 0) && (n+1<argc))
351         {
352            ncycles = strtol(argv[n+1], NULL, 0);
353         }
354         else if ((strcmp(argv[n],"-SOFT") == 0) && (n+1<argc) )
355         {
356            strcpy(soft_name, argv[n+1]);
357         }
358         else if ((strcmp(argv[n],"-DEBUG") == 0) && (n+1<argc) )
359         {
360            debug_ok = true;
361            debug_from = strtol(argv[n+1], NULL, 0);
362         }
363         else if ((strcmp(argv[n],"-DISK") == 0) && (n+1<argc) )
364         {
365            strcpy(disk_name, argv[n+1]);
366         }
367         else if ((strcmp(argv[n],"-MEMCID") == 0) && (n+1<argc) )
368         {
369            debug_memc_id = strtol(argv[n+1], NULL, 0);
370            size_t x = debug_memc_id >> 4;
371            size_t y = debug_memc_id & 0xF;
372            if( (x>=XMAX) || (y>=YMAX) )
373            {
374                std::cout << "MEMCID parameter does'nt fit XMAX/YMAX" << std::endl;
375                exit(0);
376            }
377         }
378         else if ((strcmp(argv[n],"-XRAMID") == 0) && (n+1<argc) )
379         {
380            debug_xram_id = strtol(argv[n+1], NULL, 0);
381            size_t x = debug_xram_id >> 4;
382            size_t y = debug_xram_id & 0xF;
383            if( (x>=XMAX) || (y>=YMAX) )
384            {
385                std::cout << "XRAMID parameter does'nt fit XMAX/YMAX" << std::endl;
386                exit(0);
387            }
388         }
389         else if ((strcmp(argv[n],"-IOB") == 0) && (n+1<argc) )
390         {
391            debug_iob = strtol(argv[n+1], NULL, 0);
392         }
393         else if ((strcmp(argv[n],"-PROCID") == 0) && (n+1<argc) )
394         {
395            debug_proc_id     = strtol(argv[n+1], NULL, 0);
396            size_t cluster_xy = debug_proc_id / NB_PROCS_MAX ;
397            size_t x          = cluster_xy >> 4;
398            size_t y          = cluster_xy & 0xF;
399            if( (x>=XMAX) || (y>=YMAX) )
400            {
401                std::cout << "PROCID parameter does'nt fit XMAX/YMAX" << std::endl;
402                exit(0);
403            }
404         }
405         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n+1) < argc))
406         {
407            threads_nr = strtol(argv[n+1], NULL, 0);
408            threads_nr = (threads_nr < 1) ? 1 : threads_nr;
409         }
410         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n+1 < argc))
411         {
412            frozen_cycles = strtol(argv[n+1], NULL, 0);
413         }
414         else if ((strcmp(argv[n], "-PERIOD") == 0) && (n+1 < argc))
415         {
416            debug_period = strtol(argv[n+1], NULL, 0);
417         }
418         else
419         {
420            std::cout << "   Arguments are (key,value) couples." << std::endl;
421            std::cout << "   The order is not important." << std::endl;
422            std::cout << "   Accepted arguments are :" << std::endl << std::endl;
423            std::cout << "     -SOFT pathname_for_embedded_soft" << std::endl;
424            std::cout << "     -DISK pathname_for_disk_image" << std::endl;
425            std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl;
426            std::cout << "     -DEBUG debug_start_cycle" << std::endl;
427            std::cout << "     -THREADS simulator's threads number" << std::endl;
428            std::cout << "     -FROZEN max_number_of_lines" << std::endl;
429            std::cout << "     -PERIOD number_of_cycles between trace" << std::endl;
430            std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl;
431            std::cout << "     -XRAMID index_xram_to_be_traced" << std::endl;
432            std::cout << "     -PROCID index_proc_to_be_traced" << std::endl;
433            std::cout << "     -IOB    non_zero_value" << std::endl;
434            exit(0);
435         }
436      }
437   }
438
439   // Activate Distributed Boot (set by environment variable)
440   // When this is activated, every processor boots with its instruction and data
441   // physical address extension register initialized to its cluster index
442   // (X_LOCAL, Y_LOCAL). To support this feature, a distributed ROM is
443   // implemented in each cluster.
444
445   const bool distributed_boot = (getenv("DISTRIBUTED_BOOT") != NULL);
446
447   // checking hardware parameters
448   assert( (XMAX <= 16) and
449           "The XMAX parameter cannot be larger than 16" );
450
451   assert( (YMAX <= 16) and
452           "The YMAX parameter cannot be larger than 16" );
453
454   assert( (NB_PROCS_MAX <= 8) and
455           "The NB_PROCS_MAX parameter cannot be larger than 8" );
456
457   assert( (NB_DMA_CHANNELS <= 4) and
458           "The NB_DMA_CHANNELS parameter cannot be larger than 4" );
459
460   assert( (NB_TTY_CHANNELS == 1) and
461           "The NB_TTY_CHANNELS parameter must be 1" );
462
463   assert( (NB_NIC_CHANNELS == 2) and
464           "The NB_NIC_CHANNELS parameter must be 2" );
465
466   std::cout << std::endl << std::dec
467             << " - XMAX            = " << XMAX << std::endl
468             << " - YMAX            = " << YMAX << std::endl
469             << " - NB_PROCS_MAX    = " << NB_PROCS_MAX <<  std::endl
470             << " - NB_TTY_CHANNELS = " << NB_TTY_CHANNELS <<  std::endl
471             << " - NB_DMA_CHANNELS = " << NB_DMA_CHANNELS <<  std::endl
472             << " - NB_NIC_CHANNELS = " << NB_NIC_CHANNELS <<  std::endl
473             << " - MEMC_WAYS       = " << MEMC_WAYS << std::endl
474             << " - MEMC_SETS       = " << MEMC_SETS << std::endl
475             << " - RAM_LATENCY     = " << XRAM_LATENCY << std::endl
476             << " - MAX_FROZEN      = " << frozen_cycles << std::endl
477             << " - DIST_BOOT       = " << distributed_boot << std::endl
478             << " - DEBUG_PROCID    = " << debug_proc_id << std::endl
479             << " - DEBUG_MEMCID    = " << debug_memc_id << std::endl
480             << " - DEBUG_XRAMID    = " << debug_xram_id << std::endl;
481
482   std::cout << std::endl;
483
484#if USE_OPENMP
485   omp_set_dynamic(false);
486   omp_set_num_threads(threads_nr);
487   std::cerr << "Built with openmp version " << _OPENMP << std::endl;
488#endif
489
490   // Define VciParams objects
491   typedef soclib::caba::VciParams<vci_cell_width_int,
492                                   vci_plen_width,
493                                   vci_address_width,
494                                   vci_rerror_width,
495                                   vci_clen_width,
496                                   vci_rflag_width,
497                                   vci_srcid_width,
498                                   vci_pktid_width,
499                                   vci_trdid_width,
500                                   vci_wrplen_width> vci_param_int;
501
502   typedef soclib::caba::VciParams<vci_cell_width_ext,
503                                   vci_plen_width,
504                                   vci_address_width,
505                                   vci_rerror_width,
506                                   vci_clen_width,
507                                   vci_rflag_width,
508                                   vci_srcid_width,
509                                   vci_pktid_width,
510                                   vci_trdid_width,
511                                   vci_wrplen_width> vci_param_ext;
512
513   /////////////////////////////////////////////////////////////////////
514   // INT network mapping table
515   // - two levels address decoding for commands
516   // - two levels srcid decoding for responses
517   // - NB_PROCS_MAX + 2 (MDMA, IOBX) local initiators per cluster
518   // - 4 local targets (MEMC, XICU, MDMA, IOBX) per cluster
519   /////////////////////////////////////////////////////////////////////
520   MappingTable maptab_int( vci_address_width,
521                            IntTab(x_width + y_width, 16 - x_width - y_width),
522                            IntTab(x_width + y_width, vci_srcid_width - x_width - y_width),
523                            0x00FF000000);
524
525   for (size_t x = 0; x < XMAX; x++)
526   {
527      for (size_t y = 0; y < YMAX; y++)
528      {
529         uint64_t offset = ((uint64_t)cluster(x,y))
530                              << (vci_address_width-x_width-y_width);
531         bool config    = true;
532         bool cacheable = true;
533
534         // the four following segments are defined in all clusters
535
536         std::ostringstream    smemc_conf;
537         smemc_conf << "int_seg_memc_conf_" << x << "_" << y;
538         maptab_int.add(Segment(smemc_conf.str(), SEG_MMC_BASE+offset, SEG_MMC_SIZE,
539                     IntTab(cluster(x,y), INT_MEMC_TGT_ID), not cacheable, config ));
540
541         std::ostringstream    smemc_xram;
542         smemc_xram << "int_seg_memc_xram_" << x << "_" << y;
543         maptab_int.add(Segment(smemc_xram.str(), SEG_RAM_BASE+offset, SEG_RAM_SIZE,
544                     IntTab(cluster(x,y), INT_MEMC_TGT_ID), cacheable));
545
546         std::ostringstream    sxicu;
547         sxicu << "int_seg_xicu_" << x << "_" << y;
548         maptab_int.add(Segment(sxicu.str(), SEG_XCU_BASE+offset, SEG_XCU_SIZE,
549                     IntTab(cluster(x,y), INT_XICU_TGT_ID), not cacheable));
550
551         std::ostringstream    smdma;
552         smdma << "int_seg_mdma_" << x << "_" << y;
553         maptab_int.add(Segment(smdma.str(), SEG_DMA_BASE+offset, SEG_DMA_SIZE,
554                     IntTab(cluster(x,y), INT_MDMA_TGT_ID), not cacheable));
555
556         std::ostringstream    sbrom;
557         sbrom << "int_seg_brom_" << x << "_" << y;
558         maptab_int.add(Segment(sbrom.str(), SEG_ROM_BASE+offset, SEG_ROM_SIZE,
559                     IntTab(cluster(x,y), INT_BROM_TGT_ID), cacheable));
560
561         // the following segments are only defined in cluster_iob0 or in cluster_iob1
562
563         if ( (cluster(x,y) == cluster_iob0) or (cluster(x,y) == cluster_iob1) )
564         {
565            std::ostringstream    siobx;
566            siobx << "int_seg_iobx_" << x << "_" << y;
567            maptab_int.add(Segment(siobx.str(), SEG_IOB_BASE+offset, SEG_IOB_SIZE,
568                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable, config ));
569
570            std::ostringstream    stty;
571            stty << "int_seg_mtty_" << x << "_" << y;
572            maptab_int.add(Segment(stty.str(), SEG_TTY_BASE+offset, SEG_TTY_SIZE,
573                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
574
575            std::ostringstream    sfbf;
576            sfbf << "int_seg_fbuf_" << x << "_" << y;
577            maptab_int.add(Segment(sfbf.str(), SEG_FBF_BASE+offset, SEG_FBF_SIZE,
578                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
579
580            std::ostringstream    sbdv;
581            sbdv << "int_seg_bdev_" << x << "_" << y;
582            maptab_int.add(Segment(sbdv.str(), SEG_IOC_BASE+offset, SEG_IOC_SIZE,
583                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
584
585            std::ostringstream    snic;
586            snic << "int_seg_mnic_" << x << "_" << y;
587            maptab_int.add(Segment(snic.str(), SEG_NIC_BASE+offset, SEG_NIC_SIZE,
588                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
589
590            std::ostringstream    sdma;
591            sdma << "int_seg_cdma_" << x << "_" << y;
592            maptab_int.add(Segment(sdma.str(), SEG_CMA_BASE+offset, SEG_CMA_SIZE,
593                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
594
595            std::ostringstream    spic;
596            spic << "int_seg_iopi_" << x << "_" << y;
597            maptab_int.add(Segment(spic.str(), SEG_PIC_BASE+offset, SEG_PIC_SIZE,
598                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
599
600            std::ostringstream    ssim;
601            ssim << "int_seg_simh_" << x << "_" << y;
602            maptab_int.add(Segment(ssim.str(), SEG_SIM_BASE+offset, SEG_SIM_SIZE,
603                        IntTab(cluster(x,y), INT_IOBX_TGT_ID), not cacheable));
604         }
605
606         // This define the mapping between the SRCIDs
607         // and the port index on the local interconnect.
608
609         maptab_int.srcid_map( IntTab( cluster(x,y), MDMA_LOCAL_SRCID ),
610                               IntTab( cluster(x,y), INT_MDMA_INI_ID ) );
611
612         maptab_int.srcid_map( IntTab( cluster(x,y), IOBX_LOCAL_SRCID ),
613                               IntTab( cluster(x,y), INT_IOBX_INI_ID ) );
614
615         maptab_int.srcid_map( IntTab( cluster(x,y), IOPI_LOCAL_SRCID ),
616                               IntTab( cluster(x,y), INT_IOBX_INI_ID ) );
617
618         for ( size_t p = 0 ; p < NB_PROCS_MAX ; p++ )
619         maptab_int.srcid_map( IntTab( cluster(x,y), PROC_LOCAL_SRCID+p ),
620                               IntTab( cluster(x,y), INT_PROC_INI_ID+p ) );
621      }
622   }
623   std::cout << "INT network " << maptab_int << std::endl;
624
625    /////////////////////////////////////////////////////////////////////////
626    // RAM network mapping table
627    // - two levels address decoding for commands
628    // - two levels srcid decoding for responses
629    // - 2 local initiators (MEMC, IOBX) per cluster
630    //   (IOBX component only in cluster_iob0 and cluster_iob1)
631    // - 1 local target (XRAM) per cluster
632    ////////////////////////////////////////////////////////////////////////
633    MappingTable maptab_ram( vci_address_width,
634                             IntTab(x_width+y_width, 0),
635                             IntTab(x_width+y_width, vci_srcid_width - x_width - y_width),
636                             0x00FF000000);
637
638    for (size_t x = 0; x < XMAX; x++)
639    {
640        for (size_t y = 0; y < YMAX ; y++)
641        {
642            uint64_t offset = ((uint64_t)cluster(x,y))
643                                << (vci_address_width-x_width-y_width);
644
645            std::ostringstream sxram;
646            sxram << "ext_seg_xram_" << x << "_" << y;
647            maptab_ram.add(Segment(sxram.str(), SEG_RAM_BASE+offset,
648                           SEG_RAM_SIZE, IntTab(cluster(x,y), RAM_XRAM_TGT_ID), false));
649        }
650    }
651
652    // This define the mapping between the initiators SRCID
653    // and the port index on the RAM local interconnect.
654    // External initiator have two alias SRCID (iob0 / iob1)
655
656    maptab_ram.srcid_map( IntTab( cluster_iob0, CDMA_LOCAL_SRCID ),
657                          IntTab( cluster_iob0, RAM_IOBX_INI_ID ) );
658
659    maptab_ram.srcid_map( IntTab( cluster_iob1, CDMA_LOCAL_SRCID ),
660                          IntTab( cluster_iob1, RAM_IOBX_INI_ID ) );
661
662    maptab_ram.srcid_map( IntTab( cluster_iob0, BDEV_LOCAL_SRCID ),
663                          IntTab( cluster_iob0, RAM_IOBX_INI_ID ) );
664
665    maptab_ram.srcid_map( IntTab( cluster_iob1, BDEV_LOCAL_SRCID ),
666                          IntTab( cluster_iob1, RAM_IOBX_INI_ID ) );
667
668    maptab_ram.srcid_map( IntTab( cluster_iob0, IOPI_LOCAL_SRCID ),
669                          IntTab( cluster_iob0, RAM_IOBX_INI_ID ) );
670
671    maptab_ram.srcid_map( IntTab( cluster_iob1, IOPI_LOCAL_SRCID ),
672                          IntTab( cluster_iob1, RAM_IOBX_INI_ID ) );
673
674    maptab_ram.srcid_map( IntTab( cluster_iob0, MEMC_LOCAL_SRCID ),
675                          IntTab( cluster_iob0, RAM_MEMC_INI_ID ) );
676
677    maptab_ram.srcid_map( IntTab( cluster_iob1, MEMC_LOCAL_SRCID ),
678                          IntTab( cluster_iob1, RAM_MEMC_INI_ID ) );
679
680    std::cout << "RAM network " << maptab_ram << std::endl;
681
682    ///////////////////////////////////////////////////////////////////////
683    // IOX network mapping table
684    // - two levels address decoding for commands (9, 7) bits
685    // - two levels srcid decoding for responses
686    // - 5 initiators (IOB0, IOB1, BDEV, CDMA, IOPI)
687    // - 9 targets (IOB0, IOB1, BDEV, CDMA, MTTY, FBUF, BROM, MNIC, IOPI)
688    //
689    // Address bit 32 is used to determine if a command must be routed to
690    // IOB0 or IOB1.
691    ///////////////////////////////////////////////////////////////////////
692    MappingTable maptab_iox(
693          vci_address_width,
694          IntTab(x_width + y_width - 1, 16 - x_width - y_width + 1),
695          IntTab(x_width + y_width    , vci_param_ext::S - x_width - y_width),
696          0x00FF000000);
697
698    // External peripherals segments
699    // When there is more than one cluster, external peripherals can be accessed
700    // through two segments, depending on the used IOB (IOB0 or IOB1).
701
702    const uint64_t iob0_base = ((uint64_t)cluster_iob0)
703       << (vci_address_width - x_width - y_width);
704
705    maptab_iox.add(Segment("iox_seg_mtty_0", SEG_TTY_BASE + iob0_base, SEG_TTY_SIZE,
706                   IntTab(0, IOX_MTTY_TGT_ID), false));
707    maptab_iox.add(Segment("iox_seg_fbuf_0", SEG_FBF_BASE + iob0_base, SEG_FBF_SIZE,
708                   IntTab(0, IOX_FBUF_TGT_ID), false));
709    maptab_iox.add(Segment("iox_seg_bdev_0", SEG_IOC_BASE + iob0_base, SEG_IOC_SIZE,
710                   IntTab(0, IOX_BDEV_TGT_ID), false));
711    maptab_iox.add(Segment("iox_seg_mnic_0", SEG_NIC_BASE + iob0_base, SEG_NIC_SIZE,
712                   IntTab(0, IOX_MNIC_TGT_ID), false));
713    maptab_iox.add(Segment("iox_seg_cdma_0", SEG_CMA_BASE + iob0_base, SEG_CMA_SIZE,
714                   IntTab(0, IOX_CDMA_TGT_ID), false));
715    maptab_iox.add(Segment("iox_seg_iopi_0", SEG_PIC_BASE + iob0_base, SEG_PIC_SIZE,
716                   IntTab(0, IOX_IOPI_TGT_ID), false));
717    maptab_iox.add(Segment("iox_seg_simh_0", SEG_SIM_BASE + iob0_base, SEG_SIM_SIZE,
718                   IntTab(0, IOX_SIMH_TGT_ID), false));
719
720    if ( cluster_iob0 != cluster_iob1 )
721    {
722       const uint64_t iob1_base = ((uint64_t)cluster_iob1)
723          << (vci_address_width - x_width - y_width);
724
725        maptab_iox.add(Segment("iox_seg_mtty_1", SEG_TTY_BASE + iob1_base, SEG_TTY_SIZE,
726                   IntTab(0, IOX_MTTY_TGT_ID), false));
727        maptab_iox.add(Segment("iox_seg_fbuf_1", SEG_FBF_BASE + iob1_base, SEG_FBF_SIZE,
728                   IntTab(0, IOX_FBUF_TGT_ID), false));
729        maptab_iox.add(Segment("iox_seg_bdev_1", SEG_IOC_BASE + iob1_base, SEG_IOC_SIZE,
730                   IntTab(0, IOX_BDEV_TGT_ID), false));
731        maptab_iox.add(Segment("iox_seg_mnic_1", SEG_NIC_BASE + iob1_base, SEG_NIC_SIZE,
732                   IntTab(0, IOX_MNIC_TGT_ID), false));
733        maptab_iox.add(Segment("iox_seg_cdma_1", SEG_CMA_BASE + iob1_base, SEG_CMA_SIZE,
734                   IntTab(0, IOX_CDMA_TGT_ID), false));
735        maptab_iox.add(Segment("iox_seg_iopi_1", SEG_PIC_BASE + iob1_base, SEG_PIC_SIZE,
736                   IntTab(0, IOX_IOPI_TGT_ID), false));
737        maptab_iox.add(Segment("iox_seg_simh_1", SEG_SIM_BASE + iob1_base, SEG_SIM_SIZE,
738                   IntTab(0, IOX_SIMH_TGT_ID), false));
739    }
740
741    // If there is more than one cluster, external peripherals
742    // can access RAM through two segments (IOB0 / IOB1).
743    // As IOMMU is not activated, addresses are 40 bits (physical addresses),
744    // and the choice depends on address bit A[32].
745    for (size_t x = 0; x < XMAX; x++)
746    {
747        for (size_t y = 0; y < YMAX ; y++)
748        {
749            const bool wti       = true;
750            const bool cacheable = true;
751
752            const uint64_t offset = ((uint64_t)cluster(x,y))
753                << (vci_address_width-x_width-y_width);
754
755            const uint64_t xicu_base = SEG_XCU_BASE + offset;
756
757            if ( (y & 0x1) == 0 ) // use IOB0
758            {
759                std::ostringstream sxcu0;
760                sxcu0 << "iox_seg_xcu0_" << x << "_" << y;
761                maptab_iox.add(Segment(sxcu0.str(), xicu_base, SEG_XCU_SIZE,
762                            IntTab(0, IOX_IOB0_TGT_ID), not cacheable, wti));
763
764                std::ostringstream siob0;
765                siob0 << "iox_seg_ram0_" << x << "_" << y;
766                maptab_iox.add(Segment(siob0.str(), offset, SEG_XCU_BASE,
767                            IntTab(0, IOX_IOB0_TGT_ID), not cacheable, not wti));
768            }
769            else                  // USE IOB1
770            {
771                std::ostringstream sxcu1;
772                sxcu1 << "iox_seg_xcu1_" << x << "_" << y;
773                maptab_iox.add(Segment(sxcu1.str(), xicu_base, SEG_XCU_SIZE,
774                            IntTab(0, IOX_IOB1_TGT_ID), not cacheable, wti));
775
776                std::ostringstream siob1;
777                siob1 << "iox_seg_ram1_" << x << "_" << y;
778                maptab_iox.add(Segment(siob1.str(), offset, SEG_XCU_BASE,
779                            IntTab(0, IOX_IOB1_TGT_ID), not cacheable, not wti));
780            }
781        }
782    }
783
784    // This define the mapping between the external initiators (SRCID)
785    // and the port index on the IOX local interconnect.
786
787    maptab_iox.srcid_map( IntTab( 0, CDMA_LOCAL_SRCID ) ,
788                          IntTab( 0, IOX_CDMA_INI_ID  ) );
789    maptab_iox.srcid_map( IntTab( 0, BDEV_LOCAL_SRCID ) ,
790                          IntTab( 0, IOX_BDEV_INI_ID  ) );
791    maptab_iox.srcid_map( IntTab( 0, IOPI_LOCAL_SRCID ) ,
792                          IntTab( 0, IOX_IOPI_INI_ID  ) );
793    maptab_iox.srcid_map( IntTab( 0, IOX_IOB0_INI_ID  ) ,
794                          IntTab( 0, IOX_IOB0_INI_ID  ) );
795
796    if ( cluster_iob0 != cluster_iob1 )
797    {
798        maptab_iox.srcid_map( IntTab( 0, IOX_IOB1_INI_ID ) ,
799                              IntTab( 0, IOX_IOB1_INI_ID ) );
800    }
801
802    std::cout << "IOX network " << maptab_iox << std::endl;
803
804    ////////////////////
805    // Signals
806    ///////////////////
807
808    sc_clock                          signal_clk("clk");
809    sc_signal<bool>                   signal_resetn("resetn");
810
811    sc_signal<bool>                   signal_irq_false;
812    sc_signal<bool>                   signal_irq_bdev;
813    sc_signal<bool>                   signal_irq_mtty_rx;
814    sc_signal<bool>                   signal_irq_mnic_rx[NB_NIC_CHANNELS];
815    sc_signal<bool>                   signal_irq_mnic_tx[NB_NIC_CHANNELS];
816    sc_signal<bool>                   signal_irq_cdma[NB_CMA_CHANNELS];
817
818    // VCI signals for IOX network
819    VciSignals<vci_param_ext>         signal_vci_ini_iob0("signal_vci_ini_iob0");
820    VciSignals<vci_param_ext>         signal_vci_ini_iob1("signal_vci_ini_iob1");
821    VciSignals<vci_param_ext>         signal_vci_ini_bdev("signal_vci_ini_bdev");
822    VciSignals<vci_param_ext>         signal_vci_ini_cdma("signal_vci_ini_cdma");
823    VciSignals<vci_param_ext>         signal_vci_ini_iopi("signal_vci_ini_iopi");
824
825    VciSignals<vci_param_ext>         signal_vci_tgt_iob0("signal_vci_tgt_iob0");
826    VciSignals<vci_param_ext>         signal_vci_tgt_iob1("signal_vci_tgt_iob1");
827    VciSignals<vci_param_ext>         signal_vci_tgt_mtty("signal_vci_tgt_mtty");
828    VciSignals<vci_param_ext>         signal_vci_tgt_fbuf("signal_vci_tgt_fbuf");
829    VciSignals<vci_param_ext>         signal_vci_tgt_mnic("signal_vci_tgt_mnic");
830    VciSignals<vci_param_ext>         signal_vci_tgt_bdev("signal_vci_tgt_bdev");
831    VciSignals<vci_param_ext>         signal_vci_tgt_cdma("signal_vci_tgt_cdma");
832    VciSignals<vci_param_ext>         signal_vci_tgt_iopi("signal_vci_ini_iopi");
833    VciSignals<vci_param_ext>         signal_vci_tgt_simh("signal_vci_ini_simh");
834
835   // Horizontal inter-clusters INT network DSPIN
836   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_h_inc =
837      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_h_inc", XMAX-1, YMAX, 3);
838   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_h_dec =
839      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_h_dec", XMAX-1, YMAX, 3);
840   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_h_inc =
841      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_h_inc", XMAX-1, YMAX, 2);
842   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_h_dec =
843      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_h_dec", XMAX-1, YMAX, 2);
844
845   // Vertical inter-clusters INT network DSPIN
846   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_v_inc =
847      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_v_inc", XMAX, YMAX-1, 3);
848   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_v_dec =
849      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_v_dec", XMAX, YMAX-1, 3);
850   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_v_inc =
851      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_v_inc", XMAX, YMAX-1, 2);
852   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_v_dec =
853      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_v_dec", XMAX, YMAX-1, 2);
854
855   // Mesh boundaries INT network DSPIN
856   DspinSignals<dspin_int_cmd_width>**** signal_dspin_false_int_cmd_in =
857      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_false_int_cmd_in", XMAX, YMAX, 4, 3);
858   DspinSignals<dspin_int_cmd_width>**** signal_dspin_false_int_cmd_out =
859      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_false_int_cmd_out", XMAX, YMAX, 4, 3);
860   DspinSignals<dspin_int_rsp_width>**** signal_dspin_false_int_rsp_in =
861      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_false_int_rsp_in", XMAX, YMAX, 4, 2);
862   DspinSignals<dspin_int_rsp_width>**** signal_dspin_false_int_rsp_out =
863      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_false_int_rsp_out", XMAX, YMAX, 4, 2);
864
865
866   // Horizontal inter-clusters RAM network DSPIN
867   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_h_inc =
868      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_h_inc", XMAX-1, YMAX);
869   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_h_dec =
870      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_h_dec", XMAX-1, YMAX);
871   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_h_inc =
872      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_h_inc", XMAX-1, YMAX);
873   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_h_dec =
874      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_h_dec", XMAX-1, YMAX);
875
876   // Vertical inter-clusters RAM network DSPIN
877   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_v_inc =
878      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_v_inc", XMAX, YMAX-1);
879   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_v_dec =
880      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_v_dec", XMAX, YMAX-1);
881   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_v_inc =
882      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_v_inc", XMAX, YMAX-1);
883   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_v_dec =
884      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_v_dec", XMAX, YMAX-1);
885
886   // Mesh boundaries RAM network DSPIN
887   DspinSignals<dspin_ram_cmd_width>*** signal_dspin_false_ram_cmd_in =
888      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_false_ram_cmd_in", XMAX, YMAX, 4);
889   DspinSignals<dspin_ram_cmd_width>*** signal_dspin_false_ram_cmd_out =
890      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_false_ram_cmd_out", XMAX, YMAX, 4);
891   DspinSignals<dspin_ram_rsp_width>*** signal_dspin_false_ram_rsp_in =
892      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_false_ram_rsp_in", XMAX, YMAX, 4);
893   DspinSignals<dspin_ram_rsp_width>*** signal_dspin_false_ram_rsp_out =
894      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_false_ram_rsp_out", XMAX, YMAX, 4);
895
896   ////////////////////////////
897   //      Loader
898   ////////////////////////////
899
900#if USE_ALMOS
901   soclib::common::Loader loader(almos_bootloader_pathname,
902                                 almos_archinfo_pathname,
903                                 almos_kernel_pathname);
904#else
905   soclib::common::Loader loader(soft_name);
906#endif
907
908   // initialize memory with a value different than 0 (expose software errors
909   // dues to uninitialized data)
910   loader.memory_default(0xA0);
911
912   typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
913   proc_iss::set_loader(loader);
914
915   ////////////////////////////////////////
916   //  Instanciated Hardware Components
917   ////////////////////////////////////////
918
919   std::cout << std::endl << "External Bus and Peripherals" << std::endl << std::endl;
920
921   const size_t nb_iox_initiators = (cluster_iob0 != cluster_iob1) ? 5 : 4;
922   const size_t nb_iox_targets = (cluster_iob0 != cluster_iob1) ? 9 : 8;
923
924   // IOX network
925   VciIoxNetwork<vci_param_ext>* iox_network;
926   iox_network = new VciIoxNetwork<vci_param_ext>( "iox_network",
927                                                   maptab_iox,
928                                                   nb_iox_targets,
929                                                   nb_iox_initiators );
930
931   // Network Controller
932   VciMultiNic<vci_param_ext>*  mnic;
933   mnic = new VciMultiNic<vci_param_ext>( "mnic",
934                                          IntTab(0, IOX_MNIC_TGT_ID),
935                                          maptab_iox,
936                                          NB_NIC_CHANNELS,
937                                          0,           // mac_4 address
938                                          0,           // mac_2 address
939                                          nic_rx_name,
940                                          nic_tx_name);
941
942   // Frame Buffer
943   VciFrameBuffer<vci_param_ext>*  fbuf;
944   fbuf = new VciFrameBuffer<vci_param_ext>( "fbuf",
945                                             IntTab(0, IOX_FBUF_TGT_ID),
946                                             maptab_iox,
947                                             FBUF_X_SIZE, FBUF_Y_SIZE );
948
949   // Block Device
950   // for AHCI
951   // std::vector<std::string> filenames;
952   // filenames.push_back(disk_name);            // one single disk
953   VciBlockDeviceTsar<vci_param_ext>*  bdev;
954   bdev = new VciBlockDeviceTsar<vci_param_ext>( "bdev",
955                                                  maptab_iox,
956                                                  IntTab(0, BDEV_LOCAL_SRCID),
957                                                  IntTab(0, IOX_BDEV_TGT_ID),
958                                                  disk_name,
959                                                  512,        // block size
960                                                  64,         // burst size (bytes)
961                                                  0 );        // disk latency
962
963   // Chained Buffer DMA controller
964   VciChbufDma<vci_param_ext>*  cdma;
965   cdma = new VciChbufDma<vci_param_ext>( "cdma",
966                                          maptab_iox,
967                                          IntTab(0, CDMA_LOCAL_SRCID),
968                                          IntTab(0, IOX_CDMA_TGT_ID),
969                                          64,          // burst size (bytes)
970                                          2*NB_NIC_CHANNELS );
971   // Multi-TTY controller
972   std::vector<std::string> vect_names;
973   for( size_t tid = 0 ; tid < NB_TTY_CHANNELS ; tid++ )
974   {
975      std::ostringstream term_name;
976         term_name <<  "term" << tid;
977         vect_names.push_back(term_name.str().c_str());
978      }
979      VciMultiTty<vci_param_ext>*  mtty;
980      mtty = new VciMultiTty<vci_param_ext>( "mtty",
981                                             IntTab(0, IOX_MTTY_TGT_ID),
982                                             maptab_iox,
983                                             vect_names);
984
985   // IOPIC
986   VciIopic<vci_param_ext>* iopi;
987   iopi = new VciIopic<vci_param_ext>( "iopi",
988                                       maptab_iox,
989                                       IntTab(0, IOPI_LOCAL_SRCID),
990                                       IntTab(0, IOX_IOPI_TGT_ID),
991                                       32 );        // number of input HWI
992
993   // Simhelper
994   VciSimhelper<vci_param_ext>* simh;
995   simh = new VciSimhelper<vci_param_ext>("simh",
996                                          IntTab(0, IOX_SIMH_TGT_ID),
997                                          maptab_iox );
998
999   // Clusters
1000   TsarIobCluster<vci_param_int,
1001                  vci_param_ext,
1002                  dspin_int_cmd_width,
1003                  dspin_int_rsp_width,
1004                  dspin_ram_cmd_width,
1005                  dspin_ram_rsp_width>* clusters[XMAX][YMAX];
1006
1007#if USE_OPENMP
1008#pragma omp parallel
1009    {
1010#pragma omp for
1011#endif
1012        for(size_t i = 0; i  < (XMAX * YMAX); i++)
1013        {
1014            size_t x = i / YMAX;
1015            size_t y = i % YMAX;
1016
1017#if USE_OPENMP
1018#pragma omp critical
1019            {
1020#endif
1021            std::cout << std::endl;
1022            std::cout << "Cluster_" << std::dec << x << "_" << y << std::endl;
1023            std::cout << std::endl;
1024
1025            const bool is_iob0 = (cluster(x,y) == cluster_iob0);
1026            const bool is_iob1 = (cluster(x,y) == cluster_iob1);
1027            const bool is_io_cluster = is_iob0 || is_iob1;
1028
1029            const int iox_iob_ini_id = is_iob0 ?
1030                IOX_IOB0_INI_ID :
1031                IOX_IOB1_INI_ID ;
1032            const int iox_iob_tgt_id = is_iob0 ?
1033                IOX_IOB0_TGT_ID :
1034                IOX_IOB1_TGT_ID ;
1035
1036            std::ostringstream sc;
1037            sc << "cluster_" << x << "_" << y;
1038            clusters[x][y] = new TsarIobCluster<vci_param_int,
1039                                                vci_param_ext,
1040                                                dspin_int_cmd_width,
1041                                                dspin_int_rsp_width,
1042                                                dspin_ram_cmd_width,
1043                                                dspin_ram_rsp_width>
1044            (
1045                sc.str().c_str(),
1046                NB_PROCS_MAX,
1047                NB_DMA_CHANNELS,
1048                x,
1049                y,
1050                XMAX,
1051                YMAX,
1052
1053                maptab_int,
1054                maptab_ram,
1055                maptab_iox,
1056
1057                x_width,
1058                y_width,
1059                vci_srcid_width - x_width - y_width,            // l_id width,
1060
1061                INT_MEMC_TGT_ID,
1062                INT_XICU_TGT_ID,
1063                INT_MDMA_TGT_ID,
1064                INT_BROM_TGT_ID,
1065                INT_IOBX_TGT_ID,
1066
1067                INT_PROC_INI_ID,
1068                INT_MDMA_INI_ID,
1069                INT_IOBX_INI_ID,
1070
1071                RAM_XRAM_TGT_ID,
1072
1073                RAM_MEMC_INI_ID,
1074                RAM_IOBX_INI_ID,
1075
1076                is_io_cluster,
1077                iox_iob_tgt_id,
1078                iox_iob_ini_id,
1079
1080                MEMC_WAYS,
1081                MEMC_SETS,
1082                L1_IWAYS,
1083                L1_ISETS,
1084                L1_DWAYS,
1085                L1_DSETS,
1086                XRAM_LATENCY,
1087                XCU_NB_INPUTS,
1088
1089                distributed_boot,
1090
1091                loader,
1092
1093                frozen_cycles,
1094                debug_from,
1095                debug_ok and (cluster(x,y) == debug_memc_id),
1096                debug_ok and (cluster(x,y) == debug_proc_id),
1097                debug_ok and debug_iob
1098            );
1099
1100#if USE_OPENMP
1101            } // end critical
1102#endif
1103        } // end for
1104#if USE_OPENMP
1105    }
1106#endif
1107
1108    std::cout << std::endl;
1109
1110    ///////////////////////////////////////////////////////////////////////////////
1111    //     Net-list
1112    ///////////////////////////////////////////////////////////////////////////////
1113
1114    // IOX network connexion
1115    iox_network->p_clk                                   (signal_clk);
1116    iox_network->p_resetn                                (signal_resetn);
1117    iox_network->p_to_ini[IOX_IOB0_INI_ID]               (signal_vci_ini_iob0);
1118    iox_network->p_to_ini[IOX_BDEV_INI_ID]               (signal_vci_ini_bdev);
1119    iox_network->p_to_ini[IOX_CDMA_INI_ID]               (signal_vci_ini_cdma);
1120    iox_network->p_to_ini[IOX_IOPI_INI_ID]               (signal_vci_ini_iopi);
1121
1122    iox_network->p_to_tgt[IOX_IOB0_TGT_ID]               (signal_vci_tgt_iob0);
1123    iox_network->p_to_tgt[IOX_MTTY_TGT_ID]               (signal_vci_tgt_mtty);
1124    iox_network->p_to_tgt[IOX_FBUF_TGT_ID]               (signal_vci_tgt_fbuf);
1125    iox_network->p_to_tgt[IOX_MNIC_TGT_ID]               (signal_vci_tgt_mnic);
1126    iox_network->p_to_tgt[IOX_BDEV_TGT_ID]               (signal_vci_tgt_bdev);
1127    iox_network->p_to_tgt[IOX_CDMA_TGT_ID]               (signal_vci_tgt_cdma);
1128    iox_network->p_to_tgt[IOX_IOPI_TGT_ID]               (signal_vci_tgt_iopi);
1129    iox_network->p_to_tgt[IOX_SIMH_TGT_ID]               (signal_vci_tgt_simh);
1130
1131    if (cluster_iob0 != cluster_iob1)
1132    {
1133        iox_network->p_to_ini[IOX_IOB1_INI_ID]           (signal_vci_ini_iob1);
1134        iox_network->p_to_tgt[IOX_IOB1_TGT_ID]           (signal_vci_tgt_iob1);
1135    }
1136
1137    // BDEV connexion
1138    bdev->p_clk                                          (signal_clk);
1139    bdev->p_resetn                                       (signal_resetn);
1140    bdev->p_irq                                          (signal_irq_bdev);
1141    bdev->p_vci_target                                   (signal_vci_tgt_bdev);
1142    bdev->p_vci_initiator                                (signal_vci_ini_bdev);
1143
1144    std::cout << "  - BDEV connected" << std::endl;
1145
1146    // FBUF connexion
1147    fbuf->p_clk                                          (signal_clk);
1148    fbuf->p_resetn                                       (signal_resetn);
1149    fbuf->p_vci                                          (signal_vci_tgt_fbuf);
1150
1151    std::cout << "  - FBUF connected" << std::endl;
1152
1153    // MNIC connexion
1154    mnic->p_clk                                          (signal_clk);
1155    mnic->p_resetn                                       (signal_resetn);
1156    mnic->p_vci                                          (signal_vci_tgt_mnic);
1157    for ( size_t i=0 ; i<NB_NIC_CHANNELS ; i++ )
1158    {
1159         mnic->p_rx_irq[i]                               (signal_irq_mnic_rx[i]);
1160         mnic->p_tx_irq[i]                               (signal_irq_mnic_tx[i]);
1161    }
1162
1163    std::cout << "  - MNIC connected" << std::endl;
1164
1165    // MTTY connexion
1166    mtty->p_clk                                          (signal_clk);
1167    mtty->p_resetn                                       (signal_resetn);
1168    mtty->p_vci                                          (signal_vci_tgt_mtty);
1169    mtty->p_irq[0]                                       (signal_irq_mtty_rx);
1170
1171    std::cout << "  - MTTY connected" << std::endl;
1172
1173    // CDMA connexion
1174    cdma->p_clk                                          (signal_clk);
1175    cdma->p_resetn                                       (signal_resetn);
1176    cdma->p_vci_target                                   (signal_vci_tgt_cdma);
1177    cdma->p_vci_initiator                                (signal_vci_ini_cdma);
1178    for ( size_t i=0 ; i<(NB_NIC_CHANNELS*2) ; i++)
1179    {
1180        cdma->p_irq[i]                                   (signal_irq_cdma[i]);
1181    }
1182
1183    std::cout << "  - CDMA connected" << std::endl;
1184
1185    // IOPI connexion
1186    iopi->p_clk                                          (signal_clk);
1187    iopi->p_resetn                                       (signal_resetn);
1188    iopi->p_vci_target                                   (signal_vci_tgt_iopi);
1189    iopi->p_vci_initiator                                (signal_vci_ini_iopi);
1190    for ( size_t i=0 ; i<32 ; i++)
1191    {
1192       if     (i < NB_NIC_CHANNELS)    iopi->p_hwi[i] (signal_irq_mnic_rx[i]);
1193       else if(i < 2 )                 iopi->p_hwi[i] (signal_irq_false);
1194       else if(i < 2+NB_NIC_CHANNELS)  iopi->p_hwi[i] (signal_irq_mnic_tx[i-2]);
1195       else if(i < 4 )                 iopi->p_hwi[i] (signal_irq_false);
1196       else if(i < 4+NB_CMA_CHANNELS)  iopi->p_hwi[i] (signal_irq_cdma[i-4]);
1197       else if(i < 8)                  iopi->p_hwi[i] (signal_irq_false);
1198       else if(i == 8)                 iopi->p_hwi[i] (signal_irq_bdev);
1199       else if(i == 9)                 iopi->p_hwi[i] (signal_irq_mtty_rx);
1200       else                            iopi->p_hwi[i] (signal_irq_false);
1201    }
1202
1203    std::cout << "  - IOPIC connected" << std::endl;
1204
1205    // Simhelper connexion
1206    simh->p_clk(signal_clk);
1207    simh->p_resetn(signal_resetn);
1208    simh->p_vci(signal_vci_tgt_simh);
1209
1210    // IOB0 cluster connexion to IOX network
1211    (*clusters[0][0]->p_vci_iob_iox_ini) (signal_vci_ini_iob0);
1212    (*clusters[0][0]->p_vci_iob_iox_tgt) (signal_vci_tgt_iob0);
1213
1214    // IOB1 cluster connexion to IOX network
1215    // (only when there is more than 1 cluster)
1216    if ( cluster_iob0 != cluster_iob1 )
1217    {
1218        (*clusters[XMAX-1][YMAX-1]->p_vci_iob_iox_ini) (signal_vci_ini_iob1);
1219        (*clusters[XMAX-1][YMAX-1]->p_vci_iob_iox_tgt) (signal_vci_tgt_iob1);
1220    }
1221
1222    // All clusters Clock & RESET connexions
1223    for ( size_t x = 0; x < (XMAX); x++ )
1224    {
1225        for (size_t y = 0; y < YMAX; y++)
1226        {
1227            clusters[x][y]->p_clk     (signal_clk);
1228            clusters[x][y]->p_resetn  (signal_resetn);
1229        }
1230    }
1231
1232   // Inter Clusters horizontal connections
1233   if (XMAX > 1)
1234   {
1235      for (size_t x = 0; x < (XMAX-1); x++)
1236      {
1237         for (size_t y = 0; y < YMAX; y++)
1238         {
1239            for (size_t k = 0; k < 3; k++)
1240            {
1241               clusters[x][y]->p_dspin_int_cmd_out[EAST][k]      (signal_dspin_int_cmd_h_inc[x][y][k]);
1242               clusters[x+1][y]->p_dspin_int_cmd_in[WEST][k]     (signal_dspin_int_cmd_h_inc[x][y][k]);
1243               clusters[x][y]->p_dspin_int_cmd_in[EAST][k]       (signal_dspin_int_cmd_h_dec[x][y][k]);
1244               clusters[x+1][y]->p_dspin_int_cmd_out[WEST][k]    (signal_dspin_int_cmd_h_dec[x][y][k]);
1245            }
1246
1247            for (size_t k = 0; k < 2; k++)
1248            {
1249               clusters[x][y]->p_dspin_int_rsp_out[EAST][k]      (signal_dspin_int_rsp_h_inc[x][y][k]);
1250               clusters[x+1][y]->p_dspin_int_rsp_in[WEST][k]     (signal_dspin_int_rsp_h_inc[x][y][k]);
1251               clusters[x][y]->p_dspin_int_rsp_in[EAST][k]       (signal_dspin_int_rsp_h_dec[x][y][k]);
1252               clusters[x+1][y]->p_dspin_int_rsp_out[WEST][k]    (signal_dspin_int_rsp_h_dec[x][y][k]);
1253            }
1254
1255            clusters[x][y]->p_dspin_ram_cmd_out[EAST]      (signal_dspin_ram_cmd_h_inc[x][y]);
1256            clusters[x+1][y]->p_dspin_ram_cmd_in[WEST]     (signal_dspin_ram_cmd_h_inc[x][y]);
1257            clusters[x][y]->p_dspin_ram_cmd_in[EAST]       (signal_dspin_ram_cmd_h_dec[x][y]);
1258            clusters[x+1][y]->p_dspin_ram_cmd_out[WEST]    (signal_dspin_ram_cmd_h_dec[x][y]);
1259            clusters[x][y]->p_dspin_ram_rsp_out[EAST]      (signal_dspin_ram_rsp_h_inc[x][y]);
1260            clusters[x+1][y]->p_dspin_ram_rsp_in[WEST]     (signal_dspin_ram_rsp_h_inc[x][y]);
1261            clusters[x][y]->p_dspin_ram_rsp_in[EAST]       (signal_dspin_ram_rsp_h_dec[x][y]);
1262            clusters[x+1][y]->p_dspin_ram_rsp_out[WEST]    (signal_dspin_ram_rsp_h_dec[x][y]);
1263         }
1264      }
1265   }
1266
1267   std::cout << std::endl << "Horizontal connections established" << std::endl;
1268
1269   // Inter Clusters vertical connections
1270   if (YMAX > 1)
1271   {
1272      for (size_t y = 0; y < (YMAX-1); y++)
1273      {
1274         for (size_t x = 0; x < XMAX; x++)
1275         {
1276            for (size_t k = 0; k < 3; k++)
1277            {
1278               clusters[x][y]->p_dspin_int_cmd_out[NORTH][k]     (signal_dspin_int_cmd_v_inc[x][y][k]);
1279               clusters[x][y+1]->p_dspin_int_cmd_in[SOUTH][k]    (signal_dspin_int_cmd_v_inc[x][y][k]);
1280               clusters[x][y]->p_dspin_int_cmd_in[NORTH][k]      (signal_dspin_int_cmd_v_dec[x][y][k]);
1281               clusters[x][y+1]->p_dspin_int_cmd_out[SOUTH][k]   (signal_dspin_int_cmd_v_dec[x][y][k]);
1282            }
1283
1284            for (size_t k = 0; k < 2; k++)
1285            {
1286               clusters[x][y]->p_dspin_int_rsp_out[NORTH][k]     (signal_dspin_int_rsp_v_inc[x][y][k]);
1287               clusters[x][y+1]->p_dspin_int_rsp_in[SOUTH][k]    (signal_dspin_int_rsp_v_inc[x][y][k]);
1288               clusters[x][y]->p_dspin_int_rsp_in[NORTH][k]      (signal_dspin_int_rsp_v_dec[x][y][k]);
1289               clusters[x][y+1]->p_dspin_int_rsp_out[SOUTH][k]   (signal_dspin_int_rsp_v_dec[x][y][k]);
1290            }
1291
1292            clusters[x][y]->p_dspin_ram_cmd_out[NORTH]     (signal_dspin_ram_cmd_v_inc[x][y]);
1293            clusters[x][y+1]->p_dspin_ram_cmd_in[SOUTH]    (signal_dspin_ram_cmd_v_inc[x][y]);
1294            clusters[x][y]->p_dspin_ram_cmd_in[NORTH]      (signal_dspin_ram_cmd_v_dec[x][y]);
1295            clusters[x][y+1]->p_dspin_ram_cmd_out[SOUTH]   (signal_dspin_ram_cmd_v_dec[x][y]);
1296            clusters[x][y]->p_dspin_ram_rsp_out[NORTH]     (signal_dspin_ram_rsp_v_inc[x][y]);
1297            clusters[x][y+1]->p_dspin_ram_rsp_in[SOUTH]    (signal_dspin_ram_rsp_v_inc[x][y]);
1298            clusters[x][y]->p_dspin_ram_rsp_in[NORTH]      (signal_dspin_ram_rsp_v_dec[x][y]);
1299            clusters[x][y+1]->p_dspin_ram_rsp_out[SOUTH]   (signal_dspin_ram_rsp_v_dec[x][y]);
1300         }
1301      }
1302   }
1303
1304   std::cout << "Vertical connections established" << std::endl;
1305
1306   // East & West boundary cluster connections
1307   for (size_t y = 0; y < YMAX; y++)
1308   {
1309      for (size_t k = 0; k < 3; k++)
1310      {
1311         clusters[0][y]->p_dspin_int_cmd_in[WEST][k]          (signal_dspin_false_int_cmd_in[0][y][WEST][k]);
1312         clusters[0][y]->p_dspin_int_cmd_out[WEST][k]         (signal_dspin_false_int_cmd_out[0][y][WEST][k]);
1313         clusters[XMAX-1][y]->p_dspin_int_cmd_in[EAST][k]     (signal_dspin_false_int_cmd_in[XMAX-1][y][EAST][k]);
1314         clusters[XMAX-1][y]->p_dspin_int_cmd_out[EAST][k]    (signal_dspin_false_int_cmd_out[XMAX-1][y][EAST][k]);
1315      }
1316
1317      for (size_t k = 0; k < 2; k++)
1318      {
1319         clusters[0][y]->p_dspin_int_rsp_in[WEST][k]          (signal_dspin_false_int_rsp_in[0][y][WEST][k]);
1320         clusters[0][y]->p_dspin_int_rsp_out[WEST][k]         (signal_dspin_false_int_rsp_out[0][y][WEST][k]);
1321         clusters[XMAX-1][y]->p_dspin_int_rsp_in[EAST][k]     (signal_dspin_false_int_rsp_in[XMAX-1][y][EAST][k]);
1322         clusters[XMAX-1][y]->p_dspin_int_rsp_out[EAST][k]    (signal_dspin_false_int_rsp_out[XMAX-1][y][EAST][k]);
1323      }
1324
1325     clusters[0][y]->p_dspin_ram_cmd_in[WEST]       (signal_dspin_false_ram_cmd_in[0][y][WEST]);
1326     clusters[0][y]->p_dspin_ram_cmd_out[WEST]      (signal_dspin_false_ram_cmd_out[0][y][WEST]);
1327     clusters[0][y]->p_dspin_ram_rsp_in[WEST]       (signal_dspin_false_ram_rsp_in[0][y][WEST]);
1328     clusters[0][y]->p_dspin_ram_rsp_out[WEST]      (signal_dspin_false_ram_rsp_out[0][y][WEST]);
1329
1330     clusters[XMAX-1][y]->p_dspin_ram_cmd_in[EAST]  (signal_dspin_false_ram_cmd_in[XMAX-1][y][EAST]);
1331     clusters[XMAX-1][y]->p_dspin_ram_cmd_out[EAST] (signal_dspin_false_ram_cmd_out[XMAX-1][y][EAST]);
1332     clusters[XMAX-1][y]->p_dspin_ram_rsp_in[EAST]  (signal_dspin_false_ram_rsp_in[XMAX-1][y][EAST]);
1333     clusters[XMAX-1][y]->p_dspin_ram_rsp_out[EAST] (signal_dspin_false_ram_rsp_out[XMAX-1][y][EAST]);
1334   }
1335
1336   std::cout << "East & West boundaries established" << std::endl;
1337
1338   // North & South boundary clusters connections
1339   for (size_t x = 0; x < XMAX; x++)
1340   {
1341      for (size_t k = 0; k < 3; k++)
1342      {
1343         clusters[x][0]->p_dspin_int_cmd_in[SOUTH][k]         (signal_dspin_false_int_cmd_in[x][0][SOUTH][k]);
1344         clusters[x][0]->p_dspin_int_cmd_out[SOUTH][k]        (signal_dspin_false_int_cmd_out[x][0][SOUTH][k]);
1345         clusters[x][YMAX-1]->p_dspin_int_cmd_in[NORTH][k]    (signal_dspin_false_int_cmd_in[x][YMAX-1][NORTH][k]);
1346         clusters[x][YMAX-1]->p_dspin_int_cmd_out[NORTH][k]   (signal_dspin_false_int_cmd_out[x][YMAX-1][NORTH][k]);
1347      }
1348
1349      for (size_t k = 0; k < 2; k++)
1350      {
1351         clusters[x][0]->p_dspin_int_rsp_in[SOUTH][k]         (signal_dspin_false_int_rsp_in[x][0][SOUTH][k]);
1352         clusters[x][0]->p_dspin_int_rsp_out[SOUTH][k]        (signal_dspin_false_int_rsp_out[x][0][SOUTH][k]);
1353         clusters[x][YMAX-1]->p_dspin_int_rsp_in[NORTH][k]    (signal_dspin_false_int_rsp_in[x][YMAX-1][NORTH][k]);
1354         clusters[x][YMAX-1]->p_dspin_int_rsp_out[NORTH][k]   (signal_dspin_false_int_rsp_out[x][YMAX-1][NORTH][k]);
1355      }
1356
1357      clusters[x][0]->p_dspin_ram_cmd_in[SOUTH]       (signal_dspin_false_ram_cmd_in[x][0][SOUTH]);
1358      clusters[x][0]->p_dspin_ram_cmd_out[SOUTH]      (signal_dspin_false_ram_cmd_out[x][0][SOUTH]);
1359      clusters[x][0]->p_dspin_ram_rsp_in[SOUTH]       (signal_dspin_false_ram_rsp_in[x][0][SOUTH]);
1360      clusters[x][0]->p_dspin_ram_rsp_out[SOUTH]      (signal_dspin_false_ram_rsp_out[x][0][SOUTH]);
1361
1362      clusters[x][YMAX-1]->p_dspin_ram_cmd_in[NORTH]  (signal_dspin_false_ram_cmd_in[x][YMAX-1][NORTH]);
1363      clusters[x][YMAX-1]->p_dspin_ram_cmd_out[NORTH] (signal_dspin_false_ram_cmd_out[x][YMAX-1][NORTH]);
1364      clusters[x][YMAX-1]->p_dspin_ram_rsp_in[NORTH]  (signal_dspin_false_ram_rsp_in[x][YMAX-1][NORTH]);
1365      clusters[x][YMAX-1]->p_dspin_ram_rsp_out[NORTH] (signal_dspin_false_ram_rsp_out[x][YMAX-1][NORTH]);
1366   }
1367
1368   std::cout << "North & South boundaries established" << std::endl << std::endl;
1369
1370   ////////////////////////////////////////////////////////
1371   //   Simulation
1372   ///////////////////////////////////////////////////////
1373
1374   sc_start(sc_core::sc_time(0, SC_NS));
1375
1376   signal_resetn = false;
1377   signal_irq_false = false;
1378
1379   // network boundaries signals
1380   for (size_t x = 0; x < XMAX ; x++)
1381   {
1382      for (size_t y = 0; y < YMAX ; y++)
1383      {
1384         for (size_t a = 0; a < 4; a++)
1385         {
1386            for (size_t k = 0; k < 3; k++)
1387            {
1388               signal_dspin_false_int_cmd_in[x][y][a][k].write = false;
1389               signal_dspin_false_int_cmd_in[x][y][a][k].read = true;
1390               signal_dspin_false_int_cmd_out[x][y][a][k].write = false;
1391               signal_dspin_false_int_cmd_out[x][y][a][k].read = true;
1392            }
1393
1394            for (size_t k = 0; k < 2; k++)
1395            {
1396               signal_dspin_false_int_rsp_in[x][y][a][k].write = false;
1397               signal_dspin_false_int_rsp_in[x][y][a][k].read = true;
1398               signal_dspin_false_int_rsp_out[x][y][a][k].write = false;
1399               signal_dspin_false_int_rsp_out[x][y][a][k].read = true;
1400            }
1401
1402            signal_dspin_false_ram_cmd_in[x][y][a].write = false;
1403            signal_dspin_false_ram_cmd_in[x][y][a].read = true;
1404            signal_dspin_false_ram_cmd_out[x][y][a].write = false;
1405            signal_dspin_false_ram_cmd_out[x][y][a].read = true;
1406
1407            signal_dspin_false_ram_rsp_in[x][y][a].write = false;
1408            signal_dspin_false_ram_rsp_in[x][y][a].read = true;
1409            signal_dspin_false_ram_rsp_out[x][y][a].write = false;
1410            signal_dspin_false_ram_rsp_out[x][y][a].read = true;
1411         }
1412      }
1413   }
1414
1415   sc_start(sc_core::sc_time(1, SC_NS));
1416   signal_resetn = true;
1417
1418   // simulation loop
1419   struct timeval t1,t2;
1420
1421   // cycles between stats
1422   const size_t stats_period = 100000;
1423   const size_t simul_period = debug_ok ? debug_period : stats_period;
1424
1425   for (size_t n = 0; n < ncycles; n += simul_period)
1426   {
1427      // stats display
1428      if((n % stats_period) == 0)
1429      {
1430         if (n > 0)
1431         {
1432            gettimeofday(&t2, NULL);
1433
1434            uint64_t ms1 = (uint64_t) t1.tv_sec  * 1000ULL +
1435               (uint64_t) t1.tv_usec / 1000;
1436            uint64_t ms2 = (uint64_t) t2.tv_sec  * 1000ULL +
1437               (uint64_t) t2.tv_usec / 1000;
1438            std::cerr << "### cycle = " << n << " / frequency (Khz) = "
1439               << (double) stats_period / (double) (ms2 - ms1) << std::endl;
1440         }
1441
1442         gettimeofday(&t1, NULL);
1443      }
1444
1445      // Monitor a specific address for one L1 cache
1446      // clusters[1][1]->proc[0]->cache_monitor(0x50090ULL);
1447
1448      // Monitor a specific address for one L2 cache
1449      // clusters[0][0]->memc->cache_monitor( 0x170000ULL);
1450
1451      // Monitor a specific address for one XRAM
1452      // if (n == 3000000) clusters[0][0]->xram->start_monitor( 0x170000ULL , 64);
1453
1454      if (debug_ok and (n > debug_from) and (n % debug_period == 0))
1455      {
1456         std::cout << "****************** cycle " << std::dec << n ;
1457         std::cout << " ************************************************" << std::endl;
1458
1459         // trace proc[debug_proc_id]
1460         if ( debug_proc_id != 0xFFFFFFFF )
1461         {
1462            size_t l          = debug_proc_id % NB_PROCS_MAX ;
1463            size_t cluster_xy = debug_proc_id / NB_PROCS_MAX ;
1464            size_t x          = cluster_xy >> 4;
1465            size_t y          = cluster_xy & 0xF;
1466
1467            clusters[x][y]->proc[l]->print_trace(1);
1468            std::ostringstream proc_signame;
1469            proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ;
1470            clusters[x][y]->signal_int_vci_ini_proc[l].print_trace(proc_signame.str());
1471
1472            clusters[x][y]->xicu->print_trace(l);
1473            std::ostringstream xicu_signame;
1474            xicu_signame << "[SIG]XICU_" << x << "_" << y;
1475            clusters[x][y]->signal_int_vci_tgt_xicu.print_trace(xicu_signame.str());
1476
1477            //              clusters[x][y]->mdma->print_trace();
1478            //              std::ostringstream mdma_signame;
1479            //              mdma_signame << "[SIG]MDMA_" << x << "_" << y;
1480            //              clusters[x][y]->signal_int_vci_tgt_mdma.print_trace(mdma_signame.str());
1481
1482            if( clusters[x][y]->signal_proc_it[l].read() )
1483               std::cout << "### IRQ_PROC_" << std::dec
1484                  << x << "_" << y << "_" << l << " ACTIVE" << std::endl;
1485         }
1486
1487         // trace memc[debug_memc_id]
1488         if ( debug_memc_id != 0xFFFFFFFF )
1489         {
1490            size_t x = debug_memc_id >> 4;
1491            size_t y = debug_memc_id & 0xF;
1492
1493            clusters[x][y]->memc->print_trace(0);
1494            std::ostringstream smemc_tgt;
1495            smemc_tgt << "[SIG]MEMC_TGT_" << x << "_" << y;
1496            clusters[x][y]->signal_int_vci_tgt_memc.print_trace(smemc_tgt.str());
1497            std::ostringstream smemc_ini;
1498            smemc_ini << "[SIG]MEMC_INI_" << x << "_" << y;
1499            clusters[x][y]->signal_ram_vci_ini_memc.print_trace(smemc_ini.str());
1500
1501            clusters[x][y]->xram->print_trace();
1502            std::ostringstream sxram_tgt;
1503            sxram_tgt << "[SIG]XRAM_TGT_" << x << "_" << y;
1504            clusters[x][y]->signal_ram_vci_tgt_xram.print_trace(sxram_tgt.str());
1505         }
1506
1507
1508         // trace XRAM and XRAM network routers in cluster[debug_xram_id]
1509         if ( debug_xram_id != 0xFFFFFFFF )
1510         {
1511            size_t x = debug_xram_id >> 4;
1512            size_t y = debug_xram_id & 0xF;
1513
1514            clusters[x][y]->xram->print_trace();
1515            std::ostringstream sxram_tgt;
1516            sxram_tgt << "[SIG]XRAM_TGT_" << x << "_" << y;
1517            clusters[x][y]->signal_ram_vci_tgt_xram.print_trace(sxram_tgt.str());
1518
1519            clusters[x][y]->ram_router_cmd->print_trace();
1520            clusters[x][y]->ram_router_rsp->print_trace();
1521         }
1522
1523         // trace iob, iox and external peripherals
1524         if ( debug_iob )
1525         {
1526            clusters[0][0]->iob->print_trace();
1527            clusters[XMAX-1][YMAX-1]->iob->print_trace();
1528            //              clusters[0][0]->signal_int_vci_tgt_iobx.print_trace( "[SIG]IOB0_INT_TGT");
1529            //              clusters[0][0]->signal_int_vci_ini_iobx.print_trace( "[SIG]IOB0_INT_INI");
1530            //              clusters[0][0]->signal_ram_vci_ini_iobx.print_trace( "[SIG]IOB0_RAM_INI");
1531
1532            signal_vci_ini_iob0.print_trace("[SIG]IOB0_IOX_INI");
1533            signal_vci_tgt_iob0.print_trace("[SIG]IOB0_IOX_TGT");
1534
1535            //              cdma->print_trace();
1536            //              signal_vci_tgt_cdma.print_trace("[SIG]IOX_CDMA_TGT");
1537            //              signal_vci_ini_cdma.print_trace("[SIG]IOX_CDMA_INI");
1538
1539            //              mtty->print_trace();
1540            //              signal_vci_tgt_mtty.print_trace("[SIG]IOX_MTTY_TGT");
1541
1542            bdev->print_trace();
1543            signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT");
1544            signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI");
1545
1546            mnic->print_trace();
1547            signal_vci_tgt_mnic.print_trace("[SIG]MNIC_TGT");
1548
1549            //              fbuf->print_trace();
1550            //              signal_vci_tgt_fbuf.print_trace("[SIG]FBUF");
1551
1552            iopi->print_trace();
1553            signal_vci_ini_iopi.print_trace("[SIG]IOPI_INI");
1554            signal_vci_tgt_iopi.print_trace("[SIG]IOPI_TGT");
1555
1556            signal_vci_tgt_simh.print_trace("[SIG]SIMH_TGT");
1557
1558            iox_network->print_trace();
1559
1560            // interrupts
1561            if (signal_irq_bdev)       std::cout << "### IRQ_BDEV ACTIVE"       << std::endl;
1562            if (signal_irq_mtty_rx)    std::cout << "### IRQ_MTTY ACTIVE"       << std::endl;
1563            if (signal_irq_mnic_rx[0]) std::cout << "### IRQ_MNIC_RX[0] ACTIVE" << std::endl;
1564            if (signal_irq_mnic_rx[1]) std::cout << "### IRQ_MNIC_RX[1] ACTIVE" << std::endl;
1565            if (signal_irq_mnic_tx[0]) std::cout << "### IRQ_MNIC_TX[0] ACTIVE" << std::endl;
1566            if (signal_irq_mnic_tx[1]) std::cout << "### IRQ_MNIC_TX[1] ACTIVE" << std::endl;
1567         }
1568      }
1569
1570      sc_start(sc_core::sc_time(simul_period, SC_NS));
1571   }
1572   return EXIT_SUCCESS;
1573}
1574
1575int sc_main (int argc, char *argv[])
1576{
1577   try {
1578      return _main(argc, argv);
1579   } catch (soclib::exception::RunTimeError &e) {
1580      std::cout << "RunTimeError: " << e.what() << std::endl;
1581   } catch (std::exception &e) {
1582      std::cout << e.what() << std::endl;
1583   } catch (...) {
1584      std::cout << "Unknown exception occured" << std::endl;
1585      throw;
1586   }
1587   return 1;
1588}
1589
1590
1591// Local Variables:
1592// tab-width: 3
1593// c-basic-offset: 3
1594// c-file-offsets:((innamespace . 0)(inline-open . 0))
1595// indent-tabs-mode: nil
1596// End:
1597
1598// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
1599
1600
1601
Note: See TracBrowser for help on using the repository browser.