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
RevLine 
[258]1//////////////////////////////////////////////////////////////////////////////////
2// File     : stdio.h         
3// Date     : 01/04/2010
4// Author   : alain greiner & Joel Porquet
5// Copyright (c) UPMC-LIP6
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.
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
[438]18#define SYSCALL_PROC_XYP          0x00
19#define SYSCALL_PROC_TIME         0x01
[258]20#define SYSCALL_TTY_WRITE         0x02
21#define SYSCALL_TTY_READ          0x03
[438]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
[258]32#define SYSCALL_EXIT              0x0E
33#define SYSCALL_PROC_NUMBER       0x0F
34
[438]35#define SYSCALL_FBF_SYNC_WRITE    0x10
36#define SYSCALL_FBF_SYNC_READ     0x11
[267]37#define SYSCALL_THREAD_ID         0x12
[438]38//                                0x13
39#define SYSCALL_TIM_ALLOC         0x14
40#define SYSCALL_TIM_START         0x15
41#define SYSCALL_TIM_STOP          0x16
42//                                0x17
43//                                0x18
[258]44#define SYSCALL_CTX_SWITCH        0x19
45#define SYSCALL_VOBJ_GET_VBASE    0x1A
[438]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
[258]51
52#define SYSCALL_FAT_OPEN          0x20
53#define SYSCALL_FAT_READ          0x21
[259]54#define SYSCALL_FAT_WRITE         0x22
55#define SYSCALL_FAT_LSEEK         0x23
[260]56#define SYSCALL_FAT_FSTAT         0x24
57#define SYSCALL_FAT_CLOSE         0x25
[438]58//                                0x26
59//                                0x27
60//                                0x28
61//                                0x29
62//                                0x2A
63//                                0x2B
64//                                0x2C
65//                                0x2D
66//                                0x2E
67//                                0x2F
[258]68
69//////////////////////////////////////////////////////////////////////////////////
[368]70// NULL pointer definition
71//////////////////////////////////////////////////////////////////////////////////
72
73#define NULL (void *)0
74
75//////////////////////////////////////////////////////////////////////////////////
[258]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.
[438]79// Returns -1 to signal an error.
[258]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"
[345]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 */
[258]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               );
[345]119    return (volatile int)reg_no_and_output;
[258]120}
121
122//////////////////////////////////////////////////////////////////////////
[295]123//               MIPS32 related system calls
124//////////////////////////////////////////////////////////////////////////
[258]125
[295]126//////////////////////////////////////////////////////////////////////////
[431]127extern void giet_proc_xyp( unsigned int* cluster_x,
128                           unsigned int* cluster_y,
129                           unsigned int* lpid );
[382]130
[438]131extern unsigned int giet_proctime();
132
133extern unsigned int giet_rand();
134
[382]135//////////////////////////////////////////////////////////////////////////
[438]136//                    Task context system calls
[382]137//////////////////////////////////////////////////////////////////////////
138
[438]139extern unsigned int giet_proc_task_id();
[382]140
[438]141extern unsigned int giet_global_task_id(); 
142
143extern unsigned int giet_thread_id(); 
144
[382]145//////////////////////////////////////////////////////////////////////////
[295]146//             TTY device related system calls
147//////////////////////////////////////////////////////////////////////////
[258]148
[438]149extern void giet_tty_alloc();
150
[295]151extern void giet_tty_printf( char* format, ... );
[258]152
[295]153extern void giet_shr_printf( char* format, ... );
[258]154
[295]155extern void giet_tty_getc( char* byte );
[258]156
[295]157extern void giet_tty_gets( char* buf, unsigned int bufsize );
[258]158
[295]159extern void giet_tty_getw( unsigned int* val );
[258]160
[295]161//////////////////////////////////////////////////////////////////////////
162//                TIMER device related system calls
163//////////////////////////////////////////////////////////////////////////
[258]164
[438]165extern void giet_timer_alloc();
[258]166
[438]167extern void giet_timer_start( unsigned int period );
168
[295]169extern void giet_timer_stop();
[258]170 
171//////////////////////////////////////////////////////////////////////////
[295]172//                Frame buffer device related system calls
173//////////////////////////////////////////////////////////////////////////
[258]174
[438]175extern void giet_fbf_cma_alloc();
[258]176
[438]177extern void giet_fbf_cma_start( void*        buf0, 
178                                void*        buf1,
[295]179                                unsigned int length );
[258]180
[438]181extern void giet_fbf_cma_display( unsigned int buffer );
[258]182
[438]183extern void giet_fbf_cma_stop();
[258]184
[438]185extern void giet_fbf_sync_read( unsigned int offset, 
186                                void*        buffer, 
187                                unsigned int length );
[258]188
[438]189extern void giet_fbf_sync_write( unsigned int offset, 
190                                 void*        buffer, 
191                                 unsigned int length );
192
[258]193//////////////////////////////////////////////////////////////////////////
[295]194//                  NIC related system calls
195//////////////////////////////////////////////////////////////////////////
[258]196
[438]197extern void giet_nic_alloc();
[258]198
[438]199extern void giet_nic_sync_send( void* buffer);
[258]200
[438]201extern void giet_nic_sync_receive( void* buffer );
202
[258]203//////////////////////////////////////////////////////////////////////////
[295]204//               FAT related system calls
205//////////////////////////////////////////////////////////////////////////
[258]206
207extern int giet_fat_open(  const char*  pathname,
208                           unsigned int flags );
209
[295]210extern void giet_fat_read(  unsigned int fd,
211                            void*        buffer,
212                            unsigned int count,
213                            unsigned int offset );
[258]214
[295]215extern void giet_fat_write( unsigned int fd,
216                            void*        buffer,
217                            unsigned int count,
218                            unsigned int offset );
[258]219
[295]220extern void giet_fat_lseek( unsigned int fd,
221                            unsigned int offset,
222                            unsigned int whence );
[258]223
[295]224extern void giet_fat_fstat( unsigned int fd );
[260]225
[295]226extern void giet_fat_close( unsigned int fd );
[258]227
228//////////////////////////////////////////////////////////////////////////
[382]229//                    Miscelaneous system calls
230//////////////////////////////////////////////////////////////////////////
[258]231
[382]232extern void giet_exit( char* string );
[258]233
[389]234extern void giet_assert( unsigned int condition, 
235                         char*        string );
[258]236
[389]237extern void giet_context_switch();
238
[438]239extern void giet_procnumber( unsigned int cluster_xy,
240                             unsigned int buffer );
241
[295]242extern void giet_vobj_get_vbase( char*         vspace_name, 
243                                 char*         vobj_name, 
244                                 unsigned int* vobj_vaddr);
[258]245
[438]246extern void giet_vobj_get_length( char*         vspace_name, 
247                                  char*         vobj_name, 
248                                  unsigned int* vobj_vaddr);
[295]249
250extern void giet_heap_info( unsigned int* vaddr, 
[368]251                            unsigned int* length,
252                            unsigned int  x,
253                            unsigned int  y );
[295]254
[390]255extern void giet_get_xy( void*          ptr, 
256                         unsigned int*  px,
257                         unsigned int*  py );
258
[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.