[susieq] Update qib_genbits.pl to handle SusieQ definitions
The latest RTL-generated register lists include (mostly redundant) xxx_MSB values alongside xxx_LSB and xxx_RMASK, and also include default register values.
This commit is contained in:
parent
7467cf5f09
commit
ef0e76811b
|
@ -20,6 +20,7 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
my $offsets = {};
|
my $offsets = {};
|
||||||
|
my $defaults = {};
|
||||||
my $structures = {};
|
my $structures = {};
|
||||||
my $structure = "";
|
my $structure = "";
|
||||||
|
|
||||||
|
@ -28,8 +29,12 @@ while ( <> ) {
|
||||||
if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
|
if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
|
||||||
$structure = $1;
|
$structure = $1;
|
||||||
$offsets->{$structure} = $2;
|
$offsets->{$structure} = $2;
|
||||||
|
} elsif ( /^\#define ${structure}_DEF (\S+)$/ ) {
|
||||||
|
$defaults->{$structure} = $1;
|
||||||
} elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
|
} elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
|
||||||
$structures->{$structure}->{$1}->{LSB} = $2;
|
$structures->{$structure}->{$1}->{LSB} = $2;
|
||||||
|
} elsif ( /^\#define ${structure}_(\S+)_MSB (\S+)$/ ) {
|
||||||
|
$structures->{$structure}->{$1}->{MSB} = $2;
|
||||||
} elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
|
} elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
|
||||||
$structures->{$structure}->{$1}->{RMASK} = $2;
|
$structures->{$structure}->{$1}->{RMASK} = $2;
|
||||||
} elsif ( /^\s*$/ ) {
|
} elsif ( /^\s*$/ ) {
|
||||||
|
@ -39,7 +44,8 @@ while ( <> ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $data = [ map { { name => $_, offset => $offsets->{$_} }; }
|
my $data = [ map { { name => $_, offset => $offsets->{$_},
|
||||||
|
default => $defaults->{$_} }; }
|
||||||
sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
|
sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
|
||||||
keys %$offsets ];
|
keys %$offsets ];
|
||||||
|
|
||||||
|
@ -47,6 +53,7 @@ foreach my $datum ( @$data ) {
|
||||||
next unless exists $structures->{$datum->{name}};
|
next unless exists $structures->{$datum->{name}};
|
||||||
$structure = $structures->{$datum->{name}};
|
$structure = $structures->{$datum->{name}};
|
||||||
my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
|
my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
|
||||||
|
msb => $structure->{$_}->{MSB},
|
||||||
rmask => $structure->{$_}->{RMASK} }; }
|
rmask => $structure->{$_}->{RMASK} }; }
|
||||||
sort { hex ( $structure->{$a}->{LSB} ) <=>
|
sort { hex ( $structure->{$a}->{LSB} ) <=>
|
||||||
hex ( $structure->{$b}->{LSB} ) }
|
hex ( $structure->{$b}->{LSB} ) }
|
||||||
|
@ -54,7 +61,7 @@ foreach my $datum ( @$data ) {
|
||||||
$datum->{fields} = $fields;
|
$datum->{fields} = $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n/* This file has been further processed by $0 */\n\n"
|
print "\n/* This file has been further processed by $0 */\n\n";
|
||||||
print "FILE_LICENCE ( GPL2_ONLY );\n\n";
|
print "FILE_LICENCE ( GPL2_ONLY );\n\n";
|
||||||
|
|
||||||
foreach my $datum ( @$data ) {
|
foreach my $datum ( @$data ) {
|
||||||
|
@ -66,11 +73,15 @@ foreach my $datum ( @$data ) {
|
||||||
printf "struct %s_pb {\n", $datum->{name};
|
printf "struct %s_pb {\n", $datum->{name};
|
||||||
foreach my $field ( @{$datum->{fields}} ) {
|
foreach my $field ( @{$datum->{fields}} ) {
|
||||||
my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
|
my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
|
||||||
die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
|
die "Inconsistent LSB/RMASK in $datum->{name} before $field->{name}\n"
|
||||||
|
if $pad_width < 0;
|
||||||
printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
|
printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
|
||||||
if $pad_width;
|
if $pad_width;
|
||||||
|
$lsb += $pad_width;
|
||||||
# Damn Perl can't cope with 64-bit hex constants
|
# Damn Perl can't cope with 64-bit hex constants
|
||||||
my $width = 0;
|
my $width = 0;
|
||||||
|
die "Missing RMASK in $datum->{name}.$field->{name}\n"
|
||||||
|
unless defined $field->{rmask};
|
||||||
my $rmask = $field->{rmask};
|
my $rmask = $field->{rmask};
|
||||||
while ( $rmask =~ /^(0x.+)f$/i ) {
|
while ( $rmask =~ /^(0x.+)f$/i ) {
|
||||||
$width += 4;
|
$width += 4;
|
||||||
|
@ -81,16 +92,25 @@ foreach my $datum ( @$data ) {
|
||||||
$width++;
|
$width++;
|
||||||
$rmask >>= 1;
|
$rmask >>= 1;
|
||||||
}
|
}
|
||||||
|
if ( defined $field->{msb} ) {
|
||||||
|
my $msb_width = ( hex ( $field->{msb} ) - $lsb + 1 );
|
||||||
|
$width ||= $msb_width;
|
||||||
|
die "Inconsistent LSB/MSB/RMASK in $datum->{name}.$field->{name}\n"
|
||||||
|
unless $width == $msb_width;
|
||||||
|
}
|
||||||
printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
|
printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
|
||||||
$lsb += $width;
|
$lsb += $width;
|
||||||
}
|
}
|
||||||
my $pad_width = ( 64 - $lsb );
|
my $pad_width = ( 64 - $lsb );
|
||||||
die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
|
die "Inconsistent LSB/RMASK in $datum->{name} final field\n"
|
||||||
|
if $pad_width < 0;
|
||||||
printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
|
printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
|
||||||
if $pad_width;
|
if $pad_width;
|
||||||
printf "};\n";
|
printf "};\n";
|
||||||
printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
|
printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
|
||||||
$datum->{name}, $datum->{name};
|
$datum->{name}, $datum->{name};
|
||||||
}
|
}
|
||||||
|
printf "/* Default value: %s */\n", $datum->{default}
|
||||||
|
if defined $datum->{default};
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue