Subversion Repositories ps3ware

Compare Revisions

Ignore whitespace Rev 213 → Rev 214

/trunk/spe-loader/spe_loader.h
File deleted
/trunk/spe-loader/shared_functions.h
New file
0,0 → 1,61
/**
* SPE Loader
* --------------------------------
* Licensed under the BSDv2
* shared_functions.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 SHARED_FUNCTIONS_H
#define SHARED_FUNCTIONS_H
 
#include <stdint.h>
 
typedef struct arg_s {
uint64_t fileaddr;
uint64_t fsize;
int argument;
} arg_t __attribute__((aligned(128)));
 
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;
 
#ifdef __SPU__
 
void dmaWaitAny(unsigned int uiMask);
 
 
void printint(int to_print);
 
 
void dmaGetnWait(void *localstore, unsigned long long extern_adr, uint32_t size, int tag);
#endif
 
#endif
/trunk/spe-loader/loader.c
33,21 → 33,17
#include <pthread.h>
#include <malloc.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include "spe_loader.h"
#include "shared_functions.h"
 
// int FileSize(char* filename)
// {
// struct stat stbuf;
// stat(filename, &stbuf);
// return stbuf.st_size;
// }
 
typedef struct run_struct_s {
struct spe_context * ctx;
struct arg_s *args;
pthread_t pts;
int thread_id;
void *argp;
uint64_t *argp;
uint64_t *envp;
spe_program_handle_t *image;
unsigned int createflags;
63,11 → 59,11
run_struct_t *rs;
rs = (run_struct_t *)memalign(128,sizeof(struct run_struct_s ));
rs = (struct run_struct_s *)memalign(64,sizeof(struct run_struct_s ));
arg_t *args;
//arg_t *args;
args = (arg_t *)memalign(128,sizeof(struct arg_s));
rs->args = (struct arg_s *)memalign(128,sizeof(struct arg_s));
printf("Reading file\n");
80,24 → 76,30
}
fseek(LOADME,0,SEEK_END);
args->fsize=ftell(LOADME);
rs->args->fsize=ftell(LOADME);
args->argument=1337;
rs->args->argument=1337;
char *buffer=memalign(128,(args->fsize + 15 ) & ~15);
printf("filesize is %d\n",args->fsize);
char *buffer;
 
printf("ppu: buffer pointer %p\n",&buffer);
buffer= (char *)memalign(128, (( rs->args->fsize + 15 ) &~15) );
 
rewind(LOADME);
 
fread(buffer,1,rs->args->fsize,LOADME);
 
printf("ppu: first 4 bytes of executable 0:%1x 1:%1x 2:%1x 3:%1x\n",buffer[0],buffer[1],buffer[2],buffer[3]);
 
rs->args->fileaddr=buffer;
 
rs->argp = rs->args;
 
printf("ppu: filesize is %d\n",rs->args->fsize);
printf("ppu: file buffer is allocated at %p\n",rs->args->fileaddr);
 
rs->envp =(void*)sizeof(struct arg_s);
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;
107,7 → 109,7
rs->image=spe_image_open("spe_loader");
rs->ctx = spe_context_create(rs->createflags, NULL);
printf("starting spu thread\n");
printf("ppu: starting spu thread\n");
rs->thread_id = pthread_create(&rs->pts, NULL,&spe_thread,rs);
uint32_t msg=0;
115,12 → 117,20
while (spe_out_mbox_status(rs->ctx) == 0);
spe_out_mbox_read(rs->ctx,&msg,1);
printf("spe sendt back %d\n",msg);
printf("ppu: spe sendt pre load handshake %d\n",msg);
 
while (spe_out_mbox_status(rs->ctx) == 0);
spe_out_mbox_read(rs->ctx,&msg,1);
 
printf("ppu: spe sendt back %d\n",msg);
 
fclose(LOADME);
free(buffer);
 
spe_context_destroy(rs->ctx);
printf("ppu_thread: spu context destroyed\n");
 
return 0;
}
static void * spe_thread(void * arg)
130,14 → 140,13
 
if (spe_program_load(arg_ptr->ctx, arg_ptr->image) < 0)
{
fprintf(stderr,"error loading spu-elf");
fprintf(stderr,"ppu: 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");
printf("ppu_thread: starting spu\n");
spe_context_run(arg_ptr->ctx, &arg_ptr->entry, arg_ptr->runflags, arg_ptr->argp, arg_ptr->envp, NULL);
printf("ppu_thread: exit from SPU\n");
 
pthread_exit(NULL);
}
/trunk/spe-loader/spe_loadme.c
29,9 → 29,9
* (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"
//#include "spe_loader.h"
#include "shared_functions.h"
 
 
int main(functions_t *func,arg_t *arg)
{
func->printint(arg->argument);
/trunk/spe-loader/Makefile
1,18 → 1,23
PPU_CC=gcc
PPU_CC=powerpc64-unknown-linux-gnu-gcc
PPU_INC=
PPU_LD=-lpthread -lspe2
PPU_EXEC=loader
 
SPU_CC=spu-elf-gcc
SPU_CFLAGS_DEF= -g -fno-exceptions -Wall -O2
SPU_LD=spu-elf-ld
SPU_EXEC1=spe_loader
SPU_EXEC2=spe_loadme
SHARED_C=shared_functions.c
 
all: ppu spu
 
ppu:
${CC} ${PPU_INC} ${PPU_EXEC}.c -o ${PPU_EXEC} ${PPU_LD}
${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}
${SPU_CC} ${SPU_CFLAGS_DEF} ${SPU_EXEC1}.c ${SHARED_C} -o ${SPU_EXEC1}
${SPU_CC} -fpic -Wl,-mrelocatable -c ${SPU_EXEC2}.c -o ${SPU_EXEC2}.o
${SPU_LD} -e 0x80 ${SPU_EXEC2}.o -o ${SPU_EXEC2}.elf
spu-elf-objcopy -O binary -S ${SPU_EXEC2}.elf ${SPU_EXEC2}
 
/trunk/spe-loader/spe_loader.c
29,36 → 29,54
* (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"
#include "shared_functions.h"
#include <malloc.h>
#include <stdio.h>
#include <spu_mfcio.h>
#include <spu_intrinsics.h>
 
 
int main(unsigned long long speid, unsigned long long argp, unsigned long long envp)
{
arg_t *args = memalign(128, envp);
arg_t *args =(arg_t *) memalign(128, (envp +15)&~15);
dmaGetnWait(args,argp,(envp +15)&~15,1);
 
printf("spu: Dma of args complete\n");
 
printf("spu: filesize is %d\n",(int)args->fsize);
printf("spu: file is located at h:%x\tl:%x\n",(unsigned int)(args->fileaddr>>32),(unsigned int)args->fileaddr);
 
//args->argument=1337;
printf("spu: args argument is %d\n",args->argument);
///fetch the executable code as data
 
///fetch the executable code as data
char *data=(char*)memalign(128,(args->fsize +15)&~15);
dmaGetnWait(data,argp,(args->fsize +15)&~15,1);
 
dmaGetnWait(data,args->fileaddr,(args->fsize +15)&~15,1);
 
printf("spu: Dma of Data(program) complete\n");
///setting up some functions to share
functions_t *functions;
functions_t functions;
functions=memalign(128,sizeof(functions_t));
functions.dmaGetnWait=dmaGetnWait;
functions->dmaGetnWait=dmaGetnWait;
functions.printint=printint;
 
while (spu_stat_out_mbox() == 0);
int result=1337;
spu_write_out_mbox(result);
functions->printint=printint;
int (*runme)(functions_t *func,arg_t *arg);
 
printf("spu: byte 0:%1x 1:%1x 2:%1x 3:%1x\n",data[0],data[1],data[2],data[3]);
runme=(void*)data;
 
printf("spu: attemting to run spe as data from spe\n");
result=runme(&functions,args);
printf("spu: spe from spe completed with results %d \n" , result );
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);
/trunk/spe-loader/shared_functions.c
New file
0,0 → 1,54
/**
* SPE Loader
* --------------------------------
* Licensed under the BSDv2
* shared_functions.c - functions 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.
*/
 
#include "shared_functions.h"
 
#include <stdio.h>
#include <spu_mfcio.h>
#include <spu_intrinsics.h>
 
void dmaWaitAny(unsigned int uiMask) {
mfc_write_tag_mask(uiMask);
mfc_read_tag_status_any();
}
 
void printint(int to_print){
printf("\nspu: Loaded Program is Printing int %d\n\n",to_print);
}
 
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();
}