annotate example/get_segment/spe/ovly_table.pl @ 1615:2c6e9ed9db3b draft

merge
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 14 May 2013 13:38:17 +0900
parents 3aaa9da117f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
1 #!/usr/bin/perl
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
2 # // from readelf -all spu/spe_main
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
3 # // [12] .data PROGBITS 00000f20 0011a0 000384 00 WA 0 0 16
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
4 # // 109: 00001260 64 OBJECT GLOBAL DEFAULT 12 _ovly_table
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
5
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
6 use strict;
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
7
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
8 package ReadElf;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
9
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
10 sub new { bless {} }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
11
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
12 sub readelf {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
13 my ($self,$elf)= @_;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
14
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
15 my $debug = 0;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
16 my $section_header;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
17 my $symbol_table;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
18 my %section;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
19 my %symbol;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
20
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
21 $self->{section} = \%section;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
22 $self->{symbol} = \%symbol;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
23
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
24 open(ELF, "readelf -all $elf |");
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
25 while(<ELF>) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
26 if(/^Section Headers:/) { $section_header = 1 ; $symbol_table = 0; }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
27 elsif(/^Symbol table/) { $section_header = 0 ; $symbol_table = 1; }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
28 elsif(/^[A-Z]/) { $section_header = 0 ; $symbol_table = 0; }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
29 if ($section_header) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
30 if (/\[\s*(\d+)\]\s+(\.\w+)\s+(\w+)\s+([\da-f]+)\s+([\da-f]+)\s+([\da-f]+)\s/) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
31 $section{$2} = {nr=>$1,name=>$2,type=>$3,addr=>$4,offset=>$5,size=>$6};
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
32 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
33 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
34 if ($symbol_table) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
35 if(/^\s+(\d+):\s([\da-f]+)\s+([\da-f]+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+([\w\.\_]+)/) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
36 $symbol{$8} = {num=>$1,value=>$2,size=>$3,type=>$4,bind=>$5,vis=>$6,ndx=>$7,name=>$8};
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
37 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
38 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
39
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
40 }
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
41
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
42
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
43 if ($debug) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
44 print "seciton:\n";
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
45 foreach my $key ( keys %section) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
46 foreach my $i ( keys %{$section{$key}}) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
47 print "$i=>$section{$key}->{$i} ";
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
48 }
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
49 print "\n";
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
50 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
51
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
52 print "symbol:\n";
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
53 foreach my $key ( keys %symbol) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
54 foreach my $i ( keys %{$symbol{$key}}) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
55 print "$i=>$symbol{$key}->{$i} ";
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
56 }
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
57 print "\n";
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
58 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
59 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
60 $self;
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
61 }
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
62
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
63 sub symbol {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
64 my ($self, $name) = @_;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
65 $self->{symbol}->{$name};
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
66 }
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
67
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
68 sub segment {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
69 my ($self, $name) = @_;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
70 $self->{section}->{$name};
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
71 }
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
72
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
73
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
74 package Main;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
75
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
76 my $elf = ReadElf->new;
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
77
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
78 my $file = shift;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
79 if (! -e $file) {
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
80 open(H,">runTask_offset.h");
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
81 for my $header (@ARGV) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
82 open(HD,"<$header") or die("Can't open $header");
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
83 my $class = $header;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
84 my $entry = 0;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
85 $class =~ s/\.cc//;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
86 while(<HD>) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
87 if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
88 print H "#define runTask_${class}_offset 0x$entry\n";
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
89 last;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
90 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
91 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
92 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
93 exit(0);
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
94 }
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
95
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
96 $elf->readelf($file) ;
458
a82f377009a5 add ovly table tag modified
kono@localhost.localdomain
parents:
diff changeset
97
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
98 my $base = $elf->segment(".segment0")->{addr};
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
99
461
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
100 my @ldfiles;
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
101 my $ldsegment = "";
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
102
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
103 open(H,">runTask_offset.h");
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
104 print H "#ifndef RUNTASK_OFFSET_H\n";
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
105 print H "#define RUNTASK_OFFSET_H\n";
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
106 for my $header (@ARGV) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
107 open(HD,"<$header") or die("Can't open $header");
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
108 while(<HD>) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
109 if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
110 my $class = $1;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
111 my $segment = $2;
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
112 my $entry = $elf->symbol("runTask_$class")->{value};
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
113 print H "#define runTask_${class}_offset (0x$entry-0x$base)\n";
461
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
114 my $ofile = $header;
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
115 $ofile =~ s/\.cc/.o/;
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
116 push(@ldfiles,$ofile);
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
117 $ldsegment .= " .segment$segment { $ofile(.text) }\n";
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
118 last;
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
119 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
120 }
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
121 }
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 461
diff changeset
122 print H "#endif\n";
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
123
461
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
124 my $ld_script = <<"EOFEOF";
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
125 / \\.text /
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
126 /\\\*\(\\.text/
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
127 s/\\\*\(\\.text/\*\( EXCLUDE_FILE(@ldfiles) .text/
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
128 /} =0/
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
129 a
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
130 OVERLAY :
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
131 {
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
132 $ldsegment
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
133 }
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
134 .
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
135 w
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
136 EOFEOF
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
137
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
138 open(H,">ldscript.ed");
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
139 print H $ld_script;
009a2db963de overlay worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 459
diff changeset
140
459
5f52612a224d fix ovly_table.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 458
diff changeset
141 # end