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