Subversion Repositories ps3ware

Compare Revisions

Ignore whitespace Rev 212 → Rev 213

/trunk/spe-loader/Makefile
New file
0,0 → 1,18
PPU_CC=gcc
PPU_INC=
PPU_LD=-lpthread -lspe2
PPU_EXEC=loader
 
SPU_CC=spu-elf-gcc
SPU_EXEC1=spe_loader
SPU_EXEC2=spe_loadme
 
all: ppu spu
 
ppu:
${CC} ${PPU_INC} ${PPU_EXEC}.c -o ${PPU_EXEC} ${PPU_LD}
spu:
${SPU_CC} ${SPU_EXEC1}.c -o ${SPU_EXEC1}
${SPU_CC} -c ${SPU_EXEC2}.c
${SPU_CC} ${SPU_EXEC2}.o -o ${SPU_EXEC2}
/trunk/spe-loader/spe_loader.c
New file
0,0 → 1,66
/**
* SPE Loader
* --------------------------------
* Licensed under the BSDv2
* spe_loader.c - source code for spu function in the loader example
* Copyright (c) 2007, Kristian Jerpetjøn <kristian.jerpetjoen@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "spe_loader.h"
 
 
int main(unsigned long long speid, unsigned long long argp, unsigned long long envp)
{
arg_t *args = memalign(128, envp);
dmaGetnWait(args,argp,(envp +15)&~15,1);
///fetch the executable code as data
char *data=(char*)memalign(128,(args->fsize +15)&~15);
dmaGetnWait(data,argp,(args->fsize +15)&~15,1);
///setting up some functions to share
functions_t *functions;
functions=memalign(128,sizeof(functions_t));
functions->dmaGetnWait=dmaGetnWait;
functions->printint=printint;
int (*runme)(functions_t *func,arg_t *arg);
runme=data;
printf("attemting to run spe from spe\n ");
int result=runme(functions,args);
printf("spe from spe completed with results %d " , result );
while (spu_stat_out_mbox() == 0);
spu_write_out_mbox(result);
return result;
}
/trunk/spe-loader/spe_loader.h
New file
0,0 → 1,77
/**
* SPE Loader
* --------------------------------
* Licensed under the BSDv2
* spe_header.h - header for shared data for main function in the loader example
* Copyright (c) 2007, Kristian Jerpetjøn <kristian.jerpetjoen@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __SPE_LOADER_H
#define __SPE_LOADER_H
 
#include <stdint.h>
#include <stdio.h>
 
typedef struct arg_s {
uint64_t fileaddr;
uint64_t fsize;
int argument;
} arg_t ;
 
#ifdef __SPU__
 
#include <spu_mfcio.h>
#include <spu_intrinsics.h>
 
typedef struct functions_s {
void (*dmaGetnWait)(void *localstore, unsigned long long extern_adr, uint32_t size, int tag);
void (*printint)(int to_print);
}functions_t;
 
 
void dmaGetnWait(void *localstore, unsigned long long extern_adr, uint32_t size, int tag)
{
int uiMask=1<<tag;
mfc_get(localstore, extern_adr, size, tag, 0, 0);
mfc_write_tag_mask(uiMask);
mfc_read_tag_status_any();
}
 
void printint(int to_print){
printf("Printing int %d\n",to_print);
}
 
void dmaWaitAny(unsigned int uiMask) {
mfc_write_tag_mask(uiMask);
mfc_read_tag_status_any();
}
 
 
#endif
 
#endif
 
/trunk/spe-loader/loader.c
New file
0,0 → 1,143
/**
* SPE Loader
* --------------------------------
* Licensed under the BSDv2
* loader.c - source code for main function in the loader example
* Copyright (c) 2007, Kristian Jerpetjøn <kristian.jerpetjoen@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <libspe2.h>
#include <pthread.h>
#include <malloc.h>
#include <stdint.h>
#include <sys/stat.h>
#include "spe_loader.h"
 
// int FileSize(char* filename)
// {
// struct stat stbuf;
// stat(filename, &stbuf);
// return stbuf.st_size;
// }
 
typedef struct run_struct_s {
struct spe_context * ctx;
pthread_t pts;
int thread_id;
void *argp;
uint64_t *envp;
spe_program_handle_t *image;
unsigned int createflags;
unsigned int runflags;
unsigned int entry;
}run_struct_t;
 
static void * spe_thread(void * arg);
 
int main () {
char *fname="spe_loadme";
run_struct_t *rs;
rs = (run_struct_t *)memalign(128,sizeof(struct run_struct_s ));
arg_t *args;
args = (arg_t *)memalign(128,sizeof(struct arg_s));
printf("Reading file\n");
FILE *LOADME;
LOADME=fopen(fname,"rb");
if (LOADME==NULL) {fprintf(stderr,"Error opening file"); return -1;
}else {
printf("File opened\n");
}
fseek(LOADME,0,SEEK_END);
args->fsize=ftell(LOADME);
args->argument=1337;
char *buffer=memalign(128,(args->fsize + 15 ) & ~15);
printf("filesize is %d\n",args->fsize);
rewind(LOADME);
fread(buffer,1,args->fsize,LOADME);
rs->argp = args;
printf("setting envp\n");
rs->envp =(uint64_t) sizeof(struct arg_s);
rs->createflags = 0;
rs->entry = SPE_DEFAULT_ENTRY;
rs->runflags = 0;
rs->image=spe_image_open("spe_loader");
rs->ctx = spe_context_create(rs->createflags, NULL);
printf("starting spu thread\n");
rs->thread_id = pthread_create(&rs->pts, NULL,&spe_thread,rs);
uint32_t msg=0;
while (spe_out_mbox_status(rs->ctx) == 0);
spe_out_mbox_read(rs->ctx,&msg,1);
printf("spe sendt back %d\n",msg);
fclose(LOADME);
free(buffer);
return 0;
}
static void * spe_thread(void * arg)
{
run_struct_t * arg_ptr;
arg_ptr=(run_struct_t *) arg;
 
if (spe_program_load(arg_ptr->ctx, arg_ptr->image) < 0)
{
fprintf(stderr,"error loading spu-elf");
pthread_exit(NULL);
}
 
printf("starting spu\n");
spe_context_run(arg_ptr->ctx, &arg_ptr->entry, arg_ptr->runflags,arg_ptr->argp,arg_ptr->envp, NULL);
printf("exit from SPU\n");
spe_context_destroy(arg_ptr->ctx);
printf("spu context destroyed\n");
pthread_exit(NULL);
}
/trunk/spe-loader/spe_loadme.c
New file
0,0 → 1,40
/**
* SPE loadme
* --------------------------------
* Licensed under the BSDv2
* spe_loadme.c - code to be loaded as data
* Copyright (c) 2007, Kristian Jerpetjøn <kristian.jerpetjoen@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "spe_loader.h"
 
 
int main(functions_t *func,arg_t *arg)
{
func->printint(arg->argument);
return arg->argument;
}