source: soft/giet_vm/libs/stdio.c @ 217

Last change on this file since 217 was 204, checked in by alain, 12 years ago

mproving support for multi-clusters architectures (CLUSTER_SIZE & CLUSTER_IO_ID parameters)

File size: 28.9 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File     : stdio.c         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The stdio.c and stdio.h files are part of the GIET_VM nano-kernel.
8// This library contains all user-level functions that contain a system call
9// to access protected or shared ressources.
10///////////////////////////////////////////////////////////////////////////////////
11
12#include <stdarg.h>
13#include <stdio.h>
14
15#define SYSCALL_PROCID          0x00
16#define SYSCALL_PROCTIME        0x01
17#define SYSCALL_TTY_WRITE       0x02
18#define SYSCALL_TTY_READ        0x03
19#define SYSCALL_TIMER_START     0x04
20#define SYSCALL_TIMER_STOP      0x05
21#define SYSCALL_GCD_WRITE       0x06
22#define SYSCALL_GCD_READ        0x07
23#define SYSCALL_CTX_SWITCH      0x0D
24#define SYSCALL_EXIT            0x0E
25#define SYSCALL_PROC_NUMBER     0x0F
26#define SYSCALL_FB_SYNC_WRITE   0x10
27#define SYSCALL_FB_SYNC_READ    0x11
28#define SYSCALL_FB_WRITE        0x12
29#define SYSCALL_FB_READ         0x13
30#define SYSCALL_FB_COMPLETED    0x14
31#define SYSCALL_IOC_WRITE       0x15
32#define SYSCALL_IOC_READ        0x16
33#define SYSCALL_IOC_COMPLETED   0x17
34#define SYSCALL_VOBJ_GET_VBASE  0x1A
35
36//////////////////////////////////////////////////////////////////////////////////
37// sys_call()
38// This generic C function is used to implement all system calls.
39// It writes the system call arguments in the proper registers,
40// and tells GCC what has been modified by system call execution.
41//////////////////////////////////////////////////////////////////////////////////
42static inline unsigned int sys_call( unsigned int call_no,
43                                     unsigned int arg_0, 
44                                     unsigned int arg_1, 
45                                     unsigned int arg_2, 
46                                     unsigned int arg_3)
47{
48    register unsigned int reg_no_and_output asm("v0") = call_no;
49    register unsigned int reg_a0            asm("a0") = arg_0;
50    register unsigned int reg_a1            asm("a1") = arg_1;
51    register unsigned int reg_a2            asm("a2") = arg_2;
52    register unsigned int reg_a3            asm("a3") = arg_3;
53
54    asm volatile(
55            "syscall"
56            : "=r" (reg_no_and_output)  /* output argument */
57            : "r" (reg_a0),             /* input arguments */
58              "r" (reg_a1),
59              "r" (reg_a2),
60              "r" (reg_a3),
61              "r" (reg_no_and_output)
62            : "memory",
63            /* These persistant registers will be saved on the stack by the
64             * compiler only if they contain relevant data. */
65            "at",
66            "v1",
67            "ra",
68            "t0",
69            "t1",
70            "t2",
71            "t3",
72            "t4",
73            "t5",
74            "t6",
75            "t7",
76            "t8",
77            "t9"
78               );
79    return reg_no_and_output;
80}
81
82/////    MIPS32 related system calls  /////
83
84////////////////////////////////////////////////////////////////////////////////////
85// giet_procid()
86////////////////////////////////////////////////////////////////////////////////////
87// This function returns the processor identifier.
88////////////////////////////////////////////////////////////////////////////////////
89unsigned int giet_procid()
90{
91    return sys_call(SYSCALL_PROCID, 
92                    0, 0, 0, 0);
93}
94////////////////////////////////////////////////////////////////////////////////////
95// giet_proctime()
96////////////////////////////////////////////////////////////////////////////////////
97// This function returns the local processor time (clock cycles since boot)
98////////////////////////////////////////////////////////////////////////////////////
99unsigned int giet_proctime()
100{
101    return sys_call(SYSCALL_PROCTIME, 
102                    0, 0, 0, 0);
103}
104
105//////  TTY device related system calls /////
106
107////////////////////////////////////////////////////////////////////////////////////
108// giet_tty_putc()
109////////////////////////////////////////////////////////////////////////////////////
110// This function displays a single ascii character on a terminal.
111// The terminal index must be defined in the task context in the boot phase.
112// It doesn't use the TTY_PUT_IRQ interrupt, and the associated kernel buffer.
113// - Returns 1 if the character has been written, 0 otherwise.
114////////////////////////////////////////////////////////////////////////////////////
115unsigned int giet_tty_putc(char byte)
116{
117    return sys_call(SYSCALL_TTY_WRITE,
118                    (unsigned int)(&byte),
119                    1,
120                    0,0);
121}
122////////////////////////////////////////////////////////////////////////////////////
123// giet_tty_puts()
124////////////////////////////////////////////////////////////////////////////////////
125// This function displays a string on a terminal.
126// The terminal index must be defined in the task context in the boot phase.
127// The string must be terminated by a NUL character.
128// It doesn't use the TTY_PUT_IRQ interrupt, and the associated kernel buffer.
129// - Returns the number of written characters.
130////////////////////////////////////////////////////////////////////////////////////
131unsigned int giet_tty_puts(char *buf)
132{
133    unsigned int length = 0;
134    while (buf[length] != 0)
135    {
136        length++;
137    }
138    return sys_call(SYSCALL_TTY_WRITE,
139                    (unsigned int)buf,
140                    length,
141                    0,0);
142}
143////////////////////////////////////////////////////////////////////////////////////
144// giet_tty_putw()
145////////////////////////////////////////////////////////////////////////////////////
146// This function displays the value of a 32-bit word with decimal characters.
147// The terminal index must be defined in the task context in the boot phase.
148// It doesn't use the TTY_PUT_IRQ interrupt, and the associated kernel buffer.
149// Returns the number of written characters (should be equal to ten).
150////////////////////////////////////////////////////////////////////////////////////
151unsigned int giet_tty_putw(unsigned int val)
152{
153    char buf[10];
154    unsigned int i;
155    for (i = 0; i < 10; i++)
156    {
157        buf[9-i] = (val % 10) + 0x30;
158        val = val / 10;
159    }
160    return sys_call(SYSCALL_TTY_WRITE,
161                    (unsigned int)buf,
162                    10,
163                    0,0);
164}
165////////////////////////////////////////////////////////////////////////////////////
166// giet_tty_getc()
167////////////////////////////////////////////////////////////////////////////////////
168// This blocking function fetches a single ascii character from a terminal.
169// The terminal index must be defined in the task context in the boot phase.
170// It uses the IRQ_GET interrupt, and the associated kernel buffer.
171// - Returns 0 when completed.
172////////////////////////////////////////////////////////////////////////////////////
173unsigned int giet_tty_getc(char *byte)
174{
175    unsigned int ret = 0;
176    while (ret == 0)
177    {
178        ret = sys_call(SYSCALL_TTY_READ,
179                       (unsigned int)byte,
180                       1,
181                       0,0);
182    }
183    return 0;
184}
185////////////////////////////////////////////////////////////////////////////////////
186// giet_tty_gets()
187////////////////////////////////////////////////////////////////////////////////////
188// This blocking function fetches a string from a terminal to a fixed length buffer.
189// The terminal index must be defined in the task context in the boot phase.
190// It uses the TTY_GET_IRQ interrupt, anf the associated kernel buffer.
191// - Returns 0 when completed.
192// - Up to (bufsize - 1) characters (including the non printable characters)
193//   will be copied into buffer, and the string is always completed by a NUL
194//   character.
195// - The <LF> character is interpreted, as the function close the string with a
196//   NUL character if <LF> is read.
197// - The <DEL> character is interpreted, and the corresponding character(s) are
198//   removed from the target buffer.
199////////////////////////////////////////////////////////////////////////////////////
200unsigned int giet_tty_gets( char*                       buf, 
201                            unsigned int        bufsize )
202{
203    unsigned int ret;
204    unsigned char byte;
205    unsigned int index = 0;
206
207    while (index < (bufsize - 1))
208    {
209        do {
210            ret = sys_call(SYSCALL_TTY_READ,
211                           (unsigned int)(&byte),
212                           1,
213                           0,0);
214        } while (ret != 1);
215
216        if ( byte == 0x0A )
217            break; /* LF */
218        else if ((byte == 0x7F) && (index > 0))
219            index--; /* DEL */
220        else
221        {
222            buf[index] = byte;
223            index++;
224        }
225    }
226    buf[index] = 0;
227    return 0;
228}
229////////////////////////////////////////////////////////////////////////////////////
230// giet_tty_getw()
231////////////////////////////////////////////////////////////////////////////////////
232// This blocking function fetches a string of decimal characters (most
233// significant digit first) to build a 32-bit unsigned integer.
234// The terminal index must be defined in the task context in the boot phase.
235// It uses the TTY_GET_IRQ interrupt, anf the associated kernel buffer.
236// - Returns necessarily 0 when completed.
237//
238// - The non-blocking system function _tty_read_irq is called several times,
239//   and the decimal characters are written in a 32 characters buffer until a
240//   <LF> character is read.
241// - The <DEL> character is interpreted, and previous characters can be
242//   cancelled. All others characters are ignored.
243// - When the <LF> character is received, the string is converted to an
244//   unsigned int value. If the number of decimal digit is too large for the 32
245//   bits range, the zero value is returned.
246////////////////////////////////////////////////////////////////////////////////////
247unsigned int giet_tty_getw(unsigned int *val)
248{
249    unsigned char buf[32];
250    unsigned char byte;
251    unsigned int save = 0;
252    unsigned int dec = 0;
253    unsigned int done = 0;
254    unsigned int overflow = 0;
255    unsigned int max = 0;
256    unsigned int i;
257    unsigned int ret;
258
259    while (done == 0)
260    {
261        do {
262            ret = sys_call(SYSCALL_TTY_READ,
263                           (unsigned int)(&byte),
264                           1,
265                           0,0);
266        } while (ret != 1);
267
268        if ((byte > 0x2F) && (byte < 0x3A)) /* decimal character */
269        {
270            buf[max] = byte;
271            max++;
272            giet_tty_putc(byte);
273        }
274        else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */
275        {
276            done = 1;
277        }
278        else if (byte == 0x7F) /* DEL character */
279        {
280            if (max > 0)
281            {
282                max--; /* cancel the character */
283                giet_tty_putc(0x08);
284                giet_tty_putc(0x20);
285                giet_tty_putc(0x08);
286            }
287        }
288        if (max == 32) /* decimal string overflow */
289        {
290            for (i = 0; i < max; i++) /* cancel the string */
291            {
292                giet_tty_putc(0x08);
293                giet_tty_putc(0x20);
294                giet_tty_putc(0x08);
295            }
296            giet_tty_putc(0x30);
297            *val = 0; /* return 0 value */
298            return 0;
299        }
300    }
301
302    /* string conversion */
303    for (i = 0; i < max; i++)
304    {
305        dec = dec * 10 + (buf[i] - 0x30);
306        if (dec < save)
307            overflow = 1;
308        save = dec;
309    }
310
311    /* check overflow */
312    if (overflow == 0)
313    {
314        *val = dec; /* return decimal value */
315    }
316    else
317    {
318        for (i = 0; i < max; i++) /* cancel the string */
319        {
320            giet_tty_putc(0x08);
321            giet_tty_putc(0x20);
322            giet_tty_putc(0x08);
323        }
324        giet_tty_putc(0x30);
325        *val = 0; /* return 0 value */
326    }
327    return 0;
328}
329////////////////////////////////////////////////////////////////////////////////////
330// giet_tty_printf()
331////////////////////////////////////////////////////////////////////////////////////
332// This function is a simplified version of the mutek_printf() function.
333// The terminal index must be defined in the calling task context.
334// It doesn't use the IRQ_PUT interrupt, and the associated kernel buffer.
335// Only a limited number of formats are supported:
336//   - %d : signed decimal
337//   - %u : unsigned decimal
338//   - %x : hexadecimal
339//   - %c : char
340//   - %s : string
341// - Returns 0 if success, > 0 if error.
342////////////////////////////////////////////////////////////////////////////////////
343unsigned int giet_tty_printf(char *format, ...)
344{
345    va_list ap;
346    va_start(ap, format);
347    unsigned int ret;
348
349printf_text:
350
351    while (*format) {
352        unsigned int i;
353        for (i = 0; format[i] && format[i] != '%'; i++)
354            ;
355        if (i) {
356            ret = sys_call(SYSCALL_TTY_WRITE,
357                    (unsigned int)format,
358                    i,
359                    0,0);
360            if (ret != i)
361                return 1; /* return error */
362            format += i;
363        }
364        if (*format == '%') {
365            format++;
366            goto printf_arguments;
367        }
368    }
369
370    va_end(ap);
371    return 0;
372
373printf_arguments:
374
375    {
376        int         val = va_arg(ap, long);
377        char            buf[20];
378        char*           pbuf;
379        unsigned int        len = 0;
380        static const char   HexaTab[] = "0123456789ABCDEF";
381        unsigned int        i;
382
383        switch (*format++) {
384            case ('c'):             /* char conversion */
385                len = 1;
386                buf[0] = val;
387                pbuf = buf;
388                break;
389            case ('d'):             /* decimal signed integer */
390                if (val < 0) {
391                    val = -val;
392                    ret = sys_call(SYSCALL_TTY_WRITE,
393                            (unsigned int)"-",
394                            1,
395                            0,0);
396                    if (ret != 1)
397                        return 1; /* return error */
398                }
399            case ('u'):             /* decimal unsigned integer */
400                for( i=0 ; i<10 ; i++) {
401                    buf[9-i] = HexaTab[val % 10];
402                    if (!(val /= 10)) break;
403                }
404                len =  i+1;
405                pbuf = &buf[9-i];
406                break;
407            case ('x'):             /* hexadecimal integer */
408                ret = sys_call(SYSCALL_TTY_WRITE,
409                        (unsigned int)"0x",
410                        2,
411                        0,0);
412                if (ret != 2)
413                    return 1; /* return error */
414                for( i=0 ; i<8 ; i++) {
415                    buf[7-i] = HexaTab[val % 16U];
416                    if (!(val /= 16U)) break;
417                }
418                len =  i+1;
419                pbuf = &buf[7-i];
420                break;
421            case ('s'):             /* string */
422                {
423                    char *str = (char*)val;
424                    while ( str[len] ) len++;
425                    pbuf = (char*)val;
426                }
427                break;
428            default:
429                goto printf_text;
430        }
431
432        ret = sys_call(SYSCALL_TTY_WRITE,
433                (unsigned int)pbuf,
434                len,
435                0,0);
436        if (ret != len)
437            return 1;
438        goto printf_text;
439    }
440}
441
442
443/////  TIMER related system calls //////
444
445//////////////////////////////////////////////////////////////////////////////////
446// giet_timer_start()
447//////////////////////////////////////////////////////////////////////////////////
448// This function activates the private user timer allocated to the calling task
449// in the boot phase.
450// - Returns 0 if success, > 0 if error.
451//////////////////////////////////////////////////////////////////////////////////
452unsigned int giet_timer_start()
453{
454    return sys_call(SYSCALL_TIMER_START,
455                   0,0,0,0);
456}
457//////////////////////////////////////////////////////////////////////////////////
458// giet_timer_stop()
459//////////////////////////////////////////////////////////////////////////////////
460// This function activates the user timer allocated to the calling task.
461// - Returns 0 if success, > 0 if error.
462//////////////////////////////////////////////////////////////////////////////////
463unsigned int giet_timer_stop()
464{
465    return sys_call(SYSCALL_TIMER_STOP,
466                   0,0,0,0);
467}
468
469/////  GCD (Greatest Common Divider) related system calls
470
471#define GCD_OPA     0
472#define GCD_OPB     1
473#define GCD_START   2
474#define GCD_STATUS  3
475
476//////////////////////////////////////////////////////////////////////////////////
477// giet_gcd_set_opa()
478//////////////////////////////////////////////////////////////////////////////////
479// This function sets the operand A in the GCD coprocessor.
480// - Returns 0 if success, > 0 if error.
481//////////////////////////////////////////////////////////////////////////////////
482unsigned int giet_gcd_set_opa(unsigned int val)
483{
484    return sys_call(SYSCALL_GCD_WRITE,
485                    GCD_OPA,
486                    val,
487                    0, 0);
488}
489//////////////////////////////////////////////////////////////////////////////////
490//      giet_gcd_set_opb()
491//////////////////////////////////////////////////////////////////////////////////
492// This function sets operand B in the GCD coprocessor.
493// - Returns 0 if success, > 0 if error.
494//////////////////////////////////////////////////////////////////////////////////
495unsigned int giet_gcd_set_opb(unsigned int val)
496{
497    return sys_call(SYSCALL_GCD_WRITE,
498                    GCD_OPB,
499                    val,
500                    0, 0);
501}
502//////////////////////////////////////////////////////////////////////////////////
503//      giet_gcd_start()
504//////////////////////////////////////////////////////////////////////////////////
505// This function starts the computation in the GCD coprocessor.
506// - Returns 0 if success, > 0 if error.
507//////////////////////////////////////////////////////////////////////////////////
508unsigned int giet_gcd_start()
509{
510    return sys_call(SYSCALL_GCD_WRITE,
511                    GCD_START,
512                    0, 0, 0);
513}
514//////////////////////////////////////////////////////////////////////////////////
515//      giet_gcd_get_status()
516//////////////////////////////////////////////////////////////////////////////////
517// This function gets the status fromn the GCD coprocessor.
518// - The value is 0 when the coprocessor is idle (computation completed).
519//////////////////////////////////////////////////////////////////////////////////
520unsigned int giet_gcd_get_status(unsigned int *val)
521{
522    return sys_call(SYSCALL_GCD_READ,
523            GCD_STATUS,
524            (unsigned int)val,
525            0, 0);
526}
527//////////////////////////////////////////////////////////////////////////////////
528//      giet_gcd_get_result()
529//////////////////////////////////////////////////////////////////////////////////
530// This function gets the result of the computation from the GCD coprocessor.
531//////////////////////////////////////////////////////////////////////////////////
532unsigned int giet_gcd_get_result(unsigned int *val)
533{
534    return sys_call(SYSCALL_GCD_READ,
535            GCD_OPA,
536            (unsigned int)val,
537            0, 0);
538}
539
540///// Block device related system calls  /////
541
542//////////////////////////////////////////////////////////////////////////////////
543//      giet_ioc_write()
544//////////////////////////////////////////////////////////////////////////////////
545// Transfer data from a memory buffer to a file on the block_device.
546//     lba    : Logical Block Address (first block index)
547//     buffer : base address of the memory buffer
548//     count  : number of blocks to be transfered
549// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
550//////////////////////////////////////////////////////////////////////////////////
551unsigned int giet_ioc_write( unsigned int       lba, 
552                             void*                      buffer, 
553                             unsigned int       count)
554{
555    return sys_call(SYSCALL_IOC_WRITE,
556            lba,
557            (unsigned int)buffer,
558            count,
559            0);
560}
561//////////////////////////////////////////////////////////////////////////////////
562// giet_ioc_read()
563//////////////////////////////////////////////////////////////////////////////////
564// Transfer data from a file on the block_device to a memory buffer.
565//     lba    : Logical Block Address (first block index)
566//     buffer : base address of the memory buffer
567//     count  : number of blocks to be transfered
568// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
569//////////////////////////////////////////////////////////////////////////////////
570unsigned int giet_ioc_read( unsigned int                lba, 
571                            void*                               buffer, 
572                            unsigned int                count )
573{
574    return sys_call(SYSCALL_IOC_READ,
575            lba,
576            (unsigned int)buffer,
577            count,
578            0);
579}
580//////////////////////////////////////////////////////////////////////////////////
581// giet_ioc_completed()
582//////////////////////////////////////////////////////////////////////////////////
583// This blocking function returns 0 when the I/O transfer is
584// successfully completed, and returns 1 if an address error has been detected.
585//////////////////////////////////////////////////////////////////////////////////
586unsigned int giet_ioc_completed()
587{
588    return sys_call(SYSCALL_IOC_COMPLETED,
589            0, 0, 0, 0);
590}
591
592/////  Frame buffer device related system calls  /////
593
594//////////////////////////////////////////////////////////////////////////////////
595// giet_fb_sync_write()
596//////////////////////////////////////////////////////////////////////////////////
597// This blocking function use a memory copy strategy to transfer data from a
598// user buffer to the frame buffer device in kernel space.
599//     offset : offset (in bytes) in the frame buffer
600//     buffer : base address of the memory buffer
601//     length : number of bytes to be transfered
602// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
603//////////////////////////////////////////////////////////////////////////////////
604unsigned int giet_fb_sync_write( unsigned int   offset, 
605                                 void*                  buffer, 
606                                 unsigned int   length )
607{
608    return sys_call(SYSCALL_FB_SYNC_WRITE,
609            offset,
610            (unsigned int)buffer,
611            length,
612            0);
613}
614//////////////////////////////////////////////////////////////////////////////////
615// giet_fb_sync_read()
616//////////////////////////////////////////////////////////////////////////////////
617// This blocking function use a memory copy strategy to transfer data from the
618// frame buffer device in kernel space to an user buffer.
619//     offset : offset (in bytes) in the frame buffer
620//     buffer : base address of the user buffer
621//     length : number of bytes to be transfered
622// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
623//////////////////////////////////////////////////////////////////////////////////
624unsigned int giet_fb_sync_read( unsigned int    offset, 
625                                void*                   buffer, 
626                                unsigned int    length )
627{
628    return sys_call(SYSCALL_FB_SYNC_READ,
629            offset,
630            (unsigned int)buffer,
631            length,
632            0);
633}
634//////////////////////////////////////////////////////////////////////////////////
635// giet_fb_write()
636//////////////////////////////////////////////////////////////////////////////////
637// This non-blocking function use the DMA coprocessor to transfer data from a
638// user buffer to the frame buffer device in kernel space.
639// - offset : offset (in bytes) in the frame buffer
640// - buffer : base address of the user buffer
641// - length : number of bytes to be transfered
642// The transfer completion is signaled by an IRQ, and must be tested by the
643// fb_completed() function.
644// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
645//////////////////////////////////////////////////////////////////////////////////
646unsigned int giet_fb_write( unsigned int        offset, 
647                            void*                       buffer, 
648                            unsigned int        length )
649{
650    return sys_call(SYSCALL_FB_WRITE,
651            offset,
652            (unsigned int)buffer,
653            length,
654            0);
655}
656//////////////////////////////////////////////////////////////////////////////////
657// giet_fb_read()
658//////////////////////////////////////////////////////////////////////////////////
659// This non-blocking function use the DMA coprocessor to transfer data from the
660// frame buffer device in kernel space to an user buffer.
661// - offset : offset (in bytes) in the frame buffer
662// - buffer : base address of the memory buffer
663// - length : number of bytes to be transfered
664// The transfer completion is signaled by an IRQ, and must be tested by the
665// fb_completed() function.
666// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
667//////////////////////////////////////////////////////////////////////////////////
668unsigned int giet_fb_read( unsigned int         offset, 
669                           void*                        buffer, 
670                           unsigned int         length )
671{
672    return sys_call(SYSCALL_FB_READ,
673                    offset,
674                    (unsigned int)buffer,
675                    length,
676                    0);
677}
678//////////////////////////////////////////////////////////////////////////////////
679// giet_fb_completed()
680//////////////////////////////////////////////////////////////////////////////////
681// This blocking function returns when the transfer is completed.
682// - Returns 0 if success, > 0 if error.
683//////////////////////////////////////////////////////////////////////////////////
684unsigned int giet_fb_completed()
685{
686    return sys_call(SYSCALL_FB_COMPLETED,
687                    0, 0, 0, 0);
688}
689
690///// Miscellaneous related system calls /////
691
692//////////////////////////////////////////////////////////////////////////////////
693// giet_vobj_get_vbase()
694//////////////////////////////////////////////////////////////////////////////////
695// This function writes in argument (vobj_vaddr) the virtual base address
696// of a vobj (defined in the mapping_info data structure), identified by
697// the two arguments (vspace_name and vobj_name).
698// The (vobj_type) argument is redundant, and used for coherence checking.
699// - Returns the address if success,  0 if error ( not defined or wrong type )
700//////////////////////////////////////////////////////////////////////////////////
701unsigned int giet_vobj_get_vbase( char*                 vspace_name, 
702                                  char*                 vobj_name,
703                                  unsigned int  vobj_type, 
704                                  unsigned int* vobj_vaddr )
705{
706    return sys_call(SYSCALL_VOBJ_GET_VBASE, 
707                    (unsigned int)vspace_name,
708                    (unsigned int)vobj_name,
709                    (unsigned int)vobj_type,
710                    (unsigned int)vobj_vaddr);
711}
712
713////////////////////////////////////////////////////////////////////////////////////
714// giet_proc_number()
715////////////////////////////////////////////////////////////////////////////////////
716// This function returns in the buffer argument the number of processors
717// in the cluster specified by the cluster_id argument.
718// - Returns 0 if success, > 0 if error ( cluster index too large )
719////////////////////////////////////////////////////////////////////////////////////
720unsigned int giet_proc_number( unsigned int             cluster_id,
721                               unsigned int*    buffer )
722{
723    return sys_call(SYSCALL_PROC_NUMBER, 
724                    cluster_id,
725                    (unsigned int)buffer,
726                    0, 0);
727}
728
729/////  Miscellaneous system calls /////
730
731//////////////////////////////////////////////////////////////////////////////////
732// giet_task_exit()
733//////////////////////////////////////////////////////////////////////////////////
734// This function stops execution of the calling task with a TTY message,
735// and enter an infinite loop.
736// The task is blocked, but it still consume processor cycles ...
737//////////////////////////////////////////////////////////////////////////////////
738void giet_exit()
739{
740    sys_call(SYSCALL_EXIT, 
741             0, 0, 0, 0);
742}
743///////////////////////////////////////////////////////////////////////////////////
744// giet_rand()
745// This function returns a pseudo-random value derived from the processor cycle
746// count. This value is comprised between 0 & 65535.
747///////////////////////////////////////////////////////////////////////////////////
748unsigned int giet_rand()
749{
750    unsigned int x = sys_call(SYSCALL_PROCTIME, 
751                              0, 0, 0, 0);
752    if((x & 0xF) > 7)
753        return (x*x & 0xFFFF);
754    else
755        return (x*x*x & 0xFFFF);
756}
757//////////////////////////////////////////////////////////////////////////////////
758// giet_ctx_switch()
759// The user task calling this function is descheduled and
760// the processor is allocated to another task.
761//////////////////////////////////////////////////////////////////////////////////
762unsigned int giet_ctx_switch()
763{
764    return sys_call(SYSCALL_CTX_SWITCH, 
765                    0, 0, 0, 0);
766}
767
768
Note: See TracBrowser for help on using the repository browser.