source: soft/giet_vm/giet_libs/stdio.c

Last change on this file was 771, checked in by alain, 8 years ago

Introducing the generic xprintf() function, called by the various *printf() functions.

  • Property svn:executable set to *
File size: 30.1 KB
RevLine 
[743]1/////////////////////////////////////////////////////////////////////////////////////
[258]2// File     : stdio.c         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
[743]6/////////////////////////////////////////////////////////////////////////////////////
[258]7
8#include <stdarg.h>
9#include <stdio.h>
[771]10#include <stdlib.h>
[267]11#include <giet_config.h>
[258]12
[743]13
[521]14//////////////////////////////////////////////////////////////////////////////
[709]15//                     MIPS32 related system calls
[521]16//////////////////////////////////////////////////////////////////////////////
[390]17
[438]18////////////////////////////////////////////
[431]19void giet_proc_xyp( unsigned int* cluster_x,
20                    unsigned int* cluster_y,
21                    unsigned int* lpid )
[390]22{
[438]23    sys_call( SYSCALL_PROC_XYP,
[431]24              (unsigned int)cluster_x,
25              (unsigned int)cluster_y,
26              (unsigned int)lpid,
27               0 );
[390]28}
29
[438]30////////////////////////////
31unsigned int giet_proctime() 
[390]32{
[438]33    return (unsigned int)sys_call( SYSCALL_PROC_TIME, 
34                                   0, 0, 0, 0 );
[390]35}
36
[438]37////////////////////////
38unsigned int giet_rand() 
[390]39{
[438]40    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
41                                             0, 0, 0, 0);
[390]42    if ((x & 0xF) > 7) 
43    {
44        return (x*x & 0xFFFF);
45    }
46    else 
47    {
48        return (x*x*x & 0xFFFF);
49    }
50}
51
[521]52//////////////////////////////////////////////////////////////////////////////
[709]53//                    Threads related  system calls
[521]54//////////////////////////////////////////////////////////////////////////////
[438]55
[709]56#define THREAD_CMD_PAUSE     0
57#define THREAD_CMD_RESUME    1
58#define THREAD_CMD_CONTEXT   2
59
60//////////////////////////////////////////////////////////
61int giet_pthread_create( pthread_t*       buffer,
62                         pthread_attr_t*  attr,
63                         void*            function,
64                         void*            arg )
[438]65{
[709]66    return sys_call( SYSCALL_PTHREAD_CREATE,
67                     (unsigned int)buffer,
68                     (unsigned int)attr,
69                     (unsigned int)function,
70                     (unsigned int)arg );
71}             
72
73//////////////////////////////////////
74void giet_pthread_exit( void* string ) 
75{
76    sys_call( SYSCALL_PTHREAD_EXIT,
77              (unsigned int)string,
78              0, 0, 0 );
[438]79}
80
[709]81////////////////////////////////////////
82int giet_pthread_join( pthread_t  trdid,
83                       void**     ptr )
[438]84{
[709]85    return sys_call( SYSCALL_PTHREAD_JOIN,
86                     trdid,
87                     (unsigned int)ptr,
88                     0, 0 );
[438]89}
90
[709]91///////////////////////////////////////
92int giet_pthread_kill( pthread_t trdid,
93                       int       signal )
[438]94{
[709]95    return sys_call( SYSCALL_PTHREAD_KILL,
96                     trdid,
97                     signal,
98                     0, 0 );
[438]99}
100
[709]101/////////////////////////
102void giet_pthread_yield() 
[647]103{
[709]104    sys_call( SYSCALL_PTHREAD_YIELD,
105              0, 0, 0, 0 );
[647]106}
[438]107
[709]108/////////////////////////////////////////////////
109void giet_pthread_assert( unsigned int condition,
110                          char*        string )
[647]111{
[709]112    if ( condition == 0 ) giet_pthread_exit( string );
[647]113}
114
[713]115////////////////////////////////////////////////
116void giet_pthread_control( unsigned int command, 
117                           char*        vspace_name,
118                           char*        thread_name )
[647]119{
[713]120    int ret = sys_call( SYSCALL_PTHREAD_CONTROL,
121                        command,
122                        (unsigned int) vspace_name,
123                        (unsigned int) thread_name,
124                        0 );
[647]125
[713]126    if ( ret == SYSCALL_VSPACE_NOT_FOUND )
127    {
128        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
129                        "vspace %s not found\n", vspace_name );
130    }
131    if ( ret == SYSCALL_THREAD_NOT_FOUND )
132    {
133        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
134                        "thread %s not found\n", thread_name );
135    }
136    if ( ret == SYSCALL_UNCOHERENT_THREAD_CONTEXT )
137    {
138        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
139                        "uncoherent context for thread %s\n", thread_name );
140    }
141    if ( ret == SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE )
142    {
143        giet_tty_printf("  ERROR in PTHREAD_CONTROL : "
144                        "illegal command type %d\n", command );
145    }
[689]146}
147
[709]148
[521]149//////////////////////////////////////////////////////////////////////////////
[709]150//                    Applications related system calls
[647]151//////////////////////////////////////////////////////////////////////////////
152
153///////////////////////////////////////
154int giet_kill_application( char* name ) 
155{
156    return ( sys_call( SYSCALL_KILL_APP,
157                       (unsigned int)name,
158                       0, 0, 0 ) );
159}
160
161///////////////////////////////////////
162int giet_exec_application( char* name ) 
163{
164    return ( sys_call( SYSCALL_EXEC_APP,
165                       (unsigned int)name,
166                       0, 0, 0 ) );
167}
168
[713]169///////////////////////////////////////////
170void giet_applications_status( char* name )
[709]171{
172    sys_call( SYSCALL_APPS_STATUS,
[713]173              (unsigned int)name,
174              0, 0, 0 );
[709]175}
176
[647]177//////////////////////////////////////////////////////////////////////////////
[709]178//                    Coprocessors related system calls
[521]179//////////////////////////////////////////////////////////////////////////////
[295]180
[521]181///////////////////////////////////////////////////
[735]182void giet_coproc_alloc( unsigned int   cluster_xy,
183                        unsigned int   coproc_type,
[558]184                        unsigned int*  coproc_info )
[521]185{
186    if ( sys_call( SYSCALL_COPROC_ALLOC,
[735]187                   cluster_xy,
[521]188                   coproc_type,
189                   (unsigned int)coproc_info,
[735]190                   0 ) ) 
[709]191        giet_pthread_exit("error in giet_coproc_alloc()");
[521]192}
193
[735]194//////////////////////////////////////////////////
195void giet_coproc_release( unsigned int cluster_xy,
196                          unsigned int coproc_type )
[521]197{
198    if ( sys_call( SYSCALL_COPROC_RELEASE,
[735]199                   cluster_xy,
200                   coproc_type,
201                   0 , 0 ) ) 
[709]202        giet_pthread_exit("error in giet_coproc_release()");
[521]203}
204
205//////////////////////////////////////////////////////////////////
[735]206void giet_coproc_channel_init( unsigned int            cluster_xy,
207                               unsigned int            coproc_type,
208                               unsigned int            channel,
[521]209                               giet_coproc_channel_t*  desc )
210{
211    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
[735]212                   cluster_xy,
213                   coproc_type,
[521]214                   channel,
[735]215                   (unsigned int)desc ) )
[709]216        giet_pthread_exit("error in giet_coproc_channel_init()");
[521]217}
218
[735]219//////////////////////////////////////////////
220void giet_coproc_run( unsigned int cluster_xy,
221                      unsigned int coproc_type )
[521]222{
[558]223    if ( sys_call( SYSCALL_COPROC_RUN,
[735]224                   cluster_xy,
225                   coproc_type,
226                   0 , 0 ) ) 
[709]227        giet_pthread_exit("error in giet_coproc_run()");
[521]228}
229
[735]230////////////////////////////////////////////////////
231void giet_coproc_completed( unsigned int cluster_xy,
232                            unsigned int coproc_type )
[521]233{
234    if ( sys_call( SYSCALL_COPROC_COMPLETED,
[735]235                   cluster_xy,
236                   coproc_type,
237                   0 , 0 ) ) 
[709]238        giet_pthread_exit("error in giet_coproc_completed");
[521]239}
240
241
242//////////////////////////////////////////////////////////////////////////////
[709]243//                    TTY device related system calls
[521]244//////////////////////////////////////////////////////////////////////////////
245
[671]246//////////////////////////////////////////
247void giet_tty_alloc( unsigned int shared )
[258]248{
[521]249    if ( sys_call( SYSCALL_TTY_ALLOC,
[671]250                   shared,
[709]251                   0, 0, 0 ) )  giet_pthread_exit("error in giet_tty_alloc()");
[743]252} 
[258]253
[345]254////////////////////////////////////////
255void giet_tty_printf( char* format, ...) 
256{
[743]257    va_list      args;
[771]258    char         string[4096];
[743]259    unsigned int length;
[345]260
261    va_start( args, format );
[771]262    length = xprintf( string , 4096 , format , &args ); 
[295]263    va_end( args );
[345]264
[743]265    if ( length == 0xFFFFFFFF ) giet_pthread_exit("illegal format in giet_tty_printf()");
266   
267    if ( sys_call( SYSCALL_TTY_WRITE, 
[771]268                   (unsigned int)string,   // buffer address
[743]269                   length,                 // number of characters
270                   0xFFFFFFFF,             // channel index from thread context
271                   0) != length )   giet_pthread_exit("error in giet_tty_printf()");
[295]272
[743]273}
274
[295]275/////////////////////////////////
276void giet_tty_getc( char * byte ) 
277{
278    int ret;
279
280    do
[267]281    {
[295]282        ret = sys_call(SYSCALL_TTY_READ, 
283                      (unsigned int)byte,  // buffer address
284                      1,                   // number of characters
285                      0xFFFFFFFF,          // channel index from task context
286                      0);
[709]287        if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getc()");
[267]288    }
[295]289    while (ret != 1); 
290}
[267]291
[295]292/////////////////////////////////////
293void giet_tty_gets( char*        buf, 
294                    unsigned int bufsize ) 
295{
[647]296    int           ret;                           // return value from syscalls
[295]297    unsigned char byte;
298    unsigned int  index = 0;
[647]299    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
[295]300 
301    while (index < (bufsize - 1)) 
302    {
[647]303        // get one character
[295]304        do 
305        { 
306            ret = sys_call(SYSCALL_TTY_READ, 
307                           (unsigned int)(&byte),
308                           1,
[647]309                           0xFFFFFFFF,        // channel index from task context
[295]310                           0);
[709]311            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
[295]312        } 
313        while (ret != 1);
314
[647]315        // analyse character
316        if (byte == 0x0A)                          // LF  special character
[295]317        {
318            break; 
319        }
[647]320        else if ( (byte == 0x7F) ||                // DEL special character
321                  (byte == 0x08) )                 // BS  special character
[295]322        {
[647]323            if ( index > 0 )     
324            {
325                index--; 
326
327                // cancel character
328                ret = sys_call( SYSCALL_TTY_WRITE,
329                                (unsigned int)(&string_cancel),
330                                3,
331                                0XFFFFFFFF,        // channel index from task context
332                                0 );
[709]333                if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
[647]334            }
[295]335        }
[647]336        else if ( (byte < 0x20) || (byte > 0x7F) )  // non printable characters
[295]337        {
[647]338        }
339        else                                       // take all other characters
340        {
[295]341            buf[index] = byte;
342            index++;
[647]343
344            // echo
345            ret = sys_call( SYSCALL_TTY_WRITE,
346                            (unsigned int)(&byte),
347                            1,
348                            0XFFFFFFFF,        // channel index from task context
349                            0 );
[709]350            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
[647]351     
[295]352        }
353    }
354    buf[index] = 0;
[258]355
[743]356} 
[647]357
[295]358///////////////////////////////////////
359void giet_tty_getw( unsigned int* val ) 
360{
361    unsigned char buf[32];
362    unsigned int  string_byte   = 0x00000000;    // string containing one single byte
363    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
364    unsigned int  save = 0;
365    unsigned int  dec = 0;
366    unsigned int  done = 0;
367    unsigned int  overflow = 0;
368    unsigned int  length = 0;
369    unsigned int  i;
370    int           ret;      // return value from syscalls
371 
372    // get characters
373    while (done == 0) 
374    {
375        // read one character
376        do 
377        { 
378            ret = sys_call( SYSCALL_TTY_READ,
379                            (unsigned int)(&string_byte),
380                            1,
[647]381                            0xFFFFFFFF,    // channel index from task context
[295]382                            0); 
[709]383            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
[295]384        } 
385        while (ret != 1);
[258]386
[295]387        // analyse character
[647]388        if ((string_byte > 0x2F) && (string_byte < 0x3A))  // decimal character
[295]389        {
390            buf[length] = (unsigned char)string_byte;
391            length++;
[258]392
[295]393            // echo
394            ret = sys_call( SYSCALL_TTY_WRITE, 
395                            (unsigned int)(&string_byte),
396                            1, 
[647]397                            0xFFFFFFFF,    // channel index from task context
[295]398                            0 );
[709]399            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
[295]400        }
[647]401        else if (string_byte == 0x0A)                     // LF character
[295]402        {
403            done = 1;
404        }
[647]405        else if ( (string_byte == 0x7F) ||                // DEL character
406                  (string_byte == 0x08) )                 // BS  character
[295]407        {
408            if ( length > 0 ) 
409            {
410                length--;    // cancel the character
411
412                ret = sys_call( SYSCALL_TTY_WRITE, 
413                                (unsigned int)(&string_cancel),
414                                3, 
[647]415                                0xFFFFFFFF,    // channel index from task context
[295]416                                0 );
[709]417                if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
[295]418            }
419        }
420
421        // test buffer overflow
422        if ( length >= 32 ) 
423        {
424            overflow = 1;
425            done     = 1;
426        }
427    }  // end while characters
428
429    // string to int conversion with overflow detection
430    if ( overflow == 0 )
431    {
432        for (i = 0; (i < length) && (overflow == 0) ; i++) 
433        {
434            dec = dec * 10 + (buf[i] - 0x30);
435            if (dec < save)  overflow = 1; 
436            save = dec;
437        }
438    } 
439
440    // final evaluation
441    if ( overflow == 0 )
442    {
443        // return value
444        *val = dec;
445    }
446    else
447    {
448        // cancel all echo characters
449        for (i = 0; i < length ; i++) 
450        {
451            ret = sys_call( SYSCALL_TTY_WRITE, 
452                            (unsigned int)(&string_cancel),
453                            3, 
[647]454                            0xFFFFFFFF,    // channel index from task context
[295]455                            0 );
[709]456            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
[295]457        }
458        // echo character '0'
459        string_byte = 0x30;
460        ret = sys_call( SYSCALL_TTY_WRITE, 
461                        (unsigned int)(&string_byte),
462                        1, 
[647]463                        0xFFFFFFFF,    // channel index from task context
[295]464                        0 );
[709]465        if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
[295]466
467        // return 0 value
468        *val = 0;
469    }
[743]470}
[295]471
472
[258]473//////////////////////////////////////////////////////////////////////////////////
[709]474//                     TIMER related system calls 
[258]475//////////////////////////////////////////////////////////////////////////////////
476
[295]477///////////////////////
[438]478void giet_timer_alloc() 
[258]479{
[438]480    if ( sys_call( SYSCALL_TIM_ALLOC,
[713]481                   0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_ALLOC");
[258]482}
[295]483
[438]484////////////////////////////////////////////
485void giet_timer_start( unsigned int period ) 
486{
487    if ( sys_call( SYSCALL_TIM_START,
488                   period,
[713]489                   0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_START");
[438]490}
491
[295]492//////////////////////
493void giet_timer_stop() 
[258]494{
[438]495    if ( sys_call( SYSCALL_TIM_STOP,
[713]496                   0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_STOP");
[258]497}
498
499
500//////////////////////////////////////////////////////////////////////////////////
[709]501//                   Frame buffer related system calls 
[258]502//////////////////////////////////////////////////////////////////////////////////
503
[713]504////////////////////////////////////////
505void giet_fbf_size( unsigned int* width,
506                    unsigned int* height )
507{
508    sys_call( SYSCALL_FBF_SIZE,
509              (unsigned int)width,
510              (unsigned int)height,
511              0, 0 );
512}
513                   
514/////////////////////
515void giet_fbf_alloc()
516{
517    if ( sys_call( SYSCALL_FBF_ALLOC, 
518                   0, 0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_ALLOC");
519}
520
[722]521////////////////////////////////////////////
522void giet_fbf_cma_alloc( unsigned int nbufs )
[258]523{
[438]524    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
[722]525                   nbufs,
526                   0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_ALLOC");
[258]527}
[295]528
[722]529///////////////////////////////////////////////
530void giet_fbf_cma_init_buf( unsigned int index,
531                            void*        buf_vaddr, 
532                            void*        sts_vaddr )
[258]533{
[614]534    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
[722]535                   index,
536                   (unsigned int)buf_vaddr,
537                   (unsigned int)sts_vaddr, 
538                   0 ) )         giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF");
[614]539}
540
[722]541/////////////////////////
542void giet_fbf_cma_start()
[614]543{
[438]544    if ( sys_call( SYSCALL_FBF_CMA_START,
[722]545                   0, 0, 0, 0 ) )  giet_pthread_exit("ERROR in FBF_CMA_START");
[258]546}
[295]547
[722]548///////////////////////////////////////////////
549void giet_fbf_cma_display( unsigned int index )
[258]550{
[438]551    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
[722]552                   index, 
[713]553                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_DISPLAY");
[258]554}
[295]555
[722]556/////////////////////////////////////////////
557void giet_fbf_cma_check( unsigned int index )
558{
559    if ( sys_call( SYSCALL_FBF_CMA_CHECK,
560                   index, 
561                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_CHECK");
562}
563
[295]564////////////////////////
[438]565void giet_fbf_cma_stop()
[258]566{
[438]567    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
[722]568                   0, 0, 0, 0 ) )  giet_pthread_exit("ERROR in FBF_CMA_STOP");
[258]569}
570
[438]571//////////////////////////////////////////////
572void giet_fbf_sync_write( unsigned int offset, 
573                          void *       buffer, 
574                          unsigned int length ) 
575{
576    if ( sys_call( SYSCALL_FBF_SYNC_WRITE, 
577                   offset, 
578                   (unsigned int)buffer, 
579                   length, 
[713]580                   0 ) )  giet_pthread_exit("ERROR in FBF_SYNC_WRITE");
[438]581}
[258]582
[438]583/////////////////////////////////////////////
584void giet_fbf_sync_read( unsigned int offset, 
585                         void *       buffer, 
586                         unsigned int length ) 
587{
588    if ( sys_call( SYSCALL_FBF_SYNC_READ, 
589                   offset, 
590                   (unsigned int)buffer, 
591                   length, 
[713]592                   0 ) )   giet_pthread_exit("ERROR in FBF_SYNC_READ");
[438]593}
594
595
[258]596//////////////////////////////////////////////////////////////////////////////////
[709]597//                      NIC related system calls 
[258]598//////////////////////////////////////////////////////////////////////////////////
599
[709]600//////////////////////////////////////////
601void giet_nic_rx_alloc( unsigned int xmax,
602                        unsigned int ymax )
[258]603{
[709]604    if ( sys_call( SYSCALL_NIC_ALLOC,
605                   1,                    // RX
606                   xmax,
607                   ymax,
608                   0 ) ) giet_pthread_exit("error in giet_nic_rx_alloc()");
[258]609}
[295]610
[709]611//////////////////////////////////////////
612void giet_nic_tx_alloc( unsigned int xmax,
613                        unsigned int ymax )
[258]614{
[709]615    if ( sys_call( SYSCALL_NIC_ALLOC,
616                   0,                    // TX
617                   xmax,
618                   ymax,
619                   0 ) ) giet_pthread_exit("error in giet_nic_tx_alloc()");
[450]620}
621
[709]622////////////////////////
623void giet_nic_rx_start()
[450]624{
[461]625    if ( sys_call( SYSCALL_NIC_START,
[709]626                   1,                    // RX
627                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()");
[450]628}
629
[709]630////////////////////////
631void giet_nic_tx_start()
[450]632{
[461]633    if ( sys_call( SYSCALL_NIC_START,
[709]634                   0,                    // TX
635                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()");
[450]636}
637
[709]638/////////////////////////////////////
639void giet_nic_rx_move( void* buffer )
[450]640{
[461]641    if ( sys_call( SYSCALL_NIC_MOVE,
[709]642                   1,                    // RX
[438]643                   (unsigned int)buffer,
[709]644                   0, 0 ) )  giet_pthread_exit("error in giet_nic_rx_move()");
[258]645}
646
[709]647/////////////////////////////////////
648void giet_nic_tx_move( void* buffer )
[438]649{
[461]650    if ( sys_call( SYSCALL_NIC_MOVE,
[709]651                   0,                    // TX
[438]652                   (unsigned int)buffer,
[709]653                   0, 0 ) )  giet_pthread_exit("error in giet_nic_tx_move()");
[438]654}
655
[709]656///////////////////////
657void giet_nic_rx_stop()
[450]658{
[461]659    if ( sys_call( SYSCALL_NIC_STOP,
[709]660                   1,                    // RX
661                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()");
[450]662}
663
[709]664///////////////////////
665void giet_nic_tx_stop()
[450]666{
[461]667    if ( sys_call( SYSCALL_NIC_STOP,
[709]668                   0,                   // TX
669                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()");
[450]670}
671
[709]672////////////////////////
673void giet_nic_rx_stats()
[461]674{
675    if ( sys_call( SYSCALL_NIC_STATS,
[709]676                   1,                   // RX
677                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()");
[461]678}
[450]679
[709]680////////////////////////
681void giet_nic_tx_stats()
[461]682{
683    if ( sys_call( SYSCALL_NIC_STATS,
[709]684                   0,                   // TX
685                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()");
[461]686}
687
[709]688////////////////////////
689void giet_nic_rx_clear()
[461]690{
691    if ( sys_call( SYSCALL_NIC_CLEAR,
[709]692                   1,                   // RX
693                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()");
[461]694}
695
[709]696////////////////////////
697void giet_nic_tx_clear()
[461]698{
699    if ( sys_call( SYSCALL_NIC_CLEAR,
[709]700                   0,                   // TX
701                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()");
[461]702}
703
704
705
[295]706///////////////////////////////////////////////////////////////////////////////////
[709]707//                   FAT related system calls
[295]708///////////////////////////////////////////////////////////////////////////////////
[258]709
[588]710/////////////////////////////////////////
711int giet_fat_open( char*        pathname,
712                   unsigned int flags ) 
[295]713{
[588]714    return  sys_call( SYSCALL_FAT_OPEN, 
715                      (unsigned int)pathname, 
716                      flags,
717                      0, 0 );
[295]718}
[258]719
[588]720/////////////////////////////////////////
721int giet_fat_close( unsigned int fd_id )
[295]722{
[588]723    return  sys_call( SYSCALL_FAT_CLOSE,
724                      fd_id,
725                      0, 0, 0 );
[295]726}
727
[588]728/////////////////////////////////////////////
[623]729int giet_fat_file_info( unsigned int            fd_id,
730                        struct fat_file_info_s* info )
[295]731{
[588]732    return sys_call( SYSCALL_FAT_FINFO,
733                     fd_id,
[623]734                     (unsigned int)info,
735                     0, 0 );
[295]736}
737
[588]738///////////////////////////////////////
739int giet_fat_read( unsigned int fd_id,     
740                   void*        buffer, 
741                   unsigned int count ) 
742{
743    return sys_call( SYSCALL_FAT_READ,
744                     fd_id,
745                     (unsigned int)buffer,
746                     count,
[759]747                     0 );
[588]748}
749
[759]750///////////////////////////////////////
751int giet_fat_pread( unsigned int fd_id,     
752                    void*        buffer, 
753                    unsigned int count, 
754                    unsigned int offset ) 
755{
756    return sys_call( SYSCALL_FAT_PREAD,
757                     fd_id,
758                     (unsigned int)buffer,
759                     count,
760                     offset ); 
761}
762
[588]763////////////////////////////////////////
764int giet_fat_write( unsigned int fd_id,
[295]765                    void*        buffer, 
[588]766                    unsigned int count )
[258]767{
[295]768    return sys_call( SYSCALL_FAT_WRITE, 
[588]769                     fd_id, 
[295]770                     (unsigned int)buffer,
[588]771                     count,
[759]772                     0 ); 
[258]773}
[295]774
[588]775////////////////////////////////////////
776int giet_fat_lseek( unsigned int fd_id,
[295]777                    unsigned int offset, 
778                    unsigned int whence )
[258]779{
[588]780    return sys_call( SYSCALL_FAT_LSEEK, 
781                     fd_id, 
782                     offset, 
783                     whence,
784                     0 ); 
[258]785}
[295]786
[588]787////////////////////////////////////////////
788int giet_fat_remove( char*         pathname,
789                     unsigned int  should_be_dir )
[258]790{
[588]791    return sys_call( SYSCALL_FAT_REMOVE,
792                     (unsigned int)pathname,
793                      should_be_dir,
794                      0, 0 );
[258]795}
[295]796
797/////////////////////////////////////
[588]798int giet_fat_rename( char*  old_path,
799                     char*  new_path )
[258]800{
[588]801    return sys_call( SYSCALL_FAT_RENAME,
802                     (unsigned int)old_path,
803                     (unsigned int)new_path,
804                      0, 0 );
[258]805}
[295]806
[588]807////////////////////////////////////
808int giet_fat_mkdir( char* pathname )
809{
810    return sys_call( SYSCALL_FAT_MKDIR,
811                     (unsigned int)pathname,
812                      0, 0, 0 );
813}
[295]814
[659]815////////////////////////////////////
816int giet_fat_opendir( char* pathname )
817{
818    return sys_call( SYSCALL_FAT_OPENDIR,
819                     (unsigned int)pathname,
820                     0, 0, 0 );
821}
822
823////////////////////////////////////
824int giet_fat_closedir( unsigned int fd_id )
825{
826    return sys_call( SYSCALL_FAT_CLOSEDIR,
827                     (unsigned int)fd_id,
828                     0, 0, 0 );
829}
830
[743]831//////////////////////////////////////////
[659]832int giet_fat_readdir( unsigned int  fd_id,
833                      fat_dirent_t* entry )
834{
835    return sys_call( SYSCALL_FAT_READDIR,
836                     (unsigned int)fd_id,
837                     (unsigned int)entry,
838                     0, 0 );
839}
840
[743]841/////////////////////////////////////////
842int giet_fat_fprintf( unsigned int fd_id,
843                      char*        format, 
[749]844                      ... )
[743]845{
846    va_list      args;
[771]847    char         string[4096];
[749]848    unsigned int count;
[295]849
[743]850    va_start( args, format );
[771]851    count = xprintf( string , 4096 , format , &args ); 
[743]852    va_end( args );
[295]853
[759]854    if ( count == 0xFFFFFFFF ) giet_pthread_exit("error in giet_fat_fprintf()");
[743]855
856    return sys_call( SYSCALL_FAT_WRITE, 
857                     fd_id, 
[771]858                     (unsigned int)string,
[743]859                     count,
860                     0 );      // no physical addressing required
861}
862
[759]863/////////////////////////////////////////
864void* giet_fat_mmap( void*         vaddr,        // MAP_FIXED not supported
865                     unsigned int  length,
866                     unsigned int  prot,
867                     unsigned int  flags,
868                     unsigned int  fd_id,
869                     unsigned int  offset )
870{
871    if ( flags & MAP_FIXED )     giet_pthread_exit("error in giet_fat_mmap()");
872    if ( flags & MAP_PRIVATE )   giet_pthread_exit("error in giet_fat_mmap()");
873    if ( flags & MAP_ANONYMOUS ) giet_pthread_exit("error in giet_fat_mmap()");
874    if ( length & 0xFFF )        giet_pthread_exit("error in giet_fat_mmap()");
875    if ( offset & 0xFFF )        giet_pthread_exit("error in giet_fat_mmap()");
[743]876
[759]877    return (void*)sys_call( SYSCALL_FAT_MMAP,
878                            fd_id,
879                            length>>12,
880                            offset>>12,
881                            prot );
882}
883
[765]884///////////////////////////////////////////
885int giet_fat_munmap( void*         vaddr,
886                     unsigned int  length )
887{
[767]888    if ( length & 0xFFF )              giet_pthread_exit("error in giet_fat_munmap()");
889    if ( (unsigned int)vaddr & 0xFFF ) giet_pthread_exit("error in giet_fat_munmap()");
[759]890
[767]891    return sys_call( SYSCALL_FAT_MUNMAP,
[765]892                     (unsigned int)vaddr,
893                     length>>12,
894                     0, 0 );
895}
896
[771]897///////////////////////////////////////
898int giet_fat_dump( unsigned int type,
899                   char*        pathname,
900                   unsigned int block_id )
901{
902    return sys_call( SYSCALL_FAT_DUMP,
903                     type,
904                     (unsigned int)pathname,
905                     block_id,
906                     0 );
907
908}
909
910
[390]911//////////////////////////////////////////////////////////////////////////////////
[709]912//                      Miscellaneous system calls
[390]913//////////////////////////////////////////////////////////////////////////////////
914
[501]915/////////////////////////////////////////////////
916void giet_procs_number( unsigned int* x_size, 
917                        unsigned int* y_size,
918                        unsigned int* nprocs ) 
[438]919{
[501]920    if ( sys_call( SYSCALL_PROCS_NUMBER, 
921                   (unsigned int)x_size, 
922                   (unsigned int)y_size, 
923                   (unsigned int)nprocs, 
[709]924                   0 ) )  giet_pthread_exit("error in giet_procs_number()");
[438]925}
926
[295]927////////////////////////////////////////////////////
928void giet_vobj_get_vbase( char*         vspace_name, 
929                          char*         vobj_name, 
[438]930                          unsigned int* vbase ) 
[258]931{
[295]932    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
933                   (unsigned int) vspace_name,
934                   (unsigned int) vobj_name,
[438]935                   (unsigned int) vbase,
[709]936                   0 ) )  giet_pthread_exit("error in giet_vobj_get_vbase()");
[258]937}
[260]938
[438]939////////////////////////////////////////////////////
940void giet_vobj_get_length( char*         vspace_name, 
941                           char*         vobj_name, 
942                           unsigned int* length ) 
[260]943{
[438]944    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
945                   (unsigned int) vspace_name,
946                   (unsigned int) vobj_name,
947                   (unsigned int) length,
[709]948                   0 ) )  giet_pthread_exit("error in giet_vobj_get_length()");
[260]949}
950
[295]951/////////////////////////////////////////
952void giet_heap_info( unsigned int* vaddr, 
[368]953                     unsigned int* length,
954                     unsigned int  x,
955                     unsigned int  y ) 
[258]956{
[709]957    sys_call( SYSCALL_HEAP_INFO, 
958              (unsigned int)vaddr, 
959              (unsigned int)length, 
960              x,
961              y );
[258]962}
963
[390]964/////////////////////////////////////////
965void giet_get_xy( void*         ptr,
966                  unsigned int* px,
967                  unsigned int* py )
968{
969    if ( sys_call( SYSCALL_GET_XY,
970                   (unsigned int)ptr,
971                   (unsigned int)px,
972                   (unsigned int)py,
[709]973                   0 ) )  giet_pthread_exit("error in giet_get_xy()");
[390]974}
975
[258]976// Local Variables:
977// tab-width: 4
978// c-basic-offset: 4
979// c-file-offsets:((innamespace . 0)(inline-open . 0))
980// indent-tabs-mode: nil
981// End:
982// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
983
Note: See TracBrowser for help on using the repository browser.