Index: trunk/kernel/libk/elf.c
===================================================================
--- trunk/kernel/libk/elf.c	(revision 23)
+++ trunk/kernel/libk/elf.c	(revision 156)
@@ -33,5 +33,4 @@
 #include <syscalls.h>
 
-
 ///////////////////////////////////////////////////////////////////
 // This static function checks the .elf header.
@@ -41,32 +40,33 @@
 static bool_t elf_isValidHeader(Elf32_Ehdr *header)
 {
-	if((header->e_ident[EI_CLASS] == ELFCLASS32) 
-	   && (header->e_ident[EI_DATA] == ELFDATA2LSB) 
+	if((header->e_ident[EI_CLASS] == ELFCLASS32)
+	   && (header->e_ident[EI_DATA] == ELFDATA2LSB)
 	   && (header->e_ident[EI_VERSION] == EV_CURRENT)
 	   && (header->e_ident[EI_OSABI] == ELFOSABI_NONE)
-	   && ((header->e_machine == EM_MIPS) || 
+	   && ((header->e_machine == EM_MIPS) ||
 	       (header->e_machine == EM_MIPS_RS3_LE) ||
 	       (header->e_machine == EM_386))
-	   && (header->e_type == ET_EXEC))          return true;
-   
+	   && (header->e_type == ET_EXEC))
+		return true;
+
 	if( header->e_ident[EI_CLASS] != ELFCLASS32 )
-    printk("\n[ERROR] in %s : Elf is not 32-Binary\n", __FUNCTION__ );
+		printk("\n[ERROR] in %s : Elf is not 32-Binary\n", __FUNCTION__ );
 
 	if( header->e_ident[EI_DATA] != ELFDATA2LSB )
-    printk("\n[ERROR] in %s : Elf is not 2's complement, little endian\n", __FUNCTION__ );
-
-	if( header->e_ident[EI_VERSION] != EV_CURRENT ) 
-    printk("\n[ERROR] in %s : Elf is not in Current Version\n", __FUNCTION__);
+		printk("\n[ERROR] in %s : Elf is not 2's complement, little endian\n", __FUNCTION__ );
+
+	if( header->e_ident[EI_VERSION] != EV_CURRENT )
+		printk("\n[ERROR] in %s : Elf is not in Current Version\n", __FUNCTION__);
 
 	if( header->e_ident[EI_OSABI] != ELFOSABI_NONE )
-    printk("\n[ERROR] in %s : Unexpected Elf ABI, need UNIX System V ABI\n", __FUNCTION__ );
-
-	if( (header->e_machine == EM_MIPS) || 
-		(header->e_machine == EM_MIPS_RS3_LE) || 
-        (header->e_machine == EM_386) ) 
-	printk("\n[ERROR] in %s : unexpected core / accept only MIPS or 80386\n", __FUNCTION__ );
+		printk("\n[ERROR] in %s : Unexpected Elf ABI, need UNIX System V ABI\n", __FUNCTION__ );
+
+	if( (header->e_machine == EM_MIPS) ||
+	    (header->e_machine == EM_MIPS_RS3_LE) ||
+	    (header->e_machine == EM_386) )
+		printk("\n[ERROR] in %s : unexpected core / accept only MIPS or 80386\n", __FUNCTION__ );
 
 	if( header->e_type == ET_EXEC )
-	printk("\n[ERROR] in %s : Elf is not executable binary\n", __FUNCTION__ );
+		printk("\n[ERROR] in %s : Elf is not executable binary\n", __FUNCTION__ );
 
 	return false;
@@ -74,5 +74,5 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////
-// This function load the .elf header in the buffer allocated by the caller.
+// This function loads the .elf header in the buffer allocated by the caller.
 // @ file   : extended pointer on the remote file descriptor.
 // @ buffer : pointer on buffer allocated by the caller.
@@ -82,12 +82,12 @@
                                 void   * buffer,
                                 uint32_t size )
-{ 
-    uint32_t  count;
-
-    // load .elf header 
+{
+	uint32_t  count;
+
+	// load .elf header
 	count = vfs_move( true ,
-                      file_xp,
-                      buffer,
-                      size );
+	                  file_xp,
+	                  buffer,
+	                  size );
 
 	if( count != size )
@@ -97,6 +97,6 @@
 	}
 
-    Elf32_Ehdr * header = (Elf32_Ehdr *)buffer;
-    
+	Elf32_Ehdr * header = (Elf32_Ehdr *)buffer;
+
 	if( (header->e_ident[EI_MAG0] != ELFMAG0) ||
 	    (header->e_ident[EI_MAG1] != ELFMAG1) ||
@@ -114,5 +114,5 @@
 	}
 	return 0;
-}  // end elf_header_read()
+}
 
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -124,33 +124,34 @@
 ///////////////////////////////////////////////////////////////////////////////////////
 static error_t elf_segments_load( xptr_t       file_xp,
-				                  void       * segs_base,
+                                  void       * segs_base,
                                   uint32_t     nb_segs,
-				                  process_t  * process )
+                                  process_t  * process )
 {
 	error_t      error;
 	uint32_t     index;
 	uint32_t     file_size;
-    uint32_t     mem_size;
+	uint32_t     mem_size;
 	intptr_t     start;
 	uint32_t     type;
 	uint32_t     flags;
 	uint32_t     offset;
-    vseg_t     * vseg;
-
-    Elf32_Phdr * seg_ptr = (Elf32_Phdr *)segs_base;
-
-    // loop on segments
-	for( index = 0 ; index < nb_segs ; index++ , seg_ptr++ ) 
-	{   
-		if( seg_ptr->p_type != PT_LOAD) continue;
-    
-        // get segment attributes
+	vseg_t     * vseg;
+
+	Elf32_Phdr * seg_ptr = (Elf32_Phdr *)segs_base;
+
+	// loop on segments
+	for( index = 0 ; index < nb_segs ; index++ , seg_ptr++ )
+	{
+		if( seg_ptr->p_type != PT_LOAD)
+			continue;
+
+		// get segment attributes
 		start     = seg_ptr->p_vaddr;
-        offset    = seg_ptr->p_offset;
-        file_size = seg_ptr->p_filesz;
-        mem_size  = seg_ptr->p_memsz;
-        flags     = seg_ptr->p_flags;
-
-        // check alignment
+		offset    = seg_ptr->p_offset;
+		file_size = seg_ptr->p_filesz;
+		mem_size  = seg_ptr->p_memsz;
+		flags     = seg_ptr->p_flags;
+
+		// check alignment
 		if( start & CONFIG_PPM_PAGE_MASK )
 		{
@@ -159,6 +160,6 @@
 		}
 
-        // check size
-        if( file_size != mem_size )
+		// check size
+		if( file_size != mem_size )
 		{
 			printk("\n[WARNING] in %s : base = %x / mem_size = %x / file_size = %x\n",
@@ -166,9 +167,9 @@
 		}
 
-        // set seek on segment base in file
+		// set seek on segment base in file
 		error = vfs_lseek( file_xp,
-                           offset,
-                           SEEK_SET,
-                           NULL );
+		                   offset,
+		                   SEEK_SET,
+		                   NULL );
 
 		if( error )
@@ -180,24 +181,24 @@
 		if( flags & PF_X ) // found CODE segment
 		{
-            type                       = VSEG_TYPE_CODE;
+			type                       = VSEG_TYPE_CODE;
 			process->vmm.code_vpn_base = start >> CONFIG_PPM_PAGE_SHIFT;
 
 			elf_dmsg("\n[INFO] %s found CODE vseg / base = %x / size = %x\n",
-                     __FUNCTION__ , start , mem_size );
-		}
-		else                   // found DATA segment
-		{
-            type                       = VSEG_TYPE_DATA;
+			         __FUNCTION__ , start , mem_size );
+		}
+		else               // found DATA segment
+		{
+			type                       = VSEG_TYPE_DATA;
 			process->vmm.data_vpn_base = start >> CONFIG_PPM_PAGE_SHIFT;
 
 			elf_dmsg("\n[INFO] %s found DATA vseg / base = %x / size = %x\n",
-                     __FUNCTION__, start , mem_size );
-		}
-
-        // register vseg in VMM
-		vseg = (vseg_t *)vmm_create_vseg( process, 
-					                      start,
-					                      mem_size, 
-					                      type );
+			         __FUNCTION__, start , mem_size );
+		}
+
+		// register vseg in VMM
+		vseg = (vseg_t *)vmm_create_vseg( process,
+		                                  start,
+		                                  mem_size,
+		                                  type );
 		if( vseg == NULL )
 		{
@@ -211,5 +212,5 @@
 
 	return 0;
-} // end elf_load_segments()
+}
 
 ///////////////////////////////////////////////
@@ -217,53 +218,53 @@
                           process_t * process)
 {
-    char         path_copy[CONFIG_VFS_MAX_PATH_LENGTH];
+	char         path_copy[CONFIG_VFS_MAX_PATH_LENGTH];
 	kmem_req_t   req;              // kmem request for program header
 	uint32_t     length;           // actual path length
 	Elf32_Ehdr   header;           // local buffer for .elf header
 	void       * segs_base;        // pointer on buffer for segment descriptors array
-    uint32_t     segs_size;        // size of buffer for segment descriptors array  
+	uint32_t     segs_size;        // size of buffer for segment descriptors array
 	xptr_t       file_xp;          // extended pointer on created file descriptor
-    uint32_t     file_id;          // file descriptor index (unused)
-    uint32_t     count;            // bytes counter
+	uint32_t     file_id;          // file descriptor index (unused)
+	uint32_t     count;            // bytes counter
 	error_t      error;
 
-    // get path length from user space
+	// get path length from user space
 	length = hal_strlen_from_uspace( pathname );
 
-    if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
-    {
-        printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ );
-        return -1;
-    }
-
-    // make a local copy for pathname
-    hal_copy_from_uspace( path_copy , pathname , length+1 );
-
-    // open file
-    file_xp = XPTR_NULL;  // avoid GCC warning
-    file_id = -1;
-
-	error = vfs_open( process->vfs_cwd_xp, 
-                      path_copy,
-                      O_RDONLY,
-                      0,
-                      &file_xp,
-                      &file_id );
+	if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
+	{
+		printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ );
+		return -1;
+	}
+
+	// make a local copy for pathname
+	hal_copy_from_uspace( path_copy , pathname , length+1 );
+
+	// open file
+	file_xp = XPTR_NULL;  // avoid GCC warning
+	file_id = -1;
+
+	error = vfs_open( process->vfs_cwd_xp,
+	                  path_copy,
+	                  O_RDONLY,
+	                  0,
+	                  &file_xp,
+	                  &file_id );
 	if( error )
 	{
 		printk("\n[ERROR] in %s : failed to open executable file %s\n",
-               __FUNCTION__ , path_copy );
-		return -1;
-	}
-
-    // load header in local buffer
-	error = elf_header_read( file_xp , 
-                             &header,
-                             sizeof(Elf32_Ehdr) );
-	if( error ) 
-    {
-        vfs_close( file_xp , file_id );
-        return -1;
-    }
+		       __FUNCTION__ , path_copy );
+		return -1;
+	}
+
+	// load header in local buffer
+	error = elf_header_read( file_xp ,
+	                         &header,
+	                         sizeof(Elf32_Ehdr) );
+	if( error )
+	{
+		vfs_close( file_xp , file_id );
+		return -1;
+	}
 
 	elf_dmsg("\n[INFO] %s loaded elf header for %s\n", __FUNCTION__ , path_copy );
@@ -272,12 +273,12 @@
 	{
 		printk("\n[ERROR] in %s : no segments found\n", __FUNCTION__ );
-        vfs_close( file_xp , file_id );
-		return -1;
-	}
-
-    // compute buffer size for segment descriptors array
+		vfs_close( file_xp , file_id );
+		return -1;
+	}
+
+	// compute buffer size for segment descriptors array
 	segs_size = sizeof(Elf32_Phdr) * header.e_phnum;
-  
-    // allocate memory for segment descriptors array
+
+	// allocate memory for segment descriptors array
 	req.type  = KMEM_GENERIC;
 	req.size  = segs_size;
@@ -286,11 +287,11 @@
 
 	if( segs_base == NULL )
-    {
+	{
 		printk("\n[ERROR] in %s : no memory for segment descriptors\n", __FUNCTION__ );
-        vfs_close( file_xp , file_id );
-        return -1;
-    }
-
-    // set seek pointer in file descriptor to access segment descriptors array
+		vfs_close( file_xp , file_id );
+		return -1;
+	}
+
+	// set seek pointer in file descriptor to access segment descriptors array
 	error = vfs_lseek( file_xp , header.e_phoff, SEEK_SET , NULL );
 
@@ -298,22 +299,22 @@
 	{
 		printk("\n[ERROR] in %s : cannot seek for descriptors array\n", __FUNCTION__ );
-        vfs_close( file_xp , file_id );
-	    req.ptr = segs_base;
-	    kmem_free( &req );
-		return -1;
-	}
-
-    // load seg descriptors array to local buffer 
+		vfs_close( file_xp , file_id );
+		req.ptr = segs_base;
+		kmem_free( &req );
+		return -1;
+	}
+
+	// load seg descriptors array to local buffer
 	count = vfs_move( true,
-                      file_xp, 
-                      segs_base,
-                      segs_size );
+	                  file_xp,
+	                  segs_base,
+	                  segs_size );
 
 	if( count != segs_size )
 	{
 		printk("\n[ERROR] in %s : cannot read segments descriptors\n", __FUNCTION__ );
-        vfs_close( file_xp , file_id );
-	    req.ptr = segs_base;
-	    kmem_free( &req );
+		vfs_close( file_xp , file_id );
+		req.ptr = segs_base;
+		kmem_free( &req );
 		return -1;
 	}
@@ -321,31 +322,31 @@
 	elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , path_copy );
 
-    // register loadable segments in process VMM
-	error = elf_segments_load( file_xp, 
-                               segs_base,
-                               header.e_phnum,
-                               process );
+	// register loadable segments in process VMM
+	error = elf_segments_load( file_xp,
+	                           segs_base,
+	                           header.e_phnum,
+	                           process );
 	if( error )
-    {
-        vfs_close( file_xp , file_id );
-	    req.ptr = segs_base;
-	    kmem_free( &req );
-		return -1;
-    }
-
-    // register process entry point in VMM
+	{
+		vfs_close( file_xp , file_id );
+		req.ptr = segs_base;
+		kmem_free( &req );
+		return -1;
+	}
+
+	// register process entry point in VMM
 	process->vmm.entry_point = (intptr_t)header.e_entry;
 
-    // register extended pointer on .elf file descriptor 
-    process->vfs_bin_xp = file_xp;
-
-    // release allocated memory for program header
+	// register extended pointer on .elf file descriptor
+	process->vfs_bin_xp = file_xp;
+
+	// release allocated memory for program header
 	req.ptr = segs_base;
 	kmem_free(&req);
 
-	elf_dmsg("\n[INFO] %s successfully completed / entry point = %x for %s]\n", 
+	elf_dmsg("\n[INFO] %s successfully completed / entry point = %x for %s]\n",
 		 __FUNCTION__, (uint32_t) header.e_entry , path_copy );
 
 	return 0;
-}  // end elf_load_process()
-
+}
+
