Changeset 743 for soft


Ignore:
Timestamp:
Dec 12, 2015, 7:10:24 PM (8 years ago)
Author:
alain
Message:

Introducing the giet_fat_printf() system call.

Location:
soft/giet_vm/giet_libs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_libs/stdio.c

    r735 r743  
    1 //////////////////////////////////////////////////////////////////////////////
     1/////////////////////////////////////////////////////////////////////////////////////
    22// File     : stdio.c         
    33// Date     : 01/04/2010
    44// Author   : alain greiner & Joel Porquet
    55// Copyright (c) UPMC-LIP6
    6 //////////////////////////////////////////////////////////////////////////////
     6/////////////////////////////////////////////////////////////////////////////////////
    77
    88#include <stdarg.h>
     
    1010#include <giet_config.h>
    1111
    12 //////////////////////////////////////////////////////////////////////////////
    13 //                     MIPS32 related system calls
    14 //////////////////////////////////////////////////////////////////////////////
    15 
    16 ////////////////////////////////////////////
    17 void giet_proc_xyp( unsigned int* cluster_x,
    18                     unsigned int* cluster_y,
    19                     unsigned int* lpid )
    20 {
    21     sys_call( SYSCALL_PROC_XYP,
    22               (unsigned int)cluster_x,
    23               (unsigned int)cluster_y,
    24               (unsigned int)lpid,
    25                0 );
    26 }
    27 
    28 ////////////////////////////
    29 unsigned int giet_proctime()
    30 {
    31     return (unsigned int)sys_call( SYSCALL_PROC_TIME,
    32                                    0, 0, 0, 0 );
    33 }
    34 
    35 ////////////////////////
    36 unsigned int giet_rand()
    37 {
    38     unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
    39                                              0, 0, 0, 0);
    40     if ((x & 0xF) > 7)
    41     {
    42         return (x*x & 0xFFFF);
     12/////////////////////////////////////////////////////////////////////////////////////
     13// This function is called by both the giet_tty_printf() and
     14// the giet_fat_printf() system calls.
     15// It analyse the <format> and <args> arguments and returns a byte stream
     16// in the <stream> buffer. The TO_STREAM macro checks buffer overflow.
     17// It returns number of written bytes in case of success.
     18// It returns 0xFFFFFFFF in case of error (illegal format, or buffer overflow).
     19/////////////////////////////////////////////////////////////////////////////////////
     20
     21#define TO_STREAM(x) do { stream[ps] = (x); ps++; if(ps==maxlen) return -1; } while(0);
     22
     23static unsigned int xprintf( char*        stream,
     24                             unsigned int maxlen,
     25                             char*        format,
     26                             va_list*     args)
     27{
     28    unsigned int ps = 0;    // write pointer to the stream buffer
     29
     30xprintf_text:
     31
     32    while ( *format != 0 )
     33    {
     34
     35        if (*format == '%')   // copy argument to stream
     36        {
     37            format++;
     38            goto xprintf_arguments;
     39        }
     40        else                  // copy one char to stream
     41        {
     42            TO_STREAM( *format );
     43            format++;
     44        }
    4345    }
    44     else
    45     {
    46         return (x*x*x & 0xFFFF);
    47     }
    48 }
    49 
    50 //////////////////////////////////////////////////////////////////////////////
    51 //                    Threads related  system calls
    52 //////////////////////////////////////////////////////////////////////////////
    53 
    54 #define THREAD_CMD_PAUSE     0
    55 #define THREAD_CMD_RESUME    1
    56 #define THREAD_CMD_CONTEXT   2
    57 
    58 //////////////////////////////////////////////////////////
    59 int giet_pthread_create( pthread_t*       buffer,
    60                          pthread_attr_t*  attr,
    61                          void*            function,
    62                          void*            arg )
    63 {
    64     return sys_call( SYSCALL_PTHREAD_CREATE,
    65                      (unsigned int)buffer,
    66                      (unsigned int)attr,
    67                      (unsigned int)function,
    68                      (unsigned int)arg );
    69 }             
    70 
    71 //////////////////////////////////////
    72 void giet_pthread_exit( void* string )
    73 {
    74     sys_call( SYSCALL_PTHREAD_EXIT,
    75               (unsigned int)string,
    76               0, 0, 0 );
    77 }
    78 
    79 ////////////////////////////////////////
    80 int giet_pthread_join( pthread_t  trdid,
    81                        void**     ptr )
    82 {
    83     return sys_call( SYSCALL_PTHREAD_JOIN,
    84                      trdid,
    85                      (unsigned int)ptr,
    86                      0, 0 );
    87 }
    88 
    89 ///////////////////////////////////////
    90 int giet_pthread_kill( pthread_t trdid,
    91                        int       signal )
    92 {
    93     return sys_call( SYSCALL_PTHREAD_KILL,
    94                      trdid,
    95                      signal,
    96                      0, 0 );
    97 }
    98 
    99 /////////////////////////
    100 void giet_pthread_yield()
    101 {
    102     sys_call( SYSCALL_PTHREAD_YIELD,
    103               0, 0, 0, 0 );
    104 }
    105 
    106 /////////////////////////////////////////////////
    107 void giet_pthread_assert( unsigned int condition,
    108                           char*        string )
    109 {
    110     if ( condition == 0 ) giet_pthread_exit( string );
    111 }
    112 
    113 ////////////////////////////////////////////////
    114 void giet_pthread_control( unsigned int command, 
    115                            char*        vspace_name,
    116                            char*        thread_name )
    117 {
    118     int ret = sys_call( SYSCALL_PTHREAD_CONTROL,
    119                         command,
    120                         (unsigned int) vspace_name,
    121                         (unsigned int) thread_name,
    122                         0 );
    123 
    124     if ( ret == SYSCALL_VSPACE_NOT_FOUND )
    125     {
    126         giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
    127                         "vspace %s not found\n", vspace_name );
    128     }
    129     if ( ret == SYSCALL_THREAD_NOT_FOUND )
    130     {
    131         giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
    132                         "thread %s not found\n", thread_name );
    133     }
    134     if ( ret == SYSCALL_UNCOHERENT_THREAD_CONTEXT )
    135     {
    136         giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
    137                         "uncoherent context for thread %s\n", thread_name );
    138     }
    139     if ( ret == SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE )
    140     {
    141         giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
    142                         "illegal command type %d\n", command );
    143     }
    144 }
    145 
    146 
    147 //////////////////////////////////////////////////////////////////////////////
    148 //                    Applications related system calls
    149 //////////////////////////////////////////////////////////////////////////////
    150 
    151 ///////////////////////////////////////
    152 int giet_kill_application( char* name )
    153 {
    154     return ( sys_call( SYSCALL_KILL_APP,
    155                        (unsigned int)name,
    156                        0, 0, 0 ) );
    157 }
    158 
    159 ///////////////////////////////////////
    160 int giet_exec_application( char* name )
    161 {
    162     return ( sys_call( SYSCALL_EXEC_APP,
    163                        (unsigned int)name,
    164                        0, 0, 0 ) );
    165 }
    166 
    167 ///////////////////////////////////////////
    168 void giet_applications_status( char* name )
    169 {
    170     sys_call( SYSCALL_APPS_STATUS,
    171               (unsigned int)name,
    172               0, 0, 0 );
    173 }
    174 
    175 //////////////////////////////////////////////////////////////////////////////
    176 //                    Coprocessors related system calls
    177 //////////////////////////////////////////////////////////////////////////////
    178 
    179 ///////////////////////////////////////////////////
    180 void giet_coproc_alloc( unsigned int   cluster_xy,
    181                         unsigned int   coproc_type,
    182                         unsigned int*  coproc_info )
    183 {
    184     if ( sys_call( SYSCALL_COPROC_ALLOC,
    185                    cluster_xy,
    186                    coproc_type,
    187                    (unsigned int)coproc_info,
    188                    0 ) ) 
    189         giet_pthread_exit("error in giet_coproc_alloc()");
    190 }
    191 
    192 //////////////////////////////////////////////////
    193 void giet_coproc_release( unsigned int cluster_xy,
    194                           unsigned int coproc_type )
    195 {
    196     if ( sys_call( SYSCALL_COPROC_RELEASE,
    197                    cluster_xy,
    198                    coproc_type,
    199                    0 , 0 ) ) 
    200         giet_pthread_exit("error in giet_coproc_release()");
    201 }
    202 
    203 //////////////////////////////////////////////////////////////////
    204 void giet_coproc_channel_init( unsigned int            cluster_xy,
    205                                unsigned int            coproc_type,
    206                                unsigned int            channel,
    207                                giet_coproc_channel_t*  desc )
    208 {
    209     if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
    210                    cluster_xy,
    211                    coproc_type,
    212                    channel,
    213                    (unsigned int)desc ) )
    214         giet_pthread_exit("error in giet_coproc_channel_init()");
    215 }
    216 
    217 //////////////////////////////////////////////
    218 void giet_coproc_run( unsigned int cluster_xy,
    219                       unsigned int coproc_type )
    220 {
    221     if ( sys_call( SYSCALL_COPROC_RUN,
    222                    cluster_xy,
    223                    coproc_type,
    224                    0 , 0 ) )
    225         giet_pthread_exit("error in giet_coproc_run()");
    226 }
    227 
    228 ////////////////////////////////////////////////////
    229 void giet_coproc_completed( unsigned int cluster_xy,
    230                             unsigned int coproc_type )
    231 {
    232     if ( sys_call( SYSCALL_COPROC_COMPLETED,
    233                    cluster_xy,
    234                    coproc_type,
    235                    0 , 0 ) )
    236         giet_pthread_exit("error in giet_coproc_completed");
    237 }
    238 
    239 
    240 //////////////////////////////////////////////////////////////////////////////
    241 //                    TTY device related system calls
    242 //////////////////////////////////////////////////////////////////////////////
    243 
    244 //////////////////////////////////////////
    245 void giet_tty_alloc( unsigned int shared )
    246 {
    247     if ( sys_call( SYSCALL_TTY_ALLOC,
    248                    shared,
    249                    0, 0, 0 ) )  giet_pthread_exit("error in giet_tty_alloc()");
    250 }
    251 
    252 ////////////////////////////////////////////////////////////////////////
    253 static  int __printf( char* format, unsigned int channel, va_list* args)
    254 {
    255     int ret;                    // return value from the syscall
    256     enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers;
    257 
    258 printf_text:
    259 
    260     while (*format)
    261     {
    262         unsigned int i;
    263         for (i = 0 ; format[i] && (format[i] != '%') ; i++);
    264         if (i)
    265         {
    266             ret = sys_call(SYSCALL_TTY_WRITE,
    267                            (unsigned int)format,
    268                            i,
    269                            channel,
    270                            0);
    271 
    272             if (ret != i) goto return_error;
    273 
    274             format += i;
    275         }
    276         if (*format == '%')
    277         {
    278             format++;
    279             modifiers = NO_MOD;
    280             goto printf_arguments;
    281         }
    282     }
    283 
    284     return 0;
    285 
    286 printf_arguments:
    287 
    288     {
    289         char              buf[30];
    290         char *            pbuf;
    291         unsigned int      len = 0;
     46
     47    return ps;
     48
     49xprintf_arguments:
     50
     51    {
     52        char              buf[30];    // buffer to display one number
     53        char *            pbuf;       // pointer on first char to display
     54        unsigned int      len = 0;    // number of char to display
    29255        static const char HexaTab[] = "0123456789ABCDEF";
    29356        unsigned int      i;
    29457       
    295         /* Ignored fields : width and precision */
    296         for (; *format >= '0' && *format <= '9'; format++);
    297 
    298         switch (*format++)
    299         {
    300             case ('%'):
     58        // Ignore fields width and precision
     59        for ( ; *format >= '0' && *format <= '9'; format++ );
     60
     61        switch (*format)
     62        {
     63            case ('c'):             // char conversion
    30164            {
    302                 len = 1;
    303                 pbuf = "%";
     65                int val = va_arg( *args, int );
     66                buf[0] = val;
     67                pbuf   = buf;
     68                len    = 1;
    30469                break;
    30570            }
    306             case ('c'):             /* char conversion */
     71            case ('d'):             // decimal signed integer
    30772            {
    30873                int val = va_arg( *args, int );
    309                 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
    310                
    311                 len = 1;
    312                 buf[0] = val;
    313                 pbuf = &buf[0];
    314                 break;
    315             }
    316             case ('d'):             /* decimal signed integer */
    317             {
    318                 int val = va_arg( *args, int );
    319                
    320                 if (modifiers == LL_MOD) goto return_error; // 64 bits not supported
    321                
    32274                if (val < 0)
    32375                {
     76                    TO_STREAM( '-' );
    32477                    val = -val;
    325                     ret = sys_call(SYSCALL_TTY_WRITE,
    326                                    (unsigned int)"-",
    327                                    1,
    328                                    channel,
    329                                    0);
    330                     if (ret != 1) goto return_error;
    33178                }
    33279                for(i = 0; i < 10; i++)
    33380                {
     81
    33482                    buf[9 - i] = HexaTab[val % 10];
    33583                    if (!(val /= 10)) break;
     
    33987                break;
    34088            }
    341             case ('u'):             /* decimal unsigned integer */
     89            case ('u'):             // decimal unsigned integer
    34290            {
    343                 if (modifiers != LL_MOD) //32 bits integer
    344                 {
    345                     unsigned int val = va_arg( *args, unsigned int );
    346                     for(i = 0; i < 10; i++)
    347                     {
    348                         buf[9 - i] = HexaTab[val % 10];
    349                         if (!(val /= 10)) break;
    350                     }
    351                     len =  i + 1;
    352                     pbuf = &buf[9 - i];
    353                     break;
    354                 }
    355                 //64 bits : base 10 unsupported : continue to hexa
     91                unsigned int val = va_arg( *args, unsigned int );
     92                for(i = 0; i < 10; i++)
     93                {
     94                    buf[9 - i] = HexaTab[val % 10];
     95                    if (!(val /= 10)) break;
     96                }
     97                len =  i + 1;
     98                pbuf = &buf[9 - i];
     99                break;
    356100            }
    357             case ('x'):
    358             case ('X'):             /* hexadecimal integer */
     101            case ('x'):             // 32 bits hexadecimal
     102            case ('l'):             // 64 bits hexadecimal
    359103            {
     104                unsigned int       imax;
    360105                unsigned long long val;
    361                 int imax;
    362                
    363                 if (modifiers == LL_MOD) // 64 bits
     106               
     107                if ( *format == 'l' )   // 64 bits
    364108                {
    365109                    val = va_arg( *args, unsigned long long);
    366                    
    367                     // if asked to print in base 10, can do only if it fits in 32 bits
    368                     if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL)))
    369                     {
    370                         unsigned int uintv = (unsigned int) val;
    371                        
    372                         for(i = 0; i < 10; i++)
    373                         {
    374                             buf[9 - i] = HexaTab[uintv % 10];
    375                             if (!(uintv /= 10)) break;
    376                         }
    377                         len =  i + 1;
    378                         pbuf = &buf[9 - i];
    379                         break;
    380                     }
    381                    
    382110                    imax = 16;
    383111                }
    384                 else //32 bits
     112                else                    // 32 bits
    385113                {
    386114                    val = va_arg( *args, unsigned int);
     
    388116                }
    389117               
    390                 ret = sys_call(SYSCALL_TTY_WRITE,
    391                                (unsigned int)"0x",
    392                                2,
    393                                channel,
    394                                0);
    395                 if (ret != 2) goto return_error;
     118                TO_STREAM( '0' );
     119                TO_STREAM( 'x' );
    396120               
    397121                for(i = 0; i < imax; i++)
     
    407131            {
    408132                char* str = va_arg( *args, char* );
    409                
    410                 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
    411                
    412                 while (str[len])
    413                 {
    414                     len++;
    415                 }
     133                while (str[len]) { len++; }
    416134                pbuf = str;
    417135                break;
     
    419137            case ('e'):
    420138            case ('f'):
    421             case ('g'):             /* IEEE754 64 bits */
     139            case ('g'):             // IEEE754 64 bits
    422140            {
    423141                union
     
    429147                val.d = va_arg( *args, double );
    430148               
    431                 unsigned long long digits = val.ull & 0xFFFFFFFFFFFFFULL;    //get mantissa
    432                
    433                 unsigned int
    434                     base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52), //get exposant
    435                     intp = (unsigned int)val.d,         //get integer part of the float
    436                     decp;
     149                unsigned long long digits;
     150                digits = val.ull & 0xFFFFFFFFFFFFFULL;    // mantisse
     151               
     152                unsigned int base;
     153                base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52); // exp
     154
     155                unsigned int intp;
     156                intp = (unsigned int)val.d;         // integer part
     157
     158                unsigned int decp;                  // decimal part
    437159               
    438160                int isvalue = 0;
    439161               
    440                 if (base == 0x7FF) //special value
    441                 {
    442                     if (digits & 0xFFFFFFFFFFFFFULL)
     162                if (base == 0x7FF) // special values
     163                {
     164                    if (digits & 0xFFFFFFFFFFFFFULL)  // Not a Number
    443165                    {
    444                         /* Not a Number */
    445166                        buf[0] = 'N';
    446167                        buf[1] = 'a';
     
    449170                        pbuf = buf;
    450171                    }
    451                     else
     172                    else                              // infinite
    452173                    {
    453174                        /* inf */
     
    462183                }
    463184               
    464                 if (val.ull & 0x8000000000000000ULL)
    465                 {
    466                     /* negative */
    467                     ret = sys_call(SYSCALL_TTY_WRITE,
    468                                 (unsigned int)"-",
    469                                 1,
    470                                 channel,
    471                                 0);
    472                     if (ret != 1) goto return_error;
     185                if (val.ull & 0x8000000000000000ULL)  // negative
     186                {
     187                    TO_STREAM( '-' );
    473188                    val.d = val.d * -1;
    474189                }
    475                 else
    476                 {
    477                     /* positive */
    478                     ret = sys_call(SYSCALL_TTY_WRITE,
    479                                 (unsigned int)"+",
    480                                 1,
    481                                 channel,
    482                                 0);
    483                     if (ret != 1) goto return_error;
    484                 }
    485                
    486                 if (val.d > 0xFFFFFFFF)
    487                 {
    488                     /* overflow */
     190                else                                  // positive
     191                {
     192                    TO_STREAM( '+' );
     193                }
     194               
     195                if (val.d > 0xFFFFFFFF)              // overflow
     196                {
    489197                    buf[0] = 'B';
    490198                    buf[1] = 'I';
     
    517225                if (!isvalue)
    518226                {
    519                     if (val.d != 0)
     227                    if (val.d != 0)                   // underflow
    520228                    {
    521                         /* underflow */
    522229                        buf[0] = 'T';
    523230                        buf[1] = 'I';
     
    531238                break;
    532239            }
    533             case ('l'):
    534                 switch (modifiers)
    535                 {
    536                     case NO_MOD:
    537                         modifiers = L_MOD;
    538                         goto printf_arguments;
    539240                   
    540                     case L_MOD:
    541                         modifiers = LL_MOD;
    542                         goto printf_arguments;
    543                    
    544                     default:
    545                         goto return_error;
    546                 }
    547 
    548             /* Ignored fields : width and precision */
    549             case ('.'): goto printf_arguments;
    550                
    551             default:
    552                 goto return_error;
    553         }
    554 
    555         ret = sys_call(SYSCALL_TTY_WRITE,
    556                        (unsigned int)pbuf,
    557                        len,
    558                        channel,
    559                        0);
    560         if (ret != len)  goto return_error;
     241            default:       // unsupported argument type
     242            {
     243                return -1;
     244            }
     245        }  // end switch on  argument type
     246
     247        format++;
     248
     249        // copy argument to stream
     250        for( i = 0 ; i < len ; i++ )
     251        {
     252            TO_STREAM( pbuf[i] );
     253        }
    561254       
    562         goto printf_text;
     255        goto xprintf_text;
    563256    }
    564257
    565 return_error:
    566     return 1;
    567 } // end __printf()
    568 
     258} // end xprintf()
     259
     260
     261//////////////////////////////////////////////////////////////////////////////
     262//                     MIPS32 related system calls
     263//////////////////////////////////////////////////////////////////////////////
     264
     265////////////////////////////////////////////
     266void giet_proc_xyp( unsigned int* cluster_x,
     267                    unsigned int* cluster_y,
     268                    unsigned int* lpid )
     269{
     270    sys_call( SYSCALL_PROC_XYP,
     271              (unsigned int)cluster_x,
     272              (unsigned int)cluster_y,
     273              (unsigned int)lpid,
     274               0 );
     275}
     276
     277////////////////////////////
     278unsigned int giet_proctime()
     279{
     280    return (unsigned int)sys_call( SYSCALL_PROC_TIME,
     281                                   0, 0, 0, 0 );
     282}
     283
     284////////////////////////
     285unsigned int giet_rand()
     286{
     287    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
     288                                             0, 0, 0, 0);
     289    if ((x & 0xF) > 7)
     290    {
     291        return (x*x & 0xFFFF);
     292    }
     293    else
     294    {
     295        return (x*x*x & 0xFFFF);
     296    }
     297}
     298
     299//////////////////////////////////////////////////////////////////////////////
     300//                    Threads related  system calls
     301//////////////////////////////////////////////////////////////////////////////
     302
     303#define THREAD_CMD_PAUSE     0
     304#define THREAD_CMD_RESUME    1
     305#define THREAD_CMD_CONTEXT   2
     306
     307//////////////////////////////////////////////////////////
     308int giet_pthread_create( pthread_t*       buffer,
     309                         pthread_attr_t*  attr,
     310                         void*            function,
     311                         void*            arg )
     312{
     313    return sys_call( SYSCALL_PTHREAD_CREATE,
     314                     (unsigned int)buffer,
     315                     (unsigned int)attr,
     316                     (unsigned int)function,
     317                     (unsigned int)arg );
     318}             
     319
     320//////////////////////////////////////
     321void giet_pthread_exit( void* string )
     322{
     323    sys_call( SYSCALL_PTHREAD_EXIT,
     324              (unsigned int)string,
     325              0, 0, 0 );
     326}
     327
     328////////////////////////////////////////
     329int giet_pthread_join( pthread_t  trdid,
     330                       void**     ptr )
     331{
     332    return sys_call( SYSCALL_PTHREAD_JOIN,
     333                     trdid,
     334                     (unsigned int)ptr,
     335                     0, 0 );
     336}
     337
     338///////////////////////////////////////
     339int giet_pthread_kill( pthread_t trdid,
     340                       int       signal )
     341{
     342    return sys_call( SYSCALL_PTHREAD_KILL,
     343                     trdid,
     344                     signal,
     345                     0, 0 );
     346}
     347
     348/////////////////////////
     349void giet_pthread_yield()
     350{
     351    sys_call( SYSCALL_PTHREAD_YIELD,
     352              0, 0, 0, 0 );
     353}
     354
     355/////////////////////////////////////////////////
     356void giet_pthread_assert( unsigned int condition,
     357                          char*        string )
     358{
     359    if ( condition == 0 ) giet_pthread_exit( string );
     360}
     361
     362////////////////////////////////////////////////
     363void giet_pthread_control( unsigned int command, 
     364                           char*        vspace_name,
     365                           char*        thread_name )
     366{
     367    int ret = sys_call( SYSCALL_PTHREAD_CONTROL,
     368                        command,
     369                        (unsigned int) vspace_name,
     370                        (unsigned int) thread_name,
     371                        0 );
     372
     373    if ( ret == SYSCALL_VSPACE_NOT_FOUND )
     374    {
     375        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
     376                        "vspace %s not found\n", vspace_name );
     377    }
     378    if ( ret == SYSCALL_THREAD_NOT_FOUND )
     379    {
     380        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
     381                        "thread %s not found\n", thread_name );
     382    }
     383    if ( ret == SYSCALL_UNCOHERENT_THREAD_CONTEXT )
     384    {
     385        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
     386                        "uncoherent context for thread %s\n", thread_name );
     387    }
     388    if ( ret == SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE )
     389    {
     390        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
     391                        "illegal command type %d\n", command );
     392    }
     393}
     394
     395
     396//////////////////////////////////////////////////////////////////////////////
     397//                    Applications related system calls
     398//////////////////////////////////////////////////////////////////////////////
     399
     400///////////////////////////////////////
     401int giet_kill_application( char* name )
     402{
     403    return ( sys_call( SYSCALL_KILL_APP,
     404                       (unsigned int)name,
     405                       0, 0, 0 ) );
     406}
     407
     408///////////////////////////////////////
     409int giet_exec_application( char* name )
     410{
     411    return ( sys_call( SYSCALL_EXEC_APP,
     412                       (unsigned int)name,
     413                       0, 0, 0 ) );
     414}
     415
     416///////////////////////////////////////////
     417void giet_applications_status( char* name )
     418{
     419    sys_call( SYSCALL_APPS_STATUS,
     420              (unsigned int)name,
     421              0, 0, 0 );
     422}
     423
     424//////////////////////////////////////////////////////////////////////////////
     425//                    Coprocessors related system calls
     426//////////////////////////////////////////////////////////////////////////////
     427
     428///////////////////////////////////////////////////
     429void giet_coproc_alloc( unsigned int   cluster_xy,
     430                        unsigned int   coproc_type,
     431                        unsigned int*  coproc_info )
     432{
     433    if ( sys_call( SYSCALL_COPROC_ALLOC,
     434                   cluster_xy,
     435                   coproc_type,
     436                   (unsigned int)coproc_info,
     437                   0 ) ) 
     438        giet_pthread_exit("error in giet_coproc_alloc()");
     439}
     440
     441//////////////////////////////////////////////////
     442void giet_coproc_release( unsigned int cluster_xy,
     443                          unsigned int coproc_type )
     444{
     445    if ( sys_call( SYSCALL_COPROC_RELEASE,
     446                   cluster_xy,
     447                   coproc_type,
     448                   0 , 0 ) ) 
     449        giet_pthread_exit("error in giet_coproc_release()");
     450}
     451
     452//////////////////////////////////////////////////////////////////
     453void giet_coproc_channel_init( unsigned int            cluster_xy,
     454                               unsigned int            coproc_type,
     455                               unsigned int            channel,
     456                               giet_coproc_channel_t*  desc )
     457{
     458    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
     459                   cluster_xy,
     460                   coproc_type,
     461                   channel,
     462                   (unsigned int)desc ) )
     463        giet_pthread_exit("error in giet_coproc_channel_init()");
     464}
     465
     466//////////////////////////////////////////////
     467void giet_coproc_run( unsigned int cluster_xy,
     468                      unsigned int coproc_type )
     469{
     470    if ( sys_call( SYSCALL_COPROC_RUN,
     471                   cluster_xy,
     472                   coproc_type,
     473                   0 , 0 ) )
     474        giet_pthread_exit("error in giet_coproc_run()");
     475}
     476
     477////////////////////////////////////////////////////
     478void giet_coproc_completed( unsigned int cluster_xy,
     479                            unsigned int coproc_type )
     480{
     481    if ( sys_call( SYSCALL_COPROC_COMPLETED,
     482                   cluster_xy,
     483                   coproc_type,
     484                   0 , 0 ) )
     485        giet_pthread_exit("error in giet_coproc_completed");
     486}
     487
     488
     489//////////////////////////////////////////////////////////////////////////////
     490//                    TTY device related system calls
     491//////////////////////////////////////////////////////////////////////////////
     492
     493//////////////////////////////////////////
     494void giet_tty_alloc( unsigned int shared )
     495{
     496    if ( sys_call( SYSCALL_TTY_ALLOC,
     497                   shared,
     498                   0, 0, 0 ) )  giet_pthread_exit("error in giet_tty_alloc()");
     499}
    569500
    570501////////////////////////////////////////
    571502void giet_tty_printf( char* format, ...)
    572503{
    573     va_list args;
     504    va_list      args;
     505    char         stream[4096];
     506    unsigned int length;
    574507
    575508    va_start( args, format );
    576     int ret = __printf(format, 0xFFFFFFFF, &args);
     509    length = xprintf( stream, 4096, format, &args );
    577510    va_end( args );
    578511
    579     if (ret)
    580     {
    581         giet_pthread_exit("error in giet_tty_printf()");
    582     }
    583 } // end giet_tty_printf()
     512    if ( length == 0xFFFFFFFF ) giet_pthread_exit("illegal format in giet_tty_printf()");
     513   
     514    if ( sys_call( SYSCALL_TTY_WRITE,
     515                   (unsigned int)stream,   // buffer address
     516                   length,                 // number of characters
     517                   0xFFFFFFFF,             // channel index from thread context
     518                   0) != length )   giet_pthread_exit("error in giet_tty_printf()");
     519
     520}
    584521
    585522/////////////////////////////////
     
    664601    buf[index] = 0;
    665602
    666 }   // end giet_tty_gets()
     603}
    667604
    668605///////////////////////////////////////
     
    778715        *val = 0;
    779716    }
    780 }   // end giet_tty_getw()
     717}
    781718
    782719
     
    11261063}
    11271064
    1128 ////////////////////////////////////
     1065//////////////////////////////////////////
    11291066int giet_fat_readdir( unsigned int  fd_id,
    11301067                      fat_dirent_t* entry )
     
    11361073}
    11371074
     1075/////////////////////////////////////////
     1076int giet_fat_fprintf( unsigned int fd_id,
     1077                      char*        format,
     1078                      ... );
     1079{
     1080    va_list      args;
     1081    char         stream[4096];
     1082    unsigned int length;
     1083
     1084    va_start( args, format );
     1085    count = xprintf( stream, 4096, format, &args );
     1086    va_end( args );
     1087
     1088    if ( length == 0xFFFFFFFF ) giet_pthread_exit("illegal format in giet_fat_fprintf()");
     1089
     1090    return sys_call( SYSCALL_FAT_WRITE,
     1091                     fd_id,
     1092                     (unsigned int)stream,
     1093                     count,
     1094                     0 );      // no physical addressing required
     1095}
    11381096
    11391097
  • soft/giet_vm/giet_libs/stdio.h

    r735 r743  
    387387                             fat_dirent_t* entry );
    388388
     389extern int giet_fat_fprintf( unsigned int  fd_id,
     390                             char*         format, ... );
     391
    389392//////////////////////////////////////////////////////////////////////////
    390393//                    Miscelaneous system calls
Note: See TracChangeset for help on using the changeset viewer.