OSDN Git Service

55fdd4e7e8a1cf6b5a23d0d357a6f44952da7fc3
[trx-305dsp/dsp.git] / trx305 / kernel / cfg / jsp / jsp_checkscript.cpp
1 /*
2  *  TOPPERS/JSP Kernel
3  *      Toyohashi Open Platform for Embedded Real-Time Systems/
4  *      Just Standard Profile Kernel
5  * 
6  *  Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7  *                              Toyohashi Univ. of Technology, JAPAN
8  * 
9  *  上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation 
10  *  によって公表されている GNU General Public License の Version 2 に記
11  *  述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
12  *  を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
13  *  利用と呼ぶ)することを無償で許諾する.
14  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
15  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
16  *      スコード中に含まれていること.
17  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
18  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
19  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
20  *      の無保証規定を掲載すること.
21  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
22  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
23  *      と.
24  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
25  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
26  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
27  *        報告すること.
28  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
29  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
30  * 
31  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
32  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
33  *  含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
34  *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
35  * 
36  *  @(#) $Id: jsp_checkscript.cpp,v 1.1 2009/01/31 05:27:37 suikan Exp $
37  */
38
39 // $Header: /cvsroot/toppersjsp4bf/jsp/cfg/jsp/jsp_checkscript.cpp,v 1.1 2009/01/31 05:27:37 suikan Exp $
40
41 #include "jsp/jsp_defs.h"
42 #include "jsp/jsp_common.h"
43
44 #include <string>
45 #include <iostream>
46
47 #include "base/component.h"
48 #include "base/mpstrstream.h"
49
50 using namespace std;
51 using namespace ToppersJsp;
52
53 class CheckScriptGenerator : public Component
54 {
55 protected:
56     virtual void parseOption(Directory & container);
57     virtual void body(Directory & container);
58     
59     void insertMagic(void) throw(Exception);
60
61 public:
62     CheckScriptGenerator(void) : Component(FINALIZE) {};
63 } instance_of_CheckScriptGenerator;
64
65 void CheckScriptGenerator::parseOption(Directory & container)
66 {
67     MultipartStream * stream;
68     string work;
69
70     if(findOption("h","help"))
71     {
72         cerr << '\n' << Message(
73             "Configuration Checker Script Generation Option\n"
74             "  -c, --check  : Generate a checker script\n",
75             "カーネル構成チェックスクリプト生成用オプション\n"
76             "  -c, --check  : チェックスクリプトを生成します\n");
77         return;
78     }
79
80     if(findOption("c","check",&work))
81     {
82         if(work.empty())
83             work.assign("kernel_chk.c");
84
85         stream = new MultipartStream(work);
86         stream->createPart("header")
87                .createPart("body")
88                .createPart("footer");
89
90         container["/file/kernel_chk"] = stream;
91
92         checkOption("ci","checker-macro");
93         activateComponent();
94     }
95 }
96
97 static void createScriptEntry(Directory & container, MultipartStream * out, const char * objname, const char * member, bool mode = true)
98 {
99     string work;
100     string inib;
101     Directory * scope;
102     int i, j;
103     
104     (*out) << container.format("\n\t\t/* $@ */\n\n");
105
106     if(mode)
107     {
108         scope = container.getFirstChild();
109         while(scope != 0)
110         {
111             work = scope->getKey();
112             if(work[0] < '0' || work[1] > '9')
113                 (*out) << "\tOBJECT(" << container.getKey() << '_' << scope->toInteger() << ',' << work << ");\n";
114
115             scope = scope->getNext();
116         }
117
118         (*out) << container.format("\tEVAR(ID,_kernel_tmax_$(/prefix/$@/id)id);\n");
119     }else
120     {
121         i = 0;
122         scope = container.getFirstChild();
123         while(scope != 0)
124         {
125             work = scope->getKey();
126             (*out) << "\tOBJECT(" << container.getKey() << '_' << (i++) << ',' << scope->getKey() << ");\n";
127             scope = scope->getNext();
128         }
129
130         (*out) << container.format("\tEVAR(ID,_kernel_tnum_$(/prefix/$@/id)no);\n");
131     }
132
133     (*out) << container.format("\tEVAR($(/prefix/$@/SID)INIB,_kernel_$(/prefix/$@/sid)inib_table);\n");
134
135     work.assign(member);
136     i = 0;
137     j = work.find_first_of(',');
138     if(objname == NULL)
139         inib = container.getKey();
140     else
141         inib = objname;
142     
143     do {
144         (*out) << "\tMEMBER(" << inib << "_initialization_block," << work.substr(i, j-i) << ");\n";
145
146         i = j + 1;
147         j = work.find_first_of(',', i);
148     } while(i != string::npos+1);
149     (*out) << '\n';
150 }
151
152 inline void createScriptEntry(Directory & container, MultipartStream * out, const char * member)
153 {   createScriptEntry(container, out, NULL, member, true);  }
154
155 void CheckScriptGenerator::insertMagic(void) throw(Exception)
156 {
157     KernelCfg * out = dynamic_cast<KernelCfg *>(RuntimeObjectTable::getInstance(typeid(KernelCfg)));
158     if(out != 0) {
159         out->movePart("others");
160         out->createPart("checkscript");
161         (*out) << Message("\t/* Variables for kernel checker */\n", "\t/* カーネルチェッカ用変数 */\n");
162         (*out) << "const UW _checker_magic_number = 0x01234567;\n\n";
163     }
164 }
165
166 void CheckScriptGenerator::body(Directory & container)
167 {
168     MultipartStream * out;
169
170     out = reinterpret_cast<MultipartStream *>(container["/file/kernel_chk"].toPointer());
171
172     out->movePart("header") <<
173         "#include \"jsp_kernel.h\"\n"
174         "#include \"logtask.h\"\n"
175         "#include \"timer.h\"\n\n";
176
177
178     string work;
179     if(findOption("ci","checker-macro",&work)) {
180
181             /* 中身が空でなかったらincludeをするが,空ならincludeすら吐かない */
182         if(!work.empty())
183             (*out) << "#include \"" << work << "\"\n\n";
184     }
185     else {
186         (*out) <<   "#define OBJECT(x,y) __asm(\"d\" #x \",\" #y \"@\");\n"
187                     "#define MEMBER(x,y) __asm(\"s\" #x \"::\" #y \",(%0),(%1)@\" ::\\\n"
188                     "     \"i\"(sizeof(((struct x *)0)->y)), \"i\"(&((struct x *)0)->y));\n"
189                     "#define VAR(x) __asm(\"s\" #x \",(%0),(0)@\" :: \"i\"(sizeof(x)));\n"
190                     "#define EVAR(x,y) __asm(\"s\" #y \",(%0),(0)@\" :: \"i\"(sizeof(x)));\n"
191                     "#define SVAR(x) __asm(\"s\" #x \",(%0),(0)@\" :: \"i\"(sizeof(x[0])));\n"
192                     "#define DEFS(x) __asm(\"s\" #x \",(%0),(0)@\" :: \"i\"((unsigned long)x));\n\n";
193     }
194
195     (*out) <<   "#include \"queue.h\"\n\n"
196                 "#include \"task.h\"\n"
197                 "#include \"semaphore.h\"\n"
198                 "#include \"eventflag.h\"\n"
199                 "#include \"dataqueue.h\"\n"
200                 "#include \"mailbox.h\"\n"
201                 "#include \"mempfix.h\"\n"
202                 "#include \"cyclic.h\"\n"
203                 "#include \"../kernel/exception.h\"\n"
204                 "#include \"interrupt.h\"\n"
205                 "#include \"wait.h\"\n\n"
206                 "void checker_function(void)\n{\n";
207
208     out->movePart("footer") << "}\n";
209
210     out->movePart("body") <<
211         "\tDEFS(TMAX_TPRI);\n\tDEFS(TMIN_TPRI);\n\n"
212         "\tDEFS(TMAX_MPRI);\n\tDEFS(TMIN_MPRI);\n\n"
213 //      "\tDEFS(TMAX_MAXSEM);\n\n"
214         "\tDEFS(TMAX_RELTIM);\n\n"
215         "\tMEMBER(queue,next);\n\tMEMBER(queue,prev);\n\n";
216
217     createScriptEntry(container[OBJECTTREE "/" TASK],      out, "tskatr,exinf,task,ipriority,stksz,stk,texatr,texrtn");
218     createScriptEntry(container[OBJECTTREE "/" SEMAPHORE], out, "sematr,isemcnt,maxsem");
219     createScriptEntry(container[OBJECTTREE "/" EVENTFLAG], out, "flgatr,iflgptn");
220     createScriptEntry(container[OBJECTTREE "/" DATAQUEUE], out, "dtqatr,dtqcnt,dtq");
221     createScriptEntry(container[OBJECTTREE "/" MAILBOX], out, "mbxatr,maxmpri");
222     createScriptEntry(container[OBJECTTREE "/" FIXEDSIZEMEMORYPOOL], out, "fixed_memorypool", "mpfatr,blksz,mpf,limit");
223     createScriptEntry(container[OBJECTTREE "/" CYCLICHANDLER], out, "cyclic_handler", "cycatr,exinf,cychdr,cyctim,cycphs");
224     createScriptEntry(container[OBJECTTREE "/" INTERRUPTHANDLER], out, "interrupt_handler", "inhno,inhatr,inthdr", false);
225     createScriptEntry(container[OBJECTTREE "/" EXCEPTIONHANDLER], out, "cpu_exception_handler", "excno,excatr,exchdr", false);
226
227     insertMagic();
228
229     VerboseMessage("Configuration check script generation was finished successfully.\n","カーネル構成チェックスクリプトファイルを出力しました\n");
230 }
231