1 | #ifndef DATA_H |
---|
2 | #define DATA_H |
---|
3 | |
---|
4 | #include <stdint.h> |
---|
5 | #include <iostream> |
---|
6 | #include "segment.h" |
---|
7 | #include "shared/soclib_segment_table.h" |
---|
8 | |
---|
9 | using namespace std; |
---|
10 | |
---|
11 | namespace hierarchy_memory { |
---|
12 | namespace data { |
---|
13 | |
---|
14 | class entity_t |
---|
15 | { |
---|
16 | public : bool present; |
---|
17 | public : segment_t * segment; |
---|
18 | |
---|
19 | public : entity_t (bool present) |
---|
20 | { |
---|
21 | this->present = present; |
---|
22 | } |
---|
23 | |
---|
24 | public : entity_t (bool present , |
---|
25 | segment_t * segment ) |
---|
26 | { |
---|
27 | this->present = present; |
---|
28 | this->segment = segment; |
---|
29 | } |
---|
30 | |
---|
31 | friend ostream& operator<< (ostream& output_stream, const entity_t & x) |
---|
32 | { |
---|
33 | output_stream << x.present; |
---|
34 | if (x.present == true) |
---|
35 | output_stream << " " << *x.segment; |
---|
36 | |
---|
37 | return output_stream; |
---|
38 | } |
---|
39 | }; //end entity_t |
---|
40 | |
---|
41 | class param_t |
---|
42 | { |
---|
43 | public : char * name ; |
---|
44 | public : uint32_t max_seg ; |
---|
45 | public : unsigned int globalIndex; |
---|
46 | public : unsigned int localIndex ; |
---|
47 | public : SOCLIB_SEGMENT_TABLE * segtab ; |
---|
48 | |
---|
49 | public : param_t (char * name , |
---|
50 | uint32_t max_seg , |
---|
51 | unsigned int globalIndex, |
---|
52 | unsigned int localIndex , |
---|
53 | SOCLIB_SEGMENT_TABLE * segtab ) |
---|
54 | { |
---|
55 | this->name = name ; |
---|
56 | this->max_seg = max_seg ; |
---|
57 | this->globalIndex = globalIndex; |
---|
58 | this->localIndex = localIndex ; |
---|
59 | this->segtab = segtab ; |
---|
60 | } |
---|
61 | }; //end param_t |
---|
62 | |
---|
63 | class Data |
---|
64 | { |
---|
65 | private : char * name; |
---|
66 | protected : const uint32_t max_seg; |
---|
67 | protected : uint32_t nb_seg; |
---|
68 | protected : segment_t ** segment; |
---|
69 | |
---|
70 | public : Data (param_t param) : |
---|
71 | max_seg (param.max_seg) |
---|
72 | { |
---|
73 | uint32_t size_name = strlen(param.name)+1; |
---|
74 | name = new char [size_name]; |
---|
75 | strncpy(name,param.name,size_name); |
---|
76 | |
---|
77 | std::list<SEGMENT_TABLE_ENTRY> seglist = param.segtab->getSegmentList(param.globalIndex,param.localIndex); |
---|
78 | std::list<SEGMENT_TABLE_ENTRY>::iterator iter; |
---|
79 | nb_seg = 0; |
---|
80 | |
---|
81 | segment = new segment_t * [max_seg]; |
---|
82 | |
---|
83 | for (iter = seglist.begin() ; iter != seglist.end() ; ++iter , nb_seg ++) |
---|
84 | { |
---|
85 | SEGMENT_TABLE_ENTRY entry = *iter; |
---|
86 | if (nb_seg >= max_seg) |
---|
87 | { |
---|
88 | cerr << "The number of seg can't be higher that " << max_seg << endl; |
---|
89 | exit (1); |
---|
90 | } |
---|
91 | segment [nb_seg] = new segment_t (entry); |
---|
92 | |
---|
93 | param.segtab->setAddrAlloc(entry.getBase(),(void *)(segment [nb_seg]->data_addr())); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | //*****[ init ]***** |
---|
98 | public : bool init (char * section, const char * filename, const char ** list_section) |
---|
99 | { |
---|
100 | for (uint32_t it = 0; it < nb_seg; it ++) |
---|
101 | if (segment[it]->test(section) == true) |
---|
102 | return segment[it]->init(filename,list_section); |
---|
103 | |
---|
104 | return false; |
---|
105 | } |
---|
106 | |
---|
107 | //*****[ read ]***** |
---|
108 | // Read a lot of byte |
---|
109 | public : bool read (uint32_t address, uint32_t size, char * & data_dest) |
---|
110 | { |
---|
111 | uint32_t num_seg = 0; |
---|
112 | bool res = false; |
---|
113 | for (num_seg = 0; num_seg < nb_seg; num_seg ++) |
---|
114 | if (segment[num_seg]->test (address,size) == true) |
---|
115 | { |
---|
116 | segment[num_seg]->read (address,size,data_dest); |
---|
117 | res = true; |
---|
118 | break; |
---|
119 | } |
---|
120 | |
---|
121 | return res; |
---|
122 | } |
---|
123 | |
---|
124 | //*****[ entity ]***** |
---|
125 | public : entity_t entity (uint32_t address, uint32_t size) |
---|
126 | { |
---|
127 | for (uint32_t num_seg = 0; num_seg < nb_seg; num_seg ++) |
---|
128 | if (segment[num_seg]->test (address,size) == true) |
---|
129 | return entity_t (true,segment[num_seg]); |
---|
130 | |
---|
131 | return entity_t (false); |
---|
132 | } |
---|
133 | |
---|
134 | public : entity_t entity (char * name) |
---|
135 | { |
---|
136 | for (uint32_t num_seg = 0; num_seg < nb_seg; num_seg ++) |
---|
137 | if (segment[num_seg]->test(name) == true) |
---|
138 | return entity_t (true,segment[num_seg]); |
---|
139 | |
---|
140 | return entity_t (false); |
---|
141 | } |
---|
142 | |
---|
143 | //*****[ write ]***** |
---|
144 | // Write a lot of byte |
---|
145 | public : bool write (uint32_t address, uint32_t size, char * & data_src) |
---|
146 | { |
---|
147 | uint32_t num_seg = 0; |
---|
148 | bool res = false; |
---|
149 | for (num_seg = 0; num_seg < nb_seg; num_seg ++) |
---|
150 | if (segment[num_seg]->test (address,size) == true) |
---|
151 | { |
---|
152 | segment[num_seg]->write (address,size,data_src); |
---|
153 | res = true; |
---|
154 | break; |
---|
155 | } |
---|
156 | |
---|
157 | return res; |
---|
158 | } |
---|
159 | |
---|
160 | public : friend ostream& operator<< (ostream& output_stream, const Data & x) |
---|
161 | { |
---|
162 | output_stream << "<" << x.name << ">" << endl |
---|
163 | << " * nb_seg : " << x.nb_seg << endl |
---|
164 | << " * max_seg : " << x.max_seg << endl; |
---|
165 | |
---|
166 | for (uint32_t it = 0; it < x.nb_seg; it ++) |
---|
167 | output_stream << *x.segment[it] << endl; |
---|
168 | return output_stream; |
---|
169 | }; |
---|
170 | }; |
---|
171 | |
---|
172 | };}; //end namespace |
---|
173 | #endif //!DATA_H |
---|