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

Last change on this file since 554 was 550, checked in by alain, 9 years ago

Cosmetic.

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