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