⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsp_check.cpp

📁 JAPAN RTOS TOPPERS/JSP kernel 1.4 PreRelease simulation environment JSP kernel Windows simulation
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 *  TOPPERS/JSP Kernel
 *      Toyohashi Open Platform for Embedded Real-Time Systems/
 *      Just Standard Profile Kernel
 * 
 *  Copyright (C) 2000-2002 by Embedded and Real-Time Systems Laboratory
 *                              Toyohashi Univ. of Technology, JAPAN
 * 
 *  忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation 
 *  偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
 *  弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
 *  傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
 *  棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
 *  (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
 *      尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
 *      僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
 *  (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
 *      梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
 *      幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
 *      偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
 *  (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
 *      梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
 *      偲丏
 *    (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
 *        嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
 *    (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
 *        曬崘偡傞偙偲丏
 *  (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
 *      奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
 * 
 *  杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
 *  傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
 *  娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
 *  愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
 * 
 *  @(#) $Id: jsp_check.cpp,v 1.17 2003/06/30 12:50:32 takayuki Exp $
 */

// $Header: /home/CVS/configurator/jsp/jsp_check.cpp,v 1.17 2003/06/30 12:50:32 takayuki Exp $

#include "base/defs.h"
#include "jsp/jsp_defs.h"
#include "base/component.h"
#include "base/filecontainer.h"
#include <fstream>
#include <iomanip>

class ConfigurationChecker : public Component
{
public:

	enum tagCheckLevel
	{
		UNKNOWN    = 0,
		LAZY       = 1,		/* 抳柦揑 (峴偒夁偓夵憿杊巭梡)  */
		STANDARD   = 2,		/* ITRON巇條偺斖埻 (夵憿傪嫋梕) */
		TOPPERS    = 4,		/* TOPPERS/JSP偺斖埻撪          */
		RESTRICTED = 8,		/* 曅偭抂偐傜曔傑偊傞           */

		NORMAL     = 8
	};

protected:
	enum tagCheckLevel current_level;

	unsigned int error_count;
	std::string banner;

	void set_banner(Directory &, Formatter , const char *, int);
	void notify(enum tagCheckLevel, Formatter , bool = true);

	bool check_taskblock(Directory &, filecontainer *);
	bool check_semaphoreblock(Directory &, filecontainer *);
	bool check_eventflagblock(Directory &, filecontainer *);
	bool check_dataqueueblock(Directory &, filecontainer *);
	bool check_mailboxblock(Directory &, filecontainer *);
	bool check_fixed_memorypoolblock(Directory &, filecontainer *);
	bool check_cyclic_handlerblock(Directory &, filecontainer *);
	bool check_interrupt_handlerblock(Directory &, filecontainer *);
	bool check_exception_handlerblock(Directory &, filecontainer *);

	virtual void parseOption(Directory &);
	virtual void body(Directory &);

public:
	ConfigurationChecker(void);
};

//------------------------------------------------------
using namespace std;

ConfigurationChecker  instance_of_ConfigurationChecker;

//------------------------------------------------------


#define LoadVal(x,y,z) x = 0; container->load_variable(&x, sizeof(x), y, z)
#define Load(x,y) container->load_variable(&(x), sizeof(x), y)

ConfigurationChecker::ConfigurationChecker(void)
{
	bootBanner() = "--- TOPPERS/JSP Configuration Checker (ver 2.3) ---";
}

void ConfigurationChecker::set_banner(Directory & container, Formatter object, const char * type, int id)
{
	string objectname;
	Directory * node;
	char buffer[32];


	banner = string("    ") + object.str() + " : ";

	objectname = filecontainer::get_instance()->get_objectname(id, type);
	sprintf(buffer, "id = %d", id);

	if(objectname.empty())
		banner += buffer;
	else
		banner += objectname + " (" + buffer + ") ";

	node = container.findChild(OBJECTTREE, type, objectname.c_str(), "position", NULL);
	if(node != 0)
		banner += string(" at ") + node->toString();

	if(VerboseMessage::getVerbose())
	{
		cout << banner << endl;
		banner.erase();
	}
}

void ConfigurationChecker::notify(enum tagCheckLevel level, Formatter msg, bool error)
{
	if((level & current_level) != 0)
	{

		if(!banner.empty())
		{
			cout << banner << endl;
			banner.erase();
		}

		cout << "      ";

		if(error)
		{
			cout << Message("[ Error ] ","[僄儔乕] ");
			error_count ++;
		}else
			cout << Message("[Warning] ","[ 寈崘 ] ");
		cout << msg << endl;
	}
}

	/*
	 * 僞僗僋僆僽僕僃僋僩偵娭偡傞僄儔乕専弌
	 */

bool ConfigurationChecker::check_taskblock(Directory & parameter, filecontainer * container)
{
	unsigned int id;
	unsigned int maxpri;
	unsigned int minpri;
	unsigned int work;
	unsigned int num;
	struct variable_information tinib_table;
	unsigned int old_error_count = error_count;

	Message object("Task","僞僗僋");

	if(!Load(num, "_kernel_tmax_tskid"))
		ExceptionMessage(
			"Internal error: Unknown symbol (Probably, Symbol table was stripped)",
			"撪晹僄儔乕: 晄惓側僔儞儃儖柤 (幚峴宍幃偑僔儞儃儖僥乕僽儖傪娷傫偱側偄壜擻惈偑偁傝傑偡)").throwException();

	if(num < 1)
	{
		notify(RESTRICTED,
			Message("  [Task] : No tasks created\n","  [僞僗僋] : 僞僗僋僆僽僕僃僋僩偑偁傝傑偣傫\n"));
		return true;
	}

	tinib_table = container->get_variable_information("_kernel_tinib_table");
	maxpri = container->get_variable_information("TMAX_TPRI").value;
	minpri = container->get_variable_information("TMIN_TPRI").value;
	VerboseMessage("% object : % items\n","%僆僽僕僃僋僩 : % 屄\n") << object << num;
	for(id = 1; id <= num; id++)
	{
		set_banner(parameter, object, TASK, id);

			/*
			 *  懏惈僠僃僢僋
			 */
		LoadVal(work, tinib_table.address, "task_initialization_block::tskatr");

			// 懏惈抣偑 TA_HLNG|TA_ASM|TA_ACT 埲奜偺抣傪偲偭偰偄傞
		if((work & ~0x3) != 0)
			notify( STANDARD,
				Message("Illegal task attribute (It should be ((TA_HLNG||TA_ASM)|TA_ACT))",
						"晄惓側僞僗僋懏惈 ((TA_HLNG||TA_ASM)|TA_ACT)埲奜"));

			// 懏惈抣偵 TA_ASM 偑娷傑傟偰偄傞
		if((work & 0x1) != 0)
			notify( RESTRICTED,
				Message("TA_ASM specified as task attribute takes no effect.",
						"僞僗僋懏惈偵TA_ASM偑巜掕偝傟偰偄傞"));

			/* 婲摦斣抧偑0 */
		LoadVal(work, tinib_table.address, "task_initialization_block::task");
		if(work == 0)
			notify(RESTRICTED,
				Message("The address of task routine is equal to zero.",
						"奐巒斣抧偵0偑愝掕偝傟偰偄傑偡"));

			/*
			 *  桪愭搙僠僃僢僋
			 */

		LoadVal(work, tinib_table.address, "task_initialization_block::ipriority");

			// 嵟戝桪愭搙偲嵟彫桪愭搙偺愝掕偑偍偐偟偄
		if(maxpri < minpri)
			notify(LAZY,
				Message("Illegal Priority Settings found (TMAX_TPRI(%) < TMIN_TPRI).",
						"弶婜桪愭搙偑嵟掅桪愭搙(%)傪挻偊偰偄傞") << minpri);

			// 桪愭搙偺斖埻偑[嵟彫桪愭搙, 嵟戝桪愭搙]偺斖埻傪挻偊偰偄傞
		if((signed)work > (signed)(maxpri - minpri))
			notify(TOPPERS,
				Message("Initial priority is greater than maximum priority (%).",
						"弶婜桪愭搙偑嵟戝桪愭搙(%)傪挻偊偰偄傞") << maxpri);
		if((signed)work < 0)
			notify(STANDARD,
				Message("Initial priority is less than the minimum priority (%).",
						"弶婜桪愭搙偑嵟掅桪愭搙(%)傪壓夞傞") << minpri);

			/*
			 *   僞僗僋椺奜懏惈僠僃僢僋
			 */

		LoadVal(work, tinib_table.address, "task_initialization_block::texatr");

			// 懏惈抣偑TA_HLNG or TA_ASM偱側偄
		if((work & ~0x3) != 0)
			notify(STANDARD,
				Message("Task exception routine has an illegal attribute specifier.",
						"僞僗僋椺奜偵柍岠側懏惈(TA_HLNG,TA_ASM埲奜) 偑愝掕偝傟偰偄傑偡"));

			// 懏惈抣偵 TA_ASM 偑娷傑傟偰偄傞
		if((work & 0x1) != 0)
			notify( RESTRICTED,
				Message("TA_ASM, specified as texatr, does not always take effect.",
						"僞僗僋椺奜偵TA_ASM偑巜掕偝傟偰偄傑偡"));

//		LoadVal(work, tinib_table.address, "task_initialization_block::texhdr");
//		if(work == 0)
//			notify(RESTRICTED,
//				Message("NULL pointer is specified as an texrtn address.",
//						"椺奜僴儞僪儔偺斣抧偑NULL偱偡"));

			/*
			 *   僗僞僢僋僠僃僢僋
			 */

			// 僗僞僢僋僒僀僘偑0
		LoadVal(work, tinib_table.address, "task_initialization_block::stksz");
		if(work == 0)
			notify(RESTRICTED,
				Message("Stack size is equal to zero.",
						"僗僞僢僋僒僀僘偵0偑愝掕偝傟偰偄傑偡"));

			// 僗僞僢僋偺斣抧偑0
		LoadVal(work, tinib_table.address, "task_initialization_block::stk");
		if(work == 0)
			notify(RESTRICTED,
				Message("The address of task stack is equal to zero.",
						"僗僞僢僋奐巒斣抧偵0偑愝掕偝傟偰偄傑偡"));

		tinib_table.address += tinib_table.size;
	}

	return old_error_count == error_count;
}

bool ConfigurationChecker::check_semaphoreblock(Directory & parameter, filecontainer * container)
{
	unsigned int id;
	unsigned int num;
	unsigned int work;
	unsigned int work2;
	unsigned int old_error_count = error_count;

	struct variable_information seminib;
	Message object("Semaphore","僙儅僼僅");

	Load(num, "_kernel_tmax_semid");
	if(num < 1)
		return true;

	seminib = container->get_variable_information("_kernel_seminib_table");
	VerboseMessage("% object : % items\n","%僆僽僕僃僋僩 : % 屄\n") << object << num;
	for(id = 1; id <= num; id++)
	{
		set_banner(parameter, object, SEMAPHORE, id);

			//attribute validation check
		LoadVal(work, seminib.address, "semaphore_initialization_block::sematr");
		if((work & ~0x1) != 0)
			notify(STANDARD,
				Message("Illegal attribute (It should be (TA_TFIFO||TA_TPRI)).",
						"(TA_TFIFO||TA_TPRI)埲奜偺懏惈偑巜掕偝傟偰偄傞"));

			//maxcnt < isemcnt
		LoadVal(work, seminib.address, "semaphore_initialization_block::maxsem");
		LoadVal(work2,seminib.address, "semaphore_initialization_block::isemcnt");
		if(work < work2)
			notify(STANDARD,
				Message("Initial count[%] is greater than the maximum count[%] of this semaphore",
						"弶婜抣[%]偑嵟戝抣[%]傪挻偊偰偄傞") << work2 << work);

		if(work == 0)
			notify(STANDARD,
				Message("Maximum count must be greater than zero.",
						"僙儅僼僅偺嵟戝僇僂儞僩偼1埲忋偱側偗傟偽偄偗傑偣傫"));

		seminib.address += seminib.size;
	}

	return old_error_count == error_count;
}


bool ConfigurationChecker::check_eventflagblock(Directory & parameter, filecontainer * container)
{
	unsigned int id;
	unsigned int num;
	unsigned int work;

	unsigned int old_error_count = error_count;
	struct variable_information inib;
	Message object("Event flag","僀儀儞僩僼儔僌");

	Load(num, "_kernel_tmax_flgid");
	if(num < 1)
		return true;

	inib = container->get_variable_information("_kernel_flginib_table");
	VerboseMessage("% object : % items\n","%僆僽僕僃僋僩 : % 屄\n") << object << num;
	for(id = 1; id <= num; id++)
	{
		set_banner(parameter, object, EVENTFLAG, id);
			
			//attribute validation check
		LoadVal(work, inib.address, "eventflag_initialization_block::flgatr");
		if((work & ~0x7) != 0)
			notify(STANDARD,
				Message("Illegal attribute value [0x%]",
						"偍偐偟側懏惈抣 [0x%]") << setbase(16) << (work & ~0x7));

		if((work & 0x2) != 0)
			notify(TOPPERS,		//埶懚晹偱捈傜側偄偺偱RESTRICTED偵偟側偄
				Message("Attribute TA_WMUL is not supported in current version.",
						"TA_WMUL偼僒億乕僩奜"));
	
		inib.address += inib.size;
	}

	return old_error_count == error_count;
}


bool ConfigurationChecker::check_dataqueueblock(Directory & parameter, filecontainer * container)
{
	unsigned int id;
	unsigned int num;
	unsigned int work;
	unsigned int dtq;

	unsigned int old_error_count = error_count;
	struct variable_information inib;
	Message object("Data queue","僨乕僞僉儏乕");

	Load(num, "_kernel_tmax_dtqid");
	if(num < 1)
		return true;

	inib = container->get_variable_information("_kernel_dtqinib_table");
	VerboseMessage("% object : % items\n","%僆僽僕僃僋僩 : % 屄\n") << object << num;
	for(id = 1; id <= num; id++)
	{
		set_banner(parameter, object, DATAQUEUE, id);

			//attribute validation check
		LoadVal(work, inib.address, "dataqueue_initialization_block::dtqatr");
		if((work & ~0x1) != 0)
			notify(STANDARD,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -