1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | *
|
---|
9 | * ä¸è¨è使¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
11 | * ã«ãã£ã¦å
|
---|
12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
15 | å¸ï¼ä»¥ä¸ï¼
|
---|
16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
21 | * ç¨ã§ããå½¢ã§åé
|
---|
22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
24 | * è
|
---|
25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
30 | * ã¨ï¼
|
---|
31 | * (a) åé
|
---|
32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
34 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
35 | * (b) åé
|
---|
36 | å¸ã®å½¢æ
|
---|
37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
38 | * å ±åãããã¨ï¼
|
---|
39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
40 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
42 | 責ãããã¨ï¼
|
---|
43 | *
|
---|
44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
45 | ã
|
---|
46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
49 | *
|
---|
50 | * @(#) $Id: filecontainer.h,v 1.8 2003/12/15 07:32:13 takayuki Exp $
|
---|
51 | */
|
---|
52 |
|
---|
53 | // $Header: /home/CVS/configurator/base/filecontainer.h,v 1.8 2003/12/15 07:32:13 takayuki Exp $
|
---|
54 |
|
---|
55 | #ifndef FILECONTAINER_H
|
---|
56 | #define FILECONTAINER_H
|
---|
57 |
|
---|
58 | #ifdef _MSC_VER
|
---|
59 | #pragma warning(disable:4786) //ãããã°æ
|
---|
60 | å ±ã255æåã«åãè©°ãã¾ãã
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #include "testsuite.h"
|
---|
64 |
|
---|
65 | #include <string>
|
---|
66 | #include <map>
|
---|
67 |
|
---|
68 | #include "base/except.h"
|
---|
69 | #include "base/message.h"
|
---|
70 | #include "base/collection.h"
|
---|
71 |
|
---|
72 | class FileContainer : public RuntimeObject
|
---|
73 | {
|
---|
74 | public:
|
---|
75 | typedef unsigned long address_t;
|
---|
76 |
|
---|
77 | struct tagVariableInfo {
|
---|
78 | address_t address;
|
---|
79 | union {
|
---|
80 | size_t size;
|
---|
81 | int value;
|
---|
82 | };
|
---|
83 | };
|
---|
84 |
|
---|
85 | enum tagByteOrder { LITTLE, BIG, HOSTORDER=LITTLE, UNKNOWN }; /* UNKNOWNã¯ãã¹ãç¨ */
|
---|
86 |
|
---|
87 | protected:
|
---|
88 | enum tagByteOrder byteorder;
|
---|
89 |
|
---|
90 | std::map<std::string, struct tagVariableInfo> variableinfo;
|
---|
91 |
|
---|
92 | FileContainer(void) throw() : byteorder(HOSTORDER) {}
|
---|
93 | virtual ~FileContainer(void) throw() {}
|
---|
94 |
|
---|
95 | public:
|
---|
96 | /* ã¤ã³ã¿ãã§ã¼ã¹é¨ */
|
---|
97 | virtual void attachModule(const std::string & filename) throw(Exception) = 0;
|
---|
98 | virtual void loadContents(void * dest, address_t address, size_t size) throw(Exception) = 0;
|
---|
99 | virtual address_t getSymbolAddress(const std::string & symbol) throw(Exception) = 0;
|
---|
100 | virtual std::string getArchitecture(void) throw(Exception) = 0;
|
---|
101 |
|
---|
102 | virtual struct tagVariableInfo getVariableInfo(const std::string & name) throw(Exception);
|
---|
103 | virtual void attachInfo(const std::string & filename) throw(Exception);
|
---|
104 |
|
---|
105 | /* ç»é²ããã¦ããã³ã³ããã®å¼ã³åºã */
|
---|
106 | static inline FileContainer * getInstance(void) throw(Exception)
|
---|
107 | {
|
---|
108 | FileContainer * result;
|
---|
109 | RuntimeObjectTable::getInstance(&result);
|
---|
110 | if(result == 0)
|
---|
111 | ExceptionMessage("[Internal error] Filecontainer has no instance.","[å
|
---|
112 | é¨ã¨ã©ã¼] FileContainerã®ã¤ã³ã¹ã¿ã³ã¹ãããã¾ãã").throwException();
|
---|
113 | return result;
|
---|
114 | }
|
---|
115 |
|
---|
116 | enum tagByteOrder getByteOrder(void) const
|
---|
117 | { return byteorder; }
|
---|
118 | };
|
---|
119 |
|
---|
120 | class TargetVariableBase
|
---|
121 | {
|
---|
122 | protected:
|
---|
123 | FileContainer::address_t address; //夿°ã®ã¢ãã¬ã¹
|
---|
124 | size_t size; //夿°ã®ãµã¤ãº
|
---|
125 | size_t offset; //å±ããæ§é ä½ã®å
|
---|
126 | é ããã®ãªãã»ãã
|
---|
127 | size_t structure_size; //å±ããæ§é ä½ã®å¤§ãã
|
---|
128 | bool loaded; //å¤ãèªåºãæ¸ã¿ã§ãããã¨ãä¿æãããã©ã°
|
---|
129 |
|
---|
130 | inline TargetVariableBase(FileContainer::address_t _address, size_t _size) throw()
|
---|
131 | : address(_address), size(_size), offset(0), structure_size(_size), loaded(false)
|
---|
132 | {}
|
---|
133 |
|
---|
134 | inline TargetVariableBase(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
|
---|
135 | : address(addr), size(sz), offset(ofs), structure_size(ssz), loaded(false)
|
---|
136 | {}
|
---|
137 |
|
---|
138 | TargetVariableBase(const std::string & sym) throw();
|
---|
139 | TargetVariableBase(const std::string & sym, size_t _size) throw();
|
---|
140 | TargetVariableBase(const std::string & sym, const std::string & sz) throw();
|
---|
141 | TargetVariableBase(const TargetVariableBase & src) throw();
|
---|
142 |
|
---|
143 | virtual ~TargetVariableBase(void) throw() {}
|
---|
144 |
|
---|
145 | /* å
|
---|
146 | 容ã®åå¾ */
|
---|
147 | void loadContent(void * dest, size_t dest_size) throw(Exception);
|
---|
148 |
|
---|
149 | /* ã¨ã³ãã£ã¢ã³å¤æ */
|
---|
150 | void changeEndian(char * buffer, size_t size) throw();
|
---|
151 |
|
---|
152 | /* ã¢ãã¬ã¹ã®ç§»å (ã¤ãã§ã«loadedãä¸ãã) */
|
---|
153 | inline void setAddress(int offset) throw()
|
---|
154 | {
|
---|
155 | if(isValid()) {
|
---|
156 | address += offset;
|
---|
157 | loaded = false;
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | public:
|
---|
162 | inline bool isValid(void) const throw()
|
---|
163 | { return this != 0 && address != 0 && size != 0 && structure_size != 0; }
|
---|
164 |
|
---|
165 | inline size_t getSize(void) const throw()
|
---|
166 | { return this != 0 ? size : 0; }
|
---|
167 |
|
---|
168 | inline size_t getOffset(void) const throw()
|
---|
169 | { return this != 0 ? offset : 0; }
|
---|
170 |
|
---|
171 | inline size_t getStructureSize(void) const throw()
|
---|
172 | { return this != 0 ? structure_size : 0; }
|
---|
173 |
|
---|
174 | inline FileContainer::address_t getAddress(void) const throw()
|
---|
175 | { return this != 0 ? address : 0; }
|
---|
176 |
|
---|
177 | inline bool isLoaded(void) const throw()
|
---|
178 | { return this != 0 ? loaded : false; }
|
---|
179 |
|
---|
180 | /* åºæ¬çãªæä½ */
|
---|
181 | inline bool operator == (const TargetVariableBase & right) const throw()
|
---|
182 | { return isValid() && right.isValid() && address == right.address; }
|
---|
183 |
|
---|
184 | inline bool operator != (const TargetVariableBase & right) const throw()
|
---|
185 | { return ! operator ==(right); }
|
---|
186 |
|
---|
187 | inline FileContainer::address_t operator & (void) const throw()
|
---|
188 | { return isValid() ? address + offset : 0; }
|
---|
189 |
|
---|
190 | inline size_t sizeOf(void) const throw()
|
---|
191 | { return isValid() ? size : 0; }
|
---|
192 | };
|
---|
193 |
|
---|
194 | template<class T>
|
---|
195 | class TargetVariable : public TargetVariableBase
|
---|
196 | {
|
---|
197 | protected:
|
---|
198 | T entity;
|
---|
199 |
|
---|
200 | public:
|
---|
201 | /*
|
---|
202 | * ã³ã³ã¹ãã©ã¯ã¿ (TargetVariableBaseã«åé)
|
---|
203 | */
|
---|
204 | inline TargetVariable(FileContainer::address_t addr) throw()
|
---|
205 | : TargetVariableBase(addr, sizeof(T)), entity()
|
---|
206 | {}
|
---|
207 |
|
---|
208 | inline TargetVariable(FileContainer::address_t addr, size_t sz) throw()
|
---|
209 | : TargetVariableBase(addr, sz), entity()
|
---|
210 | {}
|
---|
211 |
|
---|
212 | inline TargetVariable(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
|
---|
213 | : TargetVariableBase(addr, sz, ofs, ssz), entity()
|
---|
214 | {}
|
---|
215 |
|
---|
216 | inline TargetVariable(const std::string & sym) throw()
|
---|
217 | : TargetVariableBase(sym), entity()
|
---|
218 | {}
|
---|
219 |
|
---|
220 | inline TargetVariable(const std::string & sym, const std::string & sz) throw()
|
---|
221 | : TargetVariableBase(sym, sz), entity()
|
---|
222 | {}
|
---|
223 |
|
---|
224 | inline TargetVariable(const TargetVariable<T> & src) throw()
|
---|
225 | : TargetVariableBase(src), entity()
|
---|
226 | {
|
---|
227 | if(isValid() && src.isValid()) {
|
---|
228 | loaded = src.loaded;
|
---|
229 | entity = src.entity;
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | /* ãã¹ãã©ã¯ã¿ (ç¹ã«ä½ãããªã) */
|
---|
234 | virtual ~TargetVariable(void) throw()
|
---|
235 | {}
|
---|
236 |
|
---|
237 | /* æ£å½å¤å®ã«æ ¼ç´ã«ååãªãµã¤ãºããããã©ããã追å ãã¦ãã */
|
---|
238 | inline bool isValid(void) const
|
---|
239 | { return TargetVariableBase::isValid() && (sizeof(T) >= getSize()); }
|
---|
240 |
|
---|
241 | /*
|
---|
242 | * ãã¤ã³ã¿é¢¨ã®åä½ããããªãã¬ã¼ã¿ç¾¤
|
---|
243 | */
|
---|
244 | inline TargetVariable<T> offsetInBytes(int offset) const throw()
|
---|
245 | { return TargetVariable<T>(getAddress() + offset, getSize(), getOffset(), getStructureSize()); }
|
---|
246 |
|
---|
247 | inline TargetVariable<T> operator + (int index) const throw()
|
---|
248 | { return offsetInBytes(index * static_cast<int>(getStructureSize())); }
|
---|
249 |
|
---|
250 | inline TargetVariable<T> operator - (int index) const throw()
|
---|
251 | { return offsetInBytes(- index * static_cast<int>(getStructureSize())); }
|
---|
252 |
|
---|
253 | inline TargetVariable<T> operator ++ (int) throw()
|
---|
254 | {
|
---|
255 | TargetVariable<T> result(*this);
|
---|
256 | ++ (*this);
|
---|
257 | return result;
|
---|
258 | }
|
---|
259 |
|
---|
260 | inline TargetVariable<T> operator -- (int) throw()
|
---|
261 | {
|
---|
262 | TargetVariable<T> result(*this);
|
---|
263 | -- (*this);
|
---|
264 | return result;
|
---|
265 | }
|
---|
266 |
|
---|
267 | inline TargetVariable<T> & operator ++ (void) throw()
|
---|
268 | {
|
---|
269 | setAddress(static_cast<int>(getStructureSize()));
|
---|
270 | return *this;
|
---|
271 | }
|
---|
272 |
|
---|
273 | inline TargetVariable<T> & operator -- (void) throw()
|
---|
274 | {
|
---|
275 | setAddress(-static_cast<int>(getStructureSize()));
|
---|
276 | return *this;
|
---|
277 | }
|
---|
278 |
|
---|
279 | inline TargetVariable<T> & operator += (int sz) throw()
|
---|
280 | {
|
---|
281 | setAddress(static_cast<int>(getStructureSize()) * sz);
|
---|
282 | return *this;
|
---|
283 | }
|
---|
284 |
|
---|
285 | inline TargetVariable<T> & operator -= (int sz) throw()
|
---|
286 | {
|
---|
287 | setAddress(-static_cast<int>(getStructureSize()) * sz);
|
---|
288 | return *this;
|
---|
289 | }
|
---|
290 |
|
---|
291 | inline const T & operator * (void) throw(Exception)
|
---|
292 | {
|
---|
293 | if(!isLoaded())
|
---|
294 | loadContent(&entity, sizeof(T));
|
---|
295 | return entity;
|
---|
296 | }
|
---|
297 |
|
---|
298 | inline T operator [] (int index) const throw(Exception)
|
---|
299 | { return * TargetVariable<T>(getAddress() + index * getStructureSize(), getSize(), getOffset(), getStructureSize()); }
|
---|
300 | };
|
---|
301 |
|
---|
302 | #endif
|
---|
303 |
|
---|