5 my $DATE = '2009-09-04';
6 my $AUTHOR = "Ward Vandewege <ward\@jhvc.com>";
7 my $COPYRIGHT = "2009";
8 my $LICENSE = "GPL v3 - http://www.fsf.org/licenses/gpl.txt";
9 my $URL = "https://coreboot.org";
15 # Run the bkdg for k8 through pdftotext first (from the poppler package)
18 my $raw_register = '';
26 my $previous_start = 0;
27 my $previous_stop = 0;
28 my $strip_empties = 0;
30 my $previous_bits = '';
36 $typos{'CkeDreStrength'} = 'CkeDrvStrength';
42 foreach my $k (keys %typos) {
43 $line =~ s/$k/$typos{$k}/;
46 # Make sure we do not include headers in our output
47 if (($line =~ /^Chapter 4/) || ($line =~ /Chapter 4$/)) {
52 if ($step == 99) { # header
53 if ($line =~ /Processors$/) {
61 # Headers are followed by two blank lines. Strip them.
62 if ($line =~ /^\s*$/) {
70 if (($step % 6 == 0) && ($line =~ /^\d+\.\d+\.\d+\s+(.*)$/)) {
75 $description = "$line\n";
79 #print STDERR "STEP: $step\n";
80 #print STDERR "$line\n";
82 if ((($step == 0) || ($step == 6) || ($step == 2)) && ($line =~ /^(.*)\s+Function\s+\d+:\s+Offset\s+..h$/)) {
86 $description =~ s/\n+$//ms;
88 if ($previous_bits ne '') {
89 &finish_record
($previous_bits);
90 $previous_bits = ''; # reset previous_bits (used in step 6)
95 } elsif ($step == 2) {
96 $description .= "$line\n";
100 if (($step == 3) && ($line =~ /^\s+Index (.+h)$/)) {
102 @registers = split(/,/,$raw_register);
103 for (my $i=0;$i<=$#registers;$i++) {
104 $registers[$i] =~ s/ //g;
105 $registers[$i] =~ s/h$//;
107 # OK, we have our register(s), so now we can print out the name and description lines.
108 print "\$info{'$registers[0]'}{'name'} = \"$name\";\n";
109 print "\$info{'$registers[0]'}{'description'} = \"$description\";\n";
114 if (($step == 4) && ($line =~ /^Bits\s+Mnemonic\s+Function\s+R\/W\s
+Reset
$/)) {
119 if (($step == 5) && (!($line =~ /^Field Descriptions$/))) {
120 $line =~ s/^ +//; # Strip leading spaces
121 my @f = split(/ +/,$line);
124 next if (!exists($f[0]));
126 # skip headers (they could be repeated if the table crosses a page boundary
127 next if ($f[0] eq 'Bits');
129 # Clean up funky field separator
130 if ($f[0] =~ /\d+.+\d+/) {
131 $f[0] =~ s/[^\d]+/-/g;
134 my ($start, $stop, $width) = (0,0,0);
136 $f[0] =~ s/^(\d+)[^\d]+(\d+)$/$1-$2/;
137 ($stop,$start) = ($1,$2);
138 $width = $stop-$start+1;
140 if ($f[0] =~ /^\d+$/) {
141 $start = $stop = $f[0];
144 # continuation from previous line
145 $start = $stop = $width = 0;
149 # Some lines have only bit entries
150 if (($#f < 1) && ($f[0] =~ /^\d+(|\-\d+)/)) {
156 # Some lines are a continuation of the function field a line above
162 my $tmp = "\$info{'$registers[0]'}{'ranges'}{" . $previous_res . "}{'function'} .= \"" . $f[2] . "\";\n";
163 print &multiply
($tmp,$previous_res,$previous_start,$previous_stop);
167 # Some lines have only bit and reset entries
175 # Some lines have no mnemonic and no function
183 # functions with 'reserved' mnemonic have no function
184 if ($f[1] =~ /^reserved$/i) {
190 $previous_res = $f[0];
191 $previous_start = $start;
192 $previous_stop = $stop;
194 # the 'range' field is not useful in this instance, but used in the 'fields' version of this block to easily go
195 # from a bit position to the corresponding range.
197 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'function'} = \"" . $f[2] . "\";
198 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'mnemonic'} = \"" . $f[1] . "\";
199 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'description'} = \"" . "\";
200 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'begin'} = $start;
201 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'end'} = $stop;
202 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'width'} = $width;
203 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'rw'} = \"" . $f[3] . "\";
204 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'reset'} = \"" . $f[4] . "\";
205 \$info{'$registers[0]'}{'ranges'}{'" . $f[0] . "'}{'range'} = \"" . $f[0] . "\";
209 $output = &multiply
($str,$f[0],$start,$stop);
211 # Load the data structure here, too
214 print $output . "\n\n";
215 } elsif (($step == 5) && ($line =~ /^Field Descriptions$/)) {
221 if ($line =~ /^(.*?)\((.*?)\).+Bit(s|) +(.*?)\. (.*)$/) {
224 $bits =~ s/[^\d]+/-/;
226 if ($previous_bits ne '') {
227 # We're done with a field description block
228 print "\$info{'$registers[0]'}{'ranges'}{'$previous_bits'}{'description'} = \"" . $info{$registers[0]}{'ranges'}{$previous_bits}{'description'} . "\";\n";
229 foreach my $k (keys %{$info{$registers[0]}{'ranges'}{$previous_bits}{'values'}}) {
230 print "\$info{'$registers[0]'}{'ranges'}{'$previous_bits'}{'values'}{'$k'} = \"" . $info{$registers[0]}{'ranges'}{$previous_bits}{'values'}{$k} . "\";\n";
234 if (exists($info{$registers[0]}{'ranges'}{$bits})) {
235 print STDERR
"match ($bits) on $line\n";
236 $info{$registers[0]}{'ranges'}{$bits}{'description'} = $desc . "\n";
237 $previous_bits = $bits;
239 } elsif ($previous_bits ne '') {
240 $info{$registers[0]}{'ranges'}{$previous_bits}{'description'} .= $line . "\n";
241 if ($line =~ /([0-9a-f]+b|[0-9a-f]+h) = (.*)$/i) {
242 $info{$registers[0]}{'ranges'}{$previous_bits}{'values'}{$1} = $2;
248 &finish_record
($previous_bits);
259 for (my $i=$start;$i<=$stop;$i++) {
261 $tmp =~ s/\{'$range'\}/{'$i'}/g;
262 $tmp =~ s/\{'ranges'\}/{'fields'}/g;
267 #$output .= $str if (($stop - $start + 1) > 1);
274 my $previous_bits = shift;
275 # We're done with a field description block
276 print "\$info{'$registers[0]'}{'ranges'}{'$previous_bits'}{'description'} = \"" . $info{$registers[0]}{'ranges'}{$previous_bits}{'description'} . "\";\n";
277 foreach my $k (keys %{$info{$registers[0]}{'ranges'}{$previous_bits}{'values'}}) {
278 print "\$info{'$registers[0]'}{'ranges'}{'$previous_bits'}{'values'}{'$k'} = \"" . $info{$registers[0]}{'ranges'}{$previous_bits}{'values'}{$k} . "\";\n";
281 # End of table. If this data applies to more than one register, print duplication lines.
282 for (my $i=1;$i<=$#registers;$i++) {
283 print "\$info{'$registers[$i]'} = \$info{'$registers[0]'};\n";