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

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

stdio: add %% support for printf()

  • Property svn:executable set to *
File size: 32.9 KB
RevLine 
[521]1//////////////////////////////////////////////////////////////////////////////
[258]2// File     : stdio.c         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
[521]6//////////////////////////////////////////////////////////////////////////////
[258]7
8#include <stdarg.h>
9#include <stdio.h>
[267]10#include <giet_config.h>
[258]11
[521]12//////////////////////////////////////////////////////////////////////////////
13/////////////////////  MIPS32     related system calls ///////////////////////
14//////////////////////////////////////////////////////////////////////////////
[390]15
[438]16////////////////////////////////////////////
[431]17void giet_proc_xyp( unsigned int* cluster_x,
18                    unsigned int* cluster_y,
19                    unsigned int* lpid )
[390]20{
[438]21    sys_call( SYSCALL_PROC_XYP,
[431]22              (unsigned int)cluster_x,
23              (unsigned int)cluster_y,
24              (unsigned int)lpid,
25               0 );
[390]26}
27
[438]28////////////////////////////
29unsigned int giet_proctime() 
[390]30{
[438]31    return (unsigned int)sys_call( SYSCALL_PROC_TIME, 
32                                   0, 0, 0, 0 );
[390]33}
34
[438]35////////////////////////
36unsigned int giet_rand() 
[390]37{
[438]38    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
39                                             0, 0, 0, 0);
[390]40    if ((x & 0xF) > 7) 
41    {
42        return (x*x & 0xFFFF);
43    }
44    else 
45    {
46        return (x*x*x & 0xFFFF);
47    }
48}
49
[521]50//////////////////////////////////////////////////////////////////////////////
51///////////////////// Task context  system calls /////////////////////////////
52//////////////////////////////////////////////////////////////////////////////
[438]53
54////////////////////////////////
55unsigned int giet_proc_task_id() 
56{
57    return (unsigned int)sys_call( SYSCALL_LOCAL_TASK_ID, 
58                                   0, 0, 0, 0 );
59}
60
61//////////////////////////////////
62unsigned int giet_global_task_id() 
63{
64    return (unsigned int)sys_call( SYSCALL_GLOBAL_TASK_ID, 
65                                   0, 0, 0, 0 );
66}
67
68/////////////////////////////
69unsigned int giet_thread_id() 
70{
71    return (unsigned int)sys_call( SYSCALL_THREAD_ID, 
72                                   0, 0, 0, 0 );
73}
74
75
[521]76//////////////////////////////////////////////////////////////////////////////
77///////////////////// Coprocessors  system calls  ////////////////////////////
78//////////////////////////////////////////////////////////////////////////////
[295]79
[521]80///////////////////////////////////////////////////
81void giet_coproc_alloc( unsigned int   coproc_type,
[558]82                        unsigned int*  coproc_info )
[521]83{
84    if ( sys_call( SYSCALL_COPROC_ALLOC,
85                   coproc_type,
86                   (unsigned int)coproc_info,
[558]87                   0, 0 ) ) 
[521]88        giet_exit("error in giet_coproc_alloc()");
89}
90
[558]91/////////////////////////////////////////////////////////
92void giet_coproc_release( unsigned int coproc_reg_index )
[521]93{
94    if ( sys_call( SYSCALL_COPROC_RELEASE,
[558]95                   coproc_reg_index,
[521]96                   0, 0, 0 ) ) 
97        giet_exit("error in giet_coproc_release()");
98}
99
100//////////////////////////////////////////////////////////////////
[558]101void giet_coproc_channel_init( unsigned int            channel,
[521]102                               giet_coproc_channel_t*  desc )
103{
104    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
105                   channel,
106                   (unsigned int)desc,
107                   0, 0 ) ) 
[558]108        giet_exit("error in giet_coproc_channel_init()");
[521]109}
110
[558]111/////////////////////////////////////////////////////
112void giet_coproc_run( unsigned int coproc_reg_index )
[521]113{
[558]114    if ( sys_call( SYSCALL_COPROC_RUN,
115                   coproc_reg_index,
116                   0, 0, 0 ) ) 
117        giet_exit("error in giet_coproc_run()");
[521]118}
119
[558]120////////////////////////////
121void giet_coproc_completed()
[521]122{
123    if ( sys_call( SYSCALL_COPROC_COMPLETED,
[558]124                   0, 0, 0, 0 ) ) 
[521]125        giet_exit("error in giet_coproc_completed");
126}
127
128
129//////////////////////////////////////////////////////////////////////////////
130/////////////////////  TTY device related system calls ///////////////////////
131//////////////////////////////////////////////////////////////////////////////
132
[438]133/////////////////////
134void giet_tty_alloc()
[258]135{
[521]136    if ( sys_call( SYSCALL_TTY_ALLOC,
137                   0, 0, 0, 0 ) )  giet_exit("error in giet_tty_alloc()");
[438]138}
[258]139
[438]140////////////////////////////////////////////////////////////////////////
141static  int __printf( char* format, unsigned int channel, va_list* args) 
142{
143    int ret;                    // return value from the syscall
[580]144    enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers;
[438]145
[295]146printf_text:
[258]147
[295]148    while (*format) 
[258]149    {
[295]150        unsigned int i;
151        for (i = 0 ; format[i] && (format[i] != '%') ; i++);
152        if (i) 
153        {
154            ret = sys_call(SYSCALL_TTY_WRITE, 
155                           (unsigned int)format,
156                           i, 
157                           channel,
[258]158                           0);
159
[295]160            if (ret != i) goto return_error;
161
162            format += i;
[258]163        }
[295]164        if (*format == '%') 
[258]165        {
[295]166            format++;
[580]167            modifiers = NO_MOD;
[295]168            goto printf_arguments;
[258]169        }
170    }
171
[345]172    return 0;
[295]173
174printf_arguments:
175
[258]176    {
[628]177        char              buf[30];
178        char *            pbuf;
179        unsigned int      len = 0;
[295]180        static const char HexaTab[] = "0123456789ABCDEF";
[628]181        unsigned int      i;
[580]182       
183        /* Ignored fields : width and precision */
184        for (; *format >= '0' && *format <= '9'; format++);
[258]185
[295]186        switch (*format++) 
[258]187        {
[580]188            case ('%'):
[641]189            {
190                len = 1;
191                pbuf = "%";
192                break;
193            }
[295]194            case ('c'):             /* char conversion */
[258]195            {
[345]196                int val = va_arg( *args, int );
[588]197                if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
[580]198               
[295]199                len = 1;
200                buf[0] = val;
201                pbuf = &buf[0];
202                break;
[258]203            }
[580]204            case ('d'):             /* decimal signed integer */
[258]205            {
[345]206                int val = va_arg( *args, int );
[580]207               
[588]208                if (modifiers == LL_MOD) goto return_error; // 64 bits not supported
[580]209               
[295]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;
[258]228            }
[580]229            case ('u'):             /* decimal unsigned integer */
[295]230            {
[580]231                if (modifiers != LL_MOD) //32 bits integer
[295]232                {
[580]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;
[295]242                }
[580]243                //64 bits : base 10 unsupported : continue to hexa
[295]244            }
[580]245            case ('x'):
246            case ('X'):             /* hexadecimal integer */
[295]247            {
[580]248                unsigned long long val;
249                int imax;
250               
[628]251                if (modifiers == LL_MOD) // 64 bits
[295]252                {
[580]253                    val = va_arg( *args, unsigned long long);
254                   
[628]255                    // if asked to print in base 10, can do only if it fits in 32 bits
256                    if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL))) 
[580]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;
[295]271                }
[580]272                else //32 bits
273                {
274                    val = va_arg( *args, unsigned int);
275                    imax = 8;
276                }
277               
[295]278                ret = sys_call(SYSCALL_TTY_WRITE,
279                               (unsigned int)"0x",
280                               2,
281                               channel,
282                               0);
283                if (ret != 2) goto return_error;
[580]284               
285                for(i = 0; i < imax; i++) 
[295]286                {
[580]287                    buf[(imax-1) - i] = HexaTab[val % 16];
[295]288                    if (!(val /= 16))  break;
289                }
290                len =  i + 1;
[580]291                pbuf = &buf[(imax-1) - i];
[295]292                break;
293            }
294            case ('s'):             /* string */
295            {
[345]296                char* str = va_arg( *args, char* );
[580]297               
[588]298                if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
[580]299               
[295]300                while (str[len]) 
301                {
302                    len++;
303                }
304                pbuf = str;
305                break;
306            }
[580]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
[628]316                    digits = val & 0xFFFFFFFFFFFFFULL;    //get mantissa
[580]317               
318                unsigned int
[628]319                    base = (unsigned int)((val & 0x7FF0000000000000ULL) >> 52), //get exposant
[580]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                {
[628]327                    if (digits & 0xFFFFFFFFFFFFFULL)
[580]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 */
[628]339                        buf[0] = (val & 0x8000000000000000ULL) ? '-' : '+';
[580]340                        buf[1] = 'i';
341                        buf[2] = 'n';
342                        buf[3] = 'f';
343                        len = 4;
344                        pbuf = buf;
345                    }
346                    break;
347                }
348               
[628]349                if (val & 0x8000000000000000ULL)
[580]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;
[581]383                decp = (unsigned int)(vald * 1000000000);
[580]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               
[295]436            default:
437                goto return_error;
[258]438        }
439
[295]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;
[258]448    }
449
[295]450return_error:
[345]451    return 1;
452} // end __printf()
[295]453
[345]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);
[295]462    va_end( args );
[345]463
464    if (ret)
465    {
[382]466        giet_exit("ERROR in giet_tty_printf()");
[345]467    }
[295]468} // end giet_tty_printf()
469
470////////////////////////////////////////
471void giet_shr_printf( char* format, ...) 
[258]472{
[295]473    va_list args;
[345]474    volatile unsigned int sr_save;
[258]475
[295]476    sys_call( SYSCALL_TTY_GET_LOCK,
[501]477              0,
[295]478              (unsigned int)&sr_save,
479              0, 0 );
480
[345]481    va_start( args, format );
[501]482    int ret = __printf(format, 0, &args);
[345]483    va_end( args );
[258]484
[295]485    sys_call( SYSCALL_TTY_RELEASE_LOCK,
[501]486              0,
[295]487              (unsigned int)&sr_save,
488              0, 0 );
[267]489
[345]490    if (ret)
[258]491    {
[345]492        giet_exit("error in giet_shr_printf()");
[258]493    }
[345]494} // end giet_shr_printf()
[267]495
[295]496/////////////////////////////////
497void giet_tty_getc( char * byte ) 
498{
499    int ret;
500
501    do
[267]502    {
[295]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()");
[267]509    }
[295]510    while (ret != 1); 
511}
[267]512
[295]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;
[258]549}
550
[295]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);
[258]580
[295]581        // analyse character
582        if ((string_byte > 0x2F) && (string_byte < 0x3A))  /* decimal character */
583        {
584            buf[length] = (unsigned char)string_byte;
585            length++;
[258]586
[295]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 );
[352]611                if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
[295]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 );
[352]650            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
[295]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 );
[352]659        if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
[295]660
661        // return 0 value
662        *val = 0;
663    }
664}
665
666
[258]667//////////////////////////////////////////////////////////////////////////////////
668/////////////////////  TIMER related system calls ////////////////////////////////
669//////////////////////////////////////////////////////////////////////////////////
670
[295]671///////////////////////
[438]672void giet_timer_alloc() 
[258]673{
[438]674    if ( sys_call( SYSCALL_TIM_ALLOC,
675                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()");
[258]676}
[295]677
[438]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
[295]686//////////////////////
687void giet_timer_stop() 
[258]688{
[438]689    if ( sys_call( SYSCALL_TIM_STOP,
690                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()");
[258]691}
692
693
694//////////////////////////////////////////////////////////////////////////////////
695///////////////  Frame buffer device related system calls  ///////////////////////
696//////////////////////////////////////////////////////////////////////////////////
697
[438]698/////////////////////////
699void giet_fbf_cma_alloc()
[258]700{
[438]701    if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
702                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_alloc()");
[258]703}
[295]704
705///////////////////////////////////////////
[614]706void giet_fbf_cma_init_buf( void* buf0_vbase, 
707                            void* buf1_vbase,
708                            void* sts0_vaddr,
709                            void* sts1_vaddr )
[258]710{
[614]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{
[438]721    if ( sys_call( SYSCALL_FBF_CMA_START,
[614]722                   length, 
723                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_start()");
[258]724}
[295]725
[438]726////////////////////////////////////////////////
727void giet_fbf_cma_display( unsigned int buffer )
[258]728{
[438]729    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
730                   buffer, 
731                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
[258]732}
[295]733
734////////////////////////
[438]735void giet_fbf_cma_stop()
[258]736{
[438]737    if ( sys_call( SYSCALL_FBF_CMA_STOP, 
738                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
[258]739}
740
[438]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}
[258]752
[438]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
[258]766//////////////////////////////////////////////////////////////////////////////////
767/////////////////////// NIC related system calls /////////////////////////////////
768//////////////////////////////////////////////////////////////////////////////////
769
[501]770////////////////////////////////////////////////////
771unsigned int giet_nic_rx_alloc( unsigned int xmax,
772                                unsigned int ymax )
[258]773{
[461]774    int channel = sys_call( SYSCALL_NIC_ALLOC,
775                            1, 
[501]776                            xmax,
777                            ymax,
778                            0 );
[487]779    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
[461]780
[487]781    return (unsigned int)channel;
[258]782}
[295]783
[501]784////////////////////////////////////////////////////
785unsigned int giet_nic_tx_alloc( unsigned int xmax,
786                                unsigned int ymax )
[258]787{
[461]788    int channel = sys_call( SYSCALL_NIC_ALLOC,
[501]789                            0,
790                            xmax,
791                            ymax,
792                            0 );
[461]793    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
794
[487]795    return (unsigned int)channel;
[450]796}
797
[487]798//////////////////////////////////////////////
799void giet_nic_rx_start( unsigned int channel )
[450]800{
[461]801    if ( sys_call( SYSCALL_NIC_START,
802                   1,
[487]803                   channel,
804                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
[450]805}
806
[487]807//////////////////////////////////////////////
808void giet_nic_tx_start( unsigned int channel )
[450]809{
[461]810    if ( sys_call( SYSCALL_NIC_START,
811                   0, 
[487]812                   channel,
813                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
[450]814}
815
[461]816///////////////////////////////////////////////////////////
817void giet_nic_rx_move( unsigned int channel, void* buffer )
[450]818{
[461]819    if ( sys_call( SYSCALL_NIC_MOVE,
820                   1,
821                   channel, 
[438]822                   (unsigned int)buffer,
[461]823                   0 ) )  giet_exit("error in giet_nic_rx_move()");
[258]824}
825
[461]826///////////////////////////////////////////////////////////
827void giet_nic_tx_move( unsigned int channel, void* buffer )
[438]828{
[461]829    if ( sys_call( SYSCALL_NIC_MOVE,
830                   0,
831                   channel, 
[438]832                   (unsigned int)buffer,
[461]833                   0 ) )  giet_exit("error in giet_nic_tx_move()");
[438]834}
835
[487]836/////////////////////////////////////////////
837void giet_nic_rx_stop( unsigned int channel )
[450]838{
[461]839    if ( sys_call( SYSCALL_NIC_STOP,
840                   1, 
[487]841                   channel,
842                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
[450]843}
844
[487]845/////////////////////////////////////////////
846void giet_nic_tx_stop( unsigned int channel )
[450]847{
[461]848    if ( sys_call( SYSCALL_NIC_STOP,
849                   0, 
[487]850                   channel,
851                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
[450]852}
853
[487]854//////////////////////////////////////////////
855void giet_nic_rx_stats( unsigned int channel )
[461]856{
857    if ( sys_call( SYSCALL_NIC_STATS,
858                   1, 
[487]859                   channel,
860                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
[461]861}
[450]862
[487]863//////////////////////////////////////////////
864void giet_nic_tx_stats( unsigned int channel )
[461]865{
866    if ( sys_call( SYSCALL_NIC_STATS,
867                   0, 
[487]868                   channel,
869                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
[461]870}
871
[487]872//////////////////////////////////////////////
873void giet_nic_rx_clear( unsigned int channel )
[461]874{
875    if ( sys_call( SYSCALL_NIC_CLEAR,
876                   1, 
[487]877                   channel,
878                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
[461]879}
880
[487]881//////////////////////////////////////////////
882void giet_nic_tx_clear( unsigned int channel )
[461]883{
884    if ( sys_call( SYSCALL_NIC_CLEAR,
885                   0, 
[487]886                   channel,
887                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
[461]888}
889
890
891
[295]892///////////////////////////////////////////////////////////////////////////////////
893///////////////////// FAT related system calls ////////////////////////////////////
894///////////////////////////////////////////////////////////////////////////////////
[258]895
[588]896/////////////////////////////////////////
897int giet_fat_open( char*        pathname,
898                   unsigned int flags ) 
[295]899{
[588]900    return  sys_call( SYSCALL_FAT_OPEN, 
901                      (unsigned int)pathname, 
902                      flags,
903                      0, 0 );
[295]904}
[258]905
[588]906/////////////////////////////////////////
907int giet_fat_close( unsigned int fd_id )
[295]908{
[588]909    return  sys_call( SYSCALL_FAT_CLOSE,
910                      fd_id,
911                      0, 0, 0 );
[295]912}
913
[588]914/////////////////////////////////////////////
[623]915int giet_fat_file_info( unsigned int            fd_id,
916                        struct fat_file_info_s* info )
[295]917{
[588]918    return sys_call( SYSCALL_FAT_FINFO,
919                     fd_id,
[623]920                     (unsigned int)info,
921                     0, 0 );
[295]922}
923
[588]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,
[295]938                    void*        buffer, 
[588]939                    unsigned int count )
[258]940{
[295]941    return sys_call( SYSCALL_FAT_WRITE, 
[588]942                     fd_id, 
[295]943                     (unsigned int)buffer,
[588]944                     count,
945                     0 ); 
[258]946}
[295]947
[588]948////////////////////////////////////////
949int giet_fat_lseek( unsigned int fd_id,
[295]950                    unsigned int offset, 
951                    unsigned int whence )
[258]952{
[588]953    return sys_call( SYSCALL_FAT_LSEEK, 
954                     fd_id, 
955                     offset, 
956                     whence,
957                     0 ); 
[258]958}
[295]959
[588]960////////////////////////////////////////////
961int giet_fat_remove( char*         pathname,
962                     unsigned int  should_be_dir )
[258]963{
[588]964    return sys_call( SYSCALL_FAT_REMOVE,
965                     (unsigned int)pathname,
966                      should_be_dir,
967                      0, 0 );
[258]968}
[295]969
970/////////////////////////////////////
[588]971int giet_fat_rename( char*  old_path,
972                     char*  new_path )
[258]973{
[588]974    return sys_call( SYSCALL_FAT_RENAME,
975                     (unsigned int)old_path,
976                     (unsigned int)new_path,
977                      0, 0 );
[258]978}
[295]979
[588]980////////////////////////////////////
981int giet_fat_mkdir( char* pathname )
982{
983    return sys_call( SYSCALL_FAT_MKDIR,
984                     (unsigned int)pathname,
985                      0, 0, 0 );
986}
[295]987
[588]988/////////////////////////////////////
989int giet_fat_list( char* pathname )
990{
991    return sys_call( SYSCALL_FAT_LIST,
992                     (unsigned int)pathname,
993                     0, 0, 0 );
994}
[295]995
996
[588]997
[390]998//////////////////////////////////////////////////////////////////////////////////
999///////////////////// Miscellaneous system calls /////////////////////////////////
1000//////////////////////////////////////////////////////////////////////////////////
1001
[295]1002//////////////////////////////
1003void giet_exit( char* string ) 
[258]1004{
[295]1005    sys_call( SYSCALL_EXIT,
1006              (unsigned int)string,
1007              0, 0, 0 );
[258]1008}
[295]1009
[628]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
[295]1026/////////////////////////////////////////
1027void giet_assert( unsigned int condition,
1028                  char*        string )
[258]1029{
[295]1030    if ( condition == 0 ) giet_exit( string );
[258]1031}
[295]1032
[390]1033//////////////////////////
1034void giet_context_switch() 
1035{
1036    sys_call( SYSCALL_CTX_SWITCH,
1037              0, 0, 0, 0 );
1038}
1039
[501]1040/////////////////////////////////////////////////
1041void giet_procs_number( unsigned int* x_size, 
1042                        unsigned int* y_size,
1043                        unsigned int* nprocs ) 
[438]1044{
[501]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()");
[438]1050}
1051
[295]1052////////////////////////////////////////////////////
1053void giet_vobj_get_vbase( char*         vspace_name, 
1054                          char*         vobj_name, 
[438]1055                          unsigned int* vbase ) 
[258]1056{
[295]1057    if ( sys_call( SYSCALL_VOBJ_GET_VBASE, 
1058                   (unsigned int) vspace_name,
1059                   (unsigned int) vobj_name,
[438]1060                   (unsigned int) vbase,
[390]1061                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
[258]1062}
[260]1063
[438]1064////////////////////////////////////////////////////
1065void giet_vobj_get_length( char*         vspace_name, 
1066                           char*         vobj_name, 
1067                           unsigned int* length ) 
[260]1068{
[438]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()");
[260]1074}
1075
[295]1076/////////////////////////////////////////
1077void giet_heap_info( unsigned int* vaddr, 
[368]1078                     unsigned int* length,
1079                     unsigned int  x,
1080                     unsigned int  y ) 
[258]1081{
[295]1082    if ( sys_call( SYSCALL_HEAP_INFO, 
1083                   (unsigned int)vaddr, 
1084                   (unsigned int)length, 
[368]1085                   x,
[390]1086                   y ) )  giet_exit("ERROR in giet_heap_info()");
[258]1087}
1088
[390]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
[258]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.