annotate bin/cell_ovly_table.pl @ 1877:f73ca57cdc81 draft

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