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

Last change on this file since 530 was 521, checked in by alain, 9 years ago

Introducing in the stdio.c / stdio.h files the system calls
related to the hardware coprocessors configuration and use.

  • 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
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
[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
77#define SYSCALL_COPROC_REGISTER_GET  0x38
78#define SYSCALL_COPROC_REGISTER_SET  0x39
79#define SYSCALL_COPROC_RELEASE       0x3A
80#define SYSCALL_COPROC_COMPLETED     0x3B
81#define SYSCALL_COPROC_ALLOC         0x3C
82#define SYSCALL_COPROC_CHANNEL_INIT  0x3D
83#define SYSCALL_COPROC_CHANNEL_START 0x3E
84#define SYSCALL_COPROC_CHANNEL_STOP  0x3F
[450]85
[521]86////////////////////////////////////////////////////////////////////////////
[368]87// NULL pointer definition
[521]88////////////////////////////////////////////////////////////////////////////
[368]89
90#define NULL (void *)0
91
[521]92////////////////////////////////////////////////////////////////////////////
[258]93// This generic C function is used to implement all system calls.
94// It writes the system call arguments in the proper registers,
95// and tells GCC what has been modified by system call execution.
[438]96// Returns -1 to signal an error.
[521]97////////////////////////////////////////////////////////////////////////////
[258]98static inline int sys_call( int call_no,
99                            int arg_0, 
100                            int arg_1, 
101                            int arg_2, 
102                            int arg_3 ) 
103{
104    register int reg_no_and_output asm("v0") = call_no;
105    register int reg_a0 asm("a0") = arg_0;
106    register int reg_a1 asm("a1") = arg_1;
107    register int reg_a2 asm("a2") = arg_2;
108    register int reg_a3 asm("a3") = arg_3;
109
110    asm volatile(
111            "syscall"
[345]112            : "+r" (reg_no_and_output), /* input/output argument */
113              "+r" (reg_a0),             
114              "+r" (reg_a1),
115              "+r" (reg_a2),
116              "+r" (reg_a3),
117              "+r" (reg_no_and_output)
118            : /* input arguments */
[258]119            : "memory",
120            /* These persistant registers will be saved on the stack by the
121             * compiler only if they contain relevant data. */
122            "at",
123            "v1",
124            "ra",
125            "t0",
126            "t1",
127            "t2",
128            "t3",
129            "t4",
130            "t5",
131            "t6",
132            "t7",
133            "t8",
134            "t9"
135               );
[345]136    return (volatile int)reg_no_and_output;
[258]137}
138
139//////////////////////////////////////////////////////////////////////////
[295]140//               MIPS32 related system calls
141//////////////////////////////////////////////////////////////////////////
[258]142
[431]143extern void giet_proc_xyp( unsigned int* cluster_x,
144                           unsigned int* cluster_y,
145                           unsigned int* lpid );
[382]146
[438]147extern unsigned int giet_proctime();
148
149extern unsigned int giet_rand();
150
[382]151//////////////////////////////////////////////////////////////////////////
[438]152//                    Task context system calls
[382]153//////////////////////////////////////////////////////////////////////////
154
[438]155extern unsigned int giet_proc_task_id();
[382]156
[438]157extern unsigned int giet_global_task_id(); 
158
159extern unsigned int giet_thread_id(); 
160
[382]161//////////////////////////////////////////////////////////////////////////
[521]162//             Coprocessors related system calls
163//////////////////////////////////////////////////////////////////////////
164
165// this structure is used by the giet_coproc_channel_init()
166// system call to specify the communication channel parameters.
167typedef struct giet_coproc_channel
168{
169    unsigned int  channel_mode;    // MWMR / DMA_IRQ / DMA_NO_IRQ
170    unsigned int  buffer_size;     // memory buffer size
171    unsigned int  buffer_vaddr;    // memory buffer virtual address
172    unsigned int  mwmr_vaddr;      // MWMR descriptor virtual address
173    unsigned int  lock_vaddr;      // lock for MWMR virtual address
174} giet_coproc_channel_t;
175
176extern void giet_coproc_alloc( unsigned int   coproc_type,
177                               unsigned int*  coproc_info,
178                               unsigned int*  cluster_xy );
179
180extern void giet_coproc_release( unsigned int cluster_xy );
181
182extern void giet_coproc_channel_init( unsigned int            cluster_xy,
183                                      unsigned int            channel,
184                                      giet_coproc_channel_t*  desc );
185
186extern void giet_coproc_channel_start( unsigned int    cluster_xy,
187                                       unsigned int    channel );
188
189extern void giet_coproc_channel_stop ( unsigned int    cluster_xy,
190                                       unsigned int    channel );
191
192extern void giet_coproc_completed( unsigned int cluster_xy );
193
194extern void giet_coproc_register_set( unsigned int     cluster_xy,
195                                      unsigned int     reg_index,
196                                      unsigned int     value );
197
198extern void giet_coproc_register_get( unsigned int     cluster_xy,
199                                      unsigned int     reg_index,
200                                      unsigned int*    buffer );
201
202//////////////////////////////////////////////////////////////////////////
[295]203//             TTY device related system calls
204//////////////////////////////////////////////////////////////////////////
[258]205
[438]206extern void giet_tty_alloc();
207
[295]208extern void giet_tty_printf( char* format, ... );
[258]209
[295]210extern void giet_shr_printf( char* format, ... );
[258]211
[295]212extern void giet_tty_getc( char* byte );
[258]213
[295]214extern void giet_tty_gets( char* buf, unsigned int bufsize );
[258]215
[295]216extern void giet_tty_getw( unsigned int* val );
[258]217
[295]218//////////////////////////////////////////////////////////////////////////
219//                TIMER device related system calls
220//////////////////////////////////////////////////////////////////////////
[258]221
[438]222extern void giet_timer_alloc();
[258]223
[438]224extern void giet_timer_start( unsigned int period );
225
[295]226extern void giet_timer_stop();
[258]227 
228//////////////////////////////////////////////////////////////////////////
[295]229//                Frame buffer device related system calls
230//////////////////////////////////////////////////////////////////////////
[258]231
[438]232extern void giet_fbf_cma_alloc();
[258]233
[438]234extern void giet_fbf_cma_start( void*        buf0, 
235                                void*        buf1,
[295]236                                unsigned int length );
[258]237
[438]238extern void giet_fbf_cma_display( unsigned int buffer );
[258]239
[438]240extern void giet_fbf_cma_stop();
[258]241
[438]242extern void giet_fbf_sync_read( unsigned int offset, 
243                                void*        buffer, 
244                                unsigned int length );
[258]245
[438]246extern void giet_fbf_sync_write( unsigned int offset, 
247                                 void*        buffer, 
248                                 unsigned int length );
249
[258]250//////////////////////////////////////////////////////////////////////////
[295]251//                  NIC related system calls
252//////////////////////////////////////////////////////////////////////////
[258]253
[501]254extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax );
[258]255
[501]256extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax );
[258]257
[487]258extern void giet_nic_rx_start( unsigned int channel );
[438]259
[487]260extern void giet_nic_tx_start( unsigned int channel );
[450]261
[461]262extern void giet_nic_rx_move( unsigned int channel, void* buffer );
[450]263
[461]264extern void giet_nic_tx_move( unsigned int channel, void* buffer );
[450]265
[487]266extern void giet_nic_rx_stop( unsigned int channel );
[450]267
[487]268extern void giet_nic_tx_stop( unsigned int channel );
[450]269
[487]270extern void giet_nic_rx_stats( unsigned int channel );
[461]271
[487]272extern void giet_nic_tx_stats( unsigned int channel );
[461]273
[487]274extern void giet_nic_rx_clear( unsigned int channel );
[468]275
[487]276extern void giet_nic_tx_clear( unsigned int channel );
[468]277
[258]278//////////////////////////////////////////////////////////////////////////
[295]279//               FAT related system calls
280//////////////////////////////////////////////////////////////////////////
[258]281
282extern int giet_fat_open(  const char*  pathname,
283                           unsigned int flags );
284
[295]285extern void giet_fat_read(  unsigned int fd,
286                            void*        buffer,
287                            unsigned int count,
288                            unsigned int offset );
[258]289
[295]290extern void giet_fat_write( unsigned int fd,
291                            void*        buffer,
292                            unsigned int count,
293                            unsigned int offset );
[258]294
[295]295extern void giet_fat_lseek( unsigned int fd,
296                            unsigned int offset,
297                            unsigned int whence );
[258]298
[295]299extern void giet_fat_fstat( unsigned int fd );
[260]300
[295]301extern void giet_fat_close( unsigned int fd );
[258]302
303//////////////////////////////////////////////////////////////////////////
[382]304//                    Miscelaneous system calls
305//////////////////////////////////////////////////////////////////////////
[258]306
[382]307extern void giet_exit( char* string );
[258]308
[389]309extern void giet_assert( unsigned int condition, 
310                         char*        string );
[258]311
[389]312extern void giet_context_switch();
313
[501]314extern void giet_procs_number( unsigned int* x_size,
315                               unsigned int* y_size,
316                               unsigned int* nprocs );
[438]317
[295]318extern void giet_vobj_get_vbase( char*         vspace_name, 
319                                 char*         vobj_name, 
320                                 unsigned int* vobj_vaddr);
[258]321
[438]322extern void giet_vobj_get_length( char*         vspace_name, 
323                                  char*         vobj_name, 
324                                  unsigned int* vobj_vaddr);
[295]325
326extern void giet_heap_info( unsigned int* vaddr, 
[368]327                            unsigned int* length,
328                            unsigned int  x,
329                            unsigned int  y );
[295]330
[390]331extern void giet_get_xy( void*          ptr, 
332                         unsigned int*  px,
333                         unsigned int*  py );
334
[258]335#endif
336
337// Local Variables:
338// tab-width: 4
339// c-basic-offset: 4
340// c-file-offsets:((innamespace . 0)(inline-open . 0))
341// indent-tabs-mode: nil
342// End:
343// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
344
Note: See TracBrowser for help on using the repository browser.