[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 | |
---|
[663] | 15 | #include "giet_fat32/fat32_shared.h" |
---|
[709] | 16 | #include "giet_common/mips32_registers.h" |
---|
[663] | 17 | |
---|
[258] | 18 | // These define must be synchronised with |
---|
| 19 | // the _syscall_vector defined in file sys_handler.c |
---|
| 20 | |
---|
[521] | 21 | #define SYSCALL_PROC_XYP 0x00 |
---|
| 22 | #define SYSCALL_PROC_TIME 0x01 |
---|
[709] | 23 | #define SYSCALL_PROCS_NUMBER 0x02 |
---|
| 24 | #define SYSCALL_GET_XY 0x03 |
---|
| 25 | // 0x04 |
---|
| 26 | // 0x05 |
---|
[689] | 27 | // 0x06 |
---|
[521] | 28 | #define SYSCALL_HEAP_INFO 0x07 |
---|
[709] | 29 | #define SYSCALL_VOBJ_GET_VBASE 0x08 |
---|
| 30 | #define SYSCALL_VOBJ_GET_LENGTH 0x09 |
---|
[521] | 31 | #define SYSCALL_FBF_CMA_ALLOC 0x0A |
---|
[614] | 32 | #define SYSCALL_FBF_CMA_INIT_BUF 0x0B |
---|
| 33 | #define SYSCALL_FBF_CMA_START 0x0C |
---|
| 34 | #define SYSCALL_FBF_CMA_DISPLAY 0x0D |
---|
| 35 | #define SYSCALL_FBF_CMA_STOP 0x0E |
---|
[709] | 36 | // 0x0F |
---|
[258] | 37 | |
---|
[709] | 38 | #define SYSCALL_APPS_STATUS 0x10 |
---|
[614] | 39 | #define SYSCALL_FBF_SYNC_WRITE 0x11 |
---|
| 40 | #define SYSCALL_FBF_SYNC_READ 0x12 |
---|
[709] | 41 | // 0x13 |
---|
[521] | 42 | #define SYSCALL_TIM_ALLOC 0x14 |
---|
| 43 | #define SYSCALL_TIM_START 0x15 |
---|
| 44 | #define SYSCALL_TIM_STOP 0x16 |
---|
[628] | 45 | #define SYSCALL_KILL_APP 0x17 |
---|
| 46 | #define SYSCALL_EXEC_APP 0x18 |
---|
[709] | 47 | // 0x19 |
---|
| 48 | #define SYSCALL_PTHREAD_CONTROL 0x1A |
---|
| 49 | #define SYSCALL_PTHREAD_YIELD 0x1B |
---|
| 50 | #define SYSCALL_PTHREAD_KILL 0x1C |
---|
| 51 | #define SYSCALL_PTHREAD_CREATE 0x1D |
---|
| 52 | #define SYSCALL_PTHREAD_JOIN 0x1E |
---|
| 53 | #define SYSCALL_PTHREAD_EXIT 0x1F |
---|
[258] | 54 | |
---|
[521] | 55 | #define SYSCALL_FAT_OPEN 0x20 |
---|
| 56 | #define SYSCALL_FAT_READ 0x21 |
---|
| 57 | #define SYSCALL_FAT_WRITE 0x22 |
---|
| 58 | #define SYSCALL_FAT_LSEEK 0x23 |
---|
[588] | 59 | #define SYSCALL_FAT_FINFO 0x24 |
---|
[521] | 60 | #define SYSCALL_FAT_CLOSE 0x25 |
---|
[588] | 61 | #define SYSCALL_FAT_REMOVE 0x26 |
---|
| 62 | #define SYSCALL_FAT_RENAME 0x27 |
---|
| 63 | #define SYSCALL_FAT_MKDIR 0x28 |
---|
[661] | 64 | #define SYSCALL_FAT_OPENDIR 0x29 |
---|
| 65 | #define SYSCALL_FAT_CLOSEDIR 0x2A |
---|
| 66 | #define SYSCALL_FAT_READDIR 0x2B |
---|
| 67 | // 0x2C |
---|
[521] | 68 | // 0x2D |
---|
| 69 | // 0x2E |
---|
| 70 | // 0x2F |
---|
[258] | 71 | |
---|
[521] | 72 | #define SYSCALL_NIC_ALLOC 0x30 |
---|
| 73 | #define SYSCALL_NIC_START 0x31 |
---|
| 74 | #define SYSCALL_NIC_MOVE 0x32 |
---|
| 75 | #define SYSCALL_NIC_STOP 0x33 |
---|
| 76 | #define SYSCALL_NIC_STATS 0x34 |
---|
| 77 | #define SYSCALL_NIC_CLEAR 0x35 |
---|
[709] | 78 | #define SYSCALL_TTY_WRITE 0x36 |
---|
| 79 | #define SYSCALL_TTY_READ 0x37 |
---|
| 80 | #define SYSCALL_TTY_ALLOC 0x38 |
---|
[558] | 81 | // 0x39 |
---|
| 82 | // 0x3A |
---|
[521] | 83 | #define SYSCALL_COPROC_COMPLETED 0x3B |
---|
| 84 | #define SYSCALL_COPROC_ALLOC 0x3C |
---|
| 85 | #define SYSCALL_COPROC_CHANNEL_INIT 0x3D |
---|
[558] | 86 | #define SYSCALL_COPROC_RUN 0x3E |
---|
| 87 | #define SYSCALL_COPROC_RELEASE 0x3F |
---|
[450] | 88 | |
---|
[521] | 89 | //////////////////////////////////////////////////////////////////////////// |
---|
[368] | 90 | // NULL pointer definition |
---|
[521] | 91 | //////////////////////////////////////////////////////////////////////////// |
---|
[368] | 92 | |
---|
| 93 | #define NULL (void *)0 |
---|
| 94 | |
---|
[521] | 95 | //////////////////////////////////////////////////////////////////////////// |
---|
[258] | 96 | // This generic C function is used to implement all system calls. |
---|
| 97 | // It writes the system call arguments in the proper registers, |
---|
| 98 | // and tells GCC what has been modified by system call execution. |
---|
[438] | 99 | // Returns -1 to signal an error. |
---|
[521] | 100 | //////////////////////////////////////////////////////////////////////////// |
---|
[258] | 101 | static inline int sys_call( int call_no, |
---|
| 102 | int arg_0, |
---|
| 103 | int arg_1, |
---|
| 104 | int arg_2, |
---|
| 105 | int arg_3 ) |
---|
| 106 | { |
---|
| 107 | register int reg_no_and_output asm("v0") = call_no; |
---|
| 108 | register int reg_a0 asm("a0") = arg_0; |
---|
| 109 | register int reg_a1 asm("a1") = arg_1; |
---|
| 110 | register int reg_a2 asm("a2") = arg_2; |
---|
| 111 | register int reg_a3 asm("a3") = arg_3; |
---|
| 112 | |
---|
| 113 | asm volatile( |
---|
| 114 | "syscall" |
---|
[345] | 115 | : "+r" (reg_no_and_output), /* input/output argument */ |
---|
| 116 | "+r" (reg_a0), |
---|
| 117 | "+r" (reg_a1), |
---|
| 118 | "+r" (reg_a2), |
---|
| 119 | "+r" (reg_a3), |
---|
| 120 | "+r" (reg_no_and_output) |
---|
| 121 | : /* input arguments */ |
---|
[258] | 122 | : "memory", |
---|
| 123 | /* These persistant registers will be saved on the stack by the |
---|
| 124 | * compiler only if they contain relevant data. */ |
---|
| 125 | "at", |
---|
| 126 | "v1", |
---|
| 127 | "ra", |
---|
| 128 | "t0", |
---|
| 129 | "t1", |
---|
| 130 | "t2", |
---|
| 131 | "t3", |
---|
| 132 | "t4", |
---|
| 133 | "t5", |
---|
| 134 | "t6", |
---|
| 135 | "t7", |
---|
| 136 | "t8", |
---|
| 137 | "t9" |
---|
| 138 | ); |
---|
[345] | 139 | return (volatile int)reg_no_and_output; |
---|
[258] | 140 | } |
---|
| 141 | |
---|
| 142 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 143 | // MIPS32 related system calls |
---|
| 144 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 145 | |
---|
[431] | 146 | extern void giet_proc_xyp( unsigned int* cluster_x, |
---|
| 147 | unsigned int* cluster_y, |
---|
| 148 | unsigned int* lpid ); |
---|
[382] | 149 | |
---|
[438] | 150 | extern unsigned int giet_proctime(); |
---|
| 151 | |
---|
| 152 | extern unsigned int giet_rand(); |
---|
| 153 | |
---|
[382] | 154 | ////////////////////////////////////////////////////////////////////////// |
---|
[709] | 155 | // Threads related system calls |
---|
[382] | 156 | ////////////////////////////////////////////////////////////////////////// |
---|
| 157 | |
---|
[709] | 158 | typedef unsigned int pthread_t; |
---|
[382] | 159 | |
---|
[709] | 160 | typedef unsigned int pthread_attr_t; |
---|
[438] | 161 | |
---|
[709] | 162 | extern int giet_pthread_create( pthread_t* trdid, |
---|
| 163 | pthread_attr_t* attr, |
---|
| 164 | void* function, |
---|
| 165 | void* ptr ); |
---|
[438] | 166 | |
---|
[709] | 167 | extern void giet_pthread_exit( void* string ); |
---|
[647] | 168 | |
---|
[709] | 169 | extern int giet_pthread_join( pthread_t trdid, |
---|
| 170 | void** ptr ); |
---|
[647] | 171 | |
---|
[709] | 172 | extern int giet_pthread_kill( pthread_t thread_id, |
---|
| 173 | int signal ); |
---|
[647] | 174 | |
---|
[709] | 175 | extern void giet_pthread_yield(); |
---|
[689] | 176 | |
---|
[709] | 177 | extern void giet_pthread_assert( unsigned int condition, |
---|
| 178 | char* string ); |
---|
| 179 | |
---|
| 180 | extern int giet_pthread_pause( char* vspace, |
---|
| 181 | char* thread ); |
---|
| 182 | |
---|
| 183 | extern int giet_pthread_resume( char* vspace, |
---|
| 184 | char* thread ); |
---|
| 185 | |
---|
| 186 | extern int giet_pthread_context( char* vspace, |
---|
| 187 | char* thread ); |
---|
| 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 | |
---|
[709] | 197 | extern void giet_applications_status(); |
---|
| 198 | |
---|
[647] | 199 | ////////////////////////////////////////////////////////////////////////// |
---|
[521] | 200 | // Coprocessors related system calls |
---|
| 201 | ////////////////////////////////////////////////////////////////////////// |
---|
| 202 | |
---|
| 203 | // this structure is used by the giet_coproc_channel_init() |
---|
| 204 | // system call to specify the communication channel parameters. |
---|
| 205 | typedef struct giet_coproc_channel |
---|
| 206 | { |
---|
| 207 | unsigned int channel_mode; // MWMR / DMA_IRQ / DMA_NO_IRQ |
---|
| 208 | unsigned int buffer_size; // memory buffer size |
---|
| 209 | unsigned int buffer_vaddr; // memory buffer virtual address |
---|
| 210 | unsigned int mwmr_vaddr; // MWMR descriptor virtual address |
---|
| 211 | unsigned int lock_vaddr; // lock for MWMR virtual address |
---|
| 212 | } giet_coproc_channel_t; |
---|
| 213 | |
---|
| 214 | extern void giet_coproc_alloc( unsigned int coproc_type, |
---|
[558] | 215 | unsigned int* coproc_info ); |
---|
[521] | 216 | |
---|
[558] | 217 | extern void giet_coproc_release( unsigned int coproc_reg_index ); |
---|
[521] | 218 | |
---|
[558] | 219 | extern void giet_coproc_channel_init( unsigned int channel, |
---|
[521] | 220 | giet_coproc_channel_t* desc ); |
---|
| 221 | |
---|
[558] | 222 | extern void giet_coproc_run( unsigned int coproc_reg_index ); |
---|
[521] | 223 | |
---|
[558] | 224 | extern void giet_coproc_completed(); |
---|
[521] | 225 | |
---|
| 226 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 227 | // TTY device related system calls |
---|
| 228 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 229 | |
---|
[671] | 230 | extern void giet_tty_alloc( unsigned int shared ); |
---|
[438] | 231 | |
---|
[295] | 232 | extern void giet_tty_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 | |
---|
[709] | 279 | extern void giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 280 | |
---|
[709] | 281 | extern void giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 282 | |
---|
[709] | 283 | extern void giet_nic_rx_start(); |
---|
[438] | 284 | |
---|
[709] | 285 | extern void giet_nic_tx_start(); |
---|
[450] | 286 | |
---|
[709] | 287 | extern void giet_nic_rx_move( void* buffer ); |
---|
[450] | 288 | |
---|
[709] | 289 | extern void giet_nic_tx_move( void* buffer ); |
---|
[450] | 290 | |
---|
[709] | 291 | extern void giet_nic_rx_stop(); |
---|
[450] | 292 | |
---|
[709] | 293 | extern void giet_nic_tx_stop(); |
---|
[450] | 294 | |
---|
[709] | 295 | extern void giet_nic_rx_stats(); |
---|
[461] | 296 | |
---|
[709] | 297 | extern void giet_nic_tx_stats(); |
---|
[461] | 298 | |
---|
[709] | 299 | extern void giet_nic_rx_clear(); |
---|
[468] | 300 | |
---|
[709] | 301 | extern void giet_nic_tx_clear(); |
---|
[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 | |
---|
[659] | 312 | extern int giet_fat_file_info( unsigned int fd_id, |
---|
| 313 | fat_file_info_t* 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 | |
---|
[659] | 335 | extern int giet_fat_opendir( char* pathname ); |
---|
| 336 | |
---|
| 337 | extern int giet_fat_closedir( unsigned int fd_id ); |
---|
| 338 | |
---|
| 339 | extern int giet_fat_readdir( unsigned int fd_id, |
---|
| 340 | fat_dirent_t* entry ); |
---|
| 341 | |
---|
[258] | 342 | ////////////////////////////////////////////////////////////////////////// |
---|
[382] | 343 | // Miscelaneous system calls |
---|
| 344 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 345 | |
---|
[501] | 346 | extern void giet_procs_number( unsigned int* x_size, |
---|
| 347 | unsigned int* y_size, |
---|
| 348 | unsigned int* nprocs ); |
---|
[438] | 349 | |
---|
[295] | 350 | extern void giet_vobj_get_vbase( char* vspace_name, |
---|
| 351 | char* vobj_name, |
---|
| 352 | unsigned int* vobj_vaddr); |
---|
[258] | 353 | |
---|
[438] | 354 | extern void giet_vobj_get_length( char* vspace_name, |
---|
| 355 | char* vobj_name, |
---|
| 356 | unsigned int* vobj_vaddr); |
---|
[295] | 357 | |
---|
| 358 | extern void giet_heap_info( unsigned int* vaddr, |
---|
[368] | 359 | unsigned int* length, |
---|
| 360 | unsigned int x, |
---|
| 361 | unsigned int y ); |
---|
[295] | 362 | |
---|
[390] | 363 | extern void giet_get_xy( void* ptr, |
---|
| 364 | unsigned int* px, |
---|
| 365 | unsigned int* py ); |
---|
| 366 | |
---|
[258] | 367 | #endif |
---|
| 368 | |
---|
| 369 | // Local Variables: |
---|
| 370 | // tab-width: 4 |
---|
| 371 | // c-basic-offset: 4 |
---|
| 372 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 373 | // indent-tabs-mode: nil |
---|
| 374 | // End: |
---|
| 375 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 376 | |
---|