Changeset 173 for soft/giet_vm/memo/src/memo.cpp
- Timestamp:
- Jul 18, 2012, 4:59:19 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/memo/src/memo.cpp
r165 r173 51 51 PSeg::setPageSize(pageSize); 52 52 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 54 70 55 71 #ifdef MOVER_DEBUG … … 107 123 } 108 124 109 //TODO:delete110 elfpp::section* MeMo::get_sect_by_name(elfpp::object *loader, std::string name)111 {112 #ifdef MOVER_DEBUG113 std::cout << "get_sect_by_name " << name << std::endl;114 #endif115 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_DEBUG123 std::cout << "Trying " << sect->get_name() << std::endl;124 #endif125 if(!(sect->get_name()).compare(name))126 {127 return (&*sect);128 }129 }130 return NULL;131 }132 125 133 126 void MeMo::buildSoft(const std::string &filename) 134 127 { 135 128 if(!m_ginit) 136 throw soclib::exception::RunTimeError(std::string("Can't get generator! ") );129 throw exception::RunTimeError(std::string("Can't get generator! ") ); 137 130 138 131 m_generator->write(filename); … … 140 133 } 141 134 135 /* Load the content of filename in buffer, and send the size */ 136 //////////////////////////////////////////////////////// 137 size_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 */ 142 165 ////////////////////////////////////////// 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);166 size_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); 151 174 152 175 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); 154 177 155 178 input.seekg( 0, std::ifstream::end ); 156 m_size = input.tellg();179 size_t size = input.tellg(); 157 180 input.seekg( 0, std::ifstream::beg ); 158 181 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 168 187 169 188 ///////////// … … 171 190 { 172 191 //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 174 193 std::map<std::string, elfpp::object*>::iterator l; 175 194 for(l = m_loaders.begin(); l != m_loaders.end(); l++) … … 322 341 323 342 ////////////////////////////////////////// 324 void MeMo::vseg_map( mapping_vseg_t* vseg) 325 { 326 mapping_vobj_t* vobj = get_vobj_base( (mapping_header_t*) m_data ); 343 void MeMo::vseg_map( mapping_vseg_t* vseg) 344 { 345 mapping_vobj_t* vobj = get_vobj_base( (mapping_header_t*) m_data ); 327 346 PSeg *ps = &(m_psegh.get(vseg->psegid));// get physical segment pointer(PSegHandler::get) 328 347 elfpp::section* sect = NULL; … … 343 362 mapping_vobj_t* cur_vobj; 344 363 size_t simple_size = 0; //for debug 345 364 346 365 #ifdef MOVER_DEBUG 347 366 std::cout << "--------------------vseg_map "<< vseg->name <<"---------------------" << std::endl; 348 367 #endif 349 368 350 369 for ( size_t vobj_id = vseg->vobj_offset ; vobj_id < (vseg->vobj_offset + vseg->vobjs) ; vobj_id++ ) 351 370 { … … 353 372 354 373 #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 << ")" 356 375 << " size: "<< cur_vobj->length << " type: " << cur_vobj->type << std::endl; 357 376 #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")); 363 437 364 438 size_t elf_size; … … 366 440 #ifdef MOVER_DEBUG 367 441 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) 370 458 { 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; 384 463 } 385 else386 {387 #ifdef MOVER_DEBUG388 std::cout << "Found an ELF vseg" << std::endl;389 #endif390 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: delete395 //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 binarys411 * */412 m_generator->copy_info(*loader);413 m_ginit=true;414 }415 }416 464 417 465 if(elf_size > cur_vobj->length) 466 { 418 467 std::cout << "Warning, specified elf type vobj ("<< 419 468 cur_vobj->name <<") size is "<< cur_vobj->length << ", the actual size is " 420 469 << 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 } 421 473 422 474 cur_vobj->length = elf_size;//set the true size of this ELF vobj 423 475 424 476 vSO->m_file = filePath; 425 vSO->m_loadable = true; 426 } 427 first = false; 477 vSO->m_loadable = true; 478 } 428 479 429 480 //aligning the vobj->paddr if necessary 481 // 430 482 if(cur_vobj->align) 431 483 { … … 437 489 cur_paddr += cur_vobj->length; 438 490 simple_size += cur_vobj->length; 491 first = false; 439 492 } 440 493 … … 449 502 std::cout << "vseg base "<< std::hex << ps->nextLma() 450 503 <<(ps->nextLma()+simple_size) <<" size " << std::dec << simple_size << 451 std::endl; 504 std::endl; 452 505 453 506 std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma() … … 456 509 } 457 510 #endif 458 459 vSO->m_ident = vseg->ident; 511 512 vSO->m_ident = vseg->ident; 460 513 461 514 //set the lma … … 464 517 else 465 518 ps->add( *vSO ); 466 519 467 520 if(!sect) 468 521 return; … … 476 529 477 530 } // end vseg_map() 478 531 479 532 480 533 ///////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.