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

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

Try

  • Property svn:executable set to *
File size: 32.1 KB
Line 
1//////////////////////////////////////////////////////////////////////////////
2// File     : stdio.c         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
6//////////////////////////////////////////////////////////////////////////////
7
8#include <stdarg.h>
9#include <stdio.h>
10#include <giet_config.h>
11
12//////////////////////////////////////////////////////////////////////////////
13/////////////////////  MIPS32     related system calls ///////////////////////
14//////////////////////////////////////////////////////////////////////////////
15
16////////////////////////////////////////////
17void giet_proc_xyp( unsigned int* cluster_x,
18                    unsigned int* cluster_y,
19                    unsigned int* lpid )
20{
21    sys_call( SYSCALL_PROC_XYP,
22              (unsigned int)cluster_x,
23              (unsigned int)cluster_y,
24              (unsigned int)lpid,
25               0 );
26}
27
28////////////////////////////
29unsigned int giet_proctime() 
30{
31    return (unsigned int)sys_call( SYSCALL_PROC_TIME, 
32                                   0, 0, 0, 0 );
33}
34
35////////////////////////
36unsigned int giet_rand() 
37{
38    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
39                                             0, 0, 0, 0);
40    if ((x & 0xF) > 7) 
41    {
42        return (x*x & 0xFFFF);
43    }
44    else 
45    {
46        return (x*x*x & 0xFFFF);
47    }
48}
49
50//////////////////////////////////////////////////////////////////////////////
51///////////////////// Task context  system calls /////////////////////////////
52//////////////////////////////////////////////////////////////////////////////
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
76//////////////////////////////////////////////////////////////////////////////
77///////////////////// Coprocessors  system calls  ////////////////////////////
78//////////////////////////////////////////////////////////////////////////////
79
80///////////////////////////////////////////////////
81void giet_coproc_alloc( unsigned int   coproc_type,
82                        unsigned int*  coproc_info )
83{
84    if ( sys_call( SYSCALL_COPROC_ALLOC,
85                   coproc_type,
86                   (unsigned int)coproc_info,
87                   0, 0 ) ) 
88        giet_exit("error in giet_coproc_alloc()");
89}
90
91/////////////////////////////////////////////////////////
92void giet_coproc_release( unsigned int coproc_reg_index )
93{
94    if ( sys_call( SYSCALL_COPROC_RELEASE,
95                   coproc_reg_index,
96                   0, 0, 0 ) ) 
97        giet_exit("error in giet_coproc_release()");
98}
99
100//////////////////////////////////////////////////////////////////
101void giet_coproc_channel_init( unsigned int            channel,
102                               giet_coproc_channel_t*  desc )
103{
104    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
105                   channel,
106                   (unsigned int)desc,
107                   0, 0 ) ) 
108        giet_exit("error in giet_coproc_channel_init()");
109}
110
111/////////////////////////////////////////////////////
112void giet_coproc_run( unsigned int coproc_reg_index )
113{
114    if ( sys_call( SYSCALL_COPROC_RUN,
115                   coproc_reg_index,
116                   0, 0, 0 ) ) 
117        giet_exit("error in giet_coproc_run()");
118}
119
120////////////////////////////
121void giet_coproc_completed()
122{
123    if ( sys_call( SYSCALL_COPROC_COMPLETED,
124                   0, 0, 0, 0 ) ) 
125        giet_exit("error in giet_coproc_completed");
126}
127
128
129//////////////////////////////////////////////////////////////////////////////
130/////////////////////  TTY device related system calls ///////////////////////
131//////////////////////////////////////////////////////////////////////////////
132
133/////////////////////
134void giet_tty_alloc()
135{
136    if ( sys_call( SYSCALL_TTY_ALLOC,
137                   0, 0, 0, 0 ) )  giet_exit("error in giet_tty_alloc()");
138}
139
140////////////////////////////////////////////////////////////////////////
141static  int __printf( char* format, unsigned int channel, va_list* args) 
142{
143    int ret;                    // return value from the syscall
144    enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers;
145
146printf_text:
147
148    while (*format) 
149    {
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,
158                           0);
159
160            if (ret != i) goto return_error;
161
162            format += i;
163        }
164        if (*format == '%') 
165        {
166            format++;
167            modifiers = NO_MOD;
168            goto printf_arguments;
169        }
170    }
171
172    return 0;
173
174printf_arguments:
175
176    {
177        char buf[30];
178        char * pbuf;
179        unsigned int len = 0;
180        static const char HexaTab[] = "0123456789ABCDEF";
181        unsigned int i;
182       
183        /* Ignored fields : width and precision */
184        for (; *format >= '0' && *format <= '9'; format++);
185
186        switch (*format++) 
187        {
188            case ('%'):
189            case ('c'):             /* char conversion */
190            {
191                int val = va_arg( *args, int );
192                if (modifiers != NO_MOD) goto return_error; //Modifiers have no meaning
193               
194                len = 1;
195                buf[0] = val;
196                pbuf = &buf[0];
197                break;
198            }
199            case ('d'):             /* decimal signed integer */
200            {
201                int val = va_arg( *args, int );
202               
203                if (modifiers == LL_MOD) goto return_error; //64 bits not supported
204               
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;
223            }
224            case ('u'):             /* decimal unsigned integer */
225            {
226                if (modifiers != LL_MOD) //32 bits integer
227                {
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;
237                }
238                //64 bits : base 10 unsupported : continue to hexa
239            }
240            case ('x'):
241            case ('X'):             /* hexadecimal integer */
242            {
243                unsigned long long val;
244                int imax;
245               
246                if (modifiers == LL_MOD) //64 bits
247                {
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;
265                }
266                else //32 bits
267                {
268                    val = va_arg( *args, unsigned int);
269                    imax = 8;
270                }
271               
272                ret = sys_call(SYSCALL_TTY_WRITE,
273                               (unsigned int)"0x",
274                               2,
275                               channel,
276                               0);
277                if (ret != 2) goto return_error;
278               
279                for(i = 0; i < imax; i++) 
280                {
281                    buf[(imax-1) - i] = HexaTab[val % 16];
282                    if (!(val /= 16))  break;
283                }
284                len =  i + 1;
285                pbuf = &buf[(imax-1) - i];
286                break;
287            }
288            case ('s'):             /* string */
289            {
290                char* str = va_arg( *args, char* );
291               
292                if (modifiers != NO_MOD) goto return_error; //Modifiers have no meaning
293               
294                while (str[len]) 
295                {
296                    len++;
297                }
298                pbuf = str;
299                break;
300            }
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;
377                decp = (unsigned int)(vald * 100000000);
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               
430            default:
431                goto return_error;
432        }
433
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;
442    }
443
444return_error:
445    return 1;
446} // end __printf()
447
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);
456    va_end( args );
457
458    if (ret)
459    {
460        giet_exit("ERROR in giet_tty_printf()");
461    }
462} // end giet_tty_printf()
463
464////////////////////////////////////////
465void giet_shr_printf( char* format, ...) 
466{
467    va_list args;
468    volatile unsigned int sr_save;
469
470    sys_call( SYSCALL_TTY_GET_LOCK,
471              0,
472              (unsigned int)&sr_save,
473              0, 0 );
474
475    va_start( args, format );
476    int ret = __printf(format, 0, &args);
477    va_end( args );
478
479    sys_call( SYSCALL_TTY_RELEASE_LOCK,
480              0,
481              (unsigned int)&sr_save,
482              0, 0 );
483
484    if (ret)
485    {
486        giet_exit("error in giet_shr_printf()");
487    }
488} // end giet_shr_printf()
489
490/////////////////////////////////
491void giet_tty_getc( char * byte ) 
492{
493    int ret;
494
495    do
496    {
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()");
503    }
504    while (ret != 1); 
505}
506
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;
543}
544
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);
574
575        // analyse character
576        if ((string_byte > 0x2F) && (string_byte < 0x3A))  /* decimal character */
577        {
578            buf[length] = (unsigned char)string_byte;
579            length++;
580
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 );
605                if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
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 );
644            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
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 );
653        if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
654
655        // return 0 value
656        *val = 0;
657    }
658}
659
660
661//////////////////////////////////////////////////////////////////////////////////
662/////////////////////  TIMER related system calls ////////////////////////////////
663//////////////////////////////////////////////////////////////////////////////////
664
665///////////////////////
666void giet_timer_alloc() 
667{
668    if ( sys_call( SYSCALL_TIM_ALLOC,
669                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()");
670}
671
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
680//////////////////////
681void giet_timer_stop() 
682{
683    if ( sys_call( SYSCALL_TIM_STOP,
684                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()");
685}
686
687
688//////////////////////////////////////////////////////////////////////////////////
689///////////////  Frame buffer device related system calls  ///////////////////////
690//////////////////////////////////////////////////////////////////////////////////
691
692/////////////////////////
693void giet_fbf_cma_alloc()
694{
695    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
696                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_alloc()");
697}
698
699///////////////////////////////////////////
700void giet_fbf_cma_start( void *       buf0,
701                         void *       buf1,
702                         unsigned int length )
703{
704    if ( sys_call( SYSCALL_FBF_CMA_START,
705                   (unsigned int)buf0, 
706                   (unsigned int)buf1, 
707                   length,
708                   0 ) )   giet_exit("error in giet_fbf_cma_start()");
709}
710
711////////////////////////////////////////////////
712void giet_fbf_cma_display( unsigned int buffer )
713{
714    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
715                   buffer, 
716                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
717}
718
719////////////////////////
720void giet_fbf_cma_stop()
721{
722    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
723                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
724}
725
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}
737
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
751//////////////////////////////////////////////////////////////////////////////////
752/////////////////////// NIC related system calls /////////////////////////////////
753//////////////////////////////////////////////////////////////////////////////////
754
755////////////////////////////////////////////////////
756unsigned int giet_nic_rx_alloc( unsigned int xmax,
757                                unsigned int ymax )
758{
759    int channel = sys_call( SYSCALL_NIC_ALLOC,
760                            1, 
761                            xmax,
762                            ymax,
763                            0 );
764    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
765
766    return (unsigned int)channel;
767}
768
769////////////////////////////////////////////////////
770unsigned int giet_nic_tx_alloc( unsigned int xmax,
771                                unsigned int ymax )
772{
773    int channel = sys_call( SYSCALL_NIC_ALLOC,
774                            0,
775                            xmax,
776                            ymax,
777                            0 );
778    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
779
780    return (unsigned int)channel;
781}
782
783//////////////////////////////////////////////
784void giet_nic_rx_start( unsigned int channel )
785{
786    if ( sys_call( SYSCALL_NIC_START,
787                   1,
788                   channel,
789                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
790}
791
792//////////////////////////////////////////////
793void giet_nic_tx_start( unsigned int channel )
794{
795    if ( sys_call( SYSCALL_NIC_START,
796                   0, 
797                   channel,
798                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
799}
800
801///////////////////////////////////////////////////////////
802void giet_nic_rx_move( unsigned int channel, void* buffer )
803{
804    if ( sys_call( SYSCALL_NIC_MOVE,
805                   1,
806                   channel, 
807                   (unsigned int)buffer,
808                   0 ) )  giet_exit("error in giet_nic_rx_move()");
809}
810
811///////////////////////////////////////////////////////////
812void giet_nic_tx_move( unsigned int channel, void* buffer )
813{
814    if ( sys_call( SYSCALL_NIC_MOVE,
815                   0,
816                   channel, 
817                   (unsigned int)buffer,
818                   0 ) )  giet_exit("error in giet_nic_tx_move()");
819}
820
821/////////////////////////////////////////////
822void giet_nic_rx_stop( unsigned int channel )
823{
824    if ( sys_call( SYSCALL_NIC_STOP,
825                   1, 
826                   channel,
827                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
828}
829
830/////////////////////////////////////////////
831void giet_nic_tx_stop( unsigned int channel )
832{
833    if ( sys_call( SYSCALL_NIC_STOP,
834                   0, 
835                   channel,
836                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
837}
838
839//////////////////////////////////////////////
840void giet_nic_rx_stats( unsigned int channel )
841{
842    if ( sys_call( SYSCALL_NIC_STATS,
843                   1, 
844                   channel,
845                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
846}
847
848//////////////////////////////////////////////
849void giet_nic_tx_stats( unsigned int channel )
850{
851    if ( sys_call( SYSCALL_NIC_STATS,
852                   0, 
853                   channel,
854                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
855}
856
857//////////////////////////////////////////////
858void giet_nic_rx_clear( unsigned int channel )
859{
860    if ( sys_call( SYSCALL_NIC_CLEAR,
861                   1, 
862                   channel,
863                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
864}
865
866//////////////////////////////////////////////
867void giet_nic_tx_clear( unsigned int channel )
868{
869    if ( sys_call( SYSCALL_NIC_CLEAR,
870                   0, 
871                   channel,
872                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
873}
874
875
876
877///////////////////////////////////////////////////////////////////////////////////
878///////////////////// FAT related system calls ////////////////////////////////////
879///////////////////////////////////////////////////////////////////////////////////
880
881///////////////////////////////////////////
882int giet_fat_open( const char*   pathname, 
883                   unsigned int  flags )
884{
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;
891}
892
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, 
903                   offset ) != count ) giet_exit("ERROR in giet_fat_read()");
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, 
916                   offset ) != count ) giet_exit("ERROR in giet_fat_write()");
917}
918
919/* variant implementing the UNIX spec
920///////////////////////////////////////////////////////////////////////////////////
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.
925///////////////////////////////////////////////////////////////////////////////////
926void giet_fat_write( unsigned int fd,
927                    void*        buffer,
928                    unsigned int count )  // number of bytes
929{
930    return sys_call( SYSCALL_FAT_WRITE,
931                     fd,
932                     (unsigned int)buffer,
933                     count, 0 );
934}
935*/
936
937/////////////////////////////////////
938void giet_fat_lseek( unsigned int fd, 
939                    unsigned int offset, 
940                    unsigned int whence )
941{
942    if ( sys_call( SYSCALL_FAT_LSEEK, 
943                   fd, 
944                   offset, 
945                   whence, 
946                   0 ) ) giet_exit("ERROR in giet_fat_lseek()");
947}
948
949//////////////////////////////////////
950void giet_fat_fstat( unsigned int fd )
951{
952    if ( sys_call( SYSCALL_FAT_FSTAT,
953                   fd,
954                   0, 0, 0 ) )  giet_exit("ERROR in giet_fat_lseek()");
955}
956
957/////////////////////////////////////
958void giet_fat_close( unsigned int fd )
959{
960    if ( sys_call( SYSCALL_FAT_CLOSE,
961                   fd,
962                   0, 0, 0 ) )  giet_exit("ERROR in giet_fat_close()");
963}
964
965
966
967
968//////////////////////////////////////////////////////////////////////////////////
969///////////////////// Miscellaneous system calls /////////////////////////////////
970//////////////////////////////////////////////////////////////////////////////////
971
972//////////////////////////////
973void giet_exit( char* string ) 
974{
975    sys_call( SYSCALL_EXIT,
976              (unsigned int)string,
977              0, 0, 0 );
978}
979
980/////////////////////////////////////////
981void giet_assert( unsigned int condition,
982                  char*        string )
983{
984    if ( condition == 0 ) giet_exit( string );
985}
986
987//////////////////////////
988void giet_context_switch() 
989{
990    sys_call( SYSCALL_CTX_SWITCH,
991              0, 0, 0, 0 );
992}
993
994/////////////////////////////////////////////////
995void giet_procs_number( unsigned int* x_size, 
996                        unsigned int* y_size,
997                        unsigned int* nprocs ) 
998{
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()");
1004}
1005
1006////////////////////////////////////////////////////
1007void giet_vobj_get_vbase( char*         vspace_name, 
1008                          char*         vobj_name, 
1009                          unsigned int* vbase ) 
1010{
1011    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1012                   (unsigned int) vspace_name,
1013                   (unsigned int) vobj_name,
1014                   (unsigned int) vbase,
1015                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
1016}
1017
1018////////////////////////////////////////////////////
1019void giet_vobj_get_length( char*         vspace_name, 
1020                           char*         vobj_name, 
1021                           unsigned int* length ) 
1022{
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()");
1028}
1029
1030/////////////////////////////////////////
1031void giet_heap_info( unsigned int* vaddr, 
1032                     unsigned int* length,
1033                     unsigned int  x,
1034                     unsigned int  y ) 
1035{
1036    if ( sys_call( SYSCALL_HEAP_INFO, 
1037                   (unsigned int)vaddr, 
1038                   (unsigned int)length, 
1039                   x,
1040                   y ) )  giet_exit("ERROR in giet_heap_info()");
1041}
1042
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
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.