This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[RFC 4/4] cell offloaded stdio
- From: jschopp <jschopp at austin dot ibm dot com>
- To: jschopp <jschopp at austin dot ibm dot com>
- Cc: newlib at sources dot redhat dot com
- Date: Wed, 18 Oct 2006 17:40:02 -0500
- Subject: [RFC 4/4] cell offloaded stdio
- References: <4536AAE7.9000400@austin.ibm.com>
This intercepts newlib stdout, stdin, and stderr. Then translates them to cell spu
STDOUT, STDIN, and STDERR. It's probably not ideal, but it does work.
Index: newlib-1.14.0/newlib/libc/machine/spu/c99ppe.h
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/c99ppe.h
+++ newlib-1.14.0/newlib/libc/machine/spu/c99ppe.h
@@ -105,3 +105,18 @@ send_to_ppe(int signalcode, int opcode,
asm ("sync");
return (f ());
}
+
+static FILE* translate_fp(FILE* source)
+{
+
+ if(source == stdin){
+ return (FILE*)SPE_STDIN;
+ } else if(source == stdout){
+ return (FILE*)SPE_STDOUT;
+ } else if(source == stderr){
+ return (FILE*)SPE_STDERR;
+ } else {
+ return source;
+ }
+
+}
Index: newlib-1.14.0/newlib/libc/machine/spu/fputs.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fputs.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fputs.c
@@ -20,7 +20,7 @@ _DEFUN (fputs, (s, fp),
int* ret;
c99_fputs_t args;
args.s = s;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (int*)&args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FPUTS, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/fclose.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fclose.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fclose.c
@@ -10,16 +10,18 @@
#include <varargs.h>
#endif
-#ifndef _REENT_ONLY
int
_DEFUN (fclose, (fp),
FILE * fp)
{
- int* ret = (int*) &fp;
+ FILE* myfp;
+ int* ret;
+
+ myfp = translate_fp(fp);
+ ret = (int*) &myfp;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FCLOSE, &fp);
return *ret;
}
-#endif /* ! _REENT_ONLY */
Index: newlib-1.14.0/newlib/libc/machine/spu/putc.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/putc.c
+++ newlib-1.14.0/newlib/libc/machine/spu/putc.c
@@ -22,7 +22,7 @@ putc (c, fp)
int* ret;
c99_putc_t args;
args.ch = c;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (int*)&args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_PUTC, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/clearerr.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/clearerr.c
+++ newlib-1.14.0/newlib/libc/machine/spu/clearerr.c
@@ -8,7 +8,10 @@ _DEFUN (clearerr, (fp),
FILE * fp)
{
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_CLEARERR, &fp);
+ FILE* myfp;
+ myfp = translate_fp(fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_CLEARERR, &myfp);
return;
}
Index: newlib-1.14.0/newlib/libc/machine/spu/feof.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/feof.c
+++ newlib-1.14.0/newlib/libc/machine/spu/feof.c
@@ -9,9 +9,11 @@ _DEFUN (feof, (fp),
FILE * fp)
{
int* result;
- result = (int*)&fp;
+ FILE* myfp;
+ result = (int*)&myfp;
+ myfp = translate_fp(fp);
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FEOF, &fp);
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FEOF, &myfp);
return *result;
Index: newlib-1.14.0/newlib/libc/machine/spu/ferror.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/ferror.c
+++ newlib-1.14.0/newlib/libc/machine/spu/ferror.c
@@ -11,9 +11,11 @@ _DEFUN (ferror, (fp),
FILE * fp)
{
int* result;
- result = (int*)&fp;
+ FILE* myfp;
+ myfp = translate_fp(fp);
+ result = (int*)&myfp;
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FERROR, &fp);
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FERROR, &myfp);
return *result;
Index: newlib-1.14.0/newlib/libc/machine/spu/fflush.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fflush.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fflush.c
@@ -7,9 +7,12 @@ _DEFUN (fflush, (fp),
FILE * fp)
{
int* result;
- result = (int*)&fp;
+ FILE* myfp;
+ result = (int*)&myfp;
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FFLUSH, &fp);
+ myfp = translate_fp(fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FFLUSH, &myfp);
return *result;
Index: newlib-1.14.0/newlib/libc/machine/spu/fgetc.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fgetc.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fgetc.c
@@ -7,9 +7,12 @@ _DEFUN (fgetc, (fp),
FILE * fp)
{
int* result;
- result = (int*)&fp;
+ FILE* myfp;
+ result = (int*)&myfp;
+ myfp = translate_fp(fp);
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETC, &fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETC, &myfp);
return *result;
Index: newlib-1.14.0/newlib/libc/machine/spu/fgetpos.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fgetpos.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fgetpos.c
@@ -14,14 +14,14 @@ _DEFUN (fgetpos, (fp, pos),
FILE * fp _AND
_fpos_t * pos)
{
- c99_fgetpos_t arg;
+ c99_fgetpos_t args;
int* result;
result = (int*)&fp;
- arg.fp = fp;
- arg.pos = pos;
+ args.fp = translate_fp(fp);
+ args.pos = pos;
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETPOS, &arg);
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETPOS, &args);
return *result;
Index: newlib-1.14.0/newlib/libc/machine/spu/fgets.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fgets.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fgets.c
@@ -21,7 +21,7 @@ _DEFUN (fgets, (buf, n, fp),
c99_fgets_t args;
args.buf = buf;
args.n = n;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (char**) &args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETS, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/fileno.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fileno.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fileno.c
@@ -8,8 +8,13 @@ _DEFUN (fileno, (fp),
FILE *fp)
{
- int *ret = (int*)&fp;
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FILENO, &fp);
+ FILE* myfp;
+ int *ret = (int*)&myfp;
+
+
+ myfp = translate_fp(fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FILENO, &myfp);
return *ret;
}
Index: newlib-1.14.0/newlib/libc/machine/spu/fputc.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fputc.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fputc.c
@@ -20,7 +20,7 @@ fputc (c, fp)
int* ret;
c99_fputc_t args;
args.ch = c;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (int*)&args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FPUTC, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/fread.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fread.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fread.c
@@ -27,7 +27,7 @@ _DEFUN (fread, (buf, size, count, fp),
args.buf = buf;
args.size = size;
args.count = count;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (size_t*) &args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FREAD, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/freopen.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/freopen.c
+++ newlib-1.14.0/newlib/libc/machine/spu/freopen.c
@@ -23,7 +23,7 @@ _DEFUN (freopen, (file, mode, fp),
c99_freopen_t args;
args.file = file;
args.mode = mode;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (FILE**) &args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FREOPEN, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/fseek.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fseek.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fseek.c
@@ -21,7 +21,7 @@ _DEFUN (fseek, (fp, offset, whence),
{
int* ret;
c99_fseek_t args;
- args.fp = fp;
+ args.fp = translate_fp(fp);
args.offset = offset;
args.whence = whence;
ret = (int*)&args;
Index: newlib-1.14.0/newlib/libc/machine/spu/fsetpos.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fsetpos.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fsetpos.c
@@ -18,7 +18,7 @@ _DEFUN (fsetpos, (iop, pos),
{
int* ret;
c99_fsetpos_t args;
- args.fp = iop;
+ args.fp = translate_fp(iop);
args.pos = pos;
ret = (int*)&args;
Index: newlib-1.14.0/newlib/libc/machine/spu/ftell.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/ftell.c
+++ newlib-1.14.0/newlib/libc/machine/spu/ftell.c
@@ -7,9 +7,12 @@ long
_DEFUN (ftell, (fp),
FILE * fp)
{
- long *ret = (long*)&fp;
+ FILE* myfp;
+ long *ret = (long*)&myfp;
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_CLEARERR, &fp);
+ myfp = translate_fp(fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_CLEARERR, &myfp);
return *ret;
}
Index: newlib-1.14.0/newlib/libc/machine/spu/fwrite.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/fwrite.c
+++ newlib-1.14.0/newlib/libc/machine/spu/fwrite.c
@@ -27,7 +27,7 @@ _DEFUN (fwrite, (buf, size, count, fp),
args.buf = buf;
args.size = size;
args.count = count;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (size_t*) &args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FWRITE, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/getc.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/getc.c
+++ newlib-1.14.0/newlib/libc/machine/spu/getc.c
@@ -12,9 +12,12 @@ getc (fp)
FILE *fp;
{
int* ret;
- ret = (int*)&fp;
+ FILE* myfp;
+ ret = (int*)&myfp;
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_GETC, &fp);
+ myfp = translate_fp(fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_GETC, &myfp);
return *ret;
}
Index: newlib-1.14.0/newlib/libc/machine/spu/rewind.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/rewind.c
+++ newlib-1.14.0/newlib/libc/machine/spu/rewind.c
@@ -6,7 +6,10 @@ void
_DEFUN (rewind, (fp),
FILE * fp)
{
- send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_REWIND, &fp);
+ FILE* myfp;
+ myfp = translate_fp(fp);
+
+ send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_REWIND, &myfp);
return;
}
Index: newlib-1.14.0/newlib/libc/machine/spu/setbuf.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/setbuf.c
+++ newlib-1.14.0/newlib/libc/machine/spu/setbuf.c
@@ -18,7 +18,7 @@ _DEFUN (setbuf, (fp, buf),
char *buf)
{
c99_setbuf_t args;
- args.fp = fp;
+ args.fp = translate_fp(fp);
args.buf = buf;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_SETBUF, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/setvbuf.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/setvbuf.c
+++ newlib-1.14.0/newlib/libc/machine/spu/setvbuf.c
@@ -25,7 +25,7 @@ _DEFUN (setvbuf, (fp, buf, mode, size),
{
int* ret;
c99_setvbuf_t args;
- args.fp = fp;
+ args.fp = translate_fp(fp);
args.buf = buf;
args.mode = mode;
args.size = size;
Index: newlib-1.14.0/newlib/libc/machine/spu/ungetc.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/ungetc.c
+++ newlib-1.14.0/newlib/libc/machine/spu/ungetc.c
@@ -20,7 +20,7 @@ ungetc (c, fp)
int* ret;
c99_ungetc_t args;
args.c = c;
- args.fp = fp;
+ args.fp = translate_fp(fp);
ret = (int*)&args;
send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_UNGETC, &args);
Index: newlib-1.14.0/newlib/libc/machine/spu/vfprintf.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/vfprintf.c
+++ newlib-1.14.0/newlib/libc/machine/spu/vfprintf.c
@@ -31,7 +31,7 @@ _DEFUN (vfprintf, (fp, fmt0, ap),
c99_vfprintf_t args;
ret = (int*) &args;
- args.fp = fp;
+ args.fp = translate_fp(fp);
args.fmt = (char*) fmt0;
va_copy(args.ap,ap);
Index: newlib-1.14.0/newlib/libc/machine/spu/vfscanf.c
===================================================================
--- newlib-1.14.0.orig/newlib/libc/machine/spu/vfscanf.c
+++ newlib-1.14.0/newlib/libc/machine/spu/vfscanf.c
@@ -31,7 +31,7 @@ _DEFUN (vfscanf, (fp, fmt, ap),
c99_vfscanf_t args;
ret = (int*) &args;
- args.fp = fp;
+ args.fp = translate_fp(fp);
args.fmt = (char*) fmt;
va_copy(args.ap,ap);