Index: trunk/tools/bootloader_tsar/boot.c
===================================================================
--- trunk/tools/bootloader_tsar/boot.c	(revision 6)
+++ trunk/tools/bootloader_tsar/boot.c	(revision 13)
@@ -72,5 +72,5 @@
 #include <hal_types.h>
 
-#include <almos_config.h>
+#include <kernel_config.h>
 #include <boot_config.h>
 
@@ -349,9 +349,4 @@
     boot_device_t      * boot_dev; 
 
-#if DEBUG_BOOT_INFO
-boot_printf("\n[BOOT INFO] %s : enter for cluster %x at cycle %d\n",
-            __FUNCTION__ , cxy , boot_get_proctime() );
-#endif
-
     // get pointer on ARCHINFO header  and on the four arch_info arrays
     header       = (archinfo_header_t*)ARCHINFO_BASE;
@@ -398,9 +393,10 @@
     }
 
-    // loop on all arch-info peripherals in IO_cluster, 
+    // loop on arch-info peripherals in io_cluster, 
     // to initialize the boot_info array of external peripherals
 
 #if DEBUG_BOOT_INFO
-boot_printf("\n[BOOT INFO] %s : External peripherals\n", __FUNCTION__ );
+boot_printf("\n[BOOT INFO] %s : external peripherals at cycle %d\n",
+            __FUNCTION__ , cxy , boot_get_proctime() );
 #endif
 
@@ -420,5 +416,4 @@
             boot_dev->type     = device->type;
             boot_dev->base     = device->base;
-            boot_dev->size     = device->size;
             boot_dev->channels = device->channels;
             boot_dev->param0   = device->arg0;    
@@ -429,5 +424,4 @@
 
             device_id++;
-        }
 
 #if DEBUG_BOOT_INFO
@@ -436,4 +430,5 @@
             device->channels , device->irqs );   
 #endif
+        }
     
         // Initialize array of irq descriptors for PIC
@@ -460,5 +455,5 @@
             }
         }
-    }
+    }   // end loop on io_cluster peripherals
 
     // initialize number of external peripherals
@@ -492,6 +487,6 @@
     boot_info->cores_nr = core_id;
 
-    // loop on all peripherals in my_cluster to initialise
-    // boot_info array of internal peripherals in my_cluster
+    // initialise internal devices (RAM, XCU, MMC, DMA)
+    // set default values, then scan all local devices 
 
 #if DEBUG_BOOT_INFO
@@ -499,20 +494,50 @@
 #endif
 
-    device_id = 0;
+    boot_info->pages_nr         = 0; 
+    boot_info->dev_icu.channels = 0;
+    boot_info->dev_mmc.channels = 0;
+    boot_info->dev_dma.channels = 0;
+
     for (device = &device_base[my_cluster->device_offset];
          device < &device_base[my_cluster->device_offset + my_cluster->devices];
          device++ )
     {
-        // initialise one entry for each internal peripheral
-        if( (device->type == DEV_TYPE_RAM_SCL) ||
-            (device->type == DEV_TYPE_ICU_XCU) ||
-            (device->type == DEV_TYPE_MMC_TSR) ||
-            (device->type == DEV_TYPE_DMA_SCL) ) 
+        if (device->type == DEV_TYPE_RAM_SCL)
         {
-            boot_dev = &boot_info->int_dev[device_id];
+            // set total number of physical memory pages in cluster
+            boot_info->pages_nr = device->size >> CONFIG_PPM_PAGE_SHIFT;
+
+            // Get the last address allocated for the kernel segments
+            uint32_t end;
+            if( boot_info->kernel_code_end > boot_info->kernel_data_end )
+            {
+                end = boot_info->kernel_code_end;
+            }
+            else
+            {
+                end = boot_info->kernel_data_end;
+            }
+                
+            // Compute the number of pages allocated for the kernel.
+            if( (end & CONFIG_PPM_PAGE_MASK) == 0 )
+            {
+                boot_info->pages_offset = end >> CONFIG_PPM_PAGE_SHIFT;
+            }
+            else
+            {
+                boot_info->pages_offset = (end >> CONFIG_PPM_PAGE_SHIFT) + 1;
+            }
+
+#if DEBUG_BOOT_INFO
+boot_printf("  - RAM : %x pages / first free page = %x\n",
+            boot_info->pages_nr , boot_info->pages_offset );
+#endif
+        }
+        else if (device->type == DEV_TYPE_ICU_XCU) 
+        {
+            boot_dev = &boot_info->dev_icu;
 
             boot_dev->type     = device->type;
             boot_dev->base     = device->base;
-            boot_dev->size     = device->size;
             boot_dev->channels = device->channels;
             boot_dev->param0   = device->arg0;    
@@ -521,50 +546,10 @@
             boot_dev->param3   = device->arg3;    
             boot_dev->irqs     = device->irqs; 
-   
-            device_id++;
-        }
-
-#if DEBUG_BOOT_INFO
-boot_printf("  - %s : base = %l / size = %l / channels = %d / irqs = %d\n",
-            device_type_str( device->type ) , device->base , device->size ,
-            device->channels , device->irqs );   
-#endif
-
-        // Initialize information about physical memory in cluster
-        if (device->type == DEV_TYPE_RAM_SCL)
-        {
-            // Compute total number of physical memory pages in cluster
-            boot_info->pages_nr = device->size >> CONFIG_PPM_PAGE_SHIFT;
-
-            // Get the last address allocated for the kernel segments
-            uint32_t end;
-            if( boot_info->kernel_code_end > boot_info->kernel_data_end )
-            {
-                end = boot_info->kernel_code_end;
-            }
-            else
-            {
-                end = boot_info->kernel_data_end;
-            }
-                
-            // Compute the number of pages allocated for the kernel.
-            if( (end & CONFIG_PPM_PAGE_MASK) == 0 )
-            {
-                boot_info->pages_offset = end >> CONFIG_PPM_PAGE_SHIFT;
-            }
-            else
-            {
-                boot_info->pages_offset = (end >> CONFIG_PPM_PAGE_SHIFT) + 1;
-            }
-
-#if DEBUG_BOOT_INFO
-boot_printf("    . physical memory : %x pages / first free page = %x\n",
-            boot_info->pages_nr , boot_info->pages_offset );
-#endif
-        }
-            
-        // Initialize array of irq descriptors for XCU 
-        if (device->type == DEV_TYPE_ICU_XCU) 
-        {
+
+#if DEBUG_BOOT_INFO
+boot_printf("  - XCU : base = %l / size = %l / channels = %d / irqs = %d\n",
+            device->base , device->size , device->channels , device->irqs );   
+#endif
+
             for (irq_id = 0; irq_id < CONFIG_MAX_HWIS_PER_ICU; irq_id++)
             {
@@ -588,8 +573,33 @@
             }
         }
-    }
-
-    // initialize number of internal peripherals in my_cluster
-    boot_info->int_dev_nr = device_id;
+        else if( device->type == DEV_TYPE_MMC_TSR )
+        {
+            boot_dev = &boot_info->dev_mmc;
+
+            boot_dev->type     = device->type;
+            boot_dev->base     = device->base;
+            boot_dev->channels = device->channels;
+            boot_dev->irqs     = 0;
+
+#if DEBUG_BOOT_INFO
+boot_printf("  - MMC : base = %l / size = %l / channels = %d / irqs = %d\n",
+            device->base , device->size , device->channels , device->irqs );   
+#endif
+        }
+        else if( device->type == DEV_TYPE_DMA_SCL )
+        {            
+            boot_dev = &boot_info->dev_dma;
+
+            boot_dev->type     = device->type;
+            boot_dev->base     = device->base;
+            boot_dev->channels = device->channels;
+            boot_dev->irqs     = 0;
+
+#if DEBUG_BOOT_INFO
+boot_printf("  - DMA : base = %l / size = %l / channels = %d / irqs = %d\n",
+            device->base , device->size , device->channels , device->irqs );   
+#endif
+        }
+    }  // end loop on local peripherals
 
     // set boot_info signature
@@ -694,14 +704,9 @@
     unsigned int     core_id;        // Iterator on cores
 
-    // loop on devices to find XCU
-    for (device = &boot_info->int_dev[0];
-         device < &boot_info->int_dev[boot_info->int_dev_nr];
-         device++)
-    {
-        if (device->type == DEV_TYPE_ICU_XCU)
-        {
-            // loop on cores
-            for (core_id = 1; core_id < boot_info->cores_nr; core_id++)
-            {
+    device = &boot_info->dev_icu;
+ 
+    // loop on cores
+    for (core_id = 1; core_id < boot_info->cores_nr; core_id++)
+    {
 
 #if DEBUG_BOOT_WAKUP
@@ -709,8 +714,5 @@
              boot_info->cxy , core_id , boot_get_proctime() );
 #endif
-                boot_remote_sw((xptr_t) (device->base + (core_id << 2)),
-                               (uint32_t)boot_entry); 
-            }
-        }
+        boot_remote_sw( (xptr_t)(device->base + (core_id << 2)) , (uint32_t)boot_entry ); 
     }
 } // boot_wake_local_cores()
@@ -884,9 +886,22 @@
     }
 
-    // Each core compute address of a temporary kernel stack 
-    // in the upper part of the local cluster memory...
-    uint32_t stack_ptr = ((boot_info->pages_nr - lid) << 12) - 16;
-
-    // All cores initialise stack pointer,
+    // Ech core compute stack pointer to the kernel idle-thread descriptor.
+    // The array of idle-thread descriptors is allocated in the kdata segment,
+    // just after the boot_info structure
+
+    uint32_t sp;
+    uint32_t base;
+    uint32_t offset = sizeof( boot_info_t );
+    uint32_t pmask  = CONFIG_PPM_PAGE_MASK;
+    uint32_t psize  = CONFIG_PPM_PAGE_SIZE;
+
+    // compute base address of idle thread descriptors array
+    if( offset & pmask ) base = seg_kdata_base + (offset & ~pmask) + psize;
+    else                 base = seg_kdata_base + offset;
+
+    // compute stack pointer
+    sp = base + ((lid + 1) * CONFIG_THREAD_DESC_SIZE) - 16;
+
+    // Each cores initialise stack pointer,
     // reset the BEV bit in status register,
     // register "boot_info" argument in a0,
@@ -900,5 +915,5 @@
                   "move  $29,  %1            \n"
                   "jr    %2                  \n"
-                  :: "r"(boot_info) , "r"(stack_ptr) , "r"(kernel_entry) );
+                  :: "r"(boot_info) , "r"(sp) , "r"(kernel_entry) );
 
 } // boot_loader()
