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

Last change on this file since 363 was 363, checked in by ykominami, 5 years ago

add tags/jsp-1.4.4-full-UTF8

  • Property svn:executable set to *
File size: 11.4 KB
Line 
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 * 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: tlcs900offset.cpp,v 1.4 2007/04/17 05:08:07 honda Exp $
98 */
99// tlcs900offset.cpp : コンソール アプリケーション用のエントリ ポイントの定義
100//
101
102#include <stdio.h>
103#include <stdlib.h>
104#include <string.h>
105
106#define BUF_SIZE 512
107#define STR_SIZE 128
108#define BIT_SIZE 6
109
110#define NORMAL_STATE 0
111#define TEXPTN_STATE 1
112#define SP_STATE 2
113#define PC_STATE 3
114#define ENATEX_STATE 4
115
116
117static char const default_input_file[] = "makeoffset.asm";
118static char const default_output_file[] = "offset.inc";
119static char const lf[] = "\n";
120
121static char input_file[STR_SIZE];
122static char output_file[STR_SIZE];
123
124/*
125å…
126¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«ãŒBEGIN, ENDの区間である場合は
127offset_state = NORMAL_STATE;
128*/
129static int offset_state = NORMAL_STATE;
130
131static bool test_string(char** s, char const * t);
132static bool skip_space(char** s);
133static bool skip_char(char** s, char const c);
134
135unsigned int atoh(char* s);
136void get_num(char* s);
137void get_num_undo(char* s);
138
139int main(int argc, char* argv[]){
140 FILE* pfo;
141 FILE* pfi;
142 int nCnt, address;
143 int shift_bit = 1;
144 int shift_cnt = 0;
145
146 char* s;
147 char str[100];
148
149 char buf[BUF_SIZE];
150 char c;
151
152 strcpy(input_file, default_input_file);
153 strcpy(output_file, default_output_file);
154
155 //コマンドラインå…
156¥åŠ›ã‚’解析
157 for(nCnt = 1 ; nCnt < argc ; nCnt++){
158 s = argv[nCnt];
159 if(*s++ == '-'){
160 c = *s;
161 while(*s != 0){
162 if(*s == ':')
163 break;
164 s++;
165 }
166 if(*s++ == ':'){
167 switch(c){
168 //output file name
169 case 'O':
170 case 'o':
171 strcpy(output_file, s);
172 break;
173 //input file name
174 case 'R':
175 case 'r':
176 strcpy(input_file, s);
177 break;
178 default:
179 printf("tlcs900offset -R:input_file -O:output_file\n");
180 break;
181 }
182 }
183 }
184 }
185 //input, outputファイル名の標準出力
186 printf("input file = %s\n", input_file);
187 printf("output file = %s\n", output_file);
188
189 if((pfi = fopen(input_file, "r")) == NULL){
190 fprintf(stderr, "can't open input file!");
191 exit(1);
192 }
193 if((pfo = fopen(output_file, "w")) == NULL){
194 fclose(pfi);
195 fprintf(stderr, "can't open output file!");
196 exit(1);
197 }
198
199 //inputファイルの取り込み
200 for(;;){
201 if((fgets(buf, BUF_SIZE, pfi)) == NULL)
202 break;
203 s = buf;
204 switch(offset_state){
205 //; BEGIN TCB_texptnの範囲の解析
206 case TEXPTN_STATE:
207 if(test_string(&s, "; END")){
208 offset_state = NORMAL_STATE;
209 continue;
210 }
211
212 if(test_string(&s, "line") || test_string(&s, "call"))
213 continue;
214
215 if(skip_char(&s, 'x')){
216 continue;
217 }
218
219 get_num(s);
220 address = atoh(s);
221 printf("TCB_texptn\tequ\t%d\n",address);
222 fputs("TCB_texptn\t\tequ\t", pfo);
223 sprintf(str,"%d",address);
224 fputs(str, pfo);
225 fputs(lf, pfo);
226 break;
227
228 case SP_STATE:
229 //; BEGIN TCB_spの範囲の解析
230 if(test_string(&s, "; END")){
231 offset_state = NORMAL_STATE;
232 continue;
233 }
234
235 if(test_string(&s, "line") || test_string(&s, "call") )
236 continue;
237
238 if(skip_space(&s))
239 continue;
240
241 if(skip_char(&s, '(')){
242 continue;
243 }
244
245 if(skip_char(&s, 'x')){
246 continue;
247 }
248
249 get_num(s);
250 address = atoh(s);
251 printf("TCB_sp\t\tequ\t%d\n",address);
252 fputs("TCB_sp\t\t\tequ\t", pfo);
253 sprintf(str,"%d",address);
254 fputs(str, pfo);
255 fputs(lf, pfo);
256
257 break;
258
259 case PC_STATE:
260 //; BEGIN TCB_pcの範囲の解析
261 if(test_string(&s, "; END")){
262 offset_state = NORMAL_STATE;
263 continue;
264 }
265
266 if(test_string(&s, "line") || test_string(&s, "call"))
267 continue;
268
269 if(skip_char(&s, 'x')){
270 continue;
271 }
272 get_num(s);
273 address = atoh(s);
274 printf("TCB_pc\tequ\t%d\n",address);
275 fputs("TCB_pc\t\t\tequ\t", pfo);
276 sprintf(str,"%d",address);
277 fputs(str, pfo);
278 fputs(lf, pfo);
279 break;
280
281 case ENATEX_STATE:
282 //; BEGIN TCB_pcの範囲の解析
283 if(test_string(&s, "; END")){
284 offset_state = NORMAL_STATE;
285 continue;
286 }
287
288 if(test_string(&s, "line") || test_string(&s, "call"))
289 continue;
290
291 if(skip_char(&s, 'x')){
292 continue;
293 }
294 get_num(s);
295 address = atoh(s);
296 printf("TCB_enatex\tequ\t%d\n",address);
297 fputs("TCB_enatex\t\tequ\t", pfo);
298 sprintf(str,"%d",address);
299 fputs(str, pfo);
300 fputs(lf, pfo);
301 get_num_undo(s);
302 if(skip_char(&s, ',')){
303 continue;
304 }
305
306 *(s + BIT_SIZE) = '\0';
307 printf("TCB_enatex_mask\tequ\t%s\n",s);
308 fputs("TCB_enatex_mask\tequ\t", pfo);
309 fputs(s, pfo);
310 fputs(lf, pfo);
311
312 if(skip_char(&s, 'x')){
313 continue;
314 }
315
316 address = atoh(s);
317
318 for(shift_cnt=0;shift_cnt<=16;shift_cnt++){
319 if(address == shift_bit){
320 printf("TCB_enatex_bit\tequ\t%d\n",shift_cnt);
321 fputs("TCB_enatex_bit\tequ\t", pfo);
322 sprintf(str,"%d",shift_cnt);
323 fputs(str, pfo);
324 fputs(lf, pfo);
325 }
326 shift_bit<<=1;
327 }
328
329 break;
330
331 default:
332 if(test_string(&s, "; BEGIN TCB_texptn")){
333 offset_state = TEXPTN_STATE;
334 continue;
335 }else if(test_string(&s, "; BEGIN TCB_sp")){
336 offset_state = SP_STATE;
337 continue;
338 }else if(test_string(&s, "; BEGIN TCB_pc")){
339 offset_state = PC_STATE;
340 continue;
341 }else if(test_string(&s, "; BEGIN TCB_enatex")){
342 offset_state = ENATEX_STATE;
343 continue;
344 }
345
346 break;
347 }
348 }
349 return 0;
350}
351
352/*
353 * 16進文字列をint型に変換
354 */
355unsigned int atoh(char* s)
356{
357 int nCnt = 0;
358 for(;;){
359 if(*s >= '0' && *s <= '9')
360 nCnt = (nCnt * 16) + (*s - '0');
361 else if(*s >= 'A' && *s <= 'F')
362 nCnt = (nCnt * 16) + (*s - 'A' + 10);
363 else if(*s >= 'a' && *s <= 'f')
364 nCnt = (nCnt * 16) + (*s - 'a' + 10);
365 else
366 break;
367 s++;
368 }
369 return nCnt;
370}
371/*
372 * アドレス部分を抽出
373 */
374void get_num(char* s)
375{
376 int nCnt;
377
378 for(nCnt = 0 ; nCnt < 4 ; nCnt++){
379 if(*(s+nCnt) == ')'){
380 *(s+nCnt) = '\0';
381 }
382 }
383}
384
385/*
386 * get_numで書き換えた部分をå…
387ƒã«æˆ»ã™
388 */
389void get_num_undo(char* s)
390{
391 int nCnt;
392
393 for(nCnt = 0 ; nCnt < 4 ; nCnt++){
394 if(*(s+nCnt) == '\0'){
395 *(s+nCnt) = ')';
396 }
397 }
398}
399
400
401/*
402 * 文字列を比較して同一ならばTURE
403 */
404static bool test_string(char** s, char const *t)
405{
406 char* p;
407 char c;
408
409 p = *s;
410 while(*p <= ' '){
411 if(*p == 0)
412 return false;
413 p++;
414 }
415 while((c = *p++) != 0){
416 if(c != *t++)
417 break;
418 if(*t == 0){
419 *s = p;
420 return true;
421 }
422 }
423 return false;
424}
425
426/*
427 * 指定のキャラクタまでスキップ
428 */
429static bool skip_char(char** s, char const c)
430{
431 char* p;
432
433 p = *s;
434 while(*p != c){
435 if(*p == 0)
436 break;
437 p++;
438 }
439 if(*p){
440 p++;
441 *s = p;
442 return false;
443 }
444 else{
445 *s = p;
446 return true;
447 }
448}
449
450/*
451 * スペースまたはタブをスキップする
452 */
453static bool skip_space(char** s)
454{
455 char* p;
456
457 p = *s;
458 while(*p <= ' '){
459 if(*p == 0)
460 break;
461 p++;
462 }
463 *s = p;
464 if(*p)
465 return false;
466 else
467 return true;
468}
Note: See TracBrowser for help on using the repository browser.