Index: trunk/kernel/kern/kernel_init.c
===================================================================
--- trunk/kernel/kern/kernel_init.c	(revision 619)
+++ trunk/kernel/kern/kernel_init.c	(revision 623)
@@ -3,5 +3,5 @@
  *
  * Authors :  Mohamed Lamine Karaoui (2015)
- *            Alain Greiner  (2016,2017,2018)
+ *            Alain Greiner  (2016,2017,2018,2019)
  *
  * Copyright (c) Sorbonne Universites
@@ -113,5 +113,5 @@
 cxy_t                local_cxy                               CONFIG_CACHE_LINE_ALIGNED;
 
-// This variable is used for CP0 cores synchronisation in kernel_init()
+// This variable is used for core[0] cores synchronisation in kernel_init()
 __attribute__((section(".kdata")))
 xbarrier_t           global_barrier                          CONFIG_CACHE_LINE_ALIGNED;
@@ -126,5 +126,5 @@
 
 // kernel_init is the entry point defined in hal/tsar_mips32/kernel.ld
-// It is used by the bootloader.
+// It is used by the bootloader to tranfer control to kernel.
 extern void kernel_init( boot_info_t * info );
 
@@ -466,6 +466,6 @@
 // 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 CP0 core, that computes a global index
-// for all external chdevs. Each CP0 core creates only the chdevs that must be placed in 
+// This function is executed in all clusters by the core[0] core, 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.
@@ -626,5 +626,5 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////
-// This function is called by CP0 in cluster 0 to allocate memory and initialize the PIC
+// This function is called by core[0] in cluster 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).
@@ -791,5 +791,5 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////
-// This function is called by all CP0s in all cluster to complete the PIC device
+// 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 
@@ -899,9 +899,9 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 // This function is the entry point for the kernel initialisation.
-// It is executed by all cores in all clusters, but only core[0], called CP0,
-// initializes the shared resources such as the cluster manager, or the local peripherals.
+// It is executed by all cores in all clusters, but only core[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 CP0 in cluster 0 print the log messages.
+// Only core[0] in cluster 0 print the log messages.
 ///////////////////////////////////////////////////////////////////////////////////////////
 // @ info    : pointer on the local boot-info structure.
@@ -925,8 +925,8 @@
 
     /////////////////////////////////////////////////////////////////////////////////
-    // STEP 0 : Each core get its core identifier from boot_info, and makes 
+    // STEP 1 : Each core get its core identifier from boot_info, and makes 
     //          a partial initialisation of its private idle thread descriptor.
-    //          CP0 initializes the "local_cxy" global variable.
-    //          CP0 in cluster IO initializes the TXT0 chdev to print log messages.
+    //          core[0] initializes the "local_cxy" global variable.
+    //          core[0] in cluster[0] initializes the TXT0 chdev for log messages.
     /////////////////////////////////////////////////////////////////////////////////
 
@@ -936,5 +936,5 @@
                                   &core_gid );
 
-    // all CP0s initialize cluster identifier
+    // core[0] initialize cluster identifier
     if( core_lid == 0 ) local_cxy = info->cxy;
 
@@ -956,9 +956,17 @@
 #endif
 
-    // all CP0s initialize cluster info
+    // core[0] initializes cluster info
     if( core_lid == 0 ) cluster_info_init( info );
 
-    // CP0 in cluster 0 initialises TXT0 chdev descriptor
+    // 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();
+    }
 
     /////////////////////////////////////////////////////////////////////////////////
@@ -970,26 +978,17 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 0 : TXT0 initialized / cycle %d\n",
+printk("\n[%s] : exit barrier 1 : TXT0 initialized / cycle %d\n",
 __FUNCTION__, (uint32_t)hal_get_cycles() );
 #endif
 
-    /////////////////////////////////////////////////////////////////////////////
-    // STEP 1 : all cores check core identifier.
-    //          CP0 initializes the local cluster manager.
-    //          This includes the memory allocators.
-    /////////////////////////////////////////////////////////////////////////////
-
-    // 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();
-    }
-
-    // all CP0s initialise DQDT (only CPO in cluster 0 build the quad-tree)
+    /////////////////////////////////////////////////////////////////////////////////
+    // STEP 2 : core[0] initializes the cluter manager,
+    //          including the physical memory allocator. 
+    /////////////////////////////////////////////////////////////////////////////////
+
+    // core[0] initialises DQDT (only core[0] in cluster 0 build the quad-tree)
     if( core_lid == 0 ) dqdt_init();
     
-    // all CP0s initialize other cluster manager complex structures
+    // core[0] initialize other cluster manager complex structures
     if( core_lid == 0 )
     {
@@ -1012,11 +1011,11 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 1 : clusters initialised / cycle %d\n",
+printk("\n[%s] : exit barrier 2 : cluster manager initialized / cycle %d\n",
 __FUNCTION__, (uint32_t)hal_get_cycles() );
 #endif
 
     /////////////////////////////////////////////////////////////////////////////////
-    // STEP 2 : CP0 initializes the process_zero descriptor.
-    //          CP0 in cluster 0 initializes the IOPIC device.
+    // STEP 3 : core[0] initializes the process_zero descriptor,
+    //          including the kernel VMM (both GPT and VSL) 
     /////////////////////////////////////////////////////////////////////////////////
 
@@ -1025,8 +1024,28 @@
     core    = &cluster->core_tbl[core_lid];
 
-    // all CP0s initialize the process_zero descriptor
-    if( core_lid == 0 ) process_zero_create( &process_zero );
-
-    // CP0 in cluster 0 initializes the PIC chdev,
+    // 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 );
     
@@ -1039,24 +1058,24 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 2 : PIC initialised / cycle %d\n",
+printk("\n[%s] : exit barrier 4 : MMU and IOPIC initialized / cycle %d\n",
 __FUNCTION__, (uint32_t)hal_get_cycles() );
 #endif
 
     ////////////////////////////////////////////////////////////////////////////////
-    // STEP 3 : CP0 initializes the distibuted LAPIC descriptor.
-    //          CP0 initializes the internal chdev descriptors
-    //          CP0 initialize the local external chdev descriptors
+    // STEP 5 : core[0] initializes the distibuted LAPIC descriptor.
+    //          core[0] initializes the internal chdev descriptors
+    //          core[0] initialize the local external chdev descriptors
     ////////////////////////////////////////////////////////////////////////////////
 
-    // all CP0s initialize their local LAPIC extension,
+    // all core[0]s initialize their local LAPIC extension,
     if( core_lid == 0 ) lapic_init( info );
 
-    // CP0 scan the internal (private) peripherals,
+    // core[0] scan the internal (private) peripherals,
     // and allocates memory for the corresponding chdev descriptors.
     if( core_lid == 0 ) internal_devices_init( info );
         
 
-    // All CP0s contribute to initialise external peripheral chdev descriptors.
-    // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0),
+    // 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.
@@ -1072,5 +1091,5 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 3 : all chdevs initialised / cycle %d\n",
+printk("\n[%s] : exit barrier 5 : all chdevs initialised / cycle %d\n",
 __FUNCTION__, (uint32_t)hal_get_cycles() );
 #endif
@@ -1082,7 +1101,7 @@
     
     /////////////////////////////////////////////////////////////////////////////////
-    // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
+    // STEP 6 : All cores enable IPI (Inter Procesor Interrupt),
     //          Alh cores initialize IDLE thread.
-    //          Only CP0 in cluster 0 creates the VFS root inode.
+    //          Only core[0] in cluster[0] creates the VFS root inode.
     //          It access the boot device to initialize the file system context.
     /////////////////////////////////////////////////////////////////////////////////
@@ -1107,5 +1126,5 @@
 #endif
 
-    // CPO in cluster 0 creates the VFS root
+    // core[O] in cluster[0] creates the VFS root
     if( (core_lid ==  0) && (local_cxy == 0 ) ) 
     {
@@ -1137,5 +1156,4 @@
             // 4. create VFS root inode in cluster 0
             error = vfs_inode_create( FS_TYPE_FATFS,                       // fs_type
-                                      INODE_TYPE_DIR,                      // inode_type
                                       0,                                   // attr
                                       0,                                   // rights
@@ -1150,7 +1168,8 @@
             }
 
-            // 5. update FATFS root inode extension  
+            // 5. update FATFS root inode "type" and "extend" fields  
             cxy_t         vfs_root_cxy = GET_CXY( vfs_root_inode_xp );
             vfs_inode_t * vfs_root_ptr = GET_PTR( vfs_root_inode_xp );
+            hal_remote_s32( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ), INODE_TYPE_DIR );
             hal_remote_spt( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ), 
                             (void*)(intptr_t)root_dir_cluster );
@@ -1189,5 +1208,5 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 4 : VFS root (%x,%x) in cluster 0 / cycle %d\n",
+printk("\n[%s] : exit barrier 6 : VFS root (%x,%x) in cluster 0 / cycle %d\n",
 __FUNCTION__, GET_CXY(process_zero.vfs_root_xp),
 GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() );
@@ -1195,7 +1214,7 @@
 
     /////////////////////////////////////////////////////////////////////////////////
-    // STEP 5 : Other CP0s allocate memory for the selected FS context,
-    //          and initialise both the local FS context and the local VFS context
-    //          from values stored in cluster 0. 
+    // STEP 7 : In all other clusters than cluster[0], the core[0] allocates memory
+    //          for the selected FS context, and initialise the local FS context and 
+    //          the local VFS context from values stored in cluster 0. 
     //          They get the VFS root inode extended pointer from cluster 0.
     /////////////////////////////////////////////////////////////////////////////////
@@ -1259,5 +1278,5 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 1) ) 
-printk("\n[%s] : exit barrier 5 : VFS root (%x,%x) in cluster 1 / cycle %d\n",
+printk("\n[%s] : exit barrier 7 : VFS root (%x,%x) in cluster 1 / cycle %d\n",
 __FUNCTION__, GET_CXY(process_zero.vfs_root_xp),
 GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() );
@@ -1265,5 +1284,5 @@
 
     /////////////////////////////////////////////////////////////////////////////////
-    // STEP 6 : CP0 in cluster 0 makes the global DEVFS tree initialisation:
+    // STEP 8 : core[0] in cluster 0 makes the global DEVFS initialisation:
     //          It initializes the DEVFS context, and creates the DEVFS
     //          "dev" and "external" inodes in cluster 0.
@@ -1309,13 +1328,13 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 6 : DEVFS root initialized in cluster 0 / cycle %d\n",
+printk("\n[%s] : exit barrier 8 : DEVFS root initialized in cluster 0 / cycle %d\n",
 __FUNCTION__, (uint32_t)hal_get_cycles() );
 #endif
 
     /////////////////////////////////////////////////////////////////////////////////
-    // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
-    //          Each CP0 get the "dev" and "external" extended pointers from
+    // STEP 9 : All core[0]s complete in parallel the DEVFS initialization.
+    //          Each core[0] get the "dev" and "external" extended pointers from
     //          values stored in cluster 0. 
-    //          Then each CP0 in cluster(i) creates the DEVFS "internal" directory, 
+    //          Then each core[0] in cluster(i) creates the DEVFS "internal" directory, 
     //          and creates the pseudo-files for all chdevs in cluster (i).
     /////////////////////////////////////////////////////////////////////////////////
@@ -1346,33 +1365,23 @@
 #if DEBUG_KERNEL_INIT
 if( (core_lid ==  0) & (local_cxy == 0) ) 
-printk("\n[%s] : exit barrier 7 : DEV initialized in cluster 0 / cycle %d\n",
+printk("\n[%s] : exit barrier 9 : DEVFS initialized in cluster 0 / cycle %d\n",
 __FUNCTION__, (uint32_t)hal_get_cycles() );
 #endif
 
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 8 : CP0 in cluster 0 creates the first user process (process_init)
+#if( DEBUG_KERNEL_INIT & 1 )
+if( (core_lid ==  0) & (local_cxy == 0) ) 
+vfs_display( vfs_root_inode_xp );
+#endif
+
+    /////////////////////////////////////////////////////////////////////////////////
+    // STEP 10 : core[0] in cluster 0 creates the first user process (process_init).
+    //           This include the first user process VMM (GPT and VSL) creation.
+    //           Finally, it prints the ALMOS-MKH banner.
     /////////////////////////////////////////////////////////////////////////////////
 
     if( (core_lid == 0) && (local_cxy == 0) ) 
     {
-
-#if( DEBUG_KERNEL_INIT & 1 )
-vfs_display( vfs_root_inode_xp );
-#endif
-
        process_init_create();
     }
-
-    /////////////////////////////////////////////////////////////////////////////////
-    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 : process init created / cycle %d\n", 
-__FUNCTION__, (uint32_t)hal_get_cycles() );
-#endif
 
 #if (DEBUG_KERNEL_INIT & 1)
@@ -1381,13 +1390,11 @@
 #endif
 
-    /////////////////////////////////////////////////////////////////////////////////
-    // STEP 9 : CP0 in cluster 0 print banner
-    /////////////////////////////////////////////////////////////////////////////////
-    
     if( (core_lid == 0) && (local_cxy == 0) ) 
     {
         print_banner( (info->x_size * info->y_size) , info->cores_nr );
+    }
 
 #if( DEBUG_KERNEL_INIT & 1 )
+if( (core_lid ==  0) & (local_cxy == 0) ) 
 printk("\n\n***** memory fooprint for main kernel objects\n\n"
                    " - thread descriptor  : %d bytes\n"
@@ -1437,5 +1444,7 @@
 #endif
 
-    }
+    // each core updates the register(s) definig the kernel
+    // entry points for interrupts, exceptions and syscalls...
+    hal_set_kentry();
 
     // each core activates its private TICK IRQ
@@ -1448,5 +1457,5 @@
     /////////////////////////////////////////////////////////////////////////////////
 
-#if DEBUG_KERNEL_INIT
+#if( DEBUG_KERNEL_INIT & 1 )
 thread_t * this = CURRENT_THREAD;
 printk("\n[%s] : thread[%x,%x] on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
