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

Last change on this file since 771 was 771, checked in by alain, 8 years ago

Introducing the generic xprintf() function, called by the various *printf() functions.

  • Property svn:executable set to *
File size: 16.9 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#include "giet_fat32/fat32_shared.h"
16#include "giet_common/mips32_registers.h"
17
18// These define must be synchronised with
19// the _syscall_vector defined in file sys_handler.c
20
21#define SYSCALL_PROC_XYP             0x00
22#define SYSCALL_PROC_TIME            0x01
23#define SYSCALL_PROCS_NUMBER         0x02
24#define SYSCALL_GET_XY               0x03
25//                                   0x04
26#define SYSCALL_VOBJ_GET_VBASE       0x05
27#define SYSCALL_VOBJ_GET_LENGTH      0x06
28#define SYSCALL_HEAP_INFO            0x07
29#define SYSCALL_FBF_SIZE             0x08
30#define SYSCALL_FBF_ALLOC            0x09
31#define SYSCALL_FBF_CMA_ALLOC        0x0A
32#define SYSCALL_FBF_CMA_INIT_BUF     0x0B
33#define SYSCALL_FBF_CMA_START        0x0C
34#define SYSCALL_FBF_CMA_DISPLAY      0x0D
35#define SYSCALL_FBF_CMA_STOP         0x0E
36#define SYSCALL_FBF_CMA_CHECK        0x0F
37
38#define SYSCALL_APPS_STATUS          0x10
39#define SYSCALL_FBF_SYNC_WRITE       0x11
40#define SYSCALL_FBF_SYNC_READ        0x12
41//                                   0x13
42#define SYSCALL_TIM_ALLOC            0x14
43#define SYSCALL_TIM_START            0x15
44#define SYSCALL_TIM_STOP             0x16
45#define SYSCALL_KILL_APP             0x17
46#define SYSCALL_EXEC_APP             0x18
47//                                   0x19
48#define SYSCALL_PTHREAD_CONTROL      0x1A
49#define SYSCALL_PTHREAD_YIELD        0x1B
50#define SYSCALL_PTHREAD_KILL         0x1C
51#define SYSCALL_PTHREAD_CREATE       0x1D
52#define SYSCALL_PTHREAD_JOIN         0x1E
53#define SYSCALL_PTHREAD_EXIT         0x1F
54
55#define SYSCALL_FAT_OPEN             0x20
56#define SYSCALL_FAT_READ             0x21
57#define SYSCALL_FAT_WRITE            0x22
58#define SYSCALL_FAT_LSEEK            0x23
59#define SYSCALL_FAT_FINFO            0x24
60#define SYSCALL_FAT_CLOSE            0x25
61#define SYSCALL_FAT_REMOVE           0x26
62#define SYSCALL_FAT_RENAME           0x27
63#define SYSCALL_FAT_MKDIR            0x28
64#define SYSCALL_FAT_OPENDIR          0x29
65#define SYSCALL_FAT_CLOSEDIR         0x2A
66#define SYSCALL_FAT_READDIR          0x2B
67#define SYSCALL_FAT_PREAD            0x2C
68#define SYSCALL_FAT_MMAP             0x2D
69#define SYSCALL_FAT_MUNMAP           0x2E
70#define SYSCALL_FAT_DUMP             0x2F
71
72#define SYSCALL_NIC_ALLOC            0x30
73#define SYSCALL_NIC_START            0x31
74#define SYSCALL_NIC_MOVE             0x32
75#define SYSCALL_NIC_STOP             0x33
76#define SYSCALL_NIC_STATS            0x34
77#define SYSCALL_NIC_CLEAR            0x35
78#define SYSCALL_TTY_WRITE            0x36
79#define SYSCALL_TTY_READ             0x37
80#define SYSCALL_TTY_ALLOC            0x38
81//                                   0x39
82//                                   0x3A
83#define SYSCALL_COPROC_COMPLETED     0x3B
84#define SYSCALL_COPROC_ALLOC         0x3C
85#define SYSCALL_COPROC_CHANNEL_INIT  0x3D
86#define SYSCALL_COPROC_RUN           0x3E
87#define SYSCALL_COPROC_RELEASE       0x3F
88
89////////////////////////////////////////////////////////////////////////////
90// Define the error codes for the syscall handlers
91// These define must be synchronized with values in the sys_handler.h file
92////////////////////////////////////////////////////////////////////////////
93
94#define SYSCALL_OK                               ( 0 )
95#define SYSCALL_VSPACE_NOT_FOUND                 (-1 )
96#define SYSCALL_THREAD_NOT_FOUND                 (-2 )
97#define SYSCALL_NOT_IN_SAME_VSPACE               (-3 )
98#define SYSCALL_UNCOHERENT_THREAD_CONTEXT        (-4 )
99#define SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE      (-5 )
100#define SYSCALL_CANNOT_LOAD_DATA_SEGMENT         (-6 )
101#define SYSCALL_THREAD_ALREADY_ACTIVE            (-7 )
102#define SYSCALL_MAIN_NOT_FOUND                   (-8 )
103#define SYSCALL_APPLI_CANNOT_BE_KILLED           (-9 )
104#define SYSCALL_PTHREAD_ARGUMENT_NOT_SUPPORTED   (-10)
105#define SYSCALL_ILLEGAL_CLUSTER_COORDINATES      (-11)
106#define SYSCALL_VSEG_NOT_FOUND                   (-12)
107#define SYSCALL_UNDEFINED_SYSTEM_CALL            (-13)
108#define SYSCALL_COPROCESSOR_NOT_FOUND            (-14)
109#define SYSCALL_COPROCESSOR_ILLEGAL_MODE         (-15)
110#define SYSCALL_COPROCESSOR_NON_ALLOCATED        (-16)
111#define SYSCALL_CHANNEL_ALREADY_ALLOCATED        (-17)
112#define SYSCALL_NO_CHANNEL_AVAILABLE             (-18)
113#define SYSCALL_CHANNEL_NON_ALLOCATED            (-19)
114#define SYSCALL_ILLEGAL_XY_ARGUMENTS             (-20)
115#define SYSCALL_OUT_OF_KERNEL_HEAP_MEMORY        (-21)
116#define SYSCALL_ADDRESS_NON_ALIGNED              (-22)
117#define SYSCALL_ADDRESS_NON_USER_ACCESSIBLE      (-23)
118#define SYSCALL_MISSING_INITIALISATION           (-24)
119#define SYSCALL_SHARED_PERIPHERAL_BUSY           (-25)
120
121////////////////////////////////////////////////////////////////////////////
122// Command values for the giet_pthread_control() syscall
123// These define must be synchronized with values in the sys_handler.h file
124////////////////////////////////////////////////////////////////////////////
125
126#define THREAD_CMD_PAUSE        0
127#define THREAD_CMD_RESUME       1
128#define THREAD_CMD_CONTEXT      2
129
130////////////////////////////////////////////////////////////////////////////
131// Flags and protection values for the giet_fat_mmap() syscall
132// These define must be synchronized with values in the sys_handler.h file
133////////////////////////////////////////////////////////////////////////////
134
135#define MAP_ANONYMOUS           0x01
136#define MAP_FILE                0x02
137#define MAP_FIXED               0x04
138#define MAP_PRIVATE             0x08
139#define MAP_SHARED              0x10
140
141#define MAP_PROT_READ           0x1
142#define MAP_PROT_WRITE          0x2
143#define MAP_PROT_EXEC           0x4
144
145////////////////////////////////////////////////////////////////////////////
146// NULL pointer definition
147////////////////////////////////////////////////////////////////////////////
148
149#define NULL (void *)0
150
151////////////////////////////////////////////////////////////////////////////
152// This generic C function is used to implement all system calls.
153// It writes the system call arguments in the proper registers,
154// and tells GCC what has been modified by system call execution.
155// Returns -1 to signal an error.
156////////////////////////////////////////////////////////////////////////////
157static inline int sys_call( int call_no,
158                            int arg_0, 
159                            int arg_1, 
160                            int arg_2, 
161                            int arg_3 ) 
162{
163    register int reg_no_and_output asm("v0") = call_no;
164    register int reg_a0 asm("a0") = arg_0;
165    register int reg_a1 asm("a1") = arg_1;
166    register int reg_a2 asm("a2") = arg_2;
167    register int reg_a3 asm("a3") = arg_3;
168
169    asm volatile(
170            "syscall"
171            : "+r" (reg_no_and_output), /* input/output argument */
172              "+r" (reg_a0),             
173              "+r" (reg_a1),
174              "+r" (reg_a2),
175              "+r" (reg_a3),
176              "+r" (reg_no_and_output)
177            : /* input arguments */
178            : "memory",
179            /* These persistant registers will be saved on the stack by the
180             * compiler only if they contain relevant data. */
181            "at",
182            "v1",
183            "ra",
184            "t0",
185            "t1",
186            "t2",
187            "t3",
188            "t4",
189            "t5",
190            "t6",
191            "t7",
192            "t8",
193            "t9"
194               );
195    return (volatile int)reg_no_and_output;
196}
197
198//////////////////////////////////////////////////////////////////////////
199//               MIPS32 related system calls
200//////////////////////////////////////////////////////////////////////////
201
202extern void giet_proc_xyp( unsigned int* cluster_x,
203                           unsigned int* cluster_y,
204                           unsigned int* lpid );
205
206extern unsigned int giet_proctime();
207
208extern unsigned int giet_rand();
209
210//////////////////////////////////////////////////////////////////////////
211//              Threads related system calls
212//////////////////////////////////////////////////////////////////////////
213
214typedef unsigned int pthread_t;
215
216typedef unsigned int pthread_attr_t;
217
218extern int giet_pthread_create( pthread_t*       trdid,
219                                pthread_attr_t*  attr,
220                                void*            function,
221                                void*            ptr ); 
222
223extern void giet_pthread_exit( void* string );
224
225extern int giet_pthread_join( pthread_t  trdid,
226                              void**     ptr );
227
228extern int giet_pthread_kill( pthread_t thread_id,
229                              int       signal );
230
231extern void giet_pthread_yield();
232
233extern void giet_pthread_assert( unsigned int condition, 
234                                 char*        string );
235
236extern void giet_pthread_control( unsigned int command,
237                                  char*        vspace_name,
238                                  char*        thread_name );
239
240//////////////////////////////////////////////////////////////////////////
241//               Application related system calls
242//////////////////////////////////////////////////////////////////////////
243
244extern int giet_kill_application( char* name );
245
246extern int giet_exec_application( char* name );
247
248extern void giet_applications_status( char* name );
249
250//////////////////////////////////////////////////////////////////////////
251//             Coprocessors related system calls
252//////////////////////////////////////////////////////////////////////////
253
254// this structure is used by the giet_coproc_channel_init()
255// system call to specify the communication channel parameters.
256typedef struct giet_coproc_channel
257{
258    unsigned int  channel_mode;    // MWMR / DMA_IRQ / DMA_NO_IRQ
259    unsigned int  buffer_size;     // memory buffer size
260    unsigned int  buffer_vaddr;    // memory buffer virtual address
261    unsigned int  status_vaddr;    // MWMR status virtual address (12 bytes)
262    unsigned int  lock_vaddr;      // MWMR lock virtual address (64 bytes)
263} giet_coproc_channel_t;
264
265extern void giet_coproc_alloc( unsigned int   cluster_xy,
266                               unsigned int   coproc_type,
267                               unsigned int*  coproc_info );
268
269extern void giet_coproc_release( unsigned int cluster_xy,
270                                 unsigned int coproc_type );
271
272extern void giet_coproc_channel_init( unsigned int            cluster_xy,
273                                      unsigned int            coproc_type,
274                                      unsigned int            channel,
275                                      giet_coproc_channel_t*  desc );
276
277extern void giet_coproc_run( unsigned int cluster_xy,
278                             unsigned int coproc_type );
279
280extern void giet_coproc_completed( unsigned int cluster_xy,
281                                   unsigned int coproc_type );
282
283//////////////////////////////////////////////////////////////////////////
284//             TTY device related system calls
285//////////////////////////////////////////////////////////////////////////
286
287extern void giet_tty_alloc( unsigned int shared );
288
289extern void giet_tty_printf( char* format, ... );
290
291extern void giet_tty_getc( char* byte );
292
293extern void giet_tty_gets( char* buf, unsigned int bufsize );
294
295extern void giet_tty_getw( unsigned int* val );
296
297//////////////////////////////////////////////////////////////////////////
298//                TIMER device related system calls
299//////////////////////////////////////////////////////////////////////////
300
301extern void giet_timer_alloc();
302
303extern void giet_timer_start( unsigned int period );
304
305extern void giet_timer_stop();
306 
307//////////////////////////////////////////////////////////////////////////
308//                Frame buffer device related system calls
309//////////////////////////////////////////////////////////////////////////
310
311extern void giet_fbf_size();
312
313extern void giet_fbf_alloc();
314
315extern void giet_fbf_cma_alloc( unsigned int nbufs );
316
317extern void giet_fbf_cma_init_buf( unsigned int index,
318                                   void*        buf_vbase, 
319                                   void*        sts_vaddr );
320
321extern void giet_fbf_cma_start();
322
323extern void giet_fbf_cma_check( unsigned int buffer );
324
325extern void giet_fbf_cma_display( unsigned int buffer );
326
327extern void giet_fbf_cma_stop();
328
329extern void giet_fbf_sync_read( unsigned int offset, 
330                                void*        buffer, 
331                                unsigned int length );
332
333extern void giet_fbf_sync_write( unsigned int offset, 
334                                 void*        buffer, 
335                                 unsigned int length );
336
337//////////////////////////////////////////////////////////////////////////
338//                  NIC related system calls
339//////////////////////////////////////////////////////////////////////////
340
341extern void giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax );
342
343extern void giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax );
344
345extern void giet_nic_rx_start();
346
347extern void giet_nic_tx_start();
348
349extern void giet_nic_rx_move( void* buffer );
350
351extern void giet_nic_tx_move( void* buffer );
352
353extern void giet_nic_rx_stop();
354
355extern void giet_nic_tx_stop();
356
357extern void giet_nic_rx_stats();
358
359extern void giet_nic_tx_stats();
360
361extern void giet_nic_rx_clear();
362
363extern void giet_nic_tx_clear();
364
365//////////////////////////////////////////////////////////////////////////
366//               FAT related system calls
367//////////////////////////////////////////////////////////////////////////
368
369extern int giet_fat_open( char*        pathname,
370                          unsigned int flags );
371
372extern int giet_fat_close( unsigned int fd_id );
373
374extern int giet_fat_file_info( unsigned int     fd_id,
375                               fat_file_info_t* info );
376
377extern int giet_fat_read( unsigned int fd_id,
378                          void*        buffer,
379                          unsigned int count );
380
381extern int giet_fat_pread( unsigned int fd_id,
382                           void*        buffer,
383                           unsigned int count,
384                           unsigned int offset );
385 
386extern int giet_fat_write( unsigned int fd,
387                           void*        buffer,
388                           unsigned int count );
389
390extern int giet_fat_lseek( unsigned int fd,
391                           unsigned int offset,
392                           unsigned int whence );
393
394extern int giet_fat_remove( char*        pathname,
395                            unsigned int should_be_dir );
396
397extern int giet_fat_rename( char*  old_path,
398                            char*  new_path ); 
399
400extern int giet_fat_mkdir( char* pathname );
401
402extern int giet_fat_opendir( char* pathname );
403
404extern int giet_fat_closedir( unsigned int fd_id );
405
406extern int giet_fat_readdir( unsigned int  fd_id,
407                             fat_dirent_t* entry );
408
409extern int giet_fat_fprintf( unsigned int  fd_id,
410                             char*         format, ... );
411
412extern void* giet_fat_mmap( void*         vaddr,
413                            unsigned int  length,
414                            unsigned int  prot,
415                            unsigned int  flags,
416                            unsigned int  fd_id,
417                            unsigned int  offset );
418
419extern int giet_fat_munmap( void*         vaddr,
420                            unsigned int  length );
421
422extern int giet_fat_dump( unsigned int type,
423                          char*        pathname,
424                          unsigned int block_id );
425
426//////////////////////////////////////////////////////////////////////////
427//                    Miscelaneous system calls
428//////////////////////////////////////////////////////////////////////////
429
430extern void giet_procs_number( unsigned int* x_size,
431                               unsigned int* y_size,
432                               unsigned int* nprocs );
433
434extern void giet_vobj_get_vbase( char*         vspace_name, 
435                                 char*         vobj_name, 
436                                 unsigned int* vobj_vaddr);
437
438extern void giet_vobj_get_length( char*         vspace_name, 
439                                  char*         vobj_name, 
440                                  unsigned int* vobj_vaddr);
441
442extern void giet_heap_info( unsigned int* vaddr, 
443                            unsigned int* length,
444                            unsigned int  x,
445                            unsigned int  y );
446
447extern void giet_get_xy( void*          ptr, 
448                         unsigned int*  px,
449                         unsigned int*  py );
450
451#endif
452
453// Local Variables:
454// tab-width: 4
455// c-basic-offset: 4
456// c-file-offsets:((innamespace . 0)(inline-open . 0))
457// indent-tabs-mode: nil
458// End:
459// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
460
Note: See TracBrowser for help on using the repository browser.