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

Last change on this file since 325 was 295, checked in by alain, 10 years ago

Introducing a major release, to suppoort the tsar_generic_leti platform
and the various (external or internal) peripherals configurations.
The map.xml format has been modified, in order to support the new
vci_iopic componentand a new policy for peripherals initialisation.
The IRQs are nom described in the XICU and IOPIC components
(and not anymore in the processors).
To enforce this major change, the map.xml file signature changed:
The signature value must be: 0xDACE2014

This new release has been tested on the tsar_generic_leti platform
for the following mappings:

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