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

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

stdio: printf: fix compilation warning using an union

  • Property svn:executable set to *
File size: 35.2 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                union
353                {
354                    double d;
355                    unsigned long long ull;
356                } val;
357               
358                val.d = va_arg( *args, double );
359               
360                unsigned long long digits = val.ull & 0xFFFFFFFFFFFFFULL;    //get mantissa
361               
362                unsigned int
363                    base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52), //get exposant
364                    intp = (unsigned int)val.d,         //get integer part of the float
365                    decp;
366               
367                int isvalue = 0;
368               
369                if (base == 0x7FF) //special value
370                {
371                    if (digits & 0xFFFFFFFFFFFFFULL)
372                    {
373                        /* Not a Number */
374                        buf[0] = 'N';
375                        buf[1] = 'a';
376                        buf[2] = 'N';
377                        len = 3;
378                        pbuf = buf;
379                    }
380                    else
381                    {
382                        /* inf */
383                        buf[0] = (val.ull & 0x8000000000000000ULL) ? '-' : '+';
384                        buf[1] = 'i';
385                        buf[2] = 'n';
386                        buf[3] = 'f';
387                        len = 4;
388                        pbuf = buf;
389                    }
390                    break;
391                }
392               
393                if (val.ull & 0x8000000000000000ULL)
394                {
395                    /* negative */
396                    ret = sys_call(SYSCALL_TTY_WRITE,
397                                (unsigned int)"-",
398                                1,
399                                channel,
400                                0);
401                    if (ret != 1) goto return_error;
402                    val.d = val.d * -1;
403                }
404                else
405                {
406                    /* positive */
407                    ret = sys_call(SYSCALL_TTY_WRITE,
408                                (unsigned int)"+",
409                                1,
410                                channel,
411                                0);
412                    if (ret != 1) goto return_error;
413                }
414               
415                if (val.d > 0xFFFFFFFF)
416                {
417                    /* overflow */
418                    buf[0] = 'B';
419                    buf[1] = 'I';
420                    buf[2] = 'G';
421                    len = 3;
422                    pbuf = buf;
423                    break;
424                }
425               
426                val.d -= (double)intp;
427                decp = (unsigned int)(val.d * 1000000000);
428               
429                for(i = 0; i < 10; i++) 
430                {
431                    if ((!isvalue) && (intp % 10)) isvalue = 1;
432                    buf[9 - i] = HexaTab[intp % 10];
433                    if (!(intp /= 10)) break;
434                }
435                pbuf = &buf[9 - i];
436                len = i+11;
437                buf[10] = '.';
438               
439                for(i = 0; i < 9; i++)
440                {
441                    if ((!isvalue) && (decp % 10)) isvalue = 1;
442                    buf[19 - i] = HexaTab[decp % 10];
443                    decp /= 10;
444                }
445               
446                if (!isvalue)
447                {
448                    if (val.d != 0)
449                    {
450                        /* underflow */
451                        buf[0] = 'T';
452                        buf[1] = 'I';
453                        buf[2] = 'N';
454                        buf[3] = 'Y';
455                        len = 4;
456                        pbuf = buf;
457                    }
458                }
459
460                break;
461            }
462            case ('l'):
463                switch (modifiers)
464                {
465                    case NO_MOD:
466                        modifiers = L_MOD;
467                        goto printf_arguments;
468                   
469                    case L_MOD:
470                        modifiers = LL_MOD;
471                        goto printf_arguments;
472                   
473                    default:
474                        goto return_error;
475                }
476
477            /* Ignored fields : width and precision */
478            case ('.'): goto printf_arguments;
479               
480            default:
481                goto return_error;
482        }
483
484        ret = sys_call(SYSCALL_TTY_WRITE, 
485                       (unsigned int)pbuf,
486                       len,
487                       channel, 
488                       0);
489        if (ret != len)  goto return_error;
490       
491        goto printf_text;
492    }
493
494return_error:
495    return 1;
496} // end __printf()
497
498
499////////////////////////////////////////
500void giet_tty_printf( char* format, ...) 
501{
502    va_list args;
503
504    va_start( args, format );
505    int ret = __printf(format, 0xFFFFFFFF, &args);
506    va_end( args );
507
508    if (ret)
509    {
510        giet_exit("ERROR in giet_tty_printf()");
511    }
512} // end giet_tty_printf()
513
514////////////////////////////////////////
515void giet_shr_printf( char* format, ...) 
516{
517    va_list args;
518    volatile unsigned int sr_save;
519
520    sys_call( SYSCALL_TTY_GET_LOCK,
521              0,
522              (unsigned int)&sr_save,
523              0, 0 );
524
525    va_start( args, format );
526    int ret = __printf(format, 0, &args);
527    va_end( args );
528
529    sys_call( SYSCALL_TTY_RELEASE_LOCK,
530              0,
531              (unsigned int)&sr_save,
532              0, 0 );
533
534    if (ret)
535    {
536        giet_exit("error in giet_shr_printf()");
537    }
538} // end giet_shr_printf()
539
540/////////////////////////////////
541void giet_tty_getc( char * byte ) 
542{
543    int ret;
544
545    do
546    {
547        ret = sys_call(SYSCALL_TTY_READ, 
548                      (unsigned int)byte,  // buffer address
549                      1,                   // number of characters
550                      0xFFFFFFFF,          // channel index from task context
551                      0);
552        if ( ret < 0 ) giet_exit("error in giet_tty_getc()");
553    }
554    while (ret != 1); 
555}
556
557/////////////////////////////////////
558void giet_tty_gets( char*        buf, 
559                    unsigned int bufsize ) 
560{
561    int           ret;                           // return value from syscalls
562    unsigned char byte;
563    unsigned int  index = 0;
564    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
565 
566    while (index < (bufsize - 1)) 
567    {
568        // get one character
569        do 
570        { 
571            ret = sys_call(SYSCALL_TTY_READ, 
572                           (unsigned int)(&byte),
573                           1,
574                           0xFFFFFFFF,        // channel index from task context
575                           0);
576            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
577        } 
578        while (ret != 1);
579
580        // analyse character
581        if (byte == 0x0A)                          // LF  special character
582        {
583            break; 
584        }
585        else if ( (byte == 0x7F) ||                // DEL special character
586                  (byte == 0x08) )                 // BS  special character
587        {
588            if ( index > 0 )     
589            {
590                index--; 
591
592                // cancel character
593                ret = sys_call( SYSCALL_TTY_WRITE,
594                                (unsigned int)(&string_cancel),
595                                3,
596                                0XFFFFFFFF,        // channel index from task context
597                                0 );
598                if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
599            }
600        }
601        else if ( (byte < 0x20) || (byte > 0x7F) )  // non printable characters
602        {
603        }
604        else                                       // take all other characters
605        {
606            buf[index] = byte;
607            index++;
608
609            // echo
610            ret = sys_call( SYSCALL_TTY_WRITE,
611                            (unsigned int)(&byte),
612                            1,
613                            0XFFFFFFFF,        // channel index from task context
614                            0 );
615            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
616     
617        }
618    }
619    buf[index] = 0;
620
621}   // end giet_tty_gets()
622
623///////////////////////////////////////
624void giet_tty_getw( unsigned int* val ) 
625{
626    unsigned char buf[32];
627    unsigned int  string_byte   = 0x00000000;    // string containing one single byte
628    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
629    unsigned int  save = 0;
630    unsigned int  dec = 0;
631    unsigned int  done = 0;
632    unsigned int  overflow = 0;
633    unsigned int  length = 0;
634    unsigned int  i;
635    int           ret;      // return value from syscalls
636 
637    // get characters
638    while (done == 0) 
639    {
640        // read one character
641        do 
642        { 
643            ret = sys_call( SYSCALL_TTY_READ,
644                            (unsigned int)(&string_byte),
645                            1,
646                            0xFFFFFFFF,    // channel index from task context
647                            0); 
648            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
649        } 
650        while (ret != 1);
651
652        // analyse character
653        if ((string_byte > 0x2F) && (string_byte < 0x3A))  // decimal character
654        {
655            buf[length] = (unsigned char)string_byte;
656            length++;
657
658            // echo
659            ret = sys_call( SYSCALL_TTY_WRITE, 
660                            (unsigned int)(&string_byte),
661                            1, 
662                            0xFFFFFFFF,    // channel index from task context
663                            0 );
664            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
665        }
666        else if (string_byte == 0x0A)                     // LF character
667        {
668            done = 1;
669        }
670        else if ( (string_byte == 0x7F) ||                // DEL character
671                  (string_byte == 0x08) )                 // BS  character
672        {
673            if ( length > 0 ) 
674            {
675                length--;    // cancel the character
676
677                ret = sys_call( SYSCALL_TTY_WRITE, 
678                                (unsigned int)(&string_cancel),
679                                3, 
680                                0xFFFFFFFF,    // channel index from task context
681                                0 );
682                if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
683            }
684        }
685
686        // test buffer overflow
687        if ( length >= 32 ) 
688        {
689            overflow = 1;
690            done     = 1;
691        }
692    }  // end while characters
693
694    // string to int conversion with overflow detection
695    if ( overflow == 0 )
696    {
697        for (i = 0; (i < length) && (overflow == 0) ; i++) 
698        {
699            dec = dec * 10 + (buf[i] - 0x30);
700            if (dec < save)  overflow = 1; 
701            save = dec;
702        }
703    } 
704
705    // final evaluation
706    if ( overflow == 0 )
707    {
708        // return value
709        *val = dec;
710    }
711    else
712    {
713        // cancel all echo characters
714        for (i = 0; i < length ; i++) 
715        {
716            ret = sys_call( SYSCALL_TTY_WRITE, 
717                            (unsigned int)(&string_cancel),
718                            3, 
719                            0xFFFFFFFF,    // channel index from task context
720                            0 );
721            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
722        }
723        // echo character '0'
724        string_byte = 0x30;
725        ret = sys_call( SYSCALL_TTY_WRITE, 
726                        (unsigned int)(&string_byte),
727                        1, 
728                        0xFFFFFFFF,    // channel index from task context
729                        0 );
730        if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
731
732        // return 0 value
733        *val = 0;
734    }
735}   // end giet_tty_getw()
736
737
738//////////////////////////////////////////////////////////////////////////////////
739/////////////////////  TIMER related system calls ////////////////////////////////
740//////////////////////////////////////////////////////////////////////////////////
741
742///////////////////////
743void giet_timer_alloc() 
744{
745    if ( sys_call( SYSCALL_TIM_ALLOC,
746                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()");
747}
748
749////////////////////////////////////////////
750void giet_timer_start( unsigned int period ) 
751{
752    if ( sys_call( SYSCALL_TIM_START,
753                   period,
754                   0, 0, 0 ) ) giet_exit("error in giet_timer_start()");
755}
756
757//////////////////////
758void giet_timer_stop() 
759{
760    if ( sys_call( SYSCALL_TIM_STOP,
761                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()");
762}
763
764
765//////////////////////////////////////////////////////////////////////////////////
766///////////////  Frame buffer device related system calls  ///////////////////////
767//////////////////////////////////////////////////////////////////////////////////
768
769/////////////////////////
770void giet_fbf_cma_alloc()
771{
772    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
773                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_alloc()");
774}
775
776///////////////////////////////////////////
777void giet_fbf_cma_init_buf( void* buf0_vbase, 
778                            void* buf1_vbase,
779                            void* sts0_vaddr,
780                            void* sts1_vaddr )
781{
782    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
783                   (unsigned int)buf0_vbase, 
784                   (unsigned int)buf1_vbase,
785                   (unsigned int)sts0_vaddr, 
786                   (unsigned int)sts1_vaddr ) )   giet_exit("error in giet_fbf_cma_init_buf()");
787}
788
789///////////////////////////////////////////
790void giet_fbf_cma_start( unsigned int length )
791{
792    if ( sys_call( SYSCALL_FBF_CMA_START,
793                   length, 
794                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_start()");
795}
796
797////////////////////////////////////////////////
798void giet_fbf_cma_display( unsigned int buffer )
799{
800    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
801                   buffer, 
802                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
803}
804
805////////////////////////
806void giet_fbf_cma_stop()
807{
808    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
809                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
810}
811
812//////////////////////////////////////////////
813void giet_fbf_sync_write( unsigned int offset, 
814                          void *       buffer, 
815                          unsigned int length ) 
816{
817    if ( sys_call( SYSCALL_FBF_SYNC_WRITE, 
818                   offset, 
819                   (unsigned int)buffer, 
820                   length, 
821                   0 ) )  giet_exit("error in giet_fbf_sync_write()");
822}
823
824/////////////////////////////////////////////
825void giet_fbf_sync_read( unsigned int offset, 
826                         void *       buffer, 
827                         unsigned int length ) 
828{
829    if ( sys_call( SYSCALL_FBF_SYNC_READ, 
830                   offset, 
831                   (unsigned int)buffer, 
832                   length, 
833                   0 ) )   giet_exit("error in giet_fbf_sync_read()");
834}
835
836
837//////////////////////////////////////////////////////////////////////////////////
838/////////////////////// NIC related system calls /////////////////////////////////
839//////////////////////////////////////////////////////////////////////////////////
840
841////////////////////////////////////////////////////
842unsigned int giet_nic_rx_alloc( unsigned int xmax,
843                                unsigned int ymax )
844{
845    int channel = sys_call( SYSCALL_NIC_ALLOC,
846                            1, 
847                            xmax,
848                            ymax,
849                            0 );
850    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
851
852    return (unsigned int)channel;
853}
854
855////////////////////////////////////////////////////
856unsigned int giet_nic_tx_alloc( unsigned int xmax,
857                                unsigned int ymax )
858{
859    int channel = sys_call( SYSCALL_NIC_ALLOC,
860                            0,
861                            xmax,
862                            ymax,
863                            0 );
864    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
865
866    return (unsigned int)channel;
867}
868
869//////////////////////////////////////////////
870void giet_nic_rx_start( unsigned int channel )
871{
872    if ( sys_call( SYSCALL_NIC_START,
873                   1,
874                   channel,
875                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
876}
877
878//////////////////////////////////////////////
879void giet_nic_tx_start( unsigned int channel )
880{
881    if ( sys_call( SYSCALL_NIC_START,
882                   0, 
883                   channel,
884                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
885}
886
887///////////////////////////////////////////////////////////
888void giet_nic_rx_move( unsigned int channel, void* buffer )
889{
890    if ( sys_call( SYSCALL_NIC_MOVE,
891                   1,
892                   channel, 
893                   (unsigned int)buffer,
894                   0 ) )  giet_exit("error in giet_nic_rx_move()");
895}
896
897///////////////////////////////////////////////////////////
898void giet_nic_tx_move( unsigned int channel, void* buffer )
899{
900    if ( sys_call( SYSCALL_NIC_MOVE,
901                   0,
902                   channel, 
903                   (unsigned int)buffer,
904                   0 ) )  giet_exit("error in giet_nic_tx_move()");
905}
906
907/////////////////////////////////////////////
908void giet_nic_rx_stop( unsigned int channel )
909{
910    if ( sys_call( SYSCALL_NIC_STOP,
911                   1, 
912                   channel,
913                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
914}
915
916/////////////////////////////////////////////
917void giet_nic_tx_stop( unsigned int channel )
918{
919    if ( sys_call( SYSCALL_NIC_STOP,
920                   0, 
921                   channel,
922                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
923}
924
925//////////////////////////////////////////////
926void giet_nic_rx_stats( unsigned int channel )
927{
928    if ( sys_call( SYSCALL_NIC_STATS,
929                   1, 
930                   channel,
931                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
932}
933
934//////////////////////////////////////////////
935void giet_nic_tx_stats( unsigned int channel )
936{
937    if ( sys_call( SYSCALL_NIC_STATS,
938                   0, 
939                   channel,
940                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
941}
942
943//////////////////////////////////////////////
944void giet_nic_rx_clear( unsigned int channel )
945{
946    if ( sys_call( SYSCALL_NIC_CLEAR,
947                   1, 
948                   channel,
949                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
950}
951
952//////////////////////////////////////////////
953void giet_nic_tx_clear( unsigned int channel )
954{
955    if ( sys_call( SYSCALL_NIC_CLEAR,
956                   0, 
957                   channel,
958                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
959}
960
961
962
963///////////////////////////////////////////////////////////////////////////////////
964///////////////////// FAT related system calls ////////////////////////////////////
965///////////////////////////////////////////////////////////////////////////////////
966
967/////////////////////////////////////////
968int giet_fat_open( char*        pathname,
969                   unsigned int flags ) 
970{
971    return  sys_call( SYSCALL_FAT_OPEN, 
972                      (unsigned int)pathname, 
973                      flags,
974                      0, 0 );
975}
976
977/////////////////////////////////////////
978int giet_fat_close( unsigned int fd_id )
979{
980    return  sys_call( SYSCALL_FAT_CLOSE,
981                      fd_id,
982                      0, 0, 0 );
983}
984
985/////////////////////////////////////////////
986int giet_fat_file_info( unsigned int            fd_id,
987                        struct fat_file_info_s* info )
988{
989    return sys_call( SYSCALL_FAT_FINFO,
990                     fd_id,
991                     (unsigned int)info,
992                     0, 0 );
993}
994
995///////////////////////////////////////
996int giet_fat_read( unsigned int fd_id,     
997                   void*        buffer, 
998                   unsigned int count ) 
999{
1000    return sys_call( SYSCALL_FAT_READ,
1001                     fd_id,
1002                     (unsigned int)buffer,
1003                     count,
1004                     0 ); 
1005}
1006
1007////////////////////////////////////////
1008int giet_fat_write( unsigned int fd_id,
1009                    void*        buffer, 
1010                    unsigned int count )
1011{
1012    return sys_call( SYSCALL_FAT_WRITE, 
1013                     fd_id, 
1014                     (unsigned int)buffer,
1015                     count,
1016                     0 ); 
1017}
1018
1019////////////////////////////////////////
1020int giet_fat_lseek( unsigned int fd_id,
1021                    unsigned int offset, 
1022                    unsigned int whence )
1023{
1024    return sys_call( SYSCALL_FAT_LSEEK, 
1025                     fd_id, 
1026                     offset, 
1027                     whence,
1028                     0 ); 
1029}
1030
1031////////////////////////////////////////////
1032int giet_fat_remove( char*         pathname,
1033                     unsigned int  should_be_dir )
1034{
1035    return sys_call( SYSCALL_FAT_REMOVE,
1036                     (unsigned int)pathname,
1037                      should_be_dir,
1038                      0, 0 );
1039}
1040
1041/////////////////////////////////////
1042int giet_fat_rename( char*  old_path,
1043                     char*  new_path )
1044{
1045    return sys_call( SYSCALL_FAT_RENAME,
1046                     (unsigned int)old_path,
1047                     (unsigned int)new_path,
1048                      0, 0 );
1049}
1050
1051////////////////////////////////////
1052int giet_fat_mkdir( char* pathname )
1053{
1054    return sys_call( SYSCALL_FAT_MKDIR,
1055                     (unsigned int)pathname,
1056                      0, 0, 0 );
1057}
1058
1059////////////////////////////////////
1060int giet_fat_opendir( char* pathname )
1061{
1062    return sys_call( SYSCALL_FAT_OPENDIR,
1063                     (unsigned int)pathname,
1064                     0, 0, 0 );
1065}
1066
1067////////////////////////////////////
1068int giet_fat_closedir( unsigned int fd_id )
1069{
1070    return sys_call( SYSCALL_FAT_CLOSEDIR,
1071                     (unsigned int)fd_id,
1072                     0, 0, 0 );
1073}
1074
1075////////////////////////////////////
1076int giet_fat_readdir( unsigned int  fd_id,
1077                      fat_dirent_t* entry )
1078{
1079    return sys_call( SYSCALL_FAT_READDIR,
1080                     (unsigned int)fd_id,
1081                     (unsigned int)entry,
1082                     0, 0 );
1083}
1084
1085
1086
1087//////////////////////////////////////////////////////////////////////////////////
1088///////////////////// Miscellaneous system calls /////////////////////////////////
1089//////////////////////////////////////////////////////////////////////////////////
1090
1091/////////////////////////////////////////////////
1092void giet_procs_number( unsigned int* x_size, 
1093                        unsigned int* y_size,
1094                        unsigned int* nprocs ) 
1095{
1096    if ( sys_call( SYSCALL_PROCS_NUMBER, 
1097                   (unsigned int)x_size, 
1098                   (unsigned int)y_size, 
1099                   (unsigned int)nprocs, 
1100                   0 ) )  giet_exit("ERROR in giet_procs_number()");
1101}
1102
1103////////////////////////////////////////////////////
1104void giet_vobj_get_vbase( char*         vspace_name, 
1105                          char*         vobj_name, 
1106                          unsigned int* vbase ) 
1107{
1108    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1109                   (unsigned int) vspace_name,
1110                   (unsigned int) vobj_name,
1111                   (unsigned int) vbase,
1112                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
1113}
1114
1115////////////////////////////////////////////////////
1116void giet_vobj_get_length( char*         vspace_name, 
1117                           char*         vobj_name, 
1118                           unsigned int* length ) 
1119{
1120    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
1121                   (unsigned int) vspace_name,
1122                   (unsigned int) vobj_name,
1123                   (unsigned int) length,
1124                   0 ) )  giet_exit("ERROR in giet_vobj_get_length()");
1125}
1126
1127/////////////////////////////////////////
1128void giet_heap_info( unsigned int* vaddr, 
1129                     unsigned int* length,
1130                     unsigned int  x,
1131                     unsigned int  y ) 
1132{
1133    if ( sys_call( SYSCALL_HEAP_INFO, 
1134                   (unsigned int)vaddr, 
1135                   (unsigned int)length, 
1136                   x,
1137                   y ) )  giet_exit("ERROR in giet_heap_info()");
1138}
1139
1140/////////////////////////////////////////
1141void giet_get_xy( void*         ptr,
1142                  unsigned int* px,
1143                  unsigned int* py )
1144{
1145    if ( sys_call( SYSCALL_GET_XY,
1146                   (unsigned int)ptr,
1147                   (unsigned int)px,
1148                   (unsigned int)py,
1149                   0 ) )  giet_exit("ERROR in giet_get_xy()");
1150}
1151
1152// Local Variables:
1153// tab-width: 4
1154// c-basic-offset: 4
1155// c-file-offsets:((innamespace . 0)(inline-open . 0))
1156// indent-tabs-mode: nil
1157// End:
1158// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
1159
Note: See TracBrowser for help on using the repository browser.