source: soft/giet_vm/giet_libs/stdio.c @ 771

Last change on this file since 771 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
Line 
1/////////////////////////////////////////////////////////////////////////////////////
2// File     : stdio.c         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
6/////////////////////////////////////////////////////////////////////////////////////
7
8#include <stdarg.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <giet_config.h>
12
13
14//////////////////////////////////////////////////////////////////////////////
15//                     MIPS32 related system calls
16//////////////////////////////////////////////////////////////////////////////
17
18////////////////////////////////////////////
19void giet_proc_xyp( unsigned int* cluster_x,
20                    unsigned int* cluster_y,
21                    unsigned int* lpid )
22{
23    sys_call( SYSCALL_PROC_XYP,
24              (unsigned int)cluster_x,
25              (unsigned int)cluster_y,
26              (unsigned int)lpid,
27               0 );
28}
29
30////////////////////////////
31unsigned int giet_proctime() 
32{
33    return (unsigned int)sys_call( SYSCALL_PROC_TIME, 
34                                   0, 0, 0, 0 );
35}
36
37////////////////////////
38unsigned int giet_rand() 
39{
40    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
41                                             0, 0, 0, 0);
42    if ((x & 0xF) > 7) 
43    {
44        return (x*x & 0xFFFF);
45    }
46    else 
47    {
48        return (x*x*x & 0xFFFF);
49    }
50}
51
52//////////////////////////////////////////////////////////////////////////////
53//                    Threads related  system calls
54//////////////////////////////////////////////////////////////////////////////
55
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 )
65{
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 );
79}
80
81////////////////////////////////////////
82int giet_pthread_join( pthread_t  trdid,
83                       void**     ptr )
84{
85    return sys_call( SYSCALL_PTHREAD_JOIN,
86                     trdid,
87                     (unsigned int)ptr,
88                     0, 0 );
89}
90
91///////////////////////////////////////
92int giet_pthread_kill( pthread_t trdid,
93                       int       signal )
94{
95    return sys_call( SYSCALL_PTHREAD_KILL,
96                     trdid,
97                     signal,
98                     0, 0 );
99}
100
101/////////////////////////
102void giet_pthread_yield() 
103{
104    sys_call( SYSCALL_PTHREAD_YIELD,
105              0, 0, 0, 0 );
106}
107
108/////////////////////////////////////////////////
109void giet_pthread_assert( unsigned int condition,
110                          char*        string )
111{
112    if ( condition == 0 ) giet_pthread_exit( string );
113}
114
115////////////////////////////////////////////////
116void giet_pthread_control( unsigned int command, 
117                           char*        vspace_name,
118                           char*        thread_name )
119{
120    int ret = sys_call( SYSCALL_PTHREAD_CONTROL,
121                        command,
122                        (unsigned int) vspace_name,
123                        (unsigned int) thread_name,
124                        0 );
125
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    }
146}
147
148
149//////////////////////////////////////////////////////////////////////////////
150//                    Applications related system calls
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
169///////////////////////////////////////////
170void giet_applications_status( char* name )
171{
172    sys_call( SYSCALL_APPS_STATUS,
173              (unsigned int)name,
174              0, 0, 0 );
175}
176
177//////////////////////////////////////////////////////////////////////////////
178//                    Coprocessors related system calls
179//////////////////////////////////////////////////////////////////////////////
180
181///////////////////////////////////////////////////
182void giet_coproc_alloc( unsigned int   cluster_xy,
183                        unsigned int   coproc_type,
184                        unsigned int*  coproc_info )
185{
186    if ( sys_call( SYSCALL_COPROC_ALLOC,
187                   cluster_xy,
188                   coproc_type,
189                   (unsigned int)coproc_info,
190                   0 ) ) 
191        giet_pthread_exit("error in giet_coproc_alloc()");
192}
193
194//////////////////////////////////////////////////
195void giet_coproc_release( unsigned int cluster_xy,
196                          unsigned int coproc_type )
197{
198    if ( sys_call( SYSCALL_COPROC_RELEASE,
199                   cluster_xy,
200                   coproc_type,
201                   0 , 0 ) ) 
202        giet_pthread_exit("error in giet_coproc_release()");
203}
204
205//////////////////////////////////////////////////////////////////
206void giet_coproc_channel_init( unsigned int            cluster_xy,
207                               unsigned int            coproc_type,
208                               unsigned int            channel,
209                               giet_coproc_channel_t*  desc )
210{
211    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
212                   cluster_xy,
213                   coproc_type,
214                   channel,
215                   (unsigned int)desc ) )
216        giet_pthread_exit("error in giet_coproc_channel_init()");
217}
218
219//////////////////////////////////////////////
220void giet_coproc_run( unsigned int cluster_xy,
221                      unsigned int coproc_type )
222{
223    if ( sys_call( SYSCALL_COPROC_RUN,
224                   cluster_xy,
225                   coproc_type,
226                   0 , 0 ) ) 
227        giet_pthread_exit("error in giet_coproc_run()");
228}
229
230////////////////////////////////////////////////////
231void giet_coproc_completed( unsigned int cluster_xy,
232                            unsigned int coproc_type )
233{
234    if ( sys_call( SYSCALL_COPROC_COMPLETED,
235                   cluster_xy,
236                   coproc_type,
237                   0 , 0 ) ) 
238        giet_pthread_exit("error in giet_coproc_completed");
239}
240
241
242//////////////////////////////////////////////////////////////////////////////
243//                    TTY device related system calls
244//////////////////////////////////////////////////////////////////////////////
245
246//////////////////////////////////////////
247void giet_tty_alloc( unsigned int shared )
248{
249    if ( sys_call( SYSCALL_TTY_ALLOC,
250                   shared,
251                   0, 0, 0 ) )  giet_pthread_exit("error in giet_tty_alloc()");
252} 
253
254////////////////////////////////////////
255void giet_tty_printf( char* format, ...) 
256{
257    va_list      args;
258    char         string[4096];
259    unsigned int length;
260
261    va_start( args, format );
262    length = xprintf( string , 4096 , format , &args ); 
263    va_end( args );
264
265    if ( length == 0xFFFFFFFF ) giet_pthread_exit("illegal format in giet_tty_printf()");
266   
267    if ( sys_call( SYSCALL_TTY_WRITE, 
268                   (unsigned int)string,   // buffer address
269                   length,                 // number of characters
270                   0xFFFFFFFF,             // channel index from thread context
271                   0) != length )   giet_pthread_exit("error in giet_tty_printf()");
272
273}
274
275/////////////////////////////////
276void giet_tty_getc( char * byte ) 
277{
278    int ret;
279
280    do
281    {
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);
287        if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getc()");
288    }
289    while (ret != 1); 
290}
291
292/////////////////////////////////////
293void giet_tty_gets( char*        buf, 
294                    unsigned int bufsize ) 
295{
296    int           ret;                           // return value from syscalls
297    unsigned char byte;
298    unsigned int  index = 0;
299    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
300 
301    while (index < (bufsize - 1)) 
302    {
303        // get one character
304        do 
305        { 
306            ret = sys_call(SYSCALL_TTY_READ, 
307                           (unsigned int)(&byte),
308                           1,
309                           0xFFFFFFFF,        // channel index from task context
310                           0);
311            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
312        } 
313        while (ret != 1);
314
315        // analyse character
316        if (byte == 0x0A)                          // LF  special character
317        {
318            break; 
319        }
320        else if ( (byte == 0x7F) ||                // DEL special character
321                  (byte == 0x08) )                 // BS  special character
322        {
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 );
333                if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
334            }
335        }
336        else if ( (byte < 0x20) || (byte > 0x7F) )  // non printable characters
337        {
338        }
339        else                                       // take all other characters
340        {
341            buf[index] = byte;
342            index++;
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 );
350            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
351     
352        }
353    }
354    buf[index] = 0;
355
356} 
357
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,
381                            0xFFFFFFFF,    // channel index from task context
382                            0); 
383            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
384        } 
385        while (ret != 1);
386
387        // analyse character
388        if ((string_byte > 0x2F) && (string_byte < 0x3A))  // decimal character
389        {
390            buf[length] = (unsigned char)string_byte;
391            length++;
392
393            // echo
394            ret = sys_call( SYSCALL_TTY_WRITE, 
395                            (unsigned int)(&string_byte),
396                            1, 
397                            0xFFFFFFFF,    // channel index from task context
398                            0 );
399            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
400        }
401        else if (string_byte == 0x0A)                     // LF character
402        {
403            done = 1;
404        }
405        else if ( (string_byte == 0x7F) ||                // DEL character
406                  (string_byte == 0x08) )                 // BS  character
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, 
415                                0xFFFFFFFF,    // channel index from task context
416                                0 );
417                if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
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, 
454                            0xFFFFFFFF,    // channel index from task context
455                            0 );
456            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
457        }
458        // echo character '0'
459        string_byte = 0x30;
460        ret = sys_call( SYSCALL_TTY_WRITE, 
461                        (unsigned int)(&string_byte),
462                        1, 
463                        0xFFFFFFFF,    // channel index from task context
464                        0 );
465        if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
466
467        // return 0 value
468        *val = 0;
469    }
470}
471
472
473//////////////////////////////////////////////////////////////////////////////////
474//                     TIMER related system calls 
475//////////////////////////////////////////////////////////////////////////////////
476
477///////////////////////
478void giet_timer_alloc() 
479{
480    if ( sys_call( SYSCALL_TIM_ALLOC,
481                   0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_ALLOC");
482}
483
484////////////////////////////////////////////
485void giet_timer_start( unsigned int period ) 
486{
487    if ( sys_call( SYSCALL_TIM_START,
488                   period,
489                   0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_START");
490}
491
492//////////////////////
493void giet_timer_stop() 
494{
495    if ( sys_call( SYSCALL_TIM_STOP,
496                   0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_STOP");
497}
498
499
500//////////////////////////////////////////////////////////////////////////////////
501//                   Frame buffer related system calls 
502//////////////////////////////////////////////////////////////////////////////////
503
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
521////////////////////////////////////////////
522void giet_fbf_cma_alloc( unsigned int nbufs )
523{
524    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
525                   nbufs,
526                   0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_ALLOC");
527}
528
529///////////////////////////////////////////////
530void giet_fbf_cma_init_buf( unsigned int index,
531                            void*        buf_vaddr, 
532                            void*        sts_vaddr )
533{
534    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
535                   index,
536                   (unsigned int)buf_vaddr,
537                   (unsigned int)sts_vaddr, 
538                   0 ) )         giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF");
539}
540
541/////////////////////////
542void giet_fbf_cma_start()
543{
544    if ( sys_call( SYSCALL_FBF_CMA_START,
545                   0, 0, 0, 0 ) )  giet_pthread_exit("ERROR in FBF_CMA_START");
546}
547
548///////////////////////////////////////////////
549void giet_fbf_cma_display( unsigned int index )
550{
551    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
552                   index, 
553                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_DISPLAY");
554}
555
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
564////////////////////////
565void giet_fbf_cma_stop()
566{
567    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
568                   0, 0, 0, 0 ) )  giet_pthread_exit("ERROR in FBF_CMA_STOP");
569}
570
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, 
580                   0 ) )  giet_pthread_exit("ERROR in FBF_SYNC_WRITE");
581}
582
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, 
592                   0 ) )   giet_pthread_exit("ERROR in FBF_SYNC_READ");
593}
594
595
596//////////////////////////////////////////////////////////////////////////////////
597//                      NIC related system calls 
598//////////////////////////////////////////////////////////////////////////////////
599
600//////////////////////////////////////////
601void giet_nic_rx_alloc( unsigned int xmax,
602                        unsigned int ymax )
603{
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()");
609}
610
611//////////////////////////////////////////
612void giet_nic_tx_alloc( unsigned int xmax,
613                        unsigned int ymax )
614{
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()");
620}
621
622////////////////////////
623void giet_nic_rx_start()
624{
625    if ( sys_call( SYSCALL_NIC_START,
626                   1,                    // RX
627                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()");
628}
629
630////////////////////////
631void giet_nic_tx_start()
632{
633    if ( sys_call( SYSCALL_NIC_START,
634                   0,                    // TX
635                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()");
636}
637
638/////////////////////////////////////
639void giet_nic_rx_move( void* buffer )
640{
641    if ( sys_call( SYSCALL_NIC_MOVE,
642                   1,                    // RX
643                   (unsigned int)buffer,
644                   0, 0 ) )  giet_pthread_exit("error in giet_nic_rx_move()");
645}
646
647/////////////////////////////////////
648void giet_nic_tx_move( void* buffer )
649{
650    if ( sys_call( SYSCALL_NIC_MOVE,
651                   0,                    // TX
652                   (unsigned int)buffer,
653                   0, 0 ) )  giet_pthread_exit("error in giet_nic_tx_move()");
654}
655
656///////////////////////
657void giet_nic_rx_stop()
658{
659    if ( sys_call( SYSCALL_NIC_STOP,
660                   1,                    // RX
661                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()");
662}
663
664///////////////////////
665void giet_nic_tx_stop()
666{
667    if ( sys_call( SYSCALL_NIC_STOP,
668                   0,                   // TX
669                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()");
670}
671
672////////////////////////
673void giet_nic_rx_stats()
674{
675    if ( sys_call( SYSCALL_NIC_STATS,
676                   1,                   // RX
677                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()");
678}
679
680////////////////////////
681void giet_nic_tx_stats()
682{
683    if ( sys_call( SYSCALL_NIC_STATS,
684                   0,                   // TX
685                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()");
686}
687
688////////////////////////
689void giet_nic_rx_clear()
690{
691    if ( sys_call( SYSCALL_NIC_CLEAR,
692                   1,                   // RX
693                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()");
694}
695
696////////////////////////
697void giet_nic_tx_clear()
698{
699    if ( sys_call( SYSCALL_NIC_CLEAR,
700                   0,                   // TX
701                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()");
702}
703
704
705
706///////////////////////////////////////////////////////////////////////////////////
707//                   FAT related system calls
708///////////////////////////////////////////////////////////////////////////////////
709
710/////////////////////////////////////////
711int giet_fat_open( char*        pathname,
712                   unsigned int flags ) 
713{
714    return  sys_call( SYSCALL_FAT_OPEN, 
715                      (unsigned int)pathname, 
716                      flags,
717                      0, 0 );
718}
719
720/////////////////////////////////////////
721int giet_fat_close( unsigned int fd_id )
722{
723    return  sys_call( SYSCALL_FAT_CLOSE,
724                      fd_id,
725                      0, 0, 0 );
726}
727
728/////////////////////////////////////////////
729int giet_fat_file_info( unsigned int            fd_id,
730                        struct fat_file_info_s* info )
731{
732    return sys_call( SYSCALL_FAT_FINFO,
733                     fd_id,
734                     (unsigned int)info,
735                     0, 0 );
736}
737
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,
747                     0 );
748}
749
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
763////////////////////////////////////////
764int giet_fat_write( unsigned int fd_id,
765                    void*        buffer, 
766                    unsigned int count )
767{
768    return sys_call( SYSCALL_FAT_WRITE, 
769                     fd_id, 
770                     (unsigned int)buffer,
771                     count,
772                     0 ); 
773}
774
775////////////////////////////////////////
776int giet_fat_lseek( unsigned int fd_id,
777                    unsigned int offset, 
778                    unsigned int whence )
779{
780    return sys_call( SYSCALL_FAT_LSEEK, 
781                     fd_id, 
782                     offset, 
783                     whence,
784                     0 ); 
785}
786
787////////////////////////////////////////////
788int giet_fat_remove( char*         pathname,
789                     unsigned int  should_be_dir )
790{
791    return sys_call( SYSCALL_FAT_REMOVE,
792                     (unsigned int)pathname,
793                      should_be_dir,
794                      0, 0 );
795}
796
797/////////////////////////////////////
798int giet_fat_rename( char*  old_path,
799                     char*  new_path )
800{
801    return sys_call( SYSCALL_FAT_RENAME,
802                     (unsigned int)old_path,
803                     (unsigned int)new_path,
804                      0, 0 );
805}
806
807////////////////////////////////////
808int giet_fat_mkdir( char* pathname )
809{
810    return sys_call( SYSCALL_FAT_MKDIR,
811                     (unsigned int)pathname,
812                      0, 0, 0 );
813}
814
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
831//////////////////////////////////////////
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
841/////////////////////////////////////////
842int giet_fat_fprintf( unsigned int fd_id,
843                      char*        format, 
844                      ... )
845{
846    va_list      args;
847    char         string[4096];
848    unsigned int count;
849
850    va_start( args, format );
851    count = xprintf( string , 4096 , format , &args ); 
852    va_end( args );
853
854    if ( count == 0xFFFFFFFF ) giet_pthread_exit("error in giet_fat_fprintf()");
855
856    return sys_call( SYSCALL_FAT_WRITE, 
857                     fd_id, 
858                     (unsigned int)string,
859                     count,
860                     0 );      // no physical addressing required
861}
862
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()");
876
877    return (void*)sys_call( SYSCALL_FAT_MMAP,
878                            fd_id,
879                            length>>12,
880                            offset>>12,
881                            prot );
882}
883
884///////////////////////////////////////////
885int giet_fat_munmap( void*         vaddr,
886                     unsigned int  length )
887{
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()");
890
891    return sys_call( SYSCALL_FAT_MUNMAP,
892                     (unsigned int)vaddr,
893                     length>>12,
894                     0, 0 );
895}
896
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
911//////////////////////////////////////////////////////////////////////////////////
912//                      Miscellaneous system calls
913//////////////////////////////////////////////////////////////////////////////////
914
915/////////////////////////////////////////////////
916void giet_procs_number( unsigned int* x_size, 
917                        unsigned int* y_size,
918                        unsigned int* nprocs ) 
919{
920    if ( sys_call( SYSCALL_PROCS_NUMBER, 
921                   (unsigned int)x_size, 
922                   (unsigned int)y_size, 
923                   (unsigned int)nprocs, 
924                   0 ) )  giet_pthread_exit("error in giet_procs_number()");
925}
926
927////////////////////////////////////////////////////
928void giet_vobj_get_vbase( char*         vspace_name, 
929                          char*         vobj_name, 
930                          unsigned int* vbase ) 
931{
932    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
933                   (unsigned int) vspace_name,
934                   (unsigned int) vobj_name,
935                   (unsigned int) vbase,
936                   0 ) )  giet_pthread_exit("error in giet_vobj_get_vbase()");
937}
938
939////////////////////////////////////////////////////
940void giet_vobj_get_length( char*         vspace_name, 
941                           char*         vobj_name, 
942                           unsigned int* length ) 
943{
944    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
945                   (unsigned int) vspace_name,
946                   (unsigned int) vobj_name,
947                   (unsigned int) length,
948                   0 ) )  giet_pthread_exit("error in giet_vobj_get_length()");
949}
950
951/////////////////////////////////////////
952void giet_heap_info( unsigned int* vaddr, 
953                     unsigned int* length,
954                     unsigned int  x,
955                     unsigned int  y ) 
956{
957    sys_call( SYSCALL_HEAP_INFO, 
958              (unsigned int)vaddr, 
959              (unsigned int)length, 
960              x,
961              y );
962}
963
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,
973                   0 ) )  giet_pthread_exit("error in giet_get_xy()");
974}
975
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.