[172] | 1 | #! /usr/bin/perl
|
---|
| 2 | #
|
---|
| 3 | # TOPPERS ATK2
|
---|
| 4 | # Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 5 | # Automotive Kernel Version 2
|
---|
| 6 | #
|
---|
| 7 | # Copyright (C) 2001 by Embedded and Real-Time Systems Laboratory
|
---|
| 8 | # Toyohashi Univ. of Technology, JAPAN
|
---|
| 9 | # Copyright (C) 2005-2014 by Center for Embedded Computing Systems
|
---|
| 10 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 11 | # Copyright (C) 2011-2014 by FUJI SOFT INCORPORATED, JAPAN
|
---|
| 12 | # Copyright (C) 2011-2013 by Spansion LLC, USA
|
---|
| 13 | # Copyright (C) 2011-2013 by NEC Communication Systems, Ltd., JAPAN
|
---|
| 14 | # Copyright (C) 2011-2014 by Panasonic Advanced Technology Development Co., Ltd., JAPAN
|
---|
| 15 | # Copyright (C) 2011-2014 by Renesas Electronics Corporation, JAPAN
|
---|
| 16 | # Copyright (C) 2011-2014 by Sunny Giken Inc., JAPAN
|
---|
| 17 | # Copyright (C) 2011-2014 by TOSHIBA CORPORATION, JAPAN
|
---|
| 18 | # Copyright (C) 2011-2014 by Witz Corporation, JAPAN
|
---|
| 19 | #
|
---|
| 20 | # 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 21 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 22 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 23 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 24 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 25 | # スコード中に含まれていること.
|
---|
| 26 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 27 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 28 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 29 | # の無保証規定を掲載すること.
|
---|
| 30 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 31 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 32 | # と.
|
---|
| 33 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 34 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 35 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 36 | # 報告すること.
|
---|
| 37 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 38 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 39 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 40 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 41 | # 免責すること.
|
---|
| 42 | #
|
---|
| 43 | # 本ソフトウェアは,AUTOSAR(AUTomotive Open System ARchitecture)仕
|
---|
| 44 | # 様に基づいている.上記の許諾は,AUTOSARの知的財産権を許諾するもので
|
---|
| 45 | # はない.AUTOSARは,AUTOSAR仕様に基づいたソフトウェアを商用目的で利
|
---|
| 46 | # 用する者に対して,AUTOSARパートナーになることを求めている.
|
---|
| 47 | #
|
---|
| 48 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 49 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 50 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 51 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 52 | # の責任を負わない.
|
---|
| 53 | #
|
---|
| 54 | # $Id: gensvc_atk 6172 2012-11-16 00:10:34Z fsi-dankei $
|
---|
| 55 | #
|
---|
| 56 |
|
---|
| 57 | #
|
---|
| 58 | # サービスコールインタフェース生成プログラム
|
---|
| 59 | #
|
---|
| 60 | # サービスコール定義ファイル(svc.def)を読み込んで,以下のファイルを
|
---|
| 61 | # カレントディレクトリに生成する.それぞれのディレクトリへの移動は手動
|
---|
| 62 | # で行うこと.
|
---|
| 63 | #
|
---|
| 64 | # svc_table.c → kernel/ に置く
|
---|
| 65 | # kernel_fncode.h → include/ に置く
|
---|
| 66 | # svc_funccall.h → include/ に置く
|
---|
| 67 | # tool_svc.h → arch/gcc/ に置く
|
---|
| 68 | #
|
---|
| 69 |
|
---|
| 70 | # 大域変数の初期化
|
---|
| 71 |
|
---|
| 72 | $max_svcid = 0;
|
---|
| 73 | @allfncdlist = ();
|
---|
| 74 | @fncdlist = ();
|
---|
| 75 | %flagstable = ();
|
---|
| 76 | %typetable = ();
|
---|
| 77 | %prototable = ();
|
---|
| 78 | %nametable = ();
|
---|
| 79 | %fnotable = ();
|
---|
| 80 | %argstable = ();
|
---|
| 81 | %argnotable = ();
|
---|
| 82 | %tfntable = ();
|
---|
| 83 |
|
---|
| 84 | #
|
---|
| 85 | # 1行読み込み(行番号をカウント)
|
---|
| 86 | #
|
---|
| 87 | sub getline {
|
---|
| 88 | local($line);
|
---|
| 89 |
|
---|
| 90 | $line = <>;
|
---|
| 91 | $lineno++;
|
---|
| 92 | return($line);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | #
|
---|
| 96 | # エラー出力
|
---|
| 97 | #
|
---|
| 98 | sub error {
|
---|
| 99 | local($msg) = @_;
|
---|
| 100 |
|
---|
| 101 | print STDERR $msg," at line ",$lineno,".\n";
|
---|
| 102 | exit(1);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | sub eof_error {
|
---|
| 106 | print STDERR "Unexpected EOF.\n";
|
---|
| 107 | exit(1);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | #
|
---|
| 111 | # 定義ファイルの読み込み
|
---|
| 112 | #
|
---|
| 113 | $lineno = 0;
|
---|
| 114 | $next_fncd = 1;
|
---|
| 115 | $next_tfn = 0;
|
---|
| 116 | while ($line = getline()) {
|
---|
| 117 | chop $line;
|
---|
| 118 |
|
---|
| 119 | # コメントの削除
|
---|
| 120 | $line =~ s/#.*$//;
|
---|
| 121 |
|
---|
| 122 | # 空行のスキップ
|
---|
| 123 | next if ($line =~ /^[ \t]*$/);
|
---|
| 124 |
|
---|
| 125 | # 継続行(行末が '\' の行)の処理
|
---|
| 126 | while ($line =~ /^(.*)\\$/) {
|
---|
| 127 | $line = $1;
|
---|
| 128 | unless ($line1 = getline()) {
|
---|
| 129 | eof_error();
|
---|
| 130 | }
|
---|
| 131 | chop $line1;
|
---|
| 132 | $line .= $line1;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | # サービスコール定義の解析
|
---|
| 136 | unless ($line =~ /^(-?[0-9]*)[ \t]+([^ \t]+)[ \t]*(.*)$/) {
|
---|
| 137 | error("Syntax error Definition 121");
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | $fncd = $1;
|
---|
| 141 | $flags = $2;
|
---|
| 142 | $proto = $3;
|
---|
| 143 | $proto =~ s/([^ \t])[ \t]+$/\1/;
|
---|
| 144 | $proto =~ s/[ \t]+/ /g;
|
---|
| 145 |
|
---|
| 146 | # 機能コードをチェック
|
---|
| 147 | if ($fncd eq "") {
|
---|
| 148 | $fncd = $next_fncd;
|
---|
| 149 | }
|
---|
| 150 | elsif ($fncd != $next_fncd) {
|
---|
| 151 | print STDERR "Function code skipped at line: ",$lineno,"\n";
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | # 次の機能コードの計算
|
---|
| 155 | $next_fncd = $fncd + 1;
|
---|
| 156 |
|
---|
| 157 | # 未サポートのサービスコールのスキップ
|
---|
| 158 | if ($flags !~ /^[SPLNI]/) {
|
---|
| 159 | if ($proto =~ /^([A-Za-z_]+)[ \t]+(([a-z_]+)\((.*)\))$/) {
|
---|
| 160 | push(@allfncdlist, $fncd);
|
---|
| 161 | $nametable{$fncd} = $3;
|
---|
| 162 | }
|
---|
| 163 | elsif ($proto =~ /^([a-z_]+)$/) {
|
---|
| 164 | push(@allfncdlist, $fncd);
|
---|
| 165 | $nametable{$fncd} = $1;
|
---|
| 166 | }
|
---|
| 167 | next;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | if ($flags !~ /^N/) {
|
---|
| 171 | $tfntable{$fncd} = $next_tfn;
|
---|
| 172 | $next_tfn = $next_tfn + 1;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | # 機能コードの最大値の計算
|
---|
| 176 | $max_svcid = $next_tfn - 1 if ($max_svcid < $next_tfn - 1);
|
---|
| 177 |
|
---|
| 178 | # サービスコールリストに登録
|
---|
| 179 | push(@allfncdlist, $fncd);
|
---|
| 180 | push(@fncdlist, $fncd);
|
---|
| 181 |
|
---|
| 182 | # デバッグ用出力
|
---|
| 183 | print STDERR "proto ",$proto,"\n";
|
---|
| 184 | print STDERR "fncd ",$fncd,"\n";
|
---|
| 185 | print STDERR "flags ",$flags,"\n";
|
---|
| 186 |
|
---|
| 187 | # サービスコール定義の文法チェック
|
---|
| 188 | unless ($proto =~ /^([A-Za-z0-9_]+)[ \t]+(([A-Za-z0-9_]+)\((.*)\))$/) {
|
---|
| 189 | error("Syntax error 169");
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | $flagstable{$fncd} = $flags;
|
---|
| 193 | $typetable{$fncd} = $1;
|
---|
| 194 | $prototable{$fncd} = $2;
|
---|
| 195 | $nametable{$fncd} = $3;
|
---|
| 196 | $argstable{$fncd} = $4;
|
---|
| 197 | $argno = 0;
|
---|
| 198 | foreach $arg (split(/, */, $argstable{$fncd})) {
|
---|
| 199 | # "変数の型 変数名" のチェック
|
---|
| 200 | unless ($arg =~ /^([A-Za-z0-9_* ]+)( +|\*)([a-z_]+)$/) {
|
---|
| 201 | # "..." 可変引数リストのチェック
|
---|
| 202 | unless ($arg =~ /.../){
|
---|
| 203 | error("Syntax error 178");
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | $argno++;
|
---|
| 207 | }
|
---|
| 208 | $argnotable{$fncd} = $argno;
|
---|
| 209 | }
|
---|
| 210 | $num_fncd = +$max_svcid;
|
---|
| 211 |
|
---|
| 212 | #
|
---|
| 213 | # svc_table.cの生成
|
---|
| 214 | #
|
---|
| 215 | open(FILE, "> svc_table.c");
|
---|
| 216 | print FILE <<END_OF_HEADER;
|
---|
| 217 | /* This file is generated from svc.def by gensvc_atk. */
|
---|
| 218 |
|
---|
| 219 | #include "kernel_int.h"
|
---|
| 220 |
|
---|
| 221 | void * const svc_table[TMAX_SVCID + 1] = {
|
---|
| 222 | END_OF_HEADER
|
---|
| 223 |
|
---|
| 224 | # ジャンプテーブルの生成
|
---|
| 225 | foreach $fncd (@allfncdlist) {
|
---|
| 226 | if ($flagstable{$fncd}) {
|
---|
| 227 | if ($flagstable{$fncd} !~ /^N/) {
|
---|
| 228 | $entry = $nametable{$fncd};
|
---|
| 229 | print FILE "\t(void *) &",$entry,",\n";
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | print FILE <<END_OF_TAILER;
|
---|
| 235 | TARGET_SVC_TABLE
|
---|
| 236 | };
|
---|
| 237 | END_OF_TAILER
|
---|
| 238 |
|
---|
| 239 | #
|
---|
| 240 | # kernel_fncode.hの生成
|
---|
| 241 | #
|
---|
| 242 |
|
---|
| 243 | open(FILE, "> kernel_fncode.h");
|
---|
| 244 | print FILE <<END_OF_HEADER;
|
---|
| 245 | /* This file is generated from svc.def by gensvc_atk. */
|
---|
| 246 |
|
---|
| 247 | #ifndef TOPPERS_KERNEL_FNCODE_H
|
---|
| 248 | #define TOPPERS_KERNEL_FNCODE_H
|
---|
| 249 |
|
---|
| 250 | #define TMAX_SVCID ($max_svcid + TARGET_SVC_NUM)
|
---|
| 251 |
|
---|
| 252 | END_OF_HEADER
|
---|
| 253 |
|
---|
| 254 | foreach $fncd (@allfncdlist) {
|
---|
| 255 | $name = $nametable{$fncd};
|
---|
| 256 | $name =~ y/a-z/A-Z/;
|
---|
| 257 | $tfn = $tfntable{$fncd};
|
---|
| 258 | #print $tfn,"\n";
|
---|
| 259 | if ($flagstable{$fncd} !~ /^[NI]/) {
|
---|
| 260 | print FILE "#define TFN_",$name," ",$tfn,"\n";
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | print FILE <<END_OF_TAILER;
|
---|
| 265 |
|
---|
| 266 | #endif /* TOPPERS_KERNEL_FNCODE_H */
|
---|
| 267 | END_OF_TAILER
|
---|
| 268 | close(FILE);
|
---|
| 269 |
|
---|
| 270 | #
|
---|
| 271 | # svc_funccall.hの生成
|
---|
| 272 | #
|
---|
| 273 | # 関数呼出しで呼び出す場合のインタフェース
|
---|
| 274 | open(FILE, "> svc_funccall.h");
|
---|
| 275 | print FILE <<END_OF_HEADER;
|
---|
| 276 | /* This file is generated from svc.def by gensvc_atk. */
|
---|
| 277 |
|
---|
| 278 | #ifndef TOPPERS_SVC_FUNCCALL_H
|
---|
| 279 | #define TOPPERS_SVC_FUNCCALL_H
|
---|
| 280 |
|
---|
| 281 | #define SVC_CALL(system_service) _kernel_ ## system_service
|
---|
| 282 |
|
---|
| 283 | #ifdef TOPPERS_SVC_FUNCCALL
|
---|
| 284 | END_OF_HEADER
|
---|
| 285 |
|
---|
| 286 | foreach $fncd (@fncdlist) {
|
---|
| 287 | if ($flagstable{$fncd} !~ /^[I]/) {
|
---|
| 288 | $name = $nametable{$fncd};
|
---|
| 289 | if ($name) {
|
---|
| 290 | print FILE "#define ",$name," (_kernel_",$name,")\n";
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | print FILE <<END_OF_SEPARATOR;
|
---|
| 296 | #endif
|
---|
| 297 |
|
---|
| 298 | #ifndef TOPPERS_MACRO_ONLY
|
---|
| 299 |
|
---|
| 300 | END_OF_SEPARATOR
|
---|
| 301 |
|
---|
| 302 | foreach $fncd (@fncdlist) {
|
---|
| 303 | $proto = $prototable{$fncd};
|
---|
| 304 | $proto =~ s/\(\)/(void)/;
|
---|
| 305 | if ($flagstable{$fncd} !~ /^I/) {
|
---|
| 306 | print FILE "extern ",$typetable{$fncd}," _kernel_",$proto,";\n";
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | print FILE <<END_OF_TRAILER;
|
---|
| 311 |
|
---|
| 312 | #endif /* TOPPERS_MACRO_ONLY */
|
---|
| 313 | #endif /* TOPPERS_SVC_FUNCCALL */
|
---|
| 314 | END_OF_TRAILER
|
---|
| 315 | close(FILE);
|
---|
| 316 |
|
---|
| 317 | #
|
---|
| 318 | # tool_svc.hの生成
|
---|
| 319 | #
|
---|
| 320 | # ソフトウェア割込みで呼び出す場合のインタフェース
|
---|
| 321 | #
|
---|
| 322 | # CallTrustedFunction() は 引数チェックを行うので直接記述する.
|
---|
| 323 | # 呼出元のメモリアクセスの可能性があるので,"m" 属性とする.
|
---|
| 324 | #
|
---|
| 325 | open(FILE, "> tool_svc.h");
|
---|
| 326 | print FILE <<END_OF_HEADER;
|
---|
| 327 | /* This file is generated from svc.def by gensvc_atk. */
|
---|
| 328 |
|
---|
| 329 | #ifndef TOPPERS_TOOL_SVC_H
|
---|
| 330 | #define TOPPERS_TOOL_SVC_H
|
---|
| 331 |
|
---|
| 332 | #define SVC_TRAP(system_service) _trap_ ## system_service
|
---|
| 333 |
|
---|
| 334 | #ifndef TOPPERS_SVC_FUNCCALL
|
---|
| 335 | END_OF_HEADER
|
---|
| 336 |
|
---|
| 337 | foreach $fncd (@fncdlist) {
|
---|
| 338 | if ($flagstable{$fncd} !~ /^[I]/) {
|
---|
| 339 | $name = $nametable{$fncd};
|
---|
| 340 | if ($name) {
|
---|
| 341 | print FILE "#define ",$name," _trap_",$name,"\n";
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | print FILE <<END_OF_HEADER2;
|
---|
| 347 | #endif
|
---|
| 348 |
|
---|
| 349 | #ifndef TOPPERS_MACRO_ONLY
|
---|
| 350 |
|
---|
| 351 | END_OF_HEADER2
|
---|
| 352 |
|
---|
| 353 | foreach $fncd (@fncdlist) {
|
---|
| 354 | # 関数ヘッダの生成
|
---|
| 355 | if ($flagstable{$fncd} !~ /^[I]/) {
|
---|
| 356 | $proto = $prototable{$fncd};
|
---|
| 357 | print FILE "LOCAL_INLINE ",$typetable{$fncd},"\n";
|
---|
| 358 | $proto =~ s/\(\)/(void)/;
|
---|
| 359 | print FILE "_trap_", $proto,"\n";
|
---|
| 360 |
|
---|
| 361 | # 関数本体の生成
|
---|
| 362 | print FILE "{\n";
|
---|
| 363 |
|
---|
| 364 | if ($flagstable{$fncd} =~ /N/) {
|
---|
| 365 | print FILE "\treturn;\n";
|
---|
| 366 | } else {
|
---|
| 367 | print FILE "\tCAL_SVC_",$argnotable{$fncd};
|
---|
| 368 | print FILE "M" if ($flagstable{$fncd} !~ /n/);
|
---|
| 369 | print FILE "N" if ($flagstable{$fncd} =~ /n/);
|
---|
| 370 | print FILE "(";
|
---|
| 371 | print FILE $typetable{$fncd},", ";
|
---|
| 372 |
|
---|
| 373 | $name = $nametable{$fncd};
|
---|
| 374 | $name =~ y/a-z/A-Z/;
|
---|
| 375 | print FILE "TFN_",$name;
|
---|
| 376 |
|
---|
| 377 | foreach $arg (split(/, */, $argstable{$fncd})) {
|
---|
| 378 | if ($arg =~ /^([A-Za-z0-9_* ]+) +([A-Za-z0-9_]+)$/) {
|
---|
| 379 | print FILE ", ", $1, ", ", $2;
|
---|
| 380 | }
|
---|
| 381 | elsif ($arg =~ /^([A-Za-z0-9_* ]+\*)([A-Za-z0-9_]+)$/) {
|
---|
| 382 | print FILE ", ", $1, ", ", $2;
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 | print FILE ");\n";
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | print FILE "}\n";
|
---|
| 389 | print FILE "\n";
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | print FILE <<END_OF_TAILER;
|
---|
| 394 | #endif /* TOPPERS_MACRO_ONLY */
|
---|
| 395 |
|
---|
| 396 | #endif /* TOPPERS_TOOL_SVC_H */
|
---|
| 397 | END_OF_TAILER
|
---|
| 398 | close(FILE);
|
---|