Changeset 138 for trunk/IPs/systemC/Environment/Data
- Timestamp:
- May 12, 2010, 7:34:01 PM (14 years ago)
- Location:
- trunk/IPs/systemC/Environment/Data
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/IPs/systemC/Environment/Data/selftest/main.cpp
r134 r138 1 #ifdef SYSTEMC 2 #include "systemc.h" 3 #endif 1 4 #include <iostream> 2 5 #include "../include/Data.h" 6 #include "../../../shared/mapping_memory.h" 3 7 4 8 using namespace std; … … 29 33 { 30 34 cout << "<main> Begin" << endl; 31 32 { 33 // Segment * seg1 = new Segment (); 35 36 const bool test1 = false; // 37 const bool test2 = true; // 38 39 if (test1) 40 { 41 // Segment * seg1 = new Segment (); 42 43 // TEST(seg1->getType (), TYPE_TARGET_MEMORY); 44 // TEST(seg1->getIndex (), 0); 45 // TEST(seg1->getBase (), 0); 46 // TEST(seg1->getSize (), 0); 47 // TEST(seg1->getUncached (), false); 48 49 // seg1->define_target(TYPE_TARGET_SIM2OS,4); 50 // TEST(seg1->getType (), TYPE_TARGET_SIM2OS); 51 // TEST(seg1->getIndex (), 4); 52 53 // cout << *seg1 << endl; 34 54 35 // TEST(seg1->getType (), TYPE_TARGET_MEMORY); 36 // TEST(seg1->getIndex (), 0); 37 // TEST(seg1->getBase (), 0); 38 // TEST(seg1->getSize (), 0); 39 // TEST(seg1->getUncached (), false); 55 SEGMENT_TABLE_ENTRY * entry = new SEGMENT_TABLE_ENTRY("entry", 0x100, 0x1024, 21, 7, true); 40 56 41 // seg1->define_target(TYPE_TARGET_SIM2OS,4); 42 // TEST(seg1->getType (), TYPE_TARGET_SIM2OS); 43 // TEST(seg1->getIndex (), 4); 44 45 // cout << *seg1 << endl; 46 47 SEGMENT_TABLE_ENTRY * entry = new SEGMENT_TABLE_ENTRY("entry", 0x100, 0x1024, 21, 7, true); 48 49 Segment * seg2 = new Segment (entry); 50 51 cout << *seg2 << endl; 52 53 TEST(seg2->test(0x100, 0x0 ), true); 54 TEST(seg2->test(0x100, 0x1024), true); 55 TEST(seg2->test(0x100, 0x1025), false); 56 57 char * str = new char [10]; 58 59 str [0] = 'k'; 60 str [1] = 'a'; 61 str [2] = 'n'; 62 str [3] = 'e'; 63 str [4] = 'd'; 64 str [5] = 'e'; 65 str [6] = 'a'; 66 str [7] = 'd'; 67 68 seg2->write(0x200,8,str); 69 70 for (uint32_t i=0; i<10; i++) 71 str [i] = '.'; 72 73 for (uint32_t i=0; i<10; i++) 74 cout << str [i]; 75 cout << endl; 76 77 str [0] = 'i'; 78 str [1] = 's'; 79 str [2] = 'b'; 80 str [3] = 'a'; 81 str [4] = 'c'; 82 str [5] = 'k'; 83 84 seg2->write(0x204,6,str); 85 86 for (uint32_t i=0; i<10; i++) 87 str [i] = '.'; 88 89 seg2->read(0x200,10,str); 90 91 for (uint32_t i=0; i<10; i++) 92 cout << str [i]; 93 cout << endl; 94 95 Entity * entity1 = new Entity (false); 96 Entity * entity2 = new Entity (true, seg2); 97 98 cout << *entity1 << endl; 99 cout << *entity2 << endl; 100 101 delete entity2; 102 delete entity1; 103 delete [] str; 104 delete seg2; 105 delete entry; 106 // delete seg1; 107 } 108 109 { 110 SOCLIB_SEGMENT_TABLE * segtable = new SOCLIB_SEGMENT_TABLE; 111 segtable->setMSBNumber (8); 112 segtable->setDefaultTarget(0,0); 113 114 //shared data segment 115 116 const int TEXT_BASE = 0x0; 117 const int DATA_CACHED_BASE = 0x10000000; 118 const int DATA_UNCACHED_BASE = 0x40000000; 119 120 const int TEXT_SIZE = 0x4000; 121 const int DATA_CACHED_SIZE = 0x4000; 122 const int DATA_UNCACHED_SIZE = 0x4000; 123 124 // Add a segment :name , address of base , size , global index , local index, uncache 125 segtable->addSegment("text" , TEXT_BASE , TEXT_SIZE , 0 ,0 , false); 126 segtable->addSegment("data" , DATA_CACHED_BASE , DATA_CACHED_SIZE , 0 ,0 , false); 127 segtable->addSegment("data_unc" , DATA_UNCACHED_BASE , DATA_UNCACHED_SIZE , 0 ,0 , true ); 128 129 segtable->print(); 130 131 Parameters * param = new Parameters (16,0,0,segtable); 132 133 Data * data = new Data ("my_data", param); 134 135 cout << *data << endl; 136 137 const char * filename = "selftest/data/soft.x"; 138 const char * sections_text [] = {".text",NULL}; 139 const char * sections_data [] = {".data",".rodata",".bss",".sdata",".sbss", NULL}; 140 141 data->init("text" , filename, sections_text); 142 data->init("data" , filename, sections_data); 143 144 char * str = new char [8]; 145 146 data->read(0x100,8,str); 147 148 cout << hex; 149 for (uint32_t i=0; i<8; i++) 150 { 151 if (i==4) 152 cout << endl; 153 cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff); 154 } 155 cout << dec << endl; 156 157 str [0] = 0xde; 158 str [1] = 0xad; 159 str [2] = 0xbe; 160 str [3] = 0xef; 161 str [4] = 0xba; 162 str [5] = 0xbe; 163 str [6] = 0xbe; 164 str [7] = 0xef; 165 166 data->write(0x104,8,str); 167 168 data->read(0x100,8,str); 169 170 cout << hex; 171 for (uint32_t i=0; i<8; i++) 172 { 173 if (i==4) 174 cout << endl; 175 cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff); 176 } 177 cout << dec << endl; 178 179 data->read(0x108,8,str); 180 181 cout << hex; 182 for (uint32_t i=0; i<8; i++) 183 { 184 if (i==4) 185 cout << endl; 186 cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff); 187 } 188 cout << dec << endl; 189 190 delete [] str; 191 delete data; 192 delete param; 193 delete segtable; 194 } 57 Segment * seg2 = new Segment (entry); 58 59 cout << *seg2 << endl; 60 61 TEST(seg2->test(0x100, 0x0 ), true); 62 TEST(seg2->test(0x100, 0x1024), true); 63 TEST(seg2->test(0x100, 0x1025), false); 64 65 char * str = new char [10]; 66 67 str [0] = 'k'; 68 str [1] = 'a'; 69 str [2] = 'n'; 70 str [3] = 'e'; 71 str [4] = 'd'; 72 str [5] = 'e'; 73 str [6] = 'a'; 74 str [7] = 'd'; 75 76 seg2->write(0x200,8,str); 77 78 for (uint32_t i=0; i<10; i++) 79 str [i] = '.'; 80 81 for (uint32_t i=0; i<10; i++) 82 cout << str [i]; 83 cout << endl; 84 85 str [0] = 'i'; 86 str [1] = 's'; 87 str [2] = 'b'; 88 str [3] = 'a'; 89 str [4] = 'c'; 90 str [5] = 'k'; 91 92 seg2->write(0x204,6,str); 93 94 for (uint32_t i=0; i<10; i++) 95 str [i] = '.'; 96 97 seg2->read(0x200,10,str); 98 99 for (uint32_t i=0; i<10; i++) 100 cout << str [i]; 101 cout << endl; 102 103 Entity * entity1 = new Entity (false); 104 Entity * entity2 = new Entity (true, seg2); 105 106 cout << *entity1 << endl; 107 cout << *entity2 << endl; 108 109 delete entity2; 110 delete entity1; 111 delete [] str; 112 delete seg2; 113 delete entry; 114 // delete seg1; 115 } 116 117 if (test2) 118 { 119 SOCLIB_SEGMENT_TABLE * segtable = new SOCLIB_SEGMENT_TABLE; 120 segtable->setMSBNumber (8); 121 segtable->setDefaultTarget(0,0); 122 123 //shared data segment 124 125 // const int TEXT_BASE = 0x0; 126 // const int DATA_CACHED_BASE = 0x10000000; 127 // const int DATA_STACK_BASE = 0x40000000; 128 // const int DATA_UNCACHED_BASE = 0x80000000; 129 130 // const int TEXT_SIZE = 0x4000; 131 // const int DATA_CACHED_SIZE = 0x4000; 132 // const int DATA_STACK_SIZE = 0x4000; 133 // const int DATA_UNCACHED_SIZE = 0x4000; 134 135 // Add a segment name , address of base , size , global index , local index, uncache 136 segtable->addSegment("text" , TEXT_BASE , TEXT_SIZE , 0 , 0 , false); 137 segtable->addSegment("data" , DATA_CACHED_BASE , DATA_CACHED_SIZE , 0 , 0 , false); 138 // segtable->addSegment("data_stack", DATA_STACK_BASE , DATA_STACK_SIZE , 0 , 0 , false); 139 // segtable->addSegment("data_unc" , DATA_UNCACHED_BASE , DATA_UNCACHED_SIZE , 0 , 0 , true ); 140 141 segtable->print(); 142 143 Parameters * param = new Parameters (16,0,0,segtable); 144 145 Data * data = new Data ("my_data", param); 146 147 cout << *data << endl; 148 149 // const char * filename = "selftest/data/soft.x"; 150 const char * filename = "../../../../Softwares/Test/Test_000/bin/soft_NEWLIB_MORPHEO.x"; 151 const char * sections_text [] = {".text",NULL}; 152 const char * sections_data [] = {".data",".rodata",".bss",".sdata",".sbss", NULL}; 153 154 bool init_ok = true; 155 init_ok = init_ok and data->init("text" , filename, sections_text); 156 init_ok = init_ok and data->init("data" , filename, sections_data); 157 158 if (init_ok) 159 { 160 char * str = new char [8]; 161 162 data->read(0x100,8,str); 163 164 cout << "Read @100 : " << hex << "0x"; 165 for (uint32_t i=0; i<8; i++) 166 { 167 if (i==4) 168 cout << endl << "Read @104 : 0x"; 169 cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff); 170 } 171 cout << dec << endl; 172 173 str [0] = 0xde; 174 str [1] = 0xad; 175 str [2] = 0xbe; 176 str [3] = 0xef; 177 str [4] = 0xba; 178 str [5] = 0xbe; 179 str [6] = 0xbe; 180 str [7] = 0xef; 181 182 cout << "Write @104 : 0xdeadbeef" << endl; 183 cout << "Write @108 : 0xbabebeef" << endl; 184 185 data->write(0x104,8,str); 186 187 data->read(0x100,8,str); 188 189 cout << "Read @100 : " << hex << "0x"; 190 for (uint32_t i=0; i<8; i++) 191 { 192 if (i==4) 193 cout << endl << "Read @104 : 0x"; 194 cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff); 195 } 196 cout << dec << endl; 197 198 data->read(0x108,8,str); 199 200 cout << "Read @108 : " << hex << "0x"; 201 for (uint32_t i=0; i<8; i++) 202 { 203 if (i==4) 204 cout << endl << "Read @10C : 0x"; 205 cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff); 206 } 207 cout << dec << endl; 208 209 delete [] str; 210 } 211 212 delete data; 213 delete param; 214 delete segtable; 215 } 216 195 217 cout << "<main> End" << endl; 196 218 -
trunk/IPs/systemC/Environment/Data/src/Segment_init.cpp
r123 r138 9 9 void * ptab; 10 10 int size = this->size; 11 // int size = 0; 11 12 int offset = 0; 12 13 13 14 loadexec(&ptab,&size,&offset,filename,sections); 14 15 15 // std::cout << " - size : " << size << std::endl; 16 // std::cout << " - offset : " << offset << std::endl; 16 // std::cout << " - name : " << name << std::endl; 17 // std::cout << " - size : " << size << std::endl; 18 // std::cout << " - size : " << this->size << std::endl; 19 // std::cout << " - offset : " << offset << std::endl; 17 20 18 21 if (size > (int)this->size) … … 25 28 26 29 free (ptab); 27 28 30 29 31 // { -
trunk/IPs/systemC/Environment/Data/src/loadexec.c
r134 r138 73 73 return; 74 74 75 if ((sect->flags & SEC_LOAD) && !(sect->flags & SEC_IN_MEMORY)) { 76 bfd_get_section_contents(exec, sect, 77 rinfo->mem + (sect->lma - rinfo->ladr), 78 0, bfd_section_size(exec, sect)); 79 sect->contents = rinfo->mem; 75 if ((sect->flags & SEC_LOAD) && !(sect->flags & SEC_IN_MEMORY)) 76 { 77 /* #if 1 */ 78 /* printf(" * bindsection : \n"); */ 79 /* printf(" * exec : %x\n",(int)exec); */ 80 /* printf(" * sect : %x\n",(int)sect); */ 81 /* printf(" * size : %d\n",(int)(rinfo->mem + (sect->lma - rinfo->ladr))); */ 82 /* printf(" * mem : %d\n",(int)rinfo->mem); */ 83 /* printf(" * lma : %d\n",(int)sect->lma); */ 84 /* printf(" * ladr : %d\n",(int)rinfo->ladr); */ 85 /* fflush(stdout); */ 86 /* #endif */ 87 88 bfd_get_section_contents(exec, 89 sect, 90 rinfo->mem + (sect->lma - rinfo->ladr), 91 0, 92 bfd_section_size(exec, sect)); 93 sect->contents = rinfo->mem; 80 94 } 81 95 } … … 92 106 return; 93 107 108 /* #if 1 */ 109 /* printf(" * sectionsize : \n"); */ 110 /* printf(" * name : %s\n",rinfo->sections[i]); */ 111 /* printf(" * size (before): %d (%x)\n",rinfo->size,rinfo->size); */ 112 /* printf(" * ladr (before): %d (%x)\n",rinfo->ladr,rinfo->ladr); */ 113 /* printf(" * hadr (before): %d (%x)\n",rinfo->hadr,rinfo->hadr); */ 114 /* #endif */ 115 94 116 rinfo->size += bfd_section_size(exec, sect); 95 117 rinfo->ladr = sect->lma < rinfo->ladr ? sect->lma : rinfo->ladr; 96 118 rinfo->hadr = sect->lma + rinfo->size > rinfo->hadr ? 97 119 sect->lma + rinfo->size : rinfo->hadr; 120 121 /* #if 1 */ 122 /* printf(" * size (after ): %d (%x)\n",rinfo->size,rinfo->size); */ 123 /* printf(" * ladr (after ): %d (%x)\n",rinfo->ladr,rinfo->ladr); */ 124 /* printf(" * hadr (after ): %d (%x)\n",rinfo->hadr,rinfo->hadr); */ 125 /* #endif */ 126 98 127 } 99 128 100 129 void loadexec(void **emem, int *esize, int *eoffset, const char *file, const char **sections) 101 130 { 102 bfd *exec;103 131 static int x; 104 132 raminfo ringo; … … 107 135 bfd_init(); 108 136 109 exec = bfd_openr(file, NULL);137 bfd * exec = bfd_openr(file, NULL); 110 138 111 139 if (!exec) { … … 120 148 } 121 149 122 #if 0 123 cout("Loading sections "); 124 for (i = 0; sections[i]; i++) 125 __cout("%s%s", sections[i], ((sections[i+1]!=NULL)?", ":" ")); 126 __cout("from \"%s\"\n",bfd_get_filename(exec)); 127 //cout("of executable '%s' for '%s' architecture in format '%s'\n", 128 // bfd_get_filename(exec), bfd_printable_name(exec), exec->xvec->name); 129 #endif 150 /* #if 1 */ 151 /* printf(" * Loading sections from \"%s\" :\n",bfd_get_filename(exec)); */ 152 /* { */ 153 /* int i; */ 154 /* for (i = 0; sections[i]; i++) */ 155 /* printf(" * %s\n", sections[i]); */ 156 /* } */ 157 158 /* //cout("of executable '%s' for '%s' architecture in format '%s'\n", */ 159 /* // bfd_get_filename(exec), bfd_printable_name(exec), exec->xvec->name); */ 160 /* #endif */ 130 161 131 162 /* Set input parameters to bindsection */ … … 135 166 ringo.ladr = ~0; 136 167 ringo.hadr = 0; 168 ringo.mem = NULL; 169 137 170 bfd_map_over_sections(exec, sectionssize, &ringo); 171 172 /* #if 1 */ 173 /* printf(" * Meminfo : \n"); */ 174 /* printf(" * size : %d (%x)\n",ringo.size,ringo.size); */ 175 /* printf(" * esize : %d (%x)\n",*esize,*esize); */ 176 /* printf(" * ladr : %d (%x)\n",ringo.ladr,ringo.ladr); */ 177 /* printf(" * hadr : %d (%x)\n",ringo.hadr,ringo.hadr); */ 178 /* #endif */ 179 138 180 /* Get output parameters from sectionssize */ 139 181 if (ringo.size < ringo.hadr - ringo.ladr) … … 146 188 147 189 /* Start over again from the start of the memory */ 148 bfd_map_over_sections(exec, bindsection, &ringo); 190 bfd_map_over_sections(exec, 191 bindsection, 192 &ringo); 149 193 /* Get output parameters from bindsection */ 150 194
Note: See TracChangeset
for help on using the changeset viewer.