[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 |
---|
| 25 | #define SYSCALL_TTY_GET_LOCK 0x05 |
---|
| 26 | #define SYSCALL_TTY_RELEASE_LOCK 0x06 |
---|
| 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 | |
---|
[382] | 170 | ////////////////////////////////////////////////////////////////////////// |
---|
[647] | 171 | // Application related system calls |
---|
| 172 | ////////////////////////////////////////////////////////////////////////// |
---|
| 173 | |
---|
| 174 | extern int giet_kill_application( char* name ); |
---|
| 175 | |
---|
| 176 | extern int giet_exec_application( char* name ); |
---|
| 177 | |
---|
| 178 | ////////////////////////////////////////////////////////////////////////// |
---|
[521] | 179 | // Coprocessors related system calls |
---|
| 180 | ////////////////////////////////////////////////////////////////////////// |
---|
| 181 | |
---|
| 182 | // this structure is used by the giet_coproc_channel_init() |
---|
| 183 | // system call to specify the communication channel parameters. |
---|
| 184 | typedef struct giet_coproc_channel |
---|
| 185 | { |
---|
| 186 | unsigned int channel_mode; // MWMR / DMA_IRQ / DMA_NO_IRQ |
---|
| 187 | unsigned int buffer_size; // memory buffer size |
---|
| 188 | unsigned int buffer_vaddr; // memory buffer virtual address |
---|
| 189 | unsigned int mwmr_vaddr; // MWMR descriptor virtual address |
---|
| 190 | unsigned int lock_vaddr; // lock for MWMR virtual address |
---|
| 191 | } giet_coproc_channel_t; |
---|
| 192 | |
---|
| 193 | extern void giet_coproc_alloc( unsigned int coproc_type, |
---|
[558] | 194 | unsigned int* coproc_info ); |
---|
[521] | 195 | |
---|
[558] | 196 | extern void giet_coproc_release( unsigned int coproc_reg_index ); |
---|
[521] | 197 | |
---|
[558] | 198 | extern void giet_coproc_channel_init( unsigned int channel, |
---|
[521] | 199 | giet_coproc_channel_t* desc ); |
---|
| 200 | |
---|
[558] | 201 | extern void giet_coproc_run( unsigned int coproc_reg_index ); |
---|
[521] | 202 | |
---|
[558] | 203 | extern void giet_coproc_completed(); |
---|
[521] | 204 | |
---|
| 205 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 206 | // TTY device related system calls |
---|
| 207 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 208 | |
---|
[671] | 209 | extern void giet_tty_alloc( unsigned int shared ); |
---|
[438] | 210 | |
---|
[295] | 211 | extern void giet_tty_printf( char* format, ... ); |
---|
[258] | 212 | |
---|
[295] | 213 | extern void giet_tty_getc( char* byte ); |
---|
[258] | 214 | |
---|
[295] | 215 | extern void giet_tty_gets( char* buf, unsigned int bufsize ); |
---|
[258] | 216 | |
---|
[295] | 217 | extern void giet_tty_getw( unsigned int* val ); |
---|
[258] | 218 | |
---|
[295] | 219 | ////////////////////////////////////////////////////////////////////////// |
---|
| 220 | // TIMER device related system calls |
---|
| 221 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 222 | |
---|
[438] | 223 | extern void giet_timer_alloc(); |
---|
[258] | 224 | |
---|
[438] | 225 | extern void giet_timer_start( unsigned int period ); |
---|
| 226 | |
---|
[295] | 227 | extern void giet_timer_stop(); |
---|
[258] | 228 | |
---|
| 229 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 230 | // Frame buffer device related system calls |
---|
| 231 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 232 | |
---|
[438] | 233 | extern void giet_fbf_cma_alloc(); |
---|
[258] | 234 | |
---|
[614] | 235 | extern void giet_fbf_cma_init_buf( void* buf0_vbase, |
---|
| 236 | void* buf1_vbase, |
---|
| 237 | void* sts0_vaddr, |
---|
| 238 | void* sts1_vaddr ); |
---|
[258] | 239 | |
---|
[614] | 240 | extern void giet_fbf_cma_start( unsigned int length ); |
---|
| 241 | |
---|
[438] | 242 | extern void giet_fbf_cma_display( unsigned int buffer ); |
---|
[258] | 243 | |
---|
[438] | 244 | extern void giet_fbf_cma_stop(); |
---|
[258] | 245 | |
---|
[438] | 246 | extern void giet_fbf_sync_read( unsigned int offset, |
---|
| 247 | void* buffer, |
---|
| 248 | unsigned int length ); |
---|
[258] | 249 | |
---|
[438] | 250 | extern void giet_fbf_sync_write( unsigned int offset, |
---|
| 251 | void* buffer, |
---|
| 252 | unsigned int length ); |
---|
| 253 | |
---|
[258] | 254 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 255 | // NIC related system calls |
---|
| 256 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 257 | |
---|
[501] | 258 | extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 259 | |
---|
[501] | 260 | extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax ); |
---|
[258] | 261 | |
---|
[487] | 262 | extern void giet_nic_rx_start( unsigned int channel ); |
---|
[438] | 263 | |
---|
[487] | 264 | extern void giet_nic_tx_start( unsigned int channel ); |
---|
[450] | 265 | |
---|
[461] | 266 | extern void giet_nic_rx_move( unsigned int channel, void* buffer ); |
---|
[450] | 267 | |
---|
[461] | 268 | extern void giet_nic_tx_move( unsigned int channel, void* buffer ); |
---|
[450] | 269 | |
---|
[487] | 270 | extern void giet_nic_rx_stop( unsigned int channel ); |
---|
[450] | 271 | |
---|
[487] | 272 | extern void giet_nic_tx_stop( unsigned int channel ); |
---|
[450] | 273 | |
---|
[487] | 274 | extern void giet_nic_rx_stats( unsigned int channel ); |
---|
[461] | 275 | |
---|
[487] | 276 | extern void giet_nic_tx_stats( unsigned int channel ); |
---|
[461] | 277 | |
---|
[487] | 278 | extern void giet_nic_rx_clear( unsigned int channel ); |
---|
[468] | 279 | |
---|
[487] | 280 | extern void giet_nic_tx_clear( unsigned int channel ); |
---|
[468] | 281 | |
---|
[258] | 282 | ////////////////////////////////////////////////////////////////////////// |
---|
[295] | 283 | // FAT related system calls |
---|
| 284 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 285 | |
---|
[588] | 286 | extern int giet_fat_open( char* pathname, |
---|
| 287 | unsigned int flags ); |
---|
[258] | 288 | |
---|
[588] | 289 | extern int giet_fat_close( unsigned int fd_id ); |
---|
[258] | 290 | |
---|
[659] | 291 | extern int giet_fat_file_info( unsigned int fd_id, |
---|
| 292 | fat_file_info_t* info ); |
---|
[258] | 293 | |
---|
[588] | 294 | extern int giet_fat_read( unsigned int fd_id, |
---|
| 295 | void* buffer, |
---|
| 296 | unsigned int count ); |
---|
[258] | 297 | |
---|
[588] | 298 | extern int giet_fat_write( unsigned int fd, |
---|
| 299 | void* buffer, |
---|
| 300 | unsigned int count ); |
---|
[260] | 301 | |
---|
[588] | 302 | extern int giet_fat_lseek( unsigned int fd, |
---|
| 303 | unsigned int offset, |
---|
| 304 | unsigned int whence ); |
---|
[258] | 305 | |
---|
[588] | 306 | extern int giet_fat_remove( char* pathname, |
---|
| 307 | unsigned int should_be_dir ); |
---|
| 308 | |
---|
| 309 | extern int giet_fat_rename( char* old_path, |
---|
| 310 | char* new_path ); |
---|
| 311 | |
---|
| 312 | extern int giet_fat_mkdir( char* pathname ); |
---|
| 313 | |
---|
[659] | 314 | extern int giet_fat_opendir( char* pathname ); |
---|
| 315 | |
---|
| 316 | extern int giet_fat_closedir( unsigned int fd_id ); |
---|
| 317 | |
---|
| 318 | extern int giet_fat_readdir( unsigned int fd_id, |
---|
| 319 | fat_dirent_t* entry ); |
---|
| 320 | |
---|
[258] | 321 | ////////////////////////////////////////////////////////////////////////// |
---|
[382] | 322 | // Miscelaneous system calls |
---|
| 323 | ////////////////////////////////////////////////////////////////////////// |
---|
[258] | 324 | |
---|
[501] | 325 | extern void giet_procs_number( unsigned int* x_size, |
---|
| 326 | unsigned int* y_size, |
---|
| 327 | unsigned int* nprocs ); |
---|
[438] | 328 | |
---|
[295] | 329 | extern void giet_vobj_get_vbase( char* vspace_name, |
---|
| 330 | char* vobj_name, |
---|
| 331 | unsigned int* vobj_vaddr); |
---|
[258] | 332 | |
---|
[438] | 333 | extern void giet_vobj_get_length( char* vspace_name, |
---|
| 334 | char* vobj_name, |
---|
| 335 | unsigned int* vobj_vaddr); |
---|
[295] | 336 | |
---|
| 337 | extern void giet_heap_info( unsigned int* vaddr, |
---|
[368] | 338 | unsigned int* length, |
---|
| 339 | unsigned int x, |
---|
| 340 | unsigned int y ); |
---|
[295] | 341 | |
---|
[390] | 342 | extern void giet_get_xy( void* ptr, |
---|
| 343 | unsigned int* px, |
---|
| 344 | unsigned int* py ); |
---|
| 345 | |
---|
[258] | 346 | #endif |
---|
| 347 | |
---|
| 348 | // Local Variables: |
---|
| 349 | // tab-width: 4 |
---|
| 350 | // c-basic-offset: 4 |
---|
| 351 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 352 | // indent-tabs-mode: nil |
---|
| 353 | // End: |
---|
| 354 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 355 | |
---|