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

Last change on this file since 433 was 431, checked in by alain, 10 years ago

Introducing fixed format (X_WIDTH / Y_WIDTH / P_WIDTH) for processor index.

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