|
@@ -20,6 +20,7 @@ use strict;
|
20
|
20
|
use warnings;
|
21
|
21
|
|
22
|
22
|
my $offsets = {};
|
|
23
|
+my $defaults = {};
|
23
|
24
|
my $structures = {};
|
24
|
25
|
my $structure = "";
|
25
|
26
|
|
|
@@ -28,8 +29,12 @@ while ( <> ) {
|
28
|
29
|
if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
|
29
|
30
|
$structure = $1;
|
30
|
31
|
$offsets->{$structure} = $2;
|
|
32
|
+ } elsif ( /^\#define ${structure}_DEF (\S+)$/ ) {
|
|
33
|
+ $defaults->{$structure} = $1;
|
31
|
34
|
} elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
|
32
|
35
|
$structures->{$structure}->{$1}->{LSB} = $2;
|
|
36
|
+ } elsif ( /^\#define ${structure}_(\S+)_MSB (\S+)$/ ) {
|
|
37
|
+ $structures->{$structure}->{$1}->{MSB} = $2;
|
33
|
38
|
} elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
|
34
|
39
|
$structures->{$structure}->{$1}->{RMASK} = $2;
|
35
|
40
|
} elsif ( /^\s*$/ ) {
|
|
@@ -39,7 +44,8 @@ while ( <> ) {
|
39
|
44
|
}
|
40
|
45
|
}
|
41
|
46
|
|
42
|
|
-my $data = [ map { { name => $_, offset => $offsets->{$_} }; }
|
|
47
|
+my $data = [ map { { name => $_, offset => $offsets->{$_},
|
|
48
|
+ default => $defaults->{$_} }; }
|
43
|
49
|
sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
|
44
|
50
|
keys %$offsets ];
|
45
|
51
|
|
|
@@ -47,6 +53,7 @@ foreach my $datum ( @$data ) {
|
47
|
53
|
next unless exists $structures->{$datum->{name}};
|
48
|
54
|
$structure = $structures->{$datum->{name}};
|
49
|
55
|
my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
|
|
56
|
+ msb => $structure->{$_}->{MSB},
|
50
|
57
|
rmask => $structure->{$_}->{RMASK} }; }
|
51
|
58
|
sort { hex ( $structure->{$a}->{LSB} ) <=>
|
52
|
59
|
hex ( $structure->{$b}->{LSB} ) }
|
|
@@ -54,7 +61,7 @@ foreach my $datum ( @$data ) {
|
54
|
61
|
$datum->{fields} = $fields;
|
55
|
62
|
}
|
56
|
63
|
|
57
|
|
-print "\n/* This file has been further processed by $0 */\n\n"
|
|
64
|
+print "\n/* This file has been further processed by $0 */\n\n";
|
58
|
65
|
print "FILE_LICENCE ( GPL2_ONLY );\n\n";
|
59
|
66
|
|
60
|
67
|
foreach my $datum ( @$data ) {
|
|
@@ -66,11 +73,15 @@ foreach my $datum ( @$data ) {
|
66
|
73
|
printf "struct %s_pb {\n", $datum->{name};
|
67
|
74
|
foreach my $field ( @{$datum->{fields}} ) {
|
68
|
75
|
my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
|
69
|
|
- die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
|
|
76
|
+ die "Inconsistent LSB/RMASK in $datum->{name} before $field->{name}\n"
|
|
77
|
+ if $pad_width < 0;
|
70
|
78
|
printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
|
71
|
79
|
if $pad_width;
|
|
80
|
+ $lsb += $pad_width;
|
72
|
81
|
# Damn Perl can't cope with 64-bit hex constants
|
73
|
82
|
my $width = 0;
|
|
83
|
+ die "Missing RMASK in $datum->{name}.$field->{name}\n"
|
|
84
|
+ unless defined $field->{rmask};
|
74
|
85
|
my $rmask = $field->{rmask};
|
75
|
86
|
while ( $rmask =~ /^(0x.+)f$/i ) {
|
76
|
87
|
$width += 4;
|
|
@@ -81,16 +92,25 @@ foreach my $datum ( @$data ) {
|
81
|
92
|
$width++;
|
82
|
93
|
$rmask >>= 1;
|
83
|
94
|
}
|
|
95
|
+ if ( defined $field->{msb} ) {
|
|
96
|
+ my $msb_width = ( hex ( $field->{msb} ) - $lsb + 1 );
|
|
97
|
+ $width ||= $msb_width;
|
|
98
|
+ die "Inconsistent LSB/MSB/RMASK in $datum->{name}.$field->{name}\n"
|
|
99
|
+ unless $width == $msb_width;
|
|
100
|
+ }
|
84
|
101
|
printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
|
85
|
102
|
$lsb += $width;
|
86
|
103
|
}
|
87
|
104
|
my $pad_width = ( 64 - $lsb );
|
88
|
|
- die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
|
|
105
|
+ die "Inconsistent LSB/RMASK in $datum->{name} final field\n"
|
|
106
|
+ if $pad_width < 0;
|
89
|
107
|
printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
|
90
|
108
|
if $pad_width;
|
91
|
109
|
printf "};\n";
|
92
|
110
|
printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
|
93
|
111
|
$datum->{name}, $datum->{name};
|
94
|
112
|
}
|
|
113
|
+ printf "/* Default value: %s */\n", $datum->{default}
|
|
114
|
+ if defined $datum->{default};
|
95
|
115
|
print "\n";
|
96
|
116
|
}
|