OSDN Git Service

(none)
[hos/hos-v4a.git] / cfgrtr / source / crembf.cpp
1 // ---------------------------------------------------------------------------
2 //  Hyper Operating System V4  コンフィギュレーター                           
3 //    CRE_MBF API の処理                                                      
4 //                                                                            
5 //                                    Copyright (C) 1998-2003 by Project HOS  
6 //                                    http://sourceforge.jp/projects/hos/     
7 // ---------------------------------------------------------------------------
8
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "defercd.h"
14 #include "crembf.h"
15 #include "analyze.h"
16 #include "readcfg.h"
17
18
19 #define CREMBF_MBFID            0
20 #define CREMBF_MBFATR           1
21 #define CREMBF_MAXMSZ           2
22 #define CREMBF_MBFSZ            3
23 #define CREMBF_MBF                      4
24
25
26 // コンストラクタ
27 CApiCreMbf::CApiCreMbf()
28 {
29         // パラメーター構文設定
30         m_iParamSyntax[0] = 0;          // 単独パラメーター
31         m_iParamSyntax[1] = 4;          // 4パラメーターのブロック
32         m_iParams = 2;
33 }
34
35 // デストラクタ
36 CApiCreMbf::~CApiCreMbf()
37 {
38 }
39
40
41
42 // APIの解析
43 int CApiCreMbf::AnalyzeApi(const char* pszApiName, const char* pszParams)
44 {
45         if ( strcmp(pszApiName, "CRE_MBF") == 0 )
46         {
47                 return AddParams(pszParams);
48         }
49         else if ( strcmp(pszApiName, "KERNEL_MAX_MBFID") == 0 )
50         {
51                 int iId;
52
53                 if ( m_iMaxId > 0 )
54                 {
55                         return CFG_ERR_MULTIDEF;
56                 }
57
58                 if ( m_iResObj > 0 )
59                 {
60                         return CFG_ERR_DEF_CONFLICT;
61                 }
62
63                 if ( (iId = atoi(pszParams)) <= 0 )
64                 {
65                         return CFG_ERR_PARAM;
66                 }
67
68                 m_iMaxId = iId;
69
70                 return CFG_ERR_OK;
71         }
72         else if ( strcmp(pszApiName, "KERNEL_RSV_MBFID") == 0 )
73         {
74                 int iId;
75
76                 if ( m_iMaxId > 0 )
77                 {
78                         return CFG_ERR_DEF_CONFLICT;
79                 }
80
81                 if ( (iId = atoi(pszParams)) <= 0 )
82                 {
83                         return CFG_ERR_PARAM;
84                 }
85
86                 m_iResObj += iId;
87
88                 return CFG_ERR_OK;
89         }
90         
91         return CFG_ERR_NOPROC;
92 }
93
94
95 // ID 定義ファイル書き出し
96 void CApiCreMbf::WriteId(FILE* fp)
97 {
98         int i;
99
100         // ID 直接指定でないオブジェクトが在るかどうかサーチ
101         for ( i = 0; i < m_iObjs; i++ )
102         {
103                 if ( atoi(m_pParamPacks[i]->GetParam(CREMBF_MBFID)) == 0 )
104                 {
105                         break;
106                 }
107         }
108         if ( i == m_iObjs )
109         {
110                 return;
111         }
112
113         fputs("\n\n/* message buffer ID definetion */\n", fp);
114         for ( i = 0; i < m_iObjs; i++ )
115         {
116                 if ( atoi(m_pParamPacks[i]->GetParam(CREMBF_MBFID)) == 0 )
117                 {
118                         fprintf(
119                                 fp,
120                                 "#define %s\t\t%d\n",
121                                 m_pParamPacks[i]->GetParam(CREMBF_MBFID),
122                                 m_iId[i]);
123                 }
124         }
125
126         fprintf( fp,"\n#define TMAX_MBFID\t\t%d\n", m_iMaxId );
127 }
128
129
130 // cfgファイル定義部書き出し
131 void  CApiCreMbf::WriteCfgDef(FILE* fp)
132 {
133         const char* pszParam;
134         bool blOutput;  int  i, j;
135
136         // コメント出力
137         fputs(
138                 "\n\n\n"
139                 "/* ------------------------------------------ */\n"
140                 "/*      create message buffer objects         */\n"
141                 "/* ------------------------------------------ */\n"
142                 , fp);
143
144         // バッファ領域出力
145         blOutput = false;
146         for ( i = 0; i < m_iObjs; i++ )
147         {
148                 pszParam = m_pParamPacks[i]->GetParam(CREMBF_MBF);
149                 if ( strcmp(pszParam, "NULL") == 0 )
150                 {
151                         if ( !blOutput )
152                         {
153                                 fputs("\n/* message buffer area */\n", fp);
154                                 blOutput = true;
155                         }
156
157                         fprintf(
158                                 fp,
159                                 "static VP kernel_mbf%d[(%s)];\n",
160                                 m_iId[i],
161                                 m_pParamPacks[i]->GetParam(CREMBF_MBFSZ));
162                 }
163         }
164
165         if ( m_iObjs > 0 )
166         {
167                 fprintf(
168                         fp,
169                         "\n/* message buffer control block for rom area */\n"
170                         "const T_KERNEL_MBFCB_ROM kernel_mbfcb_rom[%d] =\n"
171                         "\t{\n",
172                         m_iObjs);
173
174                 // コントロールブロック(ROM部)出力
175                 for ( i = 0; i < m_iObjs; i++ )
176                 {
177                         fprintf(
178                                 fp,
179                                 "\t\t{(ATR)(%s), (UINT)(%s), (SIZE)(%s),",
180                                 m_pParamPacks[i]->GetParam(CREMBF_MBFATR),
181                                 m_pParamPacks[i]->GetParam(CREMBF_MAXMSZ),
182                                 m_pParamPacks[i]->GetParam(CREMBF_MBFSZ));
183                         pszParam = m_pParamPacks[i]->GetParam(CREMBF_MBF);
184                         if ( strcmp(pszParam, "NULL") == 0 )
185                         {
186                                 fprintf(
187                                         fp,
188                                         "(VP)kernel_mbf%d},\n",
189                                         m_iId[i]);
190                         }
191                         else
192                         {
193                                 fprintf(
194                                         fp,
195                                         "(VP)(%s)},\n",
196                                         m_pParamPacks[i]->GetParam(CREMBF_MBF));
197                         }
198                 }
199                 fprintf(fp, "\t};\n");
200         }
201
202         // コントロールブロック(RAM部)出力
203         if ( m_iObjs > 0 )
204         {
205                 fprintf(
206                         fp,
207                         "\n/* message buffer control block for ram area */\n"
208                         "T_KERNEL_MBFCB_RAM kernel_mbfcb_ram[%d];\n",
209                         m_iObjs);
210         }
211
212         // コントロールブロックテーブル出力
213         if ( m_iMaxId > 0 )
214         {
215                 fprintf(
216                         fp,
217                         "\n/* message buffer control block table */\n"
218                         "T_KERNEL_MBFCB_RAM *kernel_mbfcb_ram_tbl[%d] =\n"
219                         "\t{\n",
220                         m_iMaxId);
221
222                 for ( i = 0; i < m_iMaxId; i++ )
223                 {
224                         // ID検索
225                         for ( j = 0; j < m_iObjs; j++ )
226                         {
227                                 if ( m_iId[j] == i + 1 )
228                                 {
229                                         break;
230                                 }
231                         }
232                         if ( j < m_iObjs )
233                         {
234                                 // オブジェクトが存在した場合
235                                 fprintf(fp, "\t\t&kernel_mbfcb_ram[%d],\n", j);
236                         }
237                         else
238                         {
239                                 // オブジェクトが無い場合
240                                 fputs("\t\tNULL,\n", fp);
241                         }
242                 }
243                 fputs("\t};\n", fp);
244         }
245
246         // 個数情報出力
247         fprintf(
248                 fp,
249                 "\n/* mail box control block count */\n"
250                 "const INT kernel_mbfcb_cnt = %d;\n",
251                 m_iMaxId);
252 }
253
254
255 // cfgファイル初期化部書き出し
256 void  CApiCreMbf::WriteCfgIni(FILE* fp)
257 {
258         // オブジェクト存在チェック
259         if ( m_iObjs == 0 )
260         {
261                 return;
262         }
263
264         // 初期化部出力
265         fprintf(
266                 fp,
267                 "\t\n\t\n"
268                 "\t/* initialize message buffer control block */\n"
269                 "\tfor ( i = 0; i < %d; i++ )\n"
270                 "\t{\n"
271                 "\t\tkernel_mbfcb_ram[i].mbfcb_rom = &kernel_mbfcb_rom[i];\n"
272                 "\t}\n",
273                 m_iObjs);
274 }
275
276
277 // cfgファイル起動部書き出し
278 void  CApiCreMbf::WriteCfgStart(FILE* fp)
279 {
280         // オブジェクト存在チェック
281         if ( m_iObjs == 0 )
282         {
283                 return;
284         }
285
286         fputs("\tkernel_ini_mbf();\t\t/* initialize message buffer */\n", fp);
287 }
288
289
290 // ---------------------------------------------------------------------------
291 //  Copyright (C) 1998-2003 by Project HOS                                    
292 // ---------------------------------------------------------------------------