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

Last change on this file since 875 was 875, checked in by cfuguet, 9 years ago

reconf: merge modifications from the trunk/tsar_generic_iob (r874)

r874 commit message:
Introducing support for multiple TTY terminals (up to 16 channels)
in the tsar_generic_iob platform.

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