| [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 | 
|---|
| [614] | 29 | #define SYSCALL_FBF_CMA_INIT_BUF     0x0B | 
|---|
|  | 30 | #define SYSCALL_FBF_CMA_START        0x0C | 
|---|
|  | 31 | #define SYSCALL_FBF_CMA_DISPLAY      0x0D | 
|---|
|  | 32 | #define SYSCALL_FBF_CMA_STOP         0x0E | 
|---|
|  | 33 | #define SYSCALL_EXIT                 0x0F | 
|---|
| [258] | 34 |  | 
|---|
| [614] | 35 | #define SYSCALL_PROCS_NUMBER         0x10 | 
|---|
|  | 36 | #define SYSCALL_FBF_SYNC_WRITE       0x11 | 
|---|
|  | 37 | #define SYSCALL_FBF_SYNC_READ        0x12 | 
|---|
|  | 38 | #define SYSCALL_THREAD_ID            0x13 | 
|---|
| [521] | 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] | 108 | static 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] | 153 | extern void giet_proc_xyp( unsigned int* cluster_x, | 
|---|
|  | 154 | unsigned int* cluster_y, | 
|---|
|  | 155 | unsigned int* lpid ); | 
|---|
| [382] | 156 |  | 
|---|
| [438] | 157 | extern unsigned int giet_proctime(); | 
|---|
|  | 158 |  | 
|---|
|  | 159 | extern unsigned int giet_rand(); | 
|---|
|  | 160 |  | 
|---|
| [382] | 161 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [438] | 162 | //                    Task context system calls | 
|---|
| [382] | 163 | ////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 164 |  | 
|---|
| [438] | 165 | extern unsigned int giet_proc_task_id(); | 
|---|
| [382] | 166 |  | 
|---|
| [438] | 167 | extern unsigned int giet_global_task_id(); | 
|---|
|  | 168 |  | 
|---|
|  | 169 | extern 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. | 
|---|
|  | 177 | typedef 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 |  | 
|---|
|  | 186 | extern void giet_coproc_alloc( unsigned int   coproc_type, | 
|---|
| [558] | 187 | unsigned int*  coproc_info ); | 
|---|
| [521] | 188 |  | 
|---|
| [558] | 189 | extern void giet_coproc_release( unsigned int coproc_reg_index ); | 
|---|
| [521] | 190 |  | 
|---|
| [558] | 191 | extern void giet_coproc_channel_init( unsigned int            channel, | 
|---|
| [521] | 192 | giet_coproc_channel_t*  desc ); | 
|---|
|  | 193 |  | 
|---|
| [558] | 194 | extern void giet_coproc_run( unsigned int coproc_reg_index ); | 
|---|
| [521] | 195 |  | 
|---|
| [558] | 196 | extern void giet_coproc_completed(); | 
|---|
| [521] | 197 |  | 
|---|
|  | 198 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 199 | //             TTY device related system calls | 
|---|
|  | 200 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 201 |  | 
|---|
| [438] | 202 | extern void giet_tty_alloc(); | 
|---|
|  | 203 |  | 
|---|
| [295] | 204 | extern void giet_tty_printf( char* format, ... ); | 
|---|
| [258] | 205 |  | 
|---|
| [295] | 206 | extern void giet_shr_printf( char* format, ... ); | 
|---|
| [258] | 207 |  | 
|---|
| [295] | 208 | extern void giet_tty_getc( char* byte ); | 
|---|
| [258] | 209 |  | 
|---|
| [295] | 210 | extern void giet_tty_gets( char* buf, unsigned int bufsize ); | 
|---|
| [258] | 211 |  | 
|---|
| [295] | 212 | extern void giet_tty_getw( unsigned int* val ); | 
|---|
| [258] | 213 |  | 
|---|
| [295] | 214 | ////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 215 | //                TIMER device related system calls | 
|---|
|  | 216 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 217 |  | 
|---|
| [438] | 218 | extern void giet_timer_alloc(); | 
|---|
| [258] | 219 |  | 
|---|
| [438] | 220 | extern void giet_timer_start( unsigned int period ); | 
|---|
|  | 221 |  | 
|---|
| [295] | 222 | extern void giet_timer_stop(); | 
|---|
| [258] | 223 |  | 
|---|
|  | 224 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 225 | //                Frame buffer device related system calls | 
|---|
|  | 226 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 227 |  | 
|---|
| [438] | 228 | extern void giet_fbf_cma_alloc(); | 
|---|
| [258] | 229 |  | 
|---|
| [614] | 230 | extern void giet_fbf_cma_init_buf( void* buf0_vbase, | 
|---|
|  | 231 | void* buf1_vbase, | 
|---|
|  | 232 | void* sts0_vaddr, | 
|---|
|  | 233 | void* sts1_vaddr ); | 
|---|
| [258] | 234 |  | 
|---|
| [614] | 235 | extern void giet_fbf_cma_start( unsigned int length ); | 
|---|
|  | 236 |  | 
|---|
| [438] | 237 | extern void giet_fbf_cma_display( unsigned int buffer ); | 
|---|
| [258] | 238 |  | 
|---|
| [438] | 239 | extern void giet_fbf_cma_stop(); | 
|---|
| [258] | 240 |  | 
|---|
| [438] | 241 | extern void giet_fbf_sync_read( unsigned int offset, | 
|---|
|  | 242 | void*        buffer, | 
|---|
|  | 243 | unsigned int length ); | 
|---|
| [258] | 244 |  | 
|---|
| [438] | 245 | extern void giet_fbf_sync_write( unsigned int offset, | 
|---|
|  | 246 | void*        buffer, | 
|---|
|  | 247 | unsigned int length ); | 
|---|
|  | 248 |  | 
|---|
| [258] | 249 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 250 | //                  NIC related system calls | 
|---|
|  | 251 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 252 |  | 
|---|
| [501] | 253 | extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax ); | 
|---|
| [258] | 254 |  | 
|---|
| [501] | 255 | extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax ); | 
|---|
| [258] | 256 |  | 
|---|
| [487] | 257 | extern void giet_nic_rx_start( unsigned int channel ); | 
|---|
| [438] | 258 |  | 
|---|
| [487] | 259 | extern void giet_nic_tx_start( unsigned int channel ); | 
|---|
| [450] | 260 |  | 
|---|
| [461] | 261 | extern void giet_nic_rx_move( unsigned int channel, void* buffer ); | 
|---|
| [450] | 262 |  | 
|---|
| [461] | 263 | extern void giet_nic_tx_move( unsigned int channel, void* buffer ); | 
|---|
| [450] | 264 |  | 
|---|
| [487] | 265 | extern void giet_nic_rx_stop( unsigned int channel ); | 
|---|
| [450] | 266 |  | 
|---|
| [487] | 267 | extern void giet_nic_tx_stop( unsigned int channel ); | 
|---|
| [450] | 268 |  | 
|---|
| [487] | 269 | extern void giet_nic_rx_stats( unsigned int channel ); | 
|---|
| [461] | 270 |  | 
|---|
| [487] | 271 | extern void giet_nic_tx_stats( unsigned int channel ); | 
|---|
| [461] | 272 |  | 
|---|
| [487] | 273 | extern void giet_nic_rx_clear( unsigned int channel ); | 
|---|
| [468] | 274 |  | 
|---|
| [487] | 275 | extern void giet_nic_tx_clear( unsigned int channel ); | 
|---|
| [468] | 276 |  | 
|---|
| [258] | 277 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 278 | //               FAT related system calls | 
|---|
|  | 279 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 280 |  | 
|---|
| [588] | 281 | extern int giet_fat_open( char*        pathname, | 
|---|
|  | 282 | unsigned int flags ); | 
|---|
| [258] | 283 |  | 
|---|
| [588] | 284 | extern int giet_fat_close( unsigned int fd_id ); | 
|---|
| [258] | 285 |  | 
|---|
| [588] | 286 | extern int giet_fat_file_info( unsigned int  fd_id, | 
|---|
|  | 287 | unsigned int* size, | 
|---|
|  | 288 | unsigned int* offset ); | 
|---|
| [258] | 289 |  | 
|---|
| [588] | 290 | extern int giet_fat_read( unsigned int fd_id, | 
|---|
|  | 291 | void*        buffer, | 
|---|
|  | 292 | unsigned int count ); | 
|---|
| [258] | 293 |  | 
|---|
| [588] | 294 | extern int giet_fat_write( unsigned int fd, | 
|---|
|  | 295 | void*        buffer, | 
|---|
|  | 296 | unsigned int count ); | 
|---|
| [260] | 297 |  | 
|---|
| [588] | 298 | extern int giet_fat_lseek( unsigned int fd, | 
|---|
|  | 299 | unsigned int offset, | 
|---|
|  | 300 | unsigned int whence ); | 
|---|
| [258] | 301 |  | 
|---|
| [588] | 302 | extern int giet_fat_remove( char*        pathname, | 
|---|
|  | 303 | unsigned int should_be_dir ); | 
|---|
|  | 304 |  | 
|---|
|  | 305 | extern int giet_fat_rename( char*  old_path, | 
|---|
|  | 306 | char*  new_path ); | 
|---|
|  | 307 |  | 
|---|
|  | 308 | extern int giet_fat_mkdir( char* pathname ); | 
|---|
|  | 309 |  | 
|---|
|  | 310 | extern int giet_fat_list( char* pathname ); | 
|---|
|  | 311 |  | 
|---|
| [258] | 312 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [382] | 313 | //                    Miscelaneous system calls | 
|---|
|  | 314 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 315 |  | 
|---|
| [382] | 316 | extern void giet_exit( char* string ); | 
|---|
| [258] | 317 |  | 
|---|
| [389] | 318 | extern void giet_assert( unsigned int condition, | 
|---|
|  | 319 | char*        string ); | 
|---|
| [258] | 320 |  | 
|---|
| [389] | 321 | extern void giet_context_switch(); | 
|---|
|  | 322 |  | 
|---|
| [501] | 323 | extern void giet_procs_number( unsigned int* x_size, | 
|---|
|  | 324 | unsigned int* y_size, | 
|---|
|  | 325 | unsigned int* nprocs ); | 
|---|
| [438] | 326 |  | 
|---|
| [295] | 327 | extern void giet_vobj_get_vbase( char*         vspace_name, | 
|---|
|  | 328 | char*         vobj_name, | 
|---|
|  | 329 | unsigned int* vobj_vaddr); | 
|---|
| [258] | 330 |  | 
|---|
| [438] | 331 | extern void giet_vobj_get_length( char*         vspace_name, | 
|---|
|  | 332 | char*         vobj_name, | 
|---|
|  | 333 | unsigned int* vobj_vaddr); | 
|---|
| [295] | 334 |  | 
|---|
|  | 335 | extern void giet_heap_info( unsigned int* vaddr, | 
|---|
| [368] | 336 | unsigned int* length, | 
|---|
|  | 337 | unsigned int  x, | 
|---|
|  | 338 | unsigned int  y ); | 
|---|
| [295] | 339 |  | 
|---|
| [390] | 340 | extern void giet_get_xy( void*          ptr, | 
|---|
|  | 341 | unsigned int*  px, | 
|---|
|  | 342 | unsigned int*  py ); | 
|---|
|  | 343 |  | 
|---|
| [258] | 344 | #endif | 
|---|
|  | 345 |  | 
|---|
|  | 346 | // Local Variables: | 
|---|
|  | 347 | // tab-width: 4 | 
|---|
|  | 348 | // c-basic-offset: 4 | 
|---|
|  | 349 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
|  | 350 | // indent-tabs-mode: nil | 
|---|
|  | 351 | // End: | 
|---|
|  | 352 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
|  | 353 |  | 
|---|