Index: trunk/kernel/kern/kernel_init.c
===================================================================
--- trunk/kernel/kern/kernel_init.c	(revision 690)
+++ trunk/kernel/kern/kernel_init.c	(revision 1)
@@ -1,7 +1,6 @@
 /*
  * kernel_init.c - kernel parallel initialization
- *
- * Authors :  Mohamed Lamine Karaoui (2015)
- *            Alain Greiner          (2016,2017,2018,2019,2020)
+ * 
+ * Authors :  Alain Greiner  (2016)
  *
  * Copyright (c) Sorbonne Universites
@@ -23,337 +22,103 @@
  */
 
-#include <kernel_config.h>
+#include <almos_config.h>
 #include <errno.h>
-#include <hal_kernel_types.h>
+#include <hal_types.h>
 #include <hal_special.h>
 #include <hal_context.h>
-#include <hal_irqmask.h>
-#include <hal_macros.h>
-#include <hal_ppm.h>
-#include <barrier.h>
-#include <xbarrier.h>
-#include <remote_fifo.h>
+#include <remote_barrier.h>
 #include <core.h>
 #include <list.h>
-#include <xlist.h>
-#include <xhtab.h>
 #include <thread.h>
 #include <scheduler.h>
-#include <ksocket.h>
 #include <kmem.h>
 #include <cluster.h>
+#include <devfs.h>
+#include <sysfs.h>
 #include <string.h>
 #include <memcpy.h>
 #include <ppm.h>
-#include <kcm.h>
 #include <page.h>
-#include <chdev.h>
+#include <device.h>
 #include <boot_info.h>
 #include <dqdt.h>
+#include <dev_icu.h>
 #include <dev_mmc.h>
-#include <dev_dma.h>
-#include <dev_iob.h>
+#include <dev_mwr.h>
+#include <dev_iox.h>
 #include <dev_ioc.h>
-#include <dev_txt.h>
 #include <dev_pic.h>
 #include <printk.h>
 #include <vfs.h>
-#include <devfs.h>
-#include <mapper.h>
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// All the following global variables are replicated in all clusters.
+
+
+#define KERNEL_INIT_SYNCRO  0xA5A5B5B5
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// All these global variables are replicated in all clusters.
 // They are initialised by the kernel_init() function.
-//
-// WARNING : The section names have been defined to control the base addresses of the
-// boot_info structure and the idle thread descriptors, through the kernel.ld script:
-// - the boot_info structure is built by the bootloader, and used by kernel_init.
-//   it must be the first object in the kdata segment.
-// - the array of idle threads descriptors must be placed on the first page boundary after
-//   the boot_info structure in the kdata segment.
-///////////////////////////////////////////////////////////////////////////////////////////
-
-// This variable defines the local boot_info structure
-__attribute__((section(".kinfo")))
-boot_info_t          boot_info;
-
-// This variable defines the "idle" threads descriptors array
-__attribute__((section(".kidle")))
-char                 idle_threads[CONFIG_THREAD_DESC_SIZE *
-                                   CONFIG_MAX_LOCAL_CORES]   CONFIG_PPM_PAGE_ALIGNED;
-
-// This variable defines the local cluster manager
-__attribute__((section(".kdata")))
-cluster_t            cluster_manager                         CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable defines the TXT_TX[0] chdev
-__attribute__((section(".kdata")))
-chdev_t              txt0_tx_chdev                           CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable defines the TXT_RX[0] chdev
-__attribute__((section(".kdata")))
-chdev_t              txt0_rx_chdev                           CONFIG_CACHE_LINE_ALIGNED;
-
-// This variables define the kernel process0 descriptor
-__attribute__((section(".kdata")))
-process_t            process_zero                            CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable defines a set of extended pointers on the distributed chdevs
-__attribute__((section(".kdata")))
-chdev_directory_t    chdev_dir                               CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable contains the input IRQ indexes for the IOPIC controller
-__attribute__((section(".kdata")))
-iopic_input_t        iopic_input                             CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable contains the input IRQ indexes for the LAPIC controller
-__attribute__((section(".kdata")))
-lapic_input_t        lapic_input                             CONFIG_CACHE_LINE_ALIGNED;
+///////////////////////////////////////////////////////////////////////////////////////////
+
+// This variable defines the local cluster manager 
+cluster_t            cluster_manager    CACHELINE_ALIGNED; 
+
+// This variable defines the kernel process descriptor and associated thread
+process_t            process_zero       CACHELINE_ALIGNED;            
+thread_t             thread_zero        CACHELINE_ALIGNED;
+
+// This variable contains the extended pointers on the device descriptors
+devices_directory_t  devices_dir        CACHELINE_ALIGNED;
+
+// This variable contains the input IRQ indexes for the PIC and ICU devices
+devices_input_irq_t  devices_input_irq   CACHELINE_ALIGNED;
+
+// This variable synchronizes the cores during kernel_init()
+volatile uint32_t    local_sync_init = 0;  
 
 // This variable defines the local cluster identifier
-__attribute__((section(".kdata")))
-cxy_t                local_cxy                               CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable is used for core[0] cores synchronisation in kernel_init()
-__attribute__((section(".kdata")))
-xbarrier_t           global_barrier                          CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable is used for local cores synchronisation in kernel_init()
-__attribute__((section(".kdata")))
-barrier_t            local_barrier                           CONFIG_CACHE_LINE_ALIGNED;
-
-// This variable defines the array of supported File System contexts
-__attribute__((section(".kdata")))
-vfs_ctx_t            fs_context[FS_TYPES_NR]                 CONFIG_CACHE_LINE_ALIGNED;
-
-// This array is used for debug, and describes the kernel locks usage,
-// It must be kept consistent with the defines in kernel_config.h file.
-__attribute__((section(".kdata")))
-char * lock_type_str[] =
-{
-    "unused_0",              //  0   must be unused to help debug
-
-    "CLUSTER_KCM",           //  1
-    "SCHED_STATE",           //  2
-    "VMM_STACK",             //  3
-    "VMM_MMAP",              //  4
-    "KCM_STATE",             //  5
-    "KHM_STATE",             //  6
-    "HTAB_STATE",            //  7
-    "CORE_ALARMS",           //  8
-
-    "VFS_CTX",               //  9
-    "PPM_FREE",              // 10
-    "THREAD_JOIN",           // 11
-    "XHTAB_STATE",           // 12
-    "CHDEV_QUEUE",           // 13
-    "CHDEV_TXT0",            // 14
-    "CHDEV_TXTLIST",         // 15
-    "PAGE_STATE",            // 16
-    "MUTEX_STATE",           // 17
-    "CONDVAR_STATE",         // 18
-    "SEM_STATE",             // 19
-    "PROCESS_CWD",           // 20
-    "BARRIER_STATE",         // 21
-    "LISTEN_SOCKET",         // 22
-
-    "CLUSTER_PREFTBL",       // 23
-
-    "SOCKET_STATE",          // 24
-    "PPM_DIRTY",             // 25
-    "CLUSTER_LOCALS",        // 26
-    "CLUSTER_COPIES",        // 27
-    "PROCESS_CHILDREN",      // 28
-    "PROCESS_USERSYNC",      // 29
-    "PROCESS_FDARRAY",       // 30
-    "PROCESS_DIR",           // 31
-    "VMM_VSL",               // 32
-
-    "PROCESS_THTBL",         // 33
-
-    "MAPPER_STATE",          // 34
-    "VFS_SIZE",              // 35
-    "VFS_FILE",              // 36
-    "VFS_MAIN",              // 37
-    "FATFS_FAT",             // 38
-    "FBF_WINDOWS",           // 39
-};        
-
-// debug variables to analyse the sys_read()  syscalls timing
-
-#if DEBUG_SYS_READ
-uint32_t   enter_sys_read;
-uint32_t   exit_sys_read;
-
-uint32_t   enter_devfs_read;
-uint32_t   exit_devfs_read;
-
-uint32_t   enter_txt_read;
-uint32_t   exit_txt_read;
-
-uint32_t   enter_chdev_cmd_read;
-uint32_t   exit_chdev_cmd_read;
-
-uint32_t   enter_chdev_server_read;
-uint32_t   exit_chdev_server_read;
-
-uint32_t   enter_tty_cmd_read;
-uint32_t   exit_tty_cmd_read;
-
-uint32_t   enter_tty_isr_read;
-uint32_t   exit_tty_isr_read;
-#endif
-
-// debug variables  to analyse the sys_write() syscall timing
-
-#if DEBUG_SYS_WRITE    
-uint32_t   enter_sys_write;
-uint32_t   exit_sys_write;
-
-uint32_t   enter_devfs_write;
-uint32_t   exit_devfs_write;
-
-uint32_t   enter_txt_write;
-uint32_t   exit_txt_write;
-
-uint32_t   enter_chdev_cmd_write;
-uint32_t   exit_chdev_cmd_write;
-
-uint32_t   enter_chdev_server_write;
-uint32_t   exit_chdev_server_write;
-
-uint32_t   enter_tty_cmd_write;
-uint32_t   exit_tty_cmd_write;
-
-uint32_t   enter_tty_isr_write;
-uint32_t   exit_tty_isr_write;
-#endif
-
-// intrumentation variables : cumulated costs per syscall type in cluster
-
-#if CONFIG_INSTRUMENTATION_SYSCALLS
-__attribute__((section(".kdata")))
-uint32_t   syscalls_cumul_cost[SYSCALLS_NR];
-
-__attribute__((section(".kdata")))
-uint32_t   syscalls_occurences[SYSCALLS_NR];
-#endif
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This function displays the ALMOS_MKH banner.
-///////////////////////////////////////////////////////////////////////////////////////////
-static void print_banner( uint32_t nclusters , uint32_t ncores )
-{
-    printk("\n"
-           "                    _        __    __     _____     ______         __    __    _   __   _     _   \n"
-           "          /\\       | |      |  \\  /  |   / ___ \\   / _____|       |  \\  /  |  | | / /  | |   | |  \n"
-           "         /  \\      | |      |   \\/   |  | /   \\ | | /             |   \\/   |  | |/ /   | |   | |  \n"
-           "        / /\\ \\     | |      | |\\  /| |  | |   | | | |_____   ___  | |\\  /| |  |   /    | |___| |  \n"
-           "       / /__\\ \\    | |      | | \\/ | |  | |   | | \\_____  \\ |___| | | \\/ | |  |   \\    |  ___  |  \n"
-           "      / ______ \\   | |      | |    | |  | |   | |       | |       | |    | |  | |\\ \\   | |   | |  \n"
-           "     / /      \\ \\  | |____  | |    | |  | \\___/ |  _____/ |       | |    | |  | | \\ \\  | |   | |  \n"
-           "    /_/        \\_\\ |______| |_|    |_|   \\_____/  |______/        |_|    |_|  |_|  \\_\\ |_|   |_|  \n"
-           "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n"
-           "\n\n\t\t %s / %d cluster(s) / %d core(s) per cluster\n\n",
-           CONFIG_VERSION , nclusters , ncores );
+cxy_t                local_cxy;
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// This function displays the ALMOS_MKH.banner.
+///////////////////////////////////////////////////////////////////////////////////////////
+static void print_boot_banner()
+{ 
+        printk("\n           ____        ___        ___       ___    _______    ________         ___       ___   ___     ___   \n");
+        printk("          /    \\      |   |      |   \\     /   |  /  ___  \\  /  ____  |       |   \\     /   | |   |   /  / \n");
+        printk("         /  __  \\      | |        |   \\___/   |  |  /   \\  | | /    |_/        |   \\___/   |   | |   /  /  \n");
+        printk("        /  /  \\  \\     | |        |  _     _  |  | |     | | | |______   ___   |  _     _  |   | |__/  /     \n");
+        printk("       /  /____\\  \\    | |        | | \\   / | |  | |     | | \\______  \\ |___|  | | \\   / | |   |  __  <  \n");
+        printk("      /   ______   \\   | |     _  | |  \\_/  | |  | |     | |  _     | |        | |  \\_/  | |   | |  \\  \\  \n");
+        printk("     /   /      \\   \\  | |____/ | | |       | |  |  \\___/  | | \\____/ |        | |       | |   | |   \\  \\\n");
+        printk("    /_____/    \\_____\\|_________/|___|     |___|  \\_______/  |________/       |___|     |___| |___|   \\__\\\n");
+
+
+        printk("\n\n\t\t\t\t Multi-Kernel Advanced Locality Management Operating System\n");
+        printk("\t\t\t\t   %s \n\n\n", CONFIG_ALMOS_VERSION );
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////////////////
-// This function initializes the TXT_TX[0] and TXT_RX[0] chdev descriptors, implementing
-// the "kernel terminal", shared by all kernel instances for debug messages. 
-// These chdev are implemented as global variables (replicated in all clusters),
-// because this terminal is used before the kmem allocator initialisation, but only 
-// the chdevs in cluster 0 are registered in the "chdev_dir" directory.
-// As this TXT0 chdev supports only the TXT_SYNC_WRITE command, we don't create
-// a server thread, we don't allocate a WTI, and we don't initialize the waiting queue.
-// Note: The TXT_RX[0] chdev is created, but is not used by ALMOS-MKH (september 2018).
+// This static function allocates memory for all devices descriptors associated 
+// to peripherals contained in the local cluster: 
+// - the internal (replicated) devices are placed in the local cluster.
+// - the external devices are pseudo-randomly distributed on all clusters. 
+// It initialises these device descriptors as specified by the boot_info_t structure,
+// including the dynamic linking with the driver for the specified implementation.
+// Finally, all copies of the devices directory are initialised.
+// TODO check that cluster IO contains a PIC and IOB [AG]
 ///////////////////////////////////////////////////////////////////////////////////////////
 // @ info    : pointer on the local boot-info structure.
 ///////////////////////////////////////////////////////////////////////////////////////////
-static void __attribute__ ((noinline)) txt0_device_init( boot_info_t * info )
+static void devices_init( boot_info_t * info )
 {
     boot_device_t * dev_tbl;         // pointer on array of devices in boot_info
-    uint32_t        dev_nr;          // actual number of devices in this cluster
-    xptr_t          base;            // remote pointer on segment base
-    uint32_t        func;            // device functional index
-    uint32_t        impl;            // device implementation index
-    uint32_t        i;               // device index in dev_tbl
-    uint32_t        x;               // X cluster coordinate
-    uint32_t        y;               // Y cluster coordinate
-
-    // get number of peripherals and base of devices array from boot_info
-    dev_nr      = info->ext_dev_nr;
-    dev_tbl     = info->ext_dev;
-
-    // loop on external peripherals to find TXT device
-    for( i = 0 ; i < dev_nr ; i++ )
-    {
-        base        = dev_tbl[i].base;
-        func        = FUNC_FROM_TYPE( dev_tbl[i].type );
-        impl        = IMPL_FROM_TYPE( dev_tbl[i].type );
-
-        if (func == DEV_FUNC_TXT )
-        {
-            // initialize TXT_TX[0] chdev
-            txt0_tx_chdev.func    = func;
-            txt0_tx_chdev.impl    = impl;
-            txt0_tx_chdev.channel = 0;
-            txt0_tx_chdev.base    = base;
-            txt0_tx_chdev.is_rx   = false;
-            remote_busylock_init( XPTR( local_cxy , &txt0_tx_chdev.wait_lock ),
-                                  LOCK_CHDEV_TXT0 );
-            
-            // make TXT specific initialisations 
-            dev_txt_init( &txt0_tx_chdev );                 
-
-            // initialize TXT_RX[0] chdev
-            txt0_rx_chdev.func    = func;
-            txt0_rx_chdev.impl    = impl;
-            txt0_rx_chdev.channel = 0;
-            txt0_rx_chdev.base    = base;
-            txt0_rx_chdev.is_rx   = true;
-            remote_busylock_init( XPTR( local_cxy , &txt0_rx_chdev.wait_lock ),
-                                  LOCK_CHDEV_TXT0 );
-            
-            // make TXT specific initialisations 
-            dev_txt_init( &txt0_rx_chdev );
-
-            // register TXT_TX[0] & TXT_RX[0] in chdev_dir[x][y]
-            // for all valid clusters             
-            for( x = 0 ; x < info->x_size ; x++ )
-            {
-                for( y = 0 ; y < info->y_size ; y++ )
-                {
-                    cxy_t cxy = HAL_CXY_FROM_XY( x , y );
-
-                    if( cluster_is_active( cxy ) )
-                    {
-                        hal_remote_s64( XPTR( cxy , &chdev_dir.txt_tx[0] ) ,
-                                        XPTR( local_cxy , &txt0_tx_chdev ) );
-                        hal_remote_s64( XPTR( cxy , &chdev_dir.txt_rx[0] ) ,
-                                        XPTR( local_cxy , &txt0_rx_chdev ) );
-                    }
-                }
-            }
-
-            hal_fence();
-        }
-	} // end loop on devices
-}  // end txt0_device_init()
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This function allocates memory and initializes the chdev descriptors for the internal
-// peripherals contained in the local cluster, other than the LAPIC, as specified by 
-// the boot_info, including the linking with the driver for the specified implementation.
-// The relevant entries in all copies of the devices directory are initialised.
-///////////////////////////////////////////////////////////////////////////////////////////
-// @ info    : pointer on the local boot-info structure.
-///////////////////////////////////////////////////////////////////////////////////////////
-static void __attribute__ ((noinline)) internal_devices_init( boot_info_t * info )
-{
-    boot_device_t * dev_tbl;         // pointer on array of internaldevices in boot_info
 	uint32_t        dev_nr;          // actual number of devices in this cluster
+	xptr_t          xp_dev;          // extended pointer on device descriptor
+	xptr_t          xp_dev_bis;      // extended pointer on second device descriptor
 	xptr_t          base;            // remote pointer on segment base
+	uint32_t        size;            // channel size (bytes)
+    uint32_t        type;            // peripheral type
     uint32_t        func;            // device functionnal index
     uint32_t        impl;            // device implementation index
@@ -362,1208 +127,380 @@
 	uint32_t        y;               // Y cluster coordinate
 	uint32_t        channels;        // number of channels
-	uint32_t        channel;         // channel index
-	chdev_t       * chdev_ptr;       // local pointer on created chdev
-
-    // get number of internal peripherals and base from boot_info
-	dev_nr	= info->int_dev_nr;
-    dev_tbl = info->int_dev;
-
-    // loop on internal peripherals
+	uint32_t        chl;             // channel index
+	uint32_t        p0;              // device parameter 0
+	uint32_t        p1;              // device parameter 1
+	uint32_t        p2;              // device parameter 2
+	uint32_t        p3;              // device parameter 3
+    bool_t          is_local;        // true for internal peripherals
+
+    // get number of peripherals from boot_info
+	dev_nr	    = info->devices_nr;
+    dev_tbl     = info->dev;
+
+    // loop on all peripherals in cluster
 	for( i = 0 ; i < dev_nr ; i++ )
 	{
-        base        = dev_tbl[i].base;
-        channels    = dev_tbl[i].channels;
-        func        = FUNC_FROM_TYPE( dev_tbl[i].type );
-        impl        = IMPL_FROM_TYPE( dev_tbl[i].type );
- 
-        //////////////////////////
-        if( func == DEV_FUNC_MMC )  
-        {
-            // create chdev in local cluster
-            chdev_ptr = chdev_create( func,
-                                      impl,
-                                      0,          // channel
-                                      false,      // direction
-                                      base );
-            if( chdev_ptr == NULL )
+        size     = dev_tbl[i].size;
+        base     = dev_tbl[i].base;
+        type     = dev_tbl[i].type;
+        channels = dev_tbl[i].channels;
+        p0       = dev_tbl[i].param0;
+        p1       = dev_tbl[i].param1;
+        p2       = dev_tbl[i].param2;
+        p3       = dev_tbl[i].param3;
+
+        func     = FUNC_FROM_TYPE( type );
+        impl     = IMPL_FROM_TYPE( type );
+
+        // do nothing for RAM and ROM functional types
+        if( (type == DEV_FUNC_RAM) || (type == DEV_FUNC_ROM) ) continue;
+
+        // loop on channels in peripheral
+        for( chl = 0 ; chl < channels ; chl++ )
+        { 
+            // target cluster is local for internal (replicated) peripherals
+            if( (func == DEV_FUNC_ICU) || 
+                (func == DEV_FUNC_MMC) ||
+                (func == DEV_FUNC_MWR) )   is_local = true;
+            else                           is_local = false;
+
+            // allocate memory and initialize device descriptor
+		    xp_dev = device_alloc( info , is_local );
+
+            if( xp_dev == XPTR_NULL ) hal_core_sleep();
+            
+            device_init( xp_dev ,
+                         func ,
+                         impl,
+                         chl,
+                         false,                    // TX
+                         base + size*chl,
+                         size );
+
+            // allocate memory and initialise another device descriptor if NIC, 
+            // ALMOS-MKH uses two separate devices descriptor for NIC_RX and NIC_TX
+            if( func == DEV_FUNC_NIC )
             {
-                printk("\n[PANIC] in %s : cannot create MMC chdev\n",
-                __FUNCTION__ );
-                hal_core_sleep();
-            }
-            
-#if (DEBUG_KERNEL_INIT & 0x1)
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-printk("\n[%s] created chdev[%x,%x] for MMC\n",
-__FUNCTION__ , local_cxy , chdev_ptr );
-#endif
-            // make MMC specific initialisation
-            dev_mmc_init( chdev_ptr );
-
-            // set the MMC field in all chdev_dir[x][y] structures
+                xp_dev_bis = device_alloc( info , is_local );
+
+                if( xp_dev_bis == XPTR_NULL ) hal_core_sleep();
+
+                device_init( xp_dev_bis ,
+                             func ,
+                             impl,
+                             chl,
+                             true,                // RX
+                             (base + size*chl),
+                             size );
+             }
+
+            // TODO ??? AG
+		    // devfs_register( dev );
+
+            // make device type specific initialisation
+            // the number of parameters depends on the device type
+            if     ( func == DEV_FUNC_ICU ) dev_icu_init( xp_dev , p0 , p1 , p2 );     
+            else if( func == DEV_FUNC_MMC ) dev_mmc_init( xp_dev );
+// TODO     else if( func == DEV_FUNC_MWR ) dev_mwr_init( xp_dev , p0 , p1 , p2 , p3 );
+            else if( func == DEV_FUNC_IOB ) dev_iox_init( xp_dev );
+            else if( func == DEV_FUNC_IOC ) dev_ioc_init( xp_dev );
+            else if( func == DEV_FUNC_TXT ) dev_txt_init( xp_dev );
+            else if( func == DEV_FUNC_PIC ) dev_pic_init( xp_dev , p0 );
+            else if( func == DEV_FUNC_NIC ) dev_nic_init( xp_dev );
+            else                            hal_core_sleep();
+
+           // initialize the replicated devices_dir[x][y] structures
+           // defining the extended pointers on all devices descriptors 
+           xptr_t * ptr_dev;    
+           xptr_t * ptr_dev_bis;    
+
+           if( func == DEV_FUNC_ICU ) ptr_dev     = &devices_dir.icu[local_cxy];
+           if( func == DEV_FUNC_MMC ) ptr_dev     = &devices_dir.mmc[local_cxy];
+           if( func == DEV_FUNC_MWR ) ptr_dev     = &devices_dir.mwr[local_cxy];
+
+           if( func == DEV_FUNC_TXT ) ptr_dev     = &devices_dir.txt[chl];
+           if( func == DEV_FUNC_IOB ) ptr_dev     = &devices_dir.iob;
+           if( func == DEV_FUNC_IOC ) ptr_dev     = &devices_dir.ioc;
+           if( func == DEV_FUNC_PIC ) ptr_dev     = &devices_dir.pic;
+           if( func == DEV_FUNC_NIC ) ptr_dev     = &devices_dir.nic_tx[chl];
+           if( func == DEV_FUNC_NIC ) ptr_dev_bis = &devices_dir.nic_rx[chl];
+  
             for( x = 0 ; x < info->x_size ; x++ )
             {
                 for( y = 0 ; y < info->y_size ; y++ )
                 {
-                    cxy_t cxy = HAL_CXY_FROM_XY( x , y );
-
-                    if( cluster_is_active( cxy ) )
+                    cxy_t  cxy = (x<<info->y_width) + y;
+                     
+                    hal_remote_swd( XPTR( cxy , ptr_dev ) , xp_dev );
+
+                    if( func == DEV_FUNC_NIC )
                     {
-                        hal_remote_s64( XPTR( cxy , &chdev_dir.mmc[local_cxy] ), 
-                                        XPTR( local_cxy , chdev_ptr ) );
+                       hal_remote_swd( XPTR( cxy , ptr_dev_bis ) , xp_dev_bis );
                     }
                 }
             }
-
-#if( DEBUG_KERNEL_INIT & 0x1 )
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-printk("\n[%s] initialised chdev[%x,%x] for MMC\n",
-__FUNCTION__ , local_cxy , chdev_ptr );
-#endif
-        }
-        ///////////////////////////////
-        else if( func == DEV_FUNC_DMA )
+           
+		    kinit_dmsg("[INFO] %s created device %s / channel %d / in cluster %x\n",
+                       __FUNCTION__ , device_func_str[func] , chl , dev_cxy );
+
+        } // end loop on channels
+
+        // initialize the replicated devices_irq[x][y] structures
+        // defining how peripherals are connected to PIC or ICU components
+        uint32_t   id;
+        uint8_t    valid;
+        uint32_t   dev_type;
+        uint8_t    channel;
+        uint8_t    is_rx;
+        uint32_t * ptr_irq; 
+
+        // default initiialization for devices_irq structure
+        
+        // only external peripherals can be connected to PIC
+        if( func == DEV_FUNC_PIC )  
         {
-            // create one chdev per channel in local cluster
-            for( channel = 0 ; channel < channels ; channel++ )
-            { 	
-                // create chdev[channel] in local cluster
-                chdev_ptr = chdev_create( func,
-                                          impl,
-                                          channel,
-                                          false,     // direction
-                                          base );
-                if( chdev_ptr == NULL )
+            // loop on PIC inputs
+            for( id = 0 ; id < CONFIG_MAX_IRQS_PER_PIC ; id++ )
+            {
+                valid     = dev_tbl[i].irq[id].valid;
+                dev_type  = dev_tbl[i].irq[id].dev_type;
+                channel   = dev_tbl[i].irq[id].channel;
+                is_rx     = dev_tbl[i].irq[id].is_rx;
+
+                // only valid IRQs are registered in the devices_input_irq structure
+                // ptr_irq is a local pointer on the entry to be set in devices_irq
+                if( valid )
                 {
-                    printk("\n[PANIC] in %s : cannot create DMA chdev\n",
-                    __FUNCTION__ );
-                    hal_core_sleep();
-                }
-            
-#if (DEBUG_KERNEL_INIT & 0x1)
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-printk("\n[%s] cxy %x : created chdev[%x,%x] for DMA[%d]\n",
-__FUNCTION__ , local_cxy , chdev_ptr , channel );
-#endif
-                // make DMA specific initialisation
-                dev_dma_init( chdev_ptr );     
-
-                // initialize only the DMA[channel] field in the local chdev_dir[x][y]
-                // structure because the DMA device is not remotely accessible.
-                chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr );
-
-#if( DEBUG_KERNEL_INIT & 0x1 )
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-printk("\n[%s] initialised chdev[%x,%x] for DMA[%d]\n",
-__FUNCTION__ , local_cxy , chdev_ptr , channel );
-#endif
-            }
-        }
-    }
-}  // end internal_devices_init()
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This function allocates memory and initializes the chdev descriptors for the  
-// external (shared) peripherals other than the IOPIC, as specified by the boot_info.
-// This includes the dynamic linking with the driver for the specified implementation.
-// These chdev descriptors are distributed on all clusters, using a modulo on a global 
-// index, identically computed in all clusters.
-// This function is executed in all clusters by the core[0], that computes a global index
-// for all external chdevs. Each core[0] core creates only the chdevs that must be placed  
-// in the local cluster, because the global index matches the local index. 
-// The relevant entries in all copies of the devices directory are initialised.
-///////////////////////////////////////////////////////////////////////////////////////////
-// @ info    : pointer on the local boot-info structure.
-///////////////////////////////////////////////////////////////////////////////////////////
-static void external_devices_init( boot_info_t * info )
-{
-    boot_device_t * dev_tbl;         // pointer on array of external devices in boot_info
-	uint32_t        dev_nr;          // actual number of external devices 
-	xptr_t          base;            // remote pointer on segment base
-    uint32_t        func;            // device functionnal index
-    uint32_t        impl;            // device implementation index
-	uint32_t        i;               // device index in dev_tbl
-	uint32_t        x;               // X cluster coordinate
-	uint32_t        y;               // Y cluster coordinate
-	uint32_t        channels;        // number of channels
-	uint32_t        channel;         // channel index
-	uint32_t        directions;      // number of directions (1 or 2)
-	uint32_t        rx;              // direction index (0 or 1)
-    chdev_t       * chdev;           // local pointer on one channel_device descriptor
-    uint32_t        ext_chdev_gid;   // global index of external chdev
-
-    // get number of peripherals and base of devices array from boot_info
-    dev_nr      = info->ext_dev_nr;
-    dev_tbl     = info->ext_dev;
-
-    // initializes global index (PIC is already placed in cluster 0)
-    ext_chdev_gid = 1;
-
-    // loop on external peripherals
-    for( i = 0 ; i < dev_nr ; i++ )
-    {
-        base     = dev_tbl[i].base;
-        channels = dev_tbl[i].channels;
-        func     = FUNC_FROM_TYPE( dev_tbl[i].type );
-        impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
-
-        // There is one chdev per direction for NIC and for TXT
-        if((func == DEV_FUNC_NIC) || (func == DEV_FUNC_TXT)) directions = 2;
-        else                                                 directions = 1;
-
-        // do nothing for ROM, that does not require a device descriptor.
-        if( func == DEV_FUNC_ROM ) continue;
-
-        // do nothing for PIC, that is already initialized
-        if( func == DEV_FUNC_PIC ) continue;
-
-        // check PIC device initialized
-        if( chdev_dir.pic == XPTR_NULL )
-        {
-            printk("\n[PANIC] in %s : PIC device must be initialized first\n",
-            __FUNCTION__ );
-            hal_core_sleep();
-        }
-
-        // check external device functionnal type
-        if( (func != DEV_FUNC_IOB) && 
-            (func != DEV_FUNC_IOC) && 
-            (func != DEV_FUNC_TXT) &&
-            (func != DEV_FUNC_NIC) && 
-            (func != DEV_FUNC_FBF) )
-        {
-            printk("\n[PANIC] in %s : undefined peripheral type\n",
-            __FUNCTION__ );
-            hal_core_sleep();
-        }
-
-        // loop on channels
-        for( channel = 0 ; channel < channels ; channel++ )
-        {
-            // loop on directions
-            for( rx = 0 ; rx < directions ; rx++ )
-            {
-                // skip TXT0 that has already been initialized
-                if( (func == DEV_FUNC_TXT) && (channel == 0) ) continue;
-
-                // all kernel instances compute the target cluster for all chdevs,
-                // and the global index ext_chdev_gid[func,channel,direction]
-                cxy_t target_cxy;
-                while( 1 )
-                {
-                    uint32_t offset     = ext_chdev_gid % ( info->x_size * info->y_size );
-                    uint32_t x          = offset / info->y_size;
-                    uint32_t y          = offset % info->y_size;
-
-                    target_cxy = HAL_CXY_FROM_XY( x , y );
-
-                    // exit loop if target cluster is active
-                    if( cluster_is_active( target_cxy ) ) break;
-                
-                    // increment global index otherwise
-                    ext_chdev_gid++;
-                }
-
-                // allocate and initialize a local chdev
-                // when local cluster matches target cluster
-                if( target_cxy == local_cxy )
-                {
-                    chdev = chdev_create( func,
-                                          impl,
-                                          channel,
-                                          rx,          // direction
-                                          base );
-
-                    if( chdev == NULL )
-                    {
-                        printk("\n[PANIC] in %s : cannot allocate chdev\n",
-                        __FUNCTION__ );
-                        hal_core_sleep();
-                    }
-
-#if (DEBUG_KERNEL_INIT & 0x1)
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-printk("\n[%s] created chdev[%x,%x] for %s[%d] / is_rx %d\n",
-__FUNCTION__ , local_cxy , chdev , chdev_func_str(func) , channel , rx );
-#endif
-                    // make device type specific initialisation
-                    if     ( func == DEV_FUNC_IOB ) dev_iob_init( chdev );
-                    else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev );
-                    else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev );
-                    else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev );
-                    else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev );
-
-                    // all external (shared) devices are remotely accessible
-                    // initialize the replicated chdev_dir[x][y] structures
-                    // defining the extended pointers on chdev descriptors
-                    xptr_t * entry = NULL;
-
-                    if(func==DEV_FUNC_IOB             ) entry  = &chdev_dir.iob;
-                    if(func==DEV_FUNC_IOC             ) entry  = &chdev_dir.ioc[channel];
-                    if(func==DEV_FUNC_FBF             ) entry  = &chdev_dir.fbf[channel];
-                    if((func==DEV_FUNC_TXT) && (rx==0)) entry  = &chdev_dir.txt_tx[channel];
-                    if((func==DEV_FUNC_TXT) && (rx==1)) entry  = &chdev_dir.txt_rx[channel];
-                    if((func==DEV_FUNC_NIC) && (rx==0)) entry  = &chdev_dir.nic_tx[channel];
-                    if((func==DEV_FUNC_NIC) && (rx==1)) entry  = &chdev_dir.nic_rx[channel];
-
+                    uint16_t dev_func = FUNC_FROM_TYPE( dev_type );
+                    if( dev_func == DEV_FUNC_TXT )   
+                        ptr_irq = &devices_input_irq.txt[channel];
+                    if( dev_func == DEV_FUNC_IOC )                   
+                        ptr_irq = &devices_input_irq.ioc; 
+                    if( (dev_func == DEV_FUNC_NIC) && (is_rx == 0) ) 
+                        ptr_irq = &devices_input_irq.nic_tx[channel]; 
+                    if( (dev_func == DEV_FUNC_NIC) && (is_rx != 0) ) 
+                        ptr_irq = &devices_input_irq.nic_rx[channel]; 
+                   
+                    // all copies of devices_irq must be updated in all clusters
                     for( x = 0 ; x < info->x_size ; x++ )
                     {
                         for( y = 0 ; y < info->y_size ; y++ )
                         {
-                            cxy_t cxy = HAL_CXY_FROM_XY( x , y );
-
-                            if( cluster_is_active( cxy ) && ( entry != NULL ) )
-                            {
-                                hal_remote_s64( XPTR( cxy , entry ),
-                                                XPTR( local_cxy , chdev ) );
-                            }
+                            cxy_t  cxy = (x<<info->y_width) + y;
+                            hal_remote_sw( XPTR( cxy , ptr_irq ) , id );
+                        }	
+                    }
+                }
+            } // end loop on PIC inputs
+        } // end PIC
+
+        // only internal peripherals can be connected to ICU
+        if( func == DEV_FUNC_ICU )  
+        {
+            // loop on ICU inputs
+            for( id = 0 ; id < CONFIG_MAX_HWIS_PER_ICU ; id++ )
+            {
+                valid    = dev_tbl[i].irq[id].valid;
+                dev_type = dev_tbl[i].irq[id].dev_type;
+                channel  = dev_tbl[i].irq[id].channel;
+
+                // only valid IRQs are registered in the devices_input_irq structure
+                // ptr_irq is a local pointer on the entry to be set in devices_irq
+                if( valid )
+                {
+                    uint16_t dev_func = FUNC_FROM_TYPE( dev_type );
+                    if( dev_func == DEV_FUNC_MMC )  
+                        ptr_irq = &devices_input_irq.mmc[local_cxy];
+                    if( dev_func == DEV_FUNC_MWR )  
+                        ptr_irq = &devices_input_irq.mwr[local_cxy]; 
+                   
+                    // all copies of devices_irq must be updated in all clusters
+                    for( x = 0 ; x < info->x_size ; x++ )
+                    {
+                        for( y = 0 ; y < info->y_size ; y++ )
+                        {
+                            cxy_t  cxy = (x<<info->y_width) + y;
+                            hal_remote_sw( XPTR( cxy , ptr_irq ) , id );
                         }
                     }
-
-#if( DEBUG_KERNEL_INIT & 1 )
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-printk("\n[%s] initialised chdev[%x,%x] for %s\n",
-__FUNCTION__ , local_cxy, chdev , chdev->name );
-#endif
-
-                }  // end if match
-
-                // increment chdev global index (matching or not)
-                ext_chdev_gid++;
-
-            } // end loop on directions
-        }  // end loop on channels
-	} // end loop on devices
-}  // end external_devices_init()
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This function is called by core[0][0] to allocate memory and initialize the PIC
-// device, namely the informations attached to the external IOPIC controller, that
-// must be replicated in all clusters (struct iopic_input).
-// This initialisation must be done before other devices initialisation because the IRQ
-// routing infrastructure is required for both internal and external devices init.
+                }
+            }  // end loop on ICU inputs
+        }  // end ICU
+	} // end loop on peripherals
+}  // end devices_init()
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// This function is the entry point for the kernel initialisation.
+// It is executed by all cores in all clusters, but only core[0] in each cluster
+// initialize the cluster manager, ant the other local shared resources. 
+// To comply with the multi-kernels paradigm, it access only local cluster memory,
+// using only informations contained in the local boot_info_t structure, 
+// that has been set by the bootloader.
+// All cores TODO ...
 ///////////////////////////////////////////////////////////////////////////////////////////
 // @ info    : pointer on the local boot-info structure.
 ///////////////////////////////////////////////////////////////////////////////////////////
-static void __attribute__ ((noinline)) iopic_init( boot_info_t * info )
+void kernel_init( boot_info_t * info )
 {
-    boot_device_t * dev_tbl;         // pointer on boot_info external devices array
-	uint32_t        dev_nr;          // actual number of external devices
-	xptr_t          base;            // remote pointer on segment base
-    uint32_t        func;            // device functionnal index
-    uint32_t        impl;            // device implementation index
-	uint32_t        i;               // device index in dev_tbl
-    uint32_t        x;               // cluster X coordinate
-    uint32_t        y;               // cluster Y coordinate
-    bool_t          found;           // IOPIC found
-	chdev_t       * chdev;           // pointer on PIC chdev descriptor
-
-    // get number of external peripherals and base of array from boot_info
-	dev_nr	    = info->ext_dev_nr;
-    dev_tbl     = info->ext_dev;
-
-    // avoid GCC warning
-    base        = XPTR_NULL;
-    impl        = 0;
-
-    // loop on external peripherals to get the IOPIC  
-	for( i = 0 , found = false ; i < dev_nr ; i++ )
-	{
-        func = FUNC_FROM_TYPE( dev_tbl[i].type );
-
-        if( func == DEV_FUNC_PIC )
+    uint32_t     core_lid;      // running core local index
+    cxy_t        core_cxy;      // running core cluster identifier
+    gid_t        core_gid;      // running core hardware identifier 
+    cluster_t  * cluster;       // pointer on local cluster manager
+    core_t     * core;          // pointer on running core descriptor
+    thread_t   * thread_idle;   // pointer on thread_idle  
+
+	uint32_t     i;
+    bool_t       found;
+    error_t      error;
+
+    // initialise global cluster identifier
+    local_cxy = info->cxy;
+
+    // each core get its global index from hardware register
+    core_gid = hal_get_gid(); 
+
+    // Each core makes an associative search in boot_info
+    // to get its (cxy,lid) composite index 
+    found    = false;
+    core_cxy = 0;
+    core_lid = 0;
+    for( i = 0 ; i < info->cores_nr ; i++ )
+    {
+        if( core_gid == info->core[i].gid )
         {
-            base     = dev_tbl[i].base;
-            impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
-            found    = true;
+            core_lid = info->core[i].lid;
+            core_cxy = info->core[i].cxy;
+            found = true;
             break;
         }
     }
-
-    // check PIC existence
-    if( found == false )
-    {
-        printk("\n[PANIC] in %s : PIC device not found\n",
-        __FUNCTION__ );
+         
+    if ( found == false )
+    {
+        printk("PANIC in %s : Core %d not registered in cluster %x\n",
+               __FUNCTION__ , core_gid , local_cxy );
         hal_core_sleep();
     }
 
-    // allocate and initialize the PIC chdev in cluster 0
-    chdev = chdev_create( DEV_FUNC_PIC,
-                          impl,
-                          0,      // channel
-                          0,      // direction,
-                          base );
-
-    // check memory
-    if( chdev == NULL )
-    {
-        printk("\n[PANIC] in %s : no memory for PIC chdev\n",
-        __FUNCTION__ );
+    if ( core_cxy != local_cxy) 
+    {
+        printk("PANIC in %s : Core %d has wrong cxy in cluster %x\n",
+               __FUNCTION__ , core_gid , local_cxy );
         hal_core_sleep();
     }
 
-    // make PIC device type specific initialisation
-    dev_pic_init( chdev );
-
-    // register, in all clusters, the extended pointer
-    // on PIC chdev in "chdev_dir" array
-    xptr_t * entry = &chdev_dir.pic;    
-                
-    for( x = 0 ; x < info->x_size ; x++ )
-    {
-        for( y = 0 ; y < info->y_size ; y++ )
+    // from this point, only core[0] initialises local resources
+    if( core_lid == 0 )    
+    {
+        // initialize local cluster manager (cores and memory allocators)
+        error = cluster_init( info );
+        if ( error == 0 ) 
         {
-            cxy_t cxy = HAL_CXY_FROM_XY( x , y );
-
-            if( cluster_is_active( cxy ) )
-            {
-                hal_remote_s64( XPTR( cxy , entry ) , 
-                                XPTR( local_cxy , chdev ) );
-            }
-        }
-    }
-
-    // initialize, in all clusters, the "iopic_input" structure
-    // defining how external IRQs are connected to IOPIC 
-
-    // register default value for unused inputs 
-    for( x = 0 ; x < info->x_size ; x++ )
-    {
-        for( y = 0 ; y < info->y_size ; y++ )
-        {
-            cxy_t cxy = HAL_CXY_FROM_XY( x , y );
-
-            if( cluster_is_active( cxy ) )
-            {
-                hal_remote_memset( XPTR( cxy , &iopic_input ), 
-                                   0xFF , sizeof(iopic_input_t) );
-            }
-        }
-    }
-
-    // register input IRQ index for valid inputs 
-    uint32_t   id;             // input IRQ index
-    uint8_t    valid;          // input IRQ is connected
-    uint32_t   type;           // source device type
-    uint8_t    channel;        // source device channel
-    uint8_t    is_rx;          // source device direction
-    uint32_t * ptr = NULL;     // local pointer on one field in iopic_input stucture
-
-    for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ )
-    {
-        valid   = dev_tbl[i].irq[id].valid;
-        type    = dev_tbl[i].irq[id].dev_type;
-        channel = dev_tbl[i].irq[id].channel;
-        is_rx   = dev_tbl[i].irq[id].is_rx;
-        func    = FUNC_FROM_TYPE( type );
-
-        // get pointer on relevant field in iopic_input
-        if( valid )
-        {
-            if     ( func == DEV_FUNC_IOC )                 ptr = &iopic_input.ioc[channel]; 
-            else if((func == DEV_FUNC_TXT) && (is_rx == 0)) ptr = &iopic_input.txt_tx[channel];
-            else if((func == DEV_FUNC_TXT) && (is_rx != 0)) ptr = &iopic_input.txt_rx[channel];
-            else if((func == DEV_FUNC_NIC) && (is_rx == 0)) ptr = &iopic_input.nic_tx[channel];
-            else if((func == DEV_FUNC_NIC) && (is_rx != 0)) ptr = &iopic_input.nic_rx[channel];
-            else if( func == DEV_FUNC_IOB )                 ptr = &iopic_input.iob;
-            else
-            {
-                printk("\n[PANIC] in %s : illegal source device for IOPIC input\n",
-                __FUNCTION__ );
-                hal_core_sleep();
-            }
-
-            // set one entry in all "iopic_input" structures
-            for( x = 0 ; x < info->x_size ; x++ )
-            {
-                for( y = 0 ; y < info->y_size ; y++ )
-                {
-                    cxy_t cxy = HAL_CXY_FROM_XY( x , y );
-
-                    if( cluster_is_active( cxy ) )
-                    {
-                        hal_remote_s64( XPTR( cxy , ptr ) , id ); 
-                    }
-                }
-            }
-        }
-    } 
-
-#if( DEBUG_KERNEL_INIT & 0x1 )
-if( hal_time_stamp() > DEBUG_KERNEL_INIT )
-{
-    printk("\n[%s] created PIC chdev in cluster %x at cycle %d\n",
-    __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
-    dev_pic_inputs_display();
-}
-#endif
-    
-}  // end iopic_init()
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This function is called by all core[0]s in all cluster to complete the PIC device
-// initialisation, namely the informations attached to the LAPIC controller.
-// This initialisation must be done after the IOPIC initialisation, but before other 
-// devices initialisation because the IRQ routing infrastructure is required for both
-// internal and external devices initialisation.
-///////////////////////////////////////////////////////////////////////////////////////////
-// @ info    : pointer on the local boot-info structure.
-///////////////////////////////////////////////////////////////////////////////////////////
-static void __attribute__ ((noinline)) lapic_init( boot_info_t * info )
-{
-    boot_device_t * dev_tbl;      // pointer on boot_info internal devices array
-    uint32_t        dev_nr;       // number of internal devices
-    uint32_t        i;            // device index in dev_tbl
-	xptr_t          base;         // remote pointer on segment base
-    uint32_t        func;         // device functionnal type in boot_info
-    bool_t          found;        // LAPIC found
-
-    // get number of internal peripherals and base 
-	dev_nr	    = info->int_dev_nr;
-    dev_tbl     = info->int_dev;
-
-    // loop on internal peripherals to get the lapic device 
-	for( i = 0 , found = false ; i < dev_nr ; i++ )
-	{
-        func = FUNC_FROM_TYPE( dev_tbl[i].type );
-
-        if( func == DEV_FUNC_ICU )
-        {
-            base     = dev_tbl[i].base;
-            found    = true;
-            break;
-        }
-    }
-
-    // if the LAPIC controller is not defined in the boot_info,
-    // we simply don't initialize the PIC extensions in the kernel, 
-    // making the assumption that the LAPIC related informations 
-    // are hidden in the hardware specific PIC driver. 
-    if( found )
-    {
-        // initialise the PIC extensions for
-        // the core descriptor and core manager extensions
-        dev_pic_extend_init( (uint32_t *)GET_PTR( base ) );
-
-        // initialize the "lapic_input" structure
-        // defining how internal IRQs are connected to LAPIC 
-        uint32_t        id;
-        uint8_t         valid;
-        uint8_t         channel;
-        uint32_t        func;
-
-        for( id = 0 ; id < CONFIG_MAX_INTERNAL_IRQS ; id++ )
-        {
-            valid    = dev_tbl[i].irq[id].valid;
-            func     = FUNC_FROM_TYPE( dev_tbl[i].irq[id].dev_type );
-            channel  = dev_tbl[i].irq[id].channel;
-
-            if( valid ) // only valid local IRQs are registered
-            {
-                if     ( func == DEV_FUNC_MMC ) lapic_input.mmc = id;
-                else if( func == DEV_FUNC_DMA ) lapic_input.dma[channel] = id;
-                else
-                {
-                    printk("\n[PANIC] in %s : illegal source device for LAPIC input\n",
-                    __FUNCTION__ );
-                    hal_core_sleep();
-                }
-            }
-        }
-    }
-}  // end lapic_init()
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This static function returns the identifiers of the calling core.
-///////////////////////////////////////////////////////////////////////////////////////////
-// @ info    : pointer on boot_info structure.
-// @ lid     : [out] core local index in cluster.
-// @ cxy     : [out] cluster identifier.
-// @ lid     : [out] core global identifier (hardware).
-// @ return 0 if success / return -1 if not found.
-///////////////////////////////////////////////////////////////////////////////////////////
-static error_t __attribute__ ((noinline)) get_core_identifiers( boot_info_t * info,
-                                                                lid_t       * lid,
-                                                                cxy_t       * cxy,
-                                                                gid_t       * gid )
-{
-    uint32_t   i;
-    gid_t      global_id;
-
-    // get global identifier from hardware register
-    global_id = hal_get_gid();
-
-    // makes an associative search in boot_info to get (cxy,lid) from global_id
-    for( i = 0 ; i < info->cores_nr ; i++ )
-    {
-        if( global_id == info->core[i].gid )
-        {
-            *lid = info->core[i].lid;
-            *cxy = info->core[i].cxy;
-            *gid = global_id;
-            return 0;
-        }
-    }
-    return -1;
-}
-
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////
-// This function is the entry point for the kernel initialisation.
-// It is executed by all cores in all clusters, but only core[cxy][0] initializes
-// the shared resources such as the cluster manager, or the local peripherals.
-// To comply with the multi-kernels paradigm, it accesses only local cluster memory, using
-// only information contained in the local boot_info_t structure, set by the bootloader.
-// Only core[0] in cluster 0 print the log messages.
-///////////////////////////////////////////////////////////////////////////////////////////
-// @ info    : pointer on the local boot-info structure.
-///////////////////////////////////////////////////////////////////////////////////////////
-void kernel_init( boot_info_t * info )
-{
-    lid_t        core_lid = -1;             // running core local index
-    cxy_t        core_cxy = -1;             // running core cluster identifier
-    gid_t        core_gid;                  // running core hardware identifier 
-    cluster_t  * cluster;                   // pointer on local cluster manager
-    core_t     * core;                      // pointer on running core descriptor
-    thread_t   * thread;                    // pointer on idle thread descriptor
-
-    xptr_t       vfs_root_inode_xp;         // extended pointer on VFS root inode
-    xptr_t       devfs_dev_inode_xp;        // extended pointer on DEVFS dev inode    
-    xptr_t       devfs_external_inode_xp;   // extended pointer on DEVFS external inode       
-
-    error_t      error;
-    reg_t        status;                    // running core status register
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 1 : Each core get its core identifier from boot_info, and makes 
-    //          a partial initialisation of its private idle thread descriptor.
-    //          core[0] initializes the "local_cxy" global variable.
-    //          core[0] in cluster[0] initializes the TXT0 chdev for log messages.
-    /////////////////////////////////////////////////////////////////////////////////
-
-    error = get_core_identifiers( info,
-                                  &core_lid,
-                                  &core_cxy,
-                                  &core_gid );
-
-    // core[0] initialize cluster identifier
-    if( core_lid == 0 ) local_cxy = info->cxy;
-
-    // each core gets a pointer on its private idle thread descriptor
-    thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) );
-
-    // each core registers this thread pointer in hardware register
-    hal_set_current_thread( thread );
-
-    // each core register core descriptor pointer in idle thread descriptor
-    thread->core = &LOCAL_CLUSTER->core_tbl[core_lid];
-
-    // each core initializes the idle thread locks counters
-    thread->busylocks = 0;
-
-#if DEBUG_BUSYLOCK
-    // each core initialise the idle thread list of busylocks
-    xlist_root_init( XPTR( local_cxy , &thread->busylocks_root ) );
-#endif
-
-    // core[0] initializes cluster info
-    if( core_lid == 0 ) cluster_info_init( info );
-
-    // core[0] in cluster[0] initialises TXT0 chdev descriptor
-    if( (core_lid == 0) && (core_cxy == 0) ) txt0_device_init( info );
-
-    // all cores check identifiers
-    if( error )
-    {
-        printk("\n[PANIC] in %s : illegal core : gid %x / cxy %x / lid %d",
-        __FUNCTION__, core_lid, core_cxy, core_lid );
-        hal_core_sleep();
-    }
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 1 : TXT0 initialized / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 2 : core[0] initializes the cluster manager,
-    //          including the physical memory allocators. 
-    /////////////////////////////////////////////////////////////////////////////////
-
-    // core[0] initialises DQDT (only core[0][0] build the quad-tree)
-    if( core_lid == 0 ) dqdt_init();
-    
-    // core[0] initialize other cluster manager complex structures
-    if( core_lid == 0 )
-    {
-        error = cluster_manager_init( info );
-
-        if( error )
-        {
-             printk("\n[PANIC] in %s : cannot initialize cluster manager in cluster %x\n",
-             __FUNCTION__, local_cxy );
-             hal_core_sleep();
-        }
-    }
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 2 : cluster manager initialized / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 3 : all cores initialize the idle thread descriptor.
-    //          core[0] initializes the process_zero descriptor,
-    //          including the kernel VMM (both GPT and VSL) 
-    /////////////////////////////////////////////////////////////////////////////////
-
-    // all cores get pointer on local cluster manager & core descriptor
-    cluster = &cluster_manager;
-    core    = &cluster->core_tbl[core_lid];
-
-    // all cores update the register(s) defining the kernel
-    // entry points for interrupts, exceptions and syscalls,
-    // this must be done before VFS initialisation, because 
-    // kernel_init() uses RPCs requiring IPIs...
-    hal_set_kentry();
-
-    // all cores initialize the idle thread descriptor
-    thread_idle_init( thread,
-                      THREAD_IDLE,
-                      &thread_idle_func,
-                      NULL,
-                      core_lid );
-
-    // core[0] initializes the process_zero descriptor,
-    if( core_lid == 0 ) process_zero_create( &process_zero , info );
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 3 : kernel processs initialized / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 4 : all cores initialize their private MMU 
-    //          core[0] in cluster 0 initializes the IOPIC device.
-    /////////////////////////////////////////////////////////////////////////////////
-
-    // all cores initialise their MMU
-    hal_mmu_init( &process_zero.vmm.gpt );
-
-    // core[0] in cluster[0] initializes the PIC chdev,
-    if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
-    
-    ////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    ////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 4 : MMU and IOPIC initialized / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-    ////////////////////////////////////////////////////////////////////////////////
-    // STEP 5 : core[0] initialize the distibuted LAPIC descriptor.
-    //          core[0] initialize the internal chdev descriptors
-    //          core[0] initialize the local external chdev descriptors
-    ////////////////////////////////////////////////////////////////////////////////
-
-    // all core[0]s initialize their local LAPIC extension,
-    if( core_lid == 0 ) lapic_init( info );
-
-    // core[0] scan the internal (private) peripherals,
-    // and allocates memory for the corresponding chdev descriptors.
-    if( core_lid == 0 ) internal_devices_init( info );
-
-    // All core[0]s contribute to initialise external peripheral chdev descriptors.
-    // Each core[0][cxy] scan the set of external (shared) peripherals (but the TXT0),
-    // and allocates memory for the chdev descriptors that must be placed
-    // on the (cxy) cluster according to the global index value.
-
-    if( core_lid == 0 ) external_devices_init( info );
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 5 : chdevs initialised / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-#if CONFIG_INSTRUMENTATION_CHDEVS
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-chdev_dir_display();
-#endif
-    
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 6 : All cores enable IPI (Inter Procesor Interrupt),
-    //          All cores unblock the idle thread, and register it in scheduler.
-    //          The core[0] in cluster defined by the CONFIG_VFS_ROOT_CXY parameter,
-    //          access the IOC device to initialize the VFS for the FS identified
-    //          by the CONFIG_VFS_ROOT_IS_*** parameter. It does the following
-    //          actions in the VFS_ROOT cluster :
-    //          1. allocate and initialize the selected FS context,
-    //          2. create and initializes the VFS root inodes,
-    //          3. initialize the VFS context for FATFS (in fs_context[] array),
-    //          4. create the <.> and <..> dentries in VFS root directory,
-    //          5. register the VFS root inode in process_zero descriptor, 
-    //          6. allocate the DEVFS context, 
-    //          7. initialize the VFS context for DEVFS (in fs_context[] array),
-    //          8. create the <dev> and <external> inodes,
-    //          9. initialize the DEVFS context.
-    /////////////////////////////////////////////////////////////////////////////////
-
-    // All cores enable IPI 
-    dev_pic_enable_ipi();
-    hal_enable_irq( &status );
-
-    // all cores unblock the idle thread, and register it in scheduler
-    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
-    core->scheduler.idle = thread;
-
-    // core[O] in VFS_ROOT cluster creates the VFS root
-    if( (core_lid ==  0) && (local_cxy == CONFIG_VFS_ROOT_CXY ) ) 
-    {
-        // Only FATFS is supported yet,
-        // TODO other File System can be introduced below
-        if( CONFIG_VFS_ROOT_IS_FATFS )
-        {
-            // 1. allocate memory and initialize FATFS context in VFS_ROOT cluster
-            xptr_t  fatfs_ctx_xp = fatfs_ctx_alloc( CONFIG_VFS_ROOT_CXY );
-
-            if( fatfs_ctx_xp == XPTR_NULL )
-            {
-                printk("\n[PANIC] in %s : cannot allocate FATFS context in cluster %x\n",
-                __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
-                hal_core_sleep();
-            }
-
-            // initialise FATFS context in VFS_ROOT cluster from IOC device (boot_record)
-            error = fatfs_ctx_init( fatfs_ctx_xp );
-
-            if( error )
-            {
-                printk("\n[PANIC] in %s : cannot initialize FATFS context in cluster %x\n",
-                __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
-                hal_core_sleep();
-            }
-
-#if( DEBUG_KERNEL_INIT & 1 )
-printk("\n[%s] initialized FATFS context in cluster %x\n",
-__FUNCTION__, CONFIG_VFS_ROOT_CXY );
-#endif
-    
-            // get various informations from FATFS context
-            fatfs_ctx_t * fatfs_ctx_ptr = GET_PTR( fatfs_ctx_xp );
-
-            uint32_t root_dir_cluster    = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
-                                           &fatfs_ctx_ptr->root_dir_cluster ) );
-
-            uint32_t bytes_per_sector    = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
-                                           &fatfs_ctx_ptr->bytes_per_sector ) );
- 
-            uint32_t sectors_per_cluster = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
-                                           &fatfs_ctx_ptr->sectors_per_cluster ) );
- 
-            uint32_t cluster_size        = bytes_per_sector * sectors_per_cluster;
- 
-            uint32_t fat_sectors_count   = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
-                                           &fatfs_ctx_ptr->fat_sectors_count ) ) << 7;
-
-            uint32_t total_clusters      = fat_sectors_count << 7;
- 
-            // 2. create VFS root inode in VFS_ROOT cluster
-            // TODO define attr, rights, uid, gid
-            error = vfs_inode_create( CONFIG_VFS_ROOT_CXY,          // target cluster
-                                      FS_TYPE_FATFS,                // fs_type
-                                      0,                            // attr
-                                      0,                            // rights
-                                      0,                            // uid
-                                      0,                            // gid
-                                      &vfs_root_inode_xp );         // return
-            if( error )
-            {
-                printk("\n[PANIC] in %s : cannot create VFS root inode in cluster %x\n",
-                __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
-                hal_core_sleep();
-            }
-
-#if( DEBUG_KERNEL_INIT & 1 )
-vfs_inode_t * root_inode = GET_PTR( vfs_root_inode_xp );
-printk("\n[%s] created </> root inode %x in cluster %x / ctx %x\n",
-__FUNCTION__, root_inode, CONFIG_VFS_ROOT_CXY, root_inode->ctx );
-#endif
-    
-            // update FATFS root inode "type" and "extend" fields  
-            vfs_inode_t * vfs_root_inode_ptr = GET_PTR( vfs_root_inode_xp );
-
-            hal_remote_s32( XPTR( CONFIG_VFS_ROOT_CXY , &vfs_root_inode_ptr->type ),
-                            FILE_TYPE_DIR );
-
-            hal_remote_spt( XPTR( CONFIG_VFS_ROOT_CXY , &vfs_root_inode_ptr->extend ), 
-                            (void*)(intptr_t)root_dir_cluster );
-
-            // 3. initialize the VFS context for FATFS in VFS_ROOT cluster
-            vfs_ctx_init( CONFIG_VFS_ROOT_CXY,                      // target cluster
-                          FS_TYPE_FATFS,                            // fs type
-	                      total_clusters,                           // number of clusters
-	                      cluster_size,                             // bytes
-	                      vfs_root_inode_xp,                        // VFS root
-                          fatfs_ctx_ptr );                          // extend
-
-#if( DEBUG_KERNEL_INIT & 1 )
-vfs_ctx_t * vfs_for_fatfs_ctx =  &fs_context[FS_TYPE_FATFS];
-printk("\n[%s] initialized VFS_for_FATFS context in cluster %x / ctx %x / fs_type %d\n",
-__FUNCTION__, CONFIG_VFS_ROOT_CXY, vfs_for_fatfs_ctx, vfs_for_fatfs_ctx->type );
-#endif
-        }
-        else
-        {
-            printk("\n[PANIC] in %s : unsupported VFS type in cluster %x\n",
-            __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
+            printk("PANIC in %s : Failed to initialize cluster manager in cluster %x\n",
+                   __FUNCTION__ , local_cxy );
             hal_core_sleep();
         }
 
-        // 4. create the <.> and <..> dentries in VFS root directory
-        // the VFS root parent inode is the VFS root inode itself 
-        vfs_add_special_dentries( vfs_root_inode_xp,
-                                  vfs_root_inode_xp );
-
-        // 5. register VFS root inode in target cluster process_zero descriptor 
-        hal_remote_s64( XPTR( CONFIG_VFS_ROOT_CXY , &process_zero.vfs_root_xp ),
-                        vfs_root_inode_xp );
-        hal_remote_s64( XPTR( CONFIG_VFS_ROOT_CXY , &process_zero.cwd_xp ),
-                        vfs_root_inode_xp );
-
-        // 6. allocate memory for DEVFS context in VFS_ROOT cluster
-        xptr_t devfs_ctx_xp = devfs_ctx_alloc( CONFIG_VFS_ROOT_CXY );
-
-        if( devfs_ctx_xp == XPTR_NULL )
+        // initialize process_zero descriptor
+		process_zero_init( info );
+
+        // initialize thread_zero descriptor
+	    memset( &thread_zero , 0 , sizeof(thread_t) );
+	    thread_zero.type     = THREAD_KERNEL;
+	    thread_zero.process  = &process_zero;
+	    hal_set_current_thread( &thread_zero );
+
+        // initialise local devices descriptors
+        devices_init( info );
+
+        // TODO initialize devFS and sysFS
+		// devfs_root_init();
+		// sysfs_root_init();
+
+		// TODO dire précisément ce qu'on fait ici [AG]
+		// hal_arch_init( info );
+
+        // TODO ??? [AG]
+		// clusters_sysfs_register();
+
+        // initialize virtual file system
+        // vfs_init();
+
+        // TODO ??? [AG]
+		// sysconf_init();
+
+        // activate other cores in same cluster
+		local_sync_init = KERNEL_INIT_SYNCRO;
+		hal_wbflush();
+    }
+    else   // other cores                                  
+    {
+        // other cores wait synchro from core[0]
+		while( local_sync_init != KERNEL_INIT_SYNCRO )
         {
-            printk("\n[PANIC] in %s : cannot create DEVFS context in cluster %x\n",
-            __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
-            hal_core_sleep();
+		   uint32_t retval = hal_time_stamp() + 1000;
+		   while( hal_time_stamp() < retval )  asm volatile ("nop");
         }
 
-        // 7. initialize the VFS context for DEVFS in VFS_ROOT cluster 
-        vfs_ctx_init( CONFIG_VFS_ROOT_CXY,                          // target cluster
-                      FS_TYPE_DEVFS,                                // fs type
-	                  0,                                            // total_clusters: unused
-	                  0,                                            // cluster_size: unused 
-	                  vfs_root_inode_xp,                            // VFS root
-                      GET_PTR( devfs_ctx_xp ) );                    // extend
-
-#if( DEBUG_KERNEL_INIT & 1 )
-vfs_ctx_t * vfs_for_devfs_ctx =  &fs_context[FS_TYPE_DEVFS];
-printk("\n[%s] initialized VFS_for_DEVFS context in cluster %x / ctx %x / fs_type %d\n",
-__FUNCTION__, CONFIG_VFS_ROOT_CXY, vfs_for_devfs_ctx, vfs_for_devfs_ctx->type );
-#endif
-
-        // 8. create "dev" and "external" inodes (directories)
-        devfs_global_init( vfs_root_inode_xp,
-                           &devfs_dev_inode_xp,
-                           &devfs_external_inode_xp );
-
-        // 9. initializes DEVFS context in VFS_ROOT cluster
-        devfs_ctx_init( devfs_ctx_xp,
-                        devfs_dev_inode_xp,
-                        devfs_external_inode_xp );
-    }
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == CONFIG_VFS_ROOT_CXY) ) 
-printk("\n[%s] exit barrier 6 : VFS root inode (%x) created in cluster (%x) / cycle %d\n",
-__FUNCTION__, GET_CXY(vfs_root_inode_xp), 
-GET_PTR(vfs_root_inode_xp), (uint32_t)hal_get_cycles() );
-#endif
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 7 : In all clusters other than the VFS_ROOT cluster, the core[0] makes
-    //          the following local actions to complete the VFS initialisation :
-    //          1. allocate a local context for the selected FS extension,
-    //          2. copy FS context from VFS_ROOT cluster to local cluster,
-    //          3. copy VFS_for_FATFS context from VFS_ROOT cluster to local cluster, 
-    //          4. allocate a local context for the DEVFS extension, 
-    //          5. copy DEVFS context from VFS_ROOT cluster to local cluster,
-    //          6. update the local "root_inode_xp" field in process_zero.
-    /////////////////////////////////////////////////////////////////////////////////
-
-    if( (core_lid ==  0) && (local_cxy != CONFIG_VFS_ROOT_CXY) ) 
-    {
-        // only FATFS is supported yet
-        // TODO other File System can be introduced below
-        if( CONFIG_VFS_ROOT_IS_FATFS )
-        {
-            // 1. allocate a local FATFS context extension
-            xptr_t local_fatfs_ctx_xp = fatfs_ctx_alloc( local_cxy );
-
-            if( local_fatfs_ctx_xp == XPTR_NULL )
-            {
-                printk("\n[PANIC] in %s : cannot create FATFS context in cluster %x\n",
-                __FUNCTION__ , local_cxy );
-                hal_core_sleep();
-            }
-
-            // get local pointer on VFS_for_FATFS context (same in all clusters) 
-            vfs_ctx_t * vfs_fat_ctx_ptr = &fs_context[FS_TYPE_FATFS];
-
-            // build extended pointer on VFS_for_FATFS "extend" field in VFS_ROOT cluster
-            xptr_t fatfs_extend_xp = XPTR( CONFIG_VFS_ROOT_CXY , &vfs_fat_ctx_ptr->extend );
-
-            // get local pointer on FATFS context in VFS_ROOT cluster 
-            fatfs_ctx_t * remote_fatfs_ctx_ptr = hal_remote_lpt( fatfs_extend_xp );
-
-            // build extended pointer on FATFS context in VFS_ROOT cluster
-            xptr_t remote_fatfs_ctx_xp = XPTR( CONFIG_VFS_ROOT_CXY , remote_fatfs_ctx_ptr );
-
-            // 2. copy FATFS context from VFS_ROOT cluster to local cluster
-            hal_remote_memcpy( local_fatfs_ctx_xp,
-                               remote_fatfs_ctx_xp,
-                               sizeof(fatfs_ctx_t) );
-
-            // build extended pointer on remote VFS_for_FATFS context
-            xptr_t remote_vfs_ctx_xp = XPTR( CONFIG_VFS_ROOT_CXY , vfs_fat_ctx_ptr );
-
-            // build extended pointer on local VFS_for_FATFS context
-            xptr_t local_vfs_ctx_xp = XPTR( local_cxy , vfs_fat_ctx_ptr );
- 
-            // 3. copy VFS_for_FATFS context from VFS_ROOT cluster to local cluster
-            hal_remote_memcpy( local_vfs_ctx_xp,
-                               remote_vfs_ctx_xp,
-                               sizeof(vfs_ctx_t) );
-
-            // update "extend" field in local VFS_for_FATFS context
-            vfs_fat_ctx_ptr->extend = GET_PTR( local_fatfs_ctx_xp );
-
-// check local FATFS and VFS context copies
-assert( __FUNCTION__, (((fatfs_ctx_t *)vfs_fat_ctx_ptr->extend)->sectors_per_cluster == 8),
-"illegal FATFS context" );
-
-        }
-        else
-        {
-            printk("\n[PANIC] in %s : unsupported VFS type in cluster %x\n",
-            __FUNCTION__ , local_cxy );
-            hal_core_sleep();
-        }
-
-        // 4. allocate a local DEVFS context extension, 
-        xptr_t local_devfs_ctx_xp = devfs_ctx_alloc( local_cxy );
-
-        // get local pointer on VFS_for_DEVFS context (same in all clusters) 
-        vfs_ctx_t * vfs_dev_ctx_ptr = &fs_context[FS_TYPE_DEVFS];
-
-        // build extended pointer on VFS_for_DEVFS extend field in VFS_ROOT cluster
-        xptr_t remote_extend_xp = XPTR( CONFIG_VFS_ROOT_CXY , &vfs_dev_ctx_ptr->extend );
-
-        // get local pointer on DEVFS context in VFS_ROOT cluster 
-        devfs_ctx_t * remote_devfs_ctx_ptr = hal_remote_lpt( remote_extend_xp );
-
-        // build extended pointer on FATFS context in VFS_ROOT cluster
-        xptr_t remote_devfs_ctx_xp = XPTR( CONFIG_VFS_ROOT_CXY , remote_devfs_ctx_ptr );
-
-        // 5. copy DEVFS context from VFS_ROOT cluster to local cluster
-        hal_remote_memcpy( local_devfs_ctx_xp,
-                           remote_devfs_ctx_xp,
-                           sizeof(devfs_ctx_t) );
-
-        // update "extend" field in local VFS_for_DEVFS context
-        vfs_dev_ctx_ptr->extend = GET_PTR( local_devfs_ctx_xp );
-
-        // get extended pointer on VFS root inode from VFS_ROOT cluster
-        vfs_root_inode_xp = hal_remote_l64( XPTR( CONFIG_VFS_ROOT_CXY,
-                                                  &process_zero.vfs_root_xp ) );
-
-        // 6. update local process_zero descriptor
-        process_zero.vfs_root_xp = vfs_root_inode_xp;
-        process_zero.cwd_xp      = vfs_root_inode_xp;
-    }
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 7 : VFS & DEVFS contexts replicated in all clusters / cycle %d\n",
-__FUNCTION__ , (uint32_t)hal_get_cycles() );
-#endif
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 8 : In all clusters in parallel, core[0] completes DEVFS initialization.
-    //          Each core[0] creates the local DEVFS "internal" directory,
-    //          and creates the pseudo-files for chdevs placed in local cluster.
-    /////////////////////////////////////////////////////////////////////////////////
-
+        // other cores initialise thread_zero descriptor 
+	    memset( &thread_zero , 0 , sizeof(thread_t) );
+	    thread_zero.type     = THREAD_KERNEL;
+	    thread_zero.process  = &process_zero;
+	    hal_set_current_thread( &thread_zero );
+    }
+
+
+    // each core get pointer on local cluster manager and on core descriptor
+    cluster = LOCAL_CLUSTER;
+  	core    = &cluster->core_tbl[core_lid];
+
+	// each core creates its private idle thread descriptor	
+	error = thread_kernel_create( &thread_idle,
+                                  THREAD_IDLE, 
+                                  &thread_idle_func, 
+                                  NULL,
+                                  core_lid );
+    if( error )
+	{
+		printk("ERROR in %s: failed to create idle thread for core %d in cluster %x\n",
+               __FUNCTION__ , core_lid , core_cxy );
+        hal_core_sleep();
+    }
+
+    // each core register thread_idle in scheduler 
+    core->scheduler.idle = thread_idle;
+
+    // each core register thread pointer in core hardware register
+    hal_set_current_thread( thread_idle );
+
+    kinit_dmsg("INFO %s  Created thread idle %x for core %d at cycle %d ]\n",
+               thread, hal_get_gid(), hal_time_stamp());
+
+    // global syncho for all core[0] in all clusters
     if( core_lid == 0 )
     {
-        // get local pointer on local DEVFS context
-        devfs_ctx_t * ctx = fs_context[FS_TYPE_DEVFS].extend;
-
-        // populate DEVFS in all clusters
-        devfs_local_init( ctx->dev_inode_xp,
-                          ctx->external_inode_xp );
-    }
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 8 : DEVFS initialized in all clusters / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-#if( DEBUG_KERNEL_INIT & 1 )
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-vfs_display( vfs_root_inode_xp );
-#endif
-
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 9 : core[0] in cluster 0 creates the first user process (process_init).
-    //          This include the process VMM (GPT and VSL) creation.
-    //          Finally, it prints the ALMOS-MKH banner.
-    /////////////////////////////////////////////////////////////////////////////////
-
-    if( (core_lid == 0) && (local_cxy == 0) ) 
-    {
-        process_init_create();
-    }
-
-#if DEBUG_KERNEL_INIT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] exit barrier 9 : process_init created in cluster 0 / cycle %d\n",
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
-
-    if( (core_lid == 0) && (local_cxy == 0) ) 
-    {
-        print_banner( (info->x_size * info->y_size) , info->cores_nr );
-    }
-
-#if CONFIG_INSTRUMENTATION_FOOTPRINT
-if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n\n***** memory fooprint for main kernel objects\n\n"
-                   " - thread descriptor  : %d bytes\n"
-                   " - process descriptor : %d bytes\n"
-                   " - cluster manager    : %d bytes\n"
-                   " - chdev descriptor   : %d bytes\n"
-                   " - core descriptor    : %d bytes\n"
-                   " - scheduler          : %d bytes\n"
-                   " - socket descriptor  : %d bytes\n"
-                   " - rpc fifo           : %d bytes\n"
-                   " - page descriptor    : %d bytes\n"
-                   " - mapper descriptor  : %d bytes\n"
-                   " - vseg descriptor    : %d bytes\n"
-                   " - ppm manager        : %d bytes\n"
-                   " - kcm manager        : %d bytes\n"
-                   " - vmm manager        : %d bytes\n"
-                   " - vfs inode          : %d bytes\n"
-                   " - vfs dentry         : %d bytes\n"
-                   " - vfs file           : %d bytes\n"
-                   " - vfs context        : %d bytes\n"
-                   " - xhtab root         : %d bytes\n"
-                   " - list item          : %d bytes\n"
-                   " - xlist item         : %d bytes\n"
-                   " - busylock           : %d bytes\n"
-                   " - remote busylock    : %d bytes\n"
-                   " - queuelock          : %d bytes\n"
-                   " - remote queuelock   : %d bytes\n"
-                   " - rwlock             : %d bytes\n"
-                   " - remote rwlock      : %d bytes\n",
-                   sizeof( thread_t           ),
-                   sizeof( process_t          ),
-                   sizeof( cluster_t          ),
-                   sizeof( chdev_t            ),
-                   sizeof( core_t             ),
-                   sizeof( scheduler_t        ),
-                   sizeof( socket_t           ),
-                   sizeof( remote_fifo_t      ),
-                   sizeof( page_t             ),
-                   sizeof( mapper_t           ),
-                   sizeof( vseg_t             ),
-                   sizeof( ppm_t              ),
-                   sizeof( kcm_t              ),
-                   sizeof( vmm_t              ),
-                   sizeof( vfs_inode_t        ),
-                   sizeof( vfs_dentry_t       ),
-                   sizeof( vfs_file_t         ),
-                   sizeof( vfs_ctx_t          ),
-                   sizeof( xhtab_t            ),
-                   sizeof( list_entry_t       ),
-                   sizeof( xlist_entry_t      ),
-                   sizeof( busylock_t         ),
-                   sizeof( remote_busylock_t  ),
-                   sizeof( queuelock_t        ),
-                   sizeof( remote_queuelock_t ),
-                   sizeof( rwlock_t           ),
-                   sizeof( remote_rwlock_t    ));
-#endif
-
-    // number of cycles per TICK (depends on the actual system clock frequency
-    uint32_t cycles_per_tick = cluster->sys_clk / CONFIG_SCHED_TICKS_PER_SECOND;
-
-    // each core activates its private TICK IRQ
-    dev_pic_enable_timer( cycles_per_tick );
-
-    /////////////////////////////////////////////////////////////////////////////////
-    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ),
-                                        (info->x_size * info->y_size) );
-    barrier_wait( &local_barrier , info->cores_nr );
-    /////////////////////////////////////////////////////////////////////////////////
-
-#if DEBUG_KERNEL_INIT 
-thread_t * this = CURRENT_THREAD;
-printk("\n[%s] : thread[%x,%x] on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
-__FUNCTION__ , this->process->pid, this->trdid,
-local_cxy, core_lid, (uint32_t)hal_get_cycles() );
-#endif
-
-    // each core jump to thread_idle_func
-    thread_idle_func();
-
-}  // end kernel_init()
-
+        remote_barrier( XPTR( info->io_cxy , &cluster->barrier ) , 
+                        (cluster->x_size * cluster->y_size) );
+    }
+
+    // local synchro for all cores in local cluster
+    remote_barrier( XPTR( local_cxy , &cluster->barrier ) , 
+                    cluster->cores_nr );
+
+    if( core_lid ==  0 )
+    {
+        kinit_dmsg("INFO %s completed for cluster %x at cycle %d\n",
+                   __FUNCTION__ , local_cxy , hal_time_stamp() );
+
+        if( local_cxy == info->io_cxy ) print_boot_banner();
+    }
+
+    // load idle thread context in calling core
+	hal_cpu_context_load( thread_idle );
+
+} // end kernel_init()
+
+
+
