[54] | 1 | /*
|
---|
| 2 | * TOPPERS/ASP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Advanced Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
|
---|
| 7 | *
|
---|
| 8 | * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 9 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 10 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 11 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 12 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 13 | * スコード中に含まれていること.
|
---|
| 14 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 15 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 16 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 17 | * の無保証規定を掲載すること.
|
---|
| 18 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 19 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 20 | * と.
|
---|
| 21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 24 | * 報告すること.
|
---|
| 25 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 26 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 27 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 28 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 29 | * 免責すること.
|
---|
| 30 | *
|
---|
| 31 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 32 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 33 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 34 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 35 | * の責任を負わない.
|
---|
| 36 | *
|
---|
| 37 | */
|
---|
| 38 | #include <fstream>
|
---|
| 39 | #include <map>
|
---|
| 40 | #include "toppers/workaround.hpp"
|
---|
| 41 | #include "toppers/s_record.hpp"
|
---|
| 42 | #include "toppers/nm_symbol.hpp"
|
---|
| 43 | #include "toppers/misc.hpp"
|
---|
| 44 | #include "toppers/diagnostics.hpp"
|
---|
| 45 | #include "toppers/itronx/checker.hpp"
|
---|
| 46 | #include "toppers/itronx/cfg1_out.hpp"
|
---|
| 47 |
|
---|
| 48 | namespace toppers
|
---|
| 49 | {
|
---|
| 50 | namespace itronx
|
---|
| 51 | {
|
---|
| 52 |
|
---|
| 53 | struct checker::implementation
|
---|
| 54 | {
|
---|
| 55 | protected:
|
---|
| 56 | std::tr1::shared_ptr< s_record > srec_;
|
---|
| 57 | std::tr1::shared_ptr< nm_symbol > syms_;
|
---|
| 58 |
|
---|
| 59 | virtual ~implementation() {}
|
---|
| 60 | virtual bool do_check( cfg1_out& cfg1out, std::map< std::string, std::size_t > const& count_map )
|
---|
| 61 | {
|
---|
| 62 | return true;
|
---|
| 63 | }
|
---|
| 64 | virtual implementation* do_clone() const
|
---|
| 65 | {
|
---|
| 66 | return new implementation( *this );
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | friend class checker;
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | checker::checker()
|
---|
| 73 | : pimpl_( new implementation )
|
---|
| 74 | {
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | /*!
|
---|
| 78 | * \brief コピーコンストラクタ
|
---|
| 79 | * \param[in] コピー元
|
---|
| 80 | */
|
---|
| 81 | checker::checker( checker const& other )
|
---|
| 82 | : pimpl_( other.pimpl_->do_clone() )
|
---|
| 83 | {
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | //! デストラクタ
|
---|
| 87 | checker::~checker()
|
---|
| 88 | {
|
---|
| 89 | delete pimpl_;
|
---|
| 90 | pimpl_ = 0;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /*!
|
---|
| 94 | * \brief ROMイメージのロード
|
---|
| 95 | * \param[in] srec_file Sレコード形式のファイル名
|
---|
| 96 | * \param[in] nm_file nmコマンドが出力したシンボルテーブルのファイル名
|
---|
| 97 | */
|
---|
| 98 | void checker::load_rom_image( std::string const& srec_file, std::string const& nm_file )
|
---|
| 99 | {
|
---|
| 100 | std::ifstream ifs_srec( srec_file.c_str() );
|
---|
| 101 | if ( !ifs_srec.is_open() )
|
---|
| 102 | {
|
---|
| 103 | fatal( _( "cannot open file `%1%\'" ), srec_file );
|
---|
| 104 | }
|
---|
| 105 | std::tr1::shared_ptr< s_record > srec( new s_record( ifs_srec ) );
|
---|
| 106 |
|
---|
| 107 | std::ifstream ifs_nm( nm_file.c_str() );
|
---|
| 108 | if ( !ifs_nm.is_open() )
|
---|
| 109 | {
|
---|
| 110 | fatal( _( "cannot open file `%1%\'" ), nm_file );
|
---|
| 111 | }
|
---|
| 112 | std::tr1::shared_ptr< nm_symbol > syms( new nm_symbol( ifs_nm ) );
|
---|
| 113 |
|
---|
| 114 | pimpl_->srec_.swap( srec );
|
---|
| 115 | pimpl_->syms_.swap( syms );
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | /*!
|
---|
| 119 | * \brief チェックの実施
|
---|
| 120 | * \param[in] cfg1_out情報
|
---|
| 121 | */
|
---|
| 122 | bool checker::check( cfg1_out& cfg1out ) const
|
---|
| 123 | {
|
---|
| 124 | cfg1_out::static_api_map api_map( cfg1out.merge() );
|
---|
| 125 |
|
---|
| 126 | std::map< std::string, std::size_t > count_map;
|
---|
| 127 | for ( cfg1_out::static_api_map::const_iterator iter( api_map.begin() ), last( api_map.end() );
|
---|
| 128 | iter != last;
|
---|
| 129 | ++iter )
|
---|
| 130 | {
|
---|
| 131 | std::size_t count = 0;
|
---|
| 132 | for ( std::vector< static_api >::const_iterator iter2( iter->second.begin() ), last2( iter->second.end() );
|
---|
| 133 | iter2 != last2;
|
---|
| 134 | ++iter2 )
|
---|
| 135 | {
|
---|
| 136 | if ( !iter2->get_info()->slave )
|
---|
| 137 | {
|
---|
| 138 | ++count;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | count_map[ iter->first ] = count;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | return pimpl_->do_check( cfg1out, count_map );
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | /*!
|
---|
| 148 | * \brief シンボル情報の検索
|
---|
| 149 | * \param[in] symbol 検索するシンボル名
|
---|
| 150 | * \return 検索結果
|
---|
| 151 | *
|
---|
| 152 | * 検索に失敗した場合には、返却値の.typeフィールドに-1が設定される。
|
---|
| 153 | */
|
---|
| 154 | nm_symbol::entry checker::find( std::string const& symbol ) const
|
---|
| 155 | {
|
---|
| 156 | return pimpl_->syms_->find( symbol );
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /*!
|
---|
| 160 | * \brief 指定アドレスの整数値を取得
|
---|
| 161 | * \param[in] address アドレス
|
---|
| 162 | * \param[in] size 整数値を構成するバイト数
|
---|
| 163 | * \param[in] little_endian バイトオーダーがリトルエンディアンならtrueを指定する
|
---|
| 164 | * \return 取得した整数値を符号無しで返す。
|
---|
| 165 | */
|
---|
| 166 | std::tr1::uintmax_t checker::get( std::size_t address, std::size_t size, bool little_endian ) const
|
---|
| 167 | {
|
---|
| 168 | return pimpl_->srec_->get_value( address, size, little_endian );
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | }
|
---|
| 172 | }
|
---|