Main Page | Alphabetical List | Class List | File List | Class Members | File Members

slice_stdio_os1.h

Go to the documentation of this file.
00001 /* =============
00002  * apeNEXT/nlibc
00003  * =============
00004  *
00005  * apeNEXT multidata stdio
00006  *
00007  * $Id: slice_stdio_os1.h,v 1.20 2006/05/06 14:42:24 pleiter Exp $
00008  *----------------------------------------------------------------------------------------------- */
00009 #ifndef _NLIBC_OS1_SLICE_STDIO_H
00010 #define _NLIBC_OS1_SLICE_STDIO_H
00011 
00012 #include <nlibc.h>
00013 
00014 #include <stdarg.h>             // for va_list etc.
00015 #include <os1/defs_os1.h>       // for SYS_IOFMT_*
00016 
00017 //--------------------------------------------------------------------------------------------------
00018 // OS0 compatibility routines
00019 //--------------------------------------------------------------------------------------------------
00020 
00021 /*--------------------------------------------------------------------------------------------------
00022 /!
00023 \par NAME
00024   mfputi, mfputx, mfputd,                                                                       \n
00025   mfputu, mputi, mputx, mputd,                                                                  \n
00026   mputu - formatted output of int, complex, double and unsigned                                 \n
00027   from specified node(s)                                                                        \n
00028 
00029 \par SYNOPSIS
00030   #include <stdio.h>                                                                            \n
00031                                                                                                 \n
00032   mfputi(int x1, int y1, int z1, [ int x2, int y2, int z2, ] int value, FILE *stream)           \n
00033   mfputx(int x1, int y1, int z1, [ int x2, int y2, int z2, ] complex value, FILE *stream)       \n
00034   mfputd(int x1, int y1, int z1, [ int x2, int y2, int z2, ] double value, FILE *stream)        \n
00035   mfputu(int x1, int y1, int z1, [ int x2, int y2, int z2, ] unsigned value, FILE *stream)      \n
00036   mputi(int x1, int y1, int z1, [ int x2, int y2, int z2, ] int value)                          \n
00037   mputx(int x1, int y1, int z1, [ int x2, int y2, int z2, ] complex value)                      \n
00038   mputd(int x1, int y1, int z1, [ int x2, int y2, int z2, ] double value)                       \n
00039   mputu(int x1, int y1, int z1, [ int x2, int y2, int z2, ] unsigned value)
00040 
00041 \par DESCRIPTION
00042   The functions produce formatted output of their value argument on the specified stream (fput
00043   variants) or on stdout (put variants). The format used is defined by nose. The specification
00044   of the second coordinate triple is optional.  If present, it specifies the 'upper' corner of
00045   a slice of nodes.  If not present, the first triple specifies coordinates of a single
00046   node.
00047 
00048 \par RETURN VALUE
00049   Number of written words
00050 */
00051 //--------------------------------------------------------------------------------------------------
00052 
00053 #define __MIOPUT(ITS, CTS, CTYPE, STREAM) \
00054         va_list ap;\
00055         int n_args;\
00056         int x2 = x1, y2 = y1, z2 = z1;\
00057         CTYPE value;\
00058         vector int sys_retval;\
00059         int fput_retval;\
00060         FILE *stream;\
00061 \
00062         asm("\n\t!! begin mfput"#CTS"()");\
00063         va_start( ap, z1 );\
00064 \
00065         n_args = __builtin_argcount();\
00066         if( n_args >= 6 ) {\
00067                 x2 = va_arg(ap, int);\
00068                 y2 = va_arg(ap, int);\
00069                 z2 = va_arg(ap, int);\
00070         }\
00071 \
00072         value = va_arg(ap,CTYPE);\
00073         stream = STREAM;\
00074 \
00075         asm("\t$io_start\n"\
00076             "\t$io_fd( 0.%1 )\n"\
00077             "\t$io_slice(0.%2,0.%3,0.%4,0.%5,0.%6,0.%7)\n"\
00078             "\t$io_put"#ITS"( 0x0.%8 )\n"\
00079             "\t$io_end\n"\
00080             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00081             : "=r" (sys_retval)\
00082             : "r" (stream->fd),\
00083               "r" (x1),  "r" (y1),  "r" (z1),  "r" (x2),  "r" (y2),  "r" (z2), \
00084               "r" (&value) );\
00085 \
00086         fput_retval = (sys_retval.lo) ? -1 : 0;\
00087         asm("\t!! end mfput"#CTS"()");\
00088         return fput_retval
00089 
00090 #ifdef __HAS_MAIN
00091 #define BODY(args) args
00092 #else
00093 #define BODY(args) ;
00094 #endif
00095 
00096 #if !defined(__cflow_processed) || defined(_uses_mfputi_slice_stdio_os1_h)
00097 int mfputi( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(d,i,int,(va_arg(ap, FILE*))); })
00098 #endif // mfputi()
00099 
00100 #if !defined(__cflow_processed) || defined(_uses_mputi_slice_stdio_os1_h)
00101 int mputi( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(d,i,int,stdout); })
00102 #endif // mfputi()
00103 
00104 #if !defined(__cflow_processed) || defined(_uses_mfputiv_slice_stdio_os1_h)
00105 int mfputiv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(dv,iv,int,(va_arg(ap, FILE*))); })
00106 #endif // mfputiv()
00107 
00108 #if !defined(__cflow_processed) || defined(_uses_mputiv_slice_stdio_os1_h)
00109 int mputiv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(dv,iv,int,stdout); })
00110 #endif // mfputiv()
00111 
00112 #if !defined(__cflow_processed) || defined(_uses_mfputx_slice_stdio_os1_h)
00113 int mfputx( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(z,x,complex,(va_arg(ap, FILE*))); })
00114 #endif // mfputx()
00115 
00116 #if !defined(__cflow_processed) || defined(_uses_mputx_slice_stdio_os1_h)
00117 int mputx( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(z,x,complex,stdout); })
00118 #endif // mputx()
00119 
00120 #if !defined(__cflow_processed) || defined(_uses_mfputd_slice_stdio_os1_h)
00121 int mfputd( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(e,d,double,(va_arg(ap, FILE*))); })
00122 #endif // mfputd()
00123 
00124 #if !defined(__cflow_processed) || defined(_uses_mputd_slice_stdio_os1_h)
00125 int mputd( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(e,d,double,stdout); })
00126 #endif // mputd()
00127 
00128 #if !defined(__cflow_processed) || defined(_uses_mfputu_slice_stdio_os1_h)
00129 int mfputu( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,(va_arg(ap, FILE*))); })
00130 #endif // mfputu()
00131 
00132 #if !defined(__cflow_processed) || defined(_uses_mputu_slice_stdio_os1_h)
00133 int mputu( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,stdout); })
00134 #endif // mputu()
00135 
00136 #if !defined(__cflow_processed) || defined(_uses_mfputh_slice_stdio_os1_h)
00137 int mfputh( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,(va_arg(ap, FILE*))); })
00138 #endif // mfputh()
00139 
00140 #if !defined(__cflow_processed) || defined(_uses_mputh_slice_stdio_os1_h)
00141 int mputh( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,stdout); })
00142 #endif // mputh()
00143 
00144 #if !defined(__cflow_processed) || defined(_uses_mfputhv_slice_stdio_os1_h)
00145 int mfputhv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(xv,u,unsigned,(va_arg(ap, FILE*))); })
00146 #endif // mfputhv()
00147 
00148 #if !defined(__cflow_processed) || defined(_uses_mputhv_slice_stdio_os1_h)
00149 int mputhv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(xv,u,unsigned,stdout); })
00150 #endif // mputhv()
00151 
00152 #define __MIOPUTA(ITS, ITYPE, CTS, CTYPE, BS,STREAM) \
00153         va_list ap;\
00154         int n_args;\
00155         int x2 = x1, y2 = y1, z2 = z1;\
00156         CTYPE *ptr;\
00157         int size;\
00158         vector int sys_retval;\
00159         int fput_retval;\
00160         FILE *stream;\
00161 \
00162         asm("\n\t!! begin mfput"#CTS"a()");\
00163         va_start( ap, z1 );\
00164 \
00165         n_args = __builtin_argcount();\
00166         if( n_args >= 7 ) {\
00167                 x2 = va_arg(ap, int);\
00168                 y2 = va_arg(ap, int);\
00169                 z2 = va_arg(ap, int);\
00170         }\
00171 \
00172         ptr = va_arg(ap,CTYPE *);\
00173         size= va_arg(ap,int);\
00174         stream = STREAM;\
00175 \
00176         asm("\t$io_start\n"\
00177             "\t$io_fd( 0.%1 )\n"\
00178             "\t$io_slice(0.%2,0.%3,0.%4,0.%5,0.%6,0.%7)\n"\
00179             "\t\\equ $cmd   $SYS_IOCMD_SWR\n"\
00180             "\t\\equ $fmt   <$SYS_IOFMT_"#ITYPE">\n"\
00181             "\t\\equ $bs    "#BS"\n"\
00182             "\t\\equ $sep   <$SYS_IOPSEP_NL .or. $SYS_IOWSEP_SPACE>\n"\
00183             "\t$io_packet($cmd, <$fmt .or. $sep>, $SYS_IORDFLG_NOP, $SYS_IODEV_MEM, 0.%9, $bs, 0.%8)\n"\
00184             "\t$io_end\n"\
00185             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00186             : "=r" (sys_retval)\
00187             : "r" (stream->fd),\
00188               "r" (x1),  "r" (y1),  "r" (z1),  "r" (x2),  "r" (y2),  "r" (z2), \
00189               "r" (ptr), "r" (size) );\
00190 \
00191         fput_retval = (sys_retval.lo) ? -1 : 0;\
00192         asm("\t!! end mfput"#CTS"a()");\
00193         return fput_retval
00194 
00195 #if !defined(__cflow_processed) || defined(_uses_mfputia_slice_stdio_os1_h)
00196 int mfputia( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(d,INT,i,int,$SYS_IOBS_L,(va_arg(ap, FILE*))); })
00197 #endif // mfputi()
00198 
00199 #if !defined(__cflow_processed) || defined(_uses_mputia_slice_stdio_os1_h)
00200 int mputia( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(d,INT,i,int,$SYS_IOBS_L,stdout); })
00201 #endif // mputi()
00202 
00203 #if !defined(__cflow_processed) || defined(_uses_mfputxa_slice_stdio_os1_h)
00204 int mfputxa( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,x,complex,$SYS_IOBS_V,(va_arg(ap, FILE*))); })
00205 #endif // mputxa()
00206 
00207 #if !defined(__cflow_processed) || defined(_uses_mputxa_slice_stdio_os1_h)
00208 int mputxa( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,x,complex,$SYS_IOBS_V,stdout); })
00209 #endif // mputxa()
00210 
00211 #if !defined(__cflow_processed) || defined(_uses_mfputda_slice_stdio_os1_h)
00212 int mfputda( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(e,DBL,d,double,$SYS_IOBS_L,(va_arg(ap, FILE*))); })
00213 #endif // mfputd()
00214 
00215 #if !defined(__cflow_processed) || defined(_uses_mputda_slice_stdio_os1_h)
00216 int mputda( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(e,DBL,d,double,$SYS_IOBS_L,stdout); })
00217 #endif // mputd()
00218 
00219 #if !defined(__cflow_processed) || defined(_uses_mfputva_slice_stdio_os1_h)
00220 int mfputva( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,v,vector,$SYS_IOBS_V,(va_arg(ap, FILE*))); })
00221 #endif // mputva()
00222 
00223 #if !defined(__cflow_processed) || defined(_uses_mputva_slice_stdio_os1_h)
00224 int mputva( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,v,vector,$SYS_IOBS_V,stdout); })
00225 #endif // mputva()
00226 
00227 /*--------------------------------------------------------------------------------------------------
00228 /!
00229 \par NAME
00230   mfgeti, mfgetx, mfgetd,
00231   mfgetu, mgeti, mgetx, mgetd,
00232   mgetu - formatted outget of int, complex, double and unsigned from specified node(s)
00233 
00234 \par SYNOPSIS
00235   #include <stdio.h>                                                                            \n
00236                                                                                                 \n
00237   mfgeti(int x1, int y1, int z1, [ int x2, int y2, int z2, ] int *ptr, FILE *stream)            \n
00238   mfgetx(int x1, int y1, int z1, [ int x2, int y2, int z2, ] complex *ptr, FILE *stream)        \n
00239   mfgetd(int x1, int y1, int z1, [ int x2, int y2, int z2, ] double *ptr, FILE *stream)         \n
00240   mfgetu(int x1, int y1, int z1, [ int x2, int y2, int z2, ] unsigned *ptr, FILE *stream)       \n
00241   mgeti(int x1, int y1, int z1, [ int x2, int y2, int z2, ] int *ptr)                           \n
00242   mgetx(int x1, int y1, int z1, [ int x2, int y2, int z2, ] complex *ptr)                       \n
00243   mgetd(int x1, int y1, int z1, [ int x2, int y2, int z2, ] double *ptr)                        \n
00244   mgetu(int x1, int y1, int z1, [ int x2, int y2, int z2, ] unsigned *ptr)
00245 
00246 \par RETURN VALUE
00247   Number of written words
00248 */
00249 //------------------------------------------------------------------------------
00250 
00251 #define __MIOGET(ITS, CTS, CTYPE, STREAM) \
00252         va_list ap;\
00253         int n_args;\
00254         int x2 = x1, y2 = y1, z2 = z1;\
00255         CTYPE *ptr;\
00256         vector int sys_retval;\
00257         int fput_retval;\
00258         FILE *stream;\
00259 \
00260         asm("\n\t!! begin mfput"#CTS"()");\
00261         va_start( ap, z1 );\
00262 \
00263         n_args = __builtin_argcount();\
00264         if( n_args >= 6 ) {\
00265                 x2 = va_arg(ap, int);\
00266                 y2 = va_arg(ap, int);\
00267                 z2 = va_arg(ap, int);\
00268         }\
00269 \
00270         ptr = va_arg(ap, CTYPE *);\
00271         stream = STREAM;\
00272 \
00273         asm("\t$io_start\n"\
00274             "\t$io_fd( 0.%1 )\n"\
00275             "\t$io_slice(0.%2,0.%3,0.%4,0.%5,0.%6,0.%7)\n"\
00276             "\t$io_get"#ITS"( 0.%8 )\n"\
00277             "\t$io_end\n"\
00278             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00279             : "=r" (sys_retval)\
00280             : "r" (stream->fd),\
00281               "r" (x1),  "r" (y1),  "r" (z1),  "r" (x2),  "r" (y2),  "r" (z2), \
00282               "r" (ptr) );\
00283 \
00284         fput_retval = (sys_retval.lo) ? -1 : 0;\
00285         asm("\t!! end mfput"#CTS"()");\
00286         return fput_retval
00287 
00288 #if !defined(__cflow_processed) || defined(_uses_mfgeti_slice_stdio_os1_h)
00289 int mfgeti( int x1, int y1, int z1, ... ) BODY({ __MIOGET(d,i,int,(va_arg(ap, FILE*))); })
00290 #endif // mfgeti()
00291 
00292 #if !defined(__cflow_processed) || defined(_uses_mfgetx_slice_stdio_os1_h)
00293 int mfgetx( int x1, int y1, int z1, ... ) BODY({ __MIOGET(z,x,complex,(va_arg(ap, FILE*))); })
00294 #endif // mfgetx()
00295 
00296 #if !defined(__cflow_processed) || defined(_uses_mfgetdi_slice_stdio_os1_h)
00297 int mfgetdi( int x1, int y1, int z1, ... ) BODY({ __MIOGET(e,d,double,(va_arg(ap, FILE*))); })
00298 #endif // mfgetdi()
00299 
00300 #undef BODY
00301 
00302 //-----------------------------------------------------------------------------------------
00341 //--------------------------------------------------------------------------------------------------
00342 #define mprintf(ARGS...) mfprintf(stdout, ##ARGS)
00343 
00344 #ifndef __HAS_MAIN
00345 extern int mfprintf(FILE *stream, int x1, int y1, int z1, ...);
00346 #else
00347 #if !defined(__cflow_processed) || defined(_uses_mfprintf_slice_stdio_os1_h)
00348 int mfprintf(FILE *stream, int x1, int y1, int z1, ...)
00349 {
00350 #pragma localmem
00351 
00352   int         iocnt;
00353   vector int  argcnt, arginfo, sys_retval;
00354   va_list     ap; 
00355   int         x2 = x1, y2 = y1, z2 = z1;
00356   char        *format;
00357 
00358   if(! stream || stream->mode == _SYS_IOMODE_CLOSED) {
00359     errno = EBADF;
00360     return 0;
00361   }
00362 
00363   va_start(ap, z1);
00364 
00365   argcnt = __builtin_argcount();
00366   iocnt  = argcnt.lo - 5;
00367 
00368   if (iocnt < 0) {                      // insufficient number of arguments
00369     errno = EINVAL;
00370     return 0;
00371   }
00372 
00373   // check if more node coordinates follow
00374   // by testing the argument type 
00375   //   if 'int' : read 3 more coords
00376   //   else     : assume it's the 'format' arg.
00377   { va_list     ap2; 
00378     vector int  arginfo; 
00379     void        *ptr = _va_ptr(ap2);
00380 
00381     va_copy(ap2, ap);
00382     arginfo = _va_info(ap2);
00383     if (arginfo.hi == NLCC_INT) {
00384       x2 = va_arg(ap, int);
00385       y2 = va_arg(ap, int);
00386       z2 = va_arg(ap, int);
00387       iocnt -= 3;
00388     }
00389   }
00390 
00391   format = va_arg(ap, char *);
00392 
00393   asm("\t!! begin mfprintf()\n");
00394 
00395   // set file descriptor, slice and output format string
00396   asm("\t$io_start\n"
00397       "\t$io_fd(0.%0)\n"
00398       "\t$io_slice(0.%3, 0.%4, 0.%5, 0.%6, 0.%7, 0.%8)\n"\
00399       "\t$io_cnt_set(%2)\n"
00400       "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00401       "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00402       "\t\\equ $dev   $SYS_IODEV_MEM\n"
00403       "\t\\equ $bs    $SYS_IOBS_V\n"
00404       "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00405       "\t$io_packet($cmd, $fmt, $rdflg, $dev, 0, $bs, 0.%1 )"
00406       : : "r" (stream->fd), "r" (format), "r" (iocnt),
00407           "r" (x1), "r" (y1), "r" (z1), 
00408           "r" (x2), "r" (y2), "r" (z2));
00409 
00410   asm("\t$io_setloopflg\n");
00411 
00412   for(; iocnt > 0; iocnt --) {
00413     vector int arginfo = _va_info(ap);
00414     void *ptr = _va_ptr(ap);
00415     _va_skip(ap, arginfo.lo);
00416     if (arginfo.hi == NLCC_STRING) {
00417       char *str = *(char **)ptr;
00418       asm("\t$io_cnt_decr\n"
00419           "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00420           "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00421           "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00422           "\t\\equ $dev   $SYS_IODEV_MEM\n"
00423           "\t\\equ $bs    $SYS_IOBS_V\n"
00424           "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00425           "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, 0, $bs, 0.%0)\n"
00426           : :  "r" (str) );
00427     }
00428     else {
00429       asm("\t$io_cnt_decr\n"
00430           "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00431           "\t\\equ $fmt   $SYS_IOFMT_BIN\n"
00432           "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00433           "\t\\equ $dev   $SYS_IODEV_MEM\n"
00434           "\t\\equ $l     0.%1\n"
00435           "\t\\equ $bs    $SYS_IOBS_V\n"
00436           "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00437           "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, $l, $bs, 0.%0)\n"
00438           : :  "r" (ptr), "r" (arginfo.lo) );
00439     }
00440   }
00441   va_end(ap);
00442 
00443   asm("\t$io_cnt_clear\n"
00444       "\t$io_end\n"
00445       "\t!! end mfprintf()\n"
00446       "\tlmtr %0 $MEM_SYS_RVAL\n"
00447       : "=r" (sys_retval) );
00448 
00449   return (int) (sys_retval.hi);
00450 }
00451 #endif // mfprintf()
00452 #endif // Has Main
00453 
00454 #define mvprintf(ARGS...) mvfprintf(stdout, ##ARGS)
00455 
00456 #ifndef __HAS_MAIN
00457 extern int mvfprintf(FILE *stream, int x1, int y1, int z1, ... );
00458 #else
00459 #if !defined(__cflow_processed) || defined(_uses_mvfprintf_slice_stdio_os1_h)
00460 int mvfprintf(FILE *stream, int x1, int y1, int z1, ... )
00461 {
00462 #pragma localmem
00463         int n_args, n_pargs;
00464         vector int sys_retval;
00465         va_list ap, ap2, ap3; 
00466         int x2 = x1, y2 = y1, z2 = z1;
00467         char *format;
00468 
00469         va_start( ap, z1 );
00470 
00471         n_args = __builtin_argcount();
00472         n_pargs = n_args;
00473         // function expects at 5 or 8 arguments
00474 
00475         printf("n_args: %d\n",n_args);
00476 
00477         if( (n_args != 6) && (n_args !=9) ) 
00478         {
00479             return(0);
00480         }
00481         else
00482         {
00483         
00484             // check if more node coordinates follow
00485             // by testing the argument type 
00486             //  if 'int' : read 3 more coords
00487             //   else    : assume it's the 'format' arg.
00488             {   
00489                 va_list ap2; 
00490                 vector int arginfo; 
00491                 void *ptr = _va_ptr(ap2);
00492                 
00493                 va_copy(ap2,ap);
00494                 arginfo = _va_info(ap2);
00495                 if( arginfo.hi == NLCC_INT ) {
00496                     x2 = va_arg(ap, int);
00497                     y2 = va_arg(ap, int);
00498                     z2 = va_arg(ap, int);
00499                     n_pargs -= 8;
00500                 } else
00501                     n_pargs -= 5;
00502             }
00503 
00504             printf("n_pargs: %d\n",n_pargs);
00505             
00506             format = va_arg(ap, char *);
00507             
00508             va_copy(ap3,(va_list)va_arg(ap, va_list));
00509             
00510             n_pargs=_va_args(ap3);
00511             
00512             if( ! stream->fd ) { 
00513                 errno = EBADF;
00514                 return 0;
00515             }
00516 
00517             asm("\t!! begin mvfprintf()\n");
00518             
00519             // output format string
00520             asm("\t$io_start\n"
00521                 "\t$io_fd( 0.%0 )\n"
00522                 "\t$io_slice(0.%3,0.%4,0.%5,0.%6,0.%7,0.%8)\n"\
00523                 "\t$io_cnt_set( %2 )\n"
00524                 "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00525                 "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00526                 "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_SPACE>\n"
00527                 "\t\\equ $dev   $SYS_IODEV_MEM\n"
00528                 "\t\\equ $bs    $SYS_IOBS_V\n"
00529                 "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00530                 "\t$io_packet($cmd, < $fmt .or. $sep >, $rdflg, $dev, 0, $bs, 0.%1 )"
00531                 : : "r" (stream->fd), "r" (format), "r" (n_pargs),
00532                 "r" (x1), "r" (y1), "r" (z1), 
00533                 "r" (x2), "r" (y2), "r" (z2));
00534             
00535             for(; n_pargs > 0; n_pargs -- ) {
00536                 vector int arginfo = _va_info(ap3);
00537                 void *ptr = _va_ptr(ap3);
00538                 _va_skip( ap3, arginfo.lo );
00539                 if( arginfo.hi == NLCC_STRING ) {
00540                     char *str = *(char **)ptr;
00541                     asm("\t$io_cnt_decr\n"
00542                         "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00543                         "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00544                         "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00545                         "\t\\equ $dev   $SYS_IODEV_MEM\n"
00546                         "\t\\equ $bs    $SYS_IOBS_V\n"
00547                         "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00548                         "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, 0, $bs, 0.%0)\n"
00549                         : :  "r" (str) );
00550                 } else {
00551                     asm("\t$io_cnt_decr\n"
00552                         "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00553                         "\t\\equ $fmt   $SYS_IOFMT_BIN\n"
00554                         "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00555                         "\t\\equ $dev   $SYS_IODEV_MEM\n"
00556                         "\t\\equ $l     0.%1\n"
00557                         "\t\\equ $bs    $SYS_IOBS_V\n"
00558                         "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00559                         "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, $l, $bs, 0.%0)\n"
00560                         : :  "r" (ptr), "r" (arginfo.lo) );
00561                 }
00562             }
00563             va_end(ap3);
00564             va_end(ap);
00565             asm("\t$io_cnt_clear\n"
00566                 "\t$io_end\n"
00567                 "\t!! end mvfprintf()\n"
00568                 "\tlmtr %0 $MEM_SYS_RVAL\n"
00569                 : "=r" (sys_retval) );
00570             
00571             return (int) (sys_retval.hi);
00572         }
00573 }
00574 #endif // mvfprintf()
00575 #endif // Has Main
00576 
00577 /*--------------------------------------------------------------------------------------------------
00578 /!
00579 \par NAME   
00580   slread(), mfread(), mfwrite() -  binary stream input/output for slices                        \n
00581                                                                                                 \n
00582   slread() - read single data to slice of nodes                                                 \n
00583   mfread() - read multiple data to slice of nodes                                               \n
00584   mfwrite() - write multiple data to slice of nodes                                             \n
00585 
00586 \par SYNOPSIS
00587   #include <stdio.h>                                                                            \n
00588                                                                                                 \n
00589   size_t slead(int x1, int y1, int z1, [int x2, int y2, int z2,]
00590                void *ptr, size_t size, size_t nmemb, FILE *stream)                              \n
00591   size_t fread(int x1, int y1, int z1, [int x2, int y2, int z2,]
00592                void *ptr, size_t size, size_t nmemb, FILE *stream)                              \n
00593   size_t fwrite(int x1, int y1, int z1,[int x2, int y2, int z2,]
00594                 void *ptr, size_t size, size_t nmemb, FILE *stream)                             \n
00595 
00596 \par DESCRIPTION 
00597   See: fread(), fwrite()
00598 
00599 \par RETURN VALUE
00600   See: fread(), fwrite()
00601 
00602 \par BUG
00603   fmread, slread bug: if reading exeeds EOF, no data are read to memory and the memory remains
00604   unchanged
00605 
00606 \par NOTE
00607   nodes read/write according to node_abs_id, starting with lowest number.
00608   (the id is calculated to be: node_abs_id = x*LY*LZ + y*LY + z)
00609 */
00610 //--------------------------------------------------------------------------------------------------
00611 
00612 #define __MF_ANZARGS 7
00613 #define __TMF_ANZARGS 7
00614 
00615 #define __MFSTART(ANZARGS) \
00616         int iocnt, retval, nbytes;\
00617         vector int argcnt, sys_rval;\
00618         size_t size, nmemb;\
00619         void *ptr;\
00620         FILE *stream;\
00621         va_list ap;\
00622         int x2 = x1, y2 = y1, z2 = z1;\
00623 \
00624         va_start( ap, z1 );\
00625         argcnt = __builtin_argcount();\
00626         iocnt = argcnt.lo;\
00627 \
00628         if (iocnt==ANZARGS+3) {\
00629                 x2 = va_arg(ap, int);\
00630                 y2 = va_arg(ap, int);\
00631                 z2 = va_arg(ap, int);\
00632         }\
00633         else if (iocnt!=ANZARGS) return 0
00634 
00635 #define __MFCHECK(STREAM) \
00636         assert( (nbytes%16)==0 );\
00637         stream = STREAM;\
00638         if( ! stream->fd ) {\
00639                 errno = EBADF;\
00640                 return 0;\
00641         }  
00642 
00643 #define __MIOPACKET(IOCMD,IOBS,IORDFLG) \
00644       asm("\t$io_start\n"\
00645             "\t\\equl $cmd   "#IOCMD"\n"\
00646             "\t\\equl $fmt   $SYS_IOFMT_BIN\n"\
00647             "\t\\equl $sep   $SYS_IOPSEP_NOP\n"\
00648             "\t\\equl $rdflg "#IORDFLG"\n"\
00649             "\t\\equl $dev   $SYS_IODEV_MEM\n"\
00650             "\t\\equl $l     %1>>4\n"\
00651             "\t\\equl $bs    "#IOBS"\n"\
00652             "\t$io_fd( 0.%2 )\n"\
00653             "\t$io_slice(0.%4,0.%5,0.%6,0.%7,0.%8,0.%9)\n"\
00654             "\t$io_slice_set\n"\
00655             "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, $l, $bs, 0.%3)\n"\
00656             "\t$io_end\n"\
00657             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00658             : "=r" (sys_rval) : "r" (nbytes), "r" (stream->fd), "r" (ptr),\
00659                "r" (x1), "r" (y1), "r" (z1), "r" (x2), "r" (y2), "r" (z2) )
00660 
00661 #define __MFEND \
00662         retval = nmemb;\
00663         where (sys_rval.lo) {\
00664                 stream->err = 1;\
00665                 retval = 0;\
00666         }\
00667 \
00668         return retval
00669 
00670 //--------------------------------------------------------------------------------------------------
00671 
00672 #define _MFIO(IOCMD,STREAM) \
00673         __MFSTART(__MF_ANZARGS);\
00674         ptr = va_arg(ap, void*);\
00675         size = va_arg(ap, size_t);\
00676         nmemb = va_arg(ap, size_t);\
00677         nbytes = size * nmemb;\
00678         __MFCHECK(STREAM);\
00679         __MIOPACKET(IOCMD,$SYS_IOBS_V,$SYS_IORDFLG_NOP);\
00680         __MFEND
00681 
00682 #define _TMFIO(IOCMD,STREAM) \
00683         __MFSTART(__TMF_ANZARGS);\
00684         ptr = va_arg(ap, void*);\
00685         size = va_arg(ap, size_t);\
00686         nmemb = 1;\
00687         nbytes = size * nmemb;\
00688         __MFCHECK(STREAM);\
00689         if( (tcode==NLCC_FLOAT) || (tcode==NLCC_DOUBLE) ) {\
00690                 __MIOPACKET(IOCMD,$SYS_IOBS_L,$SYS_IORDFLG_HZERO);\
00691         }\
00692         else if( (tcode==NLCC_INT) || (tcode==NLCC_UNSIGNED) ) {\
00693                 __MIOPACKET(IOCMD,$SYS_IOBS_L,$SYS_IORDFLG_HMIRROR);\
00694         }\
00695         else if( (tcode==NLCC_COMPLEX) || (tcode==NLCC_VECTOR) || (tcode==NLCC_VFLOAT) || (tcode==NLCC_VINT) || (tcode==NLCC_VUINT) ) {\
00696                 __MIOPACKET(IOCMD,$SYS_IOBS_V,$SYS_IORDFLG_NOP);\
00697         }\
00698         __MFEND
00699 
00700 //--------------------------------------------------------------------------------------------------
00701 
00702 #ifdef __HAS_MAIN
00703 #define BODY(args) args
00704 #else
00705 #define BODY(args) ;
00706 #endif
00707 
00708 #ifndef __HAS_MAIN
00709 extern size_t slread(int x1, int y1, int z1, ...);
00710 #else
00711 #if !defined(__cflow_processed) || defined(_uses_slread_slice_stdio_os1_h)
00712 size_t slread(int x1, int y1, int z1, ...) BODY({ _MFIO($SYS_IOCMD_BRD,(va_arg(ap, FILE*)));})  
00713 #endif // slread()
00714 #endif // Has Main
00715 
00716 #ifndef __HAS_MAIN
00717 extern size_t mfread(int x1, int y1, int z1, ...);
00718 #else
00719 #if !defined(__cflow_processed) || defined(_uses_mfread_slice_stdio_os1_h)
00720 size_t mfread(int x1, int y1, int z1, ...) BODY({ _MFIO($SYS_IOCMD_MRD,(va_arg(ap, FILE*)));})  
00721 #endif // mfread()
00722 #endif // Has Main
00723 
00724 #ifndef __HAS_MAIN
00725 extern size_t mfwrite(int x1, int y1, int z1, ...);
00726 #else
00727 #if !defined(__cflow_processed) || defined(_uses_mfwrite_slice_stdio_os1_h)
00728 size_t mfwrite(int x1, int y1, int z1, ...) BODY({ _MFIO($SYS_IOCMD_SWR,(va_arg(ap, FILE*)));}) 
00729 #endif // mfwrite()
00730 #endif // Has Main
00731 
00732 #undef BODY
00733 
00734 
00735 //-----------------------------------------------------------------------------------------
00760 //--------------------------------------------------------------------------------------------------
00761 #define mscanf(ARGS...) mfscanf(stdin, ##ARGS)
00762 
00763 #ifndef __HAS_MAIN
00764 extern int mfscanf(FILE *stream, int x1, int y1, int z1, ...);
00765 #else
00766 #if !defined(__cflow_processed) || defined(_uses_mfscanf_slice_stdio_os1_h)
00767 int mfscanf(FILE *stream, int x1, int y1, int z1, ...)
00768 {
00769 #pragma localmem
00770 
00771   int         iocnt;
00772   vector int  argcnt, arginfo, sys_rval;
00773   va_list     ap; 
00774   int         x2 = x1, y2 = y1, z2 = z1;
00775   char        *format;
00776 
00777   if(! stream || stream->mode == _SYS_IOMODE_CLOSED) {
00778     errno = EBADF;
00779     return 0;
00780   }
00781 
00782   va_start(ap, z1);
00783 
00784   argcnt = __builtin_argcount();
00785   iocnt  = argcnt.lo - 5;
00786 
00787   if (iocnt < 0) {                      // insufficient number of arguments
00788     errno = EINVAL;
00789     return 0;
00790   }
00791 
00792   // check if more node coordinates follow
00793   // by testing the argument type 
00794   //   if 'int' : read 3 more coords
00795   //   else     : assume it's the 'format' arg.
00796   { va_list     ap2; 
00797     vector int  arginfo; 
00798     void        *ptr = _va_ptr(ap2);
00799 
00800     va_copy(ap2, ap);
00801     arginfo = _va_info(ap2);
00802     if (arginfo.hi == NLCC_INT) {
00803       x2 = va_arg(ap, int);
00804       y2 = va_arg(ap, int);
00805       z2 = va_arg(ap, int);
00806       iocnt -= 3;
00807     }
00808   }
00809 
00810   format = va_arg(ap, char *);
00811 
00812   asm("\t!! begin mscanf()\n");
00813 
00814   // set file descriptor, slice and output format string
00815   asm("\t$io_start\n"
00816       "\t$io_fd(0.%0)\n"
00817       "\t$io_slice(0.%3, 0.%4, 0.%5, 0.%6, 0.%7, 0.%8)\n"\
00818       "\t$io_cnt_set(%2)\n"
00819       "\t\\equ $cmd   $SYS_IOCMD_MSCF\n"
00820       "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00821       "\t\\equ $dev   $SYS_IODEV_MEM\n"
00822       "\t\\equ $bs    $SYS_IOBS_V\n"
00823       "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00824       "\t$io_packet($cmd, $fmt, $rdflg, $dev, 0, $bs, 0.%1 )"
00825       : : "r" (stream->fd), "r" (format), "r" (iocnt),
00826           "r" (x1), "r" (y1), "r" (z1), 
00827           "r" (x2), "r" (y2), "r" (z2));
00828 
00829   asm("\t$io_setloopflg\n");
00830 
00831   for(; iocnt > 0; iocnt--) {
00832     int size = _va_info(ap);
00833     void *ptr = *(void**) (_va_ptr(ap));
00834     _va_skip( ap, size );
00835     asm("\t$io_cnt_decr\n"
00836         "\t\\equ $cmd   $SYS_IOCMD_MSCF\n"
00837         "\t\\equ $fmt   $SYS_IOFMT_BIN\n"
00838         "\t\\equ $dev   $SYS_IODEV_MEM\n"
00839         "\t\\equ $l     1\n"
00840         "\t\\equ $bs    $SYS_IOBS_V\n"
00841         "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00842         "\t$io_packet($cmd, $fmt, $rdflg, $dev, $l, $bs, 0.%0)\n"
00843         : :  "r" (ptr));
00844   }
00845   va_end(ap);
00846 
00847   asm("\t$io_cnt_clear\n"
00848       "\t$io_end\n"
00849       "\t!! end mfscanf()\n"
00850       "\tlmtr %0 $MEM_SYS_RVAL\n"
00851       : "=r" (sys_rval) );
00852 
00853   where (sys_rval.lo)
00854     stream->err = 1;
00855 
00856   return (int) (sys_rval.hi);
00857 }
00858 #endif // mfscanf()
00859 #endif // Has Main
00860 
00861 #endif    /* _NLIBC_OS1_SLICE_STDIO_H */

Generated on Fri Jul 14 10:51:31 2006 for nlibc by doxygen 1.3.5