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

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

Inroducing support in the stdio for dynamic allocation of peripherals
in the stdio library.

  • Property svn:executable set to *
File size: 9.3 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_PROC_XYP          0x00
19#define SYSCALL_PROC_TIME         0x01
20#define SYSCALL_TTY_WRITE         0x02
21#define SYSCALL_TTY_READ          0x03
22#define SYSCALL_TTY_ALLOC         0x04
23#define SYSCALL_TTY_GET_LOCK      0x05
24#define SYSCALL_TTY_RELEASE_LOCK  0x06
25#define SYSCALL_HEAP_INFO         0x07
26#define SYSCALL_LOCAL_TASK_ID     0x08
27#define SYSCALL_GLOBAL_TASK_ID    0x09
28#define SYSCALL_FBF_CMA_ALLOC     0x0A
29#define SYSCALL_FBF_CMA_START     0x0B
30#define SYSCALL_FBF_CMA_DISPLAY   0x0C
31#define SYSCALL_FBF_CMA_STOP      0x0D
32#define SYSCALL_EXIT              0x0E
33#define SYSCALL_PROC_NUMBER       0x0F
34
35#define SYSCALL_FBF_SYNC_WRITE    0x10
36#define SYSCALL_FBF_SYNC_READ     0x11
37#define SYSCALL_THREAD_ID         0x12
38//                                0x13
39#define SYSCALL_TIM_ALLOC         0x14
40#define SYSCALL_TIM_START         0x15
41#define SYSCALL_TIM_STOP          0x16
42//                                0x17
43//                                0x18
44#define SYSCALL_CTX_SWITCH        0x19
45#define SYSCALL_VOBJ_GET_VBASE    0x1A
46#define SYSCALL_VOBJ_GET_LENGTH   0x1B
47#define SYSCALL_GET_XY            0x1C
48#define SYSCALL_NIC_ALLOC         0x1D
49#define SYSCALL_NIC_SYNC_SEND     0x1E
50#define SYSCALL_NIC_SYNC_RECEIVE  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//                                0x26
59//                                0x27
60//                                0x28
61//                                0x29
62//                                0x2A
63//                                0x2B
64//                                0x2C
65//                                0x2D
66//                                0x2E
67//                                0x2F
68
69//////////////////////////////////////////////////////////////////////////////////
70// NULL pointer definition
71//////////////////////////////////////////////////////////////////////////////////
72
73#define NULL (void *)0
74
75//////////////////////////////////////////////////////////////////////////////////
76// This generic C function is used to implement all system calls.
77// It writes the system call arguments in the proper registers,
78// and tells GCC what has been modified by system call execution.
79// Returns -1 to signal an error.
80//////////////////////////////////////////////////////////////////////////////////
81static inline int sys_call( int call_no,
82                            int arg_0, 
83                            int arg_1, 
84                            int arg_2, 
85                            int arg_3 ) 
86{
87    register int reg_no_and_output asm("v0") = call_no;
88    register int reg_a0 asm("a0") = arg_0;
89    register int reg_a1 asm("a1") = arg_1;
90    register int reg_a2 asm("a2") = arg_2;
91    register int reg_a3 asm("a3") = arg_3;
92
93    asm volatile(
94            "syscall"
95            : "+r" (reg_no_and_output), /* input/output argument */
96              "+r" (reg_a0),             
97              "+r" (reg_a1),
98              "+r" (reg_a2),
99              "+r" (reg_a3),
100              "+r" (reg_no_and_output)
101            : /* input arguments */
102            : "memory",
103            /* These persistant registers will be saved on the stack by the
104             * compiler only if they contain relevant data. */
105            "at",
106            "v1",
107            "ra",
108            "t0",
109            "t1",
110            "t2",
111            "t3",
112            "t4",
113            "t5",
114            "t6",
115            "t7",
116            "t8",
117            "t9"
118               );
119    return (volatile int)reg_no_and_output;
120}
121
122//////////////////////////////////////////////////////////////////////////
123//               MIPS32 related system calls
124//////////////////////////////////////////////////////////////////////////
125
126//////////////////////////////////////////////////////////////////////////
127extern void giet_proc_xyp( unsigned int* cluster_x,
128                           unsigned int* cluster_y,
129                           unsigned int* lpid );
130
131extern unsigned int giet_proctime();
132
133extern unsigned int giet_rand();
134
135//////////////////////////////////////////////////////////////////////////
136//                    Task context system calls
137//////////////////////////////////////////////////////////////////////////
138
139extern unsigned int giet_proc_task_id();
140
141extern unsigned int giet_global_task_id(); 
142
143extern unsigned int giet_thread_id(); 
144
145//////////////////////////////////////////////////////////////////////////
146//             TTY device related system calls
147//////////////////////////////////////////////////////////////////////////
148
149extern void giet_tty_alloc();
150
151extern void giet_tty_printf( char* format, ... );
152
153extern void giet_shr_printf( char* format, ... );
154
155extern void giet_tty_getc( char* byte );
156
157extern void giet_tty_gets( char* buf, unsigned int bufsize );
158
159extern void giet_tty_getw( unsigned int* val );
160
161//////////////////////////////////////////////////////////////////////////
162//                TIMER device related system calls
163//////////////////////////////////////////////////////////////////////////
164
165extern void giet_timer_alloc();
166
167extern void giet_timer_start( unsigned int period );
168
169extern void giet_timer_stop();
170 
171//////////////////////////////////////////////////////////////////////////
172//                Frame buffer device related system calls
173//////////////////////////////////////////////////////////////////////////
174
175extern void giet_fbf_cma_alloc();
176
177extern void giet_fbf_cma_start( void*        buf0, 
178                                void*        buf1,
179                                unsigned int length );
180
181extern void giet_fbf_cma_display( unsigned int buffer );
182
183extern void giet_fbf_cma_stop();
184
185extern void giet_fbf_sync_read( unsigned int offset, 
186                                void*        buffer, 
187                                unsigned int length );
188
189extern void giet_fbf_sync_write( unsigned int offset, 
190                                 void*        buffer, 
191                                 unsigned int length );
192
193//////////////////////////////////////////////////////////////////////////
194//                  NIC related system calls
195//////////////////////////////////////////////////////////////////////////
196
197extern void giet_nic_alloc();
198
199extern void giet_nic_sync_send( void* buffer);
200
201extern void giet_nic_sync_receive( void* buffer );
202
203//////////////////////////////////////////////////////////////////////////
204//               FAT related system calls
205//////////////////////////////////////////////////////////////////////////
206
207extern int giet_fat_open(  const char*  pathname,
208                           unsigned int flags );
209
210extern void giet_fat_read(  unsigned int fd,
211                            void*        buffer,
212                            unsigned int count,
213                            unsigned int offset );
214
215extern void giet_fat_write( unsigned int fd,
216                            void*        buffer,
217                            unsigned int count,
218                            unsigned int offset );
219
220extern void giet_fat_lseek( unsigned int fd,
221                            unsigned int offset,
222                            unsigned int whence );
223
224extern void giet_fat_fstat( unsigned int fd );
225
226extern void giet_fat_close( unsigned int fd );
227
228//////////////////////////////////////////////////////////////////////////
229//                    Miscelaneous system calls
230//////////////////////////////////////////////////////////////////////////
231
232extern void giet_exit( char* string );
233
234extern void giet_assert( unsigned int condition, 
235                         char*        string );
236
237extern void giet_context_switch();
238
239extern void giet_procnumber( unsigned int cluster_xy,
240                             unsigned int buffer );
241
242extern void giet_vobj_get_vbase( char*         vspace_name, 
243                                 char*         vobj_name, 
244                                 unsigned int* vobj_vaddr);
245
246extern void giet_vobj_get_length( char*         vspace_name, 
247                                  char*         vobj_name, 
248                                  unsigned int* vobj_vaddr);
249
250extern void giet_heap_info( unsigned int* vaddr, 
251                            unsigned int* length,
252                            unsigned int  x,
253                            unsigned int  y );
254
255extern void giet_get_xy( void*          ptr, 
256                         unsigned int*  px,
257                         unsigned int*  py );
258
259#endif
260
261// Local Variables:
262// tab-width: 4
263// c-basic-offset: 4
264// c-file-offsets:((innamespace . 0)(inline-open . 0))
265// indent-tabs-mode: nil
266// End:
267// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
268
Note: See TracBrowser for help on using the repository browser.