1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
#!/bin/perl
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
#
use strict;
use File::Basename;
my $PROGNAME = basename($0);
my ($funcunit, $error);
my @funcunits = ();
my @errorrefs = ();
my $codelinesin = 0; # number of input 'code' lines for an ereport type
my $codeoutlen = 0; # number of output lines from sub state_code
my $state = "initial";
sub usage() {
print STDERR "Usage: $PROGNAME inputfile\n";
exit(2);
}
sub bail() {
print STDERR "$PROGNAME: ", join(" ", @_), "\n";
exit(1);
}
sub parsebail() {
print STDERR "$PROGNAME: $::infile: $.: ", join(" ", @_), "\n";
exit(1);
}
sub error_alloc() {
my @a = ();
push(@::errorrefs, \@a);
return (\@a);
}
sub error_dup() {
my ($drop) = @_;
my $newref = &error_alloc();
my $zeroref = $::errorrefs[0];
my $n = $#$zeroref - $drop;
@$newref = @$zeroref[0 .. $n];
}
sub code_lines() {
return ($::codelinesin++);
}
sub error_init() {
&error_alloc();
$::codelinesin = 0;
}
sub error_reset() {
@::errorrefs = ();
$::codelinesin = 0;
$::codeoutlen = 0;
}
sub errout() {
my ($line) = @_;
foreach my $ref (@::errorrefs) {
push(@$ref, $line);
}
}
sub errout_N() {
my ($instance, $line) = @_;
my $ref = @::errorrefs[$instance];
push(@$ref, $line);
return 1;
}
sub print_errout() {
foreach my $ref (@::errorrefs) {
print @$ref;
}
}
sub print_header() {
print "#include \"ao_mca_disp.h\"\n\n";
}
sub print_footer() {
print 'const ao_error_disp_t *ao_error_disp[] = {' . "\n";
foreach my $name (@funcunits) {
print "\t$name,\n";
}
print "};\n";
}
sub funcunit_begin() {
my $arrnm = "ao_error_disp_" . $_[0];
print "static const ao_error_disp_t " . $arrnm . "[] = {\n";
@funcunits = (@funcunits, $arrnm);
}
sub funcunit_end() {
print "\t{ NULL }\n};\n\n";
}
sub error_begin() {
my ($ereport_name) = @_;
$ereport_name =~ tr/[a-z]./[A-Z]_/;
my $flags_name = $ereport_name;
$flags_name =~ s/EREPORT_/EREPORT_PAYLOAD_FLAGS_/;
&errout("\tFM_$ereport_name,\n\tFM_$flags_name,\n");
}
sub error_end() {
&errout("\t},\n\n");
&print_errout();
&error_reset();
}
sub print_bits() {
my $name = $_[0];
my @bits = @_[1..$#_];
my $out = "";
if (@bits == 0) {
$out = "\t0,";
} elsif (@bits == 1) {
$out = "\t$bits[0],";
} else {
$out = "\t( " . join(" | ", @bits) . " ),";
}
$out .= " /* $name */" if (defined $name);
$out .= "\n";
return ($out);
}
sub field_burst() {
my ($field, $valuesref, $name, $prefix) = @_;
if ($field eq "-") {
return ();
}
map {
if (!defined ${$valuesref}{$_}) {
&parsebail("unknown $name value `$_'");
}
$_ = ${$valuesref}{$_};
tr/[a-z]/[A-Z]/;
$prefix . "_" . $_;
} split(/\//, $field);
}
sub bin2dec() {
my $bin = $_[0];
my $dec = 0;
foreach my $bit (split(//, $bin)) {
$dec = $dec * 2 + ($bit eq "1" ? 1 : 0);
}
$dec;
}
sub state_funcunit() {
my $val = $_[0];
if (defined $::funcunit) {
&funcunit_end();
}
$::funcunit = $val;
undef $::error;
&funcunit_begin($::funcunit);
}
sub state_desc() {
my $desc = $_[0];
&error_init();
&errout("\t/* $desc */\n\t{\n");
}
sub state_error() {
$::error = $_[0];
&error_begin($::error);
}
sub state_mask_on() {
@::mask_on = map { tr/[a-z]/[A-Z]/; $_; } split(/,\s*/, $_[0]);
}
sub state_mask_off() {
my @mask_off = map { tr/[a-z]/[A-Z]/; $_; } split(/,\s*/, $_[0]);
&errout(&print_bits("mask", @::mask_on, @mask_off));
&errout(&print_bits("mask_res", @::mask_on));
}
sub state_code() {
my ($ext, $type, $pp, $t, $r4, $addr, $ii, $ll, $tt) =
split(/\s+/, $_[0]);
my %tt_values = ( instr => 1, data => 1, gen => 1, '-' => 1 );
my %ll_values = ( l0 => 1, l1 => 1, l2 => 1, lg => 1 );
my %r4_values = (
gen => 'gen',
rd => 'rd',
wr => 'wr',
drd => 'drd',
dwr => 'dwr',
ird => 'ird',
pf => 'prefetch',
ev => 'evict',
snp => 'snoop',
'-' => '-');
my %pp_values = (
src => 'src',
rsp => 'rsp',
obs => 'obs',
gen => 'gen',
'-' => '-' );
my %t_values = ( 0 => 1, 1 => 1, '-' => 1 );
my %ii_values = (
mem => 'mem',
io => 'io',
gen => 'gen',
'-' => '-' );
my $instance = &code_lines();
if ($instance > 0) {
&error_dup($::codeoutlen); # dup info thus far
}
if (!defined $tt_values{$tt}) {
&parsebail("unknown tt value `$tt'");
}
if (!defined $ll_values{$ll}) {
&parsebail("unknown ll value `$ll'");
}
my @r4 = &field_burst($r4, \%r4_values, "r4", "AO_MCA_R4_BIT");
my @pp = ($pp eq '-') ? () :
&field_burst($pp, \%pp_values, "pp", "AO_MCA_PP_BIT");
if (!defined $t_values{$t}) {
&parsebail("unknown t value `$t'");
}
my @ii = ($ii eq '-') ? () :
&field_burst($ii, \%ii_values, "ii", "AO_MCA_II_BIT");
map {
tr/[a-z]/[A-Z]/;
} ($ii, $ll, $tt);
if ($type eq "bus") {
if ($pp eq "-" || $t eq "-" || $r4 eq "-" || $ii eq "-" ||
$ll eq "-" ||
$tt ne "-") {
&parsebail("invalid members for bus code type");
}
$::codeoutlen += &errout_N($instance, "\tAMD_ERRCODE_MKBUS(" .
"0, " . # pp
"AMD_ERRCODE_T_" . ($t ? "TIMEOUT" : "NONE") . ", " .
"0, " . # r4
"0, " . # ii
"AMD_ERRCODE_LL_$ll),\n");
} elsif ($type eq "mem") {
if ($r4 eq "-" || $tt eq "-" || $ll eq "-" ||
$pp ne "-" || $t ne "-" || $ii ne "-") {
&parsebail("invalid members for mem code type");
}
$::codeoutlen += &errout_N($instance, "\tAMD_ERRCODE_MKMEM(" .
"0, " . # r4
"AMD_ERRCODE_TT_$tt, " .
"AMD_ERRCODE_LL_$ll),\n");
} elsif ($type eq "tlb") {
if ($tt eq "-" || $ll eq "-" ||
$r4 ne "-" || $pp ne "-" || $t ne "-" || $ii ne "-") {
&parsebail("invalid members for tlb code type");
}
$::codeoutlen += &errout_N($instance, "\tAMD_ERRCODE_MKTLB(" .
"AMD_ERRCODE_TT_$tt, " .
"AMD_ERRCODE_LL_$ll),\n");
} else {
&parsebail("unknown code type `$type'");
}
$::codeoutlen += &errout_N($instance, "\t" . &bin2dec($ext) .
", /* ext code $ext */\n");
$::codeoutlen += &errout_N($instance, &print_bits("pp_bits", @pp));
$::codeoutlen += &errout_N($instance, &print_bits("ii_bits", @ii));
$::codeoutlen += &errout_N($instance, &print_bits("r4_bits", @r4));
my $valid_hi;
my $valid_lo;
if ($addr eq "none") {
$valid_hi = $valid_lo = 0;
} elsif ($addr =~ /<(\d+):(\d+)>/) {
$valid_hi = $1;
$valid_lo = $2;
} else {
&parsebail("invalid addr specification");
}
$::codeoutlen += &errout_N($instance, "\t" . $valid_hi .
", /* addr valid hi */\n");
$::codeoutlen += &errout_N($instance, "\t" . $valid_lo .
", /* addr valid lo */\n");
}
sub state_panic() {
my @vals = split(/,\s*/, $_[0]);
if ($#vals < 0) {
&errout("\t0, /* panic_when */\n");
} else {
@vals = map { tr/[a-z]/[A-Z]/; "AO_AED_PANIC_" . $_; } @vals;
&errout(&print_bits("panic_when", @vals));
}
}
sub state_flags() {
my @flags = split(/,\s*/, $_[0]);
@flags = map { tr/[a-z]/[A-Z]/; "AO_AED_F_" . $_; } @flags;
&errout(&print_bits("flags", @flags));
}
my %stateparse = (
funcunit => [ \&state_funcunit, 'desc' ],
desc => [ \&state_desc, 'error' ],
error => [ \&state_error, 'mask on' ],
'mask on' => [ \&state_mask_on, 'mask off' ],
'mask off' => [ \&state_mask_off, 'code' ],
code => [ \&state_code, 'code|panic' ],
panic => [ \&state_panic, 'flags' ],
flags => [ \&state_flags, 'initial' ]
);
usage unless (@ARGV == 1);
my $infile = $ARGV[0];
open(INFILE, "<$infile") || &bail("failed to open $infile: $!");
&print_header();
while (<INFILE>) {
chop;
/^#/ && next;
/^$/ && next;
if (!/^\s*(\S[^=]*\S)\s*=\s*(\S.*)?$/) {
&parsebail("failed to parse");
}
my ($keyword, $val) = ($1, $2);
if ($state eq "initial") {
if ($keyword eq "funcunit") {
$state = "funcunit";
} elsif ($keyword eq "desc") {
$state = "desc";
} else {
&parsebail("unexpected keyword $keyword between " .
"errors");
}
} elsif ($state eq "desc") {
if ($keyword eq "funcunit") {
$state = "funcunit";
}
}
if (!($keyword =~ /$state/)) {
&parsebail("keyword `$keyword' invalid here; expected " .
"`$state'");
}
$state = $keyword; # disambiguate between multiple legal states
if (!defined $stateparse{$state}) {
&parsebail("attempt to transition to invalid state `$state'");
}
my ($handler, $next) = @{$stateparse{$state}};
&{$handler}($val);
$state = $next;
if ($state eq "initial") {
&error_end();
}
}
close(INFILE);
if ($state ne "initial" && $state ne "desc") {
&bail("input file ended prematurely");
}
if (defined $::funcunit) {
&funcunit_end();
} else {
&bail("no functional units defined");
}
&print_footer;
|