comparison bin/cell_fixpic.pl @ 0:04e28d8d3c6f

first commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 08 Nov 2010 01:23:25 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:04e28d8d3c6f
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
30 # lqr -> li (for global)
31 # ila global -> a $0,.LC0-.,$1
32
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 (! /^#/) {
49 next if (/\.section\s+\.rodata/);
50 if (/\s(brsl|hbrr|br)\s+[^\s]+,\s*(\d+[fb])/) {
51 } elsif(/\s(br)\s+([^\s]+)/||/\s(brsl|hbrr)\s+[^\s]+,\s*([^\s]+)/) {
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 }
58 }
59
60 # } elsif(/\s(lqr)\s+(\$\d+),([^\s]+)/) {
61 # my $name = $2;
62 # if (! defined $local{$name} || defined $weak{$name} ) {
63 # s/lqr/lqd/;
64 # }
65 # } elsif(/\s(ila)\s+(\$\d+),([^\s]+)/) {
66 # my $name = $3;
67 # if (! defined $local{$name} || defined $weak{$name} ) {
68 # $_ = $_;
69 # } else {
70 # $_ = "\tai\t$2,\$0,$3-.\n";
71 # }
72 }
73 print ;
74 }
75
76 # end