ioregs.pl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/perl
  2. #
  3. # Parse ioregs.h into a .S file to export the register names
  4. # as actual symbols; this is highly useful for debugging.
  5. use strict;
  6. use integer;
  7. my($infile, $outfile) = @ARGV;
  8. unless (defined($outfile)) {
  9. die "Usage: $0 infile outfile\n";
  10. }
  11. open(my $in, '<', $infile)
  12. or die "$0: $infile: $!\n";
  13. open(my $out, '>', $outfile)
  14. or die "$0: $outfile: $!\n";
  15. my %range = ();
  16. my %sizes = ('B' => 1, 'H' => 2, 'L' => 4);
  17. sub outsym($$$$) {
  18. my($out, $sym, $dev, $size) = @_;
  19. print $out ".globl $sym\n";
  20. print $out "$sym = (. - XDEV_ADDR_BASE) + $dev\n";
  21. print $out ".type $sym, \@object\n";
  22. if ($size) {
  23. print $out ".size $sym, $size\n";
  24. }
  25. }
  26. print $out "\#include \"iodevs.h\"\n";
  27. print $out "\#include \"iodeva.h\"\n";
  28. print $out "\n";
  29. print $out "\.section \".ioregs\",\"aw\",\@nobits\n";
  30. print $out "XDEV_ADDR_BASE = .\n";
  31. while (my $l = <$in>) {
  32. $l =~ s/^\s+//;
  33. $l =~ s/\s+$//;
  34. if ($l =~ /^\/\*\s*(\w+)\s*\=\s*([0-9]+)\s*(\.\.\.\s*([0-9]+))\s*\*\//) {
  35. $range{$1} = [$2, $3 ? $4 : $2];
  36. } elsif ($l =~ /^\/\*\s*(\w+)\s*\=\s*\*\//) {
  37. undef $range{$1};
  38. } elsif ($l =~ /^\#\s*define\s+(\w+)(\((\w+)\))?\s+(IODEVR?(\w).*)$/) {
  39. my $sym = $1;
  40. my $dev = $4;
  41. my $size = $sizes{$5};
  42. if ($2) {
  43. my $v = $3;
  44. my $r = $range{$v};
  45. next unless (defined($r));
  46. for (my $i = $r->[0]; $i <= $r->[1]; $i++) {
  47. print $out "\#define $v $i\n";
  48. outsym($out, $sym.$i, $dev, $size);
  49. print $out "\#undef $v\n";
  50. print $out "\n";
  51. }
  52. } else {
  53. outsym($out, $sym, $dev, $size);
  54. print $out "\n";
  55. }
  56. }
  57. }
  58. close($in);
  59. close($out);