Changeset 138 for trunk/IPs/systemC/Environment/Data/selftest
- Timestamp:
- May 12, 2010, 7:34:01 PM (14 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.