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

Last change on this file since 659 was 659, checked in by guerin, 9 years ago

stdio: add giet_fat_opendir, giet_fat_closedir, giet_fat_readdir

  • Property svn:executable set to *
File size: 35.4 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 <giet_config.h>
11
12//////////////////////////////////////////////////////////////////////////////
13/////////////////////  MIPS32     related system calls ///////////////////////
14//////////////////////////////////////////////////////////////////////////////
15
16////////////////////////////////////////////
17void giet_proc_xyp( unsigned int* cluster_x,
18                    unsigned int* cluster_y,
19                    unsigned int* lpid )
20{
21    sys_call( SYSCALL_PROC_XYP,
22              (unsigned int)cluster_x,
23              (unsigned int)cluster_y,
24              (unsigned int)lpid,
25               0 );
26}
27
28////////////////////////////
29unsigned int giet_proctime() 
30{
31    return (unsigned int)sys_call( SYSCALL_PROC_TIME, 
32                                   0, 0, 0, 0 );
33}
34
35////////////////////////
36unsigned int giet_rand() 
37{
38    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
39                                             0, 0, 0, 0);
40    if ((x & 0xF) > 7) 
41    {
42        return (x*x & 0xFFFF);
43    }
44    else 
45    {
46        return (x*x*x & 0xFFFF);
47    }
48}
49
50//////////////////////////////////////////////////////////////////////////////
51///////////////////// Task related  system calls /////////////////////////////
52//////////////////////////////////////////////////////////////////////////////
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//////////////////////////////
76void giet_exit( char* string ) 
77{
78    sys_call( SYSCALL_EXIT,
79              (unsigned int)string,
80              0, 0, 0 );
81}
82
83/////////////////////////////////////////
84void giet_assert( unsigned int condition,
85                  char*        string )
86{
87    if ( condition == 0 ) giet_exit( string );
88}
89
90//////////////////////////
91void giet_context_switch() 
92{
93    sys_call( SYSCALL_CTX_SWITCH,
94              0, 0, 0, 0 );
95}
96
97//////////////////////////////////////////////////////////////////////////////
98///////////////////// Applications  system calls /////////////////////////////
99//////////////////////////////////////////////////////////////////////////////
100
101///////////////////////////////////////
102int giet_kill_application( char* name ) 
103{
104    return ( sys_call( SYSCALL_KILL_APP,
105                       (unsigned int)name,
106                       0, 0, 0 ) );
107}
108
109///////////////////////////////////////
110int giet_exec_application( char* name ) 
111{
112    return ( sys_call( SYSCALL_EXEC_APP,
113                       (unsigned int)name,
114                       0, 0, 0 ) );
115}
116
117//////////////////////////////////////////////////////////////////////////////
118///////////////////// Coprocessors  system calls  ////////////////////////////
119//////////////////////////////////////////////////////////////////////////////
120
121///////////////////////////////////////////////////
122void giet_coproc_alloc( unsigned int   coproc_type,
123                        unsigned int*  coproc_info )
124{
125    if ( sys_call( SYSCALL_COPROC_ALLOC,
126                   coproc_type,
127                   (unsigned int)coproc_info,
128                   0, 0 ) ) 
129        giet_exit("error in giet_coproc_alloc()");
130}
131
132/////////////////////////////////////////////////////////
133void giet_coproc_release( unsigned int coproc_reg_index )
134{
135    if ( sys_call( SYSCALL_COPROC_RELEASE,
136                   coproc_reg_index,
137                   0, 0, 0 ) ) 
138        giet_exit("error in giet_coproc_release()");
139}
140
141//////////////////////////////////////////////////////////////////
142void giet_coproc_channel_init( unsigned int            channel,
143                               giet_coproc_channel_t*  desc )
144{
145    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
146                   channel,
147                   (unsigned int)desc,
148                   0, 0 ) ) 
149        giet_exit("error in giet_coproc_channel_init()");
150}
151
152/////////////////////////////////////////////////////
153void giet_coproc_run( unsigned int coproc_reg_index )
154{
155    if ( sys_call( SYSCALL_COPROC_RUN,
156                   coproc_reg_index,
157                   0, 0, 0 ) ) 
158        giet_exit("error in giet_coproc_run()");
159}
160
161////////////////////////////
162void giet_coproc_completed()
163{
164    if ( sys_call( SYSCALL_COPROC_COMPLETED,
165                   0, 0, 0, 0 ) ) 
166        giet_exit("error in giet_coproc_completed");
167}
168
169
170//////////////////////////////////////////////////////////////////////////////
171/////////////////////  TTY device related system calls ///////////////////////
172//////////////////////////////////////////////////////////////////////////////
173
174/////////////////////
175void giet_tty_alloc()
176{
177    if ( sys_call( SYSCALL_TTY_ALLOC,
178                   0, 0, 0, 0 ) )  giet_exit("error in giet_tty_alloc()");
179}
180
181////////////////////////////////////////////////////////////////////////
182static  int __printf( char* format, unsigned int channel, va_list* args) 
183{
184    int ret;                    // return value from the syscall
185    enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers;
186
187printf_text:
188
189    while (*format) 
190    {
191        unsigned int i;
192        for (i = 0 ; format[i] && (format[i] != '%') ; i++);
193        if (i) 
194        {
195            ret = sys_call(SYSCALL_TTY_WRITE, 
196                           (unsigned int)format,
197                           i, 
198                           channel,
199                           0);
200
201            if (ret != i) goto return_error;
202
203            format += i;
204        }
205        if (*format == '%') 
206        {
207            format++;
208            modifiers = NO_MOD;
209            goto printf_arguments;
210        }
211    }
212
213    return 0;
214
215printf_arguments:
216
217    {
218        char              buf[30];
219        char *            pbuf;
220        unsigned int      len = 0;
221        static const char HexaTab[] = "0123456789ABCDEF";
222        unsigned int      i;
223       
224        /* Ignored fields : width and precision */
225        for (; *format >= '0' && *format <= '9'; format++);
226
227        switch (*format++) 
228        {
229            case ('%'):
230            {
231                len = 1;
232                pbuf = "%";
233                break;
234            }
235            case ('c'):             /* char conversion */
236            {
237                int val = va_arg( *args, int );
238                if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
239               
240                len = 1;
241                buf[0] = val;
242                pbuf = &buf[0];
243                break;
244            }
245            case ('d'):             /* decimal signed integer */
246            {
247                int val = va_arg( *args, int );
248               
249                if (modifiers == LL_MOD) goto return_error; // 64 bits not supported
250               
251                if (val < 0) 
252                {
253                    val = -val;
254                    ret = sys_call(SYSCALL_TTY_WRITE, 
255                                   (unsigned int)"-",
256                                   1,
257                                   channel,
258                                   0);
259                    if (ret != 1) goto return_error;
260                }
261                for(i = 0; i < 10; i++) 
262                {
263                    buf[9 - i] = HexaTab[val % 10];
264                    if (!(val /= 10)) break;
265                }
266                len =  i + 1;
267                pbuf = &buf[9 - i];
268                break;
269            }
270            case ('u'):             /* decimal unsigned integer */
271            {
272                if (modifiers != LL_MOD) //32 bits integer
273                {
274                    unsigned int val = va_arg( *args, unsigned int );
275                    for(i = 0; i < 10; i++) 
276                    {
277                        buf[9 - i] = HexaTab[val % 10];
278                        if (!(val /= 10)) break;
279                    }
280                    len =  i + 1;
281                    pbuf = &buf[9 - i];
282                    break;
283                }
284                //64 bits : base 10 unsupported : continue to hexa
285            }
286            case ('x'):
287            case ('X'):             /* hexadecimal integer */
288            {
289                unsigned long long val;
290                int imax;
291               
292                if (modifiers == LL_MOD) // 64 bits
293                {
294                    val = va_arg( *args, unsigned long long);
295                   
296                    // if asked to print in base 10, can do only if it fits in 32 bits
297                    if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL))) 
298                    {
299                        unsigned int uintv = (unsigned int) val;
300                       
301                        for(i = 0; i < 10; i++) 
302                        {
303                            buf[9 - i] = HexaTab[uintv % 10];
304                            if (!(uintv /= 10)) break;
305                        }
306                        len =  i + 1;
307                        pbuf = &buf[9 - i];
308                        break;
309                    }
310                   
311                    imax = 16;
312                }
313                else //32 bits
314                {
315                    val = va_arg( *args, unsigned int);
316                    imax = 8;
317                }
318               
319                ret = sys_call(SYSCALL_TTY_WRITE,
320                               (unsigned int)"0x",
321                               2,
322                               channel,
323                               0);
324                if (ret != 2) goto return_error;
325               
326                for(i = 0; i < imax; i++) 
327                {
328                    buf[(imax-1) - i] = HexaTab[val % 16];
329                    if (!(val /= 16))  break;
330                }
331                len =  i + 1;
332                pbuf = &buf[(imax-1) - i];
333                break;
334            }
335            case ('s'):             /* string */
336            {
337                char* str = va_arg( *args, char* );
338               
339                if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
340               
341                while (str[len]) 
342                {
343                    len++;
344                }
345                pbuf = str;
346                break;
347            }
348            case ('e'):
349            case ('f'):
350            case ('g'):             /* IEEE754 64 bits */
351            {
352               
353                double vald = va_arg( *args, double);
354               
355                unsigned long long
356                    val = *(unsigned long long*)&vald, //get ieee754 without conversion
357                    digits = val & 0xFFFFFFFFFFFFFULL;    //get mantissa
358               
359                unsigned int
360                    base = (unsigned int)((val & 0x7FF0000000000000ULL) >> 52), //get exposant
361                    intp = (unsigned int)vald,         //get integer part of the float
362                    decp;
363               
364                int isvalue = 0;
365               
366                if (base == 0x7FF) //special value
367                {
368                    if (digits & 0xFFFFFFFFFFFFFULL)
369                    {
370                        /* Not a Number */
371                        buf[0] = 'N';
372                        buf[1] = 'a';
373                        buf[2] = 'N';
374                        len = 3;
375                        pbuf = buf;
376                    }
377                    else
378                    {
379                        /* inf */
380                        buf[0] = (val & 0x8000000000000000ULL) ? '-' : '+';
381                        buf[1] = 'i';
382                        buf[2] = 'n';
383                        buf[3] = 'f';
384                        len = 4;
385                        pbuf = buf;
386                    }
387                    break;
388                }
389               
390                if (val & 0x8000000000000000ULL)
391                {
392                    /* negative */
393                    ret = sys_call(SYSCALL_TTY_WRITE,
394                                (unsigned int)"-",
395                                1,
396                                channel,
397                                0);
398                    if (ret != 1) goto return_error;
399                    vald = vald * -1;
400                }
401                else
402                {
403                    /* positive */
404                    ret = sys_call(SYSCALL_TTY_WRITE,
405                                (unsigned int)"+",
406                                1,
407                                channel,
408                                0);
409                    if (ret != 1) goto return_error;
410                }
411               
412                if (vald > 0xFFFFFFFF)
413                {
414                    /* overflow */
415                    buf[0] = 'B';
416                    buf[1] = 'I';
417                    buf[2] = 'G';
418                    len = 3;
419                    pbuf = buf;
420                    break;
421                }
422               
423                vald -= (double)intp;
424                decp = (unsigned int)(vald * 1000000000);
425               
426                for(i = 0; i < 10; i++) 
427                {
428                    if ((!isvalue) && (intp % 10)) isvalue = 1;
429                    buf[9 - i] = HexaTab[intp % 10];
430                    if (!(intp /= 10)) break;
431                }
432                pbuf = &buf[9 - i];
433                len = i+11;
434                buf[10] = '.';
435               
436                for(i = 0; i < 9; i++)
437                {
438                    if ((!isvalue) && (decp % 10)) isvalue = 1;
439                    buf[19 - i] = HexaTab[decp % 10];
440                    decp /= 10;
441                }
442               
443                if (!isvalue)
444                {
445                    if (vald != 0)
446                    {
447                        /* underflow */
448                        buf[0] = 'T';
449                        buf[1] = 'I';
450                        buf[2] = 'N';
451                        buf[3] = 'Y';
452                        len = 4;
453                        pbuf = buf;
454                    }
455                }
456
457                break;
458            }
459            case ('l'):
460                switch (modifiers)
461                {
462                    case NO_MOD:
463                        modifiers = L_MOD;
464                        goto printf_arguments;
465                   
466                    case L_MOD:
467                        modifiers = LL_MOD;
468                        goto printf_arguments;
469                   
470                    default:
471                        goto return_error;
472                }
473
474            /* Ignored fields : width and precision */
475            case ('.'): goto printf_arguments;
476               
477            default:
478                goto return_error;
479        }
480
481        ret = sys_call(SYSCALL_TTY_WRITE, 
482                       (unsigned int)pbuf,
483                       len,
484                       channel, 
485                       0);
486        if (ret != len)  goto return_error;
487       
488        goto printf_text;
489    }
490
491return_error:
492    return 1;
493} // end __printf()
494
495
496////////////////////////////////////////
497void giet_tty_printf( char* format, ...) 
498{
499    va_list args;
500
501    va_start( args, format );
502    int ret = __printf(format, 0xFFFFFFFF, &args);
503    va_end( args );
504
505    if (ret)
506    {
507        giet_exit("ERROR in giet_tty_printf()");
508    }
509} // end giet_tty_printf()
510
511////////////////////////////////////////
512void giet_shr_printf( char* format, ...) 
513{
514    va_list args;
515    volatile unsigned int sr_save;
516
517    sys_call( SYSCALL_TTY_GET_LOCK,
518              0,
519              (unsigned int)&sr_save,
520              0, 0 );
521
522    va_start( args, format );
523    int ret = __printf(format, 0, &args);
524    va_end( args );
525
526    sys_call( SYSCALL_TTY_RELEASE_LOCK,
527              0,
528              (unsigned int)&sr_save,
529              0, 0 );
530
531    if (ret)
532    {
533        giet_exit("error in giet_shr_printf()");
534    }
535} // end giet_shr_printf()
536
537/////////////////////////////////
538void giet_tty_getc( char * byte ) 
539{
540    int ret;
541
542    do
543    {
544        ret = sys_call(SYSCALL_TTY_READ, 
545                      (unsigned int)byte,  // buffer address
546                      1,                   // number of characters
547                      0xFFFFFFFF,          // channel index from task context
548                      0);
549        if ( ret < 0 ) giet_exit("error in giet_tty_getc()");
550    }
551    while (ret != 1); 
552}
553
554/////////////////////////////////////
555void giet_tty_gets( char*        buf, 
556                    unsigned int bufsize ) 
557{
558    int           ret;                           // return value from syscalls
559    unsigned char byte;
560    unsigned int  index = 0;
561    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
562 
563    while (index < (bufsize - 1)) 
564    {
565        // get one character
566        do 
567        { 
568            ret = sys_call(SYSCALL_TTY_READ, 
569                           (unsigned int)(&byte),
570                           1,
571                           0xFFFFFFFF,        // channel index from task context
572                           0);
573            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
574        } 
575        while (ret != 1);
576
577        // analyse character
578        if (byte == 0x0A)                          // LF  special character
579        {
580            break; 
581        }
582        else if ( (byte == 0x7F) ||                // DEL special character
583                  (byte == 0x08) )                 // BS  special character
584        {
585            if ( index > 0 )     
586            {
587                index--; 
588
589                // cancel character
590                ret = sys_call( SYSCALL_TTY_WRITE,
591                                (unsigned int)(&string_cancel),
592                                3,
593                                0XFFFFFFFF,        // channel index from task context
594                                0 );
595                if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
596            }
597        }
598        else if ( (byte < 0x20) || (byte > 0x7F) )  // non printable characters
599        {
600        }
601        else                                       // take all other characters
602        {
603            buf[index] = byte;
604            index++;
605
606            // echo
607            ret = sys_call( SYSCALL_TTY_WRITE,
608                            (unsigned int)(&byte),
609                            1,
610                            0XFFFFFFFF,        // channel index from task context
611                            0 );
612            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
613     
614        }
615    }
616    buf[index] = 0;
617
618}   // end giet_tty_gets()
619
620///////////////////////////////////////
621void giet_tty_getw( unsigned int* val ) 
622{
623    unsigned char buf[32];
624    unsigned int  string_byte   = 0x00000000;    // string containing one single byte
625    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
626    unsigned int  save = 0;
627    unsigned int  dec = 0;
628    unsigned int  done = 0;
629    unsigned int  overflow = 0;
630    unsigned int  length = 0;
631    unsigned int  i;
632    int           ret;      // return value from syscalls
633 
634    // get characters
635    while (done == 0) 
636    {
637        // read one character
638        do 
639        { 
640            ret = sys_call( SYSCALL_TTY_READ,
641                            (unsigned int)(&string_byte),
642                            1,
643                            0xFFFFFFFF,    // channel index from task context
644                            0); 
645            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
646        } 
647        while (ret != 1);
648
649        // analyse character
650        if ((string_byte > 0x2F) && (string_byte < 0x3A))  // decimal character
651        {
652            buf[length] = (unsigned char)string_byte;
653            length++;
654
655            // echo
656            ret = sys_call( SYSCALL_TTY_WRITE, 
657                            (unsigned int)(&string_byte),
658                            1, 
659                            0xFFFFFFFF,    // channel index from task context
660                            0 );
661            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
662        }
663        else if (string_byte == 0x0A)                     // LF character
664        {
665            done = 1;
666        }
667        else if ( (string_byte == 0x7F) ||                // DEL character
668                  (string_byte == 0x08) )                 // BS  character
669        {
670            if ( length > 0 ) 
671            {
672                length--;    // cancel the character
673
674                ret = sys_call( SYSCALL_TTY_WRITE, 
675                                (unsigned int)(&string_cancel),
676                                3, 
677                                0xFFFFFFFF,    // channel index from task context
678                                0 );
679                if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
680            }
681        }
682
683        // test buffer overflow
684        if ( length >= 32 ) 
685        {
686            overflow = 1;
687            done     = 1;
688        }
689    }  // end while characters
690
691    // string to int conversion with overflow detection
692    if ( overflow == 0 )
693    {
694        for (i = 0; (i < length) && (overflow == 0) ; i++) 
695        {
696            dec = dec * 10 + (buf[i] - 0x30);
697            if (dec < save)  overflow = 1; 
698            save = dec;
699        }
700    } 
701
702    // final evaluation
703    if ( overflow == 0 )
704    {
705        // return value
706        *val = dec;
707    }
708    else
709    {
710        // cancel all echo characters
711        for (i = 0; i < length ; i++) 
712        {
713            ret = sys_call( SYSCALL_TTY_WRITE, 
714                            (unsigned int)(&string_cancel),
715                            3, 
716                            0xFFFFFFFF,    // channel index from task context
717                            0 );
718            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
719        }
720        // echo character '0'
721        string_byte = 0x30;
722        ret = sys_call( SYSCALL_TTY_WRITE, 
723                        (unsigned int)(&string_byte),
724                        1, 
725                        0xFFFFFFFF,    // channel index from task context
726                        0 );
727        if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
728
729        // return 0 value
730        *val = 0;
731    }
732}   // end giet_tty_getw()
733
734
735//////////////////////////////////////////////////////////////////////////////////
736/////////////////////  TIMER related system calls ////////////////////////////////
737//////////////////////////////////////////////////////////////////////////////////
738
739///////////////////////
740void giet_timer_alloc() 
741{
742    if ( sys_call( SYSCALL_TIM_ALLOC,
743                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()");
744}
745
746////////////////////////////////////////////
747void giet_timer_start( unsigned int period ) 
748{
749    if ( sys_call( SYSCALL_TIM_START,
750                   period,
751                   0, 0, 0 ) ) giet_exit("error in giet_timer_start()");
752}
753
754//////////////////////
755void giet_timer_stop() 
756{
757    if ( sys_call( SYSCALL_TIM_STOP,
758                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()");
759}
760
761
762//////////////////////////////////////////////////////////////////////////////////
763///////////////  Frame buffer device related system calls  ///////////////////////
764//////////////////////////////////////////////////////////////////////////////////
765
766/////////////////////////
767void giet_fbf_cma_alloc()
768{
769    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
770                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_alloc()");
771}
772
773///////////////////////////////////////////
774void giet_fbf_cma_init_buf( void* buf0_vbase, 
775                            void* buf1_vbase,
776                            void* sts0_vaddr,
777                            void* sts1_vaddr )
778{
779    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
780                   (unsigned int)buf0_vbase, 
781                   (unsigned int)buf1_vbase,
782                   (unsigned int)sts0_vaddr, 
783                   (unsigned int)sts1_vaddr ) )   giet_exit("error in giet_fbf_cma_init_buf()");
784}
785
786///////////////////////////////////////////
787void giet_fbf_cma_start( unsigned int length )
788{
789    if ( sys_call( SYSCALL_FBF_CMA_START,
790                   length, 
791                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_start()");
792}
793
794////////////////////////////////////////////////
795void giet_fbf_cma_display( unsigned int buffer )
796{
797    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
798                   buffer, 
799                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
800}
801
802////////////////////////
803void giet_fbf_cma_stop()
804{
805    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
806                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
807}
808
809//////////////////////////////////////////////
810void giet_fbf_sync_write( unsigned int offset, 
811                          void *       buffer, 
812                          unsigned int length ) 
813{
814    if ( sys_call( SYSCALL_FBF_SYNC_WRITE, 
815                   offset, 
816                   (unsigned int)buffer, 
817                   length, 
818                   0 ) )  giet_exit("error in giet_fbf_sync_write()");
819}
820
821/////////////////////////////////////////////
822void giet_fbf_sync_read( unsigned int offset, 
823                         void *       buffer, 
824                         unsigned int length ) 
825{
826    if ( sys_call( SYSCALL_FBF_SYNC_READ, 
827                   offset, 
828                   (unsigned int)buffer, 
829                   length, 
830                   0 ) )   giet_exit("error in giet_fbf_sync_read()");
831}
832
833
834//////////////////////////////////////////////////////////////////////////////////
835/////////////////////// NIC related system calls /////////////////////////////////
836//////////////////////////////////////////////////////////////////////////////////
837
838////////////////////////////////////////////////////
839unsigned int giet_nic_rx_alloc( unsigned int xmax,
840                                unsigned int ymax )
841{
842    int channel = sys_call( SYSCALL_NIC_ALLOC,
843                            1, 
844                            xmax,
845                            ymax,
846                            0 );
847    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
848
849    return (unsigned int)channel;
850}
851
852////////////////////////////////////////////////////
853unsigned int giet_nic_tx_alloc( unsigned int xmax,
854                                unsigned int ymax )
855{
856    int channel = sys_call( SYSCALL_NIC_ALLOC,
857                            0,
858                            xmax,
859                            ymax,
860                            0 );
861    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
862
863    return (unsigned int)channel;
864}
865
866//////////////////////////////////////////////
867void giet_nic_rx_start( unsigned int channel )
868{
869    if ( sys_call( SYSCALL_NIC_START,
870                   1,
871                   channel,
872                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
873}
874
875//////////////////////////////////////////////
876void giet_nic_tx_start( unsigned int channel )
877{
878    if ( sys_call( SYSCALL_NIC_START,
879                   0, 
880                   channel,
881                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
882}
883
884///////////////////////////////////////////////////////////
885void giet_nic_rx_move( unsigned int channel, void* buffer )
886{
887    if ( sys_call( SYSCALL_NIC_MOVE,
888                   1,
889                   channel, 
890                   (unsigned int)buffer,
891                   0 ) )  giet_exit("error in giet_nic_rx_move()");
892}
893
894///////////////////////////////////////////////////////////
895void giet_nic_tx_move( unsigned int channel, void* buffer )
896{
897    if ( sys_call( SYSCALL_NIC_MOVE,
898                   0,
899                   channel, 
900                   (unsigned int)buffer,
901                   0 ) )  giet_exit("error in giet_nic_tx_move()");
902}
903
904/////////////////////////////////////////////
905void giet_nic_rx_stop( unsigned int channel )
906{
907    if ( sys_call( SYSCALL_NIC_STOP,
908                   1, 
909                   channel,
910                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
911}
912
913/////////////////////////////////////////////
914void giet_nic_tx_stop( unsigned int channel )
915{
916    if ( sys_call( SYSCALL_NIC_STOP,
917                   0, 
918                   channel,
919                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
920}
921
922//////////////////////////////////////////////
923void giet_nic_rx_stats( unsigned int channel )
924{
925    if ( sys_call( SYSCALL_NIC_STATS,
926                   1, 
927                   channel,
928                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
929}
930
931//////////////////////////////////////////////
932void giet_nic_tx_stats( unsigned int channel )
933{
934    if ( sys_call( SYSCALL_NIC_STATS,
935                   0, 
936                   channel,
937                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
938}
939
940//////////////////////////////////////////////
941void giet_nic_rx_clear( unsigned int channel )
942{
943    if ( sys_call( SYSCALL_NIC_CLEAR,
944                   1, 
945                   channel,
946                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
947}
948
949//////////////////////////////////////////////
950void giet_nic_tx_clear( unsigned int channel )
951{
952    if ( sys_call( SYSCALL_NIC_CLEAR,
953                   0, 
954                   channel,
955                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
956}
957
958
959
960///////////////////////////////////////////////////////////////////////////////////
961///////////////////// FAT related system calls ////////////////////////////////////
962///////////////////////////////////////////////////////////////////////////////////
963
964/////////////////////////////////////////
965int giet_fat_open( char*        pathname,
966                   unsigned int flags ) 
967{
968    return  sys_call( SYSCALL_FAT_OPEN, 
969                      (unsigned int)pathname, 
970                      flags,
971                      0, 0 );
972}
973
974/////////////////////////////////////////
975int giet_fat_close( unsigned int fd_id )
976{
977    return  sys_call( SYSCALL_FAT_CLOSE,
978                      fd_id,
979                      0, 0, 0 );
980}
981
982/////////////////////////////////////////////
983int giet_fat_file_info( unsigned int            fd_id,
984                        struct fat_file_info_s* info )
985{
986    return sys_call( SYSCALL_FAT_FINFO,
987                     fd_id,
988                     (unsigned int)info,
989                     0, 0 );
990}
991
992///////////////////////////////////////
993int giet_fat_read( unsigned int fd_id,     
994                   void*        buffer, 
995                   unsigned int count ) 
996{
997    return sys_call( SYSCALL_FAT_READ,
998                     fd_id,
999                     (unsigned int)buffer,
1000                     count,
1001                     0 ); 
1002}
1003
1004////////////////////////////////////////
1005int giet_fat_write( unsigned int fd_id,
1006                    void*        buffer, 
1007                    unsigned int count )
1008{
1009    return sys_call( SYSCALL_FAT_WRITE, 
1010                     fd_id, 
1011                     (unsigned int)buffer,
1012                     count,
1013                     0 ); 
1014}
1015
1016////////////////////////////////////////
1017int giet_fat_lseek( unsigned int fd_id,
1018                    unsigned int offset, 
1019                    unsigned int whence )
1020{
1021    return sys_call( SYSCALL_FAT_LSEEK, 
1022                     fd_id, 
1023                     offset, 
1024                     whence,
1025                     0 ); 
1026}
1027
1028////////////////////////////////////////////
1029int giet_fat_remove( char*         pathname,
1030                     unsigned int  should_be_dir )
1031{
1032    return sys_call( SYSCALL_FAT_REMOVE,
1033                     (unsigned int)pathname,
1034                      should_be_dir,
1035                      0, 0 );
1036}
1037
1038/////////////////////////////////////
1039int giet_fat_rename( char*  old_path,
1040                     char*  new_path )
1041{
1042    return sys_call( SYSCALL_FAT_RENAME,
1043                     (unsigned int)old_path,
1044                     (unsigned int)new_path,
1045                      0, 0 );
1046}
1047
1048////////////////////////////////////
1049int giet_fat_mkdir( char* pathname )
1050{
1051    return sys_call( SYSCALL_FAT_MKDIR,
1052                     (unsigned int)pathname,
1053                      0, 0, 0 );
1054}
1055
1056////////////////////////////////////
1057int giet_fat_opendir( char* pathname )
1058{
1059    return sys_call( SYSCALL_FAT_OPENDIR,
1060                     (unsigned int)pathname,
1061                     0, 0, 0 );
1062}
1063
1064////////////////////////////////////
1065int giet_fat_closedir( unsigned int fd_id )
1066{
1067    return sys_call( SYSCALL_FAT_CLOSEDIR,
1068                     (unsigned int)fd_id,
1069                     0, 0, 0 );
1070}
1071
1072////////////////////////////////////
1073int giet_fat_readdir( unsigned int  fd_id,
1074                      fat_dirent_t* entry )
1075{
1076    return sys_call( SYSCALL_FAT_READDIR,
1077                     (unsigned int)fd_id,
1078                     (unsigned int)entry,
1079                     0, 0 );
1080}
1081
1082/////////////////////////////////////
1083int giet_fat_list( char* pathname )
1084{
1085    return sys_call( SYSCALL_FAT_LIST,
1086                     (unsigned int)pathname,
1087                     0, 0, 0 );
1088}
1089
1090
1091
1092//////////////////////////////////////////////////////////////////////////////////
1093///////////////////// Miscellaneous system calls /////////////////////////////////
1094//////////////////////////////////////////////////////////////////////////////////
1095
1096/////////////////////////////////////////////////
1097void giet_procs_number( unsigned int* x_size, 
1098                        unsigned int* y_size,
1099                        unsigned int* nprocs ) 
1100{
1101    if ( sys_call( SYSCALL_PROCS_NUMBER, 
1102                   (unsigned int)x_size, 
1103                   (unsigned int)y_size, 
1104                   (unsigned int)nprocs, 
1105                   0 ) )  giet_exit("ERROR in giet_procs_number()");
1106}
1107
1108////////////////////////////////////////////////////
1109void giet_vobj_get_vbase( char*         vspace_name, 
1110                          char*         vobj_name, 
1111                          unsigned int* vbase ) 
1112{
1113    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1114                   (unsigned int) vspace_name,
1115                   (unsigned int) vobj_name,
1116                   (unsigned int) vbase,
1117                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
1118}
1119
1120////////////////////////////////////////////////////
1121void giet_vobj_get_length( char*         vspace_name, 
1122                           char*         vobj_name, 
1123                           unsigned int* length ) 
1124{
1125    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
1126                   (unsigned int) vspace_name,
1127                   (unsigned int) vobj_name,
1128                   (unsigned int) length,
1129                   0 ) )  giet_exit("ERROR in giet_vobj_get_length()");
1130}
1131
1132/////////////////////////////////////////
1133void giet_heap_info( unsigned int* vaddr, 
1134                     unsigned int* length,
1135                     unsigned int  x,
1136                     unsigned int  y ) 
1137{
1138    if ( sys_call( SYSCALL_HEAP_INFO, 
1139                   (unsigned int)vaddr, 
1140                   (unsigned int)length, 
1141                   x,
1142                   y ) )  giet_exit("ERROR in giet_heap_info()");
1143}
1144
1145/////////////////////////////////////////
1146void giet_get_xy( void*         ptr,
1147                  unsigned int* px,
1148                  unsigned int* py )
1149{
1150    if ( sys_call( SYSCALL_GET_XY,
1151                   (unsigned int)ptr,
1152                   (unsigned int)px,
1153                   (unsigned int)py,
1154                   0 ) )  giet_exit("ERROR in giet_get_xy()");
1155}
1156
1157// Local Variables:
1158// tab-width: 4
1159// c-basic-offset: 4
1160// c-file-offsets:((innamespace . 0)(inline-open . 0))
1161// indent-tabs-mode: nil
1162// End:
1163// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
1164
Note: See TracBrowser for help on using the repository browser.