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

Last change on this file since 180 was 165, checked in by alain, 12 years ago

Introducing various modifications in kernel initialisation

File size: 28.7 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 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_GCD_WRITE       0x06
20#define SYSCALL_GCD_READ        0x07
21#define SYSCALL_TTY_READ_IRQ    0x0A
22#define SYSCALL_TTY_WRITE_IRQ   0x0B
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////////////////////////////////////////////////////////////////////////////////////
167// giet_tty_getc_no_irq()
168////////////////////////////////////////////////////////////////////////////////////
169// This blocking function fetches a single ascii character from a terminal.
170// The terminal index must be defined in the task context in the boot phase.
171// It doesn't use the IRQ_GET interrupt, and the associated kernel buffer.
172// - Returns necessarily 0 when completed.
173////////////////////////////////////////////////////////////////////////////////////
174unsigned int giet_tty_getc_no_irq(char *byte)
175{
176    unsigned int ret = 0;
177    while (ret == 0)
178    {
179        ret = sys_call(SYSCALL_TTY_READ,
180                       (unsigned int)byte,
181                       1,
182                       0,0);
183    }
184    return 0;
185}
186////////////////////////////////////////////////////////////////////////////////////
187// giet_tty_getc()
188////////////////////////////////////////////////////////////////////////////////////
189// This blocking function fetches a single ascii character from a terminal.
190// The terminal index must be defined in the task context in the boot phase.
191// It uses the IRQ_GET interrupt, and the associated kernel buffer.
192// - Returns 0 when completed.
193////////////////////////////////////////////////////////////////////////////////////
194unsigned int giet_tty_getc(char *byte)
195{
196    unsigned int ret = 0;
197    while (ret == 0)
198    {
199        ret = sys_call(SYSCALL_TTY_READ_IRQ,
200                       (unsigned int)byte,
201                       1,
202                       0,0);
203    }
204    return 0;
205}
206////////////////////////////////////////////////////////////////////////////////////
207// giet_tty_gets()
208////////////////////////////////////////////////////////////////////////////////////
209// This blocking function fetches a string from a terminal to a fixed length buffer.
210// The terminal index must be defined in the task context in the boot phase.
211// It uses the TTY_GET_IRQ interrupt, anf the associated kernel buffer.
212// - Returns 0 when completed.
213// - Up to (bufsize - 1) characters (including the non printable characters)
214//   will be copied into buffer, and the string is always completed by a NUL
215//   character.
216// - The <LF> character is interpreted, as the function close the string with a
217//   NUL character if <LF> is read.
218// - The <DEL> character is interpreted, and the corresponding character(s) are
219//   removed from the target buffer.
220////////////////////////////////////////////////////////////////////////////////////
221unsigned int giet_tty_gets( char*                       buf, 
222                            unsigned int        bufsize )
223{
224    unsigned int ret;
225    unsigned char byte;
226    unsigned int index = 0;
227
228    while (index < (bufsize - 1))
229    {
230        do {
231            ret = sys_call(SYSCALL_TTY_READ_IRQ,
232                           (unsigned int)(&byte),
233                           1,
234                           0,0);
235        } while (ret != 1);
236
237        if ( byte == 0x0A )
238            break; /* LF */
239        else if ((byte == 0x7F) && (index > 0))
240            index--; /* DEL */
241        else
242        {
243            buf[index] = byte;
244            index++;
245        }
246    }
247    buf[index] = 0;
248    return 0;
249}
250////////////////////////////////////////////////////////////////////////////////////
251// giet_tty_getw()
252////////////////////////////////////////////////////////////////////////////////////
253// This blocking function fetches a string of decimal characters (most
254// significant digit first) to build a 32-bit unsigned integer.
255// The terminal index must be defined in the task context in the boot phase.
256// It uses the TTY_GET_IRQ interrupt, anf the associated kernel buffer.
257// - Returns necessarily 0 when completed.
258//
259// - The non-blocking system function _tty_read_irq is called several times,
260//   and the decimal characters are written in a 32 characters buffer until a
261//   <LF> character is read.
262// - The <DEL> character is interpreted, and previous characters can be
263//   cancelled. All others characters are ignored.
264// - When the <LF> character is received, the string is converted to an
265//   unsigned int value. If the number of decimal digit is too large for the 32
266//   bits range, the zero value is returned.
267////////////////////////////////////////////////////////////////////////////////////
268unsigned int giet_tty_getw(unsigned int *val)
269{
270    unsigned char buf[32];
271    unsigned char byte;
272    unsigned int save = 0;
273    unsigned int dec = 0;
274    unsigned int done = 0;
275    unsigned int overflow = 0;
276    unsigned int max = 0;
277    unsigned int i;
278    unsigned int ret;
279
280    while (done == 0)
281    {
282        do {
283            ret = sys_call(SYSCALL_TTY_READ_IRQ,
284                           (unsigned int)(&byte),
285                           1,
286                           0,0);
287        } while (ret != 1);
288
289        if ((byte > 0x2F) && (byte < 0x3A)) /* decimal character */
290        {
291            buf[max] = byte;
292            max++;
293            giet_tty_putc(byte);
294        }
295        else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */
296        {
297            done = 1;
298        }
299        else if (byte == 0x7F) /* DEL character */
300        {
301            if (max > 0)
302            {
303                max--; /* cancel the character */
304                giet_tty_putc(0x08);
305                giet_tty_putc(0x20);
306                giet_tty_putc(0x08);
307            }
308        }
309        if (max == 32) /* decimal string overflow */
310        {
311            for (i = 0; i < max; i++) /* cancel the string */
312            {
313                giet_tty_putc(0x08);
314                giet_tty_putc(0x20);
315                giet_tty_putc(0x08);
316            }
317            giet_tty_putc(0x30);
318            *val = 0; /* return 0 value */
319            return 0;
320        }
321    }
322
323    /* string conversion */
324    for (i = 0; i < max; i++)
325    {
326        dec = dec * 10 + (buf[i] - 0x30);
327        if (dec < save)
328            overflow = 1;
329        save = dec;
330    }
331
332    /* check overflow */
333    if (overflow == 0)
334    {
335        *val = dec; /* return decimal value */
336    }
337    else
338    {
339        for (i = 0; i < max; i++) /* cancel the string */
340        {
341            giet_tty_putc(0x08);
342            giet_tty_putc(0x20);
343            giet_tty_putc(0x08);
344        }
345        giet_tty_putc(0x30);
346        *val = 0; /* return 0 value */
347    }
348    return 0;
349}
350////////////////////////////////////////////////////////////////////////////////////
351// giet_tty_printf()
352////////////////////////////////////////////////////////////////////////////////////
353// This function is a simplified version of the mutek_printf() function.
354// The terminal index must be defined in the calling task context.
355// It doesn't use the IRQ_PUT interrupt, and the associated kernel buffer.
356// Only a limited number of formats are supported:
357//   - %d : signed decimal
358//   - %u : unsigned decimal
359//   - %x : hexadecimal
360//   - %c : char
361//   - %s : string
362// - Returns 0 if success, > 0 if error.
363////////////////////////////////////////////////////////////////////////////////////
364unsigned int giet_tty_printf(char *format, ...)
365{
366    va_list ap;
367    va_start(ap, format);
368    unsigned int ret;
369
370printf_text:
371
372    while (*format) {
373        unsigned int i;
374        for (i = 0; format[i] && format[i] != '%'; i++)
375            ;
376        if (i) {
377            ret = sys_call(SYSCALL_TTY_WRITE,
378                    (unsigned int)format,
379                    i,
380                    0,0);
381            if (ret != i)
382                return 1; /* return error */
383            format += i;
384        }
385        if (*format == '%') {
386            format++;
387            goto printf_arguments;
388        }
389    }
390
391    va_end(ap);
392    return 0;
393
394printf_arguments:
395
396    {
397        int         val = va_arg(ap, long);
398        char            buf[20];
399        char*           pbuf;
400        unsigned int        len = 0;
401        static const char   HexaTab[] = "0123456789ABCDEF";
402        unsigned int        i;
403
404        switch (*format++) {
405            case ('c'):             /* char conversion */
406                len = 1;
407                buf[0] = val;
408                pbuf = buf;
409                break;
410            case ('d'):             /* decimal signed integer */
411                if (val < 0) {
412                    val = -val;
413                    ret = sys_call(SYSCALL_TTY_WRITE,
414                            (unsigned int)"-",
415                            1,
416                            0,0);
417                    if (ret != 1)
418                        return 1; /* return error */
419                }
420            case ('u'):             /* decimal unsigned integer */
421                for( i=0 ; i<10 ; i++) {
422                    buf[9-i] = HexaTab[val % 10];
423                    if (!(val /= 10)) break;
424                }
425                len =  i+1;
426                pbuf = &buf[9-i];
427                break;
428            case ('x'):             /* hexadecimal integer */
429                ret = sys_call(SYSCALL_TTY_WRITE,
430                        (unsigned int)"0x",
431                        2,
432                        0,0);
433                if (ret != 2)
434                    return 1; /* return error */
435                for( i=0 ; i<8 ; i++) {
436                    buf[7-i] = HexaTab[val % 16U];
437                    if (!(val /= 16U)) break;
438                }
439                len =  i+1;
440                pbuf = &buf[7-i];
441                break;
442            case ('s'):             /* string */
443                {
444                    char *str = (char*)val;
445                    while ( str[len] ) len++;
446                    pbuf = (char*)val;
447                }
448                break;
449            default:
450                goto printf_text;
451        }
452
453        ret = sys_call(SYSCALL_TTY_WRITE,
454                (unsigned int)pbuf,
455                len,
456                0,0);
457        if (ret != len)
458            return 1;
459        goto printf_text;
460    }
461}
462
463/////  GCD (Greatest Common Divider) related system calls
464
465#define GCD_OPA     0
466#define GCD_OPB     1
467#define GCD_START   2
468#define GCD_STATUS  3
469
470//////////////////////////////////////////////////////////////////////////////////
471// giet_gcd_set_opa()
472//////////////////////////////////////////////////////////////////////////////////
473// This function sets the operand A in the GCD coprocessor.
474// - Returns 0 if success, > 0 if error.
475//////////////////////////////////////////////////////////////////////////////////
476unsigned int giet_gcd_set_opa(unsigned int val)
477{
478    return sys_call(SYSCALL_GCD_WRITE,
479                    GCD_OPA,
480                    val,
481                    0, 0);
482}
483//////////////////////////////////////////////////////////////////////////////////
484//      giet_gcd_set_opb()
485//////////////////////////////////////////////////////////////////////////////////
486// This function sets operand B in the GCD coprocessor.
487// - Returns 0 if success, > 0 if error.
488//////////////////////////////////////////////////////////////////////////////////
489unsigned int giet_gcd_set_opb(unsigned int val)
490{
491    return sys_call(SYSCALL_GCD_WRITE,
492                    GCD_OPB,
493                    val,
494                    0, 0);
495}
496//////////////////////////////////////////////////////////////////////////////////
497//      giet_gcd_start()
498//////////////////////////////////////////////////////////////////////////////////
499// This function starts the computation in the GCD coprocessor.
500// - Returns 0 if success, > 0 if error.
501//////////////////////////////////////////////////////////////////////////////////
502unsigned int giet_gcd_start()
503{
504    return sys_call(SYSCALL_GCD_WRITE,
505                    GCD_START,
506                    0, 0, 0);
507}
508//////////////////////////////////////////////////////////////////////////////////
509//      giet_gcd_get_status()
510//////////////////////////////////////////////////////////////////////////////////
511// This function gets the status fromn the GCD coprocessor.
512// - The value is 0 when the coprocessor is idle (computation completed).
513//////////////////////////////////////////////////////////////////////////////////
514unsigned int giet_gcd_get_status(unsigned int *val)
515{
516    return sys_call(SYSCALL_GCD_READ,
517            GCD_STATUS,
518            (unsigned int)val,
519            0, 0);
520}
521//////////////////////////////////////////////////////////////////////////////////
522//      giet_gcd_get_result()
523//////////////////////////////////////////////////////////////////////////////////
524// This function gets the result of the computation from the GCD coprocessor.
525//////////////////////////////////////////////////////////////////////////////////
526unsigned int giet_gcd_get_result(unsigned int *val)
527{
528    return sys_call(SYSCALL_GCD_READ,
529            GCD_OPA,
530            (unsigned int)val,
531            0, 0);
532}
533
534///// Block device related system calls  /////
535
536//////////////////////////////////////////////////////////////////////////////////
537//      giet_ioc_write()
538//////////////////////////////////////////////////////////////////////////////////
539// Transfer data from a memory buffer to a file on the block_device.
540//     lba    : Logical Block Address (first block index)
541//     buffer : base address of the memory buffer
542//     count  : number of blocks to be transfered
543// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
544//////////////////////////////////////////////////////////////////////////////////
545unsigned int giet_ioc_write( unsigned int       lba, 
546                             void*                      buffer, 
547                             unsigned int       count)
548{
549    return sys_call(SYSCALL_IOC_WRITE,
550            lba,
551            (unsigned int)buffer,
552            count,
553            0);
554}
555//////////////////////////////////////////////////////////////////////////////////
556// giet_ioc_read()
557//////////////////////////////////////////////////////////////////////////////////
558// Transfer data from a file on the block_device to a memory buffer.
559//     lba    : Logical Block Address (first block index)
560//     buffer : base address of the memory buffer
561//     count  : number of blocks to be transfered
562// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
563//////////////////////////////////////////////////////////////////////////////////
564unsigned int giet_ioc_read( unsigned int                lba, 
565                            void*                               buffer, 
566                            unsigned int                count )
567{
568    return sys_call(SYSCALL_IOC_READ,
569            lba,
570            (unsigned int)buffer,
571            count,
572            0);
573}
574//////////////////////////////////////////////////////////////////////////////////
575// giet_ioc_completed()
576//////////////////////////////////////////////////////////////////////////////////
577// This blocking function returns 0 when the I/O transfer is
578// successfully completed, and returns 1 if an address error has been detected.
579//////////////////////////////////////////////////////////////////////////////////
580unsigned int giet_ioc_completed()
581{
582    return sys_call(SYSCALL_IOC_COMPLETED,
583            0, 0, 0, 0);
584}
585
586/////  Frame buffer device related system calls  /////
587
588//////////////////////////////////////////////////////////////////////////////////
589// giet_fb_sync_write()
590//////////////////////////////////////////////////////////////////////////////////
591// This blocking function use a memory copy strategy to transfer data from a
592// user buffer to the frame buffer device in kernel space.
593//     offset : offset (in bytes) in the frame buffer
594//     buffer : base address of the memory buffer
595//     length : number of bytes to be transfered
596// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
597//////////////////////////////////////////////////////////////////////////////////
598unsigned int giet_fb_sync_write( unsigned int   offset, 
599                                 void*                  buffer, 
600                                 unsigned int   length )
601{
602    return sys_call(SYSCALL_FB_SYNC_WRITE,
603            offset,
604            (unsigned int)buffer,
605            length,
606            0);
607}
608//////////////////////////////////////////////////////////////////////////////////
609// giet_fb_sync_read()
610//////////////////////////////////////////////////////////////////////////////////
611// This blocking function use a memory copy strategy to transfer data from the
612// frame buffer device in kernel space to an user buffer.
613//     offset : offset (in bytes) in the frame buffer
614//     buffer : base address of the user buffer
615//     length : number of bytes to be transfered
616// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
617//////////////////////////////////////////////////////////////////////////////////
618unsigned int giet_fb_sync_read( unsigned int    offset, 
619                                void*                   buffer, 
620                                unsigned int    length )
621{
622    return sys_call(SYSCALL_FB_SYNC_READ,
623            offset,
624            (unsigned int)buffer,
625            length,
626            0);
627}
628//////////////////////////////////////////////////////////////////////////////////
629// giet_fb_write()
630//////////////////////////////////////////////////////////////////////////////////
631// This non-blocking function use the DMA coprocessor to transfer data from a
632// user buffer to the frame buffer device in kernel space.
633// - offset : offset (in bytes) in the frame buffer
634// - buffer : base address of the user buffer
635// - length : number of bytes to be transfered
636// The transfer completion is signaled by an IRQ, and must be tested by the
637// fb_completed() function.
638// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
639//////////////////////////////////////////////////////////////////////////////////
640unsigned int giet_fb_write( unsigned int        offset, 
641                            void*                       buffer, 
642                            unsigned int        length )
643{
644    return sys_call(SYSCALL_FB_WRITE,
645            offset,
646            (unsigned int)buffer,
647            length,
648            0);
649}
650//////////////////////////////////////////////////////////////////////////////////
651// giet_fb_read()
652//////////////////////////////////////////////////////////////////////////////////
653// This non-blocking function use the DMA coprocessor to transfer data from the
654// frame buffer device in kernel space to an user buffer.
655// - offset : offset (in bytes) in the frame buffer
656// - buffer : base address of the memory buffer
657// - length : number of bytes to be transfered
658// The transfer completion is signaled by an IRQ, and must be tested by the
659// fb_completed() function.
660// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
661//////////////////////////////////////////////////////////////////////////////////
662unsigned int giet_fb_read( unsigned int         offset, 
663                           void*                        buffer, 
664                           unsigned int         length )
665{
666    return sys_call(SYSCALL_FB_READ,
667                    offset,
668                    (unsigned int)buffer,
669                    length,
670                    0);
671}
672//////////////////////////////////////////////////////////////////////////////////
673// giet_fb_completed()
674//////////////////////////////////////////////////////////////////////////////////
675// This blocking function returns when the transfer is completed.
676// - Returns 0 if success, > 0 if error.
677//////////////////////////////////////////////////////////////////////////////////
678unsigned int giet_fb_completed()
679{
680    return sys_call(SYSCALL_FB_COMPLETED,
681                    0, 0, 0, 0);
682}
683
684///// Miscellaneous related system calls /////
685
686//////////////////////////////////////////////////////////////////////////////////
687// giet_vobj_get_vbase()
688//////////////////////////////////////////////////////////////////////////////////
689// This function writes in argument (vobj_vaddr) the virtual base address
690// of a vobj (defined in the mapping_info data structure), identified by
691// the two arguments (vspace_name and vobj_name).
692// The (vobj_type) argument is redundant, and used for coherence checking.
693// - Returns the address if success,  0 if error ( not defined or wrong type )
694//////////////////////////////////////////////////////////////////////////////////
695unsigned int giet_vobj_get_vbase( char*                 vspace_name, 
696                                  char*                 vobj_name,
697                                  unsigned int  vobj_type, 
698                                  unsigned int* vobj_vaddr )
699{
700    return sys_call(SYSCALL_VOBJ_GET_VBASE, 
701                    (unsigned int)vspace_name,
702                    (unsigned int)vobj_name,
703                    (unsigned int)vobj_type,
704                    (unsigned int)vobj_vaddr);
705}
706
707////////////////////////////////////////////////////////////////////////////////////
708// giet_proc_number()
709////////////////////////////////////////////////////////////////////////////////////
710// This function returns in the buffer argument the number of processors
711// in the cluster specified by the cluster_id argument.
712// - Returns 0 if success, > 0 if error ( cluster index too large )
713////////////////////////////////////////////////////////////////////////////////////
714unsigned int giet_proc_number( unsigned int             cluster_id,
715                               unsigned int*    buffer )
716{
717    return sys_call(SYSCALL_PROC_NUMBER, 
718                    cluster_id,
719                    (unsigned int)buffer,
720                    0, 0);
721}
722
723/////  Miscellaneous system calls /////
724
725//////////////////////////////////////////////////////////////////////////////////
726// giet_task_exit()
727//////////////////////////////////////////////////////////////////////////////////
728// This function stops execution of the calling task with a TTY message,
729// and enter an infinite loop.
730// The task is blocked, but it still consume processor cycles ...
731//////////////////////////////////////////////////////////////////////////////////
732void giet_exit()
733{
734    sys_call(SYSCALL_EXIT, 
735             0, 0, 0, 0);
736}
737///////////////////////////////////////////////////////////////////////////////////
738// giet_rand()
739// This function returns a pseudo-random value derived from the processor cycle
740// count. This value is comprised between 0 & 65535.
741///////////////////////////////////////////////////////////////////////////////////
742unsigned int giet_rand()
743{
744    unsigned int x = sys_call(SYSCALL_PROCTIME, 
745                              0, 0, 0, 0);
746    if((x & 0xF) > 7)
747        return (x*x & 0xFFFF);
748    else
749        return (x*x*x & 0xFFFF);
750}
751//////////////////////////////////////////////////////////////////////////////////
752// giet_ctx_switch()
753// The user task calling this function is descheduled and
754// the processor is allocated to another task.
755//////////////////////////////////////////////////////////////////////////////////
756unsigned int giet_ctx_switch()
757{
758    return sys_call(SYSCALL_CTX_SWITCH, 
759                    0, 0, 0, 0);
760}
761
762
Note: See TracBrowser for help on using the repository browser.