Index: /trunk/softs/tsar_boot/conf/platform_fpga_de2-115/defs_platform.h
===================================================================
--- /trunk/softs/tsar_boot/conf/platform_fpga_de2-115/defs_platform.h	(revision 411)
+++ /trunk/softs/tsar_boot/conf/platform_fpga_de2-115/defs_platform.h	(revision 412)
@@ -7,8 +7,8 @@
 #define CACHE_LINE_SIZE 64//bytes
 
-#define INSTRUMENTATION 0
+#define BOOT_DEBUG      0
+#define BOOT_DEBUG_IOC  0
 
 #define IOC_BASE        0xFB000000
-#define VCIBD_BASE      0xFB000000
 #define TTY_BASE        0xFC000000
 #define ICU_BASE        0xFD000000
Index: /trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/defs_platform.h
===================================================================
--- /trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/defs_platform.h	(revision 411)
+++ /trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/defs_platform.h	(revision 412)
@@ -9,4 +9,3 @@
 #define ICU_BASE        0x00F00000
 #define IOC_BASE        0x00F10000
-#define VCIBD_BASE      IOC_BASE
 #define TTY_BASE        0x00F20000
Index: /trunk/softs/tsar_boot/include/boot_ioc.h
===================================================================
--- /trunk/softs/tsar_boot/include/boot_ioc.h	(revision 411)
+++ /trunk/softs/tsar_boot/include/boot_ioc.h	(revision 412)
@@ -15,5 +15,5 @@
 /**
  * boot_ioc_read()
- * 
+ *
  * Transfer data from a file on the block device to a memory buffer.
  *
Index: /trunk/softs/tsar_boot/src/boot_elf_loader.c
===================================================================
--- /trunk/softs/tsar_boot/src/boot_elf_loader.c	(revision 411)
+++ /trunk/softs/tsar_boot/src/boot_elf_loader.c	(revision 412)
@@ -37,8 +37,8 @@
     unsigned int i;
     unsigned int segment_req;
-   
+
     /*
      * Loader state machine definition
-     */  
+     */
     enum
     {
@@ -48,5 +48,20 @@
         ELF_SEGMENT_STATE,
         ELF_END_STATE
-    } init_state;
+    } init_state
+#if (BOOT_DEBUG ==1)
+    , init_state_debug
+#endif
+        ;
+
+#if (BOOT_DEBUG == 1)
+    char* init_state_str[] = {
+        "ELF_HEADER_STATE",
+        "ELF_PROGRAM_HEADER_STATE",
+        "ELF_OFFSET_STATE",
+        "ELF_SEGMENT_STATE",
+        "ELF_END_STATE"
+    };
+#endif
+
 
     boot_puts("Starting boot_elf_loader function...\n\r");
@@ -63,4 +78,7 @@
 
     init_state         = ELF_HEADER_STATE;
+#if (BOOT_DEBUG == 1)
+    init_state_debug   = ELF_END_STATE;
+#endif
 
     while(init_state != ELF_END_STATE)
@@ -88,4 +106,14 @@
         offset  +=  nb_read;
 
+#if (BOOT_DEBUG == 1)
+        if (init_state != init_state_debug)
+        {
+            boot_puts("init_state = ");
+            boot_puts(init_state_str[init_state]);
+            boot_puts("\n");
+            init_state_debug = init_state;
+        }
+#endif
+
         switch(init_state)
         {
@@ -113,12 +141,12 @@
                             "Input file does not use ELF format"
                             "\n"
-                        );  
+                        );
 
                         boot_exit();
                     }
 
-                    /* 
+                    /*
                      * Verification of Program Headers table size. It must be
-                     * smaller than the work size allocated for the 
+                     * smaller than the work size allocated for the
                      * elf_pht[PHDR_ARRAY_SIZE] array
                      **/
@@ -142,5 +170,5 @@
             /**
              * Reading ELF program headers
-             */  
+             */
             case ELF_PROGRAM_HEADER_STATE:
                 boot_memcpy(elf_pht_ptr, buffer_ptr, nb_read);
@@ -160,10 +188,41 @@
                         if(elf_pht_ptr[pseg].p_type == PT_LOAD)
                         {
-                            nb_rest = elf_pht_ptr[pseg].p_offset - offset;
+#if (BOOT_DEBUG == 1)
+                            boot_puts("found a loadable segment:\n");
+                            boot_puts("- type   : "); boot_putx(elf_pht_ptr[pseg].p_type);    boot_puts("\n");
+                            boot_puts("- offset : "); boot_putx(elf_pht_ptr[pseg].p_offset);  boot_puts("\n");
+                            boot_puts("- vaddr  : "); boot_putx(elf_pht_ptr[pseg].p_vaddr);   boot_puts("\n");
+                            boot_puts("- paddr  : "); boot_putx(elf_pht_ptr[pseg].p_paddr);   boot_puts("\n");
+                            boot_puts("- filesz : "); boot_putx(elf_pht_ptr[pseg].p_filesz);  boot_puts("\n");
+                            boot_puts("- memsz  : "); boot_putx(elf_pht_ptr[pseg].p_memsz);   boot_puts("\n");
+                            boot_puts("- flags  : "); boot_putx(elf_pht_ptr[pseg].p_flags);   boot_puts("\n");
+                            boot_puts("- align  : "); boot_putx(elf_pht_ptr[pseg].p_align);   boot_puts("\n");
+#endif
+                            if (elf_pht_ptr[pseg].p_offset < offset)
+                            {
+                                /* case where the segment to load includes the elf and program headers */
+                                nb_rest = elf_pht_ptr[pseg].p_filesz - offset;
+                                init_state = ELF_SEGMENT_STATE;
+                            }
+                            else
+                            {
+                                /* segment to load is further away in memory */
+                                nb_rest = elf_pht_ptr[pseg].p_offset - offset;
+                                init_state = ELF_OFFSET_STATE;
+                            }
                             break;
                         }
                     }
 
-                    init_state = ELF_OFFSET_STATE;
+                    if (pseg == elf_header_ptr->e_phnum)
+                    {
+                        boot_puts(
+                            "ERROR: "
+                            "No PT_LOAD found"
+                            "\n"
+                        );
+                        boot_exit();
+                    }
+
                 }
 
@@ -191,5 +250,5 @@
                  * Copying ELF segment data in memory segments using the virtual
                  * address got from the ELF file
-                 */ 
+                 */
                 segment_req = ((elf_pht_ptr[pseg].p_vaddr & 0xBFC00000) != 0xBFC00000);
 
@@ -201,5 +260,5 @@
                                 nb_read);
                 }
-    
+
                 nb_rest -= nb_read;
 
@@ -237,5 +296,5 @@
                     /*
                      * Program loading finished
-                     */ 
+                     */
                     if(pseg == elf_header_ptr->e_phnum)
                     {
Index: /trunk/softs/tsar_boot/src/boot_ioc.c
===================================================================
--- /trunk/softs/tsar_boot/src/boot_ioc.c	(revision 411)
+++ /trunk/softs/tsar_boot/src/boot_ioc.c	(revision 412)
@@ -21,5 +21,5 @@
 }
 
-#if INSTRUMENTATION
+#if (BOOT_DEBUG == 1 && BOOT_DEBUG_IOC == 1)
 inline unsigned int boot_proctime()
 {
@@ -28,5 +28,5 @@
     return ret;
 }
-#endif // end if INSTRUMENTATION
+#endif
 
 #ifndef SOCLIB_IOC
@@ -47,5 +47,5 @@
       SPI_TX_NEGEDGE,
       SPI_RX_POSEDGE
-    ); 
+    );
 
     /**
@@ -53,5 +53,5 @@
      */
     unsigned int iter = 0;
-    while(1) 
+    while(1)
     {
         boot_puts("Trying to initialize SD card... ");
@@ -118,8 +118,8 @@
 
 
-    unsigned int * ioc_address = ( unsigned int * )VCIBD_BASE;
-  
+    unsigned int * ioc_address = ( unsigned int * )IOC_BASE;
+
     while ( 1 )
-    { 
+    {
         status = ioread32(&ioc_address[BLOCK_DEVICE_STATUS]);
 
@@ -128,5 +128,5 @@
         break;
     }
-    
+
     return status;
 }
@@ -135,5 +135,5 @@
 /**
  * boot_ioc_read()
- * 
+ *
  * Transfer data from a file on the block device to a memory buffer.
  *
@@ -153,43 +153,7 @@
 {
 
-    unsigned int * ioc_address  = (unsigned int*)VCIBD_BASE;
-
-    // block_device configuration
-    iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER],
-            ( unsigned int ) buffer );
-
-    iowrite32( &ioc_address[BLOCK_DEVICE_COUNT],
-            ( unsigned int ) count );
-
-    iowrite32( &ioc_address[BLOCK_DEVICE_LBA],
-            ( unsigned int ) lba );
-
-    iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE],
-            ( unsigned int ) 0 );
-
-    iowrite32( &ioc_address[BLOCK_DEVICE_OP],
-            ( unsigned int ) BLOCK_DEVICE_READ );
-
-    _boot_ioc_completed();
-
-#if (CACHE_COHERENCE == 0)
-    boot_dbuf_invalidate(buffer, CACHE_LINE_SIZE, count * 512);
-#endif
-    return 0;
-}
-
-#else
-
-///////////////////////////////////////////////////////////////////////////////
-// FPGA version of the boot_ioc_read function
-
-int boot_ioc_read(unsigned int lba, void* buffer, unsigned int count)
-{
-    unsigned int sdcard_rsp;
-    unsigned int i;
-
-    sdcard_dev_lseek(&_sdcard_device, lba);
-
-#if INSTRUMENTATION
+    unsigned int * ioc_address  = (unsigned int*)IOC_BASE;
+
+#if (BOOT_DEBUG == 1 && BOOT_DEBUG_IOC == 1)
     unsigned int start_time;
     unsigned int end_time;
@@ -202,4 +166,60 @@
 #endif
 
+    // block_device configuration
+    iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER],
+            ( unsigned int ) buffer );
+
+    iowrite32( &ioc_address[BLOCK_DEVICE_COUNT],
+            ( unsigned int ) count );
+
+    iowrite32( &ioc_address[BLOCK_DEVICE_LBA],
+            ( unsigned int ) lba );
+
+    iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE],
+            ( unsigned int ) 0 );
+
+    iowrite32( &ioc_address[BLOCK_DEVICE_OP],
+            ( unsigned int ) BLOCK_DEVICE_READ );
+
+    _boot_ioc_completed();
+
+#if (CACHE_COHERENCE == 0)
+    boot_dbuf_invalidate(buffer, CACHE_LINE_SIZE, count * 512);
+#endif
+
+#if (BOOT_DEBUG == 1 && BOOT_DEBUG_IOC == 1)
+    end_time = boot_proctime();
+
+    boot_puts(" / cycles for transfert: ");
+    boot_putd(end_time - start_time);
+    boot_puts("\n");
+#endif
+
+    return 0;
+}
+
+#else
+
+///////////////////////////////////////////////////////////////////////////////
+// FPGA version of the boot_ioc_read function
+
+int boot_ioc_read(unsigned int lba, void* buffer, unsigned int count)
+{
+    unsigned int sdcard_rsp;
+    unsigned int i;
+
+    sdcard_dev_lseek(&_sdcard_device, lba);
+
+#if (BOOT_DEBUG ==1 && BOOT_DEBUG_IOC == 1)
+    unsigned int start_time;
+    unsigned int end_time;
+    boot_puts("[ DEBUG ] Reading blocks ");
+    boot_putd(lba);
+    boot_puts(" to ");
+    boot_putd(lba + count - 1);
+
+    start_time = boot_proctime();
+#endif
+
     for(i = 0; i < count; i++)
     {
@@ -208,8 +228,8 @@
                         (unsigned char *) buffer + (512 * i),
                         512
-                        ) 
+                        )
             ))
         {
-            boot_puts("ERROR during read on the SDCARD device. Code: "); 
+            boot_puts("ERROR during read on the SDCARD device. Code: ");
             boot_putx(sdcard_rsp);
             boot_puts("\n\r");
@@ -219,5 +239,5 @@
     }
 
-#if INSTRUMENTATION
+#if (BOOT_DEBUG == 1 && BOOT_DEBUG_IOC == 1)
     end_time = boot_proctime();
 
@@ -234,5 +254,5 @@
  * _dcache_buf_invalidate()
  *
- * Invalidate all data cache lines corresponding to a memory 
+ * Invalidate all data cache lines corresponding to a memory
  * buffer (identified by an address and a size).
  */
@@ -245,5 +265,5 @@
     unsigned int i;
 
-    // iterate on cache lines 
+    // iterate on cache lines
     for (i = 0; i < size; i += line_size) {
         asm volatile(
