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

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

1) introduce the stdint.h file to define uint*_t and int*_t types.
2) introduce the bufio service in the mwmr library.
3) modify the fbf_cma system calls to support chbuf containing more than 2 buffers.

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