3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
9 * 上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation
10 * によって公表されている GNU General Public License の Version 2 に記
11 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
12 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
14 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
15 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
18 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
19 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
21 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
22 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
24 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
25 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
26 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
28 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
29 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
31 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
32 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
33 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
34 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
36 * @(#) $Id: filecontainer.h,v 1.1 2009/01/31 05:27:37 suikan Exp $
39 // $Header: /cvsroot/toppersjsp4bf/jsp/cfg/base/filecontainer.h,v 1.1 2009/01/31 05:27:37 suikan Exp $
41 #ifndef FILECONTAINER_H
42 #define FILECONTAINER_H
45 #pragma warning(disable:4786) //デバッグ情報を255文字に切り詰めました
48 #include "testsuite.h"
53 #include "base/except.h"
54 #include "base/message.h"
55 #include "base/collection.h"
57 class FileContainer : public RuntimeObject
60 typedef unsigned long address_t;
62 struct tagVariableInfo {
70 enum tagByteOrder { LITTLE, BIG, HOSTORDER=LITTLE, UNKNOWN }; /* UNKNOWNはテスト用 */
73 enum tagByteOrder byteorder;
75 std::map<std::string, struct tagVariableInfo> variableinfo;
77 FileContainer(void) throw() : byteorder(HOSTORDER) {}
78 virtual ~FileContainer(void) throw() {}
82 virtual void attachModule(const std::string & filename) throw(Exception) = 0;
83 virtual void loadContents(void * dest, address_t address, size_t size) throw(Exception) = 0;
84 virtual address_t getSymbolAddress(const std::string & symbol) throw(Exception) = 0;
85 virtual std::string getArchitecture(void) throw(Exception) = 0;
87 virtual struct tagVariableInfo getVariableInfo(const std::string & name) throw(Exception);
88 virtual void attachInfo(const std::string & filename) throw(Exception);
90 /* 登録されているコンテナの呼び出し */
91 static inline FileContainer * getInstance(void) throw(Exception)
93 FileContainer * result;
94 RuntimeObjectTable::getInstance(&result);
96 ExceptionMessage("[Internal error] Filecontainer has no instance.","[内部エラー] FileContainerのインスタンスがありません").throwException();
100 enum tagByteOrder getByteOrder(void) const
101 { return byteorder; }
104 class TargetVariableBase
107 FileContainer::address_t address; //変数のアドレス
108 size_t size; //変数のサイズ
109 size_t offset; //属する構造体の先頭からのオフセット
110 size_t structure_size; //属する構造体の大きさ
111 bool loaded; //値が読出し済みであることを保持するフラグ
113 inline TargetVariableBase(FileContainer::address_t _address, size_t _size) throw()
114 : address(_address), size(_size), offset(0), structure_size(_size), loaded(false)
117 inline TargetVariableBase(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
118 : address(addr), size(sz), offset(ofs), structure_size(ssz), loaded(false)
121 TargetVariableBase(const std::string & sym) throw();
122 TargetVariableBase(const std::string & sym, size_t _size) throw();
123 TargetVariableBase(const std::string & sym, const std::string & sz) throw();
124 TargetVariableBase(const TargetVariableBase & src) throw();
126 virtual ~TargetVariableBase(void) throw() {}
129 void loadContent(void * dest, size_t dest_size) throw(Exception);
132 void changeEndian(char * buffer, size_t size) throw();
134 /* アドレスの移動 (ついでにloadedを下げる) */
135 inline void setAddress(int offset) throw()
144 inline bool isValid(void) const throw()
145 { return this != 0 && address != 0 && size != 0 && structure_size != 0; }
147 inline size_t getSize(void) const throw()
148 { return this != 0 ? size : 0; }
150 inline size_t getOffset(void) const throw()
151 { return this != 0 ? offset : 0; }
153 inline size_t getStructureSize(void) const throw()
154 { return this != 0 ? structure_size : 0; }
156 inline FileContainer::address_t getAddress(void) const throw()
157 { return this != 0 ? address : 0; }
159 inline bool isLoaded(void) const throw()
160 { return this != 0 ? loaded : false; }
163 inline bool operator == (const TargetVariableBase & right) const throw()
164 { return isValid() && right.isValid() && address == right.address; }
166 inline bool operator != (const TargetVariableBase & right) const throw()
167 { return ! operator ==(right); }
169 inline FileContainer::address_t operator & (void) const throw()
170 { return isValid() ? address + offset : 0; }
172 inline size_t sizeOf(void) const throw()
173 { return isValid() ? size : 0; }
177 class TargetVariable : public TargetVariableBase
184 * コンストラクタ (TargetVariableBaseに回送)
186 inline TargetVariable(FileContainer::address_t addr) throw()
187 : TargetVariableBase(addr, sizeof(T)), entity()
190 inline TargetVariable(FileContainer::address_t addr, size_t sz) throw()
191 : TargetVariableBase(addr, sz), entity()
194 inline TargetVariable(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
195 : TargetVariableBase(addr, sz, ofs, ssz), entity()
198 inline TargetVariable(const std::string & sym) throw()
199 : TargetVariableBase(sym), entity()
202 inline TargetVariable(const std::string & sym, const std::string & sz) throw()
203 : TargetVariableBase(sym, sz), entity()
206 inline TargetVariable(const TargetVariable<T> & src) throw()
207 : TargetVariableBase(src), entity()
209 if(isValid() && src.isValid()) {
215 /* デストラクタ (特に何もしない) */
216 virtual ~TargetVariable(void) throw()
219 /* 正当判定に格納に十分なサイズがあるかどうかを追加しておく */
220 inline bool isValid(void) const
221 { return TargetVariableBase::isValid() && (sizeof(T) >= getSize()); }
226 inline TargetVariable<T> offsetInBytes(int offset) const throw()
227 { return TargetVariable<T>(getAddress() + offset, getSize(), getOffset(), getStructureSize()); }
229 inline TargetVariable<T> operator + (int index) const throw()
230 { return offsetInBytes(index * static_cast<int>(getStructureSize())); }
232 inline TargetVariable<T> operator - (int index) const throw()
233 { return offsetInBytes(- index * static_cast<int>(getStructureSize())); }
235 inline TargetVariable<T> operator ++ (int) throw()
237 TargetVariable<T> result(*this);
242 inline TargetVariable<T> operator -- (int) throw()
244 TargetVariable<T> result(*this);
249 inline TargetVariable<T> & operator ++ (void) throw()
251 setAddress(static_cast<int>(getStructureSize()));
255 inline TargetVariable<T> & operator -- (void) throw()
257 setAddress(-static_cast<int>(getStructureSize()));
261 inline TargetVariable<T> & operator += (int sz) throw()
263 setAddress(static_cast<int>(getStructureSize()) * sz);
267 inline TargetVariable<T> & operator -= (int sz) throw()
269 setAddress(-static_cast<int>(getStructureSize()) * sz);
273 inline const T & operator * (void) throw(Exception)
276 loadContent(&entity, sizeof(T));
280 inline T operator [] (int index) const throw(Exception)
281 { return * TargetVariable<T>(getAddress() + index * getStructureSize(), getSize(), getOffset(), getStructureSize()); }