0
|
1 |
# Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
# e32\kernel\genexec.pl
|
|
15 |
# Generate user/kernel interface classes from single description file
|
|
16 |
# Usage:
|
|
17 |
# perl genexec.pl -i <input file> -e <enum.h> -u <user.h> -k <kernel.h>
|
|
18 |
# where: <input file> is the name of the description file
|
|
19 |
# <enum.h> is the name of the generated header file containing the dispatch enumeration
|
|
20 |
# <user.h> is the name of the generated header file containing user side interface
|
|
21 |
# <kernel.h> is the name of the generated header file containing kernel side interface
|
|
22 |
#
|
|
23 |
#
|
|
24 |
|
|
25 |
use Getopt::Long;
|
|
26 |
use Cwd;
|
|
27 |
|
|
28 |
#Getopt::Long::Configure("ignore_case");
|
|
29 |
my %opts=();
|
|
30 |
my $result = GetOptions ( \%opts,
|
|
31 |
"input=s",
|
|
32 |
"enum=s",
|
|
33 |
"user=s",
|
|
34 |
"kernel=s"
|
|
35 |
);
|
|
36 |
|
|
37 |
# Bit 0 = argument permitted
|
|
38 |
# Bit 1 = argument mandatory
|
|
39 |
# Bit 2 = can be used with fast
|
|
40 |
# Bit 3 = can be used with slow
|
|
41 |
# Bit 4 = remember all arguments from repeated use of keyword
|
|
42 |
|
|
43 |
my %keywords = (
|
|
44 |
'name' => 0x0f,
|
|
45 |
'number' => 0x0f,
|
|
46 |
'user' => 0x0f,
|
|
47 |
'specialuser' => 0x0c,
|
|
48 |
'kernel' => 0x0f,
|
|
49 |
'specialkernel' => 0x0f,
|
|
50 |
'export' => 0x0c,
|
|
51 |
'return' => 0x0d,
|
|
52 |
'arg1' => 0x0f,
|
|
53 |
'arg2' => 0x0b,
|
|
54 |
'arg3' => 0x0b,
|
|
55 |
'arg4' => 0x0b,
|
|
56 |
'karg1' => 0x0f,
|
|
57 |
'karg2' => 0x0b,
|
|
58 |
'karg3' => 0x0b,
|
|
59 |
'karg4' => 0x0b,
|
|
60 |
'unprotected' => 0x08,
|
|
61 |
'lock' => 0x08,
|
|
62 |
'nr' => 0x08,
|
|
63 |
'handle' => 0x0b,
|
|
64 |
'asm' => 0x0d,
|
|
65 |
'hw' => 0x0c,
|
|
66 |
'emulator' => 0x0c,
|
|
67 |
'extended' => 0x0b,
|
|
68 |
'ifdef' => 0x1f,
|
|
69 |
'ifndef' => 0x1f
|
|
70 |
);
|
|
71 |
|
|
72 |
my %keyword_synonyms = (
|
|
73 |
'norelease' => 'nr',
|
|
74 |
'noemulator' => 'hw'
|
|
75 |
);
|
|
76 |
|
|
77 |
my @keyword_list = keys(%keywords);
|
|
78 |
|
|
79 |
my %objects = (
|
|
80 |
'thread' => ['EThread','DThread',1],
|
|
81 |
'process' => ['EProcess','DProcess',1],
|
|
82 |
'chunk' => ['EChunk','DChunk',1],
|
|
83 |
'library' => ['ELibrary','DLibrary',1],
|
|
84 |
'semaphore' => ['ESemaphore','DSemaphore',1],
|
|
85 |
'mutex' => ['EMutex','DMutex',1],
|
|
86 |
'timer' => ['ETimer','DTimer',1],
|
|
87 |
'server' => ['EServer','DServer',1],
|
|
88 |
'session' => ['ESession','DSession',1],
|
|
89 |
'logicaldevice' => ['ELogicalDevice','DLogicalDevice',1],
|
|
90 |
'physicaldevice'=> ['EPhysicalDevice','DPhysicalDevice',1],
|
|
91 |
'logicalchannel'=> ['ELogicalChannel','DLogicalChannelBase',1],
|
|
92 |
'changenotifier'=> ['EChangeNotifier','DChangeNotifier',1],
|
|
93 |
'undertaker' => ['EUndertaker','DUndertaker',1],
|
|
94 |
'msgqueue' => ['EMsgQueue','DMsgQueue',1],
|
|
95 |
'property' => ['EPropertyRef','DPropertyRef',1],
|
|
96 |
'condvar' => ['ECondVar','DCondVar',1],
|
|
97 |
'shpool' => ['EShPool','DShPool',1],
|
|
98 |
'shbuf' => ['EShBuf','DShBuf',1],
|
|
99 |
'any' => ['','DObject',1],
|
|
100 |
'ipcmessaged' => ['EIpcMessageD','RMessageK',0],
|
|
101 |
'ipcmessage' => ['EIpcMessage','RMessageK',0],
|
|
102 |
'ipcclient' => ['EIpcClient','DThread',0]
|
|
103 |
);
|
|
104 |
|
|
105 |
my %object_synonyms = (
|
|
106 |
'ldevice' => 'logicaldevice',
|
|
107 |
'pdevice' => 'physicaldevice',
|
|
108 |
'channel' => 'logicalchannel',
|
|
109 |
'chnotifier' => 'changenotifier'
|
|
110 |
);
|
|
111 |
|
|
112 |
my @object_list = keys(%objects);
|
|
113 |
|
|
114 |
my @fast;
|
|
115 |
my @slow;
|
|
116 |
|
|
117 |
|
|
118 |
my @input;
|
|
119 |
my $file;
|
|
120 |
my $line;
|
|
121 |
my $state = 0;
|
|
122 |
my $xref;
|
|
123 |
# need to add drive letter to path of execs.txt as cpp doesn't like
|
|
124 |
# absolute paths without a drive letter
|
|
125 |
|
|
126 |
my $drive = "";
|
|
127 |
if (($^O eq "" || $^O =~ /mswin32/i) && $opts{input} !~ /^[a-z]:/i)
|
|
128 |
{
|
|
129 |
$drive = substr(Cwd::cwd(),0,2);
|
|
130 |
}
|
|
131 |
|
|
132 |
open PIPE, "cpp -I- -I. -lang-c++ $drive$opts{input} | ";
|
|
133 |
while (<PIPE>) {
|
|
134 |
if (/^\s*\#\s+(\d+)\s+\"(.*?)\"/) {
|
|
135 |
$line = $1;
|
|
136 |
$file = $2;
|
|
137 |
next;
|
|
138 |
}
|
|
139 |
if (/^\s*$/) {
|
|
140 |
++$line;
|
|
141 |
next;
|
|
142 |
}
|
|
143 |
if ($state == 0) {
|
|
144 |
my %exec;
|
|
145 |
if (/^\s*slow\s*\{\s*$/) {
|
|
146 |
$exec{'type'} = 0;
|
|
147 |
$exec{'file'} = $file;
|
|
148 |
$exec{'line'} = $line;
|
|
149 |
$xref = \%exec;
|
|
150 |
} elsif (/^\s*fast\s*\{\s*$/) {
|
|
151 |
$exec{'type'} = 1;
|
|
152 |
$exec{'file'} = $file;
|
|
153 |
$exec{'line'} = $line;
|
|
154 |
$xref = \%exec;
|
|
155 |
} else {
|
|
156 |
die "Syntax error at $file line $line\n";
|
|
157 |
}
|
|
158 |
++$state;
|
|
159 |
} elsif ($state == 1) {
|
|
160 |
if (/^\s*}\s*$/) {
|
|
161 |
if ($$xref{'type'}==0) {
|
|
162 |
push @slow, $xref;
|
|
163 |
} elsif ($$xref{'type'}==1) {
|
|
164 |
push @fast, $xref;
|
|
165 |
}
|
|
166 |
undef $xref;
|
|
167 |
$state = 0;
|
|
168 |
} else {
|
|
169 |
if (/^\s*(\w+)(.*?)$/) {
|
|
170 |
my $keyword = $1;
|
|
171 |
my $rest = $2;
|
|
172 |
my $argument = -1;
|
|
173 |
my $match_res = matchabbrev(\$keyword, \@keyword_list, \%keyword_synonyms);
|
|
174 |
if ($match_res) {
|
|
175 |
die "$match_res keyword $keyword at $file line $line\n";
|
|
176 |
}
|
|
177 |
my $flags = $keywords{$keyword};
|
|
178 |
if ($$xref{'type'}==1 && ($flags&4)==0) {
|
|
179 |
die "Keyword $keyword not permitted with FAST exec at $file line $line\n";
|
|
180 |
}
|
|
181 |
if ($$xref{'type'}==0 && ($flags&8)==0) {
|
|
182 |
die "Keyword $keyword not permitted with SLOW exec at $file line $line\n";
|
|
183 |
}
|
|
184 |
if ($rest =~ /^\s*$/) {
|
|
185 |
die "Missing argument at $file line $line\n" if ($flags & 2);
|
|
186 |
} else {
|
|
187 |
die "Invalid argument at $file line $line\n" unless ($flags & 1);
|
|
188 |
if ($rest =~ /^\s*\=\s*(.*?)\s*$/) {
|
|
189 |
$argument = $1;
|
|
190 |
} else {
|
|
191 |
die "Invalid argument syntax at $file line $line\n";
|
|
192 |
}
|
|
193 |
}
|
|
194 |
if ($keyword eq 'hw') {
|
|
195 |
$keyword = 'ifdef';
|
|
196 |
$argument = '__EPOC32__';
|
|
197 |
$flags = 0x1f;
|
|
198 |
} elsif ($keyword eq 'emulator') {
|
|
199 |
$keyword = 'ifndef';
|
|
200 |
$argument = '__EPOC32__';
|
|
201 |
$flags = 0x1f;
|
|
202 |
}
|
|
203 |
my $existing = $$xref{$keyword};
|
|
204 |
if ($flags & 16) {
|
|
205 |
if (!defined($existing)) {
|
|
206 |
my @kw_args = ();
|
|
207 |
$$xref{$keyword} = \@kw_args;
|
|
208 |
$existing = \@kw_args;
|
|
209 |
}
|
|
210 |
push @$existing, $argument;
|
|
211 |
} else {
|
|
212 |
if (!defined($existing)) {
|
|
213 |
$$xref{$keyword} = $argument;
|
|
214 |
} else {
|
|
215 |
die "Duplicate keyword $keyword at $file line $line\n";
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
}
|
|
221 |
++$line;
|
|
222 |
}
|
|
223 |
close PIPE;
|
|
224 |
|
|
225 |
checkexecs(\@fast, 'fast');
|
|
226 |
checkexecs(\@slow, 'slow');
|
|
227 |
|
|
228 |
my @ixfast = sortexecs(\@fast);
|
|
229 |
my @ixslow = sortexecs(\@slow);
|
|
230 |
|
|
231 |
my $fileheader = <<EOF;
|
|
232 |
//
|
|
233 |
// Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).All rights reserved.
|
|
234 |
//
|
|
235 |
// GENERATED FILE - DO NOT EDIT
|
|
236 |
//
|
|
237 |
|
|
238 |
/**
|
|
239 |
* \@file
|
|
240 |
* \@internalComponent
|
|
241 |
*/
|
|
242 |
|
|
243 |
EOF
|
|
244 |
|
|
245 |
my @enumfile;
|
|
246 |
push @enumfile, $fileheader;
|
|
247 |
genenum(\@ixfast, \@enumfile, "TFastExecDispatch");
|
|
248 |
genenum(\@ixslow, \@enumfile, "TExecDispatch");
|
|
249 |
|
|
250 |
my @userfile;
|
|
251 |
push @userfile, $fileheader;
|
|
252 |
push @userfile, "class Exec\n\t{\npublic\:\n";
|
|
253 |
genexecp(\@ixfast, \@userfile);
|
|
254 |
genexecp(\@ixslow, \@userfile);
|
|
255 |
push @userfile, "\t\};\n\n";
|
|
256 |
push @userfile, "#ifdef __GEN_USER_EXEC_CODE__\n";
|
|
257 |
genuser(\@ixfast, \@userfile);
|
|
258 |
genuser(\@ixslow, \@userfile);
|
|
259 |
push @userfile, "#endif\n";
|
|
260 |
|
|
261 |
my @kernelfile;
|
|
262 |
push @kernelfile, $fileheader;
|
|
263 |
push @kernelfile, "class ExecHandler\n\t{\npublic\:\n";
|
|
264 |
genexechp(\@ixfast, \@kernelfile);
|
|
265 |
genexechp(\@ixslow, \@kernelfile);
|
|
266 |
push @kernelfile, "\t\};\n\n";
|
|
267 |
push @kernelfile, "#ifdef __GEN_KERNEL_EXEC_CODE__\n";
|
|
268 |
genkernelfast(\@ixfast, \@kernelfile);
|
|
269 |
genkernelslow(\@ixslow, \@kernelfile);
|
|
270 |
push @kernelfile, "#endif\n";
|
|
271 |
|
|
272 |
if ($opts{enum}) {
|
|
273 |
open FILE, ">$opts{enum}" or die "Can't open file $opts{enum} for write\n";
|
|
274 |
print FILE @enumfile;
|
|
275 |
close FILE;
|
|
276 |
}
|
|
277 |
if ($opts{user}) {
|
|
278 |
open FILE, ">$opts{user}" or die "Can't open file $opts{user} for write\n";
|
|
279 |
print FILE @userfile;
|
|
280 |
close FILE;
|
|
281 |
}
|
|
282 |
if ($opts{kernel}) {
|
|
283 |
open FILE, ">$opts{kernel}" or die "Can't open file $opts{kernel} for write\n";
|
|
284 |
print FILE @kernelfile;
|
|
285 |
close FILE;
|
|
286 |
}
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
# Match an input string against a list of strings with a list of synonyms.
|
|
292 |
# Any non-ambiguous abbreviation will be accepted.
|
|
293 |
# IN: 1st argument is input string
|
|
294 |
# 2nd argument is reference to match list
|
|
295 |
# 3rd argument is reference to synonym hash
|
|
296 |
# OUT: If match found, return undef and replace first argument with unabbreviated match string
|
|
297 |
# If no match found, return "Unknown"
|
|
298 |
# If ambiguous input, return "Ambiguous"
|
|
299 |
#
|
|
300 |
sub matchabbrev($$$) {
|
|
301 |
my ($inref, $lref, $sref)=@_;
|
|
302 |
my @matches = grep(/^$$inref/i,@$lref);
|
|
303 |
my $nmatches = scalar(@matches);
|
|
304 |
my $synonym = 0;
|
|
305 |
if ($nmatches==0) {
|
|
306 |
@matches = grep(/^$$inref/i,keys(%$sref));
|
|
307 |
$nmatches = scalar(@matches);
|
|
308 |
$synonym = 1;
|
|
309 |
}
|
|
310 |
return "Unknown" if ($nmatches==0);
|
|
311 |
if ($nmatches>1) {
|
|
312 |
my @xmatches=grep(/^$$inref$/i,@matches);
|
|
313 |
return "Ambiguous" if (scalar(@xmatches)!=1);
|
|
314 |
$$inref=$xmatches[0];
|
|
315 |
} else {
|
|
316 |
$$inref=$matches[0];
|
|
317 |
}
|
|
318 |
$$inref = $sref->{$$inref} if ($synonym);
|
|
319 |
return undef;
|
|
320 |
}
|
|
321 |
|
|
322 |
|
|
323 |
#
|
|
324 |
# Check a list of executive calls for bad or missing arguments
|
|
325 |
# and duplicate definitions.
|
|
326 |
# Assign executive dispatch numbers.
|
|
327 |
#
|
|
328 |
sub checkexecs($$) {
|
|
329 |
my ($listref, $listname) = @_;
|
|
330 |
my $next_num = 0;
|
|
331 |
my @execnum;
|
|
332 |
my @execnames;
|
|
333 |
foreach(@$listref) {
|
|
334 |
my $xref = $_;
|
|
335 |
my $n = $xref->{'number'};
|
|
336 |
my $type = $xref->{'type'};
|
|
337 |
if ($n) {
|
|
338 |
if ($execnum[$n]) {
|
|
339 |
die "Duplicate $listname exec number $n at $xref->{'file'} line $xref->{'line'}\n";
|
|
340 |
}
|
|
341 |
$execnum[$n] = 1;
|
|
342 |
}
|
|
343 |
my $nm = $xref->{'name'};
|
|
344 |
if (!$nm) {
|
|
345 |
die "Unnamed $listname exec at $xref->{'file'} line $xref->{'line'}\n";
|
|
346 |
} elsif ($nm !~ /^\w+$/) {
|
|
347 |
die "Invalid $listname exec name $nm at $xref->{'file'} line $xref->{'line'}\n";
|
|
348 |
}
|
|
349 |
if ( scalar(grep {$_ eq $nm} @execnames) ) {
|
|
350 |
die "Duplicate $listname exec name $nm at $xref->{'file'} line $xref->{'line'}\n";
|
|
351 |
}
|
|
352 |
push @execnames, $nm;
|
|
353 |
$xref->{'enumname'} = ($type==1) ? "EFastExec$nm" : "EExec$nm";
|
|
354 |
my $u = $xref->{'user'};
|
|
355 |
if ($u) {
|
|
356 |
if ($u eq 'special') {
|
|
357 |
undef $xref->{'userclass'};
|
|
358 |
undef $xref->{'userfunc'};
|
|
359 |
$xref->{'specialuser'} = -1;
|
|
360 |
} elsif ($u =~ /^(\w+)\:\:(\w+)$/) {
|
|
361 |
$xref->{'userclass'} = $1;
|
|
362 |
$xref->{'userfunc'} = $u;
|
|
363 |
} elsif ($u =~ /^\:\:(\w+)$/) {
|
|
364 |
$xref->{'userclass'} = '';
|
|
365 |
$xref->{'userfunc'} = $1;
|
|
366 |
} elsif ($u =~ /^(\w+)$/) {
|
|
367 |
$xref->{'userclass'} = $1;
|
|
368 |
$xref->{'userfunc'} = "$1::$nm";
|
|
369 |
}
|
|
370 |
} else {
|
|
371 |
$xref->{'userclass'} = 'Exec';
|
|
372 |
$xref->{'userfunc'} = "Exec::$nm";
|
|
373 |
}
|
|
374 |
my $k = $xref->{'kernel'};
|
|
375 |
if ($k) {
|
|
376 |
if ($k eq 'special') {
|
|
377 |
undef $xref->{'kernelclass'};
|
|
378 |
undef $xref->{'kernelfunc'};
|
|
379 |
if ($type!=1 || $n!=0) {
|
|
380 |
die "special kernel only applicable to FAST EXEC 0\n";
|
|
381 |
}
|
|
382 |
} elsif ($k =~ /^(\w+)\:\:(\w+)$/) {
|
|
383 |
$xref->{'kernelclass'} = $1;
|
|
384 |
$xref->{'kernelfunc'} = $k;
|
|
385 |
} elsif ($k =~ /^\:\:(\w+)$/) {
|
|
386 |
$xref->{'kernelclass'} = '';
|
|
387 |
$xref->{'kernelfunc'} = $1;
|
|
388 |
} elsif ($k =~ /^(\w+)$/) {
|
|
389 |
$xref->{'kernelclass'} = $1;
|
|
390 |
$xref->{'kernelfunc'} = "$1::$nm";
|
|
391 |
}
|
|
392 |
} else {
|
|
393 |
$xref->{'kernelclass'} = 'ExecHandler';
|
|
394 |
$xref->{'kernelfunc'} = "ExecHandler::$nm";
|
|
395 |
}
|
|
396 |
$xref->{'karg1'} = $xref->{'arg1'} if (!defined ($xref->{'karg1'}));
|
|
397 |
my $nargs = 0;
|
|
398 |
$nargs=1 if (defined $xref->{'karg1'});
|
|
399 |
if (!$xref->{'return'}) {
|
|
400 |
$xref->{'return'} = 'void';
|
|
401 |
}
|
|
402 |
$xref->{'nargs'} = $nargs;
|
|
403 |
my $spk = $xref->{'specialkernel'};
|
|
404 |
if ($spk =~ /(\w+)(\:\:\w+)?/) {
|
|
405 |
$xref->{'kerneldispatch'} = $spk;
|
|
406 |
} elsif ($spk) {
|
|
407 |
die "Invalid function name with SPECIALKERNEL at $xref->{'file'} line $xref->{'line'}\n";
|
|
408 |
} else {
|
|
409 |
$xref->{'kerneldispatch'} = $xref->{'kernelfunc'};
|
|
410 |
}
|
|
411 |
next if ($type == 1); # nothing more to do for fast execs
|
|
412 |
$xref->{'karg2'} = $xref->{'arg2'} if (!defined ($xref->{'karg2'}));
|
|
413 |
$xref->{'karg3'} = $xref->{'arg3'} if (!defined ($xref->{'karg3'}));
|
|
414 |
$xref->{'karg4'} = $xref->{'arg4'} if (!defined ($xref->{'karg4'}));
|
|
415 |
my $h = $xref->{'handle'};
|
|
416 |
if ($h) {
|
|
417 |
my $matchres = matchabbrev(\$h, \@object_list, \%object_synonyms);
|
|
418 |
if ($matchres) {
|
|
419 |
die "$matchres object type at $xref->{'file'} line $xref->{'line'}\n";
|
|
420 |
}
|
|
421 |
my $obj_info = $objects{$h};
|
|
422 |
my $add_one = $obj_info->[2];
|
|
423 |
if ($h eq 'any') {
|
|
424 |
$xref->{'handlep'} = "0";
|
|
425 |
} else {
|
|
426 |
if ($add_one) {
|
|
427 |
$xref->{'handlep'} = "$obj_info->[0]+1";
|
|
428 |
} else {
|
|
429 |
$xref->{'handlep'} = "$obj_info->[0]";
|
|
430 |
}
|
|
431 |
}
|
|
432 |
$xref->{'arg1'} = 'TInt';
|
|
433 |
$xref->{'karg1'} = "$obj_info->[1]"."*";
|
|
434 |
$xref->{'lock'} = -1;
|
|
435 |
}
|
|
436 |
$nargs=1 if (defined $xref->{'karg1'});
|
|
437 |
$nargs=2 if (defined $xref->{'karg2'});
|
|
438 |
$nargs=3 if (defined $xref->{'karg3'});
|
|
439 |
$nargs=4 if (defined $xref->{'karg4'});
|
|
440 |
$xref->{'nargs'} = $nargs;
|
|
441 |
if ($xref->{'nr'} && !$xref->{'lock'}) {
|
|
442 |
die "NR without LOCK/HANDLE at $xref->{'file'} line $xref->{'line'}\n";
|
|
443 |
}
|
|
444 |
if ($xref->{'unprotected'} && $xref->{'lock'}) {
|
|
445 |
die "UNPROTECTED and LOCK/HANDLE incompatible at $xref->{'file'} line $xref->{'line'}\n";
|
|
446 |
}
|
|
447 |
my $ext = $xref->{'extended'};
|
|
448 |
if ($ext) {
|
|
449 |
if ( ($ext !~ /^\d$/) || $ext<2 || $ext2>8) {
|
|
450 |
die "Invalid argument to EXTENDED at $xref->{'file'} line $xref->{'line'}\n";
|
|
451 |
} elsif ($nargs<3) {
|
|
452 |
die "Need >=3 normal arguments with EXTENDED at $xref->{'file'} line $xref->{'line'}\n";
|
|
453 |
}
|
|
454 |
}
|
|
455 |
}
|
|
456 |
foreach(@$listref) {
|
|
457 |
my $xref = $_;
|
|
458 |
my $n = $xref->{'number'};
|
|
459 |
unless ($n) {
|
|
460 |
while ($execnum[$next_num]) {
|
|
461 |
++$next_num;
|
|
462 |
}
|
|
463 |
$xref->{'number'} = $next_num++;
|
|
464 |
}
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
|
|
469 |
#
|
|
470 |
# Return a list of execs indexed by dispatch number
|
|
471 |
# Include gaps for nonexistent ones
|
|
472 |
#
|
|
473 |
sub sortexecs($) {
|
|
474 |
my ($listref) = @_;
|
|
475 |
my @indexed;
|
|
476 |
my $xref;
|
|
477 |
foreach $xref (@$listref) {
|
|
478 |
my $n = $xref->{'number'};
|
|
479 |
$indexed[$n] = $xref;
|
|
480 |
}
|
|
481 |
return @indexed;
|
|
482 |
}
|
|
483 |
|
|
484 |
#
|
|
485 |
# Generate enum definition
|
|
486 |
#
|
|
487 |
sub genenum($$$) {
|
|
488 |
my ($srcref, $destref, $enumname) = @_;
|
|
489 |
push @$destref, "\nenum $enumname\n\t\{\n";
|
|
490 |
my $n;
|
|
491 |
my $xref;
|
|
492 |
for ($n=0; $n<scalar(@$srcref); ++$n) {
|
|
493 |
$xref = $$srcref[$n];
|
|
494 |
if ($xref) {
|
|
495 |
push @$destref, "\t$xref->{'enumname'} = $n,\n";
|
|
496 |
}
|
|
497 |
}
|
|
498 |
push @$destref, "\t\};\n";
|
|
499 |
}
|
|
500 |
|
|
501 |
#
|
|
502 |
# Output Exec class prototypes
|
|
503 |
#
|
|
504 |
sub genexecp($$) {
|
|
505 |
my ($srcref, $destref) = @_;
|
|
506 |
my $n;
|
|
507 |
my $xref;
|
|
508 |
for ($n=0; $n<scalar(@$srcref); ++$n) {
|
|
509 |
$xref = $$srcref[$n];
|
|
510 |
if ($xref && $xref->{'userclass'} eq 'Exec') {
|
|
511 |
$xref->{'userfunc'} =~ /^Exec\:\:(\w+)$/;
|
|
512 |
my $fdecl = "\t";
|
|
513 |
$fdecl .= "IMPORT_C " if ($xref->{'export'});
|
|
514 |
$fdecl .= "static $xref->{'return'} $1\(";
|
|
515 |
$fdecl .= $xref->{'arg1'} if ($xref->{'arg1'});
|
|
516 |
$fdecl .= ", $xref->{'arg2'}" if ($xref->{'arg2'});
|
|
517 |
$fdecl .= ", $xref->{'arg3'}" if ($xref->{'arg3'});
|
|
518 |
$fdecl .= ", $xref->{'arg4'}" if ($xref->{'arg4'});
|
|
519 |
$fdecl .= "\);\n";
|
|
520 |
push @$destref, $fdecl;
|
|
521 |
}
|
|
522 |
}
|
|
523 |
}
|
|
524 |
|
|
525 |
#
|
|
526 |
# Output ExecHandler class prototypes
|
|
527 |
#
|
|
528 |
sub genexechp($$) {
|
|
529 |
my ($srcref, $destref) = @_;
|
|
530 |
my $n;
|
|
531 |
my $xref;
|
|
532 |
for ($n=0; $n<scalar(@$srcref); ++$n) {
|
|
533 |
$xref = $$srcref[$n];
|
|
534 |
if ($xref && $xref->{'kernelclass'} eq 'ExecHandler') {
|
|
535 |
$xref->{'kernelfunc'} =~ /^ExecHandler\:\:(\w+)$/;
|
|
536 |
my $fdecl = "\tstatic $xref->{'return'} $1\(";
|
|
537 |
$fdecl .= $xref->{'karg1'} if ($xref->{'karg1'});
|
|
538 |
$fdecl .= ", $xref->{'karg2'}" if ($xref->{'karg2'});
|
|
539 |
$fdecl .= ", $xref->{'karg3'}" if ($xref->{'karg3'});
|
|
540 |
$fdecl .= ", $xref->{'karg4'}" if ($xref->{'karg4'});
|
|
541 |
$fdecl .= "\);\n";
|
|
542 |
push @$destref, $fdecl;
|
|
543 |
}
|
|
544 |
}
|
|
545 |
}
|
|
546 |
|
|
547 |
|
|
548 |
#
|
|
549 |
# Create conditional inclusion line
|
|
550 |
#
|
|
551 |
sub conditional($) {
|
|
552 |
my ($xref) = @_;
|
|
553 |
my $ifdefref = $xref->{'ifdef'};
|
|
554 |
my $ifndefref = $xref->{'ifndef'};
|
|
555 |
if (!$ifdefref and !$ifndefref) {
|
|
556 |
return undef;
|
|
557 |
}
|
|
558 |
my $n = 0;
|
|
559 |
my $cond = '#if';
|
|
560 |
foreach $x (@$ifdefref) {
|
|
561 |
$cond .= ' &&' if ($n);
|
|
562 |
++$n;
|
|
563 |
$cond .= " defined($x)";
|
|
564 |
}
|
|
565 |
foreach $x (@$ifndefref) {
|
|
566 |
$cond .= ' &&' if ($n);
|
|
567 |
++$n;
|
|
568 |
$cond .= " !defined($x)";
|
|
569 |
}
|
|
570 |
return $cond;
|
|
571 |
}
|
|
572 |
|
|
573 |
|
|
574 |
#
|
|
575 |
# Output user-side code
|
|
576 |
#
|
|
577 |
sub genuser($$) {
|
|
578 |
my ($srcref, $destref) = @_;
|
|
579 |
my $n;
|
|
580 |
my $xref;
|
|
581 |
for ($n=0; $n<scalar(@$srcref); ++$n) {
|
|
582 |
$xref = $$srcref[$n];
|
|
583 |
if ($xref && !$xref->{'specialuser'}) {
|
|
584 |
my $fdecl = "";
|
|
585 |
my $endif = 0;
|
|
586 |
my $cond = "";
|
|
587 |
$cond = conditional($xref) unless ($xref->{'export'});
|
|
588 |
if ($cond) {
|
|
589 |
$fdecl .= "$cond\n";
|
|
590 |
$endif = 1;
|
|
591 |
}
|
|
592 |
$fdecl .= "EXPORT_C " if ($xref->{'export'});
|
|
593 |
$fdecl .= "__EXECDECL__ $xref->{'return'} $xref->{'userfunc'}\(";
|
|
594 |
$fdecl .= $xref->{'arg1'} if ($xref->{'arg1'});
|
|
595 |
$fdecl .= ", $xref->{'arg2'}" if ($xref->{'arg2'});
|
|
596 |
$fdecl .= ", $xref->{'arg3'}" if ($xref->{'arg3'});
|
|
597 |
$fdecl .= ", $xref->{'arg4'}" if ($xref->{'arg4'});
|
|
598 |
$fdecl .= "\)\n\t\{\n";
|
|
599 |
my $macro = ($xref->{'type'}==1) ? "FAST_EXEC" : "SLOW_EXEC";
|
|
600 |
$macro.=chr(48+$xref->{'nargs'});
|
|
601 |
$fdecl .= "\t$macro\($xref->{'enumname'}\);\n";
|
|
602 |
$fdecl .= "\t\}\n";
|
|
603 |
$fdecl .= "#endif\n" if ($endif);
|
|
604 |
$fdecl .= "\n";
|
|
605 |
push @$destref, $fdecl;
|
|
606 |
}
|
|
607 |
}
|
|
608 |
}
|
|
609 |
|
|
610 |
|
|
611 |
#
|
|
612 |
# Output fast exec dispatch table
|
|
613 |
#
|
|
614 |
sub genkernelfast($$) {
|
|
615 |
my ($srcref, $destref) = @_;
|
|
616 |
my $fast_count = scalar(@$srcref);
|
|
617 |
push @$destref, "#define\tFAST_EXEC_COUNT\t\t$fast_count\n\n";
|
|
618 |
push @$destref, "FAST_EXEC_BEGIN\n";
|
|
619 |
push @$destref, "DECLARE_WORD(FAST_EXEC_COUNT)\n";
|
|
620 |
my $n;
|
|
621 |
my $xref;
|
|
622 |
for ($n=0; $n<$fast_count; ++$n) {
|
|
623 |
$xref = $$srcref[$n];
|
|
624 |
my $endif=0;
|
|
625 |
if ($xref && $xref->{'kernelfunc'}) {
|
|
626 |
my $cond = conditional($xref);
|
|
627 |
if ($cond) {
|
|
628 |
push @$destref, "$cond\n";
|
|
629 |
$endif = 1;
|
|
630 |
}
|
|
631 |
my $asm = $xref->{'asm'};
|
|
632 |
if ($asm =~ /^\w+$/) {
|
|
633 |
push @$destref, "#ifdef $asm\n";
|
|
634 |
}
|
|
635 |
if ($asm) {
|
|
636 |
push @$destref, "DECLARE_ASM_FUNC(_asm_exec_$xref->{'name'}, $xref->{'kerneldispatch'})\n";
|
|
637 |
} else {
|
|
638 |
push @$destref, "DECLARE_FUNC($xref->{'kerneldispatch'})\n";
|
|
639 |
}
|
|
640 |
if ($asm =~ /^\w+$/) {
|
|
641 |
push @$destref, "#else\n";
|
|
642 |
push @$destref, "DECLARE_FUNC($xref->{'kerneldispatch'})\n";
|
|
643 |
push @$destref, "#endif\n";
|
|
644 |
}
|
|
645 |
if ($endif) {
|
|
646 |
push @$destref, "#else\nDECLARE_FAST_EXEC_INVALID\n#endif\n";
|
|
647 |
}
|
|
648 |
} elsif (!$xref || $xref->{'number'}!=0) {
|
|
649 |
push @$destref, "DECLARE_FAST_EXEC_INVALID\n";
|
|
650 |
}
|
|
651 |
}
|
|
652 |
push @$destref, "FAST_EXEC_END\n\n\n";
|
|
653 |
}
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
#
|
|
658 |
# Output slow exec dispatch table
|
|
659 |
#
|
|
660 |
sub genkernelslow($$) {
|
|
661 |
my ($srcref, $destref) = @_;
|
|
662 |
my $slow_count = scalar(@$srcref);
|
|
663 |
push @$destref, "#define\tSLOW_EXEC_COUNT\t\t$slow_count\n\n";
|
|
664 |
push @$destref, "SLOW_EXEC_BEGIN\n";
|
|
665 |
push @$destref, "DECLARE_WORD(SLOW_EXEC_COUNT)\n";
|
|
666 |
push @$destref, "DECLARE_INVALID_EXEC_HANDLER\n";
|
|
667 |
push @$destref, "DECLARE_EXEC_PREPROCESS_HANDLER\n";
|
|
668 |
my $n;
|
|
669 |
my $xref;
|
|
670 |
for ($n=0; $n<$slow_count; ++$n) {
|
|
671 |
$xref = $$srcref[$n];
|
|
672 |
my $endif=0;
|
|
673 |
my $xflags="0";
|
|
674 |
$xflags .= "|EF_C" if ($xref->{'lock'});
|
|
675 |
$xflags .= "|EF_R" if ( ($xref->{'lock'}) && !($xref->{'nr'}) );
|
|
676 |
if (defined $xref->{'handlep'}) {
|
|
677 |
$xflags .= "|EF_P|($xref->{'handlep'})";
|
|
678 |
}
|
|
679 |
if ($xref->{'extended'}) {
|
|
680 |
$xflags .= "|EF_A".chr($xref->{'extended'} + 48);
|
|
681 |
}
|
|
682 |
if ($xref && $xref->{'kernelfunc'}) {
|
|
683 |
my $cond = conditional($xref);
|
|
684 |
if ($cond) {
|
|
685 |
push @$destref, "$cond\n";
|
|
686 |
$endif = 1;
|
|
687 |
}
|
|
688 |
my $asm = $xref->{'asm'};
|
|
689 |
if ($asm =~ /^\w+$/) {
|
|
690 |
push @$destref, "#ifdef $asm\n";
|
|
691 |
}
|
|
692 |
if ($asm) {
|
|
693 |
push @$destref, "DECLARE_FLAGS_ASMFUNC($xflags, _asm_exec_$xref->{'name'}, $xref->{'kerneldispatch'})\n";
|
|
694 |
} else {
|
|
695 |
push @$destref, "DECLARE_FLAGS_FUNC($xflags, $xref->{'kerneldispatch'})\n";
|
|
696 |
}
|
|
697 |
if ($asm =~ /^\w+$/) {
|
|
698 |
push @$destref, "#else\n";
|
|
699 |
push @$destref, "DECLARE_FLAGS_FUNC($xflags, $xref->{'kerneldispatch'})\n";
|
|
700 |
push @$destref, "#endif\n";
|
|
701 |
}
|
|
702 |
if ($endif) {
|
|
703 |
push @$destref, "#else\nDECLARE_SLOW_EXEC_INVALID\n#endif\n";
|
|
704 |
}
|
|
705 |
} else {
|
|
706 |
push @$destref, "DECLARE_SLOW_EXEC_INVALID\n";
|
|
707 |
}
|
|
708 |
}
|
|
709 |
push @$destref, "SLOW_EXEC_END\n\n\n";
|
|
710 |
}
|
|
711 |
|