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

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

Introduce two new system calls:

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