blob: b91de9d72a8afe250e2533038ed94c5207ee1e76 [file] [log] [blame]
Zane Shelleyba5dc162020-11-09 21:47:55 -06001#!/usr/bin/env perl
Zane Shelleyabc51c22020-11-09 21:35:35 -06002
3use warnings;
4use strict;
5
6use Data::Dumper;
7use Getopt::Long qw(:config no_ignore_case);
8use File::Path qw(make_path);
9use XML::Simple qw(:strict);
Zane Shelley0a905012021-04-26 17:07:24 -050010use JSON;
Zane Shelleyabc51c22020-11-09 21:35:35 -060011
12# Pull in from the lib directory
13use FindBin qw($RealBin);
14use FindBin qw($RealScript);
15use lib "$RealBin/lib";
16
17use BitRange;
18
19#-------------------------------------------------------------------------------
20# Global Variables
21#-------------------------------------------------------------------------------
22
23# Supported file versions and their values.
24my $FILE_VERSION =
25{
26 VER_01 => 0x01,
27};
28
29# This is a map of all currently supported models/ECs and their IDs.
30my $SUPPORTED_MODEL_EC =
31{
Zane Shelley13d04082021-06-04 08:40:48 -050032 EXPLORER_11 => { id => 0x60D20011, type => "ocmb", desc => "Explorer 1.1" },
33 EXPLORER_20 => { id => 0x60D20020, type => "ocmb", desc => "Explorer 2.0" },
34 P10_10 => { id => 0x20DA0010, type => "proc", desc => "P10 1.0" },
35 P10_20 => { id => 0x20DA0020, type => "proc", desc => "P10 2.0" },
Zane Shelleyabc51c22020-11-09 21:35:35 -060036};
37
38# All models/ECs that may exist in the XML, but no longer needs to be built.
39# This is useful for build optimization and also help prevent build breaks when
40# the XML still exists, but not needed anymore.
41my $DEPRECATED_MODEL_EC = [];
42
43# Supported register types and their values.
44my $REGISTER_TYPE =
45{
46 SCOM => { id => 0x01, addr_size => 4, reg_size => 8 },
47 IDSCOM => { id => 0x02, addr_size => 8, reg_size => 8 },
48};
49
50# Supported attention types and their values.
51my $ATTN_TYPE =
52{
Zane Shelley3d308902021-06-04 16:35:33 -050053 CS => [ 1, 'checkstop' ], # System checkstop hardware attention
54 UCS => [ 2, 'unit checkstop' ], # Unit checkstop hardware attention
55 RE => [ 3, 'recoverable' ], # Recoverable hardware attention
56 SPA => [ 4, 'special attention' ], # event requiring action by the SP FW
57 HA => [ 5, 'host attention' ], # event requiring action by the host FW
Zane Shelleyabc51c22020-11-09 21:35:35 -060058};
59
60#-------------------------------------------------------------------------------
61# Help function
62#-------------------------------------------------------------------------------
63
64sub help()
65{
66 print <<EOF;
67Usage: $RealScript -h
68 $RealScript -i <input_dir> -o <output_dir>
69
Zane Shelley738276a2021-05-24 12:55:34 -050070Generates specified data files from the input Chip Data XML.
Zane Shelleyabc51c22020-11-09 21:35:35 -060071
Zane Shelley738276a2021-05-24 12:55:34 -050072General options:
73
Zane Shelleyabc51c22020-11-09 21:35:35 -060074 -h, --help Prints this menu.
75 -i, --input Directory containing the Chip Data XML files.
Zane Shelley738276a2021-05-24 12:55:34 -050076 -o, --output Directory that will contain the data files.
77
78Data file options (must specify at least one):
79
80 --cdb Generates Chip Data Binary files.
81 --json Generates PEL Parser Data JSON files.
82
Zane Shelleyabc51c22020-11-09 21:35:35 -060083EOF
84
85 exit;
86}
87
88#-------------------------------------------------------------------------------
89# Input
90#-------------------------------------------------------------------------------
91
92help() unless @ARGV; # print help if no arguments
93
94# Get options
Zane Shelley738276a2021-05-24 12:55:34 -050095my ( $help, $src_dir, $dest_dir, $gen_cdb, $gen_json );
96help() unless GetOptions(
97 'h|help' => \$help,
98 'i|input=s' => \$src_dir,
99 'o|output=s' => \$dest_dir,
100 'cdb' => \$gen_cdb,
101 'json' => \$gen_json,
102);
Zane Shelleyabc51c22020-11-09 21:35:35 -0600103
104help() if @ARGV; # print usage if there are extra arguments
105
106# -h,--help
107help() if ( $help );
108
109# -i,--input
110die "ERROR> Option -i required." unless ( defined $src_dir );
111die "ERROR> '$src_dir' is not a directory" unless ( -d $src_dir );
112
113# -o,--output
114die "ERROR> Option -o required." unless ( defined $dest_dir );
115make_path( $dest_dir, {error => \my $err} );
116if ( @{$err} )
117{
118 my ( $file, $message ) = %{shift @{$err}};
119 die "ERROR> $message: $file\n";
120}
121
Zane Shelley738276a2021-05-24 12:55:34 -0500122# --cdb, --json
123unless ( $gen_cdb or $gen_json )
124{
125 die "ERROR> Must specify at least one data file option.";
126}
127
Zane Shelleyabc51c22020-11-09 21:35:35 -0600128#-------------------------------------------------------------------------------
129# Prototypes
130#-------------------------------------------------------------------------------
131
132sub importXML($);
133sub normalizeXML($);
Zane Shelley738276a2021-05-24 12:55:34 -0500134sub buildDataFiles($$);
Zane Shelleyabc51c22020-11-09 21:35:35 -0600135
136#-------------------------------------------------------------------------------
137# Main
138#-------------------------------------------------------------------------------
139
140# Validate and import the XML.
141my $chip_data_xml = importXML( $src_dir );
142
143# There are some fields in the XML that are shorthand and need to be expanded
144# before building the binary files.
145my $normalized_data = normalizeXML( $chip_data_xml );
146
147# The XML should now be in a format to start building the binary files.
Zane Shelley738276a2021-05-24 12:55:34 -0500148buildDataFiles( $dest_dir, $normalized_data );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600149
150#-------------------------------------------------------------------------------
151# Helper functions
152#-------------------------------------------------------------------------------
153
154sub FAIL($) { die( "ERROR> " . shift @_ ); }
155
156#-------------------------------------------------------------------------------
157# Import functions
158#-------------------------------------------------------------------------------
159
160# For each supported XML file in the given directory:
161# - Ensures the XML is well-formed.
162# - Ensures the XML validates against the schema.
163# - Imports the XML into Perl data structures.
164sub importXML($)
165{
166 my ( $dir ) = @_;
167
168 my $data = {};
169
170 # Get a list of all the XML files.
171 opendir DIR, $dir or die "Couldn't open dir '$dir': $!";
172 my @files = grep { /^.+\.xml$/ } readdir DIR;
173 closedir DIR;
174
175 # Iterate each supported file type.
176 for my $type ( "chip", "node" )
177 {
178 for my $file ( grep { /^$type\_.+\.xml$/ } @files )
179 {
180 my $path = "$dir/$file";
181
182 # Ensure the XML is well-formed and validates against the schema.
Zane Shelleyfc4aa5e2021-01-14 13:45:39 -0600183 my $out = `xmllint --noout --schema $RealBin/$type.xsd $path 2>&1`;
184 die "$out\nRAS XML validation failed on $file" if ( 0 != $? );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600185
186 # Import the XML.
187 my $xml = XMLin( $path, KeyAttr => {}, ForceArray => 1 );
188
189 # Add the file path to the XML for error output.
190 $xml->{path} = $path;
191
192 # Push each file's data to a list for each file type.
193 push @{$data->{$type}}, $xml;
194 }
195 }
196
197 return $data;
198}
199
200#-------------------------------------------------------------------------------
201# Normalize functions
202#-------------------------------------------------------------------------------
203
204# Takes a string of models/ECs separated by ',' and returns a list of supported
205# models/ECs. See $SUPPORTED_MODEL_EC and $DEPRECATED_MODEL_EC.
206sub __expandModelEc($)
207{
208 my ( $str ) = @_;
209
210 my @list = split(/,/, $str);
211
212 # Remove any deprecated models/ECs.
213 for my $d ( @{$DEPRECATED_MODEL_EC} )
214 {
215 @list = grep { $d ne $_ } @list;
216 }
217
218 # Validate the remaining models/ECs.
219 for my $m ( @list )
220 {
221 unless ( defined $SUPPORTED_MODEL_EC->{$m} )
222 {
223 FAIL("Unsupported model/EC: $m");
224 }
225 }
226
227 return @list;
228}
229
230#-------------------------------------------------------------------------------
231
232sub __getInstRange($)
233{
234 my ( $insts ) = @_;
235
236 my $list = [];
237 for ( @{$insts} ) { push @{$list}, $_->{reg_inst}; }
238
239 @{$list} = sort @{$list}; # Sort the list just in case.
240
241 return BitRange::compress($list);
242}
243
244sub __getReg($$$$)
245{
246 my ( $inst_in, $reg_type, $name, $addr_mod ) = @_;
247
248 my $inst_out = [];
249 for ( @{$inst_in} )
250 {
251 my $addr = "";
252 if ( "SCOM" eq $reg_type )
253 {
254 $addr = sprintf( "0x%08x", hex($_->{addr}) + $addr_mod );
255 }
256 elsif ( "IDSCOM" eq $reg_type )
257 {
258 # TODO: Need a portable way of handling 64-bit numbers.
259 FAIL("IDSCOM address currently not supported");
260 }
261 else
262 {
263 FAIL("Unsupported register type for node: $name");
264 }
265
266 push @{$inst_out}, { reg_inst => $_->{reg_inst}, addr => $addr };
267 }
268
269 return { name => $name, instance => $inst_out };
270}
271
272sub __getExpr($$)
273{
274 my ( $name, $config ) = @_;
275
276 # Get the register expression.
277 my $expr = { type => 'reg', value1 => $name };
278
279 if ( '0' eq $config )
280 {
281 # Take the NOT of the register expression.
282 $expr = { type => 'not', expr => [ $expr ] };
283 }
284
285 return $expr;
286}
287
288sub __getAct($$$$)
289{
290 my ( $fir, $range, $type, $config ) = @_;
291
292 FAIL("Invalid action config: $config") unless ( $config =~ /^[01]{2,3}$/ );
293
294 my @c = split( //, $config );
295
296 my $e = [];
297 push( @{$e}, __getExpr("${fir}", '1' ) );
298 push( @{$e}, __getExpr("${fir}_MASK", '0' ) );
299 push( @{$e}, __getExpr("${fir}_ACT0", shift @c) );
300 push( @{$e}, __getExpr("${fir}_ACT1", shift @c) );
301 push( @{$e}, __getExpr("${fir}_ACT2", shift @c) ) if ( 0 < scalar @c );
302
303 return { node_inst => $range, attn_type => $type,
304 expr => [ { type => 'and', expr => $e } ] };
305}
306
307#-------------------------------------------------------------------------------
308
309sub __normalizeLocalFir($)
310{
311 my ( $node ) = @_;
312
313 return unless ( defined $node->{local_fir} );
314
315 # Note that the isolator will implicitly add all register referenced by the
316 # rules to the capture group. To reduce redundancy and overall file size, we
317 # won't add these registers to the capture group.
318
319 $node->{register} = [] unless ( defined $node->{register} );
320 $node->{rule} = [] unless ( defined $node->{rule} );
321
322 for my $l ( @{$node->{local_fir}} )
323 {
324 my $n = $l->{name};
325 my $i = $l->{instance};
326 my $t = $node->{reg_type};
327
328 my $inst_range = __getInstRange($i);
329
330 my $r = [];
331 push @{$r}, __getReg($i, $t, "${n}", 0);
332 push @{$r}, __getReg($i, $t, "${n}_MASK", 3);
333 push @{$r}, __getReg($i, $t, "${n}_ACT0", 6);
334 push @{$r}, __getReg($i, $t, "${n}_ACT1", 7);
335 push @{$r}, __getReg($i, $t, "${n}_WOF", 8) if ($l->{config} =~ /W/);
336 push @{$r}, __getReg($i, $t, "${n}_ACT2", 9) if ($l->{config} =~ /2/);
337
338 push @{$node->{register}}, @{$r};
339
340 for ( @{$l->{action}} )
341 {
342 push @{$node->{rule}},
343 __getAct( $n, $inst_range, $_->{attn_type}, $_->{config} );
344 }
345 }
346
347 delete $node->{local_fir};
348}
349
350#-------------------------------------------------------------------------------
351
352# This is not very efficient, especially for large data structures. It is
353# recommended to use Data::Compare, but that is not available on the pool
354# machines.
355sub __dirtyCompare($$)
356{
357 local $Data::Dumper::Terse = 1;
358 local $Data::Dumper::Indent = 0;
359 local $Data::Dumper::Sortkeys = 1;
360 my ( $a, $b ) = ( Dumper(shift), Dumper(shift) );
361 return $a eq $b;
362}
363
364#-------------------------------------------------------------------------------
365
366sub __normalizeRegister($$)
367{
368 my ( $node, $regs ) = @_;
369
370 # There must be at least one register entry.
371 unless ( defined $node->{register} and 0 < scalar @{$node->{register}} )
372 {
373 FAIL( "Node $node->{name} does not contain at least one register" );
374 }
375
376 # All of the registers will be put in the master register list for the chip.
377 for my $r ( @{$node->{register}} )
378 {
379 # Set the default access if needed.
380 $r->{access} = 'RW' unless ( defined $r->{access} );
381
382 # Each register will keep track of its type.
383 $r->{reg_type} = $node->{reg_type};
384
Zane Shelleyd6826e52020-11-10 17:39:00 -0600385 for my $model_ec ( __expandModelEc($node->{model_ec}) )
Zane Shelleyabc51c22020-11-09 21:35:35 -0600386 {
Zane Shelleyd6826e52020-11-10 17:39:00 -0600387 if ( defined $regs->{$model_ec}->{$r->{name}} )
Zane Shelleyabc51c22020-11-09 21:35:35 -0600388 {
Zane Shelleyd6826e52020-11-10 17:39:00 -0600389 # This register already exists so check the contents for
390 # accuracy
391 unless ( __dirtyCompare($r, $regs->{$model_ec}->{$r->{name}}) )
392 {
393 FAIL("Duplicate register: $r->{name}");
394 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600395 }
Zane Shelleyd6826e52020-11-10 17:39:00 -0600396 else
397 {
398 # Add this node's register to the master register list.
399 $regs->{$model_ec}->{$r->{name}} = $r;
400 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600401 }
402 }
403
404 # Clean up this node's register data.
405 delete $node->{register};
406}
407
408#-------------------------------------------------------------------------------
409
410sub __normalizeCaptureGroup($$)
411{
412 my ( $node, $insts_data ) = @_;
413
414 # Capture groups are optional (although recommended).
415 return unless ( defined $node->{capture_group} );
416
417 for my $c ( @{$node->{capture_group}} )
418 {
419 # There must be at least one capture_register.
420 unless ( defined $c->{capture_register} and
421 0 < scalar @{$c->{capture_register}} )
422 {
423 FAIL("<capture_group> for node $node->{name} does not contain at " .
424 "least one <capture_register>" );
425 }
426
427 my @node_insts = BitRange::expand($c->{node_inst});
428
429 for my $r ( @{$c->{capture_register}} )
430 {
431 # node_inst and reg_inst must be the same size.
432 my @reg_insts = BitRange::expand($r->{reg_inst});
433 unless ( scalar @node_insts == scalar @reg_insts )
434 {
435 FAIL("capture_group/\@node_inst and capture_register/" .
436 "\@reg_inst list sized not equal for node $node->{name}");
437 }
438
439 # Expand the capture groups so there is one per node instance.
440 for ( 0 .. (scalar @node_insts - 1) )
441 {
442 my ( $ni, $ri ) = ( $node_insts[$_], $reg_insts[$_] );
443 push @{$insts_data->{$ni}->{capture_group}},
444 { reg_name => $r->{reg_name}, reg_inst => $ri };
445 }
446 }
447 }
448
449 # Clean up this node's capture group data.
450 delete $node->{capture_group};
451}
452
453#-------------------------------------------------------------------------------
454
455sub __normalizeExpr($$$$); # Called recursively
456
457sub __normalizeExpr($$$$)
458{
459 my ( $in, $ni, $idx, $size ) = @_;
460
461 my ( $t, $e, $v1, $v2 ) = ( $in->{type}, $in->{expr},
462 $in->{value1}, $in->{value2} );
463
464 my $out = { type => $t };
465
466 if ( "and" eq $t or "or" eq $t )
467 {
468 if ( defined $v1 or defined $v2 or
469 not defined $e or not (0 < scalar @{$e}) )
470 {
471 FAIL("Invalid parameters for and/or expression");
472 }
473
474 # Iterate each sub expression.
475 push @{$out->{expr}}, __normalizeExpr($_, $ni, $idx, $size) for (@{$e});
476 }
477 elsif ( "not" eq $t )
478 {
479 if ( defined $v1 or defined $v2 or
480 not defined $e or not (1 == scalar @{$e}) )
481 {
482 FAIL("Invalid parameters for not expression");
483 }
484
485 # Iterate each sub expression.
486 push @{$out->{expr}}, __normalizeExpr($_, $ni, $idx, $size) for (@{$e});
487 }
488 elsif ( "lshift" eq $t or "rshift" eq $t )
489 {
490 if ( not defined $v1 or defined $v2 or
491 not defined $e or not (1 == scalar @{$e}) )
492 {
493 FAIL("Invalid parameters for lshift/rshift expression");
494 }
495
496 # Copy value1.
497 $out->{value1} = $v1;
498
499 # Iterate each sub expression.
500 push @{$out->{expr}}, __normalizeExpr($_, $ni, $idx, $size) for (@{$e});
501 }
502 elsif ( "reg" eq $t )
503 {
504 if ( not defined $v1 or defined $e )
505 {
506 FAIL("Invalid parameters for reg expression");
507 }
508
509 # Copy value1.
510 $out->{value1} = $v1;
511
512 # value2 is optional in the XML, update the value to the node or
513 # register instance.
514 if ( defined $v2 )
515 {
516 my @reg_insts = BitRange::expand($v2);
517 unless ( $size == scalar @reg_insts )
518 {
519 FAIL("reg expression value2:$v2 list not the same ".
520 "size as containing node's rule instances:$size");
521 }
522
523 $out->{value2} = $reg_insts[$idx];
524 }
525 else
526 {
527 # The register instance is the same as the node instance.
528 $out->{value2} = $ni;
529 }
530 }
531 elsif ( "int" eq $t )
532 {
533 if ( not defined $v1 or defined $v2 or defined $e )
534 {
535 FAIL("Invalid parameters for int expression");
536 }
537
538 # Copy value1.
539 $out->{value1} = $v1;
540 }
541 else
542 {
543 FAIL("Unsupported expression type: $t");
544 }
545
546 return $out;
547}
548
549#-------------------------------------------------------------------------------
550
551sub __normalizeRule($$)
552{
553 my ( $node, $insts_data ) = @_;
554
Zane Shelleyabc51c22020-11-09 21:35:35 -0600555 # There should be only one rule per attention type and node instance for
556 # this node.
557 my $rule_dups = {};
558
559 for my $r ( @{$node->{rule}} )
560 {
561 # There should be exactly one parent expression.
562 unless ( 1 == scalar @{$r->{expr}} )
563 {
564 FAIL("Multiple parent expressions for rule: $node->{name} " .
565 "$r->{attn_type}");
566 }
567 my $expr = $r->{expr}->[0];
568
569 my @node_insts = BitRange::expand($r->{node_inst});
570 my $sz_insts = scalar @node_insts;
571
572 # Expand the expression for each node instance.
573 for my $idx ( 0 .. ($sz_insts - 1) )
574 {
575 my $ni = $node_insts[$idx];
576
577 # Check for duplicates.
578 if ( defined $rule_dups->{$r->{attn_type}}->{$ni} )
579 {
580 FAIL("Duplicate rule: $node->{name} $r->{attn_type} $ni");
581 }
582 else
583 {
584 $rule_dups->{$r->{attn_type}}->{$ni} = 1;
585 }
586
587 # Add the rule for this expression.
588 push @{$insts_data->{$ni}->{rule}},
589 { attn_type => $r->{attn_type},
590 expr => __normalizeExpr($expr, $ni, $idx, $sz_insts) };
591 }
592 }
593
594 # Clean up this node's rule data.
595 delete $node->{rule};
596}
597
598#-------------------------------------------------------------------------------
599
600sub __normalizeBit($$$)
601{
602 my ( $node, $sigs, $insts_data ) = @_;
603
Zane Shelleyabc51c22020-11-09 21:35:35 -0600604 my @node_insts = sort keys %{$insts_data};
605 my $sz_insts = scalar @node_insts;
606
607 # There should be only one child node per node instance bit position.
608 my $child_dups = {};
609
610 for my $b ( sort {$a->{pos} cmp $b->{pos}} @{$node->{bit}} )
611 {
612 my @child_insts = ();
613
614 # Ensure child_node and node_inst are set properly.
615 if ( defined $b->{child_node} )
616 {
617 # Ensure each bit has a default node_inst attribute if needed.
618 $b->{node_inst} = "0" unless ( defined $b->{node_inst} );
619
620 # Get all of the instances for this child node.
621 @child_insts = BitRange::expand($b->{node_inst});
622
623 # Both inst list must be equal in size.
624 unless ( $sz_insts == scalar @child_insts )
625 {
626 FAIL("node_inst attribute list size for node:$node->{name} " .
627 "bit:$b->{pos} does not match node instances " .
628 "represented by the <rule> element");
629 }
630 }
631 elsif ( defined $b->{node_inst} )
632 {
633 FAIL("node_inst attribute exists for node:$node->{name} " .
634 "bit:$b->{pos} with no child_node attribute");
635 }
636
637 # Get the signatures for each node, instance, and bit position.
638 for my $p ( BitRange::expand($b->{pos}) )
639 {
640 for my $i ( 0 .. ($sz_insts-1) )
641 {
642 my ( $n, $ni ) = ( $node->{name}, $node_insts[$i] );
643
644 # This is to cover a bug in the figtree information where there
645 # currently is no comment for some bits.
646 $b->{content} = "" unless ( defined $b->{content} );
647
Zane Shelleyd6826e52020-11-10 17:39:00 -0600648 for my $model_ec ( __expandModelEc($node->{model_ec}) )
Zane Shelleyabc51c22020-11-09 21:35:35 -0600649 {
Zane Shelleyd6826e52020-11-10 17:39:00 -0600650 # Check if this signature already exists.
651 if ( defined $sigs->{$model_ec}->{$n}->{$ni}->{$p} and
652 $b->{content} ne $sigs->{$model_ec}->{$n}->{$ni}->{$p} )
653 {
654 FAIL("Duplicate signature for $n $ni $p");
655 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600656
Zane Shelleyd6826e52020-11-10 17:39:00 -0600657 # Get the signatures for each node, instance, and bit
658 # position.
659 $sigs->{$model_ec}->{$n}->{$ni}->{$p} = $b->{content};
660 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600661
662 # Move onto the next instance unless a child node exists.
663 next unless ( defined $b->{child_node} );
664
665 my $pi = $child_insts[$i];
666
667 my $child = { pos => $p,
668 child_node => $b->{child_node},
669 node_inst => $pi };
670
671 # Ensure this child node doesn't already exist.
672 if ( defined $child_dups->{$ni}->{$p} and
673 not __dirtyCompare($child, $child_dups->{$ni}->{$p}) )
674 {
675 FAIL("Duplicate child_node for $n $ni $p");
676 }
677
678 # Add this child node.
679 push @{$insts_data->{$ni}->{bit}}, $child;
680 }
681 }
682 }
683
684 # Clean up this node's bit data.
685 delete $node->{bit};
686}
687
688#-------------------------------------------------------------------------------
689
690sub __normalizeNode($$$)
691{
692 my ( $node, $regs, $sigs ) = @_;
693
694 # Ensure a valid register type.
695 unless ( grep { /^$node->{reg_type}$/ } keys %{$REGISTER_TYPE} )
696 {
697 FAIL( "Unsupported register type: $node->{reg_type}" );
698 }
699
700 my $insts_data = {}; # Collect data for each instance of this node.
701
702 # First, expand the <local_fir> data if it exists.
703 __normalizeLocalFir($node);
704
705 # All registers will be put in a master register list for the chip.
706 __normalizeRegister($node, $regs);
707
708 # Split the capture group information per node instance.
709 __normalizeCaptureGroup($node, $insts_data);
710
Zane Shelleybcb43952021-07-08 22:13:57 -0500711 my $is_rule = (defined $node->{rule} and 0 < scalar @{$node->{rule}}) ? 1 : 0;
712 my $is_bit = (defined $node->{bit} and 0 < scalar @{$node->{bit}}) ? 1 : 0;
Zane Shelleyabc51c22020-11-09 21:35:35 -0600713
Zane Shelleybcb43952021-07-08 22:13:57 -0500714 # If a rule is defined, a bit must be defined as well. It is possible for
715 # neither to be defined (FFDC-only node).
716 if ( $is_rule and $is_bit )
717 {
718 # Split the rule information per node instance. The sorted instance list
719 # will be used as indexes for the node_inst attribute of the <bit>
720 # elements.
721 __normalizeRule($node, $insts_data);
722
723 # Finally, collect the signature details and split the bit information
724 # per node instance.
725 __normalizeBit($node, $sigs, $insts_data);
726 }
727 elsif ( $is_rule or $is_bit )
728 {
729 # One is defined and the other is not. This is an error.
730 FAIL("Node $node->{name} has a bit or rule defined and the other is not.");
731 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600732
733 # Now that we have all of the node data, collapse the instance data into
734 # a list.
735 for ( sort keys %{$insts_data} )
736 {
737 $insts_data->{$_}->{node_inst} = $_;
738 push @{$node->{instance}}, $insts_data->{$_};
739 }
740}
741
742#-------------------------------------------------------------------------------
743
744sub normalizeXML($)
745{
746 my ( $xml ) = @_;
747
748 my $data = {};
749
750 # Iterate each chip file.
751 for my $chip ( @{$xml->{chip}} )
752 {
753 # Iterate each model/EC.
754 for my $model_ec ( __expandModelEc($chip->{model_ec}) )
755 {
756 # Ensure there is not a duplicate definition for a model/EC.
757 if ( $data->{$model_ec}->{chip} )
758 {
759 FAIL("Duplicate data for model/EC $model_ec in:\n" .
760 " $data->{$model_ec}->{chip}->{path}\n" .
761 " $chip->{path}");
762 }
763
764 # Add this chip to the data.
765 $data->{$model_ec}->{attn_tree} = $chip->{attn_tree};
766 }
767 }
768
769 # Extract the data for each node.
770 my ( $regs, $sigs, $node_dups ) = ( {}, {}, {} );
771 for my $node ( sort { $a->{name} cmp $b->{name} } @{$xml->{node}} )
772 {
773 # A node may be defined for more than one model/EC.
774 for my $model_ec ( __expandModelEc($node->{model_ec}) )
775 {
776 # A node can only be defined once per model/EC.
777 if ( defined $node_dups->{$model_ec}->{$node->{name}} )
778 {
779 FAIL( "Duplicate node defined for $model_ec -> $node->{name} ");
780 }
781 else
782 {
783 $node_dups->{$model_ec}->{$node->{name}} = 1;
784 }
785
Zane Shelleyd6826e52020-11-10 17:39:00 -0600786 # Initialize the master list of registers and signatures of this
787 # model/EC, if necessary.
Zane Shelleyabc51c22020-11-09 21:35:35 -0600788
Zane Shelleyd6826e52020-11-10 17:39:00 -0600789 $regs->{$model_ec} = {} unless ( defined $regs->{$model_ec} );
790 $sigs->{$model_ec} = {} unless ( defined $sigs->{$model_ec} );
791 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600792
Zane Shelleyd6826e52020-11-10 17:39:00 -0600793 # The same node content will be used for each model/EC characterized by
794 # this node. There is some normalization that needs to happen because of
795 # shorthand elements, like <local_fir>, and some error checking. This
796 # only needs to be done once per node, not per model/EC.
797 __normalizeNode( $node, $regs, $sigs );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600798
Zane Shelleyd6826e52020-11-10 17:39:00 -0600799 # Push the node data for each model/EC.
800 for my $model_ec ( __expandModelEc($node->{model_ec}) )
801 {
Zane Shelleyabc51c22020-11-09 21:35:35 -0600802 push @{$data->{$model_ec}->{node}}, $node;
803 }
804 }
805
806 # Sort and collapse the master register list.
807 for my $m ( keys %{$regs} )
808 {
809 for my $n ( sort keys %{$regs->{$m}} )
810 {
811 push @{$data->{$m}->{register}}, $regs->{$m}->{$n};
812 }
813 }
814
815 # Collapse the signature lists.
816 for my $m ( keys %{$sigs} )
817 {
818 for my $n ( sort keys %{$sigs->{$m}} )
819 {
820 for my $i ( sort {$a <=> $b} keys %{$sigs->{$m}->{$n}} )
821 {
822 for my $b ( sort {$a <=> $b} keys %{$sigs->{$m}->{$n}->{$i}} )
823 {
824 push @{$data->{$m}->{signature}},
825 { name => $n, inst => $i, bit => $b,
826 desc => $sigs->{$m}->{$n}->{$i}->{$b} };
827 }
828 }
829 }
830 }
831
832 return $data;
833}
834
835#-------------------------------------------------------------------------------
836# Output functions
837#-------------------------------------------------------------------------------
838
839# The $num passed into this function can be a numeric of string. All values are
840# converted to a hex string and then into the binary format. This helps avoid
841# portability issues with endianess. Requirements:
842# - Hex strings must start with '0x'.
843# - For portability, 64-bit numbers must be passed as a hex string.
844sub __bin($$$)
845{
846 my ( $fh, $bytes, $num ) = @_;
847
848 # $bytes must be a positive integer.
849 die "Invalid bytes: $bytes" unless ( 0 < $bytes );
850
851 my $str = ''; # Default invalid string
852
853 my $char = $bytes * 2; # Number of characters in the string.
854
855 # Check if $num is a hex string.
856 if ( $num =~ /^0[x|X](.*)/ )
857 {
858 $str = $1; # strip the '0x'
859 }
860 # Check if $num is string or numeric decimal integer (32-bit max).
861 elsif ( $num =~ /^[0-9]+$/ and $bytes <= 4 )
862 {
863 $str = sprintf("%0${char}x", $num); # Convert to hex string
864 }
865
866 # Check for a hex number with the valid size.
867 unless ( $str =~ /^[0-9a-fA-F]{$char}$/ )
868 {
869 die "Invalid number: $num (size: $bytes)";
870 }
871
872 # Print the binary string.
873 print $fh pack( "H$char", $str );
874}
875
876#-------------------------------------------------------------------------------
877
878sub __hash($$)
879{
880 my $bytes = shift;
881 my @str = unpack("C*", shift); # returns an array of ascii values
882
883 # Currently only supporting 1, 2, 3, and 4 byte hashes.
884 unless ( 1 <= $bytes and $bytes <= 4 )
885 {
886 FAIL("Unsupported hash size: $bytes");
887 }
888
889 # Add padding to the end of the character array so that the size is
890 # divisible by $bytes.
891 push @str, 0 until ( 0 == scalar(@str) % $bytes );
892
893 # This hash is a simple "n*s[0] + (n-1)*s[1] + ... + s[n-1]" algorithm,
894 # where s[i] is a $bytes size chunk of the input string.
895
896 my ( $sumA, $sumB ) = ( 0, 0 );
897 while ( my @chunk = splice @str, 0, $bytes )
898 {
899 # Combine the chunk array into a single value.
900 my $val = 0; for ( @chunk ) { $val <<= 8; $val |= $_; }
901
902 # Apply the simple hash.
903 $sumA += $val;
904 $sumB += $sumA;
905 }
906
907 # Mask off everything except the target number of bytes.
908 $sumB &= 0xffffffff >> ((4 - $bytes) * 8);
909
910 return $sumB;
911}
912
913#-------------------------------------------------------------------------------
914
915sub __printRegisters($$)
916{
917 my ( $fh, $data ) = @_;
918
919 my $num_regs = scalar @{$data};
920 FAIL("No registers defined") unless ( 0 < $num_regs );
921
922 # Register list metadata
923 __bin($fh, 1, $_) for ( unpack("C*", "REGS") );
924 __bin($fh, 3, $num_regs);
925
926 my $reg_ids = {}; # for hash duplicate checking
927
928 for my $r ( @{$data} )
929 {
930 # Get the hash of the register name and check for duplicates.
931 my $id = __hash(3, $r->{name});
932 if ( defined $reg_ids->{$id} )
933 {
934 FAIL("Duplicate register ID hash " . sprintf('0x%08x', $id) .
935 " for $r->{name} and $reg_ids->{$id}");
936 }
937 else
938 {
939 $reg_ids->{$id} = $r->{name};
940 }
941
942 # Get the attribute flags.
943 my $flags = 0x00;
944 $flags |= 0x80 if ( $r->{access} =~ /R/ );
945 $flags |= 0x40 if ( $r->{access} =~ /W/ );
946
947 # Get the number of address instances.
948 my $num_inst = scalar @{$r->{instance}};
949 unless ( 0 < $num_inst )
950 {
951 FAIL("No register instances defined for $r->{name}");
952 }
953
954 # Register metadata
955 __bin($fh, 3, $id );
956 __bin($fh, 1, $REGISTER_TYPE->{$r->{reg_type}}->{id});
957 __bin($fh, 1, $flags );
958 __bin($fh, 1, $num_inst);
959
960 for my $i ( @{$r->{instance}} )
961 {
962 my $s = $REGISTER_TYPE->{$r->{reg_type}}->{addr_size};
963
964 # Register Instance metadata
965 __bin($fh, 1, $i->{reg_inst});
966 __bin($fh, $s, $i->{addr} );
967 }
968 }
969}
970
971#-------------------------------------------------------------------------------
972
973sub __printExpr($$$);
974
975sub __printExpr($$$)
976{
977 my ( $fh, $size, $expr ) = @_;
978
979 my ( $t, $e, $v1, $v2 ) = ( $expr->{type}, $expr->{expr},
980 $expr->{value1}, $expr->{value2} );
981
982 if ( "reg" eq $t )
983 {
984 __bin($fh, 1, 0x01); # expression type for "reg"
985 __bin($fh, 3, __hash(3,$v1)); # register id
986 __bin($fh, 1, $v2); # register instance
987 }
988 elsif ( "int" eq $t )
989 {
990 __bin($fh, 1, 0x02); # expression type for "int"
991 __bin($fh, $size, $v1); # integer value
992 }
993 elsif ( "and" eq $t )
994 {
995 __bin($fh, 1, 0x10); # expression type for "and"
996 __bin($fh, 1, scalar @{$e}); # number of sub-expressions
997 __printExpr($fh, $size, $_) for ( @{$e} ); # add each sub-expression
998 }
999 elsif ( "or" eq $t )
1000 {
1001 __bin($fh, 1, 0x11); # expression type for "or"
1002 __bin($fh, 1, scalar @{$e}); # number of sub-expressions
1003 __printExpr($fh, $size, $_) for ( @{$e} ); # add each sub-expression
1004 }
1005 elsif ( "not" eq $t )
1006 {
1007 __bin($fh, 1, 0x12); # expression type for "not"
1008 __printExpr($fh, $size, $e->[0]); # add only sub-expression
1009 }
1010 elsif ( "lshift" eq $t )
1011 {
1012 __bin($fh, 1, 0x13); # expression type for "lshift"
1013 __bin($fh, 1, $v1); # shift amount
1014 __printExpr($fh, $size, $e->[0]); # add only sub-expression
1015 }
1016 elsif ( "rshift" eq $t )
1017 {
1018 __bin($fh, 1, 0x14); # expression type for "rshift"
1019 __bin($fh, 1, $v1); # shift amount
1020 __printExpr($fh, $size, $e->[0]); # add only sub-expression
1021 }
1022}
1023
1024#-------------------------------------------------------------------------------
1025
1026sub __printNodes($$)
1027{
1028 my ( $fh, $data ) = @_;
1029
1030 my $num_nodes = scalar @{$data};
1031 FAIL("No nodes defined") unless ( 0 < $num_nodes );
1032
1033 # Isolation Node list metadata
1034 __bin($fh, 1, $_) for ( unpack("C*", "NODE") );
1035 __bin($fh, 2, $num_nodes);
1036
1037 my $node_ids = {}; # for hash duplicate checking
1038
1039 for my $n ( @{$data} )
1040 {
1041 # Get the hash of the node name and check for duplicates.
1042 my $id = __hash(2, $n->{name});
1043 if ( defined $node_ids->{$id} )
1044 {
1045 FAIL("Duplicate node ID hash " . sprintf('0x%08x', $id) .
1046 " for $n->{name} and $node_ids->{$id}");
1047 }
1048 else
1049 {
1050 $node_ids->{$id} = $n->{name};
1051 }
1052
1053 my $num_insts = scalar @{$n->{instance}};
1054 unless ( 0 < $num_insts )
1055 {
1056 FAIL("No nodes instances defined for $n->{name}");
1057 }
1058
1059 my $reg_type = $REGISTER_TYPE->{$n->{reg_type}}->{id};
1060 my $reg_size = $REGISTER_TYPE->{$n->{reg_type}}->{reg_size};
1061
1062 # Register metadata
1063 __bin($fh, 2, $id);
1064 __bin($fh, 1, $reg_type);
1065 __bin($fh, 1, $num_insts);
1066
1067 for my $i ( @{$n->{instance}} )
1068 {
1069 # Capture groups are optional.
1070 my $num_cap_regs = (defined $i->{capture_group})
1071 ? scalar @{$i->{capture_group}} : 0;
1072
Zane Shelleybcb43952021-07-08 22:13:57 -05001073 # Rules may not exist for this node.
1074 my $num_rules = (defined $i->{rule}) ? scalar @{$i->{rule}} : 0;
Zane Shelleyabc51c22020-11-09 21:35:35 -06001075
1076 # Child nodes may not exist for this node.
1077 my $num_bit = (defined $i->{bit}) ? scalar @{$i->{bit}} : 0;
1078
1079 # Register instance metadata
1080 __bin($fh, 1, $i->{node_inst});
1081 __bin($fh, 1, $num_cap_regs );
1082 __bin($fh, 1, $num_rules );
1083 __bin($fh, 1, $num_bit );
1084
1085 if ( 0 < $num_cap_regs )
1086 {
1087 for my $cg ( @{$i->{capture_group}} )
1088 {
1089 # Register capture register metadata
1090 __bin($fh, 3, __hash(3, $cg->{reg_name}));
1091 __bin($fh, 1, $cg->{reg_inst} );
1092 }
1093 }
1094
Zane Shelleybcb43952021-07-08 22:13:57 -05001095 if ( 0 < $num_rules )
Zane Shelleyabc51c22020-11-09 21:35:35 -06001096 {
Zane Shelleybcb43952021-07-08 22:13:57 -05001097 for my $r ( @{$i->{rule}} )
1098 {
1099 # Register rule metadata
1100 __bin($fh, 1, $ATTN_TYPE->{$r->{attn_type}}->[0]);
1101 __printExpr($fh, $reg_size, $r->{expr});
1102 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001103 }
1104
1105 if ( 0 < $num_bit )
1106 {
1107 for my $b ( @{$i->{bit}} )
1108 {
1109 # Register child node metadata
1110 __bin($fh, 1, $b->{pos} );
1111 __bin($fh, 2, __hash(2, $b->{child_node}));
1112 __bin($fh, 1, $b->{node_inst} );
1113 }
1114 }
1115 }
1116 }
1117}
1118
1119#-------------------------------------------------------------------------------
1120
1121sub __printAttnTree($$)
1122{
1123 my ( $fh, $data ) = @_;
1124
1125 my $num_root_nodes = scalar @{$data};
1126 FAIL("No root nodes defined") unless ( 0 < $num_root_nodes );
1127
1128 # Root Node list metadata
1129 __bin($fh, 1, $_) for ( unpack("C*", "ROOT") );
1130 __bin($fh, 1, $num_root_nodes);
1131
1132 for my $r ( @{$data} )
1133 {
1134 # Root Node metadata
Zane Shelley3d308902021-06-04 16:35:33 -05001135 __bin($fh, 1, $ATTN_TYPE->{$r->{attn_type}}->[0]);
1136 __bin($fh, 2, __hash(2, $r->{root_node}) );
1137 __bin($fh, 1, $r->{node_inst} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001138 }
1139}
1140
1141#-------------------------------------------------------------------------------
1142
Zane Shelley0a905012021-04-26 17:07:24 -05001143sub __printParserData($$$$)
Zane Shelleyabc51c22020-11-09 21:35:35 -06001144{
Zane Shelley0a905012021-04-26 17:07:24 -05001145 my ( $fh, $model_ec, $sig_list, $reg_list) = @_;
Zane Shelleyabc51c22020-11-09 21:35:35 -06001146
Zane Shelley74678c12021-06-04 15:46:16 -05001147 # IMPORTANT: All hash keys with hex values must be lowercase.
1148
Zane Shelley3d308902021-06-04 16:35:33 -05001149 my $attns = {};
Zane Shelley0a905012021-04-26 17:07:24 -05001150 my $regs = {};
1151 my $sigs = {};
Zane Shelleyabc51c22020-11-09 21:35:35 -06001152
Zane Shelley13d04082021-06-04 08:40:48 -05001153 # Get the chip info.
1154 my $info = $SUPPORTED_MODEL_EC->{$model_ec};
1155 $info->{'id'} = sprintf('%08x', $info->{'id'});
1156
Zane Shelley3d308902021-06-04 16:35:33 -05001157 # Get the list of attention types.
1158 while ( my ($k, $v) = each %{$ATTN_TYPE} )
1159 {
1160 $attns->{$v->[0]} = $v->[1];
1161 }
1162
Zane Shelleybc3c0402021-06-04 16:11:21 -05001163 # Get the signature data.
Zane Shelley0a905012021-04-26 17:07:24 -05001164 for my $s ( @{$sig_list} )
Zane Shelleyabc51c22020-11-09 21:35:35 -06001165 {
Zane Shelleybc3c0402021-06-04 16:11:21 -05001166 # Format is:
1167 # { id : [ name, { bit : desc, ... } ], ... }
Zane Shelley0a905012021-04-26 17:07:24 -05001168
Zane Shelleybc3c0402021-06-04 16:11:21 -05001169 # The ID is a 2-byte hash of the node name (lowercase).
1170 my $id = sprintf('%04x', __hash(2, $s->{name}));
1171
1172 if ( exists($sigs->{$id}) )
Zane Shelley0a905012021-04-26 17:07:24 -05001173 {
Zane Shelleybc3c0402021-06-04 16:11:21 -05001174 # Check for hash collisions.
1175 if ($sigs->{$id}->[0] ne $s->{name} )
1176 {
1177 FAIL("Node hash collision for $id: $sigs->{$id}->[0] " .
1178 "and $s->{name}");
1179 }
1180 }
1181 else
1182 {
1183 # Initialize this node.
1184 $sigs->{$id} = [ $s->{name}, {} ];
Zane Shelley0a905012021-04-26 17:07:24 -05001185 }
1186
Zane Shelleybc3c0402021-06-04 16:11:21 -05001187 # Check for signature collisions.
1188 if ( exists($sigs->{$id}->[1]->{$s->{bit}}) )
Zane Shelley0a905012021-04-26 17:07:24 -05001189 {
Zane Shelleybc3c0402021-06-04 16:11:21 -05001190 # Check for signature collisions.
1191 if ( $sigs->{$id}->[1]->{$s->{bit}} ne $s->{desc} )
1192 {
1193 FAIL("Multiple signatures for $s->{name} bit $s->{bit}:\n" .
1194 " $sigs->{$id}->[1]->{$s->{bit}}\n" .
1195 " $s->{desc}");
1196 }
Zane Shelley0a905012021-04-26 17:07:24 -05001197 }
Zane Shelleybc3c0402021-06-04 16:11:21 -05001198 else
1199 {
1200 # Set the signature for this bit.
1201 $sigs->{$id}->[1]->{$s->{bit}} = $s->{desc};
1202 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001203 }
Zane Shelley0a905012021-04-26 17:07:24 -05001204
Zane Shelley74678c12021-06-04 15:46:16 -05001205 # Get the register data.
Zane Shelley0a905012021-04-26 17:07:24 -05001206 for my $r ( @{$reg_list} )
1207 {
Zane Shelley74678c12021-06-04 15:46:16 -05001208 # Format is:
1209 # { id : [ name, { inst : addr, ... } ], ... }
1210
1211 # The ID is a 3-byte hash of the register name (lowercase).
Zane Shelley0a905012021-04-26 17:07:24 -05001212 my $id = sprintf('%06x', __hash(3, $r->{name}));
1213
Zane Shelley74678c12021-06-04 15:46:16 -05001214 if ( exists($regs->{$id}) )
Zane Shelley0a905012021-04-26 17:07:24 -05001215 {
Zane Shelley74678c12021-06-04 15:46:16 -05001216 # Check for hash collisions.
1217 if ( $regs->{$id}->[0] ne $r->{name} )
1218 {
1219 FAIL("Register hash collision for $id: " .
1220 "$regs->{$id}->[0] and $r->{name}");
1221 }
1222 }
1223 else
1224 {
1225 # Initialize this register.
1226 $regs->{$id} = [ $r->{name}, {} ];
Zane Shelley0a905012021-04-26 17:07:24 -05001227 }
1228
Zane Shelley74678c12021-06-04 15:46:16 -05001229 # Add the address for each instance of the register (shouldn't have to
1230 # worry about duplicates).
1231 for ( @{$r->{instance}} )
1232 {
1233 $regs->{$id}->[1]->{$_->{reg_inst}} = $_->{addr};
1234 }
Zane Shelley0a905012021-04-26 17:07:24 -05001235 }
1236
1237 my $data =
1238 {
Zane Shelley13d04082021-06-04 08:40:48 -05001239 'model_ec' => $info,
Zane Shelley3d308902021-06-04 16:35:33 -05001240 'attn_types' => $attns,
Zane Shelleybc3c0402021-06-04 16:11:21 -05001241 'registers' => $regs,
1242 'signatures' => $sigs,
Zane Shelley0a905012021-04-26 17:07:24 -05001243 };
1244
1245 print $fh to_json( $data, {utf8 => 1, pretty => 1, canonical => 1} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001246}
1247
1248#-------------------------------------------------------------------------------
1249
Zane Shelley738276a2021-05-24 12:55:34 -05001250sub buildDataFiles($$)
Zane Shelleyabc51c22020-11-09 21:35:35 -06001251{
1252 my ( $dir, $data ) = @_;
1253
1254 while ( my ($model_ec, $chip) = each %{$data} )
1255 {
1256 unless ( defined $chip->{register} )
1257 {
1258 FAIL("Chip $model_ec does not contain registers");
1259 }
1260 unless ( defined $chip->{node} )
1261 {
1262 FAIL("Chip $model_ec does not contain nodes");
1263 }
1264 unless ( defined $chip->{attn_tree} )
1265 {
1266 FAIL("Chip $model_ec does not contain attn_tree information");
1267 }
Zane Shelley0a905012021-04-26 17:07:24 -05001268 unless ( defined $chip->{signature} )
1269 {
1270 FAIL("Chip $model_ec does not contain signatures");
1271 }
1272
1273 # Chip Data Binary files ###############################################
Zane Shelleyabc51c22020-11-09 21:35:35 -06001274
Zane Shelley738276a2021-05-24 12:55:34 -05001275 if ( $gen_cdb )
1276 {
1277 my $bin_file = "$dir/chip_data_" . lc $model_ec . ".cdb";
1278 open my $bin_fh, '>', $bin_file or die "Cannot open $bin_file: $!";
1279 binmode $bin_fh; # writes a binary file
Zane Shelleyabc51c22020-11-09 21:35:35 -06001280
Zane Shelley738276a2021-05-24 12:55:34 -05001281 # Chip Data File metadata
1282 __bin($bin_fh, 1, $_) for ( unpack("C*", "CHIPDATA") );
Zane Shelley13d04082021-06-04 08:40:48 -05001283 __bin($bin_fh, 4, $SUPPORTED_MODEL_EC->{$model_ec}->{id});
1284 __bin($bin_fh, 1, $FILE_VERSION->{VER_01} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001285
Zane Shelley738276a2021-05-24 12:55:34 -05001286 __printRegisters( $bin_fh, $chip->{register} );
1287 __printNodes( $bin_fh, $chip->{node} );
1288 __printAttnTree( $bin_fh, $chip->{attn_tree} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001289
Zane Shelley738276a2021-05-24 12:55:34 -05001290 close $bin_fh;
1291 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001292
Zane Shelley0a905012021-04-26 17:07:24 -05001293 # eBMC PEL parsing JSON ################################################
Zane Shelleyabc51c22020-11-09 21:35:35 -06001294
Zane Shelley738276a2021-05-24 12:55:34 -05001295 if ( $gen_json )
1296 {
1297 my $file = "$dir/pel_parser_data_" . lc $model_ec . ".json";
1298 open my $fh, '>', $file or die "Cannot open $file: $!";
Zane Shelleyabc51c22020-11-09 21:35:35 -06001299
Zane Shelley738276a2021-05-24 12:55:34 -05001300 __printParserData( $fh, $model_ec, $chip->{signature},
1301 $chip->{register} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001302
Zane Shelley738276a2021-05-24 12:55:34 -05001303 close $fh;
1304 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001305 }
1306}
1307