source: anotherchoice/tags/jsp-1.4.4-full-UTF8/utils/tlcs900-toshiba/tlcs900vec/tlcs900vec.cpp@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 14.6 KB
RevLine 
[26]1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2002 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2003-2004 by Ryosuke Takeuchi
9 * Platform Development Center RIOCH COMPANY,LTD. JAPAN
10 * Copyright (C) 2006-2010 by Witz Corporation, JAPAN
11 *
12 * The above copyright holders grant permission gratis to use,
13 * duplicate, modify, or redistribute (hereafter called use) this
14 * software (including the one made by modifying this software),
15 * provided that the following four conditions (1) through (4) are
16 * satisfied.
17 *
18 * (1) When this software is used in the form of source code, the above
19 * copyright notice, this use conditions, and the disclaimer shown
20 * below must be retained in the source code without modification.
21 *
22 * (2) When this software is redistributed in the forms usable for the
23 * development of other software, such as in library form, the above
24 * copyright notice, this use conditions, and the disclaimer shown
25 * below must be shown without modification in the document provided
26 * with the redistributed software, such as the user manual.
27 *
28 * (3) When this software is redistributed in the forms unusable for the
29 * development of other software, such as the case when the software
30 * is embedded in a piece of equipment, either of the following two
31 * conditions must be satisfied:
32 *
33 * (a) The above copyright notice, this use conditions, and the
34 * disclaimer shown below must be shown without modification in
35 * the document provided with the redistributed software, such as
36 * the user manual.
37 *
38 * (b) How the software is to be redistributed must be reported to the
39 * TOPPERS Project according to the procedure described
40 * separately.
41 *
42 * (4) The above copyright holders and the TOPPERS Project are exempt
43 * from responsibility for any type of damage directly or indirectly
44 * caused from the use of this software and are indemnified by any
45 * users or end users of this software from any and all causes of
46 * action whatsoever.
47 *
48 * THIS SOFTWARE IS PROVIDED "AS IS." THE ABOVE COPYRIGHT HOLDERS AND
49 * THE TOPPERS PROJECT DISCLAIM ANY EXPRESS OR IMPLIED WARRANTIES,
50 * INCLUDING, BUT NOT LIMITED TO, ITS APPLICABILITY TO A PARTICULAR
51 * PURPOSE. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS AND THE
52 * TOPPERS PROJECT BE LIABLE FOR ANY TYPE OF DAMAGE DIRECTLY OR
53 * INDIRECTLY CAUSED FROM THE USE OF THIS SOFTWARE.
54 *
55 * 上記著作権者
56は,以下の (1)〜(4) の条件を満たす場合に限り,本ソフトウェ
57 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改変・
58 * 再é…
59å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
60 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作権
61 * 表示,この利用条件および下記の無保証規定が,そのままの形でソース
62 * コード中に含まれていること.
63 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使用
64 * できる形で再é…
65å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
66å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
67マ
68 * ニュアルなど)に,上記の著作権表示,この利用条件および下記の無保
69 * 証規定を掲載すること.
70 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使用
71 * できない形で再é…
72å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこと.
73 * (a) 再é…
74å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
75マニュアルなど)に,上記の著作
76 * 権表示,この利用条件および下記の無保証規定を掲載すること.
77 * (b) 再é…
78å¸ƒã®å½¢æ…
79‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに報
80 * 告すること.
81 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損害
82 * からも,上記著作権者
83およびTOPPERSプロジェクトをå…
84è²¬ã™ã‚‹ã“と.また,
85 * 本ソフトウェアのユーザまたはエンドユーザからのいかなる理由に基づ
86 * く請求からも,上記著作権者
87およびTOPPERSプロジェクトをå…
88è²¬ã™ã‚‹ã“と.
89 *
90 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
91およ
92 * びTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的に対す
93 * る適合性も含めて,いかなる保証も行わない.また,本ソフトウェアの利用
94 * により直接的または間接的に生じたいかなる損害に関しても,その責任を負
95 * わない.
96 *
97 * @(#) $Id: tlcs900vec.cpp,v 1.4 2007/04/17 05:08:07 honda Exp $
98 */
99// tlcs900vec.cpp : コンソール アプリケーション用のエントリ ポイントの定義
100//
101//------------------------------------------------------------------------------
102// 変更履歴
103//version yyyy/mm/dd 概要
104//---------- -------------------------------------------------------------------
105// 01.00 2004/01/02 初版
106// 01.01 2004/08/06 FIX VECTOR が固定値で有ったのをパラメタにて変更可能とした
107// EXCINIB のé…
108åˆ—が0の場合の問題修正。
109// M30262F8FGの生成時、割り込みベクタが1行多い不å…
110·åˆä¿®æ­£ã€‚
111// M30620FCAFPのJSP1.3用ベクタ生成コードを条件コンパイル化。
112//-----------------------------------------------------------------------------
113
114#include <stdio.h>
115#include <stdlib.h>
116#include <string.h>
117
118#define MAX_INCLUDE 8
119#define MAX_INT 64
120#define MAX_EXC 9
121#define MAX_VEC MAX_INT
122#define BUF_SIZE 512
123#define STR_SIZE 128
124
125#define INT_STATE 0
126#define EXC_STATE 1
127#define NORMAL_STATE 2
128
129struct VEC {
130 int no;
131 char no_name[STR_SIZE];
132 char no_label[STR_SIZE];
133};
134
135static char const default_input_file[] = "kernel_cfg.i";
136static char const default_output_file[] = "tlcs900vec.inc";
137static char const default_unused_int[] = "unused_interrupt";
138
139//start出力設定
140static char const start_extern[] ="\n\textern large _start";
141static char const start_vector[] = "\tdl\t_start\t; 01 0xffff00";
142static char const lf[] = "\n";
143
144static char input_file[STR_SIZE];
145static char output_file[STR_SIZE];
146static char include_file[MAX_INCLUDE][STR_SIZE];
147static int num_include = 0;
148static int num_vec[2] = {0, 0};
149static int max_int = 47;
150static int num_nodec = 0;
151static int vec_state = NORMAL_STATE;
152static struct VEC vec_table[2][MAX_VEC];
153static char unused_vec[2][STR_SIZE];
154
155static void set_TLSS_TLCS900(FILE* pfo, int m);
156static void set_global(FILE* pfo, char const * t);
157static void set_global_function(FILE* pfo, char const * t);
158static void set_vector(FILE* pfo, int kind, int no);
159static bool test_string(char** s, char const * t);
160static bool skip_space(char** s);
161static bool skip_char(char** s, char const c);
162
163int main(int argc, char* argv[])
164{
165 FILE* pfi;
166 FILE* pfo;
167 FILE* pfw;
168 char buf[BUF_SIZE];
169 struct VEC *v;
170 int i, j, k;
171 bool cnv, dec;
172 char* s;
173 char* p;
174 char* q;
175 char c;
176
177 strcpy(input_file, default_input_file);
178 strcpy(output_file, default_output_file);
179 strcpy(unused_vec[0], default_unused_int);
180 strcpy(unused_vec[1], default_unused_int);
181
182 //オプション指定
183 for(i = 1 ; i < argc ; i++){
184 s = argv[i];
185 if(*s++ == '-'){
186 c = *s++;
187 skip_space(&s);
188 switch(c){
189 case 'O': // アウトプットファイルの設定
190 case 'o':
191 strcpy(output_file, s);
192 break;
193 case 'R': // インプットファイルの設定
194 case 'r':
195 strcpy(input_file, s);
196 break;
197 default:
198 printf("m16cvec -R<input_file> -O<output_file> -I<include_file> -M<mode> -F<fixvector>\n");
199 break;
200 }
201 }
202 }
203 printf("input file = %s\n", input_file);
204 printf("output file = %s\n", output_file);
205 if((pfi = fopen(input_file, "r")) == NULL){
206 fprintf(stderr, "can't open input file !");
207 exit(1);
208 }
209 if((pfo = fopen(output_file, "w")) == NULL){
210 fclose(pfi);
211 fprintf(stderr, "can't open output file !");
212 exit(1);
213 }
214 for(i = 0 ; i < num_include ; i++){
215 printf("include file = %s\n", include_file[i]);
216 }
217 //ファイルå…
218¥åŠ›
219 for(;;){
220 if((fgets(buf, BUF_SIZE, pfi)) == NULL)
221 break;
222 s = buf;
223 switch(vec_state){
224 case INT_STATE:
225 case EXC_STATE:
226 //å…
227¥åŠ›æ–‡ã®æ–‡æœ«ã¾ã§ããŸæ™‚の処理
228 if(test_string(&s, ";"))
229 vec_state = NORMAL_STATE;
230 //文字列抽出開始
231 else if(test_string(&s, "{")){
232 v = &vec_table[vec_state][num_vec[vec_state]];
233 p = &v->no_name[0];
234 if(skip_space(&s))
235 continue;
236 dec = true;
237
238 while(*s != ','){
239 if(*s == 0)
240 continue;
241 //(,),spaceの場合は次のポインタを進める
242 if(*s == '(' || *s == ')'|| *s <= ' '){
243 s++;
244 continue;
245 }
246 //sが[0-9]でない場合
247 if(*s < '0' || *s > '9')
248 dec = false;
249 *p++ = *s++;
250 }
251 s++;
252 *p++ = 0;
253 if(dec)
254 v->no = atoi(v->no_name);
255 else{
256 v->no = -1;
257 num_nodec++;
258 }
259 p = &v->no_label[0];
260
261 if(skip_char(&s, ','))
262 continue;
263
264 test_string(&s, "(FP)");
265
266 if(skip_space(&s))
267 continue;
268 while(*s != ')' && *s != ',' && *s > ' ' && *s != '}'){
269 *p++ = *s++;
270 }
271 *p++ = 0;
272 num_vec[vec_state]++;
273
274 printf("%s\n",v->no_label);
275 }
276 else
277 continue;
278 break;
279 default:
280 if(!test_string(&s, "const"))
281 continue;
282 if(test_string(&s, "INHINIB"))
283 vec_state = INT_STATE;
284 else if(test_string(&s, "EXCINIB"))
285 vec_state = EXC_STATE;
286 break;
287 }
288 }
289 do{
290 cnv = false;
291 for(i = 0 ; i < num_include ; i++){
292 if((pfw = fopen(include_file[i], "r")) != NULL){
293 for(;;){
294 if((fgets(buf, BUF_SIZE, pfw)) == NULL)
295 break;
296 s = buf;
297 if(!test_string(&s, "#define"))
298 continue;
299 if(skip_space(&s))
300 continue;
301 for(k = 0 ; k < 2 ; k++){
302 for(j = 0 ; j < num_vec[k] ; j++){
303 v = &vec_table[k][j];
304 if(v->no < 0){
305 p = s;
306 dec = true;
307 if(test_string(&p, v->no_name)){
308 q = &v->no_name[0];
309 if(!skip_space(&p)){
310 while(*p > ' '){
311 if(*p == '(' || *p == ')'){
312 p++;
313 continue;
314 }
315 if(*p < '0' || *p > '9')
316 dec = false;
317 *q++ = *p++;
318 }
319 }
320 *q++ = 0;
321 }
322 else
323 dec = false;
324 if(dec){
325 v->no = atoi(v->no_name);
326 num_nodec--;
327 }
328 }
329 }
330 }
331 }
332 fclose(pfw);
333 }
334 else
335 printf("open error %s !!\n", include_file[i]);
336 }
337 }while(cnv);
338
339 for(i = 0 ; i < num_vec[EXC_STATE] ; i++){
340 v = &vec_table[EXC_STATE][i];
341 if(v->no >= 32 && v->no < MAX_INT){
342 vec_table[INT_STATE][num_vec[INT_STATE]] = vec_table[EXC_STATE][i];
343 num_vec[INT_STATE]++;
344 for(j = i ; j < (num_vec[EXC_STATE]-1) ; j++)
345 vec_table[EXC_STATE][j] = vec_table[EXC_STATE][j+1];
346 num_vec[EXC_STATE]--;
347 }
348 }
349 for(j = 0 ; j < num_vec[INT_STATE] ; j++){
350 v = &vec_table[INT_STATE][j];
351 if(v->no >= MAX_INT)
352 strcpy(unused_vec[INT_STATE], v->no_label);
353 else if(max_int < v->no)
354 max_int = v->no;
355 }
356 for(j = 0 ; j < num_vec[EXC_STATE] ; j++){
357 v = &vec_table[EXC_STATE][j];
358 if((v->no >= MAX_EXC && v->no < 32) || v->no >= MAX_INT)
359 strcpy(unused_vec[EXC_STATE], v->no_label);
360 }
361 //extern startを出力
362 fputs(start_extern, pfo);
363
364 if(num_nodec > 0)
365 printf("%dのエクセプション番号を特定できません!\n", num_nodec);
366 else{
367 fputs(lf, pfo);
368 for(i = 0 ; i < 2 ; i++){
369 for(j = 0 ; j < num_vec[i] ; j++)
370 set_global_function(pfo, vec_table[i][j].no_label);
371 }
372 if(!strcmp(default_unused_int, unused_vec[0]))
373 set_global(pfo, unused_vec[0]);
374 else if(!strcmp(default_unused_int, unused_vec[1]))
375 set_global(pfo, unused_vec[1]);
376 set_TLSS_TLCS900(pfo, max_int);
377
378 }
379 fclose(pfi);
380 fclose(pfo);
381 return 0;
382}
383
384static void set_TLSS_TLCS900(FILE* pfo, int m)
385{
386 int iVec_num;
387
388 fputs("\nf_vecter section code large align=4", pfo);
389 fputs(lf, pfo);
390
391 for(iVec_num = 0 ; iVec_num < MAX_INT ; iVec_num++){
392 if(iVec_num == 0){
393 fputs(start_vector, pfo);
394 fputs(lf, pfo);}
395 else
396 //この部分で設定
397 set_vector(pfo, INT_STATE, iVec_num+1);
398 }
399}
400
401/*
402 * extern 宣言をする(名前の前にアンダーバーが不要なもの)
403 */
404static void set_global(FILE* pfo, char const * t)
405{
406 fputs("\textern large ", pfo);
407 fputs(t, pfo);
408 fputs(lf, pfo);
409}
410/*
411 * extern 宣言をする(名前の前にアンダーバーが必
412要なもの)
413 */
414static void set_global_function(FILE* pfo, char const * t)
415{
416 fputs("\textern large _", pfo);
417 fputs(t, pfo);
418 fputs(lf, pfo);
419}
420
421/*
422 * ベクトルを設定する
423 */
424static void set_vector(FILE* pfo, int kind, int no)
425{
426 struct VEC* v = &vec_table[kind][0];
427 int vec_cnt;
428 int address;
429 int address_high;
430 int address_low;
431 char comment[15];
432 char comment_high[2];
433 char comment_low[2];
434
435
436 address = (no - 1) * 4;
437 address_high = address/16;
438 address_low = address%16;
439
440 sprintf(comment_high, "%x", address_high);
441 sprintf(comment_low, "%x", address_low);
442
443 fputs("\tdl\t", pfo);
444
445 comment[0] = '\t';
446 comment[1] = ';';
447 comment[2] = ' ';
448 comment[3] = (no/10)+'0';
449 comment[4] = (no%10)+'0';
450 comment[5] = ' ';
451 comment[6] = '0';
452 comment[7] = 'x';
453 comment[8] = 'f';
454 comment[9] = 'f';
455 comment[10] = 'f';
456 comment[11] = 'f';
457 comment[12] = comment_high[0];
458 comment[13] = comment_low[0];
459 comment[14] = 0;
460
461 for(vec_cnt = 0 ; vec_cnt < num_vec[kind] ; vec_cnt++, v++){
462 if(v->no == no){
463 fputs("_", pfo);
464 fputs(v->no_label, pfo);
465 fputs(comment, pfo);
466 fputs(lf, pfo);
467 return;
468 }
469 }
470 //unused interrupt
471 fputs(unused_vec[kind], pfo);
472 fputs(comment, pfo);
473 fputs(lf, pfo);
474}
475
476
477/*
478 * 文字列を比較して同一ならばTURE
479 */
480static bool test_string(char** s, char const *t)
481{
482 char* p;
483 char c;
484
485 p = *s;
486 while(*p <= ' '){
487 if(*p == 0)
488 return false;
489 p++;
490 }
491 while((c = *p++) != 0){
492 if(c != *t++)
493 break;
494 if(*t == 0){
495 *s = p;
496 return true;
497 }
498 }
499 return false;
500}
501
502/*
503 * 指定のキャラクタまでスキップ
504 */
505static bool skip_char(char** s, char const c)
506{
507 char* p;
508
509 p = *s;
510 while(*p != c){
511 if(*p == 0)
512 break;
513 p++;
514 }
515 if(*p){
516 p++;
517 *s = p;
518 return false;
519 }
520 else{
521 *s = p;
522 return true;
523 }
524}
525
526/*
527 * スペースまたはタブをスキップする
528 */
529static bool skip_space(char** s)
530{
531 char* p;
532
533 p = *s;
534 while(*p <= ' ' ){
535 if(*p == 0)
536 break;
537 p++;
538 }
539 *s = p;
540 if(*p)
541 return false;
542 else
543 return true;
544}
Note: See TracBrowser for help on using the repository browser.