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

Last change on this file since 585 was 581, checked in by laurent, 9 years ago

Adding ocean application, some mathematics functions and distributed locks

  • Property svn:executable set to *
File size: 32.1 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    {
[580]177        char buf[30];
[295]178        char * pbuf;
179        unsigned int len = 0;
180        static const char HexaTab[] = "0123456789ABCDEF";
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 );
[580]192                if (modifiers != NO_MOD) goto return_error; //Modifiers have no meaning
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               
203                if (modifiers == LL_MOD) goto return_error; //64 bits not supported
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               
246                if (modifiers == LL_MOD) //64 bits
[295]247                {
[580]248                    val = va_arg( *args, unsigned long long);
249                   
250                    if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000))) //if asked to print in base 10, can do only if it fits in 32 bits
251                    {
252                        unsigned int uintv = (unsigned int) val;
253                       
254                        for(i = 0; i < 10; i++) 
255                        {
256                            buf[9 - i] = HexaTab[uintv % 10];
257                            if (!(uintv /= 10)) break;
258                        }
259                        len =  i + 1;
260                        pbuf = &buf[9 - i];
261                        break;
262                    }
263                   
264                    imax = 16;
[295]265                }
[580]266                else //32 bits
267                {
268                    val = va_arg( *args, unsigned int);
269                    imax = 8;
270                }
271               
[295]272                ret = sys_call(SYSCALL_TTY_WRITE,
273                               (unsigned int)"0x",
274                               2,
275                               channel,
276                               0);
277                if (ret != 2) goto return_error;
[580]278               
279                for(i = 0; i < imax; i++) 
[295]280                {
[580]281                    buf[(imax-1) - i] = HexaTab[val % 16];
[295]282                    if (!(val /= 16))  break;
283                }
284                len =  i + 1;
[580]285                pbuf = &buf[(imax-1) - i];
[295]286                break;
287            }
288            case ('s'):             /* string */
289            {
[345]290                char* str = va_arg( *args, char* );
[580]291               
292                if (modifiers != NO_MOD) goto return_error; //Modifiers have no meaning
293               
[295]294                while (str[len]) 
295                {
296                    len++;
297                }
298                pbuf = str;
299                break;
300            }
[580]301            case ('e'):
302            case ('f'):
303            case ('g'):             /* IEEE754 64 bits */
304            {
305               
306                double vald = va_arg( *args, double);
307               
308                unsigned long long
309                    val = *(unsigned long long*)&vald, //get ieee754 without conversion
310                    digits = val & 0xFFFFFFFFFFFFF;    //get mantissa
311               
312                unsigned int
313                    base = (unsigned int)((val & 0x7FF0000000000000) >> 52), //get exposant
314                    intp = (unsigned int)vald,         //get integer part of the float
315                    decp;
316               
317                int isvalue = 0;
318               
319                if (base == 0x7FF) //special value
320                {
321                    if (digits & 0xFFFFFFFFFFFFF)
322                    {
323                        /* Not a Number */
324                        buf[0] = 'N';
325                        buf[1] = 'a';
326                        buf[2] = 'N';
327                        len = 3;
328                        pbuf = buf;
329                    }
330                    else
331                    {
332                        /* inf */
333                        buf[0] = (val & 0x8000000000000000) ? '-' : '+';
334                        buf[1] = 'i';
335                        buf[2] = 'n';
336                        buf[3] = 'f';
337                        len = 4;
338                        pbuf = buf;
339                    }
340                    break;
341                }
342               
343                if (val & 0x8000000000000000)
344                {
345                    /* negative */
346                    ret = sys_call(SYSCALL_TTY_WRITE,
347                                (unsigned int)"-",
348                                1,
349                                channel,
350                                0);
351                    if (ret != 1) goto return_error;
352                    vald = vald * -1;
353                }
354                else
355                {
356                    /* positive */
357                    ret = sys_call(SYSCALL_TTY_WRITE,
358                                (unsigned int)"+",
359                                1,
360                                channel,
361                                0);
362                    if (ret != 1) goto return_error;
363                }
364               
365                if (vald > 0xFFFFFFFF)
366                {
367                    /* overflow */
368                    buf[0] = 'B';
369                    buf[1] = 'I';
370                    buf[2] = 'G';
371                    len = 3;
372                    pbuf = buf;
373                    break;
374                }
375               
376                vald -= (double)intp;
[581]377                decp = (unsigned int)(vald * 1000000000);
[580]378               
379                for(i = 0; i < 10; i++) 
380                {
381                    if ((!isvalue) && (intp % 10)) isvalue = 1;
382                    buf[9 - i] = HexaTab[intp % 10];
383                    if (!(intp /= 10)) break;
384                }
385                pbuf = &buf[9 - i];
386                len = i+11;
387                buf[10] = '.';
388               
389                for(i = 0; i < 9; i++)
390                {
391                    if ((!isvalue) && (decp % 10)) isvalue = 1;
392                    buf[19 - i] = HexaTab[decp % 10];
393                    decp /= 10;
394                }
395               
396                if (!isvalue)
397                {
398                    if (vald != 0)
399                    {
400                        /* underflow */
401                        buf[0] = 'T';
402                        buf[1] = 'I';
403                        buf[2] = 'N';
404                        buf[3] = 'Y';
405                        len = 4;
406                        pbuf = buf;
407                    }
408                }
409
410                break;
411            }
412            case ('l'):
413                switch (modifiers)
414                {
415                    case NO_MOD:
416                        modifiers = L_MOD;
417                        goto printf_arguments;
418                   
419                    case L_MOD:
420                        modifiers = LL_MOD;
421                        goto printf_arguments;
422                   
423                    default:
424                        goto return_error;
425                }
426
427            /* Ignored fields : width and precision */
428            case ('.'): goto printf_arguments;
429               
[295]430            default:
431                goto return_error;
[258]432        }
433
[295]434        ret = sys_call(SYSCALL_TTY_WRITE, 
435                       (unsigned int)pbuf,
436                       len,
437                       channel, 
438                       0);
439        if (ret != len)  goto return_error;
440       
441        goto printf_text;
[258]442    }
443
[295]444return_error:
[345]445    return 1;
446} // end __printf()
[295]447
[345]448
449////////////////////////////////////////
450void giet_tty_printf( char* format, ...) 
451{
452    va_list args;
453
454    va_start( args, format );
455    int ret = __printf(format, 0xFFFFFFFF, &args);
[295]456    va_end( args );
[345]457
458    if (ret)
459    {
[382]460        giet_exit("ERROR in giet_tty_printf()");
[345]461    }
[295]462} // end giet_tty_printf()
463
464////////////////////////////////////////
465void giet_shr_printf( char* format, ...) 
[258]466{
[295]467    va_list args;
[345]468    volatile unsigned int sr_save;
[258]469
[295]470    sys_call( SYSCALL_TTY_GET_LOCK,
[501]471              0,
[295]472              (unsigned int)&sr_save,
473              0, 0 );
474
[345]475    va_start( args, format );
[501]476    int ret = __printf(format, 0, &args);
[345]477    va_end( args );
[258]478
[295]479    sys_call( SYSCALL_TTY_RELEASE_LOCK,
[501]480              0,
[295]481              (unsigned int)&sr_save,
482              0, 0 );
[267]483
[345]484    if (ret)
[258]485    {
[345]486        giet_exit("error in giet_shr_printf()");
[258]487    }
[345]488} // end giet_shr_printf()
[267]489
[295]490/////////////////////////////////
491void giet_tty_getc( char * byte ) 
492{
493    int ret;
494
495    do
[267]496    {
[295]497        ret = sys_call(SYSCALL_TTY_READ, 
498                      (unsigned int)byte,  // buffer address
499                      1,                   // number of characters
500                      0xFFFFFFFF,          // channel index from task context
501                      0);
502        if ( ret < 0 ) giet_exit("error in giet_tty_getc()");
[267]503    }
[295]504    while (ret != 1); 
505}
[267]506
[295]507/////////////////////////////////////
508void giet_tty_gets( char*        buf, 
509                    unsigned int bufsize ) 
510{
511    int           ret;
512    unsigned char byte;
513    unsigned int  index = 0;
514 
515    while (index < (bufsize - 1)) 
516    {
517        do 
518        { 
519            ret = sys_call(SYSCALL_TTY_READ, 
520                           (unsigned int)(&byte),
521                           1,
522                           0xFFFFFFFF,
523                           0);
524            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
525        } 
526        while (ret != 1);
527
528        if (byte == 0x0A)  /* LF */
529        {
530            break; 
531        }
532        else if ((byte == 0x7F) && (index > 0))  /* DEL */
533        {
534            index--; 
535        }
536        else 
537        {
538            buf[index] = byte;
539            index++;
540        }
541    }
542    buf[index] = 0;
[258]543}
544
[295]545///////////////////////////////////////
546void giet_tty_getw( unsigned int* val ) 
547{
548    unsigned char buf[32];
549    unsigned int  string_byte   = 0x00000000;    // string containing one single byte
550    unsigned int  string_cancel = 0x00082008;    // string containing BS/SPACE/BS
551    unsigned int  save = 0;
552    unsigned int  dec = 0;
553    unsigned int  done = 0;
554    unsigned int  overflow = 0;
555    unsigned int  length = 0;
556    unsigned int  i;
557    unsigned int  channel = 0xFFFFFFFF;
558    int           ret;      // return value from syscalls
559 
560    // get characters
561    while (done == 0) 
562    {
563        // read one character
564        do 
565        { 
566            ret = sys_call( SYSCALL_TTY_READ,
567                            (unsigned int)(&string_byte),
568                            1,
569                            channel, 
570                            0); 
571            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
572        } 
573        while (ret != 1);
[258]574
[295]575        // analyse character
576        if ((string_byte > 0x2F) && (string_byte < 0x3A))  /* decimal character */
577        {
578            buf[length] = (unsigned char)string_byte;
579            length++;
[258]580
[295]581            // echo
582            ret = sys_call( SYSCALL_TTY_WRITE, 
583                            (unsigned int)(&string_byte),
584                            1, 
585                            channel, 
586                            0 );
587            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
588        }
589        else if (string_byte == 0x0A)                     /* LF character */
590        {
591            done = 1;
592        }
593        else if ( (string_byte == 0x7F) ||                /* DEL character */
594                  (string_byte == 0x08) )                 /* BS  character */
595        {
596            if ( length > 0 ) 
597            {
598                length--;    // cancel the character
599
600                ret = sys_call( SYSCALL_TTY_WRITE, 
601                                (unsigned int)(&string_cancel),
602                                3, 
603                                channel, 
604                                0 );
[352]605                if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
[295]606            }
607        }
608
609        // test buffer overflow
610        if ( length >= 32 ) 
611        {
612            overflow = 1;
613            done     = 1;
614        }
615    }  // end while characters
616
617    // string to int conversion with overflow detection
618    if ( overflow == 0 )
619    {
620        for (i = 0; (i < length) && (overflow == 0) ; i++) 
621        {
622            dec = dec * 10 + (buf[i] - 0x30);
623            if (dec < save)  overflow = 1; 
624            save = dec;
625        }
626    } 
627
628    // final evaluation
629    if ( overflow == 0 )
630    {
631        // return value
632        *val = dec;
633    }
634    else
635    {
636        // cancel all echo characters
637        for (i = 0; i < length ; i++) 
638        {
639            ret = sys_call( SYSCALL_TTY_WRITE, 
640                            (unsigned int)(&string_cancel),
641                            3, 
642                            channel, 
643                            0 );
[352]644            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
[295]645        }
646        // echo character '0'
647        string_byte = 0x30;
648        ret = sys_call( SYSCALL_TTY_WRITE, 
649                        (unsigned int)(&string_byte),
650                        1, 
651                        channel, 
652                        0 );
[352]653        if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
[295]654
655        // return 0 value
656        *val = 0;
657    }
658}
659
660
[258]661//////////////////////////////////////////////////////////////////////////////////
662/////////////////////  TIMER related system calls ////////////////////////////////
663//////////////////////////////////////////////////////////////////////////////////
664
[295]665///////////////////////
[438]666void giet_timer_alloc() 
[258]667{
[438]668    if ( sys_call( SYSCALL_TIM_ALLOC,
669                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()");
[258]670}
[295]671
[438]672////////////////////////////////////////////
673void giet_timer_start( unsigned int period ) 
674{
675    if ( sys_call( SYSCALL_TIM_START,
676                   period,
677                   0, 0, 0 ) ) giet_exit("error in giet_timer_start()");
678}
679
[295]680//////////////////////
681void giet_timer_stop() 
[258]682{
[438]683    if ( sys_call( SYSCALL_TIM_STOP,
684                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()");
[258]685}
686
687
688//////////////////////////////////////////////////////////////////////////////////
689///////////////  Frame buffer device related system calls  ///////////////////////
690//////////////////////////////////////////////////////////////////////////////////
691
[438]692/////////////////////////
693void giet_fbf_cma_alloc()
[258]694{
[438]695    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
696                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_alloc()");
[258]697}
[295]698
699///////////////////////////////////////////
[438]700void giet_fbf_cma_start( void *       buf0,
701                         void *       buf1,
702                         unsigned int length )
[258]703{
[438]704    if ( sys_call( SYSCALL_FBF_CMA_START,
[295]705                   (unsigned int)buf0, 
706                   (unsigned int)buf1, 
[438]707                   length,
708                   0 ) )   giet_exit("error in giet_fbf_cma_start()");
[258]709}
[295]710
[438]711////////////////////////////////////////////////
712void giet_fbf_cma_display( unsigned int buffer )
[258]713{
[438]714    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
715                   buffer, 
716                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
[258]717}
[295]718
719////////////////////////
[438]720void giet_fbf_cma_stop()
[258]721{
[438]722    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
723                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
[258]724}
725
[438]726//////////////////////////////////////////////
727void giet_fbf_sync_write( unsigned int offset, 
728                          void *       buffer, 
729                          unsigned int length ) 
730{
731    if ( sys_call( SYSCALL_FBF_SYNC_WRITE, 
732                   offset, 
733                   (unsigned int)buffer, 
734                   length, 
735                   0 ) )  giet_exit("error in giet_fbf_sync_write()");
736}
[258]737
[438]738/////////////////////////////////////////////
739void giet_fbf_sync_read( unsigned int offset, 
740                         void *       buffer, 
741                         unsigned int length ) 
742{
743    if ( sys_call( SYSCALL_FBF_SYNC_READ, 
744                   offset, 
745                   (unsigned int)buffer, 
746                   length, 
747                   0 ) )   giet_exit("error in giet_fbf_sync_read()");
748}
749
750
[258]751//////////////////////////////////////////////////////////////////////////////////
752/////////////////////// NIC related system calls /////////////////////////////////
753//////////////////////////////////////////////////////////////////////////////////
754
[501]755////////////////////////////////////////////////////
756unsigned int giet_nic_rx_alloc( unsigned int xmax,
757                                unsigned int ymax )
[258]758{
[461]759    int channel = sys_call( SYSCALL_NIC_ALLOC,
760                            1, 
[501]761                            xmax,
762                            ymax,
763                            0 );
[487]764    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
[461]765
[487]766    return (unsigned int)channel;
[258]767}
[295]768
[501]769////////////////////////////////////////////////////
770unsigned int giet_nic_tx_alloc( unsigned int xmax,
771                                unsigned int ymax )
[258]772{
[461]773    int channel = sys_call( SYSCALL_NIC_ALLOC,
[501]774                            0,
775                            xmax,
776                            ymax,
777                            0 );
[461]778    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
779
[487]780    return (unsigned int)channel;
[450]781}
782
[487]783//////////////////////////////////////////////
784void giet_nic_rx_start( unsigned int channel )
[450]785{
[461]786    if ( sys_call( SYSCALL_NIC_START,
787                   1,
[487]788                   channel,
789                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
[450]790}
791
[487]792//////////////////////////////////////////////
793void giet_nic_tx_start( unsigned int channel )
[450]794{
[461]795    if ( sys_call( SYSCALL_NIC_START,
796                   0, 
[487]797                   channel,
798                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
[450]799}
800
[461]801///////////////////////////////////////////////////////////
802void giet_nic_rx_move( unsigned int channel, void* buffer )
[450]803{
[461]804    if ( sys_call( SYSCALL_NIC_MOVE,
805                   1,
806                   channel, 
[438]807                   (unsigned int)buffer,
[461]808                   0 ) )  giet_exit("error in giet_nic_rx_move()");
[258]809}
810
[461]811///////////////////////////////////////////////////////////
812void giet_nic_tx_move( unsigned int channel, void* buffer )
[438]813{
[461]814    if ( sys_call( SYSCALL_NIC_MOVE,
815                   0,
816                   channel, 
[438]817                   (unsigned int)buffer,
[461]818                   0 ) )  giet_exit("error in giet_nic_tx_move()");
[438]819}
820
[487]821/////////////////////////////////////////////
822void giet_nic_rx_stop( unsigned int channel )
[450]823{
[461]824    if ( sys_call( SYSCALL_NIC_STOP,
825                   1, 
[487]826                   channel,
827                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
[450]828}
829
[487]830/////////////////////////////////////////////
831void giet_nic_tx_stop( unsigned int channel )
[450]832{
[461]833    if ( sys_call( SYSCALL_NIC_STOP,
834                   0, 
[487]835                   channel,
836                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
[450]837}
838
[487]839//////////////////////////////////////////////
840void giet_nic_rx_stats( unsigned int channel )
[461]841{
842    if ( sys_call( SYSCALL_NIC_STATS,
843                   1, 
[487]844                   channel,
845                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
[461]846}
[450]847
[487]848//////////////////////////////////////////////
849void giet_nic_tx_stats( unsigned int channel )
[461]850{
851    if ( sys_call( SYSCALL_NIC_STATS,
852                   0, 
[487]853                   channel,
854                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
[461]855}
856
[487]857//////////////////////////////////////////////
858void giet_nic_rx_clear( unsigned int channel )
[461]859{
860    if ( sys_call( SYSCALL_NIC_CLEAR,
861                   1, 
[487]862                   channel,
863                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
[461]864}
865
[487]866//////////////////////////////////////////////
867void giet_nic_tx_clear( unsigned int channel )
[461]868{
869    if ( sys_call( SYSCALL_NIC_CLEAR,
870                   0, 
[487]871                   channel,
872                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
[461]873}
874
875
876
[295]877///////////////////////////////////////////////////////////////////////////////////
878///////////////////// FAT related system calls ////////////////////////////////////
879///////////////////////////////////////////////////////////////////////////////////
[258]880
[295]881///////////////////////////////////////////
882int giet_fat_open( const char*   pathname, 
883                   unsigned int  flags )
884{
[550]885    int ret = sys_call( SYSCALL_FAT_OPEN, 
886                        (unsigned int)pathname, 
887                        flags,
888                        0, 0 );
889    if ( ret < 0 ) giet_exit("error in giet_fat_open()");
890    return ret;
[295]891}
[258]892
[295]893////////////////////////////////////
894void giet_fat_read( unsigned int fd,     
895                    void*        buffer, 
896                    unsigned int count, 
897                    unsigned int offset ) 
898{
899    if ( sys_call( SYSCALL_FAT_READ,
900                   fd, 
901                   (unsigned int)buffer,
902                   count, 
[390]903                   offset ) != count ) giet_exit("ERROR in giet_fat_read()");
[295]904}
905
906/////////////////////////////////////
907void giet_fat_write( unsigned int fd,
908                     void*        buffer, 
909                     unsigned int count,
910                     unsigned int offset )
911{
912    if ( sys_call( SYSCALL_FAT_WRITE, 
913                   fd, 
914                   (unsigned int)buffer,
915                   count, 
[390]916                   offset ) != count ) giet_exit("ERROR in giet_fat_write()");
[295]917}
918
919/* variant implementing the UNIX spec
[258]920///////////////////////////////////////////////////////////////////////////////////
[295]921// This system call writes to a file identified by the "fd" file descriptor.
922// - "buffer" is the source buffer virtual address (must be word aligned).
923// - "count" is a number of bytes (must be multiple of 4).
924// It uses the implicit "lseek" pointer in file descriptor.
[258]925///////////////////////////////////////////////////////////////////////////////////
[295]926void giet_fat_write( unsigned int fd,
927                    void*        buffer,
928                    unsigned int count )  // number of bytes
[258]929{
[295]930    return sys_call( SYSCALL_FAT_WRITE,
931                     fd,
932                     (unsigned int)buffer,
933                     count, 0 );
[258]934}
[295]935*/
936
937/////////////////////////////////////
938void giet_fat_lseek( unsigned int fd, 
939                    unsigned int offset, 
940                    unsigned int whence )
[258]941{
[295]942    if ( sys_call( SYSCALL_FAT_LSEEK, 
943                   fd, 
944                   offset, 
945                   whence, 
[390]946                   0 ) ) giet_exit("ERROR in giet_fat_lseek()");
[258]947}
[295]948
949//////////////////////////////////////
950void giet_fat_fstat( unsigned int fd )
[258]951{
[295]952    if ( sys_call( SYSCALL_FAT_FSTAT,
953                   fd,
[390]954                   0, 0, 0 ) )  giet_exit("ERROR in giet_fat_lseek()");
[258]955}
[295]956
957/////////////////////////////////////
958void giet_fat_close( unsigned int fd )
[258]959{
[295]960    if ( sys_call( SYSCALL_FAT_CLOSE,
961                   fd,
[390]962                   0, 0, 0 ) )  giet_exit("ERROR in giet_fat_close()");
[258]963}
[295]964
965
966
967
[390]968//////////////////////////////////////////////////////////////////////////////////
969///////////////////// Miscellaneous system calls /////////////////////////////////
970//////////////////////////////////////////////////////////////////////////////////
971
[295]972//////////////////////////////
973void giet_exit( char* string ) 
[258]974{
[295]975    sys_call( SYSCALL_EXIT,
976              (unsigned int)string,
977              0, 0, 0 );
[258]978}
[295]979
980/////////////////////////////////////////
981void giet_assert( unsigned int condition,
982                  char*        string )
[258]983{
[295]984    if ( condition == 0 ) giet_exit( string );
[258]985}
[295]986
[390]987//////////////////////////
988void giet_context_switch() 
989{
990    sys_call( SYSCALL_CTX_SWITCH,
991              0, 0, 0, 0 );
992}
993
[501]994/////////////////////////////////////////////////
995void giet_procs_number( unsigned int* x_size, 
996                        unsigned int* y_size,
997                        unsigned int* nprocs ) 
[438]998{
[501]999    if ( sys_call( SYSCALL_PROCS_NUMBER, 
1000                   (unsigned int)x_size, 
1001                   (unsigned int)y_size, 
1002                   (unsigned int)nprocs, 
1003                   0 ) )  giet_exit("ERROR in giet_procs_number()");
[438]1004}
1005
[295]1006////////////////////////////////////////////////////
1007void giet_vobj_get_vbase( char*         vspace_name, 
1008                          char*         vobj_name, 
[438]1009                          unsigned int* vbase ) 
[258]1010{
[295]1011    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1012                   (unsigned int) vspace_name,
1013                   (unsigned int) vobj_name,
[438]1014                   (unsigned int) vbase,
[390]1015                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
[258]1016}
[260]1017
[438]1018////////////////////////////////////////////////////
1019void giet_vobj_get_length( char*         vspace_name, 
1020                           char*         vobj_name, 
1021                           unsigned int* length ) 
[260]1022{
[438]1023    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
1024                   (unsigned int) vspace_name,
1025                   (unsigned int) vobj_name,
1026                   (unsigned int) length,
1027                   0 ) )  giet_exit("ERROR in giet_vobj_get_length()");
[260]1028}
1029
[295]1030/////////////////////////////////////////
1031void giet_heap_info( unsigned int* vaddr, 
[368]1032                     unsigned int* length,
1033                     unsigned int  x,
1034                     unsigned int  y ) 
[258]1035{
[295]1036    if ( sys_call( SYSCALL_HEAP_INFO, 
1037                   (unsigned int)vaddr, 
1038                   (unsigned int)length, 
[368]1039                   x,
[390]1040                   y ) )  giet_exit("ERROR in giet_heap_info()");
[258]1041}
1042
[390]1043/////////////////////////////////////////
1044void giet_get_xy( void*         ptr,
1045                  unsigned int* px,
1046                  unsigned int* py )
1047{
1048    if ( sys_call( SYSCALL_GET_XY,
1049                   (unsigned int)ptr,
1050                   (unsigned int)px,
1051                   (unsigned int)py,
1052                   0 ) )  giet_exit("ERROR in giet_get_xy()");
1053}
1054
[258]1055// Local Variables:
1056// tab-width: 4
1057// c-basic-offset: 4
1058// c-file-offsets:((innamespace . 0)(inline-open . 0))
1059// indent-tabs-mode: nil
1060// End:
1061// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
1062
Note: See TracBrowser for help on using the repository browser.