| 1 | #include "../include/Segment.h" |
|---|
| 2 | #include "../../Common/include/Debug.h" |
|---|
| 3 | #include <string.h> |
|---|
| 4 | #include <stdlib.h> |
|---|
| 5 | |
|---|
| 6 | namespace environment { |
|---|
| 7 | namespace data { |
|---|
| 8 | |
|---|
| 9 | bool Segment::init (const char * filename,const char ** sections) |
|---|
| 10 | { |
|---|
| 11 | void * ptab; |
|---|
| 12 | int size = this->size; |
|---|
| 13 | // int size = 0; |
|---|
| 14 | int offset = 0; |
|---|
| 15 | |
|---|
| 16 | loadexec(&ptab,&size,&offset,filename,sections); |
|---|
| 17 | |
|---|
| 18 | // std::cout << " - name : " << name << std::endl; |
|---|
| 19 | // std::cout << " - size : " << size << std::endl; |
|---|
| 20 | // std::cout << " - size : " << this->size << std::endl; |
|---|
| 21 | // std::cout << " - offset : " << offset << std::endl; |
|---|
| 22 | |
|---|
| 23 | if (size > (int)this->size) |
|---|
| 24 | { |
|---|
| 25 | std::cerr << "<segment.init> : segment \"" << name << "\" is to small : size is " << this->size << " and requiert is " << size << std::endl; |
|---|
| 26 | return false; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | memcpy(data, ptab, size); |
|---|
| 30 | |
|---|
| 31 | free (ptab); |
|---|
| 32 | |
|---|
| 33 | // { |
|---|
| 34 | // _cout(DATA,"Segment Init\n"); |
|---|
| 35 | // _cout(DATA," * size : %d\n",size); |
|---|
| 36 | // _cout(DATA," * size : %d\n",this->size); |
|---|
| 37 | // _cout(DATA,"%s\n",print(0).c_str()); |
|---|
| 38 | |
|---|
| 39 | // uint32_t addr = base; |
|---|
| 40 | // uint32_t step1 = 4; |
|---|
| 41 | // uint32_t step2 = step1*8; |
|---|
| 42 | |
|---|
| 43 | // for (int32_t i=0; i<size; ++i) |
|---|
| 44 | // { |
|---|
| 45 | // if ((i%step1) == 0) |
|---|
| 46 | // _cout(DATA," "); |
|---|
| 47 | // if ((i%step2) ==0) |
|---|
| 48 | // { |
|---|
| 49 | // _cout(DATA,"\n%.8x : ",addr); |
|---|
| 50 | // addr += step2; |
|---|
| 51 | // } |
|---|
| 52 | // _cout(DATA,"%.2x",0xff&static_cast<uint32_t>(data[i])); |
|---|
| 53 | // } |
|---|
| 54 | // _cout(DATA,"\n"); |
|---|
| 55 | // } |
|---|
| 56 | |
|---|
| 57 | return true; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | }; |
|---|
| 61 | }; |
|---|