Index: soft/giet_vm/mover/src/mover.cpp
===================================================================
--- soft/giet_vm/mover/src/mover.cpp	(revision 160)
+++ soft/giet_vm/mover/src/mover.cpp	(revision 161)
@@ -5,9 +5,9 @@
  * This file is part of SoCLib, GNU LGPLv2.1.
  * 
- * SoCLib is free software; you can redistribute vs and/or modify vs
+ * SoCLib is free software; you can redistribute vSO and/or modify vSO
  * under the terms of the GNU Lesser General Public License as published
  * by the Free Software Foundation; version 2.1 of the License.
  * 
- * SoCLib is distributed in the hope that vs will be useful, but
+ * SoCLib is distributed in the hope that vSO will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
@@ -40,20 +40,18 @@
 
 
-//#define MOVER_DEBUG
+#define MOVER_DEBUG
 
 Mover::Mover( const std::string &filename, 
         const size_t pageSize)
         :m_path(filename),
-        m_pathh(filename),
+        m_pathHandler(filename),
         m_ginit(false),
         m_generator(new elfpp::object())
 {
-    //m_generator = new elfpp::object();
-    
-    //m_pathh = 
- 
+    
     PSeg::setPageSize(pageSize);
 
     load_bin(m_path);
+
 #ifdef MOVER_DEBUG
     std::cout << "Binary file path: " << m_path << std::endl;
@@ -94,4 +92,5 @@
 }
 
+//TODO:delete
 elfpp::section* Mover::get_sect_by_addr(elfpp::object *loader, unsigned int addr)
 {
@@ -103,4 +102,26 @@
             continue;
         if(sect->get_load_address() == addr) //load_addr ?
+        {
+            return (&*sect);
+        }
+    }
+    return NULL;
+}
+elfpp::section* Mover::get_sect_by_name(elfpp::object *loader, std::string name)
+{
+#ifdef MOVER_DEBUG
+    std::cout << "get_sect_by_name " << name << std::endl;
+#endif
+    FOREACH( sect, loader->get_section_table() )
+    {
+        assert(&*sect != NULL);
+        elfpp::sh_flags_e eflags = sect->get_flags();
+        if ( !(eflags & elfpp::SHF_ALLOC) )
+            continue;
+
+#ifdef MOVER_DEBUG
+        std::cout << "Trying " << sect->get_name() << std::endl;
+#endif
+        if(!(sect->get_name()).compare(name)) 
         {
             return (&*sect);
@@ -208,4 +229,5 @@
     mapping_vspace_t*	vspace  = get_vspace_base ( header );;
     mapping_vseg_t*	    vseg    = get_vseg_base ( header );
+    mapping_vobj_t*	    vobj    = get_vobj_base ( header );
 
     // header
@@ -240,16 +262,14 @@
          << " + ident = " << (bool)vseg[vseg_id].ident << std::endl 
          << " + psegname" << pseg[vseg[vseg_id].psegid].name << std::endl;
-        //TODO print vobjs
-        /*
-        for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ )
-        {
-            _tty_printf("\t vobjs     = \"%s\"\n",     vobj[vobj_id].name);
-            _tty_printf("\t name     = \"%s\"\n",     vobj[vobj_id].name);
-            _tty_printf("\t type     = \"%s\" \n", vobj[vobj_id].type);
-            _tty_printf("\t length   = \"0x%x\" \n",   vobj[vobj_id].length);
-            _tty_printf("\t align    = \"%d\" \n",   vobj[vobj_id].align);
-            _tty_printf("\t binpath  = \"%s\" \n",   vobj[vobj_id].binpath);
-            _tty_printf("\t \n");
-        }*/
+        for(size_t vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ )
+        {
+            std::cout << "\t vobjs     = "<<     vobj[vobj_id].name << std::endl;
+            std::cout<<"\t name     =" << vobj[vobj_id].name <<std::endl;
+            std::cout<<"\t type     =" << vobj[vobj_id].type <<std::endl;
+            std::cout<<"\t length   =" << vobj[vobj_id].length <<std::endl;
+            std::cout<<"\t align    =" << vobj[vobj_id].align <<std::endl;
+            std::cout<<"\t binpath  =" << vobj[vobj_id].binpath <<std::endl;
+            std::cout<<"\t \n";
+        }
     }
 
@@ -274,16 +294,13 @@
              << " + ident = " <<  (bool)vseg[vseg_id].ident  << std::endl
              << " + psegname = " << pseg[vseg[vseg_id].psegid].name  << std::endl << std::endl;
-        //TODO print vobjs
-        /*
-            for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ )
+            for(size_t vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ )
             {
-                _tty_printf("\t\t vobjs     = \"%s\"\n",     vobj[vobj_id].name);
-                _tty_printf("\t\t name     = \"%s\"\n",     vobj[vobj_id].name);
-                _tty_printf("\t\t type     = \"%s\" \n", vobj[vobj_id].type);
-                _tty_printf("\t\t length   = \"0x%x\" \n",   vobj[vobj_id].length);
-                _tty_printf("\t\t align    = \"%d\" \n",   vobj[vobj_id].align);
-                _tty_printf("\t\t binpath  = \"%s\" \n\n",   vobj[vobj_id].binpath);
+                std::cout<<"\t\t vobjs     =" << vobj[vobj_id].name <<std::endl;
+                std::cout<<"\t\t name     =" << vobj[vobj_id].name <<std::endl;
+                std::cout<<"\t\t type     =" << vobj[vobj_id].type <<std::endl;
+                std::cout<<"\t\t length   =" << vobj[vobj_id].length <<std::endl;
+                std::cout<<"\t\t align    =" << vobj[vobj_id].align <<std::endl;
+                std::cout<<"\t\t binpath  =" << vobj[vobj_id].binpath <<std::endl;
             }
-        */
         }
 
@@ -311,20 +328,18 @@
     bool aligned = false;
 
-    VSeg     * vs = new VSeg;
-    std::string s(vseg->name);
-    vs->m_name = s;
-
-    vs->m_vma = vseg->vbase;
+    VSeg   *vSO = new VSeg;
+
+    vSO->m_name = std::string(vseg->name);
+    vSO->m_vma = vseg->vbase;
+    vSO->m_lma = ps->nextLma();
 
     cur_vaddr = vseg->vbase;
     cur_paddr = ps->nextLma();
-    
-    vs->m_length = 0;
+
     mapping_vobj_t* cur_vobj;
-
     size_t simple_size = 0; //for debug
     
 #ifdef MOVER_DEBUG
-    std::cout << "--------------------vseg_map---------------------" << std::endl;
+    std::cout << "--------------------vseg_map "<< vseg->name <<"---------------------" << std::endl;
 #endif
     
@@ -334,66 +349,76 @@
 
 #ifdef MOVER_DEBUG
-        std::cout << "cur vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")" 
-                        << " size "<< cur_vobj->length << " type " <<  cur_vobj->type << std::endl;
+        std::cout << "current vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")" 
+                        << " size: "<< cur_vobj->length << " type: " <<  cur_vobj->type << std::endl;
 #endif
 
         if(cur_vobj->type == ELF)
         {
-
             if(!first) 
                 throw soclib::exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg"));
 
-            std::string f(m_pathh.getFullName(std::string(cur_vobj->binpath)));
             size_t elf_size;
-#ifdef MOVER_DEBUG
-            std::cout << "Handling: " << f << " ..." << std::endl;
-#endif
-            if(!f.compare(m_path))    //local blob: map_info
+            std::string filePath(m_pathHandler.getFullPath(std::string(cur_vobj->binpath)));
+#ifdef MOVER_DEBUG
+            std::cout << "Handling: " << filePath << " ..." << std::endl;
+#endif
+            if(!filePath.compare(m_path))    //local blob: map_info
             {
-                /**creating a new session */
+#ifdef MOVER_DEBUG
+                std::cout << "Found the vseg of the mapping info" << std::endl;
+#endif
+                /**creating a new section */
                 sect = new elfpp::section(*m_generator, elfpp::SHT_PROGBITS);
 
-                sect->set_name(std::string("seg_mapping_info"));
+                sect->set_name(std::string(cur_vobj->name));
                 sect->set_flags(elfpp::SHF_ALLOC | elfpp::SHF_WRITE);
                 sect->set_size(this->m_size);
-
-                sect->set_content(m_data);                
+                sect->set_content(this->m_data);                
 
                 elf_size = this->m_size;       
-                assert((elf_size >0) and "MAPINFO file empty !?");
+                assert((elf_size >0) and "MAPPING INFO file is empty !?");
             }
             else
             { 
 #ifdef MOVER_DEBUG
-                std::cout << "ELF vseg found " << std::endl;
-#endif
-                if(m_loaders.count(f) == 0 )
-                    m_loaders[f] = new elfpp::object(f);
-                elfpp::object* loader = m_loaders[f];
-                //elfpp::object* loader = (new elfpp::object(f));//TODO:free!
-
+                std::cout << "Found an ELF vseg" << std::endl;
+#endif
+                if(m_loaders.count(filePath) == 0 )
+                    m_loaders[filePath] = new elfpp::object(filePath);
+                elfpp::object* loader = m_loaders[filePath];//TODO:free!?
+
+                //sect =  get_sect_by_name(loader, std::string(cur_vobj->name));
+                //assert(( sect->get_vaddr() == cur_vaddr) and "Vaddr doesn't match!");
                 sect =  get_sect_by_addr(loader, cur_vaddr);
                 assert(sect and "No section found");
 
+                sect->set_name(std::string(cur_vobj->name));
+
                 elf_size = sect->get_size();
-
                 assert((elf_size >0) and "ELF section empty ?");
+
                 if(!m_ginit)
                 {
-                    //we suppose the header is the same for the all the bins
+                    /** Initailising the header of the generator from the first binary
+                    * we suppose the header is the same for all the binarys
+                    * */
                     m_generator->copy_info(*loader);
                     m_ginit=true;
                 }
             }
-            cur_vobj->length = elf_size;//set the actual size
+
             if(elf_size > cur_vobj->length)
-               std::cout << "Warning, specified elf type vobj ("<< cur_vobj->name  <<") size is "<< cur_vobj->length
-                         << ", the actual size is "  << elf_size  << std::endl;
-
-            vs->m_file = f;
-            vs->m_loadable = true;        
+                std::cout << "Warning, specified elf type vobj ("<<
+                cur_vobj->name  <<") size is "<< cur_vobj->length << ", the actual size is "
+                << elf_size  << std::endl;
+
+            cur_vobj->length = elf_size;//set the true size of this ELF vobj
+
+            vSO->m_file = filePath;
+            vSO->m_loadable = true;        
         }
         first = false;
 
+        //aligning the vobj->paddr if necessary
         if(cur_vobj->align)
         {
@@ -401,5 +426,4 @@
             aligned = true;
         }
-
 
         cur_vaddr += cur_vobj->length;
@@ -411,28 +435,32 @@
     assert((cur_paddr >= ps->nextLma() ));
 
-    vs->m_length = (cur_paddr - ps->nextLma()); //pageAlign is done by the psegs
+    vSO->m_length = (cur_paddr - ps->nextLma()); //pageAlign is done by the psegs
 
 #ifdef MOVER_DEBUG
     if(aligned)
     {
-        std::cout << "vseg base "<< std::hex << ps->nextLma() <<(ps->nextLma()+simple_size)  <<" size " << std::dec << simple_size << std::endl;
-        std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma() 
-            <<" to "<< std::hex << ps->nextLma()+vs->m_length<< " size " << std::dec << vs->m_length << std::endl;
+        std::cout << "vseg base "<< std::hex << ps->nextLma()
+        <<(ps->nextLma()+simple_size)  <<" size " << std::dec << simple_size <<
+        std::endl; 
+
+        std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma()
+        <<" to "<< std::hex << ps->nextLma()+vSO->m_length<< " size " << std::dec <<
+        vSO->m_length << std::endl;
     }
 #endif
      
-    vs->m_ident = vseg->ident;      
+    vSO->m_ident = vseg->ident;      
 
     //set the lma
     if ( vseg->ident != 0 )            // identity mapping required
-        ps->addIdent( *vs );
+        ps->addIdent( *vSO );
     else
-        ps->add( *vs );
+        ps->add( *vSO );
     
     if(!sect)
         return;
 
-    //std::cout << "section: "<< *sect <<"\n seted to: " << (*vs) << std::endl;
-    sect->set_vaddr((*vs).lma());
+    //std::cout << "section: "<< *sect <<"\n seted to: " << (*vSO) << std::endl;
+    sect->set_vaddr((*vSO).lma());
     m_generator->add_section(*(new elfpp::section(*sect)));
 
