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

Last change on this file since 623 was 623, checked in by guerin, 9 years ago

fat32: use struct for _fat_file_info(), pass is_dir

  • Property svn:executable set to *
File size: 32.4 KB
RevLine 
[521]1//////////////////////////////////////////////////////////////////////////////
[258]2// File     : stdio.c         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
[521]6//////////////////////////////////////////////////////////////////////////////
[258]7
8#include <stdarg.h>
9#include <stdio.h>
[267]10#include <giet_config.h>
[258]11
[521]12//////////////////////////////////////////////////////////////////////////////
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 );
[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               
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               
[588]292                if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
[580]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///////////////////////////////////////////
[614]700void giet_fbf_cma_init_buf( void* buf0_vbase, 
701                            void* buf1_vbase,
702                            void* sts0_vaddr,
703                            void* sts1_vaddr )
[258]704{
[614]705    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
706                   (unsigned int)buf0_vbase, 
707                   (unsigned int)buf1_vbase,
708                   (unsigned int)sts0_vaddr, 
709                   (unsigned int)sts1_vaddr ) )   giet_exit("error in giet_fbf_cma_init_buf()");
710}
711
712///////////////////////////////////////////
713void giet_fbf_cma_start( unsigned int length )
714{
[438]715    if ( sys_call( SYSCALL_FBF_CMA_START,
[614]716                   length, 
717                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_start()");
[258]718}
[295]719
[438]720////////////////////////////////////////////////
721void giet_fbf_cma_display( unsigned int buffer )
[258]722{
[438]723    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
724                   buffer, 
725                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
[258]726}
[295]727
728////////////////////////
[438]729void giet_fbf_cma_stop()
[258]730{
[438]731    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
732                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
[258]733}
734
[438]735//////////////////////////////////////////////
736void giet_fbf_sync_write( unsigned int offset, 
737                          void *       buffer, 
738                          unsigned int length ) 
739{
740    if ( sys_call( SYSCALL_FBF_SYNC_WRITE, 
741                   offset, 
742                   (unsigned int)buffer, 
743                   length, 
744                   0 ) )  giet_exit("error in giet_fbf_sync_write()");
745}
[258]746
[438]747/////////////////////////////////////////////
748void giet_fbf_sync_read( unsigned int offset, 
749                         void *       buffer, 
750                         unsigned int length ) 
751{
752    if ( sys_call( SYSCALL_FBF_SYNC_READ, 
753                   offset, 
754                   (unsigned int)buffer, 
755                   length, 
756                   0 ) )   giet_exit("error in giet_fbf_sync_read()");
757}
758
759
[258]760//////////////////////////////////////////////////////////////////////////////////
761/////////////////////// NIC related system calls /////////////////////////////////
762//////////////////////////////////////////////////////////////////////////////////
763
[501]764////////////////////////////////////////////////////
765unsigned int giet_nic_rx_alloc( unsigned int xmax,
766                                unsigned int ymax )
[258]767{
[461]768    int channel = sys_call( SYSCALL_NIC_ALLOC,
769                            1, 
[501]770                            xmax,
771                            ymax,
772                            0 );
[487]773    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
[461]774
[487]775    return (unsigned int)channel;
[258]776}
[295]777
[501]778////////////////////////////////////////////////////
779unsigned int giet_nic_tx_alloc( unsigned int xmax,
780                                unsigned int ymax )
[258]781{
[461]782    int channel = sys_call( SYSCALL_NIC_ALLOC,
[501]783                            0,
784                            xmax,
785                            ymax,
786                            0 );
[461]787    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
788
[487]789    return (unsigned int)channel;
[450]790}
791
[487]792//////////////////////////////////////////////
793void giet_nic_rx_start( unsigned int channel )
[450]794{
[461]795    if ( sys_call( SYSCALL_NIC_START,
796                   1,
[487]797                   channel,
798                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
[450]799}
800
[487]801//////////////////////////////////////////////
802void giet_nic_tx_start( unsigned int channel )
[450]803{
[461]804    if ( sys_call( SYSCALL_NIC_START,
805                   0, 
[487]806                   channel,
807                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
[450]808}
809
[461]810///////////////////////////////////////////////////////////
811void giet_nic_rx_move( unsigned int channel, void* buffer )
[450]812{
[461]813    if ( sys_call( SYSCALL_NIC_MOVE,
814                   1,
815                   channel, 
[438]816                   (unsigned int)buffer,
[461]817                   0 ) )  giet_exit("error in giet_nic_rx_move()");
[258]818}
819
[461]820///////////////////////////////////////////////////////////
821void giet_nic_tx_move( unsigned int channel, void* buffer )
[438]822{
[461]823    if ( sys_call( SYSCALL_NIC_MOVE,
824                   0,
825                   channel, 
[438]826                   (unsigned int)buffer,
[461]827                   0 ) )  giet_exit("error in giet_nic_tx_move()");
[438]828}
829
[487]830/////////////////////////////////////////////
831void giet_nic_rx_stop( unsigned int channel )
[450]832{
[461]833    if ( sys_call( SYSCALL_NIC_STOP,
834                   1, 
[487]835                   channel,
836                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
[450]837}
838
[487]839/////////////////////////////////////////////
840void giet_nic_tx_stop( unsigned int channel )
[450]841{
[461]842    if ( sys_call( SYSCALL_NIC_STOP,
843                   0, 
[487]844                   channel,
845                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
[450]846}
847
[487]848//////////////////////////////////////////////
849void giet_nic_rx_stats( unsigned int channel )
[461]850{
851    if ( sys_call( SYSCALL_NIC_STATS,
852                   1, 
[487]853                   channel,
854                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
[461]855}
[450]856
[487]857//////////////////////////////////////////////
858void giet_nic_tx_stats( unsigned int channel )
[461]859{
860    if ( sys_call( SYSCALL_NIC_STATS,
861                   0, 
[487]862                   channel,
863                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
[461]864}
865
[487]866//////////////////////////////////////////////
867void giet_nic_rx_clear( unsigned int channel )
[461]868{
869    if ( sys_call( SYSCALL_NIC_CLEAR,
870                   1, 
[487]871                   channel,
872                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
[461]873}
874
[487]875//////////////////////////////////////////////
876void giet_nic_tx_clear( unsigned int channel )
[461]877{
878    if ( sys_call( SYSCALL_NIC_CLEAR,
879                   0, 
[487]880                   channel,
881                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
[461]882}
883
884
885
[295]886///////////////////////////////////////////////////////////////////////////////////
887///////////////////// FAT related system calls ////////////////////////////////////
888///////////////////////////////////////////////////////////////////////////////////
[258]889
[588]890/////////////////////////////////////////
891int giet_fat_open( char*        pathname,
892                   unsigned int flags ) 
[295]893{
[588]894    return  sys_call( SYSCALL_FAT_OPEN, 
895                      (unsigned int)pathname, 
896                      flags,
897                      0, 0 );
[295]898}
[258]899
[588]900/////////////////////////////////////////
901int giet_fat_close( unsigned int fd_id )
[295]902{
[588]903    return  sys_call( SYSCALL_FAT_CLOSE,
904                      fd_id,
905                      0, 0, 0 );
[295]906}
907
[588]908/////////////////////////////////////////////
[623]909int giet_fat_file_info( unsigned int            fd_id,
910                        struct fat_file_info_s* info )
[295]911{
[588]912    return sys_call( SYSCALL_FAT_FINFO,
913                     fd_id,
[623]914                     (unsigned int)info,
915                     0, 0 );
[295]916}
917
[588]918///////////////////////////////////////
919int giet_fat_read( unsigned int fd_id,     
920                   void*        buffer, 
921                   unsigned int count ) 
922{
923    return sys_call( SYSCALL_FAT_READ,
924                     fd_id,
925                     (unsigned int)buffer,
926                     count,
927                     0 ); 
928}
929
930////////////////////////////////////////
931int giet_fat_write( unsigned int fd_id,
[295]932                    void*        buffer, 
[588]933                    unsigned int count )
[258]934{
[295]935    return sys_call( SYSCALL_FAT_WRITE, 
[588]936                     fd_id, 
[295]937                     (unsigned int)buffer,
[588]938                     count,
939                     0 ); 
[258]940}
[295]941
[588]942////////////////////////////////////////
943int giet_fat_lseek( unsigned int fd_id,
[295]944                    unsigned int offset, 
945                    unsigned int whence )
[258]946{
[588]947    return sys_call( SYSCALL_FAT_LSEEK, 
948                     fd_id, 
949                     offset, 
950                     whence,
951                     0 ); 
[258]952}
[295]953
[588]954////////////////////////////////////////////
955int giet_fat_remove( char*         pathname,
956                     unsigned int  should_be_dir )
[258]957{
[588]958    return sys_call( SYSCALL_FAT_REMOVE,
959                     (unsigned int)pathname,
960                      should_be_dir,
961                      0, 0 );
[258]962}
[295]963
964/////////////////////////////////////
[588]965int giet_fat_rename( char*  old_path,
966                     char*  new_path )
[258]967{
[588]968    return sys_call( SYSCALL_FAT_RENAME,
969                     (unsigned int)old_path,
970                     (unsigned int)new_path,
971                      0, 0 );
[258]972}
[295]973
[588]974////////////////////////////////////
975int giet_fat_mkdir( char* pathname )
976{
977    return sys_call( SYSCALL_FAT_MKDIR,
978                     (unsigned int)pathname,
979                      0, 0, 0 );
980}
[295]981
[588]982/////////////////////////////////////
983int giet_fat_list( char* pathname )
984{
985    return sys_call( SYSCALL_FAT_LIST,
986                     (unsigned int)pathname,
987                     0, 0, 0 );
988}
[295]989
990
[588]991
[390]992//////////////////////////////////////////////////////////////////////////////////
993///////////////////// Miscellaneous system calls /////////////////////////////////
994//////////////////////////////////////////////////////////////////////////////////
995
[295]996//////////////////////////////
997void giet_exit( char* string ) 
[258]998{
[295]999    sys_call( SYSCALL_EXIT,
1000              (unsigned int)string,
1001              0, 0, 0 );
[258]1002}
[295]1003
1004/////////////////////////////////////////
1005void giet_assert( unsigned int condition,
1006                  char*        string )
[258]1007{
[295]1008    if ( condition == 0 ) giet_exit( string );
[258]1009}
[295]1010
[390]1011//////////////////////////
1012void giet_context_switch() 
1013{
1014    sys_call( SYSCALL_CTX_SWITCH,
1015              0, 0, 0, 0 );
1016}
1017
[501]1018/////////////////////////////////////////////////
1019void giet_procs_number( unsigned int* x_size, 
1020                        unsigned int* y_size,
1021                        unsigned int* nprocs ) 
[438]1022{
[501]1023    if ( sys_call( SYSCALL_PROCS_NUMBER, 
1024                   (unsigned int)x_size, 
1025                   (unsigned int)y_size, 
1026                   (unsigned int)nprocs, 
1027                   0 ) )  giet_exit("ERROR in giet_procs_number()");
[438]1028}
1029
[295]1030////////////////////////////////////////////////////
1031void giet_vobj_get_vbase( char*         vspace_name, 
1032                          char*         vobj_name, 
[438]1033                          unsigned int* vbase ) 
[258]1034{
[295]1035    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1036                   (unsigned int) vspace_name,
1037                   (unsigned int) vobj_name,
[438]1038                   (unsigned int) vbase,
[390]1039                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
[258]1040}
[260]1041
[438]1042////////////////////////////////////////////////////
1043void giet_vobj_get_length( char*         vspace_name, 
1044                           char*         vobj_name, 
1045                           unsigned int* length ) 
[260]1046{
[438]1047    if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, 
1048                   (unsigned int) vspace_name,
1049                   (unsigned int) vobj_name,
1050                   (unsigned int) length,
1051                   0 ) )  giet_exit("ERROR in giet_vobj_get_length()");
[260]1052}
1053
[295]1054/////////////////////////////////////////
1055void giet_heap_info( unsigned int* vaddr, 
[368]1056                     unsigned int* length,
1057                     unsigned int  x,
1058                     unsigned int  y ) 
[258]1059{
[295]1060    if ( sys_call( SYSCALL_HEAP_INFO, 
1061                   (unsigned int)vaddr, 
1062                   (unsigned int)length, 
[368]1063                   x,
[390]1064                   y ) )  giet_exit("ERROR in giet_heap_info()");
[258]1065}
1066
[390]1067/////////////////////////////////////////
1068void giet_get_xy( void*         ptr,
1069                  unsigned int* px,
1070                  unsigned int* py )
1071{
1072    if ( sys_call( SYSCALL_GET_XY,
1073                   (unsigned int)ptr,
1074                   (unsigned int)px,
1075                   (unsigned int)py,
1076                   0 ) )  giet_exit("ERROR in giet_get_xy()");
1077}
1078
[258]1079// Local Variables:
1080// tab-width: 4
1081// c-basic-offset: 4
1082// c-file-offsets:((innamespace . 0)(inline-open . 0))
1083// indent-tabs-mode: nil
1084// End:
1085// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
1086
Note: See TracBrowser for help on using the repository browser.