Changeset 161 for soft/giet_vm/mover/src/mover.cpp
- Timestamp:
- Jun 20, 2012, 9:50:34 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/mover/src/mover.cpp
r160 r161 5 5 * This file is part of SoCLib, GNU LGPLv2.1. 6 6 * 7 * SoCLib is free software; you can redistribute v s and/or modify vs7 * SoCLib is free software; you can redistribute vSO and/or modify vSO 8 8 * under the terms of the GNU Lesser General Public License as published 9 9 * by the Free Software Foundation; version 2.1 of the License. 10 10 * 11 * SoCLib is distributed in the hope that v swill be useful, but11 * SoCLib is distributed in the hope that vSO will be useful, but 12 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 40 40 41 41 42 //#define MOVER_DEBUG42 #define MOVER_DEBUG 43 43 44 44 Mover::Mover( const std::string &filename, 45 45 const size_t pageSize) 46 46 :m_path(filename), 47 m_path h(filename),47 m_pathHandler(filename), 48 48 m_ginit(false), 49 49 m_generator(new elfpp::object()) 50 50 { 51 //m_generator = new elfpp::object(); 52 53 //m_pathh = 54 51 55 52 PSeg::setPageSize(pageSize); 56 53 57 54 load_bin(m_path); 55 58 56 #ifdef MOVER_DEBUG 59 57 std::cout << "Binary file path: " << m_path << std::endl; … … 94 92 } 95 93 94 //TODO:delete 96 95 elfpp::section* Mover::get_sect_by_addr(elfpp::object *loader, unsigned int addr) 97 96 { … … 103 102 continue; 104 103 if(sect->get_load_address() == addr) //load_addr ? 104 { 105 return (&*sect); 106 } 107 } 108 return NULL; 109 } 110 elfpp::section* Mover::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)) 105 126 { 106 127 return (&*sect); … … 208 229 mapping_vspace_t* vspace = get_vspace_base ( header );; 209 230 mapping_vseg_t* vseg = get_vseg_base ( header ); 231 mapping_vobj_t* vobj = get_vobj_base ( header ); 210 232 211 233 // header … … 240 262 << " + ident = " << (bool)vseg[vseg_id].ident << std::endl 241 263 << " + psegname" << pseg[vseg[vseg_id].psegid].name << std::endl; 242 //TODO print vobjs 243 /* 244 for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ ) 245 { 246 _tty_printf("\t vobjs = \"%s\"\n", vobj[vobj_id].name); 247 _tty_printf("\t name = \"%s\"\n", vobj[vobj_id].name); 248 _tty_printf("\t type = \"%s\" \n", vobj[vobj_id].type); 249 _tty_printf("\t length = \"0x%x\" \n", vobj[vobj_id].length); 250 _tty_printf("\t align = \"%d\" \n", vobj[vobj_id].align); 251 _tty_printf("\t binpath = \"%s\" \n", vobj[vobj_id].binpath); 252 _tty_printf("\t \n"); 253 }*/ 264 for(size_t vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ ) 265 { 266 std::cout << "\t vobjs = "<< vobj[vobj_id].name << std::endl; 267 std::cout<<"\t name =" << vobj[vobj_id].name <<std::endl; 268 std::cout<<"\t type =" << vobj[vobj_id].type <<std::endl; 269 std::cout<<"\t length =" << vobj[vobj_id].length <<std::endl; 270 std::cout<<"\t align =" << vobj[vobj_id].align <<std::endl; 271 std::cout<<"\t binpath =" << vobj[vobj_id].binpath <<std::endl; 272 std::cout<<"\t \n"; 273 } 254 274 } 255 275 … … 274 294 << " + ident = " << (bool)vseg[vseg_id].ident << std::endl 275 295 << " + psegname = " << pseg[vseg[vseg_id].psegid].name << std::endl << std::endl; 276 //TODO print vobjs 277 /* 278 for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ ) 296 for(size_t vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ ) 279 297 { 280 _tty_printf("\t\t vobjs = \"%s\"\n", vobj[vobj_id].name);281 _tty_printf("\t\t name = \"%s\"\n", vobj[vobj_id].name);282 _tty_printf("\t\t type = \"%s\" \n", vobj[vobj_id].type);283 _tty_printf("\t\t length = \"0x%x\" \n", vobj[vobj_id].length);284 _tty_printf("\t\t align = \"%d\" \n", vobj[vobj_id].align);285 _tty_printf("\t\t binpath = \"%s\" \n\n", vobj[vobj_id].binpath);298 std::cout<<"\t\t vobjs =" << vobj[vobj_id].name <<std::endl; 299 std::cout<<"\t\t name =" << vobj[vobj_id].name <<std::endl; 300 std::cout<<"\t\t type =" << vobj[vobj_id].type <<std::endl; 301 std::cout<<"\t\t length =" << vobj[vobj_id].length <<std::endl; 302 std::cout<<"\t\t align =" << vobj[vobj_id].align <<std::endl; 303 std::cout<<"\t\t binpath =" << vobj[vobj_id].binpath <<std::endl; 286 304 } 287 */288 305 } 289 306 … … 311 328 bool aligned = false; 312 329 313 VSeg * vs= new VSeg;314 std::string s(vseg->name); 315 v s->m_name = s;316 317 v s->m_vma = vseg->vbase;330 VSeg *vSO = new VSeg; 331 332 vSO->m_name = std::string(vseg->name); 333 vSO->m_vma = vseg->vbase; 334 vSO->m_lma = ps->nextLma(); 318 335 319 336 cur_vaddr = vseg->vbase; 320 337 cur_paddr = ps->nextLma(); 321 322 vs->m_length = 0; 338 323 339 mapping_vobj_t* cur_vobj; 324 325 340 size_t simple_size = 0; //for debug 326 341 327 342 #ifdef MOVER_DEBUG 328 std::cout << "--------------------vseg_map ---------------------" << std::endl;343 std::cout << "--------------------vseg_map "<< vseg->name <<"---------------------" << std::endl; 329 344 #endif 330 345 … … 334 349 335 350 #ifdef MOVER_DEBUG 336 std::cout << "cur vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")"337 << " size "<< cur_vobj->length << " type" << cur_vobj->type << std::endl;351 std::cout << "current vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")" 352 << " size: "<< cur_vobj->length << " type: " << cur_vobj->type << std::endl; 338 353 #endif 339 354 340 355 if(cur_vobj->type == ELF) 341 356 { 342 343 357 if(!first) 344 358 throw soclib::exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg")); 345 359 346 std::string f(m_pathh.getFullName(std::string(cur_vobj->binpath)));347 360 size_t elf_size; 348 #ifdef MOVER_DEBUG 349 std::cout << "Handling: " << f << " ..." << std::endl; 350 #endif 351 if(!f.compare(m_path)) //local blob: map_info 361 std::string filePath(m_pathHandler.getFullPath(std::string(cur_vobj->binpath))); 362 #ifdef MOVER_DEBUG 363 std::cout << "Handling: " << filePath << " ..." << std::endl; 364 #endif 365 if(!filePath.compare(m_path)) //local blob: map_info 352 366 { 353 /**creating a new session */ 367 #ifdef MOVER_DEBUG 368 std::cout << "Found the vseg of the mapping info" << std::endl; 369 #endif 370 /**creating a new section */ 354 371 sect = new elfpp::section(*m_generator, elfpp::SHT_PROGBITS); 355 372 356 sect->set_name(std::string( "seg_mapping_info"));373 sect->set_name(std::string(cur_vobj->name)); 357 374 sect->set_flags(elfpp::SHF_ALLOC | elfpp::SHF_WRITE); 358 375 sect->set_size(this->m_size); 359 360 sect->set_content(m_data); 376 sect->set_content(this->m_data); 361 377 362 378 elf_size = this->m_size; 363 assert((elf_size >0) and "MAP INFO fileempty !?");379 assert((elf_size >0) and "MAPPING INFO file is empty !?"); 364 380 } 365 381 else 366 382 { 367 383 #ifdef MOVER_DEBUG 368 std::cout << "ELF vseg found " << std::endl; 369 #endif 370 if(m_loaders.count(f) == 0 ) 371 m_loaders[f] = new elfpp::object(f); 372 elfpp::object* loader = m_loaders[f]; 373 //elfpp::object* loader = (new elfpp::object(f));//TODO:free! 374 384 std::cout << "Found an ELF vseg" << std::endl; 385 #endif 386 if(m_loaders.count(filePath) == 0 ) 387 m_loaders[filePath] = new elfpp::object(filePath); 388 elfpp::object* loader = m_loaders[filePath];//TODO:free!? 389 390 //sect = get_sect_by_name(loader, std::string(cur_vobj->name)); 391 //assert(( sect->get_vaddr() == cur_vaddr) and "Vaddr doesn't match!"); 375 392 sect = get_sect_by_addr(loader, cur_vaddr); 376 393 assert(sect and "No section found"); 377 394 395 sect->set_name(std::string(cur_vobj->name)); 396 378 397 elf_size = sect->get_size(); 379 380 398 assert((elf_size >0) and "ELF section empty ?"); 399 381 400 if(!m_ginit) 382 401 { 383 //we suppose the header is the same for the all the bins 402 /** Initailising the header of the generator from the first binary 403 * we suppose the header is the same for all the binarys 404 * */ 384 405 m_generator->copy_info(*loader); 385 406 m_ginit=true; 386 407 } 387 408 } 388 cur_vobj->length = elf_size;//set the actual size 409 389 410 if(elf_size > cur_vobj->length) 390 std::cout << "Warning, specified elf type vobj ("<< cur_vobj->name <<") size is "<< cur_vobj->length 391 << ", the actual size is " << elf_size << std::endl; 392 393 vs->m_file = f; 394 vs->m_loadable = true; 411 std::cout << "Warning, specified elf type vobj ("<< 412 cur_vobj->name <<") size is "<< cur_vobj->length << ", the actual size is " 413 << elf_size << std::endl; 414 415 cur_vobj->length = elf_size;//set the true size of this ELF vobj 416 417 vSO->m_file = filePath; 418 vSO->m_loadable = true; 395 419 } 396 420 first = false; 397 421 422 //aligning the vobj->paddr if necessary 398 423 if(cur_vobj->align) 399 424 { … … 401 426 aligned = true; 402 427 } 403 404 428 405 429 cur_vaddr += cur_vobj->length; … … 411 435 assert((cur_paddr >= ps->nextLma() )); 412 436 413 v s->m_length = (cur_paddr - ps->nextLma()); //pageAlign is done by the psegs437 vSO->m_length = (cur_paddr - ps->nextLma()); //pageAlign is done by the psegs 414 438 415 439 #ifdef MOVER_DEBUG 416 440 if(aligned) 417 441 { 418 std::cout << "vseg base "<< std::hex << ps->nextLma() <<(ps->nextLma()+simple_size) <<" size " << std::dec << simple_size << std::endl; 419 std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma() 420 <<" to "<< std::hex << ps->nextLma()+vs->m_length<< " size " << std::dec << vs->m_length << std::endl; 442 std::cout << "vseg base "<< std::hex << ps->nextLma() 443 <<(ps->nextLma()+simple_size) <<" size " << std::dec << simple_size << 444 std::endl; 445 446 std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma() 447 <<" to "<< std::hex << ps->nextLma()+vSO->m_length<< " size " << std::dec << 448 vSO->m_length << std::endl; 421 449 } 422 450 #endif 423 451 424 v s->m_ident = vseg->ident;452 vSO->m_ident = vseg->ident; 425 453 426 454 //set the lma 427 455 if ( vseg->ident != 0 ) // identity mapping required 428 ps->addIdent( *v s);456 ps->addIdent( *vSO ); 429 457 else 430 ps->add( *v s);458 ps->add( *vSO ); 431 459 432 460 if(!sect) 433 461 return; 434 462 435 //std::cout << "section: "<< *sect <<"\n seted to: " << (*v s) << std::endl;436 sect->set_vaddr((*v s).lma());463 //std::cout << "section: "<< *sect <<"\n seted to: " << (*vSO) << std::endl; 464 sect->set_vaddr((*vSO).lma()); 437 465 m_generator->add_section(*(new elfpp::section(*sect))); 438 466
Note: See TracChangeset
for help on using the changeset viewer.