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

Last change on this file since 357 was 352, checked in by alain, 11 years ago

Avoid GCC warnings for some missing initialisations.

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