Index: trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info.py	(revision 1012)
+++ trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info.py	(revision 1023)
@@ -1,4 +1,4 @@
 #--------------------------------------------------------------------
-# File      : gen_arch_info_large.sh
+# File      : gen_arch_info.py
 #--------------------------------------------------------------------
 
@@ -8,185 +8,135 @@
 import sys
 
-X_MAX = 0
-Y_MAX = 0
-CPU_PER_CLUSTER = 0
-BSCPU = 0
-BSTTY = 0
-BSDMA = 0
-MEMC_SIZE = 0
-P_WDITH = 4
-NB_TTY = 4
-TTY_CHANNEL_SIZE = 0X00000010
-TTY_SIZE = 0X00001000
-OUTPUT_IRQ_PER_PROC = 4
-DMA_SIZE = 0X00001000
-XCU_SIZE = 0X00001000
-BDV_SIZE = 0X00001000
-FBF_SIZE = 0X00200000
 
-MEMC_TGTID = 0
-XICU_TGTID = 1
-MDMA_TGTID = 2
-MTTY_TGTID = 3
-BDEV_TGTID = 4
-MNIC_TGTID = 5
-BROM_TGTID = 6
-CDMA_TGTID = 7
-SIMH_TGTID = 8
-FBUF_TGTID = 9
+exec(file("hard_params.py"))
+
+def print_comments(cmd, x, y, cpu_per_cluster, bscpu):
+    print "# TSAR hardware description in BIB (Boot Information Block) format"
+    print "# This file is autogenerated by the command: " + cmd +  " %d %d %d %d" % (x, y, cpu_per_cluster, bscpu)
+    print "# It is ready to be passed to info2bib utility so the binary format can be generated"
+    print " "
+    print "# " + getpass.getuser() + " on " + socket.gethostname() + " " + time.strftime("%H:%M:%S")
+    print " "
+    print " "
+        
+def print_header(x, y, bscpu, bstty, bsdma):
+    print "[HEADER]"
+    print "        REVISION=1"
+    print "        ARCH=SOCLIB-TSAR"
+    print "        XMAX=%d" % x
+    print "        YMAX=%d" % y
+    print "        BSCPU=%d" % bscpu
+    print "        BSTTY=0x%x" % bstty
+    print "        BSDMA=0x%x" % bsdma
+    print " "
+    print " "
 
 
-# PHYSICAL ADDRESS WIDTH
-ADDR_WIDTH = 32
+def print_cluster(x, y, x_width, y_width, cpu_per_cluster):
+    mem_addr = ram_addr(x, y, x_width, y_width)
+    mem_size = ram_size(x_width, y_width)
+    xcu_base = replicated_periph_base_addr(x_width, y_width, XCU_TGTID)
+    dma_base = replicated_periph_base_addr(x_width, y_width, DMA_TGTID)
+    xcu_addr = replicated_periph_addr(x, y, x_width, y_width, xcu_base)
+    dma_addr = replicated_periph_addr(x, y, x_width, y_width, dma_base)
+    print "[CLUSTER]"
 
-# DEFAULT VALUES
-DEFAULT_X_MAX = 8
-DEFAULT_Y_MAX = 8
-DEFAULT_CPU_PER_CLUSTER = 4
-CLUSTER_INC = 0
+    cid = x * (1 << y_width) + y
+    cpu_num = 0;
+    while (cpu_num != cpu_per_cluster):
+        gid = (cid << P_WIDTH) + cpu_num
+        print "        [CPU]    ID=%d    OUTIRQ=%d" % (gid, (cpu_num * OUTPUT_IRQ_PER_PROC)) 
+        cpu_num += 1
+    
+    print "        [DEV]    ID=RAM       BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (mem_addr, mem_size)
+    print "        [DEV]    ID=XICU      BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (xcu_addr, DMA_SIZE)
+    print "        [DEV]    ID=DMA       BASE=%#.8x    SIZE=%#.8x    IRQ=8     IRQTYPE=HWI"  % (dma_addr, XCU_SIZE)
+    print " "
+    print " "
 
-def print_comments(cmd):
-        print "# TSAR hardware description in BIB (Boot Information Block) format"
-        print "# This file is autogenerated by the command: " + cmd +  " %d %d %d %d" % (X_MAX, Y_MAX, CPU_PER_CLUSTER, BSCPU)
-        print "# It is ready to be passed to info2bib utility so the binary format can be generated"
-        print " "
-        print "# " + getpass.getuser() + " on " + socket.gethostname() + " " + time.strftime("%H:%M:%S")
-        print " "
-        print " "
-        
-def print_header():
-        print "[HEADER]"
-        print "        REVISION=1"
-        print "        ARCH=SOCLIB-TSAR"
-        print "        XMAX=%d" % X_MAX 
-        print "        YMAX=%d" % Y_MAX
-        print "        BSCPU=%d" % BSCPU
-        print "        BSTTY=0x%x" % BSTTY
-        print "        BSDMA=0x%x" % BSDMA
-        print " "
-        print " "
 
-def print_cluster(offset, cid):
-        mem_base = offset
-        mem_size = MEMC_SIZE
-        xcu_base = (offset + (CLUSTER_INC / 2) + (XICU_TGTID << 19))
-        dma_base = (offset + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))
-        print "[CLUSTER]"
-        cpu_num=0;
-        while (cpu_num != CPU_PER_CLUSTER):
-                gid = (cid << CPU_PER_CLUSTER) + cpu_num
-                print "        [CPU]    ID=%d OUTIRQ=%d" % (gid, (cpu_num * OUTPUT_IRQ_PER_PROC)) 
-                cpu_num = cpu_num + 1
-        
-        print "        [DEV]    ID=RAM       BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (mem_base, mem_size)
-        print "        [DEV]    ID=XICU      BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (xcu_base, DMA_SIZE)
-        print "        [DEV]    ID=DMA       BASE=%#.8x    SIZE=%#.8x    IRQ=8     IRQTYPE=HWI"  % (dma_base, XCU_SIZE)
-        print " "
-        print " "
+def print_io_cluster(x, y, x_width, y_width, cpu_per_cluster):
+    mem_addr = ram_addr(x, y, x_width, y_width)
+    mem_size = ram_size(x_width, y_width)
 
-def print_io_cluster(offset, cid):
-        mem_base = offset
-        mem_size = MEMC_SIZE
-        xcu_base = (offset + (CLUSTER_INC / 2) + (XICU_TGTID << 19))
-        dma_base = (offset + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))
-        bdv_base = (offset + (CLUSTER_INC / 2) + (BDEV_TGTID << 19))
-        tty_base = (offset + (CLUSTER_INC / 2) + (MTTY_TGTID << 19))
-        fbf_base = (offset + (CLUSTER_INC / 2) + (FBUF_TGTID << 19))
-        
-        print "[CLUSTER]"
-        cpu_num = 0
-        while (cpu_num != CPU_PER_CLUSTER):
-                gid = (cid << CPU_PER_CLUSTER) + cpu_num
-                print "        [CPU]    ID=%d OUTIRQ=%d" % (gid, (cpu_num * OUTPUT_IRQ_PER_PROC)) 
-                cpu_num = cpu_num + 1
-        
-        print "        [DEV]    ID=RAM       BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (mem_base, mem_size)
-        print "        [DEV]    ID=XICU      BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (xcu_base, XCU_SIZE)
-        print "        [DEV]    ID=DMA       BASE=%#.8x    SIZE=%#.8x    IRQ=8     IRQTYPE=HWI"  % (dma_base, DMA_SIZE)
-        print "        [DEV]    ID=BLKDEV    BASE=%#.8x    SIZE=%#.8x    IRQ=31    IRQTYPE=HWI"  % (bdv_base, BDV_SIZE)
-        ntty = 0
-        irq = 16
-        while (ntty < NB_TTY):
-                tty_base_i = tty_base + ntty * TTY_CHANNEL_SIZE
-                print "        [DEV]    ID=TTY       BASE=%#.8x    SIZE=%#.8x    IRQ=%d    IRQTYPE=HWI" % (tty_base_i, TTY_CHANNEL_SIZE, irq)
-                irq = irq + 1
-                ntty = ntty + 1
-        print "        [DEV]    ID=FB        BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (fbf_base, FBF_SIZE)
-        print " "
-        print " "
+    xcu_addr = periph_addr(x_width, y_width, XCU_TGTID)
+    dma_addr = periph_addr(x_width, y_width, DMA_TGTID)
+    ioc_addr = periph_addr(x_width, y_width, IOC_TGTID)
+    tty_base = periph_addr(x_width, y_width, TTY_TGTID)
+    fbf_addr = periph_addr(x_width, y_width, FBF_TGTID)
+    
+    print "[CLUSTER]"
+    cpu_num = 0
+    cid = x * (1 << y_width) + y
+    while (cpu_num != cpu_per_cluster):
+        gid = (cid << P_WIDTH) + cpu_num
+        print "        [CPU]    ID=%d    OUTIRQ=%d" % (gid, (cpu_num * OUTPUT_IRQ_PER_PROC)) 
+        cpu_num = cpu_num + 1
+    
+    print "        [DEV]    ID=RAM       BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (mem_addr, mem_size)
+    print "        [DEV]    ID=XICU      BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (xcu_addr, XCU_SIZE)
+    print "        [DEV]    ID=DMA       BASE=%#.8x    SIZE=%#.8x    IRQ=8     IRQTYPE=HWI"  % (dma_addr, DMA_SIZE)
+    print "        [DEV]    ID=BLKDEV    BASE=%#.8x    SIZE=%#.8x    IRQ=31    IRQTYPE=HWI"  % (ioc_addr, IOC_SIZE)
+    ntty = 0
+    irq = 16
+    while (ntty < NB_TTY_CHANNELS):
+        tty_base_i = tty_base + ntty * TTY_CHANNEL_SIZE
+        print "        [DEV]    ID=TTY       BASE=%#.8x    SIZE=%#.8x    IRQ=%d    IRQTYPE=HWI" % (tty_base_i, TTY_CHANNEL_SIZE, irq)
+        irq += 1
+        ntty += 1
+    print "        [DEV]    ID=FB        BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (fbf_addr, FBF_SIZE)
+    print " "
+    print " "
 
-def gen_arch_info(x, y, x_width, y_width, bscpu, arch_info_name):
-        fp = open(arch_info_name, 'w')
-        stdout = sys.stdout
-        sys.stdout = fp
-        global X_MAX
-        global Y_MAX
-        global CPU_PER_CLUSTER
-        global CLUSTER_INC
-        global MEMC_SIZE
-        global BSCPU
-        global BSDMA
-        global BSTTY
-        
-        #------------------------
-        
-        X_MAX = x
-        Y_MAX = y
-        cpu_per_cluster = DEFAULT_CPU_PER_CLUSTER
-        CPU_PER_CLUSTER = cpu_per_cluster
-        
-        #------------------------
-        CLUSTER_INC = (0x80000000 >> (x_width + y_width)) * 2
-        max_memc_size = 0x40000000 / (X_MAX * Y_MAX)
-        size = min(max_memc_size, 0x10000000)
-        MEMC_SIZE = size
+def gen_arch_info(x, y, x_width, y_width, cpu_per_cluster, bscpu, arch_info_name):
+    fp = open(arch_info_name, 'w')
+    stdout = sys.stdout
+    sys.stdout = fp
 
-        ##########################################################################################
-        #we force io_cid to 0 because this is the only cluster we know which will be present 
-        #in all platform where the number of clusters is independant of x_width and y_width values
-        io_cid = 0 
-        ##########################################################################################
+    x_io = get_x_io(x_width, y_width)
+    y_io = get_y_io(x_width, y_width)
 
-        BSCPU = bscpu
-        
-        break_loop = 0
-        xi = 0
+    ###########################################################################################
+    # we force io_cid to 0 because this is the only cluster we know which will be present 
+    # in all platform where the number of clusters is independant of x_width and y_width values
+    # io_cid = 0 
+    # @QM No.
+    ###########################################################################################
+
+    break_loop = 0
+    xi = 0
+    yi = 0
+    while (xi < x):
+        while (yi < y):
+            if xi == x_io and yi == y_io:
+                bsdma = periph_addr(x_width, y_width, DMA_TGTID)
+                bstty = periph_addr(x_width, y_width, TTY_TGTID)
+                break_loop = 1
+                break
+            else:
+                bsdma = "error"
+            yi = yi + 1
+
+        if break_loop == 1:
+            break
         yi = 0
-        while (xi < X_MAX):
-                while (yi < Y_MAX):
-                        cid = xi * (1 << y_width) + yi
-                        offset = cid << (ADDR_WIDTH - x_width - y_width)
-                        if cid == io_cid:
-                                BSDMA = offset + (CLUSTER_INC / 2) + (MDMA_TGTID << 19)
-                                BSTTY = offset + (CLUSTER_INC / 2) + (MTTY_TGTID << 19)
-                                break_loop = 1
-                                break
-                        else:
-                                bsdma="error"
-                        yi = yi + 1
+        xi = xi + 1
+    
+    # Generate the description
+    print_comments(sys.argv[0], x, y, cpu_per_cluster, bscpu)
+    print_header(x, y, bscpu, bstty, bsdma)
+    
+    xi = 0
+    yi = 0
+    while (xi < x):
+        while (yi < y):
+            if xi == x_io and yi == y_io:
+                print_io_cluster(xi, yi, x_width, y_width, cpu_per_cluster)
+            else:
+                print_cluster(xi, yi, x_width, y_width, cpu_per_cluster)
+            yi = yi + 1
+        yi = 0
+        xi = xi + 1
+    sys.stdout = stdout
+    fp.close()
 
-                if break_loop == 1:
-                        break
-                yi = 0
-                xi = xi + 1
-        
-        # Generate the description
-        print_comments(sys.argv[0])
-        print_header()
-        
-        xi = 0
-        yi = 0
-        while (xi < X_MAX):
-                while (yi < Y_MAX):
-                        cid = xi * (1 << y_width) + yi
-                        offset = cid  << (ADDR_WIDTH - (x_width + y_width))
-                        if cid == io_cid:
-                                print_io_cluster(offset, cid)
-                        else:
-                                print_cluster(offset, cid)
-                        yi = yi + 1
-                yi = 0
-                xi = xi + 1
-        sys.stdout = stdout
-        fp.close()
-
