ao_gendisp.pl (a307a255) ao_gendisp.pl (4156fc34)
1#!/bin/perl
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#

--- 20 unchanged lines hidden (view full) ---

29
30use strict;
31use File::Basename;
32
33my $PROGNAME = basename($0);
34
35my ($funcunit, $error);
36my @funcunits = ();
1#!/bin/perl
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#

--- 20 unchanged lines hidden (view full) ---

29
30use strict;
31use File::Basename;
32
33my $PROGNAME = basename($0);
34
35my ($funcunit, $error);
36my @funcunits = ();
37my @errorrefs = ();
37
38
39my $codelinesin = 0; # number of input 'code' lines for an ereport type
40my $codeoutlen = 0; # number of output lines from sub state_code
41
38my $state = "initial";
39
40sub usage() {
41 print STDERR "Usage: $PROGNAME inputfile\n";
42 exit(2);
43}
44
45sub bail() {
46 print STDERR "$PROGNAME: ", join(" ", @_), "\n";
47 exit(1);
48}
49
50sub parsebail() {
51 print STDERR "$PROGNAME: $::infile: $.: ", join(" ", @_), "\n";
52 exit(1);
53}
54
42my $state = "initial";
43
44sub usage() {
45 print STDERR "Usage: $PROGNAME inputfile\n";
46 exit(2);
47}
48
49sub bail() {
50 print STDERR "$PROGNAME: ", join(" ", @_), "\n";
51 exit(1);
52}
53
54sub parsebail() {
55 print STDERR "$PROGNAME: $::infile: $.: ", join(" ", @_), "\n";
56 exit(1);
57}
58
59sub error_alloc() {
60 my @a = ();
61
62 push(@::errorrefs, \@a);
63 return (\@a);
64}
65
66sub error_dup() {
67 my ($drop) = @_;
68 my $newref = &error_alloc();
69
70 my $zeroref = $::errorrefs[0];
71
72 my $n = $#$zeroref - $drop;
73
74 @$newref = @$zeroref[0 .. $n];
75}
76
77sub code_lines() {
78 return ($::codelinesin++);
79}
80
81sub error_init() {
82 &error_alloc();
83 $::codelinesin = 0;
84}
85
86sub error_reset() {
87 @::errorrefs = ();
88 $::codelinesin = 0;
89 $::codeoutlen = 0;
90}
91
92sub errout() {
93 my ($line) = @_;
94
95 foreach my $ref (@::errorrefs) {
96 push(@$ref, $line);
97 }
98}
99
100sub errout_N() {
101 my ($instance, $line) = @_;
102 my $ref = @::errorrefs[$instance];
103 push(@$ref, $line);
104 return 1;
105}
106
107sub print_errout() {
108 foreach my $ref (@::errorrefs) {
109 print @$ref;
110 }
111}
112
55sub print_header() {
56 print "#include \"ao_mca_disp.h\"\n\n";
57}
58
59sub print_footer() {
113sub print_header() {
114 print "#include \"ao_mca_disp.h\"\n\n";
115}
116
117sub print_footer() {
60 print "const ao_error_disp_t *ao_error_disp[] = {\n";
118 print 'const ao_error_disp_t *ao_error_disp[] = {' . "\n";
61
62 foreach my $name (@funcunits) {
63 print "\t$name,\n";
64 }
65
66 print "};\n";
67}
68
69sub funcunit_begin() {
70 my $arrnm = "ao_error_disp_" . $_[0];
71 print "static const ao_error_disp_t " . $arrnm . "[] = {\n";
72
73 @funcunits = (@funcunits, $arrnm);
74}
75
76sub funcunit_end() {
119
120 foreach my $name (@funcunits) {
121 print "\t$name,\n";
122 }
123
124 print "};\n";
125}
126
127sub funcunit_begin() {
128 my $arrnm = "ao_error_disp_" . $_[0];
129 print "static const ao_error_disp_t " . $arrnm . "[] = {\n";
130
131 @funcunits = (@funcunits, $arrnm);
132}
133
134sub funcunit_end() {
77 print "\tNULL\n};\n\n";
135 print "\t{ NULL }\n};\n\n";
78}
79
80sub error_begin() {
81 my ($ereport_name) = @_;
82
83 $ereport_name =~ tr/[a-z]./[A-Z]_/;
84 my $flags_name = $ereport_name;
85 $flags_name =~ s/EREPORT_/EREPORT_PAYLOAD_FLAGS_/;
86
136}
137
138sub error_begin() {
139 my ($ereport_name) = @_;
140
141 $ereport_name =~ tr/[a-z]./[A-Z]_/;
142 my $flags_name = $ereport_name;
143 $flags_name =~ s/EREPORT_/EREPORT_PAYLOAD_FLAGS_/;
144
87 print "\tFM_$ereport_name,\n\tFM_$flags_name,\n";
145 &errout("\tFM_$ereport_name,\n\tFM_$flags_name,\n");
88}
89
90sub error_end() {
146}
147
148sub error_end() {
91 print "\t},\n\n";
149 &errout("\t},\n\n");
150
151 &print_errout();
152
153 &error_reset();
92}
93
94sub print_bits() {
95 my $name = $_[0];
96 my @bits = @_[1..$#_];
154}
155
156sub print_bits() {
157 my $name = $_[0];
158 my @bits = @_[1..$#_];
159 my $out = "";
97
98 if (@bits == 0) {
160
161 if (@bits == 0) {
99 print "\t0,";
162 $out = "\t0,";
100 } elsif (@bits == 1) {
163 } elsif (@bits == 1) {
101 print "\t$bits[0],";
164 $out = "\t$bits[0],";
102 } else {
165 } else {
103 print "\t( ", join(" | ", @bits), " ),";
166 $out = "\t( " . join(" | ", @bits) . " ),";
104 }
105
167 }
168
106 print " /* $name */" if (defined $name);
107 print "\n";
169 $out .= " /* $name */" if (defined $name);
170 $out .= "\n";
171
172 return ($out);
108}
109
110sub field_burst() {
111 my ($field, $valuesref, $name, $prefix) = @_;
112
113 if ($field eq "-") {
114 return ();
115 }

--- 29 unchanged lines hidden (view full) ---

145 $::funcunit = $val;
146 undef $::error;
147 &funcunit_begin($::funcunit);
148}
149
150sub state_desc() {
151 my $desc = $_[0];
152
173}
174
175sub field_burst() {
176 my ($field, $valuesref, $name, $prefix) = @_;
177
178 if ($field eq "-") {
179 return ();
180 }

--- 29 unchanged lines hidden (view full) ---

210 $::funcunit = $val;
211 undef $::error;
212 &funcunit_begin($::funcunit);
213}
214
215sub state_desc() {
216 my $desc = $_[0];
217
153 print "\t/* $desc */\n\t{\n";
218 &error_init();
219
220 &errout("\t/* $desc */\n\t{\n");
154}
155
156sub state_error() {
157 $::error = $_[0];
158 &error_begin($::error);
159}
160
161sub state_mask_on() {
162 @::mask_on = map { tr/[a-z]/[A-Z]/; $_; } split(/,\s*/, $_[0]);
163}
164
165sub state_mask_off() {
166 my @mask_off = map { tr/[a-z]/[A-Z]/; $_; } split(/,\s*/, $_[0]);
167
221}
222
223sub state_error() {
224 $::error = $_[0];
225 &error_begin($::error);
226}
227
228sub state_mask_on() {
229 @::mask_on = map { tr/[a-z]/[A-Z]/; $_; } split(/,\s*/, $_[0]);
230}
231
232sub state_mask_off() {
233 my @mask_off = map { tr/[a-z]/[A-Z]/; $_; } split(/,\s*/, $_[0]);
234
168 &print_bits("mask", @::mask_on, @mask_off);
169 &print_bits("mask_res", @::mask_on);
235 &errout(&print_bits("mask", @::mask_on, @mask_off));
236 &errout(&print_bits("mask_res", @::mask_on));
170}
171
172sub state_code() {
237}
238
239sub state_code() {
173 my ($ext, $type, $pp, $t, $r4, $ii, $ll, $tt) = split(/\s+/, $_[0]);
240 my ($ext, $type, $pp, $t, $r4, $addr, $ii, $ll, $tt) =
241 split(/\s+/, $_[0]);
174
175 my %tt_values = ( instr => 1, data => 1, gen => 1, '-' => 1 );
176 my %ll_values = ( l0 => 1, l1 => 1, l2 => 1, lg => 1 );
177
178 my %r4_values = (
179 gen => 'gen',
180 rd => 'rd',
181 wr => 'wr',

--- 15 unchanged lines hidden (view full) ---

197 my %t_values = ( 0 => 1, 1 => 1, '-' => 1 );
198
199 my %ii_values = (
200 mem => 'mem',
201 io => 'io',
202 gen => 'gen',
203 '-' => '-' );
204
242
243 my %tt_values = ( instr => 1, data => 1, gen => 1, '-' => 1 );
244 my %ll_values = ( l0 => 1, l1 => 1, l2 => 1, lg => 1 );
245
246 my %r4_values = (
247 gen => 'gen',
248 rd => 'rd',
249 wr => 'wr',

--- 15 unchanged lines hidden (view full) ---

265 my %t_values = ( 0 => 1, 1 => 1, '-' => 1 );
266
267 my %ii_values = (
268 mem => 'mem',
269 io => 'io',
270 gen => 'gen',
271 '-' => '-' );
272
273 my $instance = &code_lines();
274 if ($instance > 0) {
275 &error_dup($::codeoutlen); # dup info thus far
276 }
277
205 if (!defined $tt_values{$tt}) {
206 &parsebail("unknown tt value `$tt'");
207 }
208
209 if (!defined $ll_values{$ll}) {
210 &parsebail("unknown ll value `$ll'");
211 }
212

--- 15 unchanged lines hidden (view full) ---

228
229 if ($type eq "bus") {
230 if ($pp eq "-" || $t eq "-" || $r4 eq "-" || $ii eq "-" ||
231 $ll eq "-" ||
232 $tt ne "-") {
233 &parsebail("invalid members for bus code type");
234 }
235
278 if (!defined $tt_values{$tt}) {
279 &parsebail("unknown tt value `$tt'");
280 }
281
282 if (!defined $ll_values{$ll}) {
283 &parsebail("unknown ll value `$ll'");
284 }
285

--- 15 unchanged lines hidden (view full) ---

301
302 if ($type eq "bus") {
303 if ($pp eq "-" || $t eq "-" || $r4 eq "-" || $ii eq "-" ||
304 $ll eq "-" ||
305 $tt ne "-") {
306 &parsebail("invalid members for bus code type");
307 }
308
236 print "\tAMD_ERRCODE_MKBUS(" .
309 $::codeoutlen += &errout_N($instance, "\tAMD_ERRCODE_MKBUS(" .
237 "0, " . # pp
238 "AMD_ERRCODE_T_" . ($t ? "TIMEOUT" : "NONE") . ", " .
239 "0, " . # r4
240 "0, " . # ii
310 "0, " . # pp
311 "AMD_ERRCODE_T_" . ($t ? "TIMEOUT" : "NONE") . ", " .
312 "0, " . # r4
313 "0, " . # ii
241 "AMD_ERRCODE_LL_$ll),\n";
314 "AMD_ERRCODE_LL_$ll),\n");
242
243 } elsif ($type eq "mem") {
244 if ($r4 eq "-" || $tt eq "-" || $ll eq "-" ||
245 $pp ne "-" || $t ne "-" || $ii ne "-") {
246 &parsebail("invalid members for mem code type");
247 }
248
315
316 } elsif ($type eq "mem") {
317 if ($r4 eq "-" || $tt eq "-" || $ll eq "-" ||
318 $pp ne "-" || $t ne "-" || $ii ne "-") {
319 &parsebail("invalid members for mem code type");
320 }
321
249 print "\tAMD_ERRCODE_MKMEM(" .
322 $::codeoutlen += &errout_N($instance, "\tAMD_ERRCODE_MKMEM(" .
250 "0, " . # r4
251 "AMD_ERRCODE_TT_$tt, " .
323 "0, " . # r4
324 "AMD_ERRCODE_TT_$tt, " .
252 "AMD_ERRCODE_LL_$ll),\n";
325 "AMD_ERRCODE_LL_$ll),\n");
253
254 } elsif ($type eq "tlb") {
255 if ($tt eq "-" || $ll eq "-" ||
256 $r4 ne "-" || $pp ne "-" || $t ne "-" || $ii ne "-") {
257 &parsebail("invalid members for tlb code type");
258 }
259
326
327 } elsif ($type eq "tlb") {
328 if ($tt eq "-" || $ll eq "-" ||
329 $r4 ne "-" || $pp ne "-" || $t ne "-" || $ii ne "-") {
330 &parsebail("invalid members for tlb code type");
331 }
332
260 print "\tAMD_ERRCODE_MKTLB(" .
333 $::codeoutlen += &errout_N($instance, "\tAMD_ERRCODE_MKTLB(" .
261 "AMD_ERRCODE_TT_$tt, " .
334 "AMD_ERRCODE_TT_$tt, " .
262 "AMD_ERRCODE_LL_$ll),\n";
335 "AMD_ERRCODE_LL_$ll),\n");
263 } else {
264 &parsebail("unknown code type `$type'");
265 }
266
336 } else {
337 &parsebail("unknown code type `$type'");
338 }
339
267 print "\t" . &bin2dec($ext) . ", /* ext code $ext */\n";
340 $::codeoutlen += &errout_N($instance, "\t" . &bin2dec($ext) .
341 ", /* ext code $ext */\n");
268
342
269 &print_bits("pp_bits", @pp);
270 &print_bits("ii_bits", @ii);
271 &print_bits("r4_bits", @r4);
343 $::codeoutlen += &errout_N($instance, &print_bits("pp_bits", @pp));
344 $::codeoutlen += &errout_N($instance, &print_bits("ii_bits", @ii));
345 $::codeoutlen += &errout_N($instance, &print_bits("r4_bits", @r4));
346
347 my $valid_hi;
348 my $valid_lo;
349
350 if ($addr eq "none") {
351 $valid_hi = $valid_lo = 0;
352 } elsif ($addr =~ /<(\d+):(\d+)>/) {
353 $valid_hi = $1;
354 $valid_lo = $2;
355 } else {
356 &parsebail("invalid addr specification");
357 }
358 $::codeoutlen += &errout_N($instance, "\t" . $valid_hi .
359 ", /* addr valid hi */\n");
360 $::codeoutlen += &errout_N($instance, "\t" . $valid_lo .
361 ", /* addr valid lo */\n");
272}
273
274sub state_panic() {
275 my @vals = split(/,\s*/, $_[0]);
276
277 if ($#vals < 0) {
362}
363
364sub state_panic() {
365 my @vals = split(/,\s*/, $_[0]);
366
367 if ($#vals < 0) {
278 print "\t0, /* panic_when */\n";
368 &errout("\t0, /* panic_when */\n");
279 } else {
280 @vals = map { tr/[a-z]/[A-Z]/; "AO_AED_PANIC_" . $_; } @vals;
369 } else {
370 @vals = map { tr/[a-z]/[A-Z]/; "AO_AED_PANIC_" . $_; } @vals;
281 &print_bits("panic_when", @vals);
371 &errout(&print_bits("panic_when", @vals));
282 }
283}
284
285sub state_flags() {
286 my @flags = split(/,\s*/, $_[0]);
287
288 @flags = map { tr/[a-z]/[A-Z]/; "AO_AED_F_" . $_; } @flags;
289
372 }
373}
374
375sub state_flags() {
376 my @flags = split(/,\s*/, $_[0]);
377
378 @flags = map { tr/[a-z]/[A-Z]/; "AO_AED_F_" . $_; } @flags;
379
290 &print_bits("flags", @flags);
380 &errout(&print_bits("flags", @flags));
291}
292
293my %stateparse = (
381}
382
383my %stateparse = (
294 funcunit => [ \&state_funcunit, "desc" ],
295 desc => [ \&state_desc, "error" ],
296 error => [ \&state_error, "mask on" ],
297 'mask on' => [ \&state_mask_on, "mask off" ],
298 'mask off' => [ \&state_mask_off, "code" ],
299 code => [ \&state_code, "panic" ],
300 panic => [ \&state_panic, "flags" ],
301 flags => [ \&state_flags, "initial" ]
384 funcunit => [ \&state_funcunit, 'desc' ],
385 desc => [ \&state_desc, 'error' ],
386 error => [ \&state_error, 'mask on' ],
387 'mask on' => [ \&state_mask_on, 'mask off' ],
388 'mask off' => [ \&state_mask_off, 'code' ],
389 code => [ \&state_code, 'code|panic' ],
390 panic => [ \&state_panic, 'flags' ],
391 flags => [ \&state_flags, 'initial' ]
302);
303
304usage unless (@ARGV == 1);
305
306my $infile = $ARGV[0];
307open(INFILE, "<$infile") || &bail("failed to open $infile: $!");
308
309&print_header();

--- 21 unchanged lines hidden (view full) ---

331 }
332
333 } elsif ($state eq "desc") {
334 if ($keyword eq "funcunit") {
335 $state = "funcunit";
336 }
337 }
338
392);
393
394usage unless (@ARGV == 1);
395
396my $infile = $ARGV[0];
397open(INFILE, "<$infile") || &bail("failed to open $infile: $!");
398
399&print_header();

--- 21 unchanged lines hidden (view full) ---

421 }
422
423 } elsif ($state eq "desc") {
424 if ($keyword eq "funcunit") {
425 $state = "funcunit";
426 }
427 }
428
339 if ($keyword ne $state) {
340 &parsebail("keyword `$keyword' invalid here; expected `$state'");
429 if (!($keyword =~ /$state/)) {
430 &parsebail("keyword `$keyword' invalid here; expected " .
431 "`$state'");
341 }
432 }
433 $state = $keyword; # disambiguate between multiple legal states
342
343 if (!defined $stateparse{$state}) {
344 &parsebail("attempt to transition to invalid state `$state'");
345 }
346
347 my ($handler, $next) = @{$stateparse{$state}};
348
349 &{$handler}($val);

--- 21 unchanged lines hidden ---
434
435 if (!defined $stateparse{$state}) {
436 &parsebail("attempt to transition to invalid state `$state'");
437 }
438
439 my ($handler, $next) = @{$stateparse{$state}};
440
441 &{$handler}($val);

--- 21 unchanged lines hidden ---