source: soft/giet_vm/giet_libs/stdio.h @ 376

Last change on this file since 376 was 368, checked in by alain, 10 years ago

1) Introducing the SBT barrier (Sliced Binary Tree)

in the barrier.h library.

2) Introducing a new remote_malloc.h library.

  • Property svn:executable set to *
File size: 21.4 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File     : stdio.h         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#ifndef _STDIO_H
9#define _STDIO_H
10
11// These define must be synchronised with
12// the _syscall_vector defined in file sys_handler.c
13
14#define SYSCALL_PROCID            0x00
15#define SYSCALL_PROCTIME          0x01
16#define SYSCALL_TTY_WRITE         0x02
17#define SYSCALL_TTY_READ          0x03
18#define SYSCALL_TIMER_START       0x04
19#define SYSCALL_TIMER_STOP        0x05
20#define SYSCALL_TTY_GET_LOCK      0x06
21#define SYSCALL_TTY_RELEASE_LOCK  0x07
22#define SYSCALL_HEAP_INFO         0x08
23#define SYSCALL_LOCAL_TASK_ID     0x09
24#define SYSCALL_GLOBAL_TASK_ID    0x0A
25#define SYSCALL_FB_CMA_INIT       0x0B
26#define SYSCALL_FB_CMA_WRITE      0x0C
27#define SYSCALL_FB_CMA_STOP       0x0D
28#define SYSCALL_EXIT              0x0E
29#define SYSCALL_PROC_NUMBER       0x0F
30
31#define SYSCALL_FB_SYNC_WRITE     0x10
32#define SYSCALL_FB_SYNC_READ      0x11
33#define SYSCALL_THREAD_ID         0x12
34#define SYSCALL_FREE_13           0x13
35#define SYSCALL_FREE_14           0x14
36#define SYSCALL_FREE_15           0x15
37#define SYSCALL_FREE_16           0x16
38#define SYSCALL_FREE_17           0x17
39#define SYSCALL_FREE_18           0x18
40#define SYSCALL_CTX_SWITCH        0x19
41#define SYSCALL_VOBJ_GET_VBASE    0x1A
42#define SYSCALL_FREE_1B           0x1B
43#define SYSCALL_NIC_CMA_START     0x1C
44#define SYSCALL_NIC_CMA_STOP      0x1D
45#define SYSCALL_NIC_SYNC_READ     0x1E
46#define SYSCALL_NIC_SYNC_WRITE    0x1F
47
48#define SYSCALL_FAT_OPEN          0x20
49#define SYSCALL_FAT_READ          0x21
50#define SYSCALL_FAT_WRITE         0x22
51#define SYSCALL_FAT_LSEEK         0x23
52#define SYSCALL_FAT_FSTAT         0x24
53#define SYSCALL_FAT_CLOSE         0x25
54
55//////////////////////////////////////////////////////////////////////////////////
56// NULL pointer definition
57//////////////////////////////////////////////////////////////////////////////////
58
59#define NULL (void *)0
60
61//////////////////////////////////////////////////////////////////////////////////
62// This generic C function is used to implement all system calls.
63// It writes the system call arguments in the proper registers,
64// and tells GCC what has been modified by system call execution.
65//////////////////////////////////////////////////////////////////////////////////
66static inline int sys_call( int call_no,
67                            int arg_0, 
68                            int arg_1, 
69                            int arg_2, 
70                            int arg_3 ) 
71{
72    register int reg_no_and_output asm("v0") = call_no;
73    register int reg_a0 asm("a0") = arg_0;
74    register int reg_a1 asm("a1") = arg_1;
75    register int reg_a2 asm("a2") = arg_2;
76    register int reg_a3 asm("a3") = arg_3;
77
78    asm volatile(
79            "syscall"
80            : "+r" (reg_no_and_output), /* input/output argument */
81              "+r" (reg_a0),             
82              "+r" (reg_a1),
83              "+r" (reg_a2),
84              "+r" (reg_a3),
85              "+r" (reg_no_and_output)
86            : /* input arguments */
87            : "memory",
88            /* These persistant registers will be saved on the stack by the
89             * compiler only if they contain relevant data. */
90            "at",
91            "v1",
92            "ra",
93            "t0",
94            "t1",
95            "t2",
96            "t3",
97            "t4",
98            "t5",
99            "t6",
100            "t7",
101            "t8",
102            "t9"
103               );
104    return (volatile int)reg_no_and_output;
105}
106
107//////////////////////////////////////////////////////////////////////////
108//////////////////////////////////////////////////////////////////////////
109//               MIPS32 related system calls
110//////////////////////////////////////////////////////////////////////////
111//////////////////////////////////////////////////////////////////////////
112
113//////////////////////////////////////////////////////////////////////////
114//////////////////////////////////////////////////////////////////////////
115//             TTY device related system calls
116//////////////////////////////////////////////////////////////////////////
117//////////////////////////////////////////////////////////////////////////
118
119//////////////////////////////////////////////////////////////////////////
120// This function is a modified version of the mutek_printf().
121// It uses a private terminal allocated to the calling task in the boot.
122// ("use_tty" argument in xml mapping), and does not take the TTY lock.
123// It calls several times the _tty_write system function.
124// Only a limited number of formats are supported:
125//   - %d : signed decimal
126//   - %u : unsigned decimal
127//   - %x : 32 bits hexadecimal
128//   - %l : 64 bits hexadecimal
129//   - %c : char
130//   - %s : string
131// In case or error returned by syscall, it makes a giet_exit().
132//////////////////////////////////////////////////////////////////////////
133extern void giet_tty_printf( char* format, ... );
134
135//////////////////////////////////////////////////////////////////////////
136// This function is a modified version of the mutek_printf().
137// It uses the kernel TTY0 as a shared terminal, and it takes the
138// TTY lock to get exclusive access during the format display.
139// It calls several times the _tty_write system function.
140// Only a limited number of formats are supported:
141//   - %d : signed decimal
142//   - %u : unsigned decimal
143//   - %x : 32 bits hexadecimal
144//   - %l : 64 bits hexadecimal
145//   - %c : char
146//   - %s : string
147// In case or error returned by syscall, it makes a giet_exit().
148//////////////////////////////////////////////////////////////////////////
149extern void giet_shr_printf( char* format, ... );
150
151//////////////////////////////////////////////////////////////////////////
152// This blocking function fetches a single character from the private
153// terminal allocated to the calling task in the boot.
154// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
155// In case or error returned by syscall, it makes a giet_exit().
156//////////////////////////////////////////////////////////////////////////
157extern void giet_tty_getc( char* byte );
158
159//////////////////////////////////////////////////////////////////////////
160// This blocking function fetches a string from the private terminal
161// allocated to the calling task to a fixed length buffer.
162// The terminal index must be defined in the task context in the boot.
163// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
164// - Up to (bufsize - 1) characters (including the non printable characters)
165//   are copied into buffer, and the string is completed by a NUL character.
166// - The <LF> character is interpreted, and the function close the string
167//   with a NUL character if <LF> is read.
168// - The <DEL> character is interpreted, and the corresponding character(s)
169//   are removed from the target buffer.
170// - It does not provide an echo.
171// In case or error returned by syscall, it makes a giet_exit().
172/////////////////////////////////////////////////////////////////////////
173extern void giet_tty_gets( char* buf, unsigned int bufsize );
174
175/////////////////////////////////////////////////////////////////////////
176// This blocking function fetches a string of decimal characters (most
177// significant digit first) to build a 32-bit unsigned integer from
178// the private TTY terminal allocated to the calling task.
179// The terminal index must be defined in the task context in the boot.
180// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
181// - The non-blocking system function _tty_read is called several times,
182//   and the decimal characters are written in a 32 characters buffer
183//   until a <LF> character is read.
184// - It ignores non-decimal characters, and displays an echo
185//   system function) for each decimal character.
186// - The <DEL> character is interpreted, and previous characters can be cancelled.
187// - When the <LF> character is received, the string is converted to an
188//   unsigned int value. If the number of decimal digit is too large for the 32
189//   bits range, the zero value is returned.
190// In case or error returned by syscall, it makes a giet_exit().
191//////////////////////////////////////////////////////////////////////////
192extern void giet_tty_getw( unsigned int* val );
193
194//////////////////////////////////////////////////////////////////////////
195//////////////////////////////////////////////////////////////////////////
196//                TIMER device related system calls
197//////////////////////////////////////////////////////////////////////////
198//////////////////////////////////////////////////////////////////////////
199
200//////////////////////////////////////////////////////////////////////////
201// This function activates the private user timer allocated
202// to the calling task in the boot phase.
203// In case or error returned by syscall, it makes a giet_exit().
204//////////////////////////////////////////////////////////////////////////
205extern void giet_timer_start();
206
207//////////////////////////////////////////////////////////////////////////
208// This function stops the private user timer allocated
209// to the calling task.
210// In case or error returned by syscall, it makes a giet_exit().
211//////////////////////////////////////////////////////////////////////////
212extern void giet_timer_stop();
213 
214//////////////////////////////////////////////////////////////////////////
215//////////////////////////////////////////////////////////////////////////
216//                Frame buffer device related system calls
217//////////////////////////////////////////////////////////////////////////
218//////////////////////////////////////////////////////////////////////////
219
220//////////////////////////////////////////////////////////////////////////
221// This blocking function use a memory copy strategy to transfer data
222// from the frame buffer device in kernel space to an user buffer.
223//     offset : offset (in bytes) in the frame buffer
224//     buffer : base address of the user buffer
225//     length : number of bytes to be transfered
226// In case or error returned by syscall, it makes a giet_exit().
227//////////////////////////////////////////////////////////////////////////
228extern void giet_fb_sync_read( unsigned int offset, 
229                               void*        buffer, 
230                               unsigned int length );
231
232//////////////////////////////////////////////////////////////////////////
233// This blocking function use a memory copy strategy to transfer data
234// from a user buffer to the frame buffer device in kernel space.
235//     offset : offset (in bytes) in the frame buffer
236//     buffer : base address of the memory buffer
237//     length : number of bytes to be transfered
238// In case or error returned by syscall, it makes a giet_exit().
239//////////////////////////////////////////////////////////////////////////
240extern void giet_fb_sync_write( unsigned int offset, 
241                                void*        buffer, 
242                                unsigned int length );
243
244//////////////////////////////////////////////////////////////////////////
245// This function initializes the two chbuf SRC an DST used by the CMA
246// controller and activates the CMA channel allocated to the calling task.
247// - buf0   : first user buffer virtual address
248// - buf1   : second user buffer virtual address
249// - length : buffer size (bytes)
250// In case or error returned by syscall, it makes a giet_exit().
251//////////////////////////////////////////////////////////////////////////
252extern void giet_fb_cma_init( void*        buf0, 
253                              void*        buf1,
254                              unsigned int length );
255
256//////////////////////////////////////////////////////////////////////////
257// This function initializes the two chbuf SRC an DST used by the CMA
258// controller and activates the CMA channel allocated to the calling task.
259// - buf0   : first user buffer virtual address
260// - buf0   : second user buffer virtual address
261// - length : buffer size (bytes)
262// In case or error returned by syscall, it makes a giet_exit().
263//////////////////////////////////////////////////////////////////////////
264extern void giet_fb_cma_write( unsigned int buf_id );
265
266//////////////////////////////////////////////////////////////////////////
267// This function desactivates the CMA channel allocated to the task.
268// In case or error returned by syscall, it makes a giet_exit().
269//////////////////////////////////////////////////////////////////////////
270extern void giet_fb_cma_stop();
271
272//////////////////////////////////////////////////////////////////////////
273//////////////////////////////////////////////////////////////////////////
274//                  NIC related system calls
275//////////////////////////////////////////////////////////////////////////
276//////////////////////////////////////////////////////////////////////////
277
278//////////////////////////////////////////////////////////////////////////
279// This function initializes the memory chbuf used by the CMA controller,
280// activates the NIC channel allocated to the calling task,
281// and activates the two CMA channels.
282// - tx     : RX channel if 0 / TX channel if non 0
283// - buf0   : first user buffer virtual address
284// - buf1   : second user buffer virtual address
285// - length : buffer size (bytes)
286// In case or error returned by syscall, it makes a giet_exit().
287//////////////////////////////////////////////////////////////////////////
288extern void giet_nic_cma_start();
289
290//////////////////////////////////////////////////////////////////////////
291// This function desactivates the NIC channel and the two CMA channels
292// allocated to the calling task.
293// In case or error returned by syscall, it makes a giet_exit().
294//////////////////////////////////////////////////////////////////////////
295extern void giet_nic_cma_stop();
296
297//////////////////////////////////////////////////////////////////////////
298//////////////////////////////////////////////////////////////////////////
299//               FAT related system calls
300//////////////////////////////////////////////////////////////////////////
301//////////////////////////////////////////////////////////////////////////
302
303//////////////////////////////////////////////////////////////////////////
304// Open a file identified by a pathname, and contained in the system FAT.
305// The read/write flags are not supported yet: no effect.
306// Return -1 in case or error.
307//////////////////////////////////////////////////////////////////////////
308extern int giet_fat_open(  const char*  pathname,
309                           unsigned int flags );
310
311///////////////////////////////////////////////////////////////////////////////////
312// Read "count" sectors from a file identified by "fd", skipping "offset"
313// sectors in file, and writing into the user "buffer".
314// The user buffer base address shoulb be 64 bytes aligned.
315// In case or error returned by syscall, it makes a giet_exit().
316///////////////////////////////////////////////////////////////////////////////////
317extern void giet_fat_read(  unsigned int fd,
318                            void*        buffer,
319                            unsigned int count,
320                            unsigned int offset );
321
322///////////////////////////////////////////////////////////////////////////////////
323// Write "count" sectors from a file identified by "fd", skipping "offset"
324// sectors in file, and reading from the user "buffer".
325// The user buffer base address shoulb be 64 bytes aligned.
326// In case or error returned by syscall, it makes a giet_exit().
327///////////////////////////////////////////////////////////////////////////////////
328extern void giet_fat_write( unsigned int fd,
329                            void*        buffer,
330                            unsigned int count,
331                            unsigned int offset );
332
333///////////////////////////////////////////////////////////////////////////////////
334// Change the lseek file pointer value for a file identified by "fd".
335// In case or error returned by syscall, it makes a giet_exit().
336///////////////////////////////////////////////////////////////////////////////////
337extern void giet_fat_lseek( unsigned int fd,
338                            unsigned int offset,
339                            unsigned int whence );
340
341///////////////////////////////////////////////////////////////////////////////////
342// Returns general informations of a file identified by "fd".
343// (Only the file_size in sectors for this moment)
344///////////////////////////////////////////////////////////////////////////////////
345extern void giet_fat_fstat( unsigned int fd );
346
347//////////////////////////////////////////////////////////////////////////
348// Close a file identified by "fd".
349//////////////////////////////////////////////////////////////////////////
350extern void giet_fat_close( unsigned int fd );
351
352//////////////////////////////////////////////////////////////////////////
353//////////////////////////////////////////////////////////////////////////
354//                    Miscelaneous system calls
355//////////////////////////////////////////////////////////////////////////
356//////////////////////////////////////////////////////////////////////////
357
358//////////////////////////////////////////////////////////////////////////
359// This function returns the processor identifier.
360//////////////////////////////////////////////////////////////////////////
361extern int giet_procid();
362
363//////////////////////////////////////////////////////////////////////////
364// This function returns the local processor time.
365//////////////////////////////////////////////////////////////////////////
366extern int giet_proctime();
367
368//////////////////////////////////////////////////////////////////////////
369// This functions returns the local task id.
370// If processor has n tasks the local task index is ranging from 0 to n-1
371//////////////////////////////////////////////////////////////////////////
372extern int giet_proc_task_id();
373
374//////////////////////////////////////////////////////////////////////////
375// This functions returns the global task id, (unique in the system).
376//////////////////////////////////////////////////////////////////////////
377extern int giet_global_task_id(); 
378
379//////////////////////////////////////////////////////////////////////////
380// This functions returns the thread index of the task in its vspace.
381//////////////////////////////////////////////////////////////////////////
382extern int giet_thread_id(); 
383
384//////////////////////////////////////////////////////////////////////////
385// This function returns a pseudo-random value derived from the processor
386// cycle count. This value is comprised between 0 & 65535.
387/////////////////////////////////////////////////////////////////////////
388extern int giet_rand();
389
390//////////////////////////////////////////////////////////////////////////
391// This function stops execution of the calling task with a TTY message,
392// the user task is descheduled and becomes not runable.
393// It does not consume processor cycles anymore.
394//////////////////////////////////////////////////////////////////////////
395extern void giet_exit();
396
397//////////////////////////////////////////////////////////////////////////
398// This function uses the giet_exit() system call
399// and kill the calling task if the condition is false.
400//////////////////////////////////////////////////////////////////////////
401extern void giet_assert( unsigned int, 
402                         char* string );
403
404//////////////////////////////////////////////////////////////////////////
405// This function writes in argument "vobj_vaddr" the virtual base address
406// of a vobj (defined in the mapping_info data structure), identified by
407// the two arguments "vspace_name" and "vobj_name".
408// In case or error returned by syscall, it makes a giet_exit().
409// ( vobj not defined or wrong vspace )
410//////////////////////////////////////////////////////////////////////////
411extern void giet_vobj_get_vbase( char*         vspace_name, 
412                                 char*         vobj_name, 
413                                 unsigned int* vobj_vaddr);
414
415//////////////////////////////////////////////////////////////////////////
416// This function returns in the "buffer" argument the number of processors
417// in the cluster specified by the "cluster_xy" argument.
418// In case or error returned by syscall, it makes a giet_exit().
419//////////////////////////////////////////////////////////////////////////
420extern void giet_procnumber( unsigned int cluster_xy,
421                             unsigned int buffer );
422
423//////////////////////////////////////////////////////////////////////////
424// The user task calling this function is descheduled and
425// the processor is allocated to another task.
426//////////////////////////////////////////////////////////////////////////
427extern void giet_context_switch();
428
429//////////////////////////////////////////////////////////////////////////
430// This function supports access to the task's heap or to a remote heap:
431// - If (x < X_SIZE) and (y < Y_SIZE), this function returns the base
432//   address and length of the heap associated to any task running
433//   on cluster(x,y) => remote heap
434// - Else, this function returns the base address and length of the
435//   heap associated to the calling task => local heap
436//////////////////////////////////////////////////////////////////////////
437extern void giet_heap_info( unsigned int* vaddr, 
438                            unsigned int* length,
439                            unsigned int  x,
440                            unsigned int  y );
441
442#endif
443
444// Local Variables:
445// tab-width: 4
446// c-basic-offset: 4
447// c-file-offsets:((innamespace . 0)(inline-open . 0))
448// indent-tabs-mode: nil
449// End:
450// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
451
Note: See TracBrowser for help on using the repository browser.