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

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

stdio: add %% support for printf()

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