changeset 425:799071db126e

add code load API
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 24 Sep 2009 17:18:53 +0900
parents 960471b7ee54
children 58fee2fce1bd e82be8759036
files TaskManager/kernel/schedule/Scheduler.cc TaskManager/kernel/schedule/Scheduler.h example/get_segment/ppe/Hello.cc example/get_segment/ppe/Hello.h example/get_segment/spe/Hello.cc example/get_segment/spe/Hello.h example/get_segment/spe/LoadEntry.cc example/get_segment/spe/LoadEntry.h example/get_segment/spe/fixpic.pl example/get_segment/spe/ld.script.ed example/get_segment/spe/ld.script.orig
diffstat 11 files changed, 285 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/kernel/schedule/Scheduler.cc	Thu Sep 24 16:06:01 2009 +0900
+++ b/TaskManager/kernel/schedule/Scheduler.cc	Thu Sep 24 17:18:53 2009 +0900
@@ -328,6 +328,11 @@
 /** 
  *  Task load API
  */
+void
+Scheduler::allocate_code_segment(int count, int size)
+{
+    code_segment_pool = createMemList(count, size);
+}
 
 static void
 load_task(Scheduler *m, int task_id)
--- a/TaskManager/kernel/schedule/Scheduler.h	Thu Sep 24 16:06:01 2009 +0900
+++ b/TaskManager/kernel/schedule/Scheduler.h	Thu Sep 24 17:18:53 2009 +0900
@@ -152,6 +152,7 @@
     void *mainMem_get(int id);
 
     MemorySegment * get_segment(memaddr addr, MemList *m);
+    void allocate_code_segment(int count, int size);
     MemorySegment * Scheduler::load_task(memaddr task);
 
     virtual uint32 get_tag();
--- a/example/get_segment/ppe/Hello.cc	Thu Sep 24 16:06:01 2009 +0900
+++ b/example/get_segment/ppe/Hello.cc	Thu Sep 24 17:18:53 2009 +0900
@@ -9,7 +9,7 @@
 #define SIZE (4096*sizeof(int))
 
 int
-Hello::run(void *rbuf, void *wbuf)
+Hello::run(SchedTask *smanager, void *rbuf, void *wbuf)
 {
     int task_id = get_param(0);
     int *ptr = 0;
--- a/example/get_segment/ppe/Hello.h	Thu Sep 24 16:06:01 2009 +0900
+++ b/example/get_segment/ppe/Hello.h	Thu Sep 24 17:18:53 2009 +0900
@@ -9,7 +9,7 @@
 public:
     SchedConstructor(Hello);
     
-    int run(void *r, void *w);
+    int run(SchedTask *smanager, void *r, void *w);
 };
 
 #endif
--- a/example/get_segment/spe/Hello.cc	Thu Sep 24 16:06:01 2009 +0900
+++ b/example/get_segment/spe/Hello.cc	Thu Sep 24 17:18:53 2009 +0900
@@ -9,7 +9,7 @@
 #define SIZE (4096*sizeof(int))
 
 int
-Hello::run(void *rbuf, void *wbuf)
+Hello::run(ShcedTask *smanager, void *rbuf, void *wbuf)
 {
     int task_id = get_param(0);
 
--- a/example/get_segment/spe/Hello.h	Thu Sep 24 16:06:01 2009 +0900
+++ b/example/get_segment/spe/Hello.h	Thu Sep 24 17:18:53 2009 +0900
@@ -9,7 +9,7 @@
 public:
     SchedConstructor(Hello);
     
-    int run(void *r, void *w);
+    int run(SchedTask *smanager, void *r, void *w);
 };
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/get_segment/spe/LoadEntry.cc	Thu Sep 24 17:18:53 2009 +0900
@@ -0,0 +1,4 @@
+
+void spe_load_entry() 
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/get_segment/spe/LoadEntry.h	Thu Sep 24 17:18:53 2009 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_LOAD_ENTRY
+#define INCLUDED_LOAD_ENTRY
+
+extern   void spe_load_entry();
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/get_segment/spe/fixpic.pl	Thu Sep 24 17:18:53 2009 +0900
@@ -0,0 +1,58 @@
+#!/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
+
+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 (! /^#/) {
+       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/ ;
+          }
+       }
+    }
+    print ;
+}
+
+# end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/get_segment/spe/ld.script.ed	Thu Sep 24 17:18:53 2009 +0900
@@ -0,0 +1,14 @@
+/ \.text /
+/\*(\.text/
+s/\*(\.text/*( EXCLUDE_FILE(spe\/olay\/*.o) .text/
+/} =0/
+a
+  OVERLAY :
+  {
+    .segment1 { spe/olay/add.o(.text) }
+    .segment2 { spe/olay/mul.o(.text) }
+    .segment3 { spe/olay/div.o(.text) }
+    .segment4 { spe/olay/sub.o(.text) }
+  }
+.
+w
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/get_segment/spe/ld.script.orig	Thu Sep 24 17:18:53 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) }
+}