[138] | 1 | #ifdef SYSTEMC |
---|
| 2 | #include "systemc.h" |
---|
| 3 | #endif |
---|
[81] | 4 | #include <iostream> |
---|
| 5 | #include "../include/Data.h" |
---|
[138] | 6 | #include "../../../shared/mapping_memory.h" |
---|
[81] | 7 | |
---|
| 8 | using namespace std; |
---|
| 9 | using namespace environment; |
---|
| 10 | using namespace environment::data; |
---|
| 11 | |
---|
| 12 | #define TEST(x,y) \ |
---|
| 13 | { \ |
---|
| 14 | cout << "Line " << __LINE__ << " : "; \ |
---|
| 15 | if (x==y) \ |
---|
| 16 | { \ |
---|
| 17 | cout << "Test OK" << endl; \ |
---|
| 18 | } \ |
---|
| 19 | else \ |
---|
| 20 | { \ |
---|
| 21 | cout << "Test KO" << endl; \ |
---|
| 22 | exit (EXIT_FAILURE); \ |
---|
| 23 | } \ |
---|
| 24 | } while (0) |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | #ifdef SYSTEMC |
---|
| 29 | int sc_main (int argc, char * argv[]) |
---|
| 30 | #else |
---|
| 31 | int main (int argc, char * argv[]) |
---|
| 32 | #endif |
---|
| 33 | { |
---|
| 34 | cout << "<main> Begin" << endl; |
---|
| 35 | |
---|
[138] | 36 | const bool test1 = false; // |
---|
| 37 | const bool test2 = true; // |
---|
[81] | 38 | |
---|
[138] | 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; |
---|
[81] | 54 | |
---|
[138] | 55 | SEGMENT_TABLE_ENTRY * entry = new SEGMENT_TABLE_ENTRY("entry", 0x100, 0x1024, 21, 7, true); |
---|
[81] | 56 | |
---|
[138] | 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 | } |
---|
[81] | 116 | |
---|
[138] | 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}; |
---|
[81] | 153 | |
---|
[138] | 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; |
---|
[81] | 208 | |
---|
[138] | 209 | delete [] str; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | delete data; |
---|
| 213 | delete param; |
---|
| 214 | delete segtable; |
---|
| 215 | } |
---|
[81] | 216 | |
---|
| 217 | cout << "<main> End" << endl; |
---|
| 218 | |
---|
| 219 | return EXIT_SUCCESS; |
---|
| 220 | } |
---|