kernel_chk.cpp

00001 /*
00002  *  TOPPERS/FDMP Kernel
00003  *      Toyohashi Open Platform for Embedded Real-Time Systems/
00004  *      Function Distributed Multiprocessor Kernel
00005  *
00006  *  Copyright (C) 2005 by Takagi Nobuhisa
00007  * 
00008  *  上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation 
00009  *  によって公表されている GNU General Public License の Version 2 に記
00010  *  述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
00011  *  を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
00012  *  利用と呼ぶ)することを無償で許諾する.
00013  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
00014  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
00015  *      スコード中に含まれていること.
00016  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
00017  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
00018  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
00019  *      の無保証規定を掲載すること.
00020  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
00021  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
00022  *      と.
00023  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
00024  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
00025  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
00026  *        報告すること.
00027  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
00028  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
00029  * 
00030  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
00031  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
00032  *  含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
00033  *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
00034  * 
00035  */
00036 
00037 /*
00038  *  toppers/itron/kernel_chk.cpp
00039  */
00040 #include "toppers/itron/kernel_chk.hpp"
00041 #include "toppers/itron/cfg_contents.hpp"
00042 #include "toppers/itron/kernel_object.hpp"
00043 #include "toppers/s_record.hpp"
00044 #include "toppers/reporter.hpp"
00045 
00046 namespace toppers
00047 {
00048   namespace itron
00049   {
00050 
00058     void kernel_chk::load( const s_record& srec, unsigned long address )
00059     {
00060       if ( address == ~0UL )
00061       {
00062         address = srec.lower_bound();
00063       }
00064       byteorder_ = unknown;
00065 
00066       while ( !do_load( srec, address ) )
00067       {
00068         if ( srec.upper_bound() <= address + 1 )
00069         {
00070           error( _( "illegal check script" ) );
00071         }
00072       }
00073     }
00074 
00082     long kernel_chk::countof( const std::string& object_type ) const
00083     {
00084       std::map<std::string, long>::const_iterator iter( countof_map_.find( object_type ) );
00085       if ( iter != countof_map_.end() )
00086       {
00087         return iter->second;
00088       }
00089       return 0;
00090     }
00091 
00097     unsigned long kernel_chk::get( int key ) const
00098     {
00099       if ( key < 0 || static_cast<int>( table_.size() ) <= key )
00100       {
00101         return 0;
00102       }
00103       return table_[key];
00104     }
00105 
00115     void kernel_chk::set( int key, unsigned long value )
00116     {
00117       if ( key >= 0 )
00118       {
00119         if ( key >= static_cast<int>( table_.size() ) )
00120         {
00121           table_.resize( key + 1 );
00122         }
00123         table_[key] = value;
00124       }
00125     }
00126 
00135     long kernel_chk::read_prid( const s_record& srec, unsigned long address )
00136     {
00137       const int table_size = 2;
00138       unsigned long table[table_size];
00139       long prid = -1;
00140 
00141       if ( address == ~0UL )
00142       {
00143         address = srec.lower_bound();
00144       }
00145 
00146       do
00147       {
00148         for ( int i = 0; i < table_size; i++ )
00149         {
00150           unsigned long value = 0;
00151           for ( int j = 0; j < 4; j++ )
00152           {
00153             value = value << 8 | srec[address + i*4 + j];
00154           }
00155           table[i] = value;
00156         }
00157 
00158         switch ( table[0] )
00159         {
00160         case 0x12345678:
00161           prid = static_cast<long>( table[1] );
00162           break;
00163         case 0x78563412:
00164           {
00165             unsigned long value = 0;
00166             unsigned long t = table[1];
00167             for ( int j = 0; j < 4; j++ )
00168             {
00169               value = value << 8 | ( t & 0xff );
00170               t >>= 8;
00171             }
00172             prid = static_cast<long>( value );
00173           }
00174           break;
00175         default:
00176           if ( srec.upper_bound() <= address + 1 )
00177           {
00178             return -1;
00179           }
00180           ++address;
00181           break;
00182         }
00183       } while ( prid < 0 );
00184       return prid;
00185     }
00186 
00187     bool kernel_chk::do_save( std::ostream& ostr ) const
00188     {
00189       do_file_header( ostr );
00190       do_body( ostr );
00191       return true;
00192     }
00193 
00198     void kernel_chk::do_load( const boost::shared_ptr<cfg_contents>& contents )
00199     {
00200       typedef cfg_contents::group_container::const_iterator group_iterator;
00201       const cfg_contents::group_container& container = contents->groups();
00202 
00203       for ( group_iterator giter( contents->groups().begin() ), glast( contents->groups().end() ); giter != glast; ++giter )
00204       {
00205         typedef cfg_group::object_container::const_iterator object_iterator;
00206         const boost::shared_ptr<cfg_group> group( *giter );
00207         for ( object_iterator oiter( group->objects().begin() ), olast( group->objects().end() ); oiter != olast; ++oiter )
00208         {
00209           ++countof_map_[( *oiter )->get_object_type()];
00210         }
00211       }
00212     }
00213 
00222   }
00223 }

Copyright © 2006 by TAKAGI Nobuhisa.
このページは Wed Apr 12 16:31:56 2006 に Doxygen によって生成されました。