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

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

Introduce two new arguments "cluster_xy" and "coproc_type"
in the system calls related to hardware coprocessors.

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