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

Last change on this file since 600 was 588, checked in by alain, 9 years ago

1) Fix a bug in the free() function in the malloc.c
2) Introduce new syscalls to access the FAT in stdio.c

  • Property svn:executable set to *
File size: 12.5 KB
RevLine 
[521]1/////////////////////////////////////////////////////////////////////////////
[258]2// File     : stdio.h         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
[521]6/////////////////////////////////////////////////////////////////////////////
[390]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.
[521]10/////////////////////////////////////////////////////////////////////////////
[258]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
[521]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_PROCS_NUMBER         0x0F
[258]34
[521]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//                                   0x1D
49//                                   0x1E
50//                                   0x1F
[258]51
[521]52#define SYSCALL_FAT_OPEN             0x20
53#define SYSCALL_FAT_READ             0x21
54#define SYSCALL_FAT_WRITE            0x22
55#define SYSCALL_FAT_LSEEK            0x23
[588]56#define SYSCALL_FAT_FINFO            0x24
[521]57#define SYSCALL_FAT_CLOSE            0x25
[588]58#define SYSCALL_FAT_REMOVE           0x26
59#define SYSCALL_FAT_RENAME           0x27
60#define SYSCALL_FAT_MKDIR            0x28
61#define SYSCALL_FAT_LIST             0x29
[521]62//                                   0x2A
63//                                   0x2B
64//                                   0x2C
65//                                   0x2D
66//                                   0x2E
67//                                   0x2F
[258]68
[521]69#define SYSCALL_NIC_ALLOC            0x30
70#define SYSCALL_NIC_START            0x31
71#define SYSCALL_NIC_MOVE             0x32
72#define SYSCALL_NIC_STOP             0x33
73#define SYSCALL_NIC_STATS            0x34
74#define SYSCALL_NIC_CLEAR            0x35
75//                                   0x36
76//                                   0x37
[558]77//                                   0x38
78//                                   0x39
79//                                   0x3A
[521]80#define SYSCALL_COPROC_COMPLETED     0x3B
81#define SYSCALL_COPROC_ALLOC         0x3C
82#define SYSCALL_COPROC_CHANNEL_INIT  0x3D
[558]83#define SYSCALL_COPROC_RUN           0x3E
84#define SYSCALL_COPROC_RELEASE       0x3F
[450]85
[521]86////////////////////////////////////////////////////////////////////////////
[588]87// These define must be synchronised vith values defined in fat32.h
88////////////////////////////////////////////////////////////////////////////
89
90#define SEEK_SET            0          // argument for giet_fat_lseek()
91#define SEEK_CUR            1          // argument for giet_fat_lseek
92
93#define O_CREATE            0x20       // argument for giet_fat_open()
94#define O_RDONLY            0x01       // argument for giet_fat_open()
95
96////////////////////////////////////////////////////////////////////////////
[368]97// NULL pointer definition
[521]98////////////////////////////////////////////////////////////////////////////
[368]99
100#define NULL (void *)0
101
[521]102////////////////////////////////////////////////////////////////////////////
[258]103// This generic C function is used to implement all system calls.
104// It writes the system call arguments in the proper registers,
105// and tells GCC what has been modified by system call execution.
[438]106// Returns -1 to signal an error.
[521]107////////////////////////////////////////////////////////////////////////////
[258]108static inline int sys_call( int call_no,
109                            int arg_0, 
110                            int arg_1, 
111                            int arg_2, 
112                            int arg_3 ) 
113{
114    register int reg_no_and_output asm("v0") = call_no;
115    register int reg_a0 asm("a0") = arg_0;
116    register int reg_a1 asm("a1") = arg_1;
117    register int reg_a2 asm("a2") = arg_2;
118    register int reg_a3 asm("a3") = arg_3;
119
120    asm volatile(
121            "syscall"
[345]122            : "+r" (reg_no_and_output), /* input/output argument */
123              "+r" (reg_a0),             
124              "+r" (reg_a1),
125              "+r" (reg_a2),
126              "+r" (reg_a3),
127              "+r" (reg_no_and_output)
128            : /* input arguments */
[258]129            : "memory",
130            /* These persistant registers will be saved on the stack by the
131             * compiler only if they contain relevant data. */
132            "at",
133            "v1",
134            "ra",
135            "t0",
136            "t1",
137            "t2",
138            "t3",
139            "t4",
140            "t5",
141            "t6",
142            "t7",
143            "t8",
144            "t9"
145               );
[345]146    return (volatile int)reg_no_and_output;
[258]147}
148
149//////////////////////////////////////////////////////////////////////////
[295]150//               MIPS32 related system calls
151//////////////////////////////////////////////////////////////////////////
[258]152
[431]153extern void giet_proc_xyp( unsigned int* cluster_x,
154                           unsigned int* cluster_y,
155                           unsigned int* lpid );
[382]156
[438]157extern unsigned int giet_proctime();
158
159extern unsigned int giet_rand();
160
[382]161//////////////////////////////////////////////////////////////////////////
[438]162//                    Task context system calls
[382]163//////////////////////////////////////////////////////////////////////////
164
[438]165extern unsigned int giet_proc_task_id();
[382]166
[438]167extern unsigned int giet_global_task_id(); 
168
169extern unsigned int giet_thread_id(); 
170
[382]171//////////////////////////////////////////////////////////////////////////
[521]172//             Coprocessors related system calls
173//////////////////////////////////////////////////////////////////////////
174
175// this structure is used by the giet_coproc_channel_init()
176// system call to specify the communication channel parameters.
177typedef struct giet_coproc_channel
178{
179    unsigned int  channel_mode;    // MWMR / DMA_IRQ / DMA_NO_IRQ
180    unsigned int  buffer_size;     // memory buffer size
181    unsigned int  buffer_vaddr;    // memory buffer virtual address
182    unsigned int  mwmr_vaddr;      // MWMR descriptor virtual address
183    unsigned int  lock_vaddr;      // lock for MWMR virtual address
184} giet_coproc_channel_t;
185
186extern void giet_coproc_alloc( unsigned int   coproc_type,
[558]187                               unsigned int*  coproc_info );
[521]188
[558]189extern void giet_coproc_release( unsigned int coproc_reg_index );
[521]190
[558]191extern void giet_coproc_channel_init( unsigned int            channel,
[521]192                                      giet_coproc_channel_t*  desc );
193
[558]194extern void giet_coproc_run( unsigned int coproc_reg_index );
[521]195
[558]196extern void giet_coproc_completed();
[521]197
198//////////////////////////////////////////////////////////////////////////
[295]199//             TTY device related system calls
200//////////////////////////////////////////////////////////////////////////
[258]201
[438]202extern void giet_tty_alloc();
203
[295]204extern void giet_tty_printf( char* format, ... );
[258]205
[295]206extern void giet_shr_printf( char* format, ... );
[258]207
[295]208extern void giet_tty_getc( char* byte );
[258]209
[295]210extern void giet_tty_gets( char* buf, unsigned int bufsize );
[258]211
[295]212extern void giet_tty_getw( unsigned int* val );
[258]213
[295]214//////////////////////////////////////////////////////////////////////////
215//                TIMER device related system calls
216//////////////////////////////////////////////////////////////////////////
[258]217
[438]218extern void giet_timer_alloc();
[258]219
[438]220extern void giet_timer_start( unsigned int period );
221
[295]222extern void giet_timer_stop();
[258]223 
224//////////////////////////////////////////////////////////////////////////
[295]225//                Frame buffer device related system calls
226//////////////////////////////////////////////////////////////////////////
[258]227
[438]228extern void giet_fbf_cma_alloc();
[258]229
[438]230extern void giet_fbf_cma_start( void*        buf0, 
231                                void*        buf1,
[295]232                                unsigned int length );
[258]233
[438]234extern void giet_fbf_cma_display( unsigned int buffer );
[258]235
[438]236extern void giet_fbf_cma_stop();
[258]237
[438]238extern void giet_fbf_sync_read( unsigned int offset, 
239                                void*        buffer, 
240                                unsigned int length );
[258]241
[438]242extern void giet_fbf_sync_write( unsigned int offset, 
243                                 void*        buffer, 
244                                 unsigned int length );
245
[258]246//////////////////////////////////////////////////////////////////////////
[295]247//                  NIC related system calls
248//////////////////////////////////////////////////////////////////////////
[258]249
[501]250extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax );
[258]251
[501]252extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax );
[258]253
[487]254extern void giet_nic_rx_start( unsigned int channel );
[438]255
[487]256extern void giet_nic_tx_start( unsigned int channel );
[450]257
[461]258extern void giet_nic_rx_move( unsigned int channel, void* buffer );
[450]259
[461]260extern void giet_nic_tx_move( unsigned int channel, void* buffer );
[450]261
[487]262extern void giet_nic_rx_stop( unsigned int channel );
[450]263
[487]264extern void giet_nic_tx_stop( unsigned int channel );
[450]265
[487]266extern void giet_nic_rx_stats( unsigned int channel );
[461]267
[487]268extern void giet_nic_tx_stats( unsigned int channel );
[461]269
[487]270extern void giet_nic_rx_clear( unsigned int channel );
[468]271
[487]272extern void giet_nic_tx_clear( unsigned int channel );
[468]273
[258]274//////////////////////////////////////////////////////////////////////////
[295]275//               FAT related system calls
276//////////////////////////////////////////////////////////////////////////
[258]277
[588]278extern int giet_fat_open( char*        pathname,
279                          unsigned int flags );
[258]280
[588]281extern int giet_fat_close( unsigned int fd_id );
[258]282
[588]283extern int giet_fat_file_info( unsigned int  fd_id,
284                               unsigned int* size,
285                               unsigned int* offset );
[258]286
[588]287extern int giet_fat_read( unsigned int fd_id,
288                          void*        buffer,
289                          unsigned int count );
[258]290
[588]291extern int giet_fat_write( unsigned int fd,
292                           void*        buffer,
293                           unsigned int count );
[260]294
[588]295extern int giet_fat_lseek( unsigned int fd,
296                           unsigned int offset,
297                           unsigned int whence );
[258]298
[588]299extern int giet_fat_remove( char*        pathname,
300                            unsigned int should_be_dir );
301
302extern int giet_fat_rename( char*  old_path,
303                            char*  new_path ); 
304
305extern int giet_fat_mkdir( char* pathname );
306
307extern int giet_fat_list( char* pathname );
308
[258]309//////////////////////////////////////////////////////////////////////////
[382]310//                    Miscelaneous system calls
311//////////////////////////////////////////////////////////////////////////
[258]312
[382]313extern void giet_exit( char* string );
[258]314
[389]315extern void giet_assert( unsigned int condition, 
316                         char*        string );
[258]317
[389]318extern void giet_context_switch();
319
[501]320extern void giet_procs_number( unsigned int* x_size,
321                               unsigned int* y_size,
322                               unsigned int* nprocs );
[438]323
[295]324extern void giet_vobj_get_vbase( char*         vspace_name, 
325                                 char*         vobj_name, 
326                                 unsigned int* vobj_vaddr);
[258]327
[438]328extern void giet_vobj_get_length( char*         vspace_name, 
329                                  char*         vobj_name, 
330                                  unsigned int* vobj_vaddr);
[295]331
332extern void giet_heap_info( unsigned int* vaddr, 
[368]333                            unsigned int* length,
334                            unsigned int  x,
335                            unsigned int  y );
[295]336
[390]337extern void giet_get_xy( void*          ptr, 
338                         unsigned int*  px,
339                         unsigned int*  py );
340
[258]341#endif
342
343// Local Variables:
344// tab-width: 4
345// c-basic-offset: 4
346// c-file-offsets:((innamespace . 0)(inline-open . 0))
347// indent-tabs-mode: nil
348// End:
349// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
350
Note: See TracBrowser for help on using the repository browser.