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

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

Introduce the "shared" argument in the giet_tty_alloc() system call.

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