changeset 472:699ee087234e

fix spe test_render
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 02 Oct 2009 23:20:25 +0900
parents ceaa00afd726 (diff) bf32e35f1afa (current diff)
children 7777761e8e02
files TaskManager/Test/test_render/spe/ChainInit.cc TaskManager/Test/test_render/spe/CreateSpan.cc TaskManager/Test/test_render/spe/DrawBack.cc TaskManager/Test/test_render/spe/DrawSpan.cc TaskManager/Test/test_render/spe/DrawSpan.h TaskManager/Test/test_render/spe/Load_Texture.cc TaskManager/Test/test_render/spe/TileHash.h TaskManager/Test/test_render/spe/spe-main.cc TaskManager/Test/test_render/task/DrawSpan.h TaskManager/Test/test_render/task/InitKey.cc TaskManager/Test/test_render/task/UpdateKey.h
diffstat 14 files changed, 480 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/spe/ChainInit.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/ChainInit.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -25,7 +25,7 @@
     uint32 chain_len = s->get_param(0);
 
     // property は spe 上で allocate している(global)
-    CHAIN_VARS *property = (CHAIN_VARS*)global_alloc(DATA_ID, sizeof(CHAIN_VARS)*chain_len);
+    CHAIN_VARS *property = (CHAIN_VARS*)s->global_alloc(DATA_ID, sizeof(CHAIN_VARS)*chain_len);
     memcpy(property, idata, sizeof(CHAIN_VARS)*chain_len);
 
     return 0;
--- a/TaskManager/Test/test_render/spe/CreateSpan.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/CreateSpan.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -11,10 +11,10 @@
 static const int TILE_LOAD         =  9;
 static const int TILE_STORE        = 10;
 
-static struct g {
+typedef struct g {
     SpanPackPtr spack ;
     SpanPackPtr send_spack ;
-    int prev_index = ;
+    int prev_index ;
 } G, *Gptr;
 
 SchedDefineTask(CreateSpan);
@@ -193,8 +193,8 @@
  * @param[in] tex_y_len 分割する前の Triangle に貼られている Texture の
  *                      長さの割合 (0 ... 1)
  */
-void
-CreateSpan::half_triangle(SchedTask *smanager, SpanPackPtr *spackList,
+static void
+half_triangle(SchedTask *smanager, Gptr g, SpanPackPtr *spackList,
 			  int charge_y_top, int charge_y_end,
 			  TriangleTexInfoPtr tex_info,
 			  VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10,
@@ -272,18 +272,18 @@
 	     * 現在の SpanPack をメインメモリに送り、
 	     * 新しい SpanPack を取ってくる
 	     */
-	    if (index != prev_index) {
-		tmp_spack = spack;
-		spack = send_spack;
-		send_spack = tmp_spack;
+	    if (index != g->prev_index) {
+		tmp_spack = g->spack;
+		g->spack = g->send_spack;
+		g->send_spack = tmp_spack;
 
 		smanager->dma_wait(SPAN_PACK_STORE);
-		smanager->dma_store(send_spack, (uint32)spackList[prev_index],
+		smanager->dma_store(g->send_spack, (uint32)spackList[g->prev_index],
 				    sizeof(SpanPack), SPAN_PACK_STORE);
 		
-		smanager->dma_load(spack, (uint32)spackList[index],
+		smanager->dma_load(g->spack, (uint32)spackList[index],
 				   sizeof(SpanPack), SPAN_PACK_LOAD);
-		prev_index = index;
+		g->prev_index = index;
 		smanager->dma_wait(SPAN_PACK_LOAD);
 	    }
 
@@ -292,7 +292,7 @@
 	     * メインメモリで allocate した領域 (next) を持ってきて
 	     * 現在の spack->next につなぎ、next を次の spack とする。
 	     */
-	    if (spack->info.size >= MAX_SIZE_SPAN) {
+	    if (g->spack->info.size >= MAX_SIZE_SPAN) {
 		SpanPackPtr next;
 		
 	__debug_spe("CreateSpan mainMem_alloc 0x%x\n", (unsigned int)sizeof(SpanPack));
@@ -301,22 +301,22 @@
 		next = (SpanPackPtr)smanager->mainMem_get(0);
 	__debug_spe("CreateSpan mainMem_allocated 0x%x\n", (unsigned int)next);
 		
-		spack->next = next; // この部分は TaskManager でやる
+		g->spack->next = next; // この部分は TaskManager でやる
 
-		tmp_spack = spack;
-		spack = send_spack;
-		send_spack = tmp_spack;
+		tmp_spack = g->spack;
+		g->spack = g->send_spack;
+		g->send_spack = tmp_spack;
 
 		smanager->dma_wait(SPAN_PACK_STORE);
-		smanager->dma_store(send_spack, (uint32)spackList[index],
+		smanager->dma_store(g->send_spack, (uint32)spackList[index],
 				    sizeof(SpanPack), SPAN_PACK_STORE);
 
 		spackList[index] = next;
 		
-		smanager->dma_load(spack, (uint32)spackList[index],
+		smanager->dma_load(g->spack, (uint32)spackList[index],
 				   sizeof(SpanPack), SPAN_PACK_LOAD);
 		smanager->dma_wait(SPAN_PACK_LOAD);
-		spack->init((index+1)*split_screen_h);
+		g->spack->init((index+1)*split_screen_h);
 	    }
 	} else {
 	    /**
@@ -368,7 +368,7 @@
 
 	smanager->dma_wait(SPAN_PACK_LOAD);
 
-	Span *span = &spack->span[spack->info.size++];
+	Span *span = &g->spack->span[g->spack->info.size++];
 
 	span->x          = x;
 	span->y          = y;
@@ -414,7 +414,9 @@
 static int
 run(SchedTask *smanager, void *rbuf, void *wbuf)
 {
-    smanager->__debug_spe("CreateSpan\n");
+    __debug_spe("CreateSpan\n");
+    Gptr g = (Gptr)smanager->allocate(sizeof(G));
+    g->prev_index = 0;
 
     PolygonPack *pp = (PolygonPack*)smanager->get_input(0);
     PolygonPack *next_pp = 
@@ -428,19 +430,19 @@
 	= (VertexPackPtr)smanager->allocate(sizeof(VertexPack));
     
     SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1);
-    spack = (SpanPackPtr)smanager->get_input(2);
-    send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
-    prev_index = get_param(0);
+    g->spack = (SpanPackPtr)smanager->get_input(2);
+    g->send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
+    g->prev_index = (int)smanager->get_param(0);
 
     // spack と send_spack は swap しながら DMA を繰り返すので
     // 自分で allocate した send_spack を覚えてないといけない
-    SpanPackPtr free_spack = send_spack;
+    SpanPackPtr free_spack = g->send_spack;
 
-    int charge_y_top = get_param(1);
-    int charge_y_end = get_param(2);
+    int charge_y_top = smanager->get_param(1);
+    int charge_y_end = smanager->get_param(2);
 
     do {
-	smanager->__debug_spe("CreateSpan allocated 0x%x\n",(uint32)next_pp);
+	__debug_spe("CreateSpan allocated 0x%x\n",(uint32)next_pp);
 
 	if (pp->next != NULL) {
 	    smanager->dma_load(next_pp, (uint32)pp->next,
@@ -477,10 +479,10 @@
 	     * (vMax, vMid, vMid10) (vMin, vMid, vMid10) という
 	     * 二つの Triangle に分けている
 	     */
-	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
+	    half_triangle(smanager, g, spackList, charge_y_top, charge_y_end,
 			  tri_tex_info, vMin, vMid, vMid10,
 			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
-	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
+	    half_triangle(smanager, g, spackList, charge_y_top, charge_y_end,
 			  tri_tex_info, vMax, vMid, vMid10,
 			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
 	}
@@ -493,15 +495,16 @@
     } while (pp);
 
     smanager->dma_wait(SPAN_PACK_STORE);
-    smanager->dma_store(spack, (uint32)spackList[prev_index],
+    smanager->dma_store(g->spack, (uint32)spackList[g->prev_index],
 			sizeof(SpanPack), SPAN_PACK_STORE);
     smanager->dma_wait(SPAN_PACK_STORE);
-	smanager->__debug_spe("CreateSpan spack_stored 0x%x\n",(uint32)spackList[prev_index]);
+	__debug_spe("CreateSpan spack_stored 0x%x\n",(uint32)spackList[g->prev_index]);
 
     // smanager で allocate したのだから free も smanager でやるべき
     free(free_pp);
     free(free_spack);
     free(vMid10);
+    free(g);
 
     return 0;
 }
--- a/TaskManager/Test/test_render/spe/DrawBack.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawBack.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -9,7 +9,7 @@
 SchedDefineTask(DrawBack);
 
 static void
-DrawBack::linebuf_init(int *buf, int x, int rgb)
+linebuf_init(int *buf, int x, int rgb)
 {
     for (int i = 0; i < x; i++) {
 	buf[i] = rgb;
--- a/TaskManager/Test/test_render/spe/DrawSpan.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpan.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -42,6 +42,7 @@
 }
 
 
+#if 0
 static vector signed int
 getLocalPositionVec(vector signed int d, signed int offset)
 {
@@ -53,6 +54,7 @@
 {
     return getLocalPositionVec(x, split_screen_w);
 }
+#endif
 
 
 /**
@@ -297,7 +299,7 @@
         tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
         tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
-        TilePtr tile = smanager->get_segment(tex_addr,tileList);
+        TilePtr tile = smanager->get_segment(tex_addr,g->tileList);
         smanager->wait_segment(tile);
 
         updateBuffer(g, zpos, rangex, localx, localy,
@@ -384,7 +386,7 @@
             tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
             tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
-	    TilePtr tile = smanager->get_segment(tex_addr,tileList);
+	    TilePtr tile = smanager->get_segment(tex_addr,g->tileList);
 	    smanager->wait_segment(tile);
 
             updateBuffer(g, tex_z, rangex, localx, localy,
@@ -395,15 +397,16 @@
     return ret;
 }
 
+#if 1
 void
-fix_relocation((void**)addr,int count)
+fix_relocation(char **addr,int count)
 {
     unsigned int pc;
     unsigned int label;
     __asm__ __volatile__(
 "         brsl %0,____LLLL\n"
 "____LLLL:"
-"         lia  %1,____LLLL"
+"         ila  %1,____LLLL"
         : "=r" (pc), "=r" (label));
     int offset = pc-label;
     int i;
@@ -411,6 +414,7 @@
 	addr[i] += offset;
     }
 }
+#endif
 
 static int
 run(SchedTask *smanager, void *rbuf, void *wbuf)
@@ -426,10 +430,10 @@
     Span nop_span;
     nop_span.length_x = 1;
 
-    int (*drawFunc1[2])(SchedTask *, Gptr, SpanPtr, int, int, int) = {
-        &drawDot1, &drawLine1
-    };
-    fix_relocation((void**)drawFunc1,2);
+//    int (*drawFunc1[2])(SchedTask *, Gptr, SpanPtr, int, int, int) = {
+//        &drawDot1, &drawLine1
+//    };
+//    fix_relocation((void**)drawFunc1,2);
 
     uint32 display   = smanager->get_param(0);
     int screen_width = smanager->get_param(1);
@@ -442,11 +446,11 @@
     // y の範囲
     int rangey = smanager->get_param(4);
 
-    tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
+    g->tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
 
-    g->zRow = zRow_init(rangex, rangey);
+    g->zRow = zRow_init(smanager, rangex, rangey);
     //linebuf = linebuf_init(rangex, rangey, 0x00ffffff);
-    g->linebuf = linebuf_init(rangex, rangey, 0);
+    g->linebuf = linebuf_init(smanager, rangex, rangey, 0);
 
     g->doneWrite = 0;
 
@@ -479,10 +483,15 @@
             /**
              * span の長さによって、drawLine か drawDot を選択している
              */
-            next_span_x
-                = (*drawFunc1[(span->length_x != 1)])(
-		    smanager, g,
-                    span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]);
+	    if (span->length_x != 1) {
+		next_span_x
+		    = drawLine1( smanager, g,
+			span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]);
+	    } else {
+		next_span_x
+		    = drawDot1( smanager, g,
+			span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]);
+	    }
             next_span = span;
 
             resume_span = next_span;
--- a/TaskManager/Test/test_render/spe/DrawSpan.h	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpan.h	Fri Oct 02 23:20:25 2009 +0900
@@ -5,7 +5,7 @@
 #include "Tapestry.h"
 #include "SpanPack.h"
 
-struct g {
+typedef struct g {
     int *linebuf;
     float *zRow;
     TileListPtr tileList;
@@ -16,7 +16,7 @@
 static int run(SchedTask *smanager, void *rbuf, void *wbuf);
 
 static    int* linebuf_init(SchedTask *s, int width, int height, int rgb);
-static    float* zRow_init(int width, int height);
+static    float* zRow_init(SchedTask *s, int width, int height);
 static    uint32 get_rgb(int tx, int ty, TilePtr tile);
 static    memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top);
 static    int getTexBlock(int tx, int ty, int twidth);
@@ -29,11 +29,10 @@
 static    void reboot(SpanPackPtr spack, int cur_span_x);
 #endif
 
-static    int drawDot1(SpanPtr span, int startx, int endx, int wait_tag);
+static    int drawDot1(SchedTask *s, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
 //static    void drawDot2(SpanPtr span, int startx, int endx, int js, int wait_tag);
-static    int drawLine1(SpanPtr span, int startx, int endx, int wait_tag);
+static    int drawLine1(SchedTask *s, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
 //static    void drawLine2(SpanPtr span, int startx, int endx, int js, int wait_tag);
-};
 
 typedef struct {
     uint32 display;
--- a/TaskManager/Test/test_render/spe/Load_Texture.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/Load_Texture.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -20,7 +20,7 @@
 static int
 run(SchedTask *smanager, void *rbuf , void *wbuf)
 {
-    smanager->__debug_spe("LoadTexture\n");
+    __debug_spe("LoadTexture\n");
 
     MemList *ml = smanager->createMemList(sizeof(uint32) * TEXTURE_BLOCK_SIZE, MAX_TILE);
     smanager->global_set(GLOBAL_TILE_LIST, (void *)ml);
--- a/TaskManager/Test/test_render/spe/TileHash.h	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/TileHash.h	Fri Oct 02 23:20:25 2009 +0900
@@ -24,9 +24,9 @@
 
 typedef TileHash* TileHashPtr;
 
-#endif
 
 const int hashSize = 263;
 const int tableSize = sizeof(TilePtr)*hashSize;
+#endif
 
 #endif 
--- a/TaskManager/Test/test_render/spe/spe-main.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/spe-main.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -4,6 +4,7 @@
 SchedExternTask(LoadTexture);
 SchedExternTask(SetTexture);
 SchedExternTask(DrawSpan);
+SchedExternTask(DrawSpanEnd);
 SchedExternTask(DrawSpanRenew);
 SchedExternTask(DrawBack);
 
--- a/TaskManager/Test/test_render/task/DrawSpan.h	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpan.h	Fri Oct 02 23:20:25 2009 +0900
@@ -4,19 +4,14 @@
 #include "SchedTask.h"
 #include "Tapestry.h"
 #include "SpanPack.h"
-#if !USE_MEMHASH
-#include "TileHash.h"
-#endif
 
-static typedef struct {
+typedef struct {
     int *linebuf;
     float *zRow;
     TileListPtr tileList;
     int doneWrite;
 } G, *Gptr; 
 
-
-
 static    int* linebuf_init(SchedTask *smanager, int width, int height, int rgb);
 static    float* zRow_init(SchedTask *smanager, int width, int height);
 // static    TilePtr set_rgb(memaddr addr, int wait_tag);
--- a/TaskManager/Test/test_render/task/InitKey.cc	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/task/InitKey.cc	Fri Oct 02 23:20:25 2009 +0900
@@ -11,7 +11,7 @@
 run(SchedTask *smanager, void *rbuf , void *wbuf)
 {
     
-    void *key = smanager->global_alloc(KEY_STATUS, sizeof(key_stat));
+    smanager->global_alloc(KEY_STATUS, sizeof(key_stat));
     
     return 0;
 }
--- a/TaskManager/Test/test_render/task/UpdateKey.h	Fri Oct 02 17:27:45 2009 +0900
+++ b/TaskManager/Test/test_render/task/UpdateKey.h	Fri Oct 02 23:20:25 2009 +0900
@@ -4,6 +4,6 @@
 #include "SchedTask.h"
 #include "SceneGraphRoot.h"
 
-static    void setKeyStat();
+// static    void setKeyStat();
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/cell_fixpic.pl	Fri Oct 02 23:20:25 2009 +0900
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+#
+# Author: Shinji KONO <kono@ie.u-ryukyu.ac.jp>
+# v.0.1   Sat May 30 04:41:18 JST 2009
+#
+# fix spu-gcc assembler soruce for DMA loadable PIC code
+# 
+#$(OVLOBJS): %.o : %.cc
+#        $(SPECC) $(SPECFLAGS) -c $< -S -o $(<:.cc=.s) 
+#        perl spe/fixpic.pl $(<:.cc=.s)  | $(SPECC) $(SPECFLAGS) -x assembler -c  -o $@ -
+
+use strict;
+
+my %global;
+my %local;
+my %weak;
+my @line;
+
+# Basically SPU code is PIC. But linked library is in the fixed
+# address space.
+# 
+# rewrite relative to absolute for global branch address
+# 
+# Target instruction
+#   hbrr -> hbra
+#   br   -> bra
+#   brsl -> brasl
+#   brnz cannot be global
+
+#   lqr -> li  (for global)
+#   ila    global -> a $0,.LC0-.,$1
+
+while(<>) {
+    push(@line,$_);
+    if(/\.global\s+([^\s]+)/) {
+        $global{$1} = 1;
+    }
+    if(/\.weak\s+([^\s]+)/) {
+        $weak{$1} = 1;
+	next;
+    }
+    if(/^([^\s]+):/) {
+        $local{$1} = 1;
+    }
+}
+	
+for(@line) {
+    if (! /^#/) {
+       next if (/\.section\s+\.rodata/);
+       if(/\s(br)\s+([^\s]+)/||/\s(brsl|hbrr)\s+[^\s]+,\s*([^\s]+)/) {
+          my $name = $2;
+          if (! defined $local{$name} || defined $weak{$name} ) {
+		s/hbrr/hbra/ ||
+		s/brsl/brasl/ ||
+		s/br/bra/ ;
+          }
+#       } elsif(/\s(lqr)\s+(\$\d+),([^\s]+)/) {
+#          my $name = $2;
+#          if (! defined $local{$name} || defined $weak{$name} ) {
+#	    s/lqr/lqd/;
+#          }
+#       } elsif(/\s(ila)\s+(\$\d+),([^\s]+)/) {
+#          my $name = $3;
+#          if (! defined $local{$name} || defined $weak{$name} ) {
+#	    $_ = $_;
+#	  } else {
+#	    $_ = "\tai\t$2,\$0,$3-.\n";
+#          }
+       }
+    }
+    print ;
+}
+
+# end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/cell_ovly_table.pl	Fri Oct 02 23:20:25 2009 +0900
@@ -0,0 +1,142 @@
+#!/usr/bin/perl
+# //    from readelf -all spu/spe_main
+# //   [12] .data             PROGBITS        00000f20 0011a0 000384 00  WA  0   0 16
+# //      109: 00001260    64 OBJECT  GLOBAL DEFAULT   12 _ovly_table
+
+use strict;
+
+package ReadElf;
+
+sub new { bless {} }
+
+sub readelf {
+    my ($self,$elf)= @_;
+
+    my $debug = 0;
+    my $section_header;
+    my $symbol_table;
+    my %section;
+    my %symbol;
+
+    $self->{section} = \%section;
+    $self->{symbol} = \%symbol;
+
+    open(ELF, "readelf -all $elf |");
+    while(<ELF>) {
+	    if(/^Section Headers:/) { $section_header = 1 ; $symbol_table = 0; }
+	    elsif(/^Symbol table/) { $section_header = 0 ; $symbol_table = 1; }
+	    elsif(/^[A-Z]/) { $section_header = 0 ; $symbol_table = 0; }
+	    if ($section_header) {
+		    if (/\[\s*(\d+)\]\s+(\.\w+)\s+(\w+)\s+([\da-f]+)\s+([\da-f]+)\s+([\da-f]+)\s/) {
+		    $section{$2} = {nr=>$1,name=>$2,type=>$3,addr=>$4,offset=>$5,size=>$6};
+		    }
+	    }
+	    if ($symbol_table) {
+		    if(/^\s+(\d+):\s([\da-f]+)\s+([\da-f]+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+([\w\.\_]+)/) {
+		    $symbol{$8} = {num=>$1,value=>$2,size=>$3,type=>$4,bind=>$5,vis=>$6,ndx=>$7,name=>$8};
+		    }
+	    }
+
+    }
+
+
+    if ($debug) {
+	    print "seciton:\n";
+	    foreach my $key ( keys %section) {
+		foreach my $i ( keys %{$section{$key}}) {
+		   print "$i=>$section{$key}->{$i} ";
+		}
+		print "\n";
+	    }
+
+	    print "symbol:\n";
+	    foreach my $key ( keys %symbol) {
+		foreach my $i ( keys %{$symbol{$key}}) {
+		   print "$i=>$symbol{$key}->{$i} ";
+		}
+		print "\n";
+	    }
+    }
+    $self;
+}
+
+sub symbol {
+    my ($self, $name) = @_;
+    $self->{symbol}->{$name};
+}
+
+sub segment {
+    my ($self, $name) = @_;
+    $self->{section}->{$name};
+}
+
+
+package Main;
+
+my $elf = ReadElf->new;
+
+my $file = shift;
+if (! -e $file) {
+    open(H,">runTask_offset.h");
+    for my $header (@ARGV) {
+	open(HD,"<$header") or die("Can't open $header");
+	my $class = $header;
+	my $entry = 0;
+	$class =~ s/\.cc//;
+	while(<HD>) {
+	    if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
+		print H "#define runTask_${class}_offset 0x$entry\n";
+		last;
+	    }
+	}
+    }
+    open(H,">ld.script.ed");
+    exit(0);
+}
+
+$elf->readelf($file) ;
+
+my $base = $elf->segment(".segment0")->{addr};
+
+my @ldfiles;
+my $ldsegment = "";
+
+open(H,">runTask_offset.h");
+print H "#ifndef RUNTASK_OFFSET_H\n";
+print H "#define RUNTASK_OFFSET_H\n";
+for my $header (@ARGV) {
+    open(HD,"<$header") or die("Can't open $header");
+    while(<HD>) {
+	if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
+	    my $class = $1;
+	    my $segment = $2;
+	    my $entry = $elf->symbol("runTask_$class")->{value};
+	    print H "#define runTask_${class}_offset (0x$entry-0x$base)\n";
+            my $ofile = $header;
+	    $ofile =~ s/\.cc/.o/;
+            push(@ldfiles,$ofile);
+	    $ldsegment .= "   .segment$segment { $ofile(.text) }\n";
+	    last;
+	}
+    }
+}
+print H "#endif\n";
+
+my $ld_script = <<"EOFEOF";
+/ \\.text /
+/\\\*\(\\.text/
+s/\\\*\(\\.text/\*\( EXCLUDE_FILE(@ldfiles) .text/
+/} =0/
+a
+  OVERLAY :
+  {
+$ldsegment
+  }
+.
+w
+EOFEOF
+
+open(H,">ld.script.ed");
+print H $ld_script;
+
+# end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/ld.script.orig	Fri Oct 02 23:20:25 2009 +0900
@@ -0,0 +1,193 @@
+/* Default linker script, for normal executables */
+OUTPUT_FORMAT("elf32-spu", "elf32-spu",
+	      "elf32-spu")
+OUTPUT_ARCH(spu)
+ENTRY(_start)
+SEARCH_DIR("/usr/spu/lib");
+SECTIONS
+{
+  /* Read-only sections, merged into text segment: */
+  PROVIDE (__executable_start = 0); . = 0;
+  .interrupt : { KEEP(*(.interrupt)) }
+  .interp         : { *(.interp) }
+  .hash           : { *(.hash) }
+  .gnu.hash       : { *(.gnu.hash) }
+  .dynsym         : { *(.dynsym) }
+  .dynstr         : { *(.dynstr) }
+  .gnu.version    : { *(.gnu.version) }
+  .gnu.version_d  : { *(.gnu.version_d) }
+  .gnu.version_r  : { *(.gnu.version_r) }
+  .rel.init       : { *(.rel.init) }
+  .rela.init      : { *(.rela.init) }
+  .rel.text       : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) }
+  .rela.text      : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) }
+  .rel.fini       : { *(.rel.fini) }
+  .rela.fini      : { *(.rela.fini) }
+  .rel.rodata     : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) }
+  .rela.rodata    : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) }
+  .rel.data.rel.ro   : { *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) }
+  .rela.data.rel.ro   : { *(.rela.data.rel.ro* .rela.gnu.linkonce.d.rel.ro.*) }
+  .rel.data       : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
+  .rela.data      : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) }
+  .rel.tdata	  : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) }
+  .rela.tdata	  : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) }
+  .rel.tbss	  : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) }
+  .rela.tbss	  : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) }
+  .rel.ctors      : { *(.rel.ctors) }
+  .rela.ctors     : { *(.rela.ctors) }
+  .rel.dtors      : { *(.rel.dtors) }
+  .rela.dtors     : { *(.rela.dtors) }
+  .rel.got        : { *(.rel.got) }
+  .rela.got       : { *(.rela.got) }
+  .rel.bss        : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) }
+  .rela.bss       : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) }
+  .rel.plt        : { *(.rel.plt) }
+  .rela.plt       : { *(.rela.plt) }
+  .init           :
+  {
+    KEEP (*(.init))
+  } =0
+  .plt            : { *(.plt) }
+  .text           :
+  {
+    *(.text .stub .text.* .gnu.linkonce.t.*)
+    KEEP (*(.text.*personality*))
+    /* .gnu.warning sections are handled specially by elf32.em.  */
+    *(.gnu.warning)
+  } =0
+  .fini           :
+  {
+    KEEP (*(.fini))
+  } =0
+  PROVIDE (__etext = .);
+  PROVIDE (_etext = .);
+  PROVIDE (etext = .);
+  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
+  .rodata1        : { *(.rodata1) }
+  .eh_frame_hdr : { *(.eh_frame_hdr) }
+  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
+  /* Adjust the address for the data segment.  We want to adjust up to
+     the same address within the page on the next page up.  */
+  . = ALIGN(0x80);
+  /* Exception handling  */
+  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+  /* Thread Local Storage sections  */
+  .tdata	  : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
+  .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
+  .preinit_array     :
+  {
+    PROVIDE_HIDDEN (__preinit_array_start = .);
+    KEEP (*(.preinit_array))
+    PROVIDE_HIDDEN (__preinit_array_end = .);
+  }
+  .init_array     :
+  {
+     PROVIDE_HIDDEN (__init_array_start = .);
+     KEEP (*(SORT(.init_array.*)))
+     KEEP (*(.init_array))
+     PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array     :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(.fini_array))
+    KEEP (*(SORT(.fini_array.*)))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
+  .ctors          :
+  {
+    /* gcc uses crtbegin.o to find the start of
+       the constructors, so we make sure it is
+       first.  Because this is a wildcard, it
+       doesn't matter if the user does not
+       actually link against crtbegin.o; the
+       linker won't look for a file to match a
+       wildcard.  The wildcard also means that it
+       doesn't matter which directory crtbegin.o
+       is in.  */
+    KEEP (*crtbegin.o(.ctors))
+    KEEP (*crtbegin?.o(.ctors))
+    /* We don't want to include the .ctor section from
+       the crtend.o file until after the sorted ctors.
+       The .ctor section from the crtend file contains the
+       end of ctors marker and it must be last */
+    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
+    KEEP (*(SORT(.ctors.*)))
+    KEEP (*(.ctors))
+  }
+  .dtors          :
+  {
+    KEEP (*crtbegin.o(.dtors))
+    KEEP (*crtbegin?.o(.dtors))
+    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
+    KEEP (*(SORT(.dtors.*)))
+    KEEP (*(.dtors))
+  }
+  .jcr            : { KEEP (*(.jcr)) }
+  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
+  .dynamic        : { *(.dynamic) }
+  .got            : { *(.got.plt) *(.got) }
+  .data           :
+  {
+    *(.data .data.* .gnu.linkonce.d.*)
+    KEEP (*(.gnu.linkonce.d.*personality*))
+    SORT(CONSTRUCTORS)
+  }
+  .data1          : { *(.data1) }
+  _edata = .; PROVIDE (edata = .);
+  __bss_start = .;
+  .bss            :
+  {
+   *(.dynbss)
+   *(.bss .bss.* .gnu.linkonce.b.*)
+   *(COMMON)
+   /* Align here to ensure that the .bss section occupies space up to
+      _end.  Align after .bss to ensure correct alignment even if the
+      .bss section disappears because there are no input sections.
+      FIXME: Why do we need it? When there is no .bss section, we don't
+      pad the .data section.  */
+   . = ALIGN(. != 0 ? 16 : 1);
+  }
+  .toe ALIGN(128) : { *(.toe) } = 0
+  . = ALIGN(16);
+  . = ALIGN(16);
+  PROVIDE (__stack = 0x3fff0);
+  _end = .; PROVIDE (end = .);
+  /* Stabs debugging sections.  */
+  .stab          0 : { *(.stab) }
+  .stabstr       0 : { *(.stabstr) }
+  .stab.excl     0 : { *(.stab.excl) }
+  .stab.exclstr  0 : { *(.stab.exclstr) }
+  .stab.index    0 : { *(.stab.index) }
+  .stab.indexstr 0 : { *(.stab.indexstr) }
+  .comment       0 : { *(.comment) }
+  /* DWARF debug sections.
+     Symbols in the DWARF debugging sections are relative to the beginning
+     of the section so we begin them at 0.  */
+  /* DWARF 1 */
+  .debug          0 : { *(.debug) }
+  .line           0 : { *(.line) }
+  /* GNU DWARF 1 extensions */
+  .debug_srcinfo  0 : { *(.debug_srcinfo) }
+  .debug_sfnames  0 : { *(.debug_sfnames) }
+  /* DWARF 1.1 and DWARF 2 */
+  .debug_aranges  0 : { *(.debug_aranges) }
+  .debug_pubnames 0 : { *(.debug_pubnames) }
+  /* DWARF 2 */
+  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
+  .debug_abbrev   0 : { *(.debug_abbrev) }
+  .debug_line     0 : { *(.debug_line) }
+  .debug_frame    0 : { *(.debug_frame) }
+  .debug_str      0 : { *(.debug_str) }
+  .debug_loc      0 : { *(.debug_loc) }
+  .debug_macinfo  0 : { *(.debug_macinfo) }
+  /* SGI/MIPS DWARF 2 extensions */
+  .debug_weaknames 0 : { *(.debug_weaknames) }
+  .debug_funcnames 0 : { *(.debug_funcnames) }
+  .debug_typenames 0 : { *(.debug_typenames) }
+  .debug_varnames  0 : { *(.debug_varnames) }
+  .note.spu_name 0 : { KEEP(*(.note.spu_name)) }
+  /DISCARD/ : { *(.note.GNU-stack) }
+}