2
0

ioregsa.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. my %syms;
  18. sub outsym($$$$) {
  19. my($out, $sym, $dev, $size) = @_;
  20. print $out ".globl $sym\n";
  21. print $out "$sym = $dev\n";
  22. if ($size) {
  23. print $out ".type $sym, \@object\n";
  24. print $out ".size $sym, $size\n";
  25. }
  26. }
  27. print $out "\#include \"iodevs.h\"\n";
  28. print $out "\#include \"iodeva.h\"\n";
  29. print $out "\n";
  30. outsym($out, 'IODEV_BASE', 'IODEV_ADDR_BASE', 0);
  31. outsym($out, 'XDEV_BASE', 'XDEV_ADDR_BASE', 0);
  32. while (my $l = <$in>) {
  33. $l =~ s/^\s+//;
  34. $l =~ s/\s+$//;
  35. if ($l =~ /^\/\*\s*(\w+)\s*\=\s*([0-9]+)\s*(\.\.\.\s*([0-9]+))\s*\*\//) {
  36. $range{$1} = [$2, $3 ? $4 : $2];
  37. } elsif ($l =~ /^\/\*\s*(\w+)\s*\=\s*\*\//) {
  38. undef $range{$1};
  39. } elsif ($l =~ /^\#\s*define\s+(\w+)(\((\w+)\))?\s+(IODEVR?(\w).*)$/) {
  40. my $sym = $1;
  41. my $dev = $4;
  42. my $size = $sizes{$5};
  43. if ($2) {
  44. my $v = $3;
  45. my $r = $range{$v};
  46. next unless (defined($r));
  47. for (my $i = $r->[0]; $i <= $r->[1]; $i++) {
  48. print $out "\#define $v $i\n";
  49. outsym($out, $sym.$i, $dev, $size);
  50. print $out "\#undef $v\n";
  51. print $out "\n";
  52. }
  53. } else {
  54. outsym($out, $sym, $dev, $size);
  55. print $out "\n";
  56. }
  57. }
  58. }
  59. close($in);
  60. close($out);