3 # Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
32 $offsets->{$structure} = $2;
33 } elsif ( /^\#define ${structure}_DEF (\S+)$/ ) {
34 $defaults->{$structure} = $1;
35 } elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
36 $structures->{$structure}->{$1}->{LSB} = $2;
37 } elsif ( /^\#define ${structure}_(\S+)_MSB (\S+)$/ ) {
38 $structures->{$structure}->{$1}->{MSB} = $2;
39 } elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
40 $structures->{$structure}->{$1}->{RMASK} = $2;
48 my $data = [ map { { name => $_, offset => $offsets->{$_},
49 default => $defaults->{$_} }; }
50 sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
53 foreach my $datum ( @$data ) {
54 next unless exists $structures->{$datum->{name}};
55 $structure = $structures->{$datum->{name}};
56 my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
57 msb => $structure->{$_}->{MSB},
58 rmask => $structure->{$_}->{RMASK} }; }
59 sort { hex ( $structure->{$a}->{LSB} ) <=>
60 hex ( $structure->{$b}->{LSB} ) }
62 $datum->{fields} = $fields;
65 print "\n/* This file has been further processed by $0 */\n\n";
66 print "FILE_LICENCE ( GPL2_ONLY );\n\n";
68 foreach my $datum ( @$data ) {
69 printf "#define %s_offset 0x%08xUL\n",
70 $datum->{name}, hex ( $datum->{offset} );
71 if ( exists $datum->{fields} ) {
74 printf "struct %s_pb {\n", $datum->{name};
75 foreach my $field ( @{$datum->{fields}} ) {
76 my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
77 die "Inconsistent LSB/RMASK in $datum->{name} before $field->{name}\n"
79 printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
82 # Damn Perl can't cope with 64-bit hex constants
84 die "Missing RMASK in $datum->{name}.$field->{name}\n"
85 unless defined $field->{rmask};
86 my $rmask = $field->{rmask};
87 while ( $rmask =~ /^(0x.+)f$/i ) {
91 $rmask = hex ( $rmask );
96 if ( defined $field->{msb} ) {
97 my $msb_width = ( hex ( $field->{msb} ) - $lsb + 1 );
98 $width ||= $msb_width;
99 die "Inconsistent LSB/MSB/RMASK in $datum->{name}.$field->{name}\n"
100 unless $width == $msb_width;
102 printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
105 my $pad_width = ( 64 - $lsb );
106 die "Inconsistent LSB/RMASK in $datum->{name} final field\n"
108 printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
111 printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
112 $datum->{name}, $datum->{name};
114 printf "/* Default value: %s */\n", $datum->{default}
115 if defined $datum->{default};