[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" |
---|
| 16 | |
---|
[258] | 17 | // These define must be synchronised with |
---|
| 18 | // the _syscall_vector defined in file sys_handler.c |
---|
| 19 | |
---|
[521] | 20 | #define SYSCALL_PROC_XYP 0x00 |
---|
| 21 | #define SYSCALL_PROC_TIME 0x01 |
---|
| 22 | #define SYSCALL_TTY_WRITE 0x02 |
---|
| 23 | #define SYSCALL_TTY_READ 0x03 |
---|
| 24 | #define SYSCALL_TTY_ALLOC 0x04 |
---|
[689] | 25 | #define SYSCALL_TASKS_STATUS 0x05 |
---|
| 26 | // 0x06 |
---|
[521] | 27 | #define SYSCALL_HEAP_INFO 0x07 |
---|
| 28 | #define SYSCALL_LOCAL_TASK_ID 0x08 |
---|
| 29 | #define SYSCALL_GLOBAL_TASK_ID 0x09 |
---|
| 30 | #define SYSCALL_FBF_CMA_ALLOC 0x0A |
---|
[614] | 31 | #define SYSCALL_FBF_CMA_INIT_BUF 0x0B |
---|
| 32 | #define SYSCALL_FBF_CMA_START 0x0C |
---|
| 33 | #define SYSCALL_FBF_CMA_DISPLAY 0x0D |
---|
| 34 | #define SYSCALL_FBF_CMA_STOP 0x0E |
---|
| 35 | #define SYSCALL_EXIT 0x0F |
---|
[258] | 36 | |
---|
[614] | 37 | #define SYSCALL_PROCS_NUMBER 0x10 |
---|
| 38 | #define SYSCALL_FBF_SYNC_WRITE 0x11 |
---|
| 39 | #define SYSCALL_FBF_SYNC_READ 0x12 |
---|
| 40 | #define SYSCALL_THREAD_ID 0x13 |
---|
[521] | 41 | #define SYSCALL_TIM_ALLOC 0x14 |
---|
| 42 | #define SYSCALL_TIM_START 0x15 |
---|
| 43 | #define SYSCALL_TIM_STOP 0x16 |
---|
[628] | 44 | #define SYSCALL_KILL_APP 0x17 |
---|
| 45 | #define SYSCALL_EXEC_APP 0x18 |
---|
[521] | 46 | #define SYSCALL_CTX_SWITCH 0x19 |
---|
| 47 | #define SYSCALL_VOBJ_GET_VBASE 0x1A |
---|
| 48 | #define SYSCALL_VOBJ_GET_LENGTH 0x1B |
---|
| 49 | #define SYSCALL_GET_XY 0x1C |
---|
| 50 | // 0x1D |
---|
| 51 | // 0x1E |
---|
| 52 | // 0x1F |
---|
[258] | 53 | |
---|
[521] | 54 | #define SYSCALL_FAT_OPEN 0x20 |
---|
| 55 | #define SYSCALL_FAT_READ 0x21 |
---|
| 56 | #define SYSCALL_FAT_WRITE 0x22 |
---|
| 57 | #define SYSCALL_FAT_LSEEK 0x23 |
---|
[588] | 58 | #define SYSCALL_FAT_FINFO 0x24 |
---|
[521] | 59 | #define SYSCALL_FAT_CLOSE 0x25 |
---|
[588] | 60 | #define SYSCALL_FAT_REMOVE 0x26 |
---|
| 61 | #define SYSCALL_FAT_RENAME 0x27 |
---|
| 62 | #define SYSCALL_FAT_MKDIR 0x28 |
---|
[661] | 63 | #define SYSCALL_FAT_OPENDIR 0x29 |
---|
| 64 | #define SYSCALL_FAT_CLOSEDIR 0x2A |
---|
| 65 | #define SYSCALL_FAT_READDIR 0x2B |
---|
| 66 | // 0x2C |
---|
[521] | 67 | // 0x2D |
---|
| 68 | // 0x2E |
---|
| 69 | // 0x2F |
---|
[258] | 70 | |
---|
[521] | 71 | #define SYSCALL_NIC_ALLOC 0x30 |
---|
| 72 | #define SYSCALL_NIC_START 0x31 |
---|
| 73 | #define SYSCALL_NIC_MOVE 0x32 |
---|
| 74 | #define SYSCALL_NIC_STOP 0x33 |
---|
| 75 | #define SYSCALL_NIC_STATS 0x34 |
---|
| 76 | #define SYSCALL_NIC_CLEAR 0x35 |
---|
| 77 | // 0x36 |
---|
| 78 | // 0x37 |
---|
[558] | 79 | // 0x38 |
---|
| 80 | // 0x39 |
---|
| 81 | // 0x3A |
---|
[521] | 82 | #define SYSCALL_COPROC_COMPLETED 0x3B |
---|
| 83 | #define SYSCALL_COPROC_ALLOC 0x3C |
---|
| 84 | #define SYSCALL_COPROC_CHANNEL_INIT 0x3D |
---|
[558] | 85 | #define SYSCALL_COPROC_RUN 0x3E |
---|
| 86 | #define SYSCALL_COPROC_RELEASE 0x3F |
---|
[450] | 87 | |
---|
[521] | 88 | //////////////////////////////////////////////////////////////////////////// |
---|
[368] | 89 | // NULL pointer definition |
---|
[521] | 90 | //////////////////////////////////////////////////////////////////////////// |
---|
[368] | 91 | |
---|
| 92 | #define NULL (void *)0 |
---|
| 93 | |
---|
[521] | 94 | //////////////////////////////////////////////////////////////////////////// |
---|
[258] | 95 | // This generic C function is used to implement all system calls. |
---|
| 96 | // It writes the system call arguments in the proper registers, |
---|
| 97 | // and tells GCC what has been modified by system call execution. |
---|
[438] | 98 | // Returns -1 to signal an error. |
---|
[521] | 99 | //////////////////////////////////////////////////////////////////////////// |
---|
[258] | 100 | static inline int sys_call( int call_no, |
---|
| 101 | int arg_0, |
---|
| 102 | int arg_1, |
---|
| 103 | int arg_2, |
---|
| 104 | int arg_3 ) |
---|
| 105 | { |
---|
| 106 | register int reg_no_and_output asm("v0") = call_no; |
---|
| 107 | register int reg_a0 asm("a0") = arg_0; |
---|
| 108 | register int reg_a1 asm("a1") = arg_1; |
---|
| 109 | register int reg_a2 asm("a2") = arg_2; |
---|
| 110 | register int reg_a3 asm("a3") = arg_3; |
---|
| 111 | |
---|
| 112 | asm volatile( |
---|
| 113 | "syscall" |
---|
[345] | 114 | : "+r" (reg_no_and_output), /* input/output argument */ |
---|
| 115 | "+r" (reg_a0), |
---|
| 116 | "+r" (reg_a1), |
---|
| 117 | "+r" (reg_a2), |
---|
| 118 | "+r" (reg_a3), |
---|
| 119 | "+r" (reg_no_and_output) |
---|
| 120 | : /* input arguments */ |
---|
[258] | 121 | : "memory", |
---|
| 122 | /* These persistant registers will be saved on the stack by the |
---|
| 123 | * compiler only if they contain relevant data. */ |
---|
| 124 | "at", |
---|
| 125 | "v1", |
---|
| 126 | "ra", |
---|
| 127 | "t0", |
---|
| 128 | "t1", |
---|
| 129 | "t2", |
---|
| 130 | "t3", |
---|
| 131 | "t4", |
---|
| 132 | "t5", |
---|
| 133 | "t6", |
---|
| 134 | "t7", |
---|
| 135 | "t8", |
---|
| 136 | "t9" |
---|
| 137 | ); |
---|
[345] | 138 | return (volatile int)reg_no_and_output; |
---|
[258] | 139 | } |
---|
| 140 | |
---|
| 141 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 142 | // MIPS32 related system calls |
---|
| 143 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 144 | |
---|
[431] | 145 | extern void giet_proc_xyp( unsigned int* cluster_x, |
---|
| 146 | unsigned int* cluster_y, |
---|
| 147 | unsigned int* lpid ); |
---|
[382] | 148 | |
---|
[438] | 149 | extern unsigned int giet_proctime(); |
---|
| 150 | |
---|
| 151 | extern unsigned int giet_rand(); |
---|
| 152 | |
---|
[382] | 153 | ////////////////////////////////////////////////////////////////////////// |
---|
[647] | 154 | // Task related system calls |
---|
[382] | 155 | ////////////////////////////////////////////////////////////////////////// |
---|
| 156 | |
---|
[438] | 157 | extern unsigned int giet_proc_task_id(); |
---|
[382] | 158 | |
---|
[438] | 159 | extern unsigned int giet_global_task_id(); |
---|
| 160 | |
---|
| 161 | extern unsigned int giet_thread_id(); |
---|
| 162 | |
---|
[647] | 163 | extern void giet_exit( char* string ); |
---|
| 164 | |
---|
| 165 | extern void giet_assert( unsigned int condition, |
---|
| 166 | char* string ); |
---|
| 167 | |
---|
| 168 | extern void giet_context_switch(); |
---|
| 169 | |
---|
[689] | 170 | extern void giet_tasks_status(); |
---|
| 171 | |
---|
[382] | 172 | ////////////////////////////////////////////////////////////////////////// |
---|
[647] | 173 | // Application related system calls |
---|
| 174 | ////////////////////////////////////////////////////////////////////////// |
---|
| 175 | |
---|
| 176 | extern int giet_kill_application( char* name ); |
---|
| 177 | |
---|
| 178 | extern int giet_exec_application( char* name ); |
---|
| 179 | |
---|
| 180 | ////////////////////////////////////////////////////////////////////////// |
---|
[521] | 181 | // Coprocessors related system calls |
---|
| 182 | ////////////////////////////////////////////////////////////////////////// |
---|
| 183 | |
---|
| 184 | // this structure is used by the giet_coproc_channel_init() |
---|
| 185 | // system call to specify the communication channel parameters. |
---|
| 186 | typedef struct giet_coproc_channel |
---|
| 187 | { |
---|
| 188 | unsigned int channel_mode; // MWMR / DMA_IRQ / DMA_NO_IRQ |
---|
| 189 | unsigned int buffer_size; // memory buffer size |
---|
| 190 | unsigned int buffer_vaddr; // memory buffer virtual address |
---|
| 191 | unsigned int mwmr_vaddr; // MWMR descriptor virtual address |
---|
| 192 | unsigned int lock_vaddr; // lock for MWMR virtual address |
---|
| 193 | } giet_coproc_channel_t; |
---|
| 194 | |
---|
| 195 | extern void giet_coproc_alloc( unsigned int coproc_type, |
---|
[558] | 196 | unsigned int* coproc_info ); |
---|
[521] | 197 | |
---|
[558] | 198 | extern void giet_coproc_release( unsigned int coproc_reg_index ); |
---|
[521] | 199 | |
---|
[558] | 200 | extern void giet_coproc_channel_init( unsigned int channel, |
---|
[521] | 201 | giet_coproc_channel_t* desc ); |
---|
| 202 | |
---|
[558] | 203 | extern void giet_coproc_run( unsigned int coproc_reg_index ); |
---|
[521] | 204 | |
---|
[558] | 205 | extern void giet_coproc_completed(); |
---|
[521] | 206 | |
---|
| 207 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 208 | // TTY device related system calls |
---|
| 209 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 210 | |
---|
[671] | 211 | extern void giet_tty_alloc( unsigned int shared ); |
---|
[438] | 212 | |
---|
[295] | 213 | extern void giet_tty_printf( char* format, ... ); |
---|
[258] | 214 | |
---|
[295] | 215 | extern void giet_tty_getc( char* byte ); |
---|
[258] | 216 | |
---|
[295] | 217 | extern void giet_tty_gets( char* buf, unsigned int bufsize ); |
---|
[258] | 218 | |
---|
[295] | 219 | extern void giet_tty_getw( unsigned int* val ); |
---|
[258] | 220 | |
---|
[295] | 221 | ////////////////////////////////////////////////////////////////////////// |
---|
| 222 | // TIMER device related system calls |
---|
| 223 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 224 | |
---|
[438] | 225 | extern void giet_timer_alloc(); |
---|
[258] | 226 | |
---|
[438] | 227 | extern void giet_timer_start( unsigned int period ); |
---|
| 228 | |
---|
[295] | 229 | extern void giet_timer_stop(); |
---|
[258] | 230 | |
---|
| 231 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 232 | // Frame buffer device related system calls |
---|
| 233 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 234 | |
---|
[438] | 235 | extern void giet_fbf_cma_alloc(); |
---|
[258] | 236 | |
---|
[614] | 237 | extern void giet_fbf_cma_init_buf( void* buf0_vbase, |
---|
| 238 | void* buf1_vbase, |
---|
| 239 | void* sts0_vaddr, |
---|
| 240 | void* sts1_vaddr ); |
---|
[258] | 241 | |
---|
[614] | 242 | extern void giet_fbf_cma_start( unsigned int length ); |
---|
| 243 | |
---|
[438] | 244 | extern void giet_fbf_cma_display( unsigned int buffer ); |
---|
[258] | 245 | |
---|
[438] | 246 | extern void giet_fbf_cma_stop(); |
---|
[258] | 247 | |
---|
[438] | 248 | extern void giet_fbf_sync_read( unsigned int offset, |
---|
| 249 | void* buffer, |
---|
| 250 | unsigned int length ); |
---|
[258] | 251 | |
---|
[438] | 252 | extern void giet_fbf_sync_write( unsigned int offset, |
---|
| 253 | void* buffer, |
---|
| 254 | unsigned int length ); |
---|
| 255 | |
---|
[258] | 256 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 257 | // NIC related system calls |
---|
| 258 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 259 | |
---|
[501] | 260 | extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 261 | |
---|
[501] | 262 | extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 263 | |
---|
[487] | 264 | extern void giet_nic_rx_start( unsigned int channel ); |
---|
[438] | 265 | |
---|
[487] | 266 | extern void giet_nic_tx_start( unsigned int channel ); |
---|
[450] | 267 | |
---|
[461] | 268 | extern void giet_nic_rx_move( unsigned int channel, void* buffer ); |
---|
[450] | 269 | |
---|
[461] | 270 | extern void giet_nic_tx_move( unsigned int channel, void* buffer ); |
---|
[450] | 271 | |
---|
[487] | 272 | extern void giet_nic_rx_stop( unsigned int channel ); |
---|
[450] | 273 | |
---|
[487] | 274 | extern void giet_nic_tx_stop( unsigned int channel ); |
---|
[450] | 275 | |
---|
[487] | 276 | extern void giet_nic_rx_stats( unsigned int channel ); |
---|
[461] | 277 | |
---|
[487] | 278 | extern void giet_nic_tx_stats( unsigned int channel ); |
---|
[461] | 279 | |
---|
[487] | 280 | extern void giet_nic_rx_clear( unsigned int channel ); |
---|
[468] | 281 | |
---|
[487] | 282 | extern void giet_nic_tx_clear( unsigned int channel ); |
---|
[468] | 283 | |
---|
[258] | 284 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 285 | // FAT related system calls |
---|
| 286 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 287 | |
---|
[588] | 288 | extern int giet_fat_open( char* pathname, |
---|
| 289 | unsigned int flags ); |
---|
[258] | 290 | |
---|
[588] | 291 | extern int giet_fat_close( unsigned int fd_id ); |
---|
[258] | 292 | |
---|
[659] | 293 | extern int giet_fat_file_info( unsigned int fd_id, |
---|
| 294 | fat_file_info_t* info ); |
---|
[258] | 295 | |
---|
[588] | 296 | extern int giet_fat_read( unsigned int fd_id, |
---|
| 297 | void* buffer, |
---|
| 298 | unsigned int count ); |
---|
[258] | 299 | |
---|
[588] | 300 | extern int giet_fat_write( unsigned int fd, |
---|
| 301 | void* buffer, |
---|
| 302 | unsigned int count ); |
---|
[260] | 303 | |
---|
[588] | 304 | extern int giet_fat_lseek( unsigned int fd, |
---|
| 305 | unsigned int offset, |
---|
| 306 | unsigned int whence ); |
---|
[258] | 307 | |
---|
[588] | 308 | extern int giet_fat_remove( char* pathname, |
---|
| 309 | unsigned int should_be_dir ); |
---|
| 310 | |
---|
| 311 | extern int giet_fat_rename( char* old_path, |
---|
| 312 | char* new_path ); |
---|
| 313 | |
---|
| 314 | extern int giet_fat_mkdir( char* pathname ); |
---|
| 315 | |
---|
[659] | 316 | extern int giet_fat_opendir( char* pathname ); |
---|
| 317 | |
---|
| 318 | extern int giet_fat_closedir( unsigned int fd_id ); |
---|
| 319 | |
---|
| 320 | extern int giet_fat_readdir( unsigned int fd_id, |
---|
| 321 | fat_dirent_t* entry ); |
---|
| 322 | |
---|
[258] | 323 | ////////////////////////////////////////////////////////////////////////// |
---|
[382] | 324 | // Miscelaneous system calls |
---|
| 325 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 326 | |
---|
[501] | 327 | extern void giet_procs_number( unsigned int* x_size, |
---|
| 328 | unsigned int* y_size, |
---|
| 329 | unsigned int* nprocs ); |
---|
[438] | 330 | |
---|
[295] | 331 | extern void giet_vobj_get_vbase( char* vspace_name, |
---|
| 332 | char* vobj_name, |
---|
| 333 | unsigned int* vobj_vaddr); |
---|
[258] | 334 | |
---|
[438] | 335 | extern void giet_vobj_get_length( char* vspace_name, |
---|
| 336 | char* vobj_name, |
---|
| 337 | unsigned int* vobj_vaddr); |
---|
[295] | 338 | |
---|
| 339 | extern void giet_heap_info( unsigned int* vaddr, |
---|
[368] | 340 | unsigned int* length, |
---|
| 341 | unsigned int x, |
---|
| 342 | unsigned int y ); |
---|
[295] | 343 | |
---|
[390] | 344 | extern void giet_get_xy( void* ptr, |
---|
| 345 | unsigned int* px, |
---|
| 346 | unsigned int* py ); |
---|
| 347 | |
---|
[258] | 348 | #endif |
---|
| 349 | |
---|
| 350 | // Local Variables: |
---|
| 351 | // tab-width: 4 |
---|
| 352 | // c-basic-offset: 4 |
---|
| 353 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 354 | // indent-tabs-mode: nil |
---|
| 355 | // End: |
---|
| 356 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 357 | |
---|