Changeset 255 for soft/giet_vm/memo/src
- Timestamp:
- Oct 9, 2013, 9:32:41 AM (11 years ago)
- Location:
- soft/giet_vm/memo/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/memo/src/memo.cpp
r238 r255 41 41 //#define MOVER_DEBUG 42 42 43 size_t PSeg::m_pageSize; 44 45 43 46 //////////////////////////////////////////// 44 MeMo::MeMo( 45 47 MeMo::MeMo(const std::string &filename, 48 const size_t pageSize) 46 49 : m_path(filename), 47 50 m_pathHandler(filename), … … 58 61 m_size = load_bin(m_path, m_data); 59 62 60 // checking signature 63 // checking signature 61 64 mapping_header_t* header = (mapping_header_t*)m_data; 62 65 if((IN_MAPPING_SIGNATURE != header->signature)) … … 92 95 93 96 ///////////////////////////////////////// 94 void MeMo::print( std::ostream &o) const97 void MeMo::print(std::ostream &o) const 95 98 { 96 99 std::cout << "All sections:" << std::endl; 97 FOREACH( sect, m_generator->get_section_table())100 FOREACH(sect, m_generator->get_section_table()) 98 101 { 99 102 assert(&*sect != NULL); … … 340 343 void MeMo::vseg_map( mapping_vseg_t* vseg) 341 344 { 342 mapping_vobj_t * vobj = get_vobj_base((mapping_header_t*) m_data );343 PSeg *ps = &(m_psegh.get(vseg->psegid));344 elfpp::section *sect = NULL;345 mapping_vobj_t * vobj = get_vobj_base((mapping_header_t*) m_data ); 346 PSeg * ps = &(m_psegh.get(vseg->psegid)); 347 elfpp::section * sect = NULL; 345 348 size_t cur_vaddr; 346 paddr_t cur_ paddr;349 paddr_t cur_length; 347 350 bool first = true; 348 351 bool aligned = false; 349 VSeg *vSO = new VSeg;350 mapping_vobj_t *cur_vobj;352 VSeg * vSO = new VSeg; 353 mapping_vobj_t * cur_vobj; 351 354 352 355 vSO->m_name = std::string(vseg->name); 353 356 vSO->m_vma = vseg->vbase; 354 vSO->m_lma = ps->nextLma();357 vSO->m_lma = 0; 355 358 356 359 cur_vaddr = vseg->vbase; 357 cur_paddr = ps->nextLma(); 358 359 size_t simple_size = 0; //for debug 360 361 #ifdef MOVER_DEBUG 362 std::cout << "--------------- vseg_map "<< vseg->name <<" ------------------" << std::endl; 363 #endif 364 365 for ( size_t vobj_id = vseg->vobj_offset ; 366 vobj_id < (vseg->vobj_offset + vseg->vobjs) ; vobj_id++ ) 360 cur_length = 0; // curr_length of the vseg; a new vseg is necessarily aligned on a page boundary 361 362 #ifdef MOVER_DEBUG 363 std::cout << "--------------- vseg_map "<< vseg->name <<" ------------------" << std::endl; 364 #endif 365 366 for (size_t vobj_id = vseg->vobj_offset; 367 vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) 367 368 { 368 369 cur_vobj = &vobj[vobj_id]; 369 370 370 371 #ifdef MOVER_DEBUG 371 std::cout << std::hex << "current vobj("<< vobj_id <<"): " << cur_vobj->name372 << " (" <<cur_vobj->vaddr << ")"373 << " size: "<< cur_vobj->length374 << " type: " << cur_vobj->type << std::endl;375 #endif 376 if (cur_vobj->type == VOBJ_TYPE_BLOB)372 std::cout << std::hex << "current vobj("<< vobj_id <<"): " << cur_vobj->name 373 << " (" <<cur_vobj->vaddr << ")" 374 << " size: "<< cur_vobj->length 375 << " type: " << cur_vobj->type << std::endl; 376 #endif 377 if (cur_vobj->type == VOBJ_TYPE_BLOB) 377 378 { 378 379 size_t blob_size; … … 380 381 381 382 #ifdef MOVER_DEBUG 382 std::cout << std::hex << "Handling: " << filePath << " ..." << std::endl;383 #endif 384 385 if (!filePath.compare(m_path)) // local blob: map_info386 { 387 #ifdef MOVER_DEBUG 388 std::cout << "Found the vseg of the mapping info" << std::endl;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; 389 390 #endif 390 391 blob_size = this->m_size; … … 394 395 { 395 396 #ifdef MOVER_DEBUG 396 std::cout << "Found an BLOB vseg" << std::endl;397 std::cout << "Found an BLOB vseg" << std::endl; 397 398 #endif 398 399 blob_size = bin_size(filePath); … … 408 409 assert(sect->get_content());//check allocation 409 410 410 if (!filePath.compare(m_path))//local blob: map_info411 if (!filePath.compare(m_path)) { //local blob: map_info 411 412 //memcpy(sect->get_content(), m_data, sect->get_size()); 412 413 /* this way the modification of the elf size are propageted to the giet */ 413 414 sect->set_content(this->m_data); 415 } 414 416 else 417 { 415 418 load_bin(filePath, sect->get_content()); 416 417 418 if(blob_size > cur_vobj->length) 419 } 420 421 422 if (blob_size > cur_vobj->length) 419 423 { 420 424 std::cout << std::hex << "!!! Warning, specified blob type vobj ("<< … … 424 428 } 425 429 426 cur_vobj->length = blob_size; //set the true size of this BLOB vobj430 cur_vobj->length = blob_size; //set the true size of this BLOB vobj 427 431 428 432 vSO->m_file = filePath; 429 433 vSO->m_loadable = true; 430 434 } 431 else if (cur_vobj->type == VOBJ_TYPE_ELF)435 else if (cur_vobj->type == VOBJ_TYPE_ELF) 432 436 { 433 if (!first)437 if (!first) 434 438 throw exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg")); 435 439 … … 440 444 std::cout << "Found an ELF vseg" << std::endl; 441 445 #endif 442 if (m_loaders.count(filePath) == 0)446 if (m_loaders.count(filePath) == 0) 443 447 m_loaders[filePath] = new elfpp::object(filePath); 444 elfpp::object * loader = m_loaders[filePath];//TODO:free!?445 446 sect = new elfpp::section(*get_sect_by_addr(loader, cur_vaddr)); //copy: for the case we replicate the code448 elfpp::object * loader = m_loaders[filePath]; //TODO:free!? 449 450 sect = new elfpp::section(*get_sect_by_addr(loader, cur_vaddr)); //copy: for the case we replicate the code 447 451 if (!sect) 448 452 { … … 457 461 assert((elf_size > 0) and "ELF section empty ?"); 458 462 459 if (!m_ginit)463 if (!m_ginit) 460 464 { 461 465 /** Initailising the header of the generator from the first binary, 462 466 ** we suppose that the header is the same for all the binarys **/ 463 467 m_generator->copy_info(*loader, 64); 464 m_ginit =true;465 } 466 467 if (elf_size > cur_vobj->length)468 { 469 std::cout << "Warning, specified elf type vobj (" <<470 cur_vobj->name << ") size is "<< cur_vobj->length << ", the actual size is "468 m_ginit = true; 469 } 470 471 if (elf_size > cur_vobj->length) 472 { 473 std::cout << "Warning, specified elf type vobj (" << 474 cur_vobj->name << ") size is " << cur_vobj->length << ", the actual size is " 471 475 << elf_size << std::endl; 472 //assert((elf_size < cur_vobj->length) and "elf vobj length smaller than the actual content" );//??? 473 assert((0) and "elf vobj length smaller than the actual content" );//??? 476 assert((0) and "elf vobj length smaller than the actual content"); 474 477 } 475 478 … … 481 484 482 485 //aligning the vobj->paddr if necessary 483 // 484 if(cur_vobj->align) 486 if (cur_vobj->align) 485 487 { 486 cur_ paddr = PSeg::align(cur_paddr, cur_vobj->align);488 cur_length = PSeg::align(cur_length, cur_vobj->align); 487 489 aligned = true; 488 490 } 489 491 490 492 cur_vaddr += cur_vobj->length; 491 cur_paddr += cur_vobj->length; 492 simple_size += cur_vobj->length; 493 cur_length += cur_vobj->length; 493 494 first = false; 494 495 } 495 496 496 assert((cur_vaddr >= vseg->vbase )); 497 assert((cur_paddr >= ps->nextLma() )); 498 499 vSO->m_length = (cur_paddr - ps->nextLma()); //pageAlign is done by the psegs 500 501 #ifdef MOVER_DEBUG 502 if(aligned) 503 { 504 std::cout << "vseg base "<< std::hex << ps->nextLma() 505 <<(ps->nextLma()+simple_size) <<" size " << std::dec << simple_size << 506 std::endl; 507 508 std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma() 509 <<" to "<< std::hex << ps->nextLma()+vSO->m_length<< " size " << std::dec << 510 vSO->m_length << std::endl; 511 } 512 #endif 513 497 assert(cur_vaddr >= vseg->vbase); 498 499 vSO->m_length = cur_length; //pageAlign is done by the psegs 514 500 vSO->m_ident = vseg->ident; 501 vSO->m_align = vobj[vseg->vobj_offset].align; 515 502 516 503 //set the lma for vseg that are not peripherals 517 if(ps->type() != PSEG_TYPE_PERI) 518 { 519 if ( vseg->ident != 0 ) ps->addIdent( *vSO ); 520 else ps->add( *vSO ); 521 } 522 523 // increment NextLma if required 524 if(ps->type() == PSEG_TYPE_RAM) 525 { 526 ps->incNextLma( vSO->m_length ); 527 } 528 529 if(!sect) return; 504 if (ps->type() != PSEG_TYPE_PERI) 505 { 506 if (vseg->ident != 0) ps->addIdent(*vSO); 507 else ps->add(*vSO); 508 } 509 510 if (!sect) return; 530 511 531 512 #ifdef MOVER_DEBUG … … 540 521 541 522 /////////////////////////////// 542 void MeMo::buildMap(void * desc)543 { 544 mapping_header_t * header = (mapping_header_t*)desc;545 546 mapping_cluster_t * cluster = get_cluster_base( header);547 mapping_vspace_t * vspace = get_vspace_base( header);548 mapping_pseg_t * pseg = get_pseg_base( header);549 mapping_vseg_t * vseg = get_vseg_base( header);523 void MeMo::buildMap(void * desc) 524 { 525 mapping_header_t * header = (mapping_header_t *) desc; 526 527 mapping_cluster_t * cluster = get_cluster_base(header); 528 mapping_vspace_t * vspace = get_vspace_base(header); 529 mapping_pseg_t * pseg = get_pseg_base(header); 530 mapping_vseg_t * vseg = get_vseg_base(header); 550 531 551 532 // get the psegs 552 533 553 534 #ifdef MOVER_DEBUG 554 std::cout << "\n******* Storing Pseg information *********\n" << std::endl; 555 #endif 556 557 for ( size_t cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 558 { 559 for ( size_t pseg_id = cluster[cluster_id].pseg_offset ; 560 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs ; 561 pseg_id++ ) 562 { 535 std::cout << "\n******* Storing Pseg information *********\n" << std::endl; 536 #endif 537 538 for (size_t cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 539 for (size_t pseg_id = cluster[cluster_id].pseg_offset; 540 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; 541 pseg_id++) { 563 542 std::string name(pseg[pseg_id].name); 564 PSeg *ps = new PSeg( 565 566 567 pseg[pseg_id].type);543 PSeg *ps = new PSeg(name, 544 pseg[pseg_id].base, 545 pseg[pseg_id].length, 546 pseg[pseg_id].type); 568 547 m_psegh.m_pSegs.push_back(*ps); 569 548 } … … 573 552 574 553 #ifdef MOVER_DEBUG 575 std::cout << "\n******* mapping global vsegs *********\n" << std::endl; 576 #endif 577 578 for ( size_t vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 579 { 580 vseg_map( &vseg[vseg_id]); 581 } 554 std::cout << "\n******* mapping global vsegs *********\n" << std::endl; 555 #endif 556 557 // Mapping identity segments first 558 for (size_t vseg_id = 0; vseg_id < header->globals; vseg_id++) { 559 if (vseg[vseg_id].ident == 1) { 560 vseg_map(&vseg[vseg_id]); 561 } 562 } 563 564 // Mapping non-identity segments second 565 for (size_t vseg_id = 0; vseg_id < header->globals; vseg_id++) { 566 if (vseg[vseg_id].ident == 0) { 567 vseg_map(&vseg[vseg_id]); 568 } 569 } 570 571 582 572 583 573 // loop on virtual spaces to map private vsegs 584 for (size_t vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 585 { 586 587 #ifdef MOVER_DEBUG 588 std::cout << "\n******* mapping all vsegs of " << vspace[vspace_id].name << " *********\n" << std::endl; 589 #endif 590 591 for ( size_t vseg_id = vspace[vspace_id].vseg_offset ; 592 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; 593 vseg_id++ ) 594 { 595 vseg_map( &vseg[vseg_id]); 574 for (size_t vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 575 #ifdef MOVER_DEBUG 576 std::cout << "\n******* mapping all vsegs of " << vspace[vspace_id].name << " *********\n" << std::endl; 577 #endif 578 for (size_t vseg_id = vspace[vspace_id].vseg_offset; 579 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 580 vseg_id++) { 581 if (vseg[vseg_id].ident == 1) { 582 vseg_map(&vseg[vseg_id]); 583 } 584 } 585 586 for (size_t vseg_id = vspace[vspace_id].vseg_offset; 587 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 588 vseg_id++) { 589 if (vseg[vseg_id].ident == 0) { 590 vseg_map(&vseg[vseg_id]); 591 } 596 592 } 597 593 } 598 599 594 } // end buildMap() 600 595 -
soft/giet_vm/memo/src/pseg.cpp
r238 r255 35 35 #include <iomanip> 36 36 37 #include <cstdio> 38 37 39 #include "pseg.h" 38 40 #include "exception.h" 41 42 43 #define max(x, y) (((x) > (y)) ? (x) : (y)) 39 44 40 45 … … 44 49 45 50 ////////////////////////////////////// 46 const std::string & VSeg::name() const 47 { 51 const std::string & VSeg::name() const { 48 52 return m_name; 49 53 } 50 54 51 55 ////////////////////////////////////// 52 const std::string & VSeg::file() const 53 { 56 const std::string & VSeg::file() const { 54 57 return m_file; 55 58 } 56 59 57 60 /////////////////////////// 58 uintptr_t VSeg::vma() const 59 { 61 uintptr_t VSeg::vma() const { 60 62 return m_vma; 61 63 } 62 64 63 65 ///////////////////////// 64 paddr_t VSeg::lma() const 65 { 66 paddr_t VSeg::lma() const { 66 67 return m_lma; 67 68 } 68 69 69 70 /////////////////////////// 70 size_t VSeg::length() const 71 { 71 size_t VSeg::length() const { 72 72 return m_length; 73 73 } 74 74 75 75 ///////////////////////// 76 size_t VSeg::type() const 77 { 76 size_t VSeg::type() const { 78 77 return m_type; 79 78 } 80 79 81 80 ///////////////////////////////////////// 82 void VSeg::print( std::ostream &o) const81 void VSeg::print(std::ostream &o) const 83 82 { 84 83 o << std::hex << std::noshowbase … … 89 88 << m_lma << ", size: 0x" 90 89 << std::setw (8) << std::setfill('0') 91 << m_length << ",ident: "92 << (m_ident ? "yes" : "no") << ", in(file): "93 << m_file << ", name: " << m_name << ">";90 << m_length << ",ident: " 91 << (m_ident ? "yes" : "no") << ", in(file): " 92 << m_file << ", name: " << m_name << ">"; 94 93 } 95 94 96 95 ///////////// 97 VSeg::~VSeg() 98 { 99 } 96 VSeg::~VSeg() {} 100 97 101 98 ///////////////////////////////////////// 102 VSeg & VSeg::operator=( const VSeg &ref)103 { 104 if ( &ref == this)99 VSeg & VSeg::operator=(const VSeg & ref) 100 { 101 if (&ref == this) 105 102 return *this; 106 103 107 m_name = ref.m_name ,104 m_name = ref.m_name; 108 105 m_file = ref.m_file; 109 106 m_vma = ref.m_vma; … … 111 108 m_length = ref.m_length; 112 109 m_ident = ref.m_ident; 113 110 return *this; 114 111 } 115 112 … … 117 114 VSeg::VSeg() 118 115 : m_name("No Name"), 119 120 121 122 123 116 m_file("Empty section"), 117 m_vma(0), 118 m_length(0), 119 m_loadable(false), 120 m_ident(0) 124 121 { 125 122 } … … 127 124 //////////////////////////////////// 128 125 VSeg::VSeg(std::string& binaryName, 129 130 131 132 133 134 135 136 137 138 139 126 std::string& name, 127 uintptr_t vma, 128 size_t length, 129 bool loadable, 130 bool ident) 131 : m_name(name), 132 m_file(binaryName), 133 m_vma(vma), 134 m_length(length), 135 m_loadable(loadable), 136 m_ident(ident) 140 137 { 141 138 } 142 139 143 140 ///////////////////////////// 144 VSeg::VSeg( const VSeg &ref )145 : m_name("To be copied"),146 m_file("Empty"),147 m_vma(0),148 m_length(0),149 m_loadable(false),150 m_ident(0)141 VSeg::VSeg(const VSeg &ref): 142 m_name(ref.m_name), 143 m_file(ref.m_file), 144 m_vma(ref.m_vma), 145 m_length(ref.m_length), 146 m_loadable(ref.m_loadable), 147 m_ident(ref.m_ident) 151 148 { 152 149 (*this) = ref; … … 159 156 160 157 ///////////////////////// 161 paddr_t PSeg::lma() const 162 { 163 return m_lma; 158 paddr_t PSeg::lma() const { 159 return m_lma; 164 160 } 165 161 166 162 /////////////////////////// 167 paddr_t PSeg::limit() const 168 { 169 return m_limit; 170 } 171 172 ///////////////////////////// 173 paddr_t PSeg::length() const 174 { 175 return m_length; 163 paddr_t PSeg::length() const { 164 return m_length; 176 165 } 177 166 178 167 ///////////////////////// 179 size_t PSeg::type() const 180 { 181 return m_type; 182 } 183 184 ///////////////////////////// 185 paddr_t PSeg::nextLma() const 186 { 187 return m_nextLma; 168 size_t PSeg::type() const { 169 return m_type; 188 170 } 189 171 190 172 ////////////////////////////////////// 191 const std::string & PSeg::name() const 192 { 193 return m_name; 173 const std::string & PSeg::name() const { 174 return m_name; 194 175 } 195 176 … … 198 179 { 199 180 200 if (this->m_type == PSEG_TYPE_PERI)181 if (this->m_type == PSEG_TYPE_PERI) 201 182 return; 202 183 … … 204 185 size_t size = m_vsegs.size(); 205 186 paddr_t used[size][2]; // lma, lma+length 206 size_t i, j,error=0;207 208 for (it = m_vsegs.begin(), i= 0 ; it < m_vsegs.end(); it++, i++)187 size_t i, j, error = 0; 188 189 for (it = m_vsegs.begin(), i = 0; it < m_vsegs.end(); it++, i++) 209 190 { 210 191 paddr_t it_limit = (*it).lma() + (*it).length(); 211 for(j =0; j< i; j++)192 for(j = 0; j < i; j++) 212 193 { 213 if( used[j][0] == (*it).lma() ) //not the same lma , 214 { 215 error = 1; 216 std::cout << "ok \n"; 217 } 218 if( used[j][1] == it_limit ) // and not the same limit 194 if (used[j][0] == (*it).lma()) //not the same lma , 195 { 196 error = 1; 197 } 198 if (used[j][1] == it_limit) // and not the same limit 219 199 { 220 200 error = 2; 221 201 } 222 if ( (used[j][0] < (*it).lma()) and ((*it).lma() < used[j][1])) // lma within202 if ((used[j][0] < (*it).lma()) and ((*it).lma() < used[j][1])) // lma within 223 203 { 224 204 error = 3; 225 205 } 226 if ( ((used[j][0] < it_limit) and (it_limit < used[j][1] ))) // limit no within206 if (((used[j][0] < it_limit) and (it_limit < used[j][1]))) // limit no within 227 207 { 228 208 error = 4; … … 232 212 std::cout << "used[j][1]: " << std::hex << used[j][1] << std::endl; 233 213 } 234 if (error)214 if (error) 235 215 { 236 216 std::ostringstream err; 237 err << " Error" << error << " ,ovelapping Buffers:" << std::endl217 err << " Error" << error << ", ovelapping Buffers:" << std::endl 238 218 << *it << std::endl << m_vsegs[j] << std::endl; 239 219 throw exception::RunTimeError( err.str().c_str() ); … … 246 226 } 247 227 248 //////////////////////////////////////249 void PSeg::setName(std::string& name )250 {251 m_name = name;252 }253 228 254 229 ///////////////////////////////////////////////////////// 255 paddr_t PSeg::align( paddr_t toAlign, unsigned alignPow2) 256 { 230 paddr_t PSeg::align(paddr_t toAlign, unsigned alignPow2) { 257 231 return ((toAlign + (1 << alignPow2) - 1 ) >> alignPow2) << alignPow2; 258 232 } 259 233 260 234 ////////////////////////////////////////// 261 paddr_t PSeg::pageAlign( paddr_t toAlign ) 262 { 235 paddr_t PSeg::pageAlign(paddr_t toAlign) { 263 236 size_t pgs = pageSize(); 264 237 size_t pageSizePow2 = __builtin_ctz(pgs); 265 238 266 239 return align(toAlign, pageSizePow2); 267 240 } 268 241 269 //////////////////////////////// 270 void PSeg::setLma( paddr_t lma ) 271 { 272 m_lma = lma; 273 274 m_nextLma = pageAlign(lma); 275 276 m_pageLimit = pageAlign(m_lma+m_length); 277 278 m_limit = (m_lma + m_length); 279 } 280 281 ///////////////////////////////////// 282 void PSeg::setLength( paddr_t length ) 283 { 284 m_length = length; 285 286 m_pageLimit = pageAlign(m_lma+m_length); 287 288 m_limit = (m_lma + m_length); 289 } 242 290 243 291 244 //////////////////////////// 292 void PSeg::add( VSeg& vseg ) 293 { 294 vseg.m_lma = m_nextLma; 295 // incNextLma(vseg.length()); //for the next vseg 245 void PSeg::add(VSeg& vseg) { 246 std::vector<VSeg>::iterator it; 247 int nb_elems = m_vsegs.size(); 248 int i = 0; 249 bool mapped = false; 250 paddr_t prev_base = m_lma; 251 paddr_t prev_length = 0x0; 252 paddr_t curr_base = 0x0; 253 paddr_t curr_length = 0x0; 254 paddr_t next_base = 0x0; 255 paddr_t next_length = 0x0; 256 257 const int alignment = max(vseg.m_align, __builtin_ctz(pageSize())); // 12 258 259 if (vseg.length() == 0) { 260 std::cout << "*** Error: Adding a vseg of size 0 (base " << vseg.vma() << ")" << std::endl; 261 exit(1); 262 } 263 264 if (nb_elems == 0) { 265 if (vseg.length() <= m_length) { 266 vseg.m_lma = m_lma; 267 m_vsegs.push_back(vseg); 268 return; 269 } 270 else { 271 std::cout << "*** Error: Not enough space to map first VSeg (base = " 272 << std::hex << vseg.vma() << " - Size = " << vseg.length() << ")" << std::endl; 273 std::cout << " PSeg too small! (base = " << m_lma << " - size = " 274 << m_length << ")" << std::endl; 275 exit(1); 276 } 277 } 278 279 curr_base = m_vsegs[0].lma(); // Initialisation avant recherche du min 280 curr_length = m_vsegs[0].length(); 281 for (it = m_vsegs.begin(); it != m_vsegs.end(); it++) { 282 if ((*it).lma() < curr_base) { 283 curr_base = (*it).lma(); 284 curr_length = (*it).length(); 285 } 286 } 287 288 while (i < nb_elems) { 289 if (align(prev_base + prev_length, alignment) + vseg.length() <= curr_base) { 290 vseg.m_lma = align(prev_base + prev_length, alignment); 291 mapped = true; 292 break; 293 } 294 else if (i < nb_elems - 1) { 295 // Searching for the vseg already mapped with lowest paddr > curr_base 296 next_base = 0; 297 bool found = false; 298 for (it = m_vsegs.begin(); it != m_vsegs.end(); it++) { 299 if ((!found || (*it).lma() < next_base) && (*it).lma() > curr_base) { 300 found = true; 301 next_base = (*it).lma(); 302 next_length = (*it).length(); 303 } 304 } 305 assert(found); 306 307 prev_base = curr_base; 308 prev_length = curr_length; 309 310 curr_base = next_base; 311 curr_length = next_length; 312 } 313 else { 314 if (align(curr_base + curr_length, alignment) + vseg.length() <= m_lma + m_length) { 315 vseg.m_lma = align(curr_base + curr_length, alignment); 316 mapped = true; 317 } 318 } 319 i++; 320 } 321 322 if (!mapped) { 323 std::cout << "*** Error: Not enough space to map VSeg (base = " << std::hex << vseg.vma() << " - Size = " << vseg.length() << ")" << std::endl; 324 exit(1); 325 } 326 296 327 m_vsegs.push_back(vseg); 297 328 } 298 329 330 299 331 ///////////////////////////////// 300 void PSeg::addIdent( VSeg& vseg ) 301 { 332 void PSeg::addIdent(VSeg& vseg) { 333 std::vector<VSeg>::iterator it; 334 335 for (it = m_vsegs.begin(); it != m_vsegs.end(); it++) { 336 if ((vseg.vma() == (*it).lma()) || 337 ((vseg.vma() < (*it).lma()) && (vseg.vma() + vseg.length() > (*it).lma())) || 338 ((vseg.vma() > (*it).lma()) && ((*it).lma() + (*it).length() > vseg.vma()))) { 339 std::cout << "*** Error: Identity VSeg overlaps another segment:" << std::endl 340 << "Added Segment Base : " << std::hex << vseg.vma() 341 << " - Size : " << vseg.length() << std::endl; 342 std::cout << "Existing Segment Base : " << (*it).lma() 343 << " - size : " << (*it).length() << std::endl; 344 exit(1); 345 } 346 } 347 302 348 vseg.m_lma = vseg.m_vma; 303 349 m_vsegs.push_back(vseg); 304 350 } 305 351 352 306 353 ///////////////////////////////////////// 307 void PSeg::setNextLma( paddr_t nextLma) 308 { 309 m_nextLma = nextLma; 310 confNextLma(); 311 } 312 313 ////////////////////////////////// 314 void PSeg::incNextLma( size_t inc) 315 { 316 m_nextLma += inc; 317 confNextLma(); 318 } 319 320 //////////////////////// 321 void PSeg::confNextLma() 322 { 323 if(m_nextLma > m_limit) 324 { 325 std::cerr << "Erreur pseg overflow... nextLma: " 326 << std::hex << m_nextLma << ", limit: " 327 << m_limit << std::endl; 328 exit(1); 329 } 330 331 m_nextLma = pageAlign( m_nextLma ); 332 333 if(m_nextLma > m_pageLimit) 334 { 335 std::cerr << "Erreur pseg page overflow... nextLma: " 336 << std::hex << m_nextLma << ", limit: " 337 << m_pageLimit << std::endl; 338 exit(1); 339 } 340 } 341 342 ///////////////////////////////// 343 void PSeg::setPageSize(size_t pg) 344 { 345 if( pg == 0) 346 { 347 std::cerr << "PageSize must be positive" << std::endl; 348 return; 349 } 350 pageSize() = pg; 351 } 352 353 //////////////////////// 354 size_t& PSeg::pageSize() 355 { 356 static size_t m_pageSize; 357 return m_pageSize; 358 } 359 360 ///////////////////////////////////////// 361 PSeg & PSeg::operator=( const PSeg &ref ) 362 { 363 if ( &ref == this ) 354 PSeg & PSeg::operator=(const PSeg &ref) { 355 if (&ref == this) { 364 356 return *this; 357 } 365 358 366 359 m_name = ref.m_name; 367 360 m_length = ref.m_length; 368 m_limit = ref.m_limit;369 m_pageLimit = ref.m_pageLimit;370 361 m_lma = ref.m_lma; 371 m_nextLma = ref.m_nextLma;372 362 m_vsegs = ref.m_vsegs; 373 363 m_type = ref.m_type; … … 377 367 378 368 ////////////////////////////////////////// 379 void PSeg::print( std::ostream &o) const369 void PSeg::print(std::ostream &o) const 380 370 { 381 371 o << "<Physical segment " 382 372 << std::showbase << m_name 383 373 << ", from: " << std::hex 384 << m_lma << " to " << m_limit374 << m_lma 385 375 << ", size : " << m_length 386 << ", filled to: " << m_nextLma387 376 << ", type : " << m_type 388 377 << ", containing: "<< std::endl; … … 403 392 m_length = length; 404 393 m_type = type; 405 406 setLma(lma); 394 m_lma = lma; 407 395 } 408 396 409 397 //////////////////////////////////// 410 PSeg::PSeg( 398 PSeg::PSeg(const std::string &name): 411 399 m_lma(0), 412 m_length(0), 413 m_nextLma(0), 414 m_limit(0) 415 { 400 m_length(0) { 416 401 m_name = name; 417 402 } 418 403 419 //////////////////////// 420 PSeg::PSeg( paddr_t lma): 421 m_name("No name"), 422 m_lma(0), 423 m_length(0), 424 m_nextLma(0), 425 m_limit(0) 426 { 427 setLma(lma); 428 } 429 430 //////////// 431 PSeg::PSeg() 432 : 433 m_name("Empty section"), 434 m_lma(0), 435 m_length(0), 436 m_nextLma(0), 437 m_limit(0) 438 { 439 } 440 441 ///////////////////////////// 442 PSeg::PSeg( const PSeg &ref ) 443 : m_name("To be copied"), 444 m_lma(0), 445 m_length(0), 446 m_nextLma(0), 447 m_limit(0) 448 { 449 (*this) = ref; 450 } 451 452 PSeg::~PSeg() 453 { 454 } 404 405 //////////////////////////////////// 406 PSeg::PSeg(const PSeg& pseg) { 407 m_name = pseg.m_name; 408 m_length = pseg.m_length; 409 m_lma = pseg.m_lma; 410 m_vsegs = pseg.m_vsegs; 411 m_type = pseg.m_type; 412 413 (*this) = pseg; 414 } 415 416 PSeg::~PSeg() {} 455 417 456 418
Note: See TracChangeset
for help on using the changeset viewer.