Mercurial > hg > Game > Cerium
changeset 459:5f52612a224d draft
fix ovly_table.pl
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 28 Sep 2009 19:19:38 +0900 |
parents | a82f377009a5 |
children | 433892ba596b |
files | example/get_segment/spe/Makefile example/get_segment/spe/ovly_table.pl |
diffstat | 2 files changed, 97 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/example/get_segment/spe/Makefile Sun Sep 27 17:57:33 2009 +0900 +++ b/example/get_segment/spe/Makefile Mon Sep 28 19:19:38 2009 +0900 @@ -25,8 +25,8 @@ .SUFFIXES: .cc .o -$(OFFSET_H) : - perl ovly_table.pl $(TARGET) > $(OFFSET_H) +$(OFFSET_H) : $(OVLOBJS:.o=.cc) ovly_table.pl + perl ovly_table.pl $(TARGET) $(OVLOBJS:.o=.cc) > $(OFFSET_H) $(SPEOBJS): %.o : %.cc $(OFFSET_H) $(CC) $(CFLAGS) -c $< -o $@
--- a/example/get_segment/spe/ovly_table.pl Sun Sep 27 17:57:33 2009 +0900 +++ b/example/get_segment/spe/ovly_table.pl Mon Sep 28 19:19:38 2009 +0900 @@ -5,53 +5,110 @@ use strict; -my $debug = 0; -my $section_header; -my $symbol_table; -my %section; -my %symbol; +package ReadElf; + +sub new { bless {} } + +sub readelf { + my ($self,$elf)= @_; + + my $debug = 0; + my $section_header; + my $symbol_table; + my %section; + my %symbol; + + $self->{section} = \%section; + $self->{symbol} = \%symbol; + + open(ELF, "readelf -all $elf |"); + while(<ELF>) { + if(/^Section Headers:/) { $section_header = 1 ; $symbol_table = 0; } + elsif(/^Symbol table/) { $section_header = 0 ; $symbol_table = 1; } + elsif(/^[A-Z]/) { $section_header = 0 ; $symbol_table = 0; } + if ($section_header) { + if (/\[\s*(\d+)\]\s+(\.\w+)\s+(\w+)\s+([\da-f]+)\s+([\da-f]+)\s+([\da-f]+)\s/) { + $section{$2} = {nr=>$1,name=>$2,type=>$3,addr=>$4,offset=>$5,size=>$6}; + } + } + if ($symbol_table) { + if(/^\s+(\d+):\s([\da-f]+)\s+([\da-f]+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+([\w\.\_]+)/) { + $symbol{$8} = {num=>$1,value=>$2,size=>$3,type=>$4,bind=>$5,vis=>$6,ndx=>$7,name=>$8}; + } + } + + } -open(ELF, "readelf -all $ARGV[0] |"); -while(<ELF>) { - if(/^Section Headers:/) { $section_header = 1 ; $symbol_table = 0; } - elsif(/^Symbol table/) { $section_header = 0 ; $symbol_table = 1; } - elsif(/^[A-Z]/) { $section_header = 0 ; $symbol_table = 0; } - if ($section_header) { - if (/\[\s*(\d+)\]\s+(\.\w+)\s+(\w+)\s+([\da-f]+)\s+([\da-f]+)\s+([\da-f]+)\s/) { - $section{$1} = {nr=>$1,name=>$2,type=>$3,addr=>$4,offset=>$5,size=>$6}; + if ($debug) { + print "seciton:\n"; + foreach my $key ( keys %section) { + foreach my $i ( keys %{$section{$key}}) { + print "$i=>$section{$key}->{$i} "; } - } - if ($symbol_table) { - if(/^\s+(\d+):\s([\da-f]+)\s+([\da-f]+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+([\w\.\_]+)/) { - $symbol{$8} = {num=>$1,value=>$2,size=>$3,type=>$4,bind=>$5,vis=>$6,ndx=>$7,name=>$8}; + print "\n"; + } + + print "symbol:\n"; + foreach my $key ( keys %symbol) { + foreach my $i ( keys %{$symbol{$key}}) { + print "$i=>$symbol{$key}->{$i} "; } - } - + print "\n"; + } + } + $self; } -if ($debug) { - print "seciton:\n"; - foreach my $key ( keys %section) { - foreach my $i ( keys %{$section{$key}}) { - print "$i=>$section{$key}->{$i} "; - } - print "\n"; - } +sub symbol { + my ($self, $name) = @_; + $self->{symbol}->{$name}; +} - print "symbol:\n"; - foreach my $key ( keys %symbol) { - foreach my $i ( keys %{$symbol{$key}}) { - print "$i=>$symbol{$key}->{$i} "; - } - print "\n"; - } +sub segment { + my ($self, $name) = @_; + $self->{section}->{$name}; } -my $ovly_table = $symbol{'_ovly_table'}; -my $ovly_sec = $section{$ovly_table->{'ndx'}}; + +package Main; + +my $elf = ReadElf->new; -print "#define ovly_table_offset (0x$ovly_sec->{'offset'}+0x$ovly_table->{'value'}-0x$ovly_sec->{'addr'})\n"; -print "#define ovly_table_size ($ovly_table->{'size'}/16)\n"; +my $file = shift; +if (! -e $file) { + open(H,">createTask_offset.h"); + for my $header (@ARGV) { + open(HD,"<$header") or die("Can't open $header"); + my $class = $header; + my $entry = 0; + $class =~ s/\.cc//; + while(<HD>) { + if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) { + print H "#define createTask_${class}_offset 0x$entry\n"; + last; + } + } + } + exit(0); +} +$elf->readelf($file) ; +my $base = $elf->segment(".segment0")->{addr}; + +open(H,">createTask_offset.h"); +for my $header (@ARGV) { + open(HD,"<$header") or die("Can't open $header"); + while(<HD>) { + if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) { + my $class = $1; + my $segment = $2; + my $entry = $elf->symbol("createTask_$class")->{value}; + print H "#define createTask_${class}_offset (0x$entry-0x$base)\n"; + last; + } + } +} + +# end