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

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

Introduce the giet_fbf_size() and giet_fbf_alloc() system calls.

  • Property svn:executable set to *
File size: 36.4 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
[438]819/////////////////////////
820void giet_fbf_cma_alloc()
[258]821{
[438]822    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
[713]823                   0, 0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_ALLOC");
[258]824}
[295]825
826///////////////////////////////////////////
[614]827void giet_fbf_cma_init_buf( void* buf0_vbase, 
828                            void* buf1_vbase,
829                            void* sts0_vaddr,
830                            void* sts1_vaddr )
[258]831{
[614]832    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
833                   (unsigned int)buf0_vbase, 
834                   (unsigned int)buf1_vbase,
835                   (unsigned int)sts0_vaddr, 
[713]836                   (unsigned int)sts1_vaddr ) ) giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF");
[614]837}
838
839///////////////////////////////////////////
840void giet_fbf_cma_start( unsigned int length )
841{
[438]842    if ( sys_call( SYSCALL_FBF_CMA_START,
[614]843                   length, 
[713]844                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_START");
[258]845}
[295]846
[438]847////////////////////////////////////////////////
848void giet_fbf_cma_display( unsigned int buffer )
[258]849{
[438]850    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
851                   buffer, 
[713]852                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_DISPLAY");
[258]853}
[295]854
855////////////////////////
[438]856void giet_fbf_cma_stop()
[258]857{
[438]858    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
[713]859                   0, 0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_STOP");
[258]860}
861
[438]862//////////////////////////////////////////////
863void giet_fbf_sync_write( unsigned int offset, 
864                          void *       buffer, 
865                          unsigned int length ) 
866{
867    if ( sys_call( SYSCALL_FBF_SYNC_WRITE, 
868                   offset, 
869                   (unsigned int)buffer, 
870                   length, 
[713]871                   0 ) )  giet_pthread_exit("ERROR in FBF_SYNC_WRITE");
[438]872}
[258]873
[438]874/////////////////////////////////////////////
875void giet_fbf_sync_read( unsigned int offset, 
876                         void *       buffer, 
877                         unsigned int length ) 
878{
879    if ( sys_call( SYSCALL_FBF_SYNC_READ, 
880                   offset, 
881                   (unsigned int)buffer, 
882                   length, 
[713]883                   0 ) )   giet_pthread_exit("ERROR in FBF_SYNC_READ");
[438]884}
885
886
[258]887//////////////////////////////////////////////////////////////////////////////////
[709]888//                      NIC related system calls 
[258]889//////////////////////////////////////////////////////////////////////////////////
890
[709]891//////////////////////////////////////////
892void giet_nic_rx_alloc( unsigned int xmax,
893                        unsigned int ymax )
[258]894{
[709]895    if ( sys_call( SYSCALL_NIC_ALLOC,
896                   1,                    // RX
897                   xmax,
898                   ymax,
899                   0 ) ) giet_pthread_exit("error in giet_nic_rx_alloc()");
[258]900}
[295]901
[709]902//////////////////////////////////////////
903void giet_nic_tx_alloc( unsigned int xmax,
904                        unsigned int ymax )
[258]905{
[709]906    if ( sys_call( SYSCALL_NIC_ALLOC,
907                   0,                    // TX
908                   xmax,
909                   ymax,
910                   0 ) ) giet_pthread_exit("error in giet_nic_tx_alloc()");
[450]911}
912
[709]913////////////////////////
914void giet_nic_rx_start()
[450]915{
[461]916    if ( sys_call( SYSCALL_NIC_START,
[709]917                   1,                    // RX
918                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()");
[450]919}
920
[709]921////////////////////////
922void giet_nic_tx_start()
[450]923{
[461]924    if ( sys_call( SYSCALL_NIC_START,
[709]925                   0,                    // TX
926                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()");
[450]927}
928
[709]929/////////////////////////////////////
930void giet_nic_rx_move( void* buffer )
[450]931{
[461]932    if ( sys_call( SYSCALL_NIC_MOVE,
[709]933                   1,                    // RX
[438]934                   (unsigned int)buffer,
[709]935                   0, 0 ) )  giet_pthread_exit("error in giet_nic_rx_move()");
[258]936}
937
[709]938/////////////////////////////////////
939void giet_nic_tx_move( void* buffer )
[438]940{
[461]941    if ( sys_call( SYSCALL_NIC_MOVE,
[709]942                   0,                    // TX
[438]943                   (unsigned int)buffer,
[709]944                   0, 0 ) )  giet_pthread_exit("error in giet_nic_tx_move()");
[438]945}
946
[709]947///////////////////////
948void giet_nic_rx_stop()
[450]949{
[461]950    if ( sys_call( SYSCALL_NIC_STOP,
[709]951                   1,                    // RX
952                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()");
[450]953}
954
[709]955///////////////////////
956void giet_nic_tx_stop()
[450]957{
[461]958    if ( sys_call( SYSCALL_NIC_STOP,
[709]959                   0,                   // TX
960                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()");
[450]961}
962
[709]963////////////////////////
964void giet_nic_rx_stats()
[461]965{
966    if ( sys_call( SYSCALL_NIC_STATS,
[709]967                   1,                   // RX
968                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()");
[461]969}
[450]970
[709]971////////////////////////
972void giet_nic_tx_stats()
[461]973{
974    if ( sys_call( SYSCALL_NIC_STATS,
[709]975                   0,                   // TX
976                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()");
[461]977}
978
[709]979////////////////////////
980void giet_nic_rx_clear()
[461]981{
982    if ( sys_call( SYSCALL_NIC_CLEAR,
[709]983                   1,                   // RX
984                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()");
[461]985}
986
[709]987////////////////////////
988void giet_nic_tx_clear()
[461]989{
990    if ( sys_call( SYSCALL_NIC_CLEAR,
[709]991                   0,                   // TX
992                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()");
[461]993}
994
995
996
[295]997///////////////////////////////////////////////////////////////////////////////////
[709]998//                   FAT related system calls
[295]999///////////////////////////////////////////////////////////////////////////////////
[258]1000
[588]1001/////////////////////////////////////////
1002int giet_fat_open( char*        pathname,
1003                   unsigned int flags ) 
[295]1004{
[588]1005    return  sys_call( SYSCALL_FAT_OPEN, 
1006                      (unsigned int)pathname, 
1007                      flags,
1008                      0, 0 );
[295]1009}
[258]1010
[588]1011/////////////////////////////////////////
1012int giet_fat_close( unsigned int fd_id )
[295]1013{
[588]1014    return  sys_call( SYSCALL_FAT_CLOSE,
1015                      fd_id,
1016                      0, 0, 0 );
[295]1017}
1018
[588]1019/////////////////////////////////////////////
[623]1020int giet_fat_file_info( unsigned int            fd_id,
1021                        struct fat_file_info_s* info )
[295]1022{
[588]1023    return sys_call( SYSCALL_FAT_FINFO,
1024                     fd_id,
[623]1025                     (unsigned int)info,
1026                     0, 0 );
[295]1027}
1028
[588]1029///////////////////////////////////////
1030int giet_fat_read( unsigned int fd_id,     
1031                   void*        buffer, 
1032                   unsigned int count ) 
1033{
1034    return sys_call( SYSCALL_FAT_READ,
1035                     fd_id,
1036                     (unsigned int)buffer,
1037                     count,
[709]1038                     0 );      // no physical addressing required
[588]1039}
1040
1041////////////////////////////////////////
1042int giet_fat_write( unsigned int fd_id,
[295]1043                    void*        buffer, 
[588]1044                    unsigned int count )
[258]1045{
[295]1046    return sys_call( SYSCALL_FAT_WRITE, 
[588]1047                     fd_id, 
[295]1048                     (unsigned int)buffer,
[588]1049                     count,
[709]1050                     0 );      // no physical addressing required
[258]1051}
[295]1052
[588]1053////////////////////////////////////////
1054int giet_fat_lseek( unsigned int fd_id,
[295]1055                    unsigned int offset, 
1056                    unsigned int whence )
[258]1057{
[588]1058    return sys_call( SYSCALL_FAT_LSEEK, 
1059                     fd_id, 
1060                     offset, 
1061                     whence,
1062                     0 ); 
[258]1063}
[295]1064
[588]1065////////////////////////////////////////////
1066int giet_fat_remove( char*         pathname,
1067                     unsigned int  should_be_dir )
[258]1068{
[588]1069    return sys_call( SYSCALL_FAT_REMOVE,
1070                     (unsigned int)pathname,
1071                      should_be_dir,
1072                      0, 0 );
[258]1073}
[295]1074
1075/////////////////////////////////////
[588]1076int giet_fat_rename( char*  old_path,
1077                     char*  new_path )
[258]1078{
[588]1079    return sys_call( SYSCALL_FAT_RENAME,
1080                     (unsigned int)old_path,
1081                     (unsigned int)new_path,
1082                      0, 0 );
[258]1083}
[295]1084
[588]1085////////////////////////////////////
1086int giet_fat_mkdir( char* pathname )
1087{
1088    return sys_call( SYSCALL_FAT_MKDIR,
1089                     (unsigned int)pathname,
1090                      0, 0, 0 );
1091}
[295]1092
[659]1093////////////////////////////////////
1094int giet_fat_opendir( char* pathname )
1095{
1096    return sys_call( SYSCALL_FAT_OPENDIR,
1097                     (unsigned int)pathname,
1098                     0, 0, 0 );
1099}
1100
1101////////////////////////////////////
1102int giet_fat_closedir( unsigned int fd_id )
1103{
1104    return sys_call( SYSCALL_FAT_CLOSEDIR,
1105                     (unsigned int)fd_id,
1106                     0, 0, 0 );
1107}
1108
1109////////////////////////////////////
1110int giet_fat_readdir( unsigned int  fd_id,
1111                      fat_dirent_t* entry )
1112{
1113    return sys_call( SYSCALL_FAT_READDIR,
1114                     (unsigned int)fd_id,
1115                     (unsigned int)entry,
1116                     0, 0 );
1117}
1118
[295]1119
1120
[390]1121//////////////////////////////////////////////////////////////////////////////////
[709]1122//                      Miscellaneous system calls
[390]1123//////////////////////////////////////////////////////////////////////////////////
1124
[501]1125/////////////////////////////////////////////////
1126void giet_procs_number( unsigned int* x_size, 
1127                        unsigned int* y_size,
1128                        unsigned int* nprocs ) 
[438]1129{
[501]1130    if ( sys_call( SYSCALL_PROCS_NUMBER, 
1131                   (unsigned int)x_size, 
1132                   (unsigned int)y_size, 
1133                   (unsigned int)nprocs, 
[709]1134                   0 ) )  giet_pthread_exit("error in giet_procs_number()");
[438]1135}
1136
[295]1137////////////////////////////////////////////////////
1138void giet_vobj_get_vbase( char*         vspace_name, 
1139                          char*         vobj_name, 
[438]1140                          unsigned int* vbase ) 
[258]1141{
[295]1142    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1143                   (unsigned int) vspace_name,
1144                   (unsigned int) vobj_name,
[438]1145                   (unsigned int) vbase,
[709]1146                   0 ) )  giet_pthread_exit("error in giet_vobj_get_vbase()");
[258]1147}
[260]1148
[438]1149////////////////////////////////////////////////////
1150void giet_vobj_get_length( char*         vspace_name, 
1151                           char*         vobj_name, 
1152                           unsigned int* length ) 
[260]1153{
[438]1154    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
1155                   (unsigned int) vspace_name,
1156                   (unsigned int) vobj_name,
1157                   (unsigned int) length,
[709]1158                   0 ) )  giet_pthread_exit("error in giet_vobj_get_length()");
[260]1159}
1160
[295]1161/////////////////////////////////////////
1162void giet_heap_info( unsigned int* vaddr, 
[368]1163                     unsigned int* length,
1164                     unsigned int  x,
1165                     unsigned int  y ) 
[258]1166{
[709]1167    sys_call( SYSCALL_HEAP_INFO, 
1168              (unsigned int)vaddr, 
1169              (unsigned int)length, 
1170              x,
1171              y );
[258]1172}
1173
[390]1174/////////////////////////////////////////
1175void giet_get_xy( void*         ptr,
1176                  unsigned int* px,
1177                  unsigned int* py )
1178{
1179    if ( sys_call( SYSCALL_GET_XY,
1180                   (unsigned int)ptr,
1181                   (unsigned int)px,
1182                   (unsigned int)py,
[709]1183                   0 ) )  giet_pthread_exit("error in giet_get_xy()");
[390]1184}
1185
[258]1186// Local Variables:
1187// tab-width: 4
1188// c-basic-offset: 4
1189// c-file-offsets:((innamespace . 0)(inline-open . 0))
1190// indent-tabs-mode: nil
1191// End:
1192// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
1193
Note: See TracBrowser for help on using the repository browser.