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

Last change on this file since 416 was 390, checked in by alain, 10 years ago

1) Introducing the new system call giet_get_xy() in stdio.h,

required for the free() funcyion in malloc.h

2) Fixing bugs in malloc.c

  • Property svn:executable set to *
File size: 22.6 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 identifier.
119//////////////////////////////////////////////////////////////////////////
120extern int giet_procid();
121
122//////////////////////////////////////////////////////////////////////////
123// This function returns the local processor time.
124//////////////////////////////////////////////////////////////////////////
125extern int giet_proctime();
126
127//////////////////////////////////////////////////////////////////////////
128// This function returns a pseudo-random value derived from the processor
129// cycle count. This value is comprised between 0 & 65535.
130/////////////////////////////////////////////////////////////////////////
131extern int giet_rand();
132
133//////////////////////////////////////////////////////////////////////////
134//////////////////////////////////////////////////////////////////////////
135//             TTY device related system calls
136//////////////////////////////////////////////////////////////////////////
137//////////////////////////////////////////////////////////////////////////
138
139//////////////////////////////////////////////////////////////////////////
140// This function is a modified version of the mutek_printf().
141// It uses a private terminal allocated to the calling task in the boot.
142// ("use_tty" argument in xml mapping), and does not take the TTY lock.
143// It calls several times the _tty_write system function.
144// Only a limited number of formats are supported:
145//   - %d : signed decimal
146//   - %u : unsigned decimal
147//   - %x : 32 bits hexadecimal
148//   - %l : 64 bits hexadecimal
149//   - %c : char
150//   - %s : string
151// In case or error returned by syscall, it makes a giet_exit().
152//////////////////////////////////////////////////////////////////////////
153extern void giet_tty_printf( char* format, ... );
154
155//////////////////////////////////////////////////////////////////////////
156// This function is a modified version of the mutek_printf().
157// It uses the kernel TTY0 as a shared terminal, and it takes the
158// TTY lock to get exclusive access during the format display.
159// It calls several times the _tty_write system function.
160// Only a limited number of formats are supported:
161//   - %d : signed decimal
162//   - %u : unsigned decimal
163//   - %x : 32 bits hexadecimal
164//   - %l : 64 bits hexadecimal
165//   - %c : char
166//   - %s : string
167// In case or error returned by syscall, it makes a giet_exit().
168//////////////////////////////////////////////////////////////////////////
169extern void giet_shr_printf( char* format, ... );
170
171//////////////////////////////////////////////////////////////////////////
172// This blocking function fetches a single character from the private
173// terminal allocated to the calling task in the boot.
174// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
175// In case or error returned by syscall, it makes a giet_exit().
176//////////////////////////////////////////////////////////////////////////
177extern void giet_tty_getc( char* byte );
178
179//////////////////////////////////////////////////////////////////////////
180// This blocking function fetches a string from the private terminal
181// allocated to the calling task to a fixed length buffer.
182// The terminal index must be defined in the task context in the boot.
183// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
184// - Up to (bufsize - 1) characters (including the non printable characters)
185//   are copied into buffer, and the string is completed by a NUL character.
186// - The <LF> character is interpreted, and the function close the string
187//   with a NUL character if <LF> is read.
188// - The <DEL> character is interpreted, and the corresponding character(s)
189//   are removed from the target buffer.
190// - It does not provide an echo.
191// In case or error returned by syscall, it makes a giet_exit().
192/////////////////////////////////////////////////////////////////////////
193extern void giet_tty_gets( char* buf, unsigned int bufsize );
194
195/////////////////////////////////////////////////////////////////////////
196// This blocking function fetches a string of decimal characters (most
197// significant digit first) to build a 32-bit unsigned integer from
198// the private TTY terminal allocated to the calling task.
199// The terminal index must be defined in the task context in the boot.
200// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
201// - The non-blocking system function _tty_read is called several times,
202//   and the decimal characters are written in a 32 characters buffer
203//   until a <LF> character is read.
204// - It ignores non-decimal characters, and displays an echo
205//   system function) for each decimal character.
206// - The <DEL> character is interpreted, and previous characters can be cancelled.
207// - When the <LF> character is received, the string is converted to an
208//   unsigned int value. If the number of decimal digit is too large for the 32
209//   bits range, the zero value is returned.
210// In case or error returned by syscall, it makes a giet_exit().
211//////////////////////////////////////////////////////////////////////////
212extern void giet_tty_getw( unsigned int* val );
213
214//////////////////////////////////////////////////////////////////////////
215//////////////////////////////////////////////////////////////////////////
216//                TIMER device related system calls
217//////////////////////////////////////////////////////////////////////////
218//////////////////////////////////////////////////////////////////////////
219
220//////////////////////////////////////////////////////////////////////////
221// This function activates the private user timer allocated
222// to the calling task in the boot phase.
223// In case or error returned by syscall, it makes a giet_exit().
224//////////////////////////////////////////////////////////////////////////
225extern void giet_timer_start();
226
227//////////////////////////////////////////////////////////////////////////
228// This function stops the private user timer allocated
229// to the calling task.
230// In case or error returned by syscall, it makes a giet_exit().
231//////////////////////////////////////////////////////////////////////////
232extern void giet_timer_stop();
233 
234//////////////////////////////////////////////////////////////////////////
235//////////////////////////////////////////////////////////////////////////
236//                Frame buffer device related system calls
237//////////////////////////////////////////////////////////////////////////
238//////////////////////////////////////////////////////////////////////////
239
240//////////////////////////////////////////////////////////////////////////
241// This blocking function use a memory copy strategy to transfer data
242// from the frame buffer device in kernel space to an user buffer.
243//     offset : offset (in bytes) in the frame buffer
244//     buffer : base address of the user buffer
245//     length : number of bytes to be transfered
246// In case or error returned by syscall, it makes a giet_exit().
247//////////////////////////////////////////////////////////////////////////
248extern void giet_fb_sync_read( unsigned int offset, 
249                               void*        buffer, 
250                               unsigned int length );
251
252//////////////////////////////////////////////////////////////////////////
253// This blocking function use a memory copy strategy to transfer data
254// from a user buffer to the frame buffer device in kernel space.
255//     offset : offset (in bytes) in the frame buffer
256//     buffer : base address of the memory buffer
257//     length : number of bytes to be transfered
258// In case or error returned by syscall, it makes a giet_exit().
259//////////////////////////////////////////////////////////////////////////
260extern void giet_fb_sync_write( unsigned int offset, 
261                                void*        buffer, 
262                                unsigned int length );
263
264//////////////////////////////////////////////////////////////////////////
265// This function initializes the two chbuf SRC an DST used by the CMA
266// controller and activates the CMA channel allocated to the calling task.
267// - buf0   : first user buffer virtual address
268// - buf1   : second user buffer virtual address
269// - length : buffer size (bytes)
270// In case or error returned by syscall, it makes a giet_exit().
271//////////////////////////////////////////////////////////////////////////
272extern void giet_fb_cma_init( void*        buf0, 
273                              void*        buf1,
274                              unsigned int length );
275
276//////////////////////////////////////////////////////////////////////////
277// This function initializes the two chbuf SRC an DST used by the CMA
278// controller and activates the CMA channel allocated to the calling task.
279// - buf0   : first user buffer virtual address
280// - buf0   : second user buffer virtual address
281// - length : buffer size (bytes)
282// In case or error returned by syscall, it makes a giet_exit().
283//////////////////////////////////////////////////////////////////////////
284extern void giet_fb_cma_write( unsigned int buf_id );
285
286//////////////////////////////////////////////////////////////////////////
287// This function desactivates the CMA channel allocated to the task.
288// In case or error returned by syscall, it makes a giet_exit().
289//////////////////////////////////////////////////////////////////////////
290extern void giet_fb_cma_stop();
291
292//////////////////////////////////////////////////////////////////////////
293//////////////////////////////////////////////////////////////////////////
294//                  NIC related system calls
295//////////////////////////////////////////////////////////////////////////
296//////////////////////////////////////////////////////////////////////////
297
298//////////////////////////////////////////////////////////////////////////
299// This function initializes the memory chbuf used by the CMA controller,
300// activates the NIC channel allocated to the calling task,
301// and activates the two CMA channels.
302// - tx     : RX channel if 0 / TX channel if non 0
303// - buf0   : first user buffer virtual address
304// - buf1   : second user buffer virtual address
305// - length : buffer size (bytes)
306// In case or error returned by syscall, it makes a giet_exit().
307//////////////////////////////////////////////////////////////////////////
308extern void giet_nic_cma_start();
309
310//////////////////////////////////////////////////////////////////////////
311// This function desactivates the NIC channel and the two CMA channels
312// allocated to the calling task.
313// In case or error returned by syscall, it makes a giet_exit().
314//////////////////////////////////////////////////////////////////////////
315extern void giet_nic_cma_stop();
316
317//////////////////////////////////////////////////////////////////////////
318//////////////////////////////////////////////////////////////////////////
319//               FAT related system calls
320//////////////////////////////////////////////////////////////////////////
321//////////////////////////////////////////////////////////////////////////
322
323//////////////////////////////////////////////////////////////////////////
324// Open a file identified by a pathname, and contained in the system FAT.
325// The read/write flags are not supported yet: no effect.
326// Return -1 in case or error.
327//////////////////////////////////////////////////////////////////////////
328extern int giet_fat_open(  const char*  pathname,
329                           unsigned int flags );
330
331///////////////////////////////////////////////////////////////////////////////////
332// Read "count" sectors from a file identified by "fd", skipping "offset"
333// sectors in file, and writing into the user "buffer".
334// The user buffer base address shoulb be 64 bytes aligned.
335// In case or error returned by syscall, it makes a giet_exit().
336///////////////////////////////////////////////////////////////////////////////////
337extern void giet_fat_read(  unsigned int fd,
338                            void*        buffer,
339                            unsigned int count,
340                            unsigned int offset );
341
342///////////////////////////////////////////////////////////////////////////////////
343// Write "count" sectors into a file identified by "fd", skipping "offset"
344// sectors in file, and reading from the user "buffer".
345// The user buffer base address shoulb be 64 bytes aligned.
346// In case or error returned by syscall, it makes a giet_exit().
347///////////////////////////////////////////////////////////////////////////////////
348extern void giet_fat_write( unsigned int fd,
349                            void*        buffer,
350                            unsigned int count,
351                            unsigned int offset );
352
353///////////////////////////////////////////////////////////////////////////////////
354// Change the lseek file pointer value for a file identified by "fd".
355// In case or error returned by syscall, it makes a giet_exit().
356///////////////////////////////////////////////////////////////////////////////////
357extern void giet_fat_lseek( unsigned int fd,
358                            unsigned int offset,
359                            unsigned int whence );
360
361///////////////////////////////////////////////////////////////////////////////////
362// Returns general informations of a file identified by "fd".
363// (Only the file_size in sectors for this moment)
364///////////////////////////////////////////////////////////////////////////////////
365extern void giet_fat_fstat( unsigned int fd );
366
367//////////////////////////////////////////////////////////////////////////
368// Close a file identified by "fd".
369//////////////////////////////////////////////////////////////////////////
370extern void giet_fat_close( unsigned int fd );
371
372//////////////////////////////////////////////////////////////////////////
373//////////////////////////////////////////////////////////////////////////
374//                    Task context system calls
375//////////////////////////////////////////////////////////////////////////
376//////////////////////////////////////////////////////////////////////////
377
378//////////////////////////////////////////////////////////////////////////
379// This functions returns the local task id.
380// If processor has n tasks the local task index is ranging from 0 to n-1
381//////////////////////////////////////////////////////////////////////////
382extern int giet_proc_task_id();
383
384//////////////////////////////////////////////////////////////////////////
385// This functions returns the global task id, (unique in the system).
386//////////////////////////////////////////////////////////////////////////
387extern int giet_global_task_id(); 
388
389//////////////////////////////////////////////////////////////////////////
390// This functions returns the thread index of the task in its vspace.
391//////////////////////////////////////////////////////////////////////////
392extern int giet_thread_id(); 
393
394//////////////////////////////////////////////////////////////////////////
395//////////////////////////////////////////////////////////////////////////
396//                    Miscelaneous system calls
397//////////////////////////////////////////////////////////////////////////
398//////////////////////////////////////////////////////////////////////////
399
400//////////////////////////////////////////////////////////////////////////
401// This function stops execution of the calling task with a TTY message,
402// the user task is descheduled and becomes not runable.
403// It does not consume processor cycles anymore.
404//////////////////////////////////////////////////////////////////////////
405extern void giet_exit( char* string );
406
407//////////////////////////////////////////////////////////////////////////
408// This function uses the giet_exit() system call
409// and kill the calling task if the condition is false.
410//////////////////////////////////////////////////////////////////////////
411extern void giet_assert( unsigned int condition, 
412                         char*        string );
413
414//////////////////////////////////////////////////////////////////////////
415// The user task calling this function is descheduled and
416// the processor is allocated to another task.
417//////////////////////////////////////////////////////////////////////////
418extern void giet_context_switch();
419
420//////////////////////////////////////////////////////////////////////////
421// This function writes in argument "vobj_vaddr" the virtual base address
422// of a vobj (defined in the mapping_info data structure), identified by
423// the two arguments "vspace_name" and "vobj_name".
424// In case or error returned by syscall, it makes a giet_exit().
425// ( vobj not defined or wrong vspace )
426//////////////////////////////////////////////////////////////////////////
427extern void giet_vobj_get_vbase( char*         vspace_name, 
428                                 char*         vobj_name, 
429                                 unsigned int* vobj_vaddr);
430
431//////////////////////////////////////////////////////////////////////////
432// This function returns in the "buffer" argument the number of processors
433// in the cluster specified by the "cluster_xy" argument.
434// In case or error returned by syscall, it makes a giet_exit().
435//////////////////////////////////////////////////////////////////////////
436extern void giet_procnumber( unsigned int cluster_xy,
437                             unsigned int buffer );
438
439//////////////////////////////////////////////////////////////////////////
440// This function supports access to the task's heap or to a remote heap:
441// - If (x < X_SIZE) and (y < Y_SIZE), this function returns the base
442//   address and length of the heap associated to any task running
443//   on cluster(x,y) => remote heap
444// - Else, this function returns the base address and length of the
445//   heap associated to the calling task => local heap
446//////////////////////////////////////////////////////////////////////////
447extern void giet_heap_info( unsigned int* vaddr, 
448                            unsigned int* length,
449                            unsigned int  x,
450                            unsigned int  y );
451
452//////////////////////////////////////////////////////////////////////////
453// This function takes as input a virtual address (ptr argument),
454// and returns through the (px,py) arguments the coordinates of
455// the cluster containing the physical address associated to ptr.
456// In case of error (unmapped virtual address), it makes a giet_exit().
457//////////////////////////////////////////////////////////////////////////
458extern void giet_get_xy( void*          ptr, 
459                         unsigned int*  px,
460                         unsigned int*  py );
461
462#endif
463
464// Local Variables:
465// tab-width: 4
466// c-basic-offset: 4
467// c-file-offsets:((innamespace . 0)(inline-open . 0))
468// indent-tabs-mode: nil
469// End:
470// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
471
Note: See TracBrowser for help on using the repository browser.