[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 |
---|
[628] | 42 | #define SYSCALL_KILL_APP 0x17 |
---|
| 43 | #define SYSCALL_EXEC_APP 0x18 |
---|
[521] | 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 |
---|
[659] | 62 | #define SYSCALL_FAT_OPENDIR 0x2A |
---|
| 63 | #define SYSCALL_FAT_CLOSEDIR 0x2B |
---|
| 64 | #define SYSCALL_FAT_READDIR 0x2C |
---|
[521] | 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 | |
---|
[623] | 90 | #ifndef _FAT32_SHARED |
---|
| 91 | #define _FAT32_SHARED |
---|
| 92 | typedef struct fat_file_info_s |
---|
| 93 | { |
---|
| 94 | unsigned int size; |
---|
| 95 | unsigned int offset; |
---|
| 96 | unsigned int is_dir; |
---|
| 97 | } fat_file_info_t; |
---|
| 98 | |
---|
[659] | 99 | typedef struct fat_dirent_s |
---|
| 100 | { |
---|
| 101 | unsigned int cluster; |
---|
| 102 | unsigned int size; |
---|
| 103 | unsigned int is_dir; |
---|
| 104 | char name[36]; |
---|
| 105 | } fat_dirent_t; |
---|
| 106 | |
---|
[588] | 107 | #define SEEK_SET 0 // argument for giet_fat_lseek() |
---|
| 108 | #define SEEK_CUR 1 // argument for giet_fat_lseek |
---|
| 109 | |
---|
[654] | 110 | #define O_RDONLY 0x01 // argument for giet_fat_open() |
---|
| 111 | #define O_TRUNC 0x10 // argument for giet_fat_open() |
---|
[588] | 112 | #define O_CREATE 0x20 // argument for giet_fat_open() |
---|
[623] | 113 | #endif // _FAT32_SHARED |
---|
[588] | 114 | |
---|
| 115 | //////////////////////////////////////////////////////////////////////////// |
---|
[368] | 116 | // NULL pointer definition |
---|
[521] | 117 | //////////////////////////////////////////////////////////////////////////// |
---|
[368] | 118 | |
---|
| 119 | #define NULL (void *)0 |
---|
| 120 | |
---|
[521] | 121 | //////////////////////////////////////////////////////////////////////////// |
---|
[258] | 122 | // This generic C function is used to implement all system calls. |
---|
| 123 | // It writes the system call arguments in the proper registers, |
---|
| 124 | // and tells GCC what has been modified by system call execution. |
---|
[438] | 125 | // Returns -1 to signal an error. |
---|
[521] | 126 | //////////////////////////////////////////////////////////////////////////// |
---|
[258] | 127 | static inline int sys_call( int call_no, |
---|
| 128 | int arg_0, |
---|
| 129 | int arg_1, |
---|
| 130 | int arg_2, |
---|
| 131 | int arg_3 ) |
---|
| 132 | { |
---|
| 133 | register int reg_no_and_output asm("v0") = call_no; |
---|
| 134 | register int reg_a0 asm("a0") = arg_0; |
---|
| 135 | register int reg_a1 asm("a1") = arg_1; |
---|
| 136 | register int reg_a2 asm("a2") = arg_2; |
---|
| 137 | register int reg_a3 asm("a3") = arg_3; |
---|
| 138 | |
---|
| 139 | asm volatile( |
---|
| 140 | "syscall" |
---|
[345] | 141 | : "+r" (reg_no_and_output), /* input/output argument */ |
---|
| 142 | "+r" (reg_a0), |
---|
| 143 | "+r" (reg_a1), |
---|
| 144 | "+r" (reg_a2), |
---|
| 145 | "+r" (reg_a3), |
---|
| 146 | "+r" (reg_no_and_output) |
---|
| 147 | : /* input arguments */ |
---|
[258] | 148 | : "memory", |
---|
| 149 | /* These persistant registers will be saved on the stack by the |
---|
| 150 | * compiler only if they contain relevant data. */ |
---|
| 151 | "at", |
---|
| 152 | "v1", |
---|
| 153 | "ra", |
---|
| 154 | "t0", |
---|
| 155 | "t1", |
---|
| 156 | "t2", |
---|
| 157 | "t3", |
---|
| 158 | "t4", |
---|
| 159 | "t5", |
---|
| 160 | "t6", |
---|
| 161 | "t7", |
---|
| 162 | "t8", |
---|
| 163 | "t9" |
---|
| 164 | ); |
---|
[345] | 165 | return (volatile int)reg_no_and_output; |
---|
[258] | 166 | } |
---|
| 167 | |
---|
| 168 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 169 | // MIPS32 related system calls |
---|
| 170 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 171 | |
---|
[431] | 172 | extern void giet_proc_xyp( unsigned int* cluster_x, |
---|
| 173 | unsigned int* cluster_y, |
---|
| 174 | unsigned int* lpid ); |
---|
[382] | 175 | |
---|
[438] | 176 | extern unsigned int giet_proctime(); |
---|
| 177 | |
---|
| 178 | extern unsigned int giet_rand(); |
---|
| 179 | |
---|
[382] | 180 | ////////////////////////////////////////////////////////////////////////// |
---|
[647] | 181 | // Task related system calls |
---|
[382] | 182 | ////////////////////////////////////////////////////////////////////////// |
---|
| 183 | |
---|
[438] | 184 | extern unsigned int giet_proc_task_id(); |
---|
[382] | 185 | |
---|
[438] | 186 | extern unsigned int giet_global_task_id(); |
---|
| 187 | |
---|
| 188 | extern unsigned int giet_thread_id(); |
---|
| 189 | |
---|
[647] | 190 | extern void giet_exit( char* string ); |
---|
| 191 | |
---|
| 192 | extern void giet_assert( unsigned int condition, |
---|
| 193 | char* string ); |
---|
| 194 | |
---|
| 195 | extern void giet_context_switch(); |
---|
| 196 | |
---|
[382] | 197 | ////////////////////////////////////////////////////////////////////////// |
---|
[647] | 198 | // Application related system calls |
---|
| 199 | ////////////////////////////////////////////////////////////////////////// |
---|
| 200 | |
---|
| 201 | extern int giet_kill_application( char* name ); |
---|
| 202 | |
---|
| 203 | extern int giet_exec_application( char* name ); |
---|
| 204 | |
---|
| 205 | ////////////////////////////////////////////////////////////////////////// |
---|
[521] | 206 | // Coprocessors related system calls |
---|
| 207 | ////////////////////////////////////////////////////////////////////////// |
---|
| 208 | |
---|
| 209 | // this structure is used by the giet_coproc_channel_init() |
---|
| 210 | // system call to specify the communication channel parameters. |
---|
| 211 | typedef struct giet_coproc_channel |
---|
| 212 | { |
---|
| 213 | unsigned int channel_mode; // MWMR / DMA_IRQ / DMA_NO_IRQ |
---|
| 214 | unsigned int buffer_size; // memory buffer size |
---|
| 215 | unsigned int buffer_vaddr; // memory buffer virtual address |
---|
| 216 | unsigned int mwmr_vaddr; // MWMR descriptor virtual address |
---|
| 217 | unsigned int lock_vaddr; // lock for MWMR virtual address |
---|
| 218 | } giet_coproc_channel_t; |
---|
| 219 | |
---|
| 220 | extern void giet_coproc_alloc( unsigned int coproc_type, |
---|
[558] | 221 | unsigned int* coproc_info ); |
---|
[521] | 222 | |
---|
[558] | 223 | extern void giet_coproc_release( unsigned int coproc_reg_index ); |
---|
[521] | 224 | |
---|
[558] | 225 | extern void giet_coproc_channel_init( unsigned int channel, |
---|
[521] | 226 | giet_coproc_channel_t* desc ); |
---|
| 227 | |
---|
[558] | 228 | extern void giet_coproc_run( unsigned int coproc_reg_index ); |
---|
[521] | 229 | |
---|
[558] | 230 | extern void giet_coproc_completed(); |
---|
[521] | 231 | |
---|
| 232 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 233 | // TTY device related system calls |
---|
| 234 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 235 | |
---|
[438] | 236 | extern void giet_tty_alloc(); |
---|
| 237 | |
---|
[295] | 238 | extern void giet_tty_printf( char* format, ... ); |
---|
[258] | 239 | |
---|
[295] | 240 | extern void giet_shr_printf( char* format, ... ); |
---|
[258] | 241 | |
---|
[295] | 242 | extern void giet_tty_getc( char* byte ); |
---|
[258] | 243 | |
---|
[295] | 244 | extern void giet_tty_gets( char* buf, unsigned int bufsize ); |
---|
[258] | 245 | |
---|
[295] | 246 | extern void giet_tty_getw( unsigned int* val ); |
---|
[258] | 247 | |
---|
[295] | 248 | ////////////////////////////////////////////////////////////////////////// |
---|
| 249 | // TIMER device related system calls |
---|
| 250 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 251 | |
---|
[438] | 252 | extern void giet_timer_alloc(); |
---|
[258] | 253 | |
---|
[438] | 254 | extern void giet_timer_start( unsigned int period ); |
---|
| 255 | |
---|
[295] | 256 | extern void giet_timer_stop(); |
---|
[258] | 257 | |
---|
| 258 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 259 | // Frame buffer device related system calls |
---|
| 260 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 261 | |
---|
[438] | 262 | extern void giet_fbf_cma_alloc(); |
---|
[258] | 263 | |
---|
[614] | 264 | extern void giet_fbf_cma_init_buf( void* buf0_vbase, |
---|
| 265 | void* buf1_vbase, |
---|
| 266 | void* sts0_vaddr, |
---|
| 267 | void* sts1_vaddr ); |
---|
[258] | 268 | |
---|
[614] | 269 | extern void giet_fbf_cma_start( unsigned int length ); |
---|
| 270 | |
---|
[438] | 271 | extern void giet_fbf_cma_display( unsigned int buffer ); |
---|
[258] | 272 | |
---|
[438] | 273 | extern void giet_fbf_cma_stop(); |
---|
[258] | 274 | |
---|
[438] | 275 | extern void giet_fbf_sync_read( unsigned int offset, |
---|
| 276 | void* buffer, |
---|
| 277 | unsigned int length ); |
---|
[258] | 278 | |
---|
[438] | 279 | extern void giet_fbf_sync_write( unsigned int offset, |
---|
| 280 | void* buffer, |
---|
| 281 | unsigned int length ); |
---|
| 282 | |
---|
[258] | 283 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 284 | // NIC related system calls |
---|
| 285 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 286 | |
---|
[501] | 287 | extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 288 | |
---|
[501] | 289 | extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 290 | |
---|
[487] | 291 | extern void giet_nic_rx_start( unsigned int channel ); |
---|
[438] | 292 | |
---|
[487] | 293 | extern void giet_nic_tx_start( unsigned int channel ); |
---|
[450] | 294 | |
---|
[461] | 295 | extern void giet_nic_rx_move( unsigned int channel, void* buffer ); |
---|
[450] | 296 | |
---|
[461] | 297 | extern void giet_nic_tx_move( unsigned int channel, void* buffer ); |
---|
[450] | 298 | |
---|
[487] | 299 | extern void giet_nic_rx_stop( unsigned int channel ); |
---|
[450] | 300 | |
---|
[487] | 301 | extern void giet_nic_tx_stop( unsigned int channel ); |
---|
[450] | 302 | |
---|
[487] | 303 | extern void giet_nic_rx_stats( unsigned int channel ); |
---|
[461] | 304 | |
---|
[487] | 305 | extern void giet_nic_tx_stats( unsigned int channel ); |
---|
[461] | 306 | |
---|
[487] | 307 | extern void giet_nic_rx_clear( unsigned int channel ); |
---|
[468] | 308 | |
---|
[487] | 309 | extern void giet_nic_tx_clear( unsigned int channel ); |
---|
[468] | 310 | |
---|
[258] | 311 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 312 | // FAT related system calls |
---|
| 313 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 314 | |
---|
[588] | 315 | extern int giet_fat_open( char* pathname, |
---|
| 316 | unsigned int flags ); |
---|
[258] | 317 | |
---|
[588] | 318 | extern int giet_fat_close( unsigned int fd_id ); |
---|
[258] | 319 | |
---|
[659] | 320 | extern int giet_fat_file_info( unsigned int fd_id, |
---|
| 321 | fat_file_info_t* info ); |
---|
[258] | 322 | |
---|
[588] | 323 | extern int giet_fat_read( unsigned int fd_id, |
---|
| 324 | void* buffer, |
---|
| 325 | unsigned int count ); |
---|
[258] | 326 | |
---|
[588] | 327 | extern int giet_fat_write( unsigned int fd, |
---|
| 328 | void* buffer, |
---|
| 329 | unsigned int count ); |
---|
[260] | 330 | |
---|
[588] | 331 | extern int giet_fat_lseek( unsigned int fd, |
---|
| 332 | unsigned int offset, |
---|
| 333 | unsigned int whence ); |
---|
[258] | 334 | |
---|
[588] | 335 | extern int giet_fat_remove( char* pathname, |
---|
| 336 | unsigned int should_be_dir ); |
---|
| 337 | |
---|
| 338 | extern int giet_fat_rename( char* old_path, |
---|
| 339 | char* new_path ); |
---|
| 340 | |
---|
| 341 | extern int giet_fat_mkdir( char* pathname ); |
---|
| 342 | |
---|
[659] | 343 | extern int giet_fat_opendir( char* pathname ); |
---|
| 344 | |
---|
| 345 | extern int giet_fat_closedir( unsigned int fd_id ); |
---|
| 346 | |
---|
| 347 | extern int giet_fat_readdir( unsigned int fd_id, |
---|
| 348 | fat_dirent_t* entry ); |
---|
| 349 | |
---|
[588] | 350 | extern int giet_fat_list( char* pathname ); |
---|
| 351 | |
---|
[258] | 352 | ////////////////////////////////////////////////////////////////////////// |
---|
[382] | 353 | // Miscelaneous system calls |
---|
| 354 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 355 | |
---|
[501] | 356 | extern void giet_procs_number( unsigned int* x_size, |
---|
| 357 | unsigned int* y_size, |
---|
| 358 | unsigned int* nprocs ); |
---|
[438] | 359 | |
---|
[295] | 360 | extern void giet_vobj_get_vbase( char* vspace_name, |
---|
| 361 | char* vobj_name, |
---|
| 362 | unsigned int* vobj_vaddr); |
---|
[258] | 363 | |
---|
[438] | 364 | extern void giet_vobj_get_length( char* vspace_name, |
---|
| 365 | char* vobj_name, |
---|
| 366 | unsigned int* vobj_vaddr); |
---|
[295] | 367 | |
---|
| 368 | extern void giet_heap_info( unsigned int* vaddr, |
---|
[368] | 369 | unsigned int* length, |
---|
| 370 | unsigned int x, |
---|
| 371 | unsigned int y ); |
---|
[295] | 372 | |
---|
[390] | 373 | extern void giet_get_xy( void* ptr, |
---|
| 374 | unsigned int* px, |
---|
| 375 | unsigned int* py ); |
---|
| 376 | |
---|
[258] | 377 | #endif |
---|
| 378 | |
---|
| 379 | // Local Variables: |
---|
| 380 | // tab-width: 4 |
---|
| 381 | // c-basic-offset: 4 |
---|
| 382 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 383 | // indent-tabs-mode: nil |
---|
| 384 | // End: |
---|
| 385 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 386 | |
---|