Changeset 173 for soft/giet_vm/memo/src


Ignore:
Timestamp:
Jul 18, 2012, 4:59:19 PM (12 years ago)
Author:
karaoui
Message:

Adding BLOB type for vobj.
Don't forget to set as BLOB type the mapping_info vobj in the xml.

Location:
soft/giet_vm/memo/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/memo/src/libelfpp/elfpp_section.cc

    r163 r173  
    2323#include <stdlib.h>
    2424#include <cstring>
     25#include <stdlib.h>
     26
    2527
    2628#include <dpp/foreach>
     
    8183
    8284    size_ = size;
     85  }
     86
     87  void section::set_content(void* a)
     88  {
     89    if(content_)
     90        free(content_);
     91    content_ = (uint8_t*) a;
    8392  }
    8493
  • soft/giet_vm/memo/src/memo.cpp

    r165 r173  
    5151    PSeg::setPageSize(pageSize);
    5252
    53     load_bin(m_path);
     53    /* loading map_info blob */
     54    m_data = std::malloc(bin_size(m_path));
     55    if ( !m_data )
     56        throw exception::RunTimeError("malloc failed... No memory space");
     57
     58    m_size = load_bin(m_path, m_data);
     59
     60    /* checking signature */
     61    mapping_header_t*   header = (mapping_header_t*)m_data;
     62    //assert((IN_MAPPING_SIGNATURE == header->signature) and "wrong signature");
     63    if((IN_MAPPING_SIGNATURE != header->signature))
     64    {
     65        std::cout  << "wrong signature " << std::hex <<header->signature << ", should be:"<< IN_MAPPING_SIGNATURE << std::endl;
     66        exit(1);
     67    }
     68   
     69   
    5470
    5571#ifdef MOVER_DEBUG
     
    107123}
    108124
    109 //TODO:delete
    110 elfpp::section* MeMo::get_sect_by_name(elfpp::object *loader, std::string name)
    111 {
    112 #ifdef MOVER_DEBUG
    113     std::cout << "get_sect_by_name " << name << std::endl;
    114 #endif
    115     FOREACH( sect, loader->get_section_table() )
    116     {
    117         assert(&*sect != NULL);
    118         elfpp::sh_flags_e eflags = sect->get_flags();
    119         if ( !(eflags & elfpp::SHF_ALLOC) )
    120             continue;
    121 
    122 #ifdef MOVER_DEBUG
    123         std::cout << "Trying " << sect->get_name() << std::endl;
    124 #endif
    125         if(!(sect->get_name()).compare(name))
    126         {
    127             return (&*sect);
    128         }
    129     }
    130     return NULL;
    131 }
    132125
    133126void MeMo::buildSoft(const std::string &filename)
    134127{
    135128    if(!m_ginit)
    136         throw soclib::exception::RunTimeError(std::string("Can't get generator! ") );
     129        throw exception::RunTimeError(std::string("Can't get generator! ") );
    137130
    138131    m_generator->write(filename);
     
    140133}
    141134
     135/* Load the content of filename in buffer, and send the size */
     136////////////////////////////////////////////////////////
     137size_t MeMo::load_bin(std::string filename, void* buffer)
     138{
     139
     140#ifdef MOVER_DEBUG
     141    std::cout  << "Trying to load the binary blob from file '" << filename << "'" << std::endl;
     142#endif
     143
     144    std::ifstream input(filename.c_str(), std::ios_base::binary|std::ios_base::in);
     145
     146    if ( ! input.good() )
     147        throw exception::RunTimeError(std::string("Can't open the file: ") + filename);
     148
     149    input.seekg( 0, std::ifstream::end );
     150    size_t size = input.tellg();
     151    input.seekg( 0, std::ifstream::beg );
     152
     153    if ( !buffer )
     154        throw exception::RunTimeError("Empty buffer!");
     155
     156    input.read( (char*)buffer, size );
     157
     158    input.close();
     159
     160    return size;
     161}
     162
     163
     164/* get the size of the content of the filename */
    142165//////////////////////////////////////////
    143 void* MeMo::load_bin(std::string filename)
    144 {
    145    
    146 #ifdef MOVER_DEBUG
    147     std::cout  << "Trying to load the binary blob from file '" << m_path << "'" << std::endl;
    148 #endif
    149 
    150     std::ifstream input(m_path.c_str(), std::ios_base::binary|std::ios_base::in);
     166size_t MeMo::bin_size(std::string filename)
     167{
     168
     169#ifdef MOVER_DEBUG
     170    std::cout  << "Trying to get the size of the binary blob '" << filename << "'" << std::endl;
     171#endif
     172
     173    std::ifstream input(filename.c_str(), std::ios_base::binary|std::ios_base::in);
    151174
    152175    if ( ! input.good() )
    153         throw soclib::exception::RunTimeError(std::string("Can't open the file: ") + m_path);
     176        throw exception::RunTimeError(std::string("Can't open the file: ") + filename);
    154177
    155178    input.seekg( 0, std::ifstream::end );
    156     m_size = input.tellg();
     179    size_t size = input.tellg();
    157180    input.seekg( 0, std::ifstream::beg );
    158181
    159     //m_data = new void*[m_size];
    160     m_data = std::malloc(m_size);
    161     if ( !m_data )
    162         throw soclib::exception::RunTimeError("malloc failed... No memory space");
    163 
    164     input.read( (char*)m_data, m_size );
    165    
    166     return m_data;
    167 }
     182    input.close();
     183
     184    return size;
     185}
     186
    168187
    169188/////////////
     
    171190{
    172191    //std::cout << "Deleted MeMo " << *this << std::endl;
    173     std::free(m_data);
     192    //std::free(m_data);//should be done by the elfpp driver since we passed the pointer
    174193    std::map<std::string, elfpp::object*>::iterator l;
    175194    for(l = m_loaders.begin(); l != m_loaders.end(); l++)
     
    322341
    323342//////////////////////////////////////////
    324 void MeMo::vseg_map( mapping_vseg_t* vseg) 
    325 {
    326     mapping_vobj_t*     vobj   = get_vobj_base( (mapping_header_t*) m_data ); 
     343void MeMo::vseg_map( mapping_vseg_t* vseg)
     344{
     345    mapping_vobj_t*     vobj   = get_vobj_base( (mapping_header_t*) m_data );
    327346    PSeg *ps = &(m_psegh.get(vseg->psegid));// get physical segment pointer(PSegHandler::get)
    328347    elfpp::section* sect = NULL;
     
    343362    mapping_vobj_t* cur_vobj;
    344363    size_t simple_size = 0; //for debug
    345    
     364
    346365#ifdef MOVER_DEBUG
    347366    std::cout << "--------------------vseg_map "<< vseg->name <<"---------------------" << std::endl;
    348367#endif
    349    
     368
    350369    for ( size_t vobj_id = vseg->vobj_offset ; vobj_id < (vseg->vobj_offset + vseg->vobjs) ; vobj_id++ )
    351370    {
     
    353372
    354373#ifdef MOVER_DEBUG
    355         std::cout << "current vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")"
     374        std::cout << std::hex << "current vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")"
    356375                        << " size: "<< cur_vobj->length << " type: " <<  cur_vobj->type << std::endl;
    357376#endif
    358 
    359         if(cur_vobj->type == VOBJ_TYPE_ELF)
    360         {
    361             if(!first)
    362                 throw soclib::exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg"));
     377        if(cur_vobj->type == VOBJ_TYPE_BLOB)
     378        {
     379            size_t blob_size;
     380            std::string filePath(m_pathHandler.getFullPath(std::string(cur_vobj->binpath)));
     381
     382#ifdef MOVER_DEBUG
     383            std::cout << std::hex << "Handling: " << filePath << " ..." << std::endl;
     384#endif
     385
     386            if(!filePath.compare(m_path))    //local blob: map_info
     387            {
     388#ifdef MOVER_DEBUG
     389                std::cout << "Found the vseg of the mapping info" << std::endl;
     390#endif
     391                blob_size = this->m_size;
     392                assert((blob_size >0) and "MAPPING INFO file is empty !?");
     393            }
     394            else
     395            {
     396#ifdef MOVER_DEBUG
     397                std::cout << "Found an BLOB vseg" << std::endl;
     398#endif
     399                blob_size = bin_size(filePath);
     400            }
     401
     402
     403            /**creating a new section */
     404            sect = new elfpp::section(*m_generator, elfpp::SHT_PROGBITS);
     405
     406            sect->set_name(std::string(cur_vobj->name));
     407            sect->set_flags(elfpp::SHF_ALLOC | elfpp::SHF_WRITE);
     408            sect->set_size(blob_size);//do the malloc for the get_content fonction
     409
     410            assert(sect->get_content());//check allocation
     411
     412            if(!filePath.compare(m_path))    //local blob: map_info
     413                //memcpy(sect->get_content(), m_data, sect->get_size());
     414                /* this way the modification of the elf size are propageted to the giet */
     415                sect->set_content(this->m_data);
     416            else
     417                load_bin(filePath, sect->get_content());
     418
     419
     420            if(blob_size > cur_vobj->length)
     421            {
     422                std::cout << std::hex << "!!! Warning, specified blob type vobj ("<<
     423                cur_vobj->name  <<") size is "<< cur_vobj->length << ", the actual size is "
     424                << blob_size  << " !!!" <<std::endl;
     425                assert(0 and "blob vobj length smaller than the actual content" );//???
     426            }
     427
     428            cur_vobj->length = blob_size;//set the true size of this BLOB vobj
     429
     430            vSO->m_file = filePath;
     431            vSO->m_loadable = true;
     432        }
     433        else if(cur_vobj->type == VOBJ_TYPE_ELF)
     434        {
     435            if(!first)
     436                throw exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg"));
    363437
    364438            size_t elf_size;
     
    366440#ifdef MOVER_DEBUG
    367441            std::cout << "Handling: " << filePath << " ..." << std::endl;
    368 #endif
    369             if(!filePath.compare(m_path))    //local blob: map_info
     442            std::cout << "Found an ELF vseg" << std::endl;
     443#endif
     444            if(m_loaders.count(filePath) == 0 )
     445                m_loaders[filePath] = new elfpp::object(filePath);
     446            elfpp::object* loader = m_loaders[filePath];//TODO:free!?
     447
     448            sect =  get_sect_by_addr(loader, cur_vaddr);
     449            assert(sect and "No section found");
     450
     451            sect->set_name(std::string(cur_vobj->name));
     452
     453
     454            elf_size = sect->get_size();
     455            assert((elf_size > 0) and "ELF section empty ?");
     456
     457            if(!m_ginit)
    370458            {
    371 #ifdef MOVER_DEBUG
    372                 std::cout << "Found the vseg of the mapping info" << std::endl;
    373 #endif
    374                 /**creating a new section */
    375                 sect = new elfpp::section(*m_generator, elfpp::SHT_PROGBITS);
    376 
    377                 sect->set_name(std::string(cur_vobj->name));
    378                 sect->set_flags(elfpp::SHF_ALLOC | elfpp::SHF_WRITE);
    379                 sect->set_size(this->m_size);
    380                 sect->set_content(this->m_data);               
    381 
    382                 elf_size = this->m_size;       
    383                 assert((elf_size >0) and "MAPPING INFO file is empty !?");
     459                /** Initailising the header of the generator from the first binary,
     460                ** we suppose that the header is the same for all the binarys **/
     461                m_generator->copy_info(*loader);
     462                m_ginit=true;
    384463            }
    385             else
    386             {
    387 #ifdef MOVER_DEBUG
    388                 std::cout << "Found an ELF vseg" << std::endl;
    389 #endif
    390                 if(m_loaders.count(filePath) == 0 )
    391                     m_loaders[filePath] = new elfpp::object(filePath);
    392                 elfpp::object* loader = m_loaders[filePath];//TODO:free!?
    393 
    394                 //TODO: delete
    395                 //sect =  get_sect_by_name(loader, std::string(cur_vobj->name));
    396                 //assert(( sect->get_vaddr() == cur_vaddr) and "Vaddr doesn't match!");
    397 
    398                 sect =  get_sect_by_addr(loader, cur_vaddr);
    399                 assert(sect and "No section found");
    400 
    401                 sect->set_name(std::string(cur_vobj->name));
    402 
    403 
    404                 elf_size = sect->get_size();
    405                 assert((elf_size >0) and "ELF section empty ?");
    406 
    407                 if(!m_ginit)
    408                 {
    409                     /** Initailising the header of the generator from the first binary,
    410                     * we suppose that the header is the same for all the binarys
    411                     * */
    412                     m_generator->copy_info(*loader);
    413                     m_ginit=true;
    414                 }
    415             }
    416464
    417465            if(elf_size > cur_vobj->length)
     466            {
    418467                std::cout << "Warning, specified elf type vobj ("<<
    419468                cur_vobj->name  <<") size is "<< cur_vobj->length << ", the actual size is "
    420469                << elf_size  << std::endl;
     470                //assert((elf_size < cur_vobj->length) and "elf vobj length smaller than the actual content" );//???
     471                assert((0) and "elf vobj length smaller than the actual content" );//???
     472            }
    421473
    422474            cur_vobj->length = elf_size;//set the true size of this ELF vobj
    423475
    424476            vSO->m_file = filePath;
    425             vSO->m_loadable = true;       
    426         }
    427         first = false;
     477            vSO->m_loadable = true;
     478        }
    428479
    429480        //aligning the vobj->paddr if necessary
     481        //
    430482        if(cur_vobj->align)
    431483        {
     
    437489        cur_paddr += cur_vobj->length;
    438490        simple_size += cur_vobj->length;
     491        first = false;
    439492    }
    440493
     
    449502        std::cout << "vseg base "<< std::hex << ps->nextLma()
    450503        <<(ps->nextLma()+simple_size)  <<" size " << std::dec << simple_size <<
    451         std::endl; 
     504        std::endl;
    452505
    453506        std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma()
     
    456509    }
    457510#endif
    458      
    459     vSO->m_ident = vseg->ident;     
     511
     512    vSO->m_ident = vseg->ident;
    460513
    461514    //set the lma
     
    464517    else
    465518        ps->add( *vSO );
    466    
     519
    467520    if(!sect)
    468521        return;
     
    476529
    477530} // end vseg_map()
    478 
     531 
    479532
    480533///////////////////////////////
  • soft/giet_vm/memo/src/pseg.cpp

    r163 r173  
    208208                err << " Error" << error << " ,ovelapping Buffers:" << std::endl
    209209                    << *it << std::endl << m_vsegs[j] << std::endl;
    210                 throw soclib::exception::RunTimeError( err.str().c_str() );
     210                throw exception::RunTimeError( err.str().c_str() );
    211211            }
    212212
Note: See TracChangeset for help on using the changeset viewer.