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

merge
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 14 May 2013 13:38:17 +0900
parents 16f0abb574b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
425
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/perl
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 # Author: Shinji KONO <kono@ie.u-ryukyu.ac.jp>
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 # v.0.1 Sat May 30 04:41:18 JST 2009
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 # fix spu-gcc assembler soruce for DMA loadable PIC code
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #$(OVLOBJS): %.o : %.cc
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 # $(SPECC) $(SPECFLAGS) -c $< -S -o $(<:.cc=.s)
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 # perl spe/fixpic.pl $(<:.cc=.s) | $(SPECC) $(SPECFLAGS) -x assembler -c -o $@ -
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 use strict;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 my %global;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 my %local;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 my %weak;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 my @line;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 # Basically SPU code is PIC. But linked library is in the fixed
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 # address space.
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 # rewrite relative to absolute for global branch address
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 # Target instruction
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 # hbrr -> hbra
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 # br -> bra
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 # brsl -> brasl
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 # brnz cannot be global
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 425
diff changeset
30 # lqr -> li (for global)
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 425
diff changeset
31 # ila global -> a $0,.LC0-.,$1
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 425
diff changeset
32
425
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 while(<>) {
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 push(@line,$_);
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 if(/\.global\s+([^\s]+)/) {
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 $global{$1} = 1;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 if(/\.weak\s+([^\s]+)/) {
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 $weak{$1} = 1;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 next;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 if(/^([^\s]+):/) {
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 $local{$1} = 1;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 for(@line) {
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 if (! /^#/) {
473
16f0abb574b7 string offset for get_segment relocation code...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
49 next if (/\.section\s+\.rodata/);
16f0abb574b7 string offset for get_segment relocation code...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
50 if (/\s(brsl|hbrr|br)\s+[^\s]+,\s*(\d+[fb])/) {
16f0abb574b7 string offset for get_segment relocation code...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
51 } elsif(/\s(br)\s+([^\s]+)/||/\s(brsl|hbrr)\s+[^\s]+,\s*([^\s]+)/) {
425
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 my $name = $2;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 if (! defined $local{$name} || defined $weak{$name} ) {
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 s/hbrr/hbra/ ||
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 s/brsl/brasl/ ||
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 s/br/bra/ ;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 }
473
16f0abb574b7 string offset for get_segment relocation code...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
58 }
16f0abb574b7 string offset for get_segment relocation code...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
59
466
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
60 # } elsif(/\s(lqr)\s+(\$\d+),([^\s]+)/) {
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
61 # my $name = $2;
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
62 # if (! defined $local{$name} || defined $weak{$name} ) {
465
3aaa9da117f4 fix get_segement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 425
diff changeset
63 # s/lqr/lqd/;
466
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
64 # }
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
65 # } elsif(/\s(ila)\s+(\$\d+),([^\s]+)/) {
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
66 # my $name = $3;
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
67 # if (! defined $local{$name} || defined $weak{$name} ) {
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
68 # $_ = $_;
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
69 # } else {
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
70 # $_ = "\tai\t$2,\$0,$3-.\n";
c73aff02db67 prohibit global variable in Task....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 465
diff changeset
71 # }
425
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 print ;
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
cebb48da955e add code load API
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 # end