| 1 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : stdio.h |
|---|
| 3 | // Date : 01/04/2010 |
|---|
| 4 | // Author : alain greiner & Joel Porquet |
|---|
| 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 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. |
|---|
| 10 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | |
|---|
| 12 | #ifndef _STDIO_H |
|---|
| 13 | #define _STDIO_H |
|---|
| 14 | |
|---|
| 15 | #include "giet_fat32/fat32_shared.h" |
|---|
| 16 | |
|---|
| 17 | // These define must be synchronised with |
|---|
| 18 | // the _syscall_vector defined in file sys_handler.c |
|---|
| 19 | |
|---|
| 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 |
|---|
| 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 |
|---|
| 36 | |
|---|
| 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 |
|---|
| 41 | #define SYSCALL_TIM_ALLOC 0x14 |
|---|
| 42 | #define SYSCALL_TIM_START 0x15 |
|---|
| 43 | #define SYSCALL_TIM_STOP 0x16 |
|---|
| 44 | #define SYSCALL_KILL_APP 0x17 |
|---|
| 45 | #define SYSCALL_EXEC_APP 0x18 |
|---|
| 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 |
|---|
| 53 | |
|---|
| 54 | #define SYSCALL_FAT_OPEN 0x20 |
|---|
| 55 | #define SYSCALL_FAT_READ 0x21 |
|---|
| 56 | #define SYSCALL_FAT_WRITE 0x22 |
|---|
| 57 | #define SYSCALL_FAT_LSEEK 0x23 |
|---|
| 58 | #define SYSCALL_FAT_FINFO 0x24 |
|---|
| 59 | #define SYSCALL_FAT_CLOSE 0x25 |
|---|
| 60 | #define SYSCALL_FAT_REMOVE 0x26 |
|---|
| 61 | #define SYSCALL_FAT_RENAME 0x27 |
|---|
| 62 | #define SYSCALL_FAT_MKDIR 0x28 |
|---|
| 63 | #define SYSCALL_FAT_OPENDIR 0x29 |
|---|
| 64 | #define SYSCALL_FAT_CLOSEDIR 0x2A |
|---|
| 65 | #define SYSCALL_FAT_READDIR 0x2B |
|---|
| 66 | // 0x2C |
|---|
| 67 | // 0x2D |
|---|
| 68 | // 0x2E |
|---|
| 69 | // 0x2F |
|---|
| 70 | |
|---|
| 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 |
|---|
| 79 | // 0x38 |
|---|
| 80 | // 0x39 |
|---|
| 81 | // 0x3A |
|---|
| 82 | #define SYSCALL_COPROC_COMPLETED 0x3B |
|---|
| 83 | #define SYSCALL_COPROC_ALLOC 0x3C |
|---|
| 84 | #define SYSCALL_COPROC_CHANNEL_INIT 0x3D |
|---|
| 85 | #define SYSCALL_COPROC_RUN 0x3E |
|---|
| 86 | #define SYSCALL_COPROC_RELEASE 0x3F |
|---|
| 87 | |
|---|
| 88 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 89 | // NULL pointer definition |
|---|
| 90 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 91 | |
|---|
| 92 | #define NULL (void *)0 |
|---|
| 93 | |
|---|
| 94 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 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. |
|---|
| 98 | // Returns -1 to signal an error. |
|---|
| 99 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 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" |
|---|
| 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 */ |
|---|
| 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 | ); |
|---|
| 138 | return (volatile int)reg_no_and_output; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 142 | // MIPS32 related system calls |
|---|
| 143 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 144 | |
|---|
| 145 | extern void giet_proc_xyp( unsigned int* cluster_x, |
|---|
| 146 | unsigned int* cluster_y, |
|---|
| 147 | unsigned int* lpid ); |
|---|
| 148 | |
|---|
| 149 | extern unsigned int giet_proctime(); |
|---|
| 150 | |
|---|
| 151 | extern unsigned int giet_rand(); |
|---|
| 152 | |
|---|
| 153 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 154 | // Task related system calls |
|---|
| 155 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 156 | |
|---|
| 157 | extern unsigned int giet_proc_task_id(); |
|---|
| 158 | |
|---|
| 159 | extern unsigned int giet_global_task_id(); |
|---|
| 160 | |
|---|
| 161 | extern unsigned int giet_thread_id(); |
|---|
| 162 | |
|---|
| 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 | |
|---|
| 170 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 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 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 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, |
|---|
| 194 | unsigned int* coproc_info ); |
|---|
| 195 | |
|---|
| 196 | extern void giet_coproc_release( unsigned int coproc_reg_index ); |
|---|
| 197 | |
|---|
| 198 | extern void giet_coproc_channel_init( unsigned int channel, |
|---|
| 199 | giet_coproc_channel_t* desc ); |
|---|
| 200 | |
|---|
| 201 | extern void giet_coproc_run( unsigned int coproc_reg_index ); |
|---|
| 202 | |
|---|
| 203 | extern void giet_coproc_completed(); |
|---|
| 204 | |
|---|
| 205 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 206 | // TTY device related system calls |
|---|
| 207 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 208 | |
|---|
| 209 | extern void giet_tty_alloc( unsigned int shared ); |
|---|
| 210 | |
|---|
| 211 | extern void giet_tty_printf( char* format, ... ); |
|---|
| 212 | |
|---|
| 213 | extern void giet_tty_getc( char* byte ); |
|---|
| 214 | |
|---|
| 215 | extern void giet_tty_gets( char* buf, unsigned int bufsize ); |
|---|
| 216 | |
|---|
| 217 | extern void giet_tty_getw( unsigned int* val ); |
|---|
| 218 | |
|---|
| 219 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 220 | // TIMER device related system calls |
|---|
| 221 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 222 | |
|---|
| 223 | extern void giet_timer_alloc(); |
|---|
| 224 | |
|---|
| 225 | extern void giet_timer_start( unsigned int period ); |
|---|
| 226 | |
|---|
| 227 | extern void giet_timer_stop(); |
|---|
| 228 | |
|---|
| 229 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 230 | // Frame buffer device related system calls |
|---|
| 231 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 232 | |
|---|
| 233 | extern void giet_fbf_cma_alloc(); |
|---|
| 234 | |
|---|
| 235 | extern void giet_fbf_cma_init_buf( void* buf0_vbase, |
|---|
| 236 | void* buf1_vbase, |
|---|
| 237 | void* sts0_vaddr, |
|---|
| 238 | void* sts1_vaddr ); |
|---|
| 239 | |
|---|
| 240 | extern void giet_fbf_cma_start( unsigned int length ); |
|---|
| 241 | |
|---|
| 242 | extern void giet_fbf_cma_display( unsigned int buffer ); |
|---|
| 243 | |
|---|
| 244 | extern void giet_fbf_cma_stop(); |
|---|
| 245 | |
|---|
| 246 | extern void giet_fbf_sync_read( unsigned int offset, |
|---|
| 247 | void* buffer, |
|---|
| 248 | unsigned int length ); |
|---|
| 249 | |
|---|
| 250 | extern void giet_fbf_sync_write( unsigned int offset, |
|---|
| 251 | void* buffer, |
|---|
| 252 | unsigned int length ); |
|---|
| 253 | |
|---|
| 254 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 255 | // NIC related system calls |
|---|
| 256 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 257 | |
|---|
| 258 | extern unsigned int giet_nic_rx_alloc( unsigned int xmax, unsigned int ymax ); |
|---|
| 259 | |
|---|
| 260 | extern unsigned int giet_nic_tx_alloc( unsigned int xmax, unsigned int ymax ); |
|---|
| 261 | |
|---|
| 262 | extern void giet_nic_rx_start( unsigned int channel ); |
|---|
| 263 | |
|---|
| 264 | extern void giet_nic_tx_start( unsigned int channel ); |
|---|
| 265 | |
|---|
| 266 | extern void giet_nic_rx_move( unsigned int channel, void* buffer ); |
|---|
| 267 | |
|---|
| 268 | extern void giet_nic_tx_move( unsigned int channel, void* buffer ); |
|---|
| 269 | |
|---|
| 270 | extern void giet_nic_rx_stop( unsigned int channel ); |
|---|
| 271 | |
|---|
| 272 | extern void giet_nic_tx_stop( unsigned int channel ); |
|---|
| 273 | |
|---|
| 274 | extern void giet_nic_rx_stats( unsigned int channel ); |
|---|
| 275 | |
|---|
| 276 | extern void giet_nic_tx_stats( unsigned int channel ); |
|---|
| 277 | |
|---|
| 278 | extern void giet_nic_rx_clear( unsigned int channel ); |
|---|
| 279 | |
|---|
| 280 | extern void giet_nic_tx_clear( unsigned int channel ); |
|---|
| 281 | |
|---|
| 282 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 283 | // FAT related system calls |
|---|
| 284 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 285 | |
|---|
| 286 | extern int giet_fat_open( char* pathname, |
|---|
| 287 | unsigned int flags ); |
|---|
| 288 | |
|---|
| 289 | extern int giet_fat_close( unsigned int fd_id ); |
|---|
| 290 | |
|---|
| 291 | extern int giet_fat_file_info( unsigned int fd_id, |
|---|
| 292 | fat_file_info_t* info ); |
|---|
| 293 | |
|---|
| 294 | extern int giet_fat_read( unsigned int fd_id, |
|---|
| 295 | void* buffer, |
|---|
| 296 | unsigned int count ); |
|---|
| 297 | |
|---|
| 298 | extern int giet_fat_write( unsigned int fd, |
|---|
| 299 | void* buffer, |
|---|
| 300 | unsigned int count ); |
|---|
| 301 | |
|---|
| 302 | extern int giet_fat_lseek( unsigned int fd, |
|---|
| 303 | unsigned int offset, |
|---|
| 304 | unsigned int whence ); |
|---|
| 305 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 321 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 322 | // Miscelaneous system calls |
|---|
| 323 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 324 | |
|---|
| 325 | extern void giet_procs_number( unsigned int* x_size, |
|---|
| 326 | unsigned int* y_size, |
|---|
| 327 | unsigned int* nprocs ); |
|---|
| 328 | |
|---|
| 329 | extern void giet_vobj_get_vbase( char* vspace_name, |
|---|
| 330 | char* vobj_name, |
|---|
| 331 | unsigned int* vobj_vaddr); |
|---|
| 332 | |
|---|
| 333 | extern void giet_vobj_get_length( char* vspace_name, |
|---|
| 334 | char* vobj_name, |
|---|
| 335 | unsigned int* vobj_vaddr); |
|---|
| 336 | |
|---|
| 337 | extern void giet_heap_info( unsigned int* vaddr, |
|---|
| 338 | unsigned int* length, |
|---|
| 339 | unsigned int x, |
|---|
| 340 | unsigned int y ); |
|---|
| 341 | |
|---|
| 342 | extern void giet_get_xy( void* ptr, |
|---|
| 343 | unsigned int* px, |
|---|
| 344 | unsigned int* py ); |
|---|
| 345 | |
|---|
| 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 | |
|---|