changeset 918:49b3c753e209

add loadelf in tmp/old.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 25 Jul 2010 10:46:45 +0900
parents 7f55c8727caa
children dd060540f50e
files Renderer/Engine/spe/viewer_types.cc Renderer/Engine/viewer.cc Renderer/Engine/viewer_types.cc Renderer/Engine/viewer_types.h TaskManager/ChangeLog TaskManager/kernel/schedule/SchedTaskBase.h old/tmp/loadelf.cc
diffstat 7 files changed, 184 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/spe/viewer_types.cc	Sat Jul 24 18:45:09 2010 +0900
+++ b/Renderer/Engine/spe/viewer_types.cc	Sun Jul 25 10:46:45 2010 +0900
@@ -1,30 +0,0 @@
-#include "viewer_types.h"
-
-int
-getLocalPosition(int d, int offset)
-{
-    return d & (offset-1);
-}
-
-/**
- * ワールド座標における x の値を
- * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する
- * (ex. split_screen_w が 256 の場合、
- *      x =   1 -> 1
- *      x = 256 -> 256
- *      x = 257 -> 1
- */
-int
-getLocalX(int x)
-{
-    return getLocalPosition(x, split_screen_w);
-}
-
-/**
- * getLocalX に同じ
- */
-int
-getLocalY(int y)
-{
-    return getLocalPosition(y, split_screen_h);
-}
--- a/Renderer/Engine/viewer.cc	Sat Jul 24 18:45:09 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Sun Jul 25 10:46:45 2010 +0900
@@ -177,7 +177,7 @@
 
     spackList_length = (this->height + split_screen_h - 1) / split_screen_h;
     spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length);
-    printf("spackList %0x height %d\n",(unsigned long)spackList, this->height);
+    // printf("spackList %0lx height %d\n",(unsigned long)spackList, this->height);
 
     /**
      * SPU に送る address list は 16 バイト倍数でないといけない。
--- a/Renderer/Engine/viewer_types.cc	Sat Jul 24 18:45:09 2010 +0900
+++ b/Renderer/Engine/viewer_types.cc	Sun Jul 25 10:46:45 2010 +0900
@@ -1,38 +0,0 @@
-#include "viewer_types.h"
-
-static int
-getLocalPosition(int d, int offset)
-{
-    /**
-     * offset が 2 の冪乗の時だけ使える。
-     * 現在は offset は 2 の冪乗のみなので
-     * これで問題ないけどどうなの?
-     */
-    return d & (offset-1);
-
-    // offset が 2 の冪乗以外はこれにしないとだめ
-    //return d % offset;
-}
-
-/**
- * ワールド座標における x の値を
- * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する
- * (ex. split_screen_w が 256 の場合、
- *      x =   1 -> 1
- *      x = 256 -> 256
- *      x = 257 -> 1
- */
-int
-getLocalX(int x)
-{
-    return getLocalPosition(x, split_screen_w);
-}
-
-/**
- * getLocalX に同じ
- */
-int
-getLocalY(int y)
-{
-    return getLocalPosition(y, split_screen_h);
-}
--- a/Renderer/Engine/viewer_types.h	Sat Jul 24 18:45:09 2010 +0900
+++ b/Renderer/Engine/viewer_types.h	Sun Jul 25 10:46:45 2010 +0900
@@ -27,7 +27,41 @@
 const int alphaMask = 0xff000000;
 #endif
 
-extern int getLocalX(int x);
-extern int getLocalY(int y);
+static inline int
+getLocalPosition(int d, int offset)
+{
+    /**
+     * offset が 2 の冪乗の時だけ使える。
+     * 現在は offset は 2 の冪乗のみなので
+     * これで問題ないけどどうなの?
+     */
+    return d & (offset-1);
+
+    // offset が 2 の冪乗以外はこれにしないとだめ
+    //return d % offset;
+}
+
+/**
+ * ワールド座標における x の値を
+ * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する
+ * (ex. split_screen_w が 256 の場合、
+ *      x =   1 -> 1
+ *      x = 256 -> 256
+ *      x = 257 -> 1
+ */
+static inline int
+getLocalX(int x)
+{
+    return getLocalPosition(x, split_screen_w);
+}
+
+/**
+ * getLocalX に同じ
+ */
+static inline int
+getLocalY(int y)
+{
+    return getLocalPosition(y, split_screen_h);
+}
 
 #endif
--- a/TaskManager/ChangeLog	Sat Jul 24 18:45:09 2010 +0900
+++ b/TaskManager/ChangeLog	Sun Jul 25 10:46:45 2010 +0900
@@ -1,3 +1,10 @@
+2010-7-24 Shinji KONO <kono@ie.u-ryukyu.ac.jp>
+
+   やっぱり、load module のlinkの解決はやらないといけないので、
+   無理に、SchedTaskのAPI全部を virtual にする必要はないらしい。
+      spu-gcc  spe/ChainCal.o -Wl,-R,spe-main -o tmp.o
+   と言う形で、link してやれば良い。(ただし、必要なものが参照されている場合)
+
 2010-7-16 Shinji KONO <kono@ie.u-ryukyu.ac.jp>
 
    SimpleTask のsizeを16の倍数に。そうしないと、Taskのaligmentが16に
--- a/TaskManager/kernel/schedule/SchedTaskBase.h	Sat Jul 24 18:45:09 2010 +0900
+++ b/TaskManager/kernel/schedule/SchedTaskBase.h	Sun Jul 25 10:46:45 2010 +0900
@@ -46,7 +46,7 @@
     virtual void* global_get(int id) {return 0;}
     virtual void global_set(int id, void *addr) {}
     virtual void global_free(int id) {}
-    // virtual MemList* createMemList(int size, int count);
+    virtual MemList* createMemList(int size, int count) {return 0;}
 
     virtual void mainMem_alloc(int id, int size) {}
     virtual void mainMem_wait() {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/old/tmp/loadelf.cc	Sun Jul 25 10:46:45 2010 +0900
@@ -0,0 +1,139 @@
+/*
+      load spu elf file into memory with proper alignment.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <elf.h>
+#include "types.h"
+#include <alloca.h>
+#include <malloc.h>
+#include <strings.h>
+
+
+static int
+read_file(int fd, unsigned char *buf, int size)
+{
+    int i = 0;
+    do {
+        int j = read(fd,buf+i,size-i);
+        if (j<0) return j;
+        i+=j;
+    } while( i< size ) ;
+    return i;
+}
+
+static memaddr
+load_elf1(int fd)
+{
+    Elf32_Ehdr header;
+
+    if (read_file(fd, (unsigned char *)&header, sizeof(header))<0) return 0;
+
+    if (header.e_ident[EI_CLASS]==ELFCLASS32) printf("32bit\n");
+    printf("entry %0lx\n", (unsigned long)header.e_entry);
+    printf("program header %0lx ", (unsigned long)header.e_phoff);
+    printf("length %0lx\n", (unsigned long)header.e_phentsize);
+    printf("section header %0lx ", (unsigned long)header.e_shoff);
+    printf("length %0lx\n", (unsigned long)header.e_shentsize);
+    printf("e_shstrndx %ld\n", (unsigned long)header.e_shstrndx);
+
+    int num = header.e_shnum;
+    Elf32_Shdr section[num] ;
+
+    lseek(fd,header.e_shoff + (sizeof(Elf32_Shdr )*(header.e_shstrndx)),SEEK_SET);
+    if (read_file(fd, (unsigned char *)&section[0], sizeof(Elf32_Shdr))<0) return 0;
+    unsigned char *text = (unsigned char *)alloca(section[0].sh_size);
+    lseek(fd,section[0].sh_offset,SEEK_SET);
+    if (read_file(fd, text, section[0].sh_size)<0) return 0;
+    // for(int i=0;i<section.sh_size;i++) putchar(text[i]);
+
+    lseek(fd,header.e_shoff,SEEK_SET);
+    if (read_file(fd, (unsigned char *)&section[0], sizeof(Elf32_Shdr)*num)<0) return 0;
+    long min = 0x7fffffff;
+    long max = 0;
+
+    for(int i=0; i< num; i++) {
+        if (section[i].sh_flags & SHF_ALLOC) {
+             int adr = section[i].sh_addr;
+             if (min>adr) min = adr;
+             adr += section[i].sh_size ;
+             if (max<adr) max = adr;
+        }
+        printf("section %d ",i) ;
+        printf("  sh_name %s\n",text+section[i].sh_name) ;
+        printf("  sh_name %lx ",(unsigned long)section[i].sh_name) ;
+        printf("  sh_type %lx ",(unsigned long)section[i].sh_type) ;
+        printf("  sh_addr %lx ",(unsigned long)section[i].sh_addr) ;
+        printf("  sh_offset %lx ",(unsigned long)section[i].sh_offset) ;
+        printf("  sh_size %lx\n",(unsigned long)section[i].sh_size) ;
+    }
+    printf("\nmax %lx min %lx\n",max,min) ;
+
+#if 0
+    unsigned  char  *code = (unsigned char*)malloc(max-min);
+#else
+    unsigned  char  *code ;
+    posix_memalign((void**)&code,16,max-min);
+#endif
+
+    bzero(code,max-min);
+    printf("bzero %lx\n", (unsigned long)code) ;
+
+    long poffset = -1;    
+    unsigned char *addr = code;
+    unsigned long size  = 0;    
+    for(int i=0; i< num; i++) {
+        if ((section[i].sh_flags & SHF_ALLOC) && (section[i].sh_type!=SHT_NOBITS)) {
+	    printf("loading %lx %lx\n", 
+                   (unsigned long)(section[i].sh_addr), 
+                   (unsigned long)section[i].sh_size) ;
+            long offset = (unsigned long)(section[i].sh_addr-min)-
+                  (unsigned long)section[i].sh_offset;
+	    if (offset!=poffset) {
+                if (addr && size) {
+		    printf("   reading %lx %lx\n", 
+			   (unsigned long)addr, 
+			   (unsigned long)size) ;
+		    if (read_file(fd, addr, size)<0) return 0;
+                }
+                 // there is a hole
+                printf("   hole %0x = %0x - %0x\n", offset-poffset, offset, poffset);
+                poffset = offset;
+		lseek(fd,section[i].sh_offset,SEEK_SET);
+	        addr = code + (section[i].sh_addr-min);
+            } 
+	    unsigned char *last = 
+		 code + (section[i].sh_addr-min+section[i].sh_size);
+	    size = last - addr;
+        }
+    }
+    printf("   last reading %lx %lx\n", 
+	   (unsigned long)addr, 
+	   (unsigned long)size) ;
+    if (read_file(fd, addr, size)<0) return 0;
+    return (memaddr)code;
+}
+
+static memaddr
+load_elf(const char *name)
+{
+    Elf32_Ehdr header;
+
+    int fd = open(name,O_RDONLY);
+    if (fd<0) return 0;
+    memaddr addr = load_elf1(fd);
+    close(fd);
+    return addr;
+}
+
+int
+main(int ac, char *av[])
+{
+    load_elf(av[1]);
+    return 0;
+}
+
+