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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
30 $offsets->{$structure} = $2;
31 } elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
32 $structures->{$structure}->{$1}->{LSB} = $2;
33 } elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
34 $structures->{$structure}->{$1}->{RMASK} = $2;
42 my $data = [ map { { name => $_, offset => $offsets->{$_} }; }
43 sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
46 foreach my $datum ( @$data ) {
47 next unless exists $structures->{$datum->{name}};
48 $structure = $structures->{$datum->{name}};
49 my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
50 rmask => $structure->{$_}->{RMASK} }; }
51 sort { hex ( $structure->{$a}->{LSB} ) <=>
52 hex ( $structure->{$b}->{LSB} ) }
54 $datum->{fields} = $fields;
57 print "\n/* This file has been further processed by $0 */\n\n"
58 print "FILE_LICENCE ( GPL2_ONLY );\n\n";
60 foreach my $datum ( @$data ) {
61 printf "#define %s_offset 0x%08xUL\n",
62 $datum->{name}, hex ( $datum->{offset} );
63 if ( exists $datum->{fields} ) {
66 printf "struct %s_pb {\n", $datum->{name};
67 foreach my $field ( @{$datum->{fields}} ) {
68 my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
69 die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
70 printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
72 # Damn Perl can't cope with 64-bit hex constants
74 my $rmask = $field->{rmask};
75 while ( $rmask =~ /^(0x.+)f$/i ) {
79 $rmask = hex ( $rmask );
84 printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
87 my $pad_width = ( 64 - $lsb );
88 die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
89 printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
92 printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
93 $datum->{name}, $datum->{name};