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