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

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

Introduce the giet_tasks-status() syscall.

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