📄 kernel_chk.cpp
字号:
/*
* TOPPERS/FDMP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Function Distributed Multiprocessor Kernel
*
* Copyright (C) 2005 by Takagi Nobuhisa
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
*/
/*
* toppers/itron/jsp/kernel_chk.cpp
*/
#include "toppers/itron/jsp/kernel_chk.hpp"
#include "toppers/itron/jsp/kernel_policy.hpp"
#include "toppers/s_record.hpp"
#include "toppers/reporter.hpp"
#include <ostream>
#include <boost/lexical_cast.hpp>
namespace toppers
{
namespace itron
{
namespace jsp
{
void kernel_chk::do_body( std::ostream& ostr ) const
{
ostr << "#include \"kernel_cfg.h\"\n"
"#include <stddef.h>\n"
"\n";
ostr << "const UW kernel_chk[] = {\n";
std::string table[table_size];
table[magic_number] = "0x12345678";
table[TKERNEL_PRID] = boost::lexical_cast<std::string>( (int)kernel_policy::prid_ ) + "\t/* TKERNEL_PRID */";
table[sizeof_ID] = "sizeof(ID)";
table[sizeof_UINT] = "sizeof(UINT)";
table[sizeof_SIZE] = "sizeof(SIZE)";
table[sizeof_ATR] = "sizeof(ATR)";
table[sizeof_PRI] = "sizeof(PRI)";
table[sizeof_RELTIM] = "sizeof(RELTIM)";
table[sizeof_VP] = "sizeof(VP)";
table[sizeof_VP_INT] = "sizeof(VP_INT)";
table[sizeof_FP] = "sizeof(FP)";
table[countof_TSKID] = boost::lexical_cast<std::string>( countof( "task" ) ) + "\t/* TNUM_TSKID */";
table[sizeof_TINIB] = "sizeof(TINIB)";
table[offsetof_TINIB_tskatr] = "offsetof(TINIB, tskatr)";
table[offsetof_TINIB_exinf] = "offsetof(TINIB, exinf)";
table[offsetof_TINIB_task] = "offsetof(TINIB, task)";
table[offsetof_TINIB_ipriority] = "offsetof(TINIB, ipriority)";
table[offsetof_TINIB_stksz] = "offsetof(TINIB, stksz)";
table[offsetof_TINIB_stk] = "offsetof(TINIB, stk)";
table[offsetof_TINIB_texatr] = "offsetof(TINIB, texatr)";
table[offsetof_TINIB_texrtn] = "offsetof(TINIB, texrtn)";
table[countof_SEMID] = boost::lexical_cast<std::string>( countof( "semaphore" ) ) + "\t/* TNUM_SEMID */";
table[sizeof_SEMINIB] = "sizeof(SEMINIB)";
table[offsetof_SEMINIB_sematr] = "offsetof(SEMINIB, sematr)";
table[offsetof_SEMINIB_isemcnt] = "offsetof(SEMINIB, isemcnt)";
table[offsetof_SEMINIB_maxsem] = "offsetof(SEMINIB, maxsem)";
table[countof_FLGID] = boost::lexical_cast<std::string>( countof( "eventflag" ) ) + "\t/* TNUM_FLGID */";
table[sizeof_FLGPTN] = "sizeof(FLGPTN)";
table[sizeof_FLGINIB] = "sizeof(FLGINIB)";
table[offsetof_FLGINIB_flgatr] = "offsetof(FLGINIB, flgatr)";
table[offsetof_FLGINIB_iflgptn] = "offsetof(FLGINIB, iflgptn)";
table[countof_DTQID] = boost::lexical_cast<std::string>( countof( "dataqueue" ) ) + "\t/* TNUM_DTQID */";
table[sizeof_DTQINIB] = "sizeof(DTQINIB)";
table[offsetof_DTQINIB_dtqatr] = "offsetof(DTQINIB, dtqatr)";
table[offsetof_DTQINIB_dtqcnt] = "offsetof(DTQINIB, dtqcnt)";
table[offsetof_DTQINIB_dtq] = "offsetof(DTQINIB, dtq)";
table[countof_MBXID] = boost::lexical_cast<std::string>( countof( "mailbox" ) ) + "\t/* TNUM_MBXID */";
table[sizeof_MBXINIB] = "sizeof(MBXINIB)";
table[offsetof_MBXINIB_mbxatr] = "offsetof(MBXINIB, mbxatr)";
table[offsetof_MBXINIB_maxmpri] = "offsetof(MBXINIB, maxmpri)";
table[countof_MPFID] = boost::lexical_cast<std::string>( countof( "mempfix" ) ) + "\t/* TNUM_MPFID */";
table[sizeof_MPFINIB] = "sizeof(MPFINIB)";
table[offsetof_MPFINIB_mpfatr] = "offsetof(MPFINIB, mpfatr)";
table[offsetof_MPFINIB_blksz] = "offsetof(MPFINIB, blksz)";
table[offsetof_MPFINIB_mpf] = "offsetof(MPFINIB, mpf)";
table[offsetof_MPFINIB_limit] = "offsetof(MPFINIB, limit)";
table[countof_CYCID] = boost::lexical_cast<std::string>( countof( "cyclic" ) ) + "\t/* TNUM_CYCID */";
table[sizeof_CYCINIB] = "sizeof(CYCINIB)";
table[offsetof_CYCINIB_cycatr] = "offsetof(CYCINIB, cycatr)";
table[offsetof_CYCINIB_exinf] = "offsetof(CYCINIB, exinf)";
table[offsetof_CYCINIB_cychdr] = "offsetof(CYCINIB, cychdr)";
table[offsetof_CYCINIB_cyctim] = "offsetof(CYCINIB, cyctim)";
table[offsetof_CYCINIB_cycphs] = "offsetof(CYCINIB, cycphs)";
table[countof_INHNO] = boost::lexical_cast<std::string>( countof( "interrupt" ) ) + "\t/* TNUM_INHNO */";
table[sizeof_INHNO] = "sizeof(INHNO)";
table[sizeof_INHINIB] = "sizeof(INHINIB)";
table[offsetof_INHINIB_inhno] = "offsetof(INHINIB, inhno)";
table[offsetof_INHINIB_inhatr] = "offsetof(INHINIB, inhatr)";
table[offsetof_INHINIB_inthdr] = "offsetof(INHINIB, inthdr)";
table[countof_EXCNO] = boost::lexical_cast<std::string>( countof( "exception" ) ) + "\t/* TNUM_EXCNO */";
table[sizeof_EXCNO] = "sizeof(EXCNO)";
table[sizeof_EXCINIB] = "sizeof(EXCINIB)";
table[offsetof_EXCINIB_excno] = "offsetof(EXCINIB, excno)";
table[offsetof_EXCINIB_excatr] = "offsetof(EXCINIB, excatr)";
table[offsetof_EXCINIB_exchdr] = "offsetof(EXCINIB, exchdr)";
for ( int i = 0; i < table_size; i++ )
{
ostr << '\t' << table[i] << ",\n";
}
ostr << "};\n";
}
bool kernel_chk::do_load( const s_record& srec, unsigned long address )
{
bool result = true;
set( table_size-1, 0 ); // 岠棪壔偺偨傔丄廔抂梫慺傪嬻懪偪偡傞
for ( int i = 0; i < table_size; i++ )
{
unsigned long value = 0;
for ( int j = 0; j < 4; j++ )
{
value = value << 8 | srec[address + i*4 + j];
}
set( i, value );
}
switch ( get( magic_number ) )
{
case 0x12345678:
byteorder( big_endian );
break;
case 0x78563412:
byteorder( little_endian );
for ( int i = 0; i < table_size; i++ )
{
unsigned long value = 0;
unsigned long t = get( i );
for ( int j = 0; j < 4; j++ )
{
value = value << 8 | ( t & 0xff );
t >>= 8;
}
set( i, value );
}
break;
default:
result = false;
break;
}
return result;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -