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

Last change on this file since 572 was 558, checked in by alain, 9 years ago

Introducing new syscalls to handle MWMR compliant coprocessors.

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