ioregsa.pl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 - XDEV_ADDR_BASE)\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. print $out "\.section \".iodevs\",\"aw\",\@nobits\n\n";
  31. outsym($out, 'IODEV_BASE', 'IODEV_ADDR_BASE', 0);
  32. outsym($out, 'XDEV_BASE', 'XDEV_ADDR_BASE', 0);
  33. while (my $l = <$in>) {
  34. $l =~ s/^\s+//;
  35. $l =~ s/\s+$//;
  36. if ($l =~ /^\/\*\s*(\w+)\s*\=\s*([0-9]+)\s*(\.\.\.\s*([0-9]+))\s*\*\//) {
  37. $range{$1} = [$2, $3 ? $4 : $2];
  38. } elsif ($l =~ /^\/\*\s*(\w+)\s*\=\s*\*\//) {
  39. undef $range{$1};
  40. } elsif ($l =~ /^\#\s*define\s+(\w+)(\((\w+)\))?\s+(IODEVR?(\w).*)$/) {
  41. my $sym = $1;
  42. my $dev = $4;
  43. my $size = $sizes{$5};
  44. if ($2) {
  45. my $v = $3;
  46. my $r = $range{$v};
  47. next unless (defined($r));
  48. for (my $i = $r->[0]; $i <= $r->[1]; $i++) {
  49. print $out "\#define $v $i\n";
  50. outsym($out, $sym.$i, $dev, $size);
  51. print $out "\#undef $v\n";
  52. print $out "\n";
  53. }
  54. } else {
  55. outsym($out, $sym, $dev, $size);
  56. print $out "\n";
  57. }
  58. }
  59. }
  60. close($in);
  61. close($out);