Mercurial > hg > Game > Cerium
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 |
rev | line source |
---|---|
425 | 1 #!/usr/bin/perl |
2 # | |
3 # Author: Shinji KONO <kono@ie.u-ryukyu.ac.jp> | |
4 # v.0.1 Sat May 30 04:41:18 JST 2009 | |
5 # | |
6 # fix spu-gcc assembler soruce for DMA loadable PIC code | |
7 # | |
8 #$(OVLOBJS): %.o : %.cc | |
9 # $(SPECC) $(SPECFLAGS) -c $< -S -o $(<:.cc=.s) | |
10 # perl spe/fixpic.pl $(<:.cc=.s) | $(SPECC) $(SPECFLAGS) -x assembler -c -o $@ - | |
11 | |
12 use strict; | |
13 | |
14 my %global; | |
15 my %local; | |
16 my %weak; | |
17 my @line; | |
18 | |
19 # Basically SPU code is PIC. But linked library is in the fixed | |
20 # address space. | |
21 # | |
22 # rewrite relative to absolute for global branch address | |
23 # | |
24 # Target instruction | |
25 # hbrr -> hbra | |
26 # br -> bra | |
27 # brsl -> brasl | |
28 # brnz cannot be global | |
29 | |
465 | 30 # lqr -> li (for global) |
31 # ila global -> a $0,.LC0-.,$1 | |
32 | |
425 | 33 while(<>) { |
34 push(@line,$_); | |
35 if(/\.global\s+([^\s]+)/) { | |
36 $global{$1} = 1; | |
37 } | |
38 if(/\.weak\s+([^\s]+)/) { | |
39 $weak{$1} = 1; | |
40 next; | |
41 } | |
42 if(/^([^\s]+):/) { | |
43 $local{$1} = 1; | |
44 } | |
45 } | |
46 | |
47 for(@line) { | |
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 | 52 my $name = $2; |
53 if (! defined $local{$name} || defined $weak{$name} ) { | |
54 s/hbrr/hbra/ || | |
55 s/brsl/brasl/ || | |
56 s/br/bra/ ; | |
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 | 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 | 72 } |
73 print ; | |
74 } | |
75 | |
76 # end |