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

Last change on this file since 622 was 614, checked in by bellefin, 9 years ago

Change the syscalls related to the NIC and the CMA
1) In a CHBUF, every buffer is linked to a variable called “status” which is equal to 1 if the buffer is full or 0 if it is empty. The status occupies 64 bytes to simplify cache coherence
2) The CHBUF descriptor now contains the physical addresses of the buffer and its status. It only occupies 64 bits.

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