[2] | 1 | #include "data.h" |
---|
| 2 | #include <iostream> |
---|
| 3 | |
---|
| 4 | #define TEXT_BASE 0x00000000 |
---|
| 5 | #define TEXT_SIZE 0x00005000 |
---|
| 6 | |
---|
| 7 | #define DATA_CACHED_BASE 0x10000000 |
---|
| 8 | #define DATA_CACHED_SIZE 0x00000100 |
---|
| 9 | |
---|
| 10 | #define DATA_UNCACHED_BASE 0x40000000 |
---|
| 11 | #define DATA_UNCACHED_SIZE 0x00000100 |
---|
| 12 | |
---|
| 13 | #define STACK_BASE 0x50000000 |
---|
| 14 | #define STACK_SIZE 0x00000200 |
---|
| 15 | |
---|
| 16 | #define TTY_BASE 0x60000000 |
---|
| 17 | #define TTY_SIZE 0x00000100 |
---|
| 18 | |
---|
| 19 | #define SIM2OS_BASE 0x70000000 |
---|
| 20 | #define SIM2OS_SIZE 0x00000100 |
---|
| 21 | |
---|
| 22 | #define RAMLOCK_BASE 0x80000000 |
---|
| 23 | #define RAMLOCK_SIZE 0x00000100 |
---|
| 24 | |
---|
| 25 | using namespace hierarchy_memory::data; |
---|
| 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | void test_ko (int val) |
---|
| 29 | { |
---|
| 30 | cout << "***** Test(" << val << ") KO *****" << endl; |
---|
| 31 | exit (val); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void test_ok () |
---|
| 35 | { |
---|
| 36 | cout << "***** Test OK *****" << endl; |
---|
| 37 | exit (0); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | static uint32_t num_test = 1; |
---|
| 41 | |
---|
| 42 | template <class T> |
---|
| 43 | void test(T exp1, T exp2) |
---|
| 44 | { |
---|
| 45 | if (exp1 != exp2) |
---|
| 46 | test_ko (num_test); |
---|
| 47 | num_test ++; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | int main () |
---|
| 51 | { |
---|
| 52 | cout << "<main> Test de \"Data\"" << endl; |
---|
| 53 | |
---|
| 54 | cout << " * Create a Data" << endl; |
---|
| 55 | |
---|
| 56 | SOCLIB_SEGMENT_TABLE segtable; |
---|
| 57 | segtable.setMSBNumber (8); |
---|
| 58 | segtable.setDefaultTarget(0,0); |
---|
| 59 | |
---|
| 60 | //shared data segment |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | // Add a segment :name , address of base , size , global index , local index, uncache |
---|
| 65 | segtable.addSegment("text" , TEXT_BASE , TEXT_SIZE , 0 ,0 , false); |
---|
| 66 | segtable.addSegment("data" , DATA_CACHED_BASE , DATA_CACHED_SIZE , 0 ,0 , false); |
---|
| 67 | segtable.addSegment("data_unc" , DATA_UNCACHED_BASE , DATA_UNCACHED_SIZE , 0 ,0 , true ); |
---|
| 68 | segtable.addSegment("stack" , STACK_BASE , STACK_SIZE , 0 ,0 , false); |
---|
| 69 | segtable.addSegment("tty" , TTY_BASE , TTY_SIZE , 0 ,0 , true ); |
---|
| 70 | segtable.addSegment("sim2os" , SIM2OS_BASE , SIM2OS_SIZE , 0 ,0 , true ); |
---|
| 71 | segtable.addSegment("ramlock" , RAMLOCK_BASE , RAMLOCK_SIZE , 0 ,0 , true ); |
---|
| 72 | |
---|
| 73 | Data my_data = Data(param_t("my_data",16,0,0,&segtable)); |
---|
| 74 | |
---|
| 75 | const char * sections_text [] = {".text",NULL}; |
---|
| 76 | const char * sections_data [] = {".data",".rodata",".sdata",".sbss",".bss", NULL}; |
---|
| 77 | const char * sections_stack [] = {".stack",NULL}; |
---|
| 78 | const char * filename = "soft.x"; |
---|
| 79 | |
---|
| 80 | test <bool> (my_data.init("text" , filename, sections_text) ,true); |
---|
| 81 | test <bool> (my_data.init("stack" , filename, sections_stack),true); |
---|
| 82 | test <bool> (my_data.init("data" , filename, sections_data) ,true); |
---|
| 83 | |
---|
| 84 | segtable.print(); |
---|
| 85 | |
---|
| 86 | cout << my_data << endl; |
---|
| 87 | |
---|
| 88 | uint32_t size, offset; |
---|
| 89 | char * data = new char [100]; |
---|
| 90 | |
---|
| 91 | // ************************************************************* |
---|
| 92 | offset = 0; |
---|
| 93 | size = 32; |
---|
| 94 | |
---|
| 95 | cout << " * Read of bytes [" << DATA_CACHED_BASE+offset << ":" << DATA_CACHED_BASE+offset+size << "[" << endl; |
---|
| 96 | |
---|
| 97 | test <bool> (my_data.read(DATA_CACHED_BASE+offset,size,data), true); |
---|
| 98 | |
---|
| 99 | for (uint32_t it = 0; it < size; it ++) |
---|
| 100 | { |
---|
| 101 | if (it % 4 == 0) |
---|
| 102 | printf("\n"); |
---|
| 103 | |
---|
| 104 | printf("%.2x",(unsigned char)(data[it])); |
---|
| 105 | } |
---|
| 106 | printf("\n"); |
---|
| 107 | |
---|
| 108 | // ************************************************************* |
---|
| 109 | offset = 8; |
---|
| 110 | size = 16; |
---|
| 111 | char * data_src = new char [100]; |
---|
| 112 | sprintf(data_src,"123456780abcdef0"); |
---|
| 113 | |
---|
| 114 | cout << " * Write of bytes [" << DATA_CACHED_BASE+offset << ":" << DATA_CACHED_BASE+offset+size << "[" << endl; |
---|
| 115 | |
---|
| 116 | test <bool> (my_data.write(DATA_CACHED_BASE+offset,size,data_src), true); |
---|
| 117 | |
---|
| 118 | for (uint32_t it = 0; it < size; it ++) |
---|
| 119 | { |
---|
| 120 | if (it % 4 == 0) |
---|
| 121 | printf("\n"); |
---|
| 122 | |
---|
| 123 | printf("%.2x",(unsigned char)(data_src[it])); |
---|
| 124 | } |
---|
| 125 | printf("\n"); |
---|
| 126 | |
---|
| 127 | // ************************************************************* |
---|
| 128 | offset = 0; |
---|
| 129 | size = 32; |
---|
| 130 | cout << " * Read of bytes [" << DATA_CACHED_BASE+offset << ":" << DATA_CACHED_BASE+offset+size << "[" << endl; |
---|
| 131 | |
---|
| 132 | test <bool> (my_data.read(DATA_CACHED_BASE+offset,size,data), true); |
---|
| 133 | |
---|
| 134 | for (uint32_t it = 0; it < size; it ++) |
---|
| 135 | { |
---|
| 136 | if (it % 4 == 0) |
---|
| 137 | printf("\n"); |
---|
| 138 | |
---|
| 139 | printf("%.2x",(unsigned char)(data[it])); |
---|
| 140 | } |
---|
| 141 | printf("\n"); |
---|
| 142 | |
---|
| 143 | // ************************************************************* |
---|
| 144 | |
---|
| 145 | cout << " * Recherche of address" << endl; |
---|
| 146 | test<bool> (my_data.entity(0x00000034, 2).present,true ); |
---|
| 147 | test<bool> (my_data.entity(0x00005000, 1).present,false); |
---|
| 148 | test<bool> (my_data.entity(0x00004FFD, 2).present,true ); |
---|
| 149 | test<bool> (my_data.entity(0x00004FFD, 4).present,false); |
---|
| 150 | test<bool> (my_data.entity(0x10000000, 1).present,true ); |
---|
| 151 | test<bool> (my_data.entity(0x0FFFFFFF,10).present,false); |
---|
| 152 | |
---|
| 153 | cout << " * Typage" << endl; |
---|
| 154 | cout << my_data.entity(TTY_BASE,TTY_SIZE) << endl; |
---|
| 155 | my_data.entity(TTY_BASE,TTY_SIZE).segment->define_target (TYPE_TTY,0); |
---|
| 156 | cout << my_data.entity(TTY_BASE,TTY_SIZE) << endl; |
---|
| 157 | |
---|
| 158 | cout << my_data.entity("ramlock") << endl; |
---|
| 159 | my_data.entity("ramlock").segment->define_target (TYPE_RAMLOCK,0); |
---|
| 160 | cout << my_data.entity("ramlock") << endl; |
---|
| 161 | |
---|
| 162 | test_ok (); |
---|
| 163 | } |
---|