| 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 | //                                0x1D | 
|---|
| 49 | //                                0x1E | 
|---|
| 50 | //                                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 | #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 | //                                0x38 | 
|---|
| 78 | //                                0x39 | 
|---|
| 79 | //                                0x3A | 
|---|
| 80 | //                                0x3B | 
|---|
| 81 | //                                0x3C | 
|---|
| 82 | //                                0x3D | 
|---|
| 83 | //                                0x3E | 
|---|
| 84 | //                                0x3F | 
|---|
| 85 |  | 
|---|
| 86 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 87 | // NULL pointer definition | 
|---|
| 88 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 89 |  | 
|---|
| 90 | #define NULL (void *)0 | 
|---|
| 91 |  | 
|---|
| 92 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 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. | 
|---|
| 96 | // Returns -1 to signal an error. | 
|---|
| 97 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 98 | static 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" | 
|---|
| 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 */ | 
|---|
| 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 |                ); | 
|---|
| 136 |     return (volatile int)reg_no_and_output; | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 140 | //               MIPS32 related system calls  | 
|---|
| 141 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 142 |  | 
|---|
| 143 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 144 | extern void giet_proc_xyp( unsigned int* cluster_x, | 
|---|
| 145 |                            unsigned int* cluster_y, | 
|---|
| 146 |                            unsigned int* lpid ); | 
|---|
| 147 |  | 
|---|
| 148 | extern unsigned int giet_proctime(); | 
|---|
| 149 |  | 
|---|
| 150 | extern unsigned int giet_rand(); | 
|---|
| 151 |  | 
|---|
| 152 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 153 | //                    Task context system calls | 
|---|
| 154 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 155 |  | 
|---|
| 156 | extern unsigned int giet_proc_task_id(); | 
|---|
| 157 |  | 
|---|
| 158 | extern unsigned int giet_global_task_id();  | 
|---|
| 159 |  | 
|---|
| 160 | extern unsigned int giet_thread_id();  | 
|---|
| 161 |  | 
|---|
| 162 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 163 | //             TTY device related system calls  | 
|---|
| 164 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 165 |  | 
|---|
| 166 | extern void giet_tty_alloc(); | 
|---|
| 167 |  | 
|---|
| 168 | extern void giet_tty_printf( char* format, ... ); | 
|---|
| 169 |  | 
|---|
| 170 | extern void giet_shr_printf( char* format, ... ); | 
|---|
| 171 |  | 
|---|
| 172 | extern void giet_tty_getc( char* byte ); | 
|---|
| 173 |  | 
|---|
| 174 | extern void giet_tty_gets( char* buf, unsigned int bufsize ); | 
|---|
| 175 |  | 
|---|
| 176 | extern void giet_tty_getw( unsigned int* val ); | 
|---|
| 177 |  | 
|---|
| 178 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 179 | //                TIMER device related system calls  | 
|---|
| 180 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 181 |  | 
|---|
| 182 | extern void giet_timer_alloc(); | 
|---|
| 183 |  | 
|---|
| 184 | extern void giet_timer_start( unsigned int period ); | 
|---|
| 185 |  | 
|---|
| 186 | extern void giet_timer_stop(); | 
|---|
| 187 |   | 
|---|
| 188 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 189 | //                Frame buffer device related system calls  | 
|---|
| 190 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 191 |  | 
|---|
| 192 | extern void giet_fbf_cma_alloc(); | 
|---|
| 193 |  | 
|---|
| 194 | extern void giet_fbf_cma_start( void*        buf0,  | 
|---|
| 195 |                                 void*        buf1, | 
|---|
| 196 |                                 unsigned int length ); | 
|---|
| 197 |  | 
|---|
| 198 | extern void giet_fbf_cma_display( unsigned int buffer ); | 
|---|
| 199 |  | 
|---|
| 200 | extern void giet_fbf_cma_stop(); | 
|---|
| 201 |  | 
|---|
| 202 | extern void giet_fbf_sync_read( unsigned int offset,  | 
|---|
| 203 |                                 void*        buffer,  | 
|---|
| 204 |                                 unsigned int length ); | 
|---|
| 205 |  | 
|---|
| 206 | extern void giet_fbf_sync_write( unsigned int offset,  | 
|---|
| 207 |                                  void*        buffer,  | 
|---|
| 208 |                                  unsigned int length ); | 
|---|
| 209 |  | 
|---|
| 210 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 211 | //                  NIC related system calls  | 
|---|
| 212 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 213 |  | 
|---|
| 214 | extern int giet_nic_rx_alloc(); | 
|---|
| 215 |  | 
|---|
| 216 | extern int giet_nic_tx_alloc(); | 
|---|
| 217 |  | 
|---|
| 218 | extern void giet_nic_rx_start(); | 
|---|
| 219 |  | 
|---|
| 220 | extern void giet_nic_tx_start(); | 
|---|
| 221 |  | 
|---|
| 222 | extern void giet_nic_rx_move( unsigned int channel, void* buffer ); | 
|---|
| 223 |  | 
|---|
| 224 | extern void giet_nic_tx_move( unsigned int channel, void* buffer ); | 
|---|
| 225 |  | 
|---|
| 226 | extern void giet_nic_rx_stop(); | 
|---|
| 227 |  | 
|---|
| 228 | extern void giet_nic_tx_stop(); | 
|---|
| 229 |  | 
|---|
| 230 | extern void giet_nic_rx_stats(); | 
|---|
| 231 |  | 
|---|
| 232 | extern void giet_nic_tx_stats(); | 
|---|
| 233 |  | 
|---|
| 234 | extern void giet_nic_rx_clear(); | 
|---|
| 235 |  | 
|---|
| 236 | extern void giet_nic_tx_clear(); | 
|---|
| 237 |  | 
|---|
| 238 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 239 | //               FAT related system calls  | 
|---|
| 240 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 241 |  | 
|---|
| 242 | extern int giet_fat_open(  const char*  pathname, | 
|---|
| 243 |                            unsigned int flags ); | 
|---|
| 244 |  | 
|---|
| 245 | extern void giet_fat_read(  unsigned int fd, | 
|---|
| 246 |                             void*        buffer, | 
|---|
| 247 |                             unsigned int count, | 
|---|
| 248 |                             unsigned int offset ); | 
|---|
| 249 |  | 
|---|
| 250 | extern void giet_fat_write( unsigned int fd, | 
|---|
| 251 |                             void*        buffer, | 
|---|
| 252 |                             unsigned int count, | 
|---|
| 253 |                             unsigned int offset ); | 
|---|
| 254 |  | 
|---|
| 255 | extern void giet_fat_lseek( unsigned int fd, | 
|---|
| 256 |                             unsigned int offset, | 
|---|
| 257 |                             unsigned int whence ); | 
|---|
| 258 |  | 
|---|
| 259 | extern void giet_fat_fstat( unsigned int fd ); | 
|---|
| 260 |  | 
|---|
| 261 | extern void giet_fat_close( unsigned int fd ); | 
|---|
| 262 |  | 
|---|
| 263 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 264 | //                    Miscelaneous system calls | 
|---|
| 265 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 266 |  | 
|---|
| 267 | extern void giet_exit( char* string ); | 
|---|
| 268 |  | 
|---|
| 269 | extern void giet_assert( unsigned int condition,  | 
|---|
| 270 |                          char*        string ); | 
|---|
| 271 |  | 
|---|
| 272 | extern void giet_context_switch(); | 
|---|
| 273 |  | 
|---|
| 274 | extern void giet_procnumber( unsigned int cluster_xy, | 
|---|
| 275 |                              unsigned int buffer ); | 
|---|
| 276 |  | 
|---|
| 277 | extern void giet_vobj_get_vbase( char*         vspace_name,  | 
|---|
| 278 |                                  char*         vobj_name,  | 
|---|
| 279 |                                  unsigned int* vobj_vaddr); | 
|---|
| 280 |  | 
|---|
| 281 | extern void giet_vobj_get_length( char*         vspace_name,  | 
|---|
| 282 |                                   char*         vobj_name,  | 
|---|
| 283 |                                   unsigned int* vobj_vaddr); | 
|---|
| 284 |  | 
|---|
| 285 | extern void giet_heap_info( unsigned int* vaddr,  | 
|---|
| 286 |                             unsigned int* length, | 
|---|
| 287 |                             unsigned int  x, | 
|---|
| 288 |                             unsigned int  y ); | 
|---|
| 289 |  | 
|---|
| 290 | extern void giet_get_xy( void*          ptr,  | 
|---|
| 291 |                          unsigned int*  px, | 
|---|
| 292 |                          unsigned int*  py ); | 
|---|
| 293 |  | 
|---|
| 294 | #endif | 
|---|
| 295 |  | 
|---|
| 296 | // Local Variables: | 
|---|
| 297 | // tab-width: 4 | 
|---|
| 298 | // c-basic-offset: 4 | 
|---|
| 299 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
| 300 | // indent-tabs-mode: nil | 
|---|
| 301 | // End: | 
|---|
| 302 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
| 303 |  | 
|---|