Index: /trunk/softs/test_llsc/Makefile
===================================================================
--- /trunk/softs/test_llsc/Makefile	(revision 536)
+++ /trunk/softs/test_llsc/Makefile	(revision 536)
@@ -0,0 +1,6 @@
+simul.x: top.cpp top.desc
+	soclib-cc -P -p top.desc -I. -o simul.x
+
+clean:
+	soclib-cc -x -p top.desc -I.
+	rm -rf *.o *.x term*
Index: /trunk/softs/test_llsc/README
===================================================================
--- /trunk/softs/test_llsc/README	(revision 536)
+++ /trunk/softs/test_llsc/README	(revision 536)
@@ -0,0 +1,11 @@
+
+This directory contains a script aiming at using intensively the LL/SC table, making a lot of concurrent increments on some shared variables.
+
+For each test generated, a sequential native version is made and executed, so as to have a reference result of the test. It is then diff'ed with the output of the simulated version.
+
+The main script to execute is run_simus.sh in the scripts/ directory. Some of its parameters can be set inside it (e.g. the number of processors).
+
+The sub-directory LLSCTestGenerator contains the tool which generates the source files (1 for native sequential execution, 2 for simulated execution).
+
+The simulated application is compiled using DSX-VM.
+
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Genere_Tests.cpp
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Genere_Tests.cpp	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Genere_Tests.cpp	(revision 536)
@@ -0,0 +1,58 @@
+/*
+ * Outil pour la gÃ©nÃ©ration de test de la table LL/SC
+ * @Author QM
+ */
+
+#include "Program.hpp"
+#include "config.h"
+
+#include <time.h>
+#include <cstdlib>
+#include <iostream>
+#include <cstdio>
+
+int main(int argc, char** argv){
+
+   if (argc != 9){
+      printf("usage: genere_test <nb_procs> <nb_max_incr> <nb_locks_and_vars> <locks_horizontal> <vars_horizontal> <native_filename> <main_task_filename> <task_no_tty_filename>\n");
+      exit(1);
+   }
+
+   srand(time(NULL));
+
+   FILE * native_file;
+   FILE * main_task_file;
+   FILE * task_no_tty_file;
+   
+   native_file = fopen(argv[6], "w");
+   main_task_file = fopen(argv[7], "w");
+   task_no_tty_file = fopen(argv[8], "w");
+
+   const int nb_procs = atoi(argv[1]);
+   const int nb_max_incr = atoi(argv[2]);
+   const int nb_locks = atoi(argv[3]);
+
+   const bool lock_horizontal = atoi(argv[4]);
+   const bool vars_horizontal = atoi(argv[5]);
+
+	const int line_size = LINE_SIZE;
+
+   Program prog(nb_procs, nb_locks, nb_max_incr, line_size, lock_horizontal, vars_horizontal);
+
+   string s = prog.write_output();
+   fprintf(native_file, "%s", s.c_str());
+   fclose(native_file);
+
+   s = prog.write_main_task();
+   fprintf(main_task_file, "%s", s.c_str());
+   fclose(main_task_file);
+ 
+   s = prog.write_task_no_tty();
+   fprintf(task_no_tty_file, "%s", s.c_str());
+   fclose(task_no_tty_file);  
+
+   return 0;
+}
+
+
+
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Increment.hpp
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Increment.hpp	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Increment.hpp	(revision 536)
@@ -0,0 +1,53 @@
+
+#ifndef _increment_hpp_
+#define _increment_hpp_
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <sstream>
+
+#include "functions.h"
+
+using namespace std;
+
+class Increment {
+   int lock_index;
+   int var_index;
+   int line_size;
+
+   public:
+
+   Increment(int nb_locks, int line_size, bool lock_in_line, bool vars_in_line){
+      this->line_size = line_size;
+
+      int index = randint(0, nb_locks - 1);
+      int lock_size = (lock_in_line ? ceil((float) nb_locks / line_size) * line_size : nb_locks * line_size);
+
+      lock_index = (lock_in_line ? index : index * line_size);
+      var_index = (vars_in_line ? lock_size + index : lock_size + index * line_size);
+   }
+
+   ~Increment() {}
+
+   string write_output() {
+      stringstream res;
+      res << "   tab[" << var_index << "]++;" << endl;
+
+      return res.str();
+   }
+
+   string write_task() {
+      stringstream res;
+      res << "   take_lock(&tab[" << lock_index << "]);" << endl;
+      res << "   tab[" << var_index << "]++;" << endl;
+      res << "   release_lock(&tab[" << lock_index << "]);" << endl;
+
+      return res.str();
+   }
+
+};
+
+#endif
+
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Makefile
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Makefile	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Makefile	(revision 536)
@@ -0,0 +1,11 @@
+
+HPP_FILES = $(wildcard *.hpp)
+
+
+all: generate_test
+
+generate_test: Genere_Tests.cpp $(HPP_FILES) config.h
+	g++ -o $@ $<
+
+clean:
+	rm -f generate_test
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Program.hpp
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Program.hpp	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/Program.hpp	(revision 536)
@@ -0,0 +1,259 @@
+
+#ifndef _program_hpp_
+#define _program_hpp_
+
+#include <iostream>
+#include <sstream>
+#include <stdbool.h>
+
+#include "config.h"
+#include "TestThread.hpp"
+
+
+using namespace std;
+
+class Program {
+
+   int nb_threads;
+   int nb_max_incr;
+   int nb_locks;
+   int nb_vars;
+   int line_size;
+   bool lock_in_line, vars_in_line;
+   int tab_size;
+   TestThread ** threads;
+
+   public:
+
+   Program(int nb_procs, int nb_locks, int nb_max_accesses, int line_size, bool lock_in_line, bool vars_in_line){
+      this->nb_threads = nb_procs;
+      this->nb_max_incr = nb_max_accesses;
+      this->nb_locks = nb_locks;
+      this->nb_vars = nb_locks;
+      this->line_size = line_size;
+      this->lock_in_line = lock_in_line;
+      this->vars_in_line = vars_in_line;
+      this->tab_size = (lock_in_line ? ceil((float) nb_locks / line_size) * line_size : nb_locks * line_size) + (vars_in_line ? ceil((float) nb_vars / line_size) * line_size : nb_vars * line_size);
+      this->threads = new TestThread * [nb_threads];
+
+      for (int i = 0; i < nb_threads; i++){
+         threads[i] = new TestThread(nb_locks, nb_max_accesses, line_size, lock_in_line, vars_in_line, i);
+      }
+   }
+
+   ~Program(){
+      for (int i = 0; i < nb_threads; i++){
+         delete threads[i];
+      }
+      delete [] threads;
+   }
+
+
+   string write_main_task() {
+      stringstream res;
+      res << "#include \"srl.h\"" << endl;
+      res << "#include \"stdio.h\"" << endl;
+      res << "#include \"test_llsc_main_proto.h\"" << endl;
+      res << "#include \"functions.h\"" << endl;
+      res << endl;
+      res << "/*" << endl;
+      res << " * Test generated for a dsx_vm compilation" << endl;
+      res << " * NB_LOCKS : " << nb_locks << endl;
+      res << " * NB_VARS : " << nb_vars << endl;
+      if (lock_in_line) {
+         res << " * LOCKS PLACEMENT : horizontal" << endl;
+      }
+      else {
+         res << " * LOCKS PLACEMENT : vertical" << endl;
+      }
+      if (vars_in_line) {
+         res << " * VARS PLACEMENT : horizontal" << endl;
+      }
+      else {
+         res << " * VARS PLACEMENT : vertical" << endl;
+      }
+      res << " * NB_MAX_INCRS : " << nb_max_incr << endl;
+      res << " * LINE_SIZE : " << LINE_SIZE << endl;
+      res << " */" << endl;
+      res << endl;
+      res << "int * tab;" << endl;
+      res << endl;
+      res << threads[0]->write_task();
+      res << endl;
+      res << endl;
+      res << "FUNC(test_llsc_main_func) {" << endl;
+      res << endl;
+      res << "   int i;" << endl;
+      res << endl;
+      res << "   srl_memspace_t memspace = SRL_GET_MEMSPACE(table);" << endl;
+      res << "   tab = (int *) SRL_MEMSPACE_ADDR(memspace);" << endl;
+      res << "   srl_barrier_t barrier = SRL_GET_BARRIER(barrier);" << endl;
+      res << endl;
+      res << "   // Initialisation du tableau" << endl;
+      res << "   for (i = 0; i < " << tab_size << "; i++) {" << endl;
+      res << "      tab[i] = 0;" << endl;
+      res << "   }" << endl;
+      res << endl;
+      res << "   barrier_wait(barrier);" << endl;
+      res << endl;
+      res << "   run0();" << endl;
+      res << endl;
+      res << "   barrier_wait(barrier);" << endl;
+      res << endl;
+      res << "   for (i = 0; i < " << tab_size << "; i++) {" << endl;
+      res << "      if (tab[i] != 0) {" << endl;
+      res << "         giet_tty_printf(\"tab[%d] final : %d\\n\", i, tab[i]);" << endl;
+      res << "      }" << endl;
+      res << "   }" << endl;
+      res << endl;
+      res << "   *(unsigned int *) 0x0 = 0xDEADDEAD;" << endl;
+      res << endl;
+      res << "   srl_exit();" << endl;
+      res << "}" << endl;
+      res << endl;
+
+      return res.str();
+   }
+
+   
+   string write_task_no_tty() {
+      stringstream res;
+      res << "#include \"srl.h\"" << endl;
+      res << "#include \"stdio.h\"" << endl;
+      res << "#include \"test_llsc_no_tty_proto.h\"" << endl;
+      res << "#include \"functions.h\"" << endl;
+      res << endl;
+      res << "/*" << endl;
+      res << " * Test generated for a dsx_vm compilation" << endl;
+      res << " * NB_LOCKS : " << nb_locks << endl;
+      res << " * NB_VARS : " << nb_vars << endl;
+      if (lock_in_line) {
+         res << " * LOCKS PLACEMENT : horizontal" << endl;
+      }
+      else {
+         res << " * LOCKS PLACEMENT : vertical" << endl;
+      }
+      if (vars_in_line) {
+         res << " * VARS PLACEMENT : horizontal" << endl;
+      }
+      else {
+         res << " * VARS PLACEMENT : vertical" << endl;
+      }
+      res << " * NB_MAX_INCRS : " << nb_max_incr << endl;
+      res << " * LINE_SIZE : " << LINE_SIZE << endl;
+      res << " */" << endl;
+      res << endl;
+      res << "int * tab;" << endl;
+      res << endl;
+
+      for (int i = 1; i < nb_threads; i++) {
+         res << threads[i]->write_task();
+      }
+      
+      res << endl;
+      res << endl;
+      res << "FUNC(test_llsc_no_tty_func) {" << endl;
+      res << endl;
+      res << "   srl_memspace_t memspace = SRL_GET_MEMSPACE(table);" << endl;
+      res << "   tab = (int *) SRL_MEMSPACE_ADDR(memspace);" << endl;
+      res << "   srl_barrier_t barrier = SRL_GET_BARRIER(barrier);" << endl;
+      res << "   int thread_id = SRL_GET_CONST(id);" << endl;
+      res << endl;
+      res << "   barrier_wait(barrier);" << endl;
+      res << endl;
+      res << "   if (thread_id == 1) {" << endl;
+      res << "      run1();" << endl;
+      res << "   }" << endl;
+      for (int i = 2; i < nb_threads; i++) {
+         res << "   else if (thread_id == " << i << ") {" << endl;
+         res << "      run" << i << "();" << endl;
+         res << "   }" << endl;
+      }
+      res << "   else {" << endl;
+      res << "      srl_assert(0);" << endl;
+      res << "   }" << endl;
+      res << endl;
+      res << "   barrier_wait(barrier);" << endl;
+      res << endl;
+      res << "   srl_exit();" << endl;
+      res << endl;
+      res << "}" << endl;
+      res << endl;
+
+      return res.str();
+   }
+
+
+   string write_output() {
+      cout << tab_size;
+      stringstream res;
+      res << endl;
+      res << "#include <stdio.h>" << endl;
+      res << "#include <assert.h>" << endl;
+      res << endl;
+      res << "/*" << endl;
+      res << " * Test generated for a posix execution" << endl;
+      res << " * NB_LOCKS : " << nb_locks << endl;
+      res << " * NB_VARS : " << nb_vars << endl;
+      if (lock_in_line) {
+         res << " * LOCKS PLACEMENT : horizontal" << endl;
+      }
+      else {
+         res << " * LOCKS PLACEMENT : vertical" << endl;
+      }
+      if (vars_in_line) {
+         res << " * VARS PLACEMENT : horizontal" << endl;
+      }
+      else {
+         res << " * VARS PLACEMENT : vertical" << endl;
+      }
+      res << " * NB_MAX_INCRS : " << nb_max_incr << endl;
+      res << " * LINE_SIZE : " << LINE_SIZE << endl;
+      res << " */" << endl;
+      res << endl;
+      res << "volatile int tab[" << tab_size << "];" << endl;
+      res << endl;
+      res << endl;
+
+      
+      for (int i = 0; i < nb_threads; i++) {
+         res << threads[i]->write_output();
+      }
+      
+      res << "int main() {" << endl;
+      res << endl;
+      res << "   int i;" << endl;
+      res << endl;
+      res << "   /* Version native sÃ©quentielle */" << endl;
+      res << endl;
+      res << "   // Initialisation du tableau" << endl;
+      res << "   for (i = 0; i < " << tab_size << "; i++) {" << endl;
+      res << "      tab[i] = 0;" << endl;
+      res << "   }" << endl;
+      res << endl;
+      res << "   run0();" << endl;
+      for (int i = 1; i < nb_threads; i++){
+         res << "   run" << i << "();" << endl;
+      }
+      res << endl;
+      res << "   for (i = 0; i < " << tab_size << "; i++) {" << endl;
+      res << "      if (tab[i] != 0) {" << endl;
+      res << "         printf(\"tab[%d] final : %d\\n\", i, tab[i]);" << endl;
+      res << "      }" << endl;
+      res << "   }" << endl;
+      res << endl;
+      res << "   return 0;" << endl;
+      res << "}" << endl;
+      res << endl;
+
+      return res.str();
+    }
+
+};
+
+#endif
+
+
+
+
+
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/TestThread.hpp
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/TestThread.hpp	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/TestThread.hpp	(revision 536)
@@ -0,0 +1,70 @@
+
+#ifndef _testthread_hpp_
+#define _testthread_hpp_
+
+#include <iostream>
+#include <sstream>
+#include <list>
+
+#include "Increment.hpp"
+
+using namespace std;
+
+class TestThread {
+
+   int proc_id;
+   std::list<Increment *> requests;
+
+   public:
+
+   TestThread(int nb_locks, int nb_max_accesses, int line_size, bool lock_in_line, bool vars_in_line, int proc_id) {
+      this->proc_id = proc_id;
+      const int nb_accesses = randint(1, nb_max_accesses);
+      for (int i = 0; i < nb_accesses; i++) {
+         Increment * t;
+         t = new Increment(nb_locks, line_size, lock_in_line, vars_in_line);
+         requests.push_back(t);
+      }
+   }
+
+   ~TestThread() {
+      std::list<Increment *>::iterator it;
+      for (it = requests.begin(); it != requests.end(); it++) {
+         delete (*it);
+      }
+      requests.clear();
+   }
+   
+   string write_output() {
+      stringstream res;
+      res << "void run" << proc_id << "() {" << endl;
+
+      std::list<Increment *>::iterator it;
+      for (it = requests.begin(); it != requests.end(); it++) {
+         res << (*it)->write_output();
+      }
+
+      res << "}" << endl;
+      res << endl;
+
+      return res.str();
+   }
+
+
+   string write_task() {
+      stringstream res;
+      res << "__attribute__((constructor)) void run" << proc_id << "() {" << endl;
+
+      std::list<Increment *>::iterator it;
+      for (it = requests.begin(); it != requests.end(); it++) {
+         res << (*it)->write_task();
+      }
+
+      res << "}" << endl;
+      res << endl;
+
+      return res.str();
+   }
+};
+
+#endif
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/config.h
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/config.h	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/config.h	(revision 536)
@@ -0,0 +1,8 @@
+
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+#define LINE_SIZE 16
+
+#endif
+
Index: /trunk/softs/test_llsc/scripts/LLSCTestGenerator/functions.h
===================================================================
--- /trunk/softs/test_llsc/scripts/LLSCTestGenerator/functions.h	(revision 536)
+++ /trunk/softs/test_llsc/scripts/LLSCTestGenerator/functions.h	(revision 536)
@@ -0,0 +1,43 @@
+
+#ifndef _functions_h_
+#define _functions_h_
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static int mylog2(size_t v) {
+   static const size_t b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 };
+   static const size_t S[] = { 1, 2, 4, 8, 16 };
+   int i;
+   register size_t r = 0;
+   for (i = 4; i >= 0; i--) {
+      if (v & b[i]) {
+         v >>= S[i];
+         r |= S[i];
+      }
+   }
+   return r + 1;
+}
+
+/*int randint(int a,int b){
+   int range = b - a + 1;
+   int length = (int) ceil(log2(range));
+   int mask = (int) pow(2,length) - 1;
+   printf("mask : %d\n",mask);
+   int res;
+   do {
+      res = rand() & mask;
+   }
+   while (res >= range);
+   return (res + a);
+}*/
+
+int randint(int a, int b){
+   int range = b - a + 1;
+   int res = rand() % range;
+   return res + a;
+}
+
+
+#endif
Index: /trunk/softs/test_llsc/scripts/Makefile.nat
===================================================================
--- /trunk/softs/test_llsc/scripts/Makefile.nat	(revision 536)
+++ /trunk/softs/test_llsc/scripts/Makefile.nat	(revision 536)
@@ -0,0 +1,6 @@
+
+all: test_natif
+
+test_natif: test_llsc.c
+	gcc -o $@ $<
+
Index: /trunk/softs/test_llsc/scripts/functions.c
===================================================================
--- /trunk/softs/test_llsc/scripts/functions.c	(revision 536)
+++ /trunk/softs/test_llsc/scripts/functions.c	(revision 536)
@@ -0,0 +1,28 @@
+
+#include "functions.h"
+
+void take_lock(volatile int * plock) {
+   volatile int * _plock = plock;
+   __asm__ __volatile__ (
+      "move $16, %0                   \n"
+      "giet_lock_try :                \n"
+      "ll   $2,    0($16)             \n"
+      "bnez $2,    giet_lock_try      \n"
+      "li   $3,    1                  \n"
+      "sc   $3,    0($16)             \n"
+      "beqz $3,    giet_lock_try      \n"
+      "nop                            \n"
+      "giet_lock_ok:                  \n"
+      "nop                            \n"
+      :                                
+      :"r" (_plock)                  
+      :"$2", "$3", "$4", "$16");
+}
+
+
+void release_lock(volatile int * plock) {
+   asm volatile("\tsync\n");
+   *plock = 0;
+}
+
+
Index: /trunk/softs/test_llsc/scripts/functions.h
===================================================================
--- /trunk/softs/test_llsc/scripts/functions.h	(revision 536)
+++ /trunk/softs/test_llsc/scripts/functions.h	(revision 536)
@@ -0,0 +1,8 @@
+#ifndef _FUNCTIONS_H_
+#define _FUNCTIONS_H_
+
+
+void take_lock(volatile int * plock);
+void release_lock(volatile int * plock);
+
+#endif
Index: /trunk/softs/test_llsc/scripts/run_simus.py
===================================================================
--- /trunk/softs/test_llsc/scripts/run_simus.py	(revision 536)
+++ /trunk/softs/test_llsc/scripts/run_simus.py	(revision 536)
@@ -0,0 +1,121 @@
+#!/usr/bin/python
+
+import subprocess
+import os
+import random
+
+data_dir = 'data'
+gen_dir = 'generated'
+test_gen_tool_dir = 'LLSCTestGenerator'
+
+test_gen_binary = 'generate_test'
+
+log_init_name = 'log_init_'
+log_term_name = 'log_term_'
+
+generated_test = 'test_llsc.c'
+main_task = 'test_llsc_main.c'
+task_no_tty = 'test_llsc_no_tty.c'
+
+res_natif = 'res_natif.txt'
+
+# Parametres des tests
+nb_locks = 20
+nb_max_incr = 2000
+nb_procs = 4
+
+
+os.chdir(os.path.dirname(__file__))
+
+scripts_path = os.path.abspath(".")
+top_path = os.path.abspath("../")
+
+topcell_name = "top.cpp"
+
+
+random.seed()
+
+
+def get_x_y(nb_procs):
+   x = 1
+   y = 1
+   to_x = True
+   while (x * y * 4 < nb_procs):
+      if to_x:
+         x = x * 2
+      else:
+         y = y * 2
+      to_x = not to_x
+   return x, y
+
+
+print "make -C", test_gen_tool_dir
+subprocess.call([ 'make', '-C', test_gen_tool_dir ])
+
+print "cp", os.path.join(test_gen_tool_dir, test_gen_binary), os.path.join(scripts_path, test_gen_binary)
+subprocess.call([ 'cp', os.path.join(test_gen_tool_dir, test_gen_binary), os.path.join(scripts_path, test_gen_binary)])
+
+print "mkdir -p", os.path.join(scripts_path, data_dir)
+subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ])
+
+while True:
+   x, y = get_x_y(nb_procs)
+   
+   b0 = random.randint(0, 1)
+   b1 = random.randint(0, 1)
+
+   print test_gen_binary, nb_procs, nb_max_incr, nb_locks, b0, b1, generated_test, main_task, task_no_tty
+   tab_size = subprocess.Popen([ os.path.join(scripts_path, test_gen_binary), str(nb_procs), str(nb_max_incr), str(nb_locks), str(b0), str(b1), generated_test, main_task, task_no_tty ], stdout = subprocess.PIPE).communicate()[0]
+   
+   print "make -f Makefile.nat"
+   subprocess.call([ 'make', '-f', 'Makefile.nat' ])
+
+   print "./test_natif >", os.path.join(data_dir, res_natif)
+   output = subprocess.Popen([ './test_natif' ], stdout = subprocess.PIPE).communicate()[0]
+   file = open(os.path.join(data_dir, res_natif), 'w')
+   file.write(output)
+   file.close()
+
+   print "./test_llsc.py", str(x), str(y), tab_size
+   subprocess.call([ './test_llsc.py', str(x), str(y), tab_size ])
+   
+   print "cd", top_path
+   os.chdir(top_path)
+   print "touch", topcell_name
+   subprocess.call([ 'touch', topcell_name ])
+   print "make"
+   subprocess.call([ 'make' ])
+   
+   # Launch simulation
+   print "./simul.x >", os.path.join(scripts_path, data_dir, log_init_name + str(nb_procs))
+   output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0]
+
+   # Write simulation results to data directory
+   print "cd", scripts_path
+   os.chdir(scripts_path)
+   filename = os.path.join(data_dir, log_init_name + str(nb_procs))
+   file = open(filename, 'w')
+   file.write(output)
+   file.close()
+
+   term_filename = os.path.join(scripts_path, data_dir, log_term_name + str(nb_procs))
+   print "mv", os.path.join(top_path, 'term1'), term_filename
+   subprocess.call([ 'mv', os.path.join(top_path, 'term1'), term_filename ])
+   
+   # Quit if results obtained by simulation are incorrect
+   print "diff", term_filename, os.path.join(data_dir, res_natif)
+   output = subprocess.Popen([ 'diff', term_filename, os.path.join(data_dir, res_natif) ]).communicate()[0]
+   if output != None:
+      break;
+
+
+## Enf of simulations
+
+
+
+
+
+
+
+
+
Index: /trunk/softs/test_llsc/scripts/test_llsc.py
===================================================================
--- /trunk/softs/test_llsc/scripts/test_llsc.py	(revision 536)
+++ /trunk/softs/test_llsc/scripts/test_llsc.py	(revision 536)
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+
+import sys
+import dsx
+from tsarch import TSArch
+from dsx.mapper.mapper import Mapper
+from dsx import *
+
+
+
+if len(sys.argv) < 4 or sys.argv[1] == '' or sys.argv[2] == '':
+   print "Usage: ", sys.argv[0], "<nb_clusters_x> <nb_clusters_y> <memspace_size>"
+   exit()
+
+cluster_x = int(sys.argv[1])
+cluster_y = int(sys.argv[2])
+memspace_size = int(sys.argv[3])
+
+nb_procs = 4
+nb_total_procs = nb_procs * cluster_x * cluster_y
+
+hd = TSArch(cluster_x = cluster_x, cluster_y = cluster_y, nb_proc = nb_procs, nb_tty = 4)
+
+test_llsc = TaskModel(
+        'test_llsc_main',
+        ports = {
+            'table':   MemspacePort(),
+            'barrier': BarrierPort(),
+        },
+        impls = [
+                SwTask('test_llsc_main_func',
+                           stack_size = 2048,
+                           sources = ['test_llsc_main.c', 'functions.c'],
+                           headers = ['functions.h'],
+                           defines = [])
+        ], 
+        uses = ['tty']
+        )
+
+
+test_llsc_no_tty = TaskModel(
+        'test_llsc_no_tty',
+        ports = {
+            'table':   MemspacePort(),
+            'barrier': BarrierPort(),
+            'id' : ConstPort(),
+        },
+        impls = [
+                SwTask('test_llsc_no_tty_func',
+                           stack_size = 2048,
+                           sources = ['test_llsc_no_tty.c', 'functions.c'],
+                           headers = ['functions.h'],
+                           defines = [])
+        ],
+        )
+ 
+
+barrier = Barrier('barrier')
+memspace = Memspace('memspace', memspace_size)
+
+tasks = ()
+
+
+tasks += Task('task_llsc_main', 'test_llsc_main',
+            {
+               'table'   : memspace,
+               'barrier' : barrier,
+            },
+            defines = {} ),
+
+
+for i in range(1, nb_total_procs):
+   tasks += Task('task_llsc_no_tty_%d' % i, 'test_llsc_no_tty',
+            {
+               'table'   : memspace,
+               'barrier' : barrier,
+               'id' : i,
+            },
+            defines = {} ),
+
+
+
+
+tcg = dsx.Tcg('test_llsc', *tasks)
+
+mpr = Mapper(hd ,tcg) 
+
+mpr.map('task_llsc_main', cluster = 0, proc = 0, stack = "PSEG_RAM_0")
+
+for i in range(1, nb_total_procs):
+   #print "cluster = %d - proc = %d" % (int(i) / 4, i % 4)
+   mpr.map('task_llsc_no_tty_%d' % i, cluster = int(i) / 4, proc = int(i) % 4, stack = "PSEG_RAM_%d" % (int(i) / 4))
+
+for const in tcg.nodesOfType('const'):
+   mpr.map(const, pseg = 'PSEG_RAM_0')
+
+mpr.map('memspace', pseg = "PSEG_RAM_0")
+mpr.map('barrier', pseg = "PSEG_RAM_0")
+
+mpr.map(tcg, code = 'PSEG_RAM_0', data = 'PSEG_RAM_0', ptab = "PSEG_RAM_0")
+mpr.map('system', boot = 'PSEG_ROM', kernel = 'PSEG_RAM_0', scheduler = True)
+
+mpr.generate(dsx.Giet(outdir = '.', vaddr_replicated_peri_inc = 0x100000))
+
Index: /trunk/softs/test_llsc/scripts/tsarch.py
===================================================================
--- /trunk/softs/test_llsc/scripts/tsarch.py	(revision 536)
+++ /trunk/softs/test_llsc/scripts/tsarch.py	(revision 536)
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+from dsx.hard.hard import *
+
+
+def TSArch(cluster_x, cluster_y, nb_proc = 1, nb_tty = 8, wcoproc = False):
+ 
+    nb_cluster = cluster_x * cluster_y
+
+    hd = Hardware(cluster_x, cluster_y , addr_size = 40, nb_proc = nb_proc, ccoherence = True) #nb_proc : proc by cluster
+
+
+    ######### peripherals ##########
+    hd.add(Tty('PSEG_TTY', pbase = 0xB4000000, channel_size = 16, nb_channel = nb_tty))
+    hd.add(Fbf('PSEG_FBF', pbase = 0xB2000000, channel_size = 352 * 288 * 2, nb_channel = 1))
+    hd.add(Ioc('PSEG_IOC', pbase = 0xB3000000, channel_size = 32, nb_channel = 1))
+
+    hd.add(Xicu('PSEG_XICU', pbase = 0xB0000000, channel_size = 32, nb_channel = nb_proc, replicated = True)) # name suffixed with "_<num_cluster>"
+    hd.add(Dma('PSEG_DMA', pbase = 0xB1000000, channel_size = 32, nb_channel = nb_proc, replicated = True))
+    
+    ############## MEMORY ###########
+    for cl in range(nb_cluster):
+        hd.add(RAM('PSEG_RAM_%d'%cl, pbase = 0x00000000 + (cl * hd.cluster_span), size = 0x00C00000))
+
+    ############## IRQ ############
+    hd.add(Irq(cluster_id = 0, proc_id = 0, icu_irq_id = 31, peri = Ioc, channel_id = 0))
+    for j in range(16, 31):
+        hd.add(Irq(cluster_id = 0, proc_id = 0, icu_irq_id = j, peri = Tty, channel_id = j - 16))
+
+    for cl in range(nb_cluster):
+        for p in xrange(nb_proc):
+            hd.add(Irq(cluster_id = cl, proc_id = p, icu_irq_id = p + 8, peri = Dma,  channel_id = p))
+            hd.add(Irq(cluster_id = cl, proc_id = p, icu_irq_id = p,     peri = Xicu, channel_id = p)) 
+
+
+    ############# ROM ############
+    hd.add(ROM("PSEG_ROM", pbase = 0xbfc00000, size = 0x00100000)) 
+
+    return hd
+
Index: /trunk/softs/test_llsc/top.cpp
===================================================================
--- /trunk/softs/test_llsc/top.cpp	(revision 536)
+++ /trunk/softs/test_llsc/top.cpp	(revision 536)
@@ -0,0 +1,1038 @@
+/////////////////////////////////////////////////////////////////////////
+// File: top.cpp 
+// Author: Alain Greiner 
+// Copyright: UPMC/LIP6
+// Date : may 2013
+// This program is released under the GNU public license
+/////////////////////////////////////////////////////////////////////////
+// This file define a generic TSAR architecture.
+// The physical address space is 40 bits.
+//
+// The number of clusters cannot be larger than 256.
+// The number of processors per cluster cannot be larger than 8.
+// 
+// - It uses four dspin_local_crossbar per cluster as local interconnect 
+// - It uses two virtual_dspin routers per cluster as global interconnect
+// - It uses the vci_cc_vcache_wrapper 
+// - It uses the vci_mem_cache
+// - It contains one vci_xicu per cluster.
+// - It contains one vci_multi_dma per cluster.
+// - It contains one vci_simple_ram per cluster to model the L3 cache.
+//
+// The communication between the MemCache and the Xram is 64 bits.
+//
+// All clusters are identical, but the cluster 0 (called io_cluster), 
+// contains 6 extra components:
+// - the boot rom (BROM)
+// - the disk controller (BDEV)
+// - the multi-channel network controller (MNIC)
+// - the multi-channel chained buffer dma controller (CDMA)
+// - the multi-channel tty controller (MTTY)
+// - the frame buffer controller (FBUF)
+//
+// It is build with one single component implementing a cluster,
+// defined in files tsar_xbar_cluster.* (with * = cpp, h, sd)
+//
+// The IRQs are connected to XICUs as follow:
+// - The IRQ_IN[0] to IRQ_IN[7] ports are not used in all clusters.
+// - The DMA IRQs are connected to IRQ_IN[8] to IRQ_IN[15] in all clusters.
+// - The TTY IRQs are connected to IRQ_IN[16] to IRQ_IN[30] in I/O cluster.
+// - The BDEV IRQ is connected to IRQ_IN[31] in I/O cluster.
+// 
+// Some hardware parameters are used when compiling the OS, and are used 
+// by this top.cpp file. They must be defined in the hard_config.h file :
+// - CLUSTER_X        : number of clusters in a row (power of 2)
+// - CLUSTER_Y        : number of clusters in a column (power of 2)
+// - CLUSTER_SIZE     : size of the segment allocated to a cluster
+// - NB_PROCS_MAX     : number of processors per cluster (power of 2)
+// - NB_DMA_CHANNELS  : number of DMA channels per cluster (< 9)
+// - NB_TTY_CHANNELS  : number of TTY channels in I/O cluster (< 16)
+// - NB_NIC_CHANNELS  : number of NIC channels in I/O cluster (< 9)
+// 
+// Some other hardware parameters are not used when compiling the OS,
+// and can be directly defined in this top.cpp file:
+// - XRAM_LATENCY     : external ram latency 
+// - MEMC_WAYS        : L2 cache number of ways
+// - MEMC_SETS        : L2 cache number of sets
+// - L1_IWAYS     
+// - L1_ISETS    
+// - L1_DWAYS   
+// - L1_DSETS  
+// - FBUF_X_SIZE      : width of frame buffer (pixels)
+// - FBUF_Y_SIZE      : heigth of frame buffer (lines)
+// - BDEV_SECTOR_SIZE : block size for block drvice
+// - BDEV_IMAGE_NAME  : file pathname for block device 
+// - NIC_RX_NAME      : file pathname for NIC received packets
+// - NIC_TX_NAME      : file pathname for NIC transmited packets
+// - NIC_TIMEOUT      : max number of cycles before closing a container
+/////////////////////////////////////////////////////////////////////////
+// General policy for 40 bits physical address decoding:
+// All physical segments base addresses are multiple of 1 Mbytes
+// (=> the 24 LSB bits = 0, and the 16 MSB bits define the target) 
+// The (x_width + y_width) MSB bits (left aligned) define
+// the cluster index, and the LADR bits define the local index:
+//      | X_ID  | Y_ID  |---| LADR |     OFFSET          |
+//      |x_width|y_width|---|  8   |       24            |
+/////////////////////////////////////////////////////////////////////////
+// General policy for 14 bits SRCID decoding:
+// Each component is identified by (x_id, y_id, l_id) tuple.
+//      | X_ID  | Y_ID  |---| L_ID |
+//      |x_width|y_width|---|  6   |
+/////////////////////////////////////////////////////////////////////////
+
+#include <systemc>
+#include <sys/time.h>
+#include <iostream>
+#include <sstream>
+#include <cstdlib>
+#include <cstdarg>
+#include <stdint.h>
+
+#include "gdbserver.h"
+#include "mapping_table.h"
+#include "tsar_xbar_cluster.h"
+#include "alloc_elems.h"
+
+///////////////////////////////////////////////////
+//      OS
+///////////////////////////////////////////////////
+
+//#define USE_ALMOS
+#define USE_GIET 
+
+#ifdef USE_ALMOS
+#ifdef USE_GIET
+#error "Can't use Two different OS"
+#endif
+#endif
+
+#ifndef USE_ALMOS
+#ifndef USE_GIET
+#error "You need to specify one OS"
+#endif
+#endif
+
+///////////////////////////////////////////////////
+//               Parallelisation
+///////////////////////////////////////////////////
+#define USE_OPENMP 0
+
+#if USE_OPENMP
+#include <omp.h>
+#endif
+
+//  cluster index (computed from x,y coordinates)
+#define cluster(x,y)   (y + YMAX * x)
+
+#define min(x, y) (x < y ? x : y)
+
+///////////////////////////////////////////////////////////
+//          DSPIN parameters           
+///////////////////////////////////////////////////////////
+
+#define dspin_cmd_width      39
+#define dspin_rsp_width      32
+
+///////////////////////////////////////////////////////////
+//          VCI parameters           
+///////////////////////////////////////////////////////////
+
+#define vci_cell_width_int    4
+#define vci_cell_width_ext    8
+
+#ifdef USE_ALMOS
+#define vci_address_width     32
+#endif
+#ifdef USE_GIET
+#define vci_address_width     40
+#endif
+#define vci_plen_width        8
+#define vci_rerror_width      1
+#define vci_clen_width        1
+#define vci_rflag_width       1
+#define vci_srcid_width       14
+#define vci_pktid_width       4
+#define vci_trdid_width       4
+#define vci_wrplen_width      1
+
+////////////////////////////////////////////////////////////
+//    Main Hardware Parameters values         
+//////////////////////i/////////////////////////////////////
+
+#ifdef USE_ALMOS
+#include "almos/hard_config.h"
+#define PREFIX_OS "almos/"
+#endif
+#ifdef USE_GIET
+#include "scripts/soft/hard_config.h"
+#define PREFIX_OS "/users/cao/meunier/src/giet_vm/"
+#endif
+
+////////////////////////////////////////////////////////////
+//    Secondary Hardware Parameters         
+//////////////////////i/////////////////////////////////////
+
+#define XMAX                  CLUSTER_X
+#define YMAX                  CLUSTER_Y
+
+#define XRAM_LATENCY          0
+
+#define MEMC_WAYS             16
+#define MEMC_SETS             256
+
+#define L1_IWAYS              4
+#define L1_ISETS              64
+
+#define L1_DWAYS              4
+#define L1_DSETS              64
+
+#ifdef USE_ALMOS
+#define FBUF_X_SIZE           512
+#define FBUF_Y_SIZE           512
+#endif
+#ifdef USE_GIET
+#define FBUF_X_SIZE           128
+#define FBUF_Y_SIZE           128
+#endif
+
+#ifdef USE_GIET
+#define BDEV_SECTOR_SIZE      512
+#define BDEV_IMAGE_NAME       PREFIX_OS"display/images.raw"
+#endif
+#ifdef USE_ALMOS
+#define BDEV_SECTOR_SIZE      4096
+#define BDEV_IMAGE_NAME       PREFIX_OS"hdd-img.bin"
+#endif
+
+#define NIC_RX_NAME           PREFIX_OS"nic/rx_packets.txt"
+#define NIC_TX_NAME           PREFIX_OS"nic/tx_packets.txt"
+#define NIC_TIMEOUT           10000
+
+#define NORTH                 0
+#define SOUTH                 1
+#define EAST                  2
+#define WEST                  3
+
+////////////////////////////////////////////////////////////
+//    Software to be loaded in ROM & RAM         
+//////////////////////i/////////////////////////////////////
+
+#ifdef USE_ALMOS
+#define soft_name       PREFIX_OS"bootloader.bin",\
+                        PREFIX_OS"kernel-soclib.bin@0xbfc10000:D",\
+                        PREFIX_OS"arch-info.bib@0xBFC08000:D"
+#endif
+#ifdef USE_GIET
+#define soft_pathname   "scripts/soft/soft.elf"
+#endif
+
+////////////////////////////////////////////////////////////
+//     DEBUG Parameters default values         
+//////////////////////i/////////////////////////////////////
+
+#define MAX_FROZEN_CYCLES     1000000
+
+/////////////////////////////////////////////////////////
+//    Physical segments definition
+/////////////////////////////////////////////////////////
+// There is 3 segments replicated in all clusters
+// and 5 specific segments in the "IO" cluster 
+// (containing address 0xBF000000)
+/////////////////////////////////////////////////////////
+
+#ifdef USE_GIET
+   // specific segments in "IO" cluster : absolute physical address
+   #define BROM_BASE    0x00BFC00000
+   #define BROM_SIZE    0x0000100000   // 1 Mbytes
+
+   #define FBUF_BASE    0x00B2000000
+   #define FBUF_SIZE    (FBUF_X_SIZE * FBUF_Y_SIZE * 2)
+
+   #define BDEV_BASE    0x00B3000000
+   #define BDEV_SIZE    0x0000001000   // 4 Kbytes
+
+   #define MTTY_BASE    0x00B4000000
+   #define MTTY_SIZE    0x0000001000   // 4 Kbytes
+
+   #define MNIC_BASE    0x00B5000000
+   #define MNIC_SIZE    0x0000080000   // 512 Kbytes (for 8 channels)
+
+   #define CDMA_BASE    0x00B6000000
+   #define CDMA_SIZE    0x0000004000 * NB_CMA_CHANNELS
+
+   // replicated segments : address is incremented by a cluster offset
+   //     offset  = cluster(x,y) << (address_width-x_width-y_width);
+
+   #define MEMC_BASE    0x0000000000
+   #define MEMC_SIZE    0x0010000000   // 256 Mbytes per cluster
+
+   #define XICU_BASE    0x00B0000000
+   #define XICU_SIZE    0x0000001000   // 4 Kbytes
+
+   #define MDMA_BASE    0x00B1000000
+   #define MDMA_SIZE    0x0000001000 * NB_DMA_CHANNELS  // 4 Kbytes per channel
+#endif
+
+#ifdef USE_ALMOS
+   #define CLUSTER_INC  (0x80000000ULL / (XMAX * YMAX) * 2)
+
+   #define MEMC_BASE    0x0000000000
+   #define MEMC_SIZE    min(0x02000000, (0x80000000 / (XMAX * YMAX)))
+
+   #define BROM_BASE    0x00BFC00000
+   #define BROM_SIZE    0x0000100000   // 1 Mbytes
+
+   #define XICU_BASE    (MEMC_SIZE)
+   #define XICU_SIZE    0x0000001000   // 4 Kbytes
+
+   #define MDMA_BASE    (XICU_BASE + XICU_SIZE)
+   #define MDMA_SIZE    0x0000001000 * NB_DMA_CHANNELS  // 4 Kbytes per channel  
+
+   #define BDEV_BASE    ((cluster_io_id * (CLUSTER_INC)) + MDMA_BASE + MDMA_SIZE)
+   #define BDEV_SIZE    0x0000001000   // 4 Kbytes
+
+   #define MTTY_BASE    (BDEV_BASE + BDEV_SIZE)
+   #define MTTY_SIZE    0x0000001000   // 4 Kbytes
+
+   #define FBUF_BASE    (MTTY_BASE + MTTY_SIZE)
+   #define FBUF_SIZE    (FBUF_X_SIZE * FBUF_Y_SIZE * 2) // Should be 0x80000
+
+   // Unused in almos
+   #define MNIC_BASE    (FBUF_BASE + FBUF_SIZE)
+   #define MNIC_SIZE    0x0000001000
+
+   #define CDMA_BASE    (MNIC_BASE + MNIC_SIZE)
+   #define CDMA_SIZE    0x0000004000 * NB_CMA_CHANNELS
+
+#endif
+
+
+////////////////////////////////////////////////////////////////////
+//     TGTID definition in direct space
+// For all components:  global TGTID = global SRCID = cluster_index
+////////////////////////////////////////////////////////////////////
+
+#define MEMC_TGTID      0
+#define XICU_TGTID      1
+#define MDMA_TGTID      2
+#define MTTY_TGTID      3
+#define FBUF_TGTID      4
+#define BDEV_TGTID      5
+#define MNIC_TGTID      6
+#define BROM_TGTID      7
+#define CDMA_TGTID      8
+
+bool stop_called = false;
+
+/////////////////////////////////
+int _main(int argc, char *argv[])
+{
+   using namespace sc_core;
+   using namespace soclib::caba;
+   using namespace soclib::common;
+
+#ifdef USE_GIET
+   char     soft_name[256]   = soft_pathname;      // pathname to binary code
+#endif
+   uint64_t ncycles          = 0xFFFFFFFFFFFFFFFF; // simulated cycles
+   char     disk_name[256]   = BDEV_IMAGE_NAME;    // pathname to the disk image
+   char     nic_rx_name[256] = NIC_RX_NAME;        // pathname to the rx packets file
+   char     nic_tx_name[256] = NIC_TX_NAME;        // pathname to the tx packets file
+   ssize_t  threads_nr       = 1;                  // simulator's threads number
+   bool     debug_ok         = false;              // trace activated
+   size_t   debug_period     = 1;                  // trace period
+   size_t   debug_memc_id    = 0;                  // index of memc to be traced 
+   size_t   debug_proc_id    = 0;                  // index of proc to be traced
+   uint32_t debug_from       = 0;                  // trace start cycle
+   uint32_t frozen_cycles    = MAX_FROZEN_CYCLES;  // monitoring frozen processor
+   size_t   cluster_io_id;                         // index of cluster containing IOs
+   struct   timeval t1,t2;
+   uint64_t ms1,ms2;
+
+   ////////////// command line arguments //////////////////////
+   if (argc > 1)
+   {
+      for (int n = 1; n < argc; n = n + 2)
+      {
+         if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc))
+         {
+            ncycles = atoi(argv[n + 1]);
+         }
+         else if ((strcmp(argv[n], "-SOFT") == 0) && (n + 1 < argc))
+         {
+#ifdef USE_ALMOS
+            assert( 0 && "Can't define almos soft name" );
+#endif
+#ifdef USE_GIET
+            strcpy(soft_name, argv[n + 1]);
+#endif
+         }
+         else if ((strcmp(argv[n],"-DISK") == 0) && (n + 1 < argc))
+         {
+            strcpy(disk_name, argv[n + 1]);
+         }
+         else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc))
+         {
+            debug_ok = true;
+            debug_from = atoi(argv[n + 1]);
+         }
+         else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc))
+         {
+            debug_memc_id = atoi(argv[n + 1]);
+            assert((debug_memc_id < (XMAX * YMAX)) && 
+                   "debug_memc_id larger than XMAX * YMAX" );
+         }
+         else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc))
+         {
+            debug_proc_id = atoi(argv[n + 1]);
+            assert((debug_proc_id < (XMAX * YMAX * NB_PROCS_MAX)) && 
+                   "debug_proc_id larger than XMAX * YMAX * NB_PROCS");
+         }
+         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc))
+         {
+            threads_nr = atoi(argv[n + 1]);
+            threads_nr = (threads_nr < 1) ? 1 : threads_nr;
+         }
+         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc))
+         {
+            frozen_cycles = atoi(argv[n + 1]);
+         }
+         else if ((strcmp(argv[n], "-PERIOD") == 0) && (n + 1 < argc))
+         {
+            debug_period = atoi(argv[n + 1]);
+         }
+         else
+         {
+            std::cout << "   Arguments are (key,value) couples." << std::endl;
+            std::cout << "   The order is not important." << std::endl;
+            std::cout << "   Accepted arguments are :" << std::endl << std::endl;
+            std::cout << "     -SOFT pathname_for_embedded_soft" << std::endl;
+            std::cout << "     -DISK pathname_for_disk_image" << std::endl;
+            std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl;
+            std::cout << "     -DEBUG debug_start_cycle" << std::endl;
+            std::cout << "     -THREADS simulator's threads number" << std::endl;
+            std::cout << "     -FROZEN max_number_of_lines" << std::endl;
+            std::cout << "     -PERIOD number_of_cycles between trace" << std::endl;
+            std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl;
+            std::cout << "     -PROCID index_proc_to_be_traced" << std::endl;
+            exit(0);
+         }
+      }
+   }
+
+    // checking hardware parameters
+    assert( ( (XMAX == 1) or (XMAX == 2) or (XMAX == 4) or
+              (XMAX == 8) or (XMAX == 16) ) and
+              "The XMAX parameter must be 1, 2, 4, 8 or 16" );
+
+    assert( ( (YMAX == 1) or (YMAX == 2) or (YMAX == 4) or
+              (YMAX == 8) or (YMAX == 16) ) and
+              "The YMAX parameter must be 1, 2, 4, 8 or 16" );
+
+    assert( ( (NB_PROCS_MAX == 1) or (NB_PROCS_MAX == 2) or
+              (NB_PROCS_MAX == 4) or (NB_PROCS_MAX == 8) ) and
+             "The NB_PROCS_MAX parameter must be 1, 2, 4 or 8" );
+
+    assert( (NB_DMA_CHANNELS < 9) and
+            "The NB_DMA_CHANNELS parameter must be smaller than 9" );
+
+    assert( (NB_TTY_CHANNELS < 15) and
+            "The NB_TTY_CHANNELS parameter must be smaller than 15" );
+
+    assert( (NB_NIC_CHANNELS < 9) and
+            "The NB_NIC_CHANNELS parameter must be smaller than 9" );
+
+#ifdef USE_GIET
+    assert( (vci_address_width == 40) and
+            "VCI address width with the GIET must be 40 bits" );
+#endif
+
+#ifdef USE_ALMOS
+    assert( (vci_address_width == 32) and
+            "VCI address width with ALMOS must be 32 bits" );
+#endif
+
+
+    std::cout << std::endl;
+    std::cout << " - XMAX             = " << XMAX << std::endl;
+    std::cout << " - YMAX             = " << YMAX << std::endl;
+    std::cout << " - NB_PROCS_MAX     = " << NB_PROCS_MAX <<  std::endl;
+    std::cout << " - NB_DMA_CHANNELS  = " << NB_DMA_CHANNELS <<  std::endl;
+    std::cout << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl;
+    std::cout << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl;
+    std::cout << " - MEMC_WAYS        = " << MEMC_WAYS << std::endl;
+    std::cout << " - MEMC_SETS        = " << MEMC_SETS << std::endl;
+    std::cout << " - RAM_LATENCY      = " << XRAM_LATENCY << std::endl;
+    std::cout << " - MAX_FROZEN       = " << frozen_cycles << std::endl;
+    std::cout << "[PROCS] " << NB_PROCS_MAX * XMAX * YMAX << std::endl;
+
+    std::cout << std::endl;
+    // Internal and External VCI parameters definition
+    typedef soclib::caba::VciParams<vci_cell_width_int,
+                                    vci_plen_width,
+                                    vci_address_width,
+                                    vci_rerror_width,
+                                    vci_clen_width,
+                                    vci_rflag_width,
+                                    vci_srcid_width,
+                                    vci_pktid_width,
+                                    vci_trdid_width,
+                                    vci_wrplen_width> vci_param_int;
+
+    typedef soclib::caba::VciParams<vci_cell_width_ext,
+                                    vci_plen_width,
+                                    vci_address_width,
+                                    vci_rerror_width,
+                                    vci_clen_width,
+                                    vci_rflag_width,
+                                    vci_srcid_width,
+                                    vci_pktid_width,
+                                    vci_trdid_width,
+                                    vci_wrplen_width> vci_param_ext;
+
+#if USE_OPENMP
+   omp_set_dynamic(false);
+   omp_set_num_threads(threads_nr);
+   std::cerr << "Built with openmp version " << _OPENMP << std::endl;
+#endif
+
+   // Define parameters depending on mesh size
+   size_t   x_width;
+   size_t   y_width;
+
+   if      (XMAX == 1) x_width = 0;
+   else if (XMAX == 2) x_width = 1;
+   else if (XMAX <= 4) x_width = 2;
+   else if (XMAX <= 8) x_width = 3;
+   else                x_width = 4;
+
+   if      (YMAX == 1) y_width = 0;
+   else if (YMAX == 2) y_width = 1;
+   else if (YMAX <= 4) y_width = 2;
+   else if (YMAX <= 8) y_width = 3;
+   else                y_width = 4;
+
+
+#ifdef USE_ALMOS
+   cluster_io_id = 0xbfc00000 >> (vci_address_width - x_width - y_width); // index of cluster containing IOs
+#else
+   cluster_io_id = 0;
+#endif
+
+   /////////////////////
+   //  Mapping Tables
+   /////////////////////
+
+   // internal network
+   MappingTable maptabd(vci_address_width, 
+                        IntTab(x_width + y_width, 20 - x_width - y_width), 
+                        IntTab(x_width + y_width, vci_srcid_width - x_width - y_width), 
+                        0x00FF800000);
+
+   for (size_t x = 0; x < XMAX; x++)
+   {
+      for (size_t y = 0; y < YMAX; y++)
+      {
+         sc_uint<vci_address_width> offset;
+         offset = (sc_uint<vci_address_width>)cluster(x,y) 
+                   << (vci_address_width-x_width-y_width);
+
+         std::ostringstream    si;
+         si << "seg_xicu_" << x << "_" << y;
+         maptabd.add(Segment(si.str(), XICU_BASE + offset, XICU_SIZE, 
+                  IntTab(cluster(x,y),XICU_TGTID), false));
+
+         std::ostringstream    sd;
+         sd << "seg_mdma_" << x << "_" << y;
+         maptabd.add(Segment(sd.str(), MDMA_BASE + offset, MDMA_SIZE, 
+                  IntTab(cluster(x,y),MDMA_TGTID), false));
+
+         std::ostringstream    sh;
+         sh << "seg_memc_" << x << "_" << y;
+         maptabd.add(Segment(sh.str(), MEMC_BASE + offset, MEMC_SIZE, 
+                  IntTab(cluster(x,y),MEMC_TGTID), true));
+
+         if ( cluster(x,y) == cluster_io_id )
+         {
+            maptabd.add(Segment("seg_mtty", MTTY_BASE, MTTY_SIZE, 
+                        IntTab(cluster(x,y),MTTY_TGTID), false));
+            maptabd.add(Segment("seg_fbuf", FBUF_BASE, FBUF_SIZE, 
+                        IntTab(cluster(x,y),FBUF_TGTID), false));
+            maptabd.add(Segment("seg_bdev", BDEV_BASE, BDEV_SIZE, 
+                        IntTab(cluster(x,y),BDEV_TGTID), false));
+            maptabd.add(Segment("seg_brom", BROM_BASE, BROM_SIZE, 
+                        IntTab(cluster(x,y),BROM_TGTID), true));
+            maptabd.add(Segment("seg_mnic", MNIC_BASE, MNIC_SIZE, 
+                        IntTab(cluster(x,y),MNIC_TGTID), false));
+            maptabd.add(Segment("seg_cdma", CDMA_BASE, CDMA_SIZE, 
+                        IntTab(cluster(x,y),CDMA_TGTID), false));
+         }
+      }
+   }
+   std::cout << maptabd << std::endl;
+
+   // external network
+   MappingTable maptabx(vci_address_width, 
+                        IntTab(x_width+y_width), 
+                        IntTab(x_width+y_width), 
+                        0xFFFF000000ULL);
+
+   for (size_t x = 0; x < XMAX; x++)
+   {
+      for (size_t y = 0; y < YMAX ; y++)
+      { 
+
+         sc_uint<vci_address_width> offset;
+         offset = (sc_uint<vci_address_width>)cluster(x,y) 
+                   << (vci_address_width-x_width-y_width);
+
+         std::ostringstream sh;
+         sh << "x_seg_memc_" << x << "_" << y;
+
+         maptabx.add(Segment(sh.str(), MEMC_BASE + offset, 
+                     MEMC_SIZE, IntTab(cluster(x,y)), false));
+      }
+
+   }
+   std::cout << maptabx << std::endl;
+
+   ////////////////////
+   // Signals
+   ///////////////////
+
+   sc_clock           signal_clk("clk");
+   sc_signal<bool>    signal_resetn("resetn");
+
+   // Horizontal inter-clusters DSPIN signals
+   DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_inc =
+      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_inc", XMAX-1, YMAX, 3);
+   DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_dec =
+      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_dec", XMAX-1, YMAX, 3);
+   DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_inc =
+      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_inc", XMAX-1, YMAX, 2);
+   DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_dec =
+      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_dec", XMAX-1, YMAX, 2);
+
+   // Vertical inter-clusters DSPIN signals
+   DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_inc =
+      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_inc", XMAX, YMAX-1, 3);
+   DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_dec =
+      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_dec", XMAX, YMAX-1, 3);
+   DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_inc =
+      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_inc", XMAX, YMAX-1, 2);
+   DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_dec =
+      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_dec", XMAX, YMAX-1, 2);
+
+   // Mesh boundaries DSPIN signals
+   DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_in =
+      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_in" , XMAX, YMAX, 4, 3);
+   DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_out =
+      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_out", XMAX, YMAX, 4, 3);
+   DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_in =
+      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_in" , XMAX, YMAX, 4, 2);
+   DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_out =
+      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_out", XMAX, YMAX, 4, 2);
+
+
+   ////////////////////////////
+   //      Loader    
+   ////////////////////////////
+
+   soclib::common::Loader loader(soft_name);
+
+   typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
+   proc_iss::set_loader(loader);
+
+   ////////////////////////////
+   // Clusters construction
+   ////////////////////////////
+
+   TsarXbarCluster<dspin_cmd_width,
+                   dspin_rsp_width,
+                   vci_param_int,
+                   vci_param_ext>*          clusters[XMAX][YMAX];
+
+#if USE_OPENMP
+#pragma omp parallel
+    {
+#pragma omp for
+#endif
+        for (size_t i = 0; i  < (XMAX * YMAX); i++)
+        {
+            size_t x = i / YMAX;
+            size_t y = i % YMAX;
+
+#if USE_OPENMP
+#pragma omp critical
+            {
+#endif
+            std::cout << std::endl;
+            std::cout << "Cluster_" << x << "_" << y << std::endl;
+            std::cout << std::endl;
+
+            std::ostringstream sc;
+            sc << "cluster_" << x << "_" << y;
+            clusters[x][y] = new TsarXbarCluster<dspin_cmd_width,
+                                                 dspin_rsp_width,
+                                                 vci_param_int,
+                                                 vci_param_ext>
+            (
+                sc.str().c_str(),
+                NB_PROCS_MAX,
+                NB_TTY_CHANNELS,  
+                NB_DMA_CHANNELS, 
+                x,
+                y,
+                cluster(x,y),
+                maptabd,
+                maptabx,
+                x_width,
+                y_width,
+                vci_srcid_width - x_width - y_width,   // l_id width,
+                MEMC_TGTID,
+                XICU_TGTID,
+                MDMA_TGTID,
+                FBUF_TGTID,
+                MTTY_TGTID,
+                BROM_TGTID,
+                MNIC_TGTID,
+                CDMA_TGTID,
+                BDEV_TGTID,
+                MEMC_WAYS,
+                MEMC_SETS,
+                L1_IWAYS,
+                L1_ISETS,
+                L1_DWAYS,
+                L1_DSETS,
+                XRAM_LATENCY,
+                (cluster(x,y) == cluster_io_id),
+                FBUF_X_SIZE,
+                FBUF_Y_SIZE,
+                disk_name,
+                BDEV_SECTOR_SIZE,
+                NB_NIC_CHANNELS,
+                nic_rx_name,
+                nic_tx_name,
+                NIC_TIMEOUT,
+                NB_CMA_CHANNELS,
+                loader,
+                frozen_cycles,
+                debug_from   ,
+                debug_ok and (cluster(x,y) == debug_memc_id),
+                debug_ok and (cluster(x,y) == debug_proc_id) 
+            );
+
+#if USE_OPENMP
+            } // end critical
+#endif
+        } // end for
+#if USE_OPENMP
+    }
+#endif
+
+   ///////////////////////////////////////////////////////////////
+   //     Net-list 
+   ///////////////////////////////////////////////////////////////
+
+   // Clock & RESET
+   for (size_t x = 0; x < (XMAX); x++){
+      for (size_t y = 0; y < YMAX; y++){
+         clusters[x][y]->p_clk                         (signal_clk);
+         clusters[x][y]->p_resetn                      (signal_resetn);
+      }
+   }
+
+   // Inter Clusters horizontal connections
+   if (XMAX > 1){
+      for (size_t x = 0; x < (XMAX-1); x++){
+         for (size_t y = 0; y < YMAX; y++){
+            for (size_t k = 0; k < 3; k++){
+               clusters[x][y]->p_cmd_out[EAST][k]      (signal_dspin_h_cmd_inc[x][y][k]);
+               clusters[x+1][y]->p_cmd_in[WEST][k]     (signal_dspin_h_cmd_inc[x][y][k]);
+               clusters[x][y]->p_cmd_in[EAST][k]       (signal_dspin_h_cmd_dec[x][y][k]);
+               clusters[x+1][y]->p_cmd_out[WEST][k]    (signal_dspin_h_cmd_dec[x][y][k]);
+            }
+
+            for (size_t k = 0; k < 2; k++){
+               clusters[x][y]->p_rsp_out[EAST][k]      (signal_dspin_h_rsp_inc[x][y][k]);
+               clusters[x+1][y]->p_rsp_in[WEST][k]     (signal_dspin_h_rsp_inc[x][y][k]);
+               clusters[x][y]->p_rsp_in[EAST][k]       (signal_dspin_h_rsp_dec[x][y][k]);
+               clusters[x+1][y]->p_rsp_out[WEST][k]    (signal_dspin_h_rsp_dec[x][y][k]);
+            }
+         }
+      }
+   }
+   std::cout << std::endl << "Horizontal connections established" << std::endl;   
+
+   // Inter Clusters vertical connections
+   if (YMAX > 1) {
+      for (size_t y = 0; y < (YMAX-1); y++){
+         for (size_t x = 0; x < XMAX; x++){
+            for (size_t k = 0; k < 3; k++){
+               clusters[x][y]->p_cmd_out[NORTH][k]     (signal_dspin_v_cmd_inc[x][y][k]);
+               clusters[x][y+1]->p_cmd_in[SOUTH][k]    (signal_dspin_v_cmd_inc[x][y][k]);
+               clusters[x][y]->p_cmd_in[NORTH][k]      (signal_dspin_v_cmd_dec[x][y][k]);
+               clusters[x][y+1]->p_cmd_out[SOUTH][k]   (signal_dspin_v_cmd_dec[x][y][k]);
+            }
+
+            for (size_t k = 0; k < 2; k++){
+               clusters[x][y]->p_rsp_out[NORTH][k]     (signal_dspin_v_rsp_inc[x][y][k]);
+               clusters[x][y+1]->p_rsp_in[SOUTH][k]    (signal_dspin_v_rsp_inc[x][y][k]);
+               clusters[x][y]->p_rsp_in[NORTH][k]      (signal_dspin_v_rsp_dec[x][y][k]);
+               clusters[x][y+1]->p_rsp_out[SOUTH][k]   (signal_dspin_v_rsp_dec[x][y][k]);
+            }
+         }
+      }
+   }
+   std::cout << "Vertical connections established" << std::endl;
+
+   // East & West boundary cluster connections
+   for (size_t y = 0; y < YMAX; y++)
+   {
+      for (size_t k = 0; k < 3; k++)
+      {
+         clusters[0][y]->p_cmd_in[WEST][k]        (signal_dspin_false_cmd_in[0][y][WEST][k]);
+         clusters[0][y]->p_cmd_out[WEST][k]       (signal_dspin_false_cmd_out[0][y][WEST][k]);
+         clusters[XMAX-1][y]->p_cmd_in[EAST][k]   (signal_dspin_false_cmd_in[XMAX-1][y][EAST][k]);
+         clusters[XMAX-1][y]->p_cmd_out[EAST][k]  (signal_dspin_false_cmd_out[XMAX-1][y][EAST][k]);
+      }
+
+      for (size_t k = 0; k < 2; k++)
+      {
+         clusters[0][y]->p_rsp_in[WEST][k]        (signal_dspin_false_rsp_in[0][y][WEST][k]);
+         clusters[0][y]->p_rsp_out[WEST][k]       (signal_dspin_false_rsp_out[0][y][WEST][k]);
+         clusters[XMAX-1][y]->p_rsp_in[EAST][k]   (signal_dspin_false_rsp_in[XMAX-1][y][EAST][k]);
+         clusters[XMAX-1][y]->p_rsp_out[EAST][k]  (signal_dspin_false_rsp_out[XMAX-1][y][EAST][k]);
+      }
+   }
+
+   // North & South boundary clusters connections
+   for (size_t x = 0; x < XMAX; x++)
+   {
+      for (size_t k = 0; k < 3; k++)
+      {
+         clusters[x][0]->p_cmd_in[SOUTH][k]       (signal_dspin_false_cmd_in[x][0][SOUTH][k]);
+         clusters[x][0]->p_cmd_out[SOUTH][k]      (signal_dspin_false_cmd_out[x][0][SOUTH][k]);
+         clusters[x][YMAX-1]->p_cmd_in[NORTH][k]  (signal_dspin_false_cmd_in[x][YMAX-1][NORTH][k]);
+         clusters[x][YMAX-1]->p_cmd_out[NORTH][k] (signal_dspin_false_cmd_out[x][YMAX-1][NORTH][k]);
+      }
+
+      for (size_t k = 0; k < 2; k++)
+      {
+         clusters[x][0]->p_rsp_in[SOUTH][k]       (signal_dspin_false_rsp_in[x][0][SOUTH][k]);
+         clusters[x][0]->p_rsp_out[SOUTH][k]      (signal_dspin_false_rsp_out[x][0][SOUTH][k]);
+         clusters[x][YMAX-1]->p_rsp_in[NORTH][k]  (signal_dspin_false_rsp_in[x][YMAX-1][NORTH][k]);
+         clusters[x][YMAX-1]->p_rsp_out[NORTH][k] (signal_dspin_false_rsp_out[x][YMAX-1][NORTH][k]);
+      }
+   }
+   std::cout << "North, South, West, East connections established" << std::endl;
+   std::cout << std::endl;
+
+
+   ////////////////////////////////////////////////////////
+   //   Simulation
+   ///////////////////////////////////////////////////////
+
+   sc_start(sc_core::sc_time(0, SC_NS));
+   signal_resetn = false;
+
+   // network boundaries signals
+   for (size_t x = 0; x < XMAX ; x++){
+      for (size_t y = 0; y < YMAX ; y++){
+         for (size_t a = 0; a < 4; a++){
+            for (size_t k = 0; k < 3; k++){
+               signal_dspin_false_cmd_in [x][y][a][k].write = false;
+               signal_dspin_false_cmd_in [x][y][a][k].read  = true;
+               signal_dspin_false_cmd_out[x][y][a][k].write = false;
+               signal_dspin_false_cmd_out[x][y][a][k].read  = true;
+            }
+
+            for (size_t k = 0; k < 2; k++){
+               signal_dspin_false_rsp_in [x][y][a][k].write = false;
+               signal_dspin_false_rsp_in [x][y][a][k].read  = true;
+               signal_dspin_false_rsp_out[x][y][a][k].write = false;
+               signal_dspin_false_rsp_out[x][y][a][k].read  = true;
+            }
+         }
+      }
+   }
+
+   sc_start(sc_core::sc_time(1, SC_NS));
+   signal_resetn = true;
+
+   if (gettimeofday(&t1, NULL) != 0) 
+   {
+      perror("gettimeofday");
+      return EXIT_FAILURE;
+   }
+
+   for (uint64_t n = 1; n < ncycles && !stop_called; n++)
+   {
+      // Monitor a specific address for L1 & L2 caches
+      //clusters[0][0]->proc[0]->cache_monitor(0x800002c000ULL);
+      //clusters[1][0]->memc->copies_monitor(0x800002C000ULL);
+
+      if( (n % 5000000) == 0)
+      {
+
+         if (gettimeofday(&t2, NULL) != 0) 
+         {
+            perror("gettimeofday");
+            return EXIT_FAILURE;
+         }
+
+         ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000;
+         ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000;
+         std::cerr << "platform clock frequency " << (double) 5000000 / (double) (ms2 - ms1) << "Khz" << std::endl;
+
+         if (gettimeofday(&t1, NULL) != 0) 
+         {
+            perror("gettimeofday");
+            return EXIT_FAILURE;
+         }
+      }
+
+      if (debug_ok and (n > debug_from) and (n % debug_period == 0))
+      {
+         std::cout << "****************** cycle " << std::dec << n ;
+         std::cout << " ************************************************" << std::endl;
+
+        // trace proc[debug_proc_id] 
+        size_t l = debug_proc_id % NB_PROCS_MAX ;
+        size_t y = (debug_proc_id / NB_PROCS_MAX) % YMAX ;
+        size_t x = debug_proc_id / (YMAX * NB_PROCS_MAX) ;
+
+        std::ostringstream proc_signame;
+        proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ;
+        std::ostringstream p2m_signame;
+        p2m_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " P2M" ;
+        std::ostringstream m2p_signame;
+        m2p_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " M2P" ;
+        std::ostringstream p_cmd_signame;
+        p_cmd_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " CMD" ;
+        std::ostringstream p_rsp_signame;
+        p_rsp_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " RSP" ;
+
+        clusters[x][y]->proc[l]->print_trace();
+        clusters[x][y]->wi_proc[l]->print_trace();
+        clusters[x][y]->signal_vci_ini_proc[l].print_trace(proc_signame.str());
+        clusters[x][y]->signal_dspin_p2m_proc[l].print_trace(p2m_signame.str());
+        clusters[x][y]->signal_dspin_m2p_proc[l].print_trace(m2p_signame.str());
+        clusters[x][y]->signal_dspin_cmd_proc_i[l].print_trace(p_cmd_signame.str());
+        clusters[x][y]->signal_dspin_rsp_proc_i[l].print_trace(p_rsp_signame.str());
+
+        clusters[x][y]->xbar_rsp_d->print_trace();
+        clusters[x][y]->xbar_cmd_d->print_trace();
+        clusters[x][y]->signal_dspin_cmd_l2g_d.print_trace("[SIG]L2G CMD");
+        clusters[x][y]->signal_dspin_cmd_g2l_d.print_trace("[SIG]G2L CMD");
+        clusters[x][y]->signal_dspin_rsp_l2g_d.print_trace("[SIG]L2G RSP");
+        clusters[x][y]->signal_dspin_rsp_g2l_d.print_trace("[SIG]G2L RSP");
+
+        // trace memc[debug_memc_id] 
+        x = debug_memc_id / YMAX;
+        y = debug_memc_id % YMAX;
+
+        std::ostringstream smemc;
+        smemc << "[SIG]MEMC_" << x << "_" << y;
+        std::ostringstream sxram;
+        sxram << "[SIG]XRAM_" << x << "_" << y;
+        std::ostringstream sm2p;
+        sm2p << "[SIG]MEMC_" << x << "_" << y << " M2P" ;
+        std::ostringstream sp2m;
+        sp2m << "[SIG]MEMC_" << x << "_" << y << " P2M" ;
+        std::ostringstream m_cmd_signame;
+        m_cmd_signame << "[SIG]MEMC_" << x << "_" << y <<  " CMD" ;
+        std::ostringstream m_rsp_signame;
+        m_rsp_signame << "[SIG]MEMC_" << x << "_" << y <<  " RSP" ;
+
+        clusters[x][y]->memc->print_trace();
+        clusters[x][y]->wt_memc->print_trace();
+        clusters[x][y]->signal_vci_tgt_memc.print_trace(smemc.str());
+        clusters[x][y]->signal_vci_xram.print_trace(sxram.str());
+        clusters[x][y]->signal_dspin_p2m_memc.print_trace(sp2m.str());
+        clusters[x][y]->signal_dspin_m2p_memc.print_trace(sm2p.str());
+        clusters[x][y]->signal_dspin_cmd_memc_t.print_trace(m_cmd_signame.str());
+        clusters[x][y]->signal_dspin_rsp_memc_t.print_trace(m_rsp_signame.str());
+        
+        // trace replicated peripherals
+//        clusters[1][1]->mdma->print_trace();
+//        clusters[1][1]->signal_vci_tgt_mdma.print_trace("[SIG]MDMA_TGT_1_1");
+//        clusters[1][1]->signal_vci_ini_mdma.print_trace("[SIG]MDMA_INI_1_1");
+        
+
+        // trace external peripherals
+        size_t io_x   = cluster_io_id / YMAX;
+        size_t io_y   = cluster_io_id % YMAX;
+        
+        clusters[io_x][io_y]->brom->print_trace();
+        clusters[io_x][io_y]->wt_brom->print_trace();
+        clusters[io_x][io_y]->signal_vci_tgt_brom.print_trace("[SIG]BROM");
+        clusters[io_x][io_y]->signal_dspin_cmd_brom_t.print_trace("[SIG]BROM CMD");
+        clusters[io_x][io_y]->signal_dspin_rsp_brom_t.print_trace("[SIG]BROM RSP");
+
+//        clusters[io_x][io_y]->bdev->print_trace();
+//        clusters[io_x][io_y]->signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT");
+//        clusters[io_x][io_y]->signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI");
+      }
+
+      sc_start(sc_core::sc_time(1, SC_NS));
+   }
+
+   
+   // Free memory
+   for (size_t i = 0; i  < (XMAX * YMAX); i++)
+   {
+      size_t x = i / YMAX;
+      size_t y = i % YMAX;
+      delete clusters[x][y];
+   }
+
+   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_inc, XMAX - 1, YMAX, 3);
+   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_dec, XMAX - 1, YMAX, 3);
+   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_inc, XMAX - 1, YMAX, 2);
+   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_dec, XMAX - 1, YMAX, 2);
+   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_inc, XMAX, YMAX - 1, 3);
+   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_dec, XMAX, YMAX - 1, 3);
+   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_inc, XMAX, YMAX - 1, 2);
+   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_dec, XMAX, YMAX - 1, 2);
+   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_in, XMAX, YMAX, 4, 3);
+   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_out, XMAX, YMAX, 4, 3);
+   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_in, XMAX, YMAX, 4, 2);
+   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_out, XMAX, YMAX, 4, 2);
+
+   return EXIT_SUCCESS;
+}
+
+
+void handler(int dummy = 0) {
+   stop_called = true;
+   sc_stop();
+}
+
+void voidhandler(int dummy = 0) {}
+
+int sc_main (int argc, char *argv[])
+{
+   signal(SIGINT, handler);
+   signal(SIGPIPE, voidhandler);
+
+   try {
+      return _main(argc, argv);
+   } catch (std::exception &e) {
+      std::cout << e.what() << std::endl;
+   } catch (...) {
+      std::cout << "Unknown exception occured" << std::endl;
+      throw;
+   }
+   return 1;
+}
+
+
+// Local Variables:
+// tab-width: 3
+// c-basic-offset: 3
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
Index: /trunk/softs/test_llsc/top.desc
===================================================================
--- /trunk/softs/test_llsc/top.desc	(revision 536)
+++ /trunk/softs/test_llsc/top.desc	(revision 536)
@@ -0,0 +1,46 @@
+
+# -*- python -*-
+
+# internal VCI parameters values
+vci_cell_size_int   = 4
+vci_cell_size_ext   = 8
+
+vci_plen_size       = 8
+vci_addr_size       = 40
+vci_rerror_size     = 1
+vci_clen_size       = 1
+vci_rflag_size      = 1
+vci_srcid_size      = 14
+vci_pktid_size      = 4
+vci_trdid_size      = 4
+vci_wrplen_size     = 1
+
+# DSPIN network parameters values
+dspin_cmd_flit_size     = 39
+dspin_rsp_flit_size     = 32
+
+todo = Platform('caba', 'top.cpp',
+
+   uses = [
+            Uses('caba:tsar_xbar_cluster', 
+                  vci_data_width_int = vci_cell_size_int,
+                  vci_data_width_ext = vci_cell_size_ext,
+                  dspin_cmd_width    = dspin_cmd_flit_size,
+                  dspin_rsp_width    = dspin_rsp_flit_size),
+
+            Uses('common:elf_file_loader'),
+            Uses('common:plain_file_loader'),
+           ],
+
+   # default VCI parameters (global variables)
+   cell_size   = vci_cell_size_int,  
+	plen_size   = vci_plen_size,
+	addr_size   = vci_addr_size,
+	rerror_size = vci_rerror_size,
+	clen_size   = vci_clen_size,
+	rflag_size  = vci_rflag_size,
+	srcid_size  = vci_srcid_size,
+	pktid_size  = vci_pktid_size,
+	trdid_size  = vci_trdid_size,
+	wrplen_size = vci_wrplen_size,
+)
