comparison bin/cell_fixpic.pl @ 471:ceaa00afd726

add library
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 01 Oct 2009 19:28:52 +0900
parents
children 077845279741
comparison
equal deleted inserted replaced
467:44c0bce54dcf 471:ceaa00afd726
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(br)\s+([^\s]+)/||/\s(brsl|hbrr)\s+[^\s]+,\s*([^\s]+)/) {
51 my $name = $2;
52 if (! defined $local{$name} || defined $weak{$name} ) {
53 s/hbrr/hbra/ ||
54 s/brsl/brasl/ ||
55 s/br/bra/ ;
56 }
57 # } elsif(/\s(lqr)\s+(\$\d+),([^\s]+)/) {
58 # my $name = $2;
59 # if (! defined $local{$name} || defined $weak{$name} ) {
60 # s/lqr/lqd/;
61 # }
62 # } elsif(/\s(ila)\s+(\$\d+),([^\s]+)/) {
63 # my $name = $3;
64 # if (! defined $local{$name} || defined $weak{$name} ) {
65 # $_ = $_;
66 # } else {
67 # $_ = "\tai\t$2,\$0,$3-.\n";
68 # }
69 }
70 }
71 print ;
72 }
73
74 # end