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

Last change on this file since 689 was 689, checked in by alain, 9 years ago

Introduce the giet_tasks-status() syscall.

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