[521] | 1 | ////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2 | // File : stdio.c |
---|
| 3 | // Date : 01/04/2010 |
---|
| 4 | // Author : alain greiner & Joel Porquet |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
[521] | 6 | ////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 7 | |
---|
| 8 | #include <stdarg.h> |
---|
| 9 | #include <stdio.h> |
---|
[267] | 10 | #include <giet_config.h> |
---|
[258] | 11 | |
---|
[521] | 12 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 13 | // MIPS32 related system calls |
---|
[521] | 14 | ////////////////////////////////////////////////////////////////////////////// |
---|
[390] | 15 | |
---|
[438] | 16 | //////////////////////////////////////////// |
---|
[431] | 17 | void giet_proc_xyp( unsigned int* cluster_x, |
---|
| 18 | unsigned int* cluster_y, |
---|
| 19 | unsigned int* lpid ) |
---|
[390] | 20 | { |
---|
[438] | 21 | sys_call( SYSCALL_PROC_XYP, |
---|
[431] | 22 | (unsigned int)cluster_x, |
---|
| 23 | (unsigned int)cluster_y, |
---|
| 24 | (unsigned int)lpid, |
---|
| 25 | 0 ); |
---|
[390] | 26 | } |
---|
| 27 | |
---|
[438] | 28 | //////////////////////////// |
---|
| 29 | unsigned int giet_proctime() |
---|
[390] | 30 | { |
---|
[438] | 31 | return (unsigned int)sys_call( SYSCALL_PROC_TIME, |
---|
| 32 | 0, 0, 0, 0 ); |
---|
[390] | 33 | } |
---|
| 34 | |
---|
[438] | 35 | //////////////////////// |
---|
| 36 | unsigned int giet_rand() |
---|
[390] | 37 | { |
---|
[438] | 38 | unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME, |
---|
| 39 | 0, 0, 0, 0); |
---|
[390] | 40 | if ((x & 0xF) > 7) |
---|
| 41 | { |
---|
| 42 | return (x*x & 0xFFFF); |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | return (x*x*x & 0xFFFF); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
[521] | 50 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 51 | // Threads related system calls |
---|
[521] | 52 | ////////////////////////////////////////////////////////////////////////////// |
---|
[438] | 53 | |
---|
[709] | 54 | #define THREAD_CMD_PAUSE 0 |
---|
| 55 | #define THREAD_CMD_RESUME 1 |
---|
| 56 | #define THREAD_CMD_CONTEXT 2 |
---|
| 57 | |
---|
| 58 | ////////////////////////////////////////////////////////// |
---|
| 59 | int giet_pthread_create( pthread_t* buffer, |
---|
| 60 | pthread_attr_t* attr, |
---|
| 61 | void* function, |
---|
| 62 | void* arg ) |
---|
[438] | 63 | { |
---|
[709] | 64 | return sys_call( SYSCALL_PTHREAD_CREATE, |
---|
| 65 | (unsigned int)buffer, |
---|
| 66 | (unsigned int)attr, |
---|
| 67 | (unsigned int)function, |
---|
| 68 | (unsigned int)arg ); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | ////////////////////////////////////// |
---|
| 72 | void giet_pthread_exit( void* string ) |
---|
| 73 | { |
---|
| 74 | sys_call( SYSCALL_PTHREAD_EXIT, |
---|
| 75 | (unsigned int)string, |
---|
| 76 | 0, 0, 0 ); |
---|
[438] | 77 | } |
---|
| 78 | |
---|
[709] | 79 | //////////////////////////////////////// |
---|
| 80 | int giet_pthread_join( pthread_t trdid, |
---|
| 81 | void** ptr ) |
---|
[438] | 82 | { |
---|
[709] | 83 | return sys_call( SYSCALL_PTHREAD_JOIN, |
---|
| 84 | trdid, |
---|
| 85 | (unsigned int)ptr, |
---|
| 86 | 0, 0 ); |
---|
[438] | 87 | } |
---|
| 88 | |
---|
[709] | 89 | /////////////////////////////////////// |
---|
| 90 | int giet_pthread_kill( pthread_t trdid, |
---|
| 91 | int signal ) |
---|
[438] | 92 | { |
---|
[709] | 93 | return sys_call( SYSCALL_PTHREAD_KILL, |
---|
| 94 | trdid, |
---|
| 95 | signal, |
---|
| 96 | 0, 0 ); |
---|
[438] | 97 | } |
---|
| 98 | |
---|
[709] | 99 | ///////////////////////// |
---|
| 100 | void giet_pthread_yield() |
---|
[647] | 101 | { |
---|
[709] | 102 | sys_call( SYSCALL_PTHREAD_YIELD, |
---|
| 103 | 0, 0, 0, 0 ); |
---|
[647] | 104 | } |
---|
[438] | 105 | |
---|
[709] | 106 | ///////////////////////////////////////////////// |
---|
| 107 | void giet_pthread_assert( unsigned int condition, |
---|
| 108 | char* string ) |
---|
[647] | 109 | { |
---|
[709] | 110 | if ( condition == 0 ) giet_pthread_exit( string ); |
---|
[647] | 111 | } |
---|
| 112 | |
---|
[713] | 113 | //////////////////////////////////////////////// |
---|
| 114 | void giet_pthread_control( unsigned int command, |
---|
| 115 | char* vspace_name, |
---|
| 116 | char* thread_name ) |
---|
[647] | 117 | { |
---|
[713] | 118 | int ret = sys_call( SYSCALL_PTHREAD_CONTROL, |
---|
| 119 | command, |
---|
| 120 | (unsigned int) vspace_name, |
---|
| 121 | (unsigned int) thread_name, |
---|
| 122 | 0 ); |
---|
[647] | 123 | |
---|
[713] | 124 | if ( ret == SYSCALL_VSPACE_NOT_FOUND ) |
---|
| 125 | { |
---|
| 126 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
---|
| 127 | "vspace %s not found\n", vspace_name ); |
---|
| 128 | } |
---|
| 129 | if ( ret == SYSCALL_THREAD_NOT_FOUND ) |
---|
| 130 | { |
---|
| 131 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
---|
| 132 | "thread %s not found\n", thread_name ); |
---|
| 133 | } |
---|
| 134 | if ( ret == SYSCALL_UNCOHERENT_THREAD_CONTEXT ) |
---|
| 135 | { |
---|
| 136 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
---|
| 137 | "uncoherent context for thread %s\n", thread_name ); |
---|
| 138 | } |
---|
| 139 | if ( ret == SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE ) |
---|
| 140 | { |
---|
| 141 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
---|
| 142 | "illegal command type %d\n", command ); |
---|
| 143 | } |
---|
[689] | 144 | } |
---|
| 145 | |
---|
[709] | 146 | |
---|
[521] | 147 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 148 | // Applications related system calls |
---|
[647] | 149 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 150 | |
---|
| 151 | /////////////////////////////////////// |
---|
| 152 | int giet_kill_application( char* name ) |
---|
| 153 | { |
---|
| 154 | return ( sys_call( SYSCALL_KILL_APP, |
---|
| 155 | (unsigned int)name, |
---|
| 156 | 0, 0, 0 ) ); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /////////////////////////////////////// |
---|
| 160 | int giet_exec_application( char* name ) |
---|
| 161 | { |
---|
| 162 | return ( sys_call( SYSCALL_EXEC_APP, |
---|
| 163 | (unsigned int)name, |
---|
| 164 | 0, 0, 0 ) ); |
---|
| 165 | } |
---|
| 166 | |
---|
[713] | 167 | /////////////////////////////////////////// |
---|
| 168 | void giet_applications_status( char* name ) |
---|
[709] | 169 | { |
---|
| 170 | sys_call( SYSCALL_APPS_STATUS, |
---|
[713] | 171 | (unsigned int)name, |
---|
| 172 | 0, 0, 0 ); |
---|
[709] | 173 | } |
---|
| 174 | |
---|
[647] | 175 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 176 | // Coprocessors related system calls |
---|
[521] | 177 | ////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 178 | |
---|
[521] | 179 | /////////////////////////////////////////////////// |
---|
[735] | 180 | void giet_coproc_alloc( unsigned int cluster_xy, |
---|
| 181 | unsigned int coproc_type, |
---|
[558] | 182 | unsigned int* coproc_info ) |
---|
[521] | 183 | { |
---|
| 184 | if ( sys_call( SYSCALL_COPROC_ALLOC, |
---|
[735] | 185 | cluster_xy, |
---|
[521] | 186 | coproc_type, |
---|
| 187 | (unsigned int)coproc_info, |
---|
[735] | 188 | 0 ) ) |
---|
[709] | 189 | giet_pthread_exit("error in giet_coproc_alloc()"); |
---|
[521] | 190 | } |
---|
| 191 | |
---|
[735] | 192 | ////////////////////////////////////////////////// |
---|
| 193 | void giet_coproc_release( unsigned int cluster_xy, |
---|
| 194 | unsigned int coproc_type ) |
---|
[521] | 195 | { |
---|
| 196 | if ( sys_call( SYSCALL_COPROC_RELEASE, |
---|
[735] | 197 | cluster_xy, |
---|
| 198 | coproc_type, |
---|
| 199 | 0 , 0 ) ) |
---|
[709] | 200 | giet_pthread_exit("error in giet_coproc_release()"); |
---|
[521] | 201 | } |
---|
| 202 | |
---|
| 203 | ////////////////////////////////////////////////////////////////// |
---|
[735] | 204 | void giet_coproc_channel_init( unsigned int cluster_xy, |
---|
| 205 | unsigned int coproc_type, |
---|
| 206 | unsigned int channel, |
---|
[521] | 207 | giet_coproc_channel_t* desc ) |
---|
| 208 | { |
---|
| 209 | if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT, |
---|
[735] | 210 | cluster_xy, |
---|
| 211 | coproc_type, |
---|
[521] | 212 | channel, |
---|
[735] | 213 | (unsigned int)desc ) ) |
---|
[709] | 214 | giet_pthread_exit("error in giet_coproc_channel_init()"); |
---|
[521] | 215 | } |
---|
| 216 | |
---|
[735] | 217 | ////////////////////////////////////////////// |
---|
| 218 | void giet_coproc_run( unsigned int cluster_xy, |
---|
| 219 | unsigned int coproc_type ) |
---|
[521] | 220 | { |
---|
[558] | 221 | if ( sys_call( SYSCALL_COPROC_RUN, |
---|
[735] | 222 | cluster_xy, |
---|
| 223 | coproc_type, |
---|
| 224 | 0 , 0 ) ) |
---|
[709] | 225 | giet_pthread_exit("error in giet_coproc_run()"); |
---|
[521] | 226 | } |
---|
| 227 | |
---|
[735] | 228 | //////////////////////////////////////////////////// |
---|
| 229 | void giet_coproc_completed( unsigned int cluster_xy, |
---|
| 230 | unsigned int coproc_type ) |
---|
[521] | 231 | { |
---|
| 232 | if ( sys_call( SYSCALL_COPROC_COMPLETED, |
---|
[735] | 233 | cluster_xy, |
---|
| 234 | coproc_type, |
---|
| 235 | 0 , 0 ) ) |
---|
[709] | 236 | giet_pthread_exit("error in giet_coproc_completed"); |
---|
[521] | 237 | } |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 241 | // TTY device related system calls |
---|
[521] | 242 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 243 | |
---|
[671] | 244 | ////////////////////////////////////////// |
---|
| 245 | void giet_tty_alloc( unsigned int shared ) |
---|
[258] | 246 | { |
---|
[521] | 247 | if ( sys_call( SYSCALL_TTY_ALLOC, |
---|
[671] | 248 | shared, |
---|
[709] | 249 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_tty_alloc()"); |
---|
[438] | 250 | } |
---|
[258] | 251 | |
---|
[438] | 252 | //////////////////////////////////////////////////////////////////////// |
---|
| 253 | static int __printf( char* format, unsigned int channel, va_list* args) |
---|
| 254 | { |
---|
| 255 | int ret; // return value from the syscall |
---|
[580] | 256 | enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers; |
---|
[438] | 257 | |
---|
[295] | 258 | printf_text: |
---|
[258] | 259 | |
---|
[295] | 260 | while (*format) |
---|
[258] | 261 | { |
---|
[295] | 262 | unsigned int i; |
---|
| 263 | for (i = 0 ; format[i] && (format[i] != '%') ; i++); |
---|
| 264 | if (i) |
---|
| 265 | { |
---|
| 266 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 267 | (unsigned int)format, |
---|
| 268 | i, |
---|
| 269 | channel, |
---|
[258] | 270 | 0); |
---|
| 271 | |
---|
[295] | 272 | if (ret != i) goto return_error; |
---|
| 273 | |
---|
| 274 | format += i; |
---|
[258] | 275 | } |
---|
[295] | 276 | if (*format == '%') |
---|
[258] | 277 | { |
---|
[295] | 278 | format++; |
---|
[580] | 279 | modifiers = NO_MOD; |
---|
[295] | 280 | goto printf_arguments; |
---|
[258] | 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
[345] | 284 | return 0; |
---|
[295] | 285 | |
---|
| 286 | printf_arguments: |
---|
| 287 | |
---|
[258] | 288 | { |
---|
[628] | 289 | char buf[30]; |
---|
| 290 | char * pbuf; |
---|
| 291 | unsigned int len = 0; |
---|
[295] | 292 | static const char HexaTab[] = "0123456789ABCDEF"; |
---|
[628] | 293 | unsigned int i; |
---|
[580] | 294 | |
---|
| 295 | /* Ignored fields : width and precision */ |
---|
| 296 | for (; *format >= '0' && *format <= '9'; format++); |
---|
[258] | 297 | |
---|
[295] | 298 | switch (*format++) |
---|
[258] | 299 | { |
---|
[580] | 300 | case ('%'): |
---|
[641] | 301 | { |
---|
| 302 | len = 1; |
---|
| 303 | pbuf = "%"; |
---|
| 304 | break; |
---|
| 305 | } |
---|
[295] | 306 | case ('c'): /* char conversion */ |
---|
[258] | 307 | { |
---|
[345] | 308 | int val = va_arg( *args, int ); |
---|
[588] | 309 | if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning |
---|
[580] | 310 | |
---|
[295] | 311 | len = 1; |
---|
| 312 | buf[0] = val; |
---|
| 313 | pbuf = &buf[0]; |
---|
| 314 | break; |
---|
[258] | 315 | } |
---|
[580] | 316 | case ('d'): /* decimal signed integer */ |
---|
[258] | 317 | { |
---|
[345] | 318 | int val = va_arg( *args, int ); |
---|
[580] | 319 | |
---|
[588] | 320 | if (modifiers == LL_MOD) goto return_error; // 64 bits not supported |
---|
[580] | 321 | |
---|
[295] | 322 | if (val < 0) |
---|
| 323 | { |
---|
| 324 | val = -val; |
---|
| 325 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 326 | (unsigned int)"-", |
---|
| 327 | 1, |
---|
| 328 | channel, |
---|
| 329 | 0); |
---|
| 330 | if (ret != 1) goto return_error; |
---|
| 331 | } |
---|
| 332 | for(i = 0; i < 10; i++) |
---|
| 333 | { |
---|
| 334 | buf[9 - i] = HexaTab[val % 10]; |
---|
| 335 | if (!(val /= 10)) break; |
---|
| 336 | } |
---|
| 337 | len = i + 1; |
---|
| 338 | pbuf = &buf[9 - i]; |
---|
| 339 | break; |
---|
[258] | 340 | } |
---|
[580] | 341 | case ('u'): /* decimal unsigned integer */ |
---|
[295] | 342 | { |
---|
[580] | 343 | if (modifiers != LL_MOD) //32 bits integer |
---|
[295] | 344 | { |
---|
[580] | 345 | unsigned int val = va_arg( *args, unsigned int ); |
---|
| 346 | for(i = 0; i < 10; i++) |
---|
| 347 | { |
---|
| 348 | buf[9 - i] = HexaTab[val % 10]; |
---|
| 349 | if (!(val /= 10)) break; |
---|
| 350 | } |
---|
| 351 | len = i + 1; |
---|
| 352 | pbuf = &buf[9 - i]; |
---|
| 353 | break; |
---|
[295] | 354 | } |
---|
[580] | 355 | //64 bits : base 10 unsupported : continue to hexa |
---|
[295] | 356 | } |
---|
[580] | 357 | case ('x'): |
---|
| 358 | case ('X'): /* hexadecimal integer */ |
---|
[295] | 359 | { |
---|
[580] | 360 | unsigned long long val; |
---|
| 361 | int imax; |
---|
| 362 | |
---|
[628] | 363 | if (modifiers == LL_MOD) // 64 bits |
---|
[295] | 364 | { |
---|
[580] | 365 | val = va_arg( *args, unsigned long long); |
---|
| 366 | |
---|
[628] | 367 | // if asked to print in base 10, can do only if it fits in 32 bits |
---|
| 368 | if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL))) |
---|
[580] | 369 | { |
---|
| 370 | unsigned int uintv = (unsigned int) val; |
---|
| 371 | |
---|
| 372 | for(i = 0; i < 10; i++) |
---|
| 373 | { |
---|
| 374 | buf[9 - i] = HexaTab[uintv % 10]; |
---|
| 375 | if (!(uintv /= 10)) break; |
---|
| 376 | } |
---|
| 377 | len = i + 1; |
---|
| 378 | pbuf = &buf[9 - i]; |
---|
| 379 | break; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | imax = 16; |
---|
[295] | 383 | } |
---|
[580] | 384 | else //32 bits |
---|
| 385 | { |
---|
| 386 | val = va_arg( *args, unsigned int); |
---|
| 387 | imax = 8; |
---|
| 388 | } |
---|
| 389 | |
---|
[295] | 390 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 391 | (unsigned int)"0x", |
---|
| 392 | 2, |
---|
| 393 | channel, |
---|
| 394 | 0); |
---|
| 395 | if (ret != 2) goto return_error; |
---|
[580] | 396 | |
---|
| 397 | for(i = 0; i < imax; i++) |
---|
[295] | 398 | { |
---|
[580] | 399 | buf[(imax-1) - i] = HexaTab[val % 16]; |
---|
[295] | 400 | if (!(val /= 16)) break; |
---|
| 401 | } |
---|
| 402 | len = i + 1; |
---|
[580] | 403 | pbuf = &buf[(imax-1) - i]; |
---|
[295] | 404 | break; |
---|
| 405 | } |
---|
| 406 | case ('s'): /* string */ |
---|
| 407 | { |
---|
[345] | 408 | char* str = va_arg( *args, char* ); |
---|
[580] | 409 | |
---|
[588] | 410 | if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning |
---|
[580] | 411 | |
---|
[295] | 412 | while (str[len]) |
---|
| 413 | { |
---|
| 414 | len++; |
---|
| 415 | } |
---|
| 416 | pbuf = str; |
---|
| 417 | break; |
---|
| 418 | } |
---|
[580] | 419 | case ('e'): |
---|
| 420 | case ('f'): |
---|
| 421 | case ('g'): /* IEEE754 64 bits */ |
---|
| 422 | { |
---|
[666] | 423 | union |
---|
| 424 | { |
---|
| 425 | double d; |
---|
| 426 | unsigned long long ull; |
---|
| 427 | } val; |
---|
[580] | 428 | |
---|
[666] | 429 | val.d = va_arg( *args, double ); |
---|
[580] | 430 | |
---|
[666] | 431 | unsigned long long digits = val.ull & 0xFFFFFFFFFFFFFULL; //get mantissa |
---|
[580] | 432 | |
---|
| 433 | unsigned int |
---|
[666] | 434 | base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52), //get exposant |
---|
| 435 | intp = (unsigned int)val.d, //get integer part of the float |
---|
[580] | 436 | decp; |
---|
| 437 | |
---|
| 438 | int isvalue = 0; |
---|
| 439 | |
---|
| 440 | if (base == 0x7FF) //special value |
---|
| 441 | { |
---|
[628] | 442 | if (digits & 0xFFFFFFFFFFFFFULL) |
---|
[580] | 443 | { |
---|
| 444 | /* Not a Number */ |
---|
| 445 | buf[0] = 'N'; |
---|
| 446 | buf[1] = 'a'; |
---|
| 447 | buf[2] = 'N'; |
---|
| 448 | len = 3; |
---|
| 449 | pbuf = buf; |
---|
| 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
| 453 | /* inf */ |
---|
[666] | 454 | buf[0] = (val.ull & 0x8000000000000000ULL) ? '-' : '+'; |
---|
[580] | 455 | buf[1] = 'i'; |
---|
| 456 | buf[2] = 'n'; |
---|
| 457 | buf[3] = 'f'; |
---|
| 458 | len = 4; |
---|
| 459 | pbuf = buf; |
---|
| 460 | } |
---|
| 461 | break; |
---|
| 462 | } |
---|
| 463 | |
---|
[666] | 464 | if (val.ull & 0x8000000000000000ULL) |
---|
[580] | 465 | { |
---|
| 466 | /* negative */ |
---|
| 467 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 468 | (unsigned int)"-", |
---|
| 469 | 1, |
---|
| 470 | channel, |
---|
| 471 | 0); |
---|
| 472 | if (ret != 1) goto return_error; |
---|
[666] | 473 | val.d = val.d * -1; |
---|
[580] | 474 | } |
---|
| 475 | else |
---|
| 476 | { |
---|
| 477 | /* positive */ |
---|
| 478 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 479 | (unsigned int)"+", |
---|
| 480 | 1, |
---|
| 481 | channel, |
---|
| 482 | 0); |
---|
| 483 | if (ret != 1) goto return_error; |
---|
| 484 | } |
---|
| 485 | |
---|
[666] | 486 | if (val.d > 0xFFFFFFFF) |
---|
[580] | 487 | { |
---|
| 488 | /* overflow */ |
---|
| 489 | buf[0] = 'B'; |
---|
| 490 | buf[1] = 'I'; |
---|
| 491 | buf[2] = 'G'; |
---|
| 492 | len = 3; |
---|
| 493 | pbuf = buf; |
---|
| 494 | break; |
---|
| 495 | } |
---|
| 496 | |
---|
[666] | 497 | val.d -= (double)intp; |
---|
| 498 | decp = (unsigned int)(val.d * 1000000000); |
---|
[580] | 499 | |
---|
| 500 | for(i = 0; i < 10; i++) |
---|
| 501 | { |
---|
| 502 | if ((!isvalue) && (intp % 10)) isvalue = 1; |
---|
| 503 | buf[9 - i] = HexaTab[intp % 10]; |
---|
| 504 | if (!(intp /= 10)) break; |
---|
| 505 | } |
---|
| 506 | pbuf = &buf[9 - i]; |
---|
| 507 | len = i+11; |
---|
| 508 | buf[10] = '.'; |
---|
| 509 | |
---|
| 510 | for(i = 0; i < 9; i++) |
---|
| 511 | { |
---|
| 512 | if ((!isvalue) && (decp % 10)) isvalue = 1; |
---|
| 513 | buf[19 - i] = HexaTab[decp % 10]; |
---|
| 514 | decp /= 10; |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | if (!isvalue) |
---|
| 518 | { |
---|
[666] | 519 | if (val.d != 0) |
---|
[580] | 520 | { |
---|
| 521 | /* underflow */ |
---|
| 522 | buf[0] = 'T'; |
---|
| 523 | buf[1] = 'I'; |
---|
| 524 | buf[2] = 'N'; |
---|
| 525 | buf[3] = 'Y'; |
---|
| 526 | len = 4; |
---|
| 527 | pbuf = buf; |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | break; |
---|
| 532 | } |
---|
| 533 | case ('l'): |
---|
| 534 | switch (modifiers) |
---|
| 535 | { |
---|
| 536 | case NO_MOD: |
---|
| 537 | modifiers = L_MOD; |
---|
| 538 | goto printf_arguments; |
---|
| 539 | |
---|
| 540 | case L_MOD: |
---|
| 541 | modifiers = LL_MOD; |
---|
| 542 | goto printf_arguments; |
---|
| 543 | |
---|
| 544 | default: |
---|
| 545 | goto return_error; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | /* Ignored fields : width and precision */ |
---|
| 549 | case ('.'): goto printf_arguments; |
---|
| 550 | |
---|
[295] | 551 | default: |
---|
| 552 | goto return_error; |
---|
[258] | 553 | } |
---|
| 554 | |
---|
[295] | 555 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 556 | (unsigned int)pbuf, |
---|
| 557 | len, |
---|
| 558 | channel, |
---|
| 559 | 0); |
---|
| 560 | if (ret != len) goto return_error; |
---|
| 561 | |
---|
| 562 | goto printf_text; |
---|
[258] | 563 | } |
---|
| 564 | |
---|
[295] | 565 | return_error: |
---|
[345] | 566 | return 1; |
---|
| 567 | } // end __printf() |
---|
[295] | 568 | |
---|
[345] | 569 | |
---|
| 570 | //////////////////////////////////////// |
---|
| 571 | void giet_tty_printf( char* format, ...) |
---|
| 572 | { |
---|
| 573 | va_list args; |
---|
| 574 | |
---|
| 575 | va_start( args, format ); |
---|
| 576 | int ret = __printf(format, 0xFFFFFFFF, &args); |
---|
[295] | 577 | va_end( args ); |
---|
[345] | 578 | |
---|
| 579 | if (ret) |
---|
| 580 | { |
---|
[709] | 581 | giet_pthread_exit("error in giet_tty_printf()"); |
---|
[345] | 582 | } |
---|
[295] | 583 | } // end giet_tty_printf() |
---|
| 584 | |
---|
| 585 | ///////////////////////////////// |
---|
| 586 | void giet_tty_getc( char * byte ) |
---|
| 587 | { |
---|
| 588 | int ret; |
---|
| 589 | |
---|
| 590 | do |
---|
[267] | 591 | { |
---|
[295] | 592 | ret = sys_call(SYSCALL_TTY_READ, |
---|
| 593 | (unsigned int)byte, // buffer address |
---|
| 594 | 1, // number of characters |
---|
| 595 | 0xFFFFFFFF, // channel index from task context |
---|
| 596 | 0); |
---|
[709] | 597 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getc()"); |
---|
[267] | 598 | } |
---|
[295] | 599 | while (ret != 1); |
---|
| 600 | } |
---|
[267] | 601 | |
---|
[295] | 602 | ///////////////////////////////////// |
---|
| 603 | void giet_tty_gets( char* buf, |
---|
| 604 | unsigned int bufsize ) |
---|
| 605 | { |
---|
[647] | 606 | int ret; // return value from syscalls |
---|
[295] | 607 | unsigned char byte; |
---|
| 608 | unsigned int index = 0; |
---|
[647] | 609 | unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS |
---|
[295] | 610 | |
---|
| 611 | while (index < (bufsize - 1)) |
---|
| 612 | { |
---|
[647] | 613 | // get one character |
---|
[295] | 614 | do |
---|
| 615 | { |
---|
| 616 | ret = sys_call(SYSCALL_TTY_READ, |
---|
| 617 | (unsigned int)(&byte), |
---|
| 618 | 1, |
---|
[647] | 619 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 620 | 0); |
---|
[709] | 621 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
---|
[295] | 622 | } |
---|
| 623 | while (ret != 1); |
---|
| 624 | |
---|
[647] | 625 | // analyse character |
---|
| 626 | if (byte == 0x0A) // LF special character |
---|
[295] | 627 | { |
---|
| 628 | break; |
---|
| 629 | } |
---|
[647] | 630 | else if ( (byte == 0x7F) || // DEL special character |
---|
| 631 | (byte == 0x08) ) // BS special character |
---|
[295] | 632 | { |
---|
[647] | 633 | if ( index > 0 ) |
---|
| 634 | { |
---|
| 635 | index--; |
---|
| 636 | |
---|
| 637 | // cancel character |
---|
| 638 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 639 | (unsigned int)(&string_cancel), |
---|
| 640 | 3, |
---|
| 641 | 0XFFFFFFFF, // channel index from task context |
---|
| 642 | 0 ); |
---|
[709] | 643 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
---|
[647] | 644 | } |
---|
[295] | 645 | } |
---|
[647] | 646 | else if ( (byte < 0x20) || (byte > 0x7F) ) // non printable characters |
---|
[295] | 647 | { |
---|
[647] | 648 | } |
---|
| 649 | else // take all other characters |
---|
| 650 | { |
---|
[295] | 651 | buf[index] = byte; |
---|
| 652 | index++; |
---|
[647] | 653 | |
---|
| 654 | // echo |
---|
| 655 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 656 | (unsigned int)(&byte), |
---|
| 657 | 1, |
---|
| 658 | 0XFFFFFFFF, // channel index from task context |
---|
| 659 | 0 ); |
---|
[709] | 660 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
---|
[647] | 661 | |
---|
[295] | 662 | } |
---|
| 663 | } |
---|
| 664 | buf[index] = 0; |
---|
[258] | 665 | |
---|
[647] | 666 | } // end giet_tty_gets() |
---|
| 667 | |
---|
[295] | 668 | /////////////////////////////////////// |
---|
| 669 | void giet_tty_getw( unsigned int* val ) |
---|
| 670 | { |
---|
| 671 | unsigned char buf[32]; |
---|
| 672 | unsigned int string_byte = 0x00000000; // string containing one single byte |
---|
| 673 | unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS |
---|
| 674 | unsigned int save = 0; |
---|
| 675 | unsigned int dec = 0; |
---|
| 676 | unsigned int done = 0; |
---|
| 677 | unsigned int overflow = 0; |
---|
| 678 | unsigned int length = 0; |
---|
| 679 | unsigned int i; |
---|
| 680 | int ret; // return value from syscalls |
---|
| 681 | |
---|
| 682 | // get characters |
---|
| 683 | while (done == 0) |
---|
| 684 | { |
---|
| 685 | // read one character |
---|
| 686 | do |
---|
| 687 | { |
---|
| 688 | ret = sys_call( SYSCALL_TTY_READ, |
---|
| 689 | (unsigned int)(&string_byte), |
---|
| 690 | 1, |
---|
[647] | 691 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 692 | 0); |
---|
[709] | 693 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 694 | } |
---|
| 695 | while (ret != 1); |
---|
[258] | 696 | |
---|
[295] | 697 | // analyse character |
---|
[647] | 698 | if ((string_byte > 0x2F) && (string_byte < 0x3A)) // decimal character |
---|
[295] | 699 | { |
---|
| 700 | buf[length] = (unsigned char)string_byte; |
---|
| 701 | length++; |
---|
[258] | 702 | |
---|
[295] | 703 | // echo |
---|
| 704 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 705 | (unsigned int)(&string_byte), |
---|
| 706 | 1, |
---|
[647] | 707 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 708 | 0 ); |
---|
[709] | 709 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 710 | } |
---|
[647] | 711 | else if (string_byte == 0x0A) // LF character |
---|
[295] | 712 | { |
---|
| 713 | done = 1; |
---|
| 714 | } |
---|
[647] | 715 | else if ( (string_byte == 0x7F) || // DEL character |
---|
| 716 | (string_byte == 0x08) ) // BS character |
---|
[295] | 717 | { |
---|
| 718 | if ( length > 0 ) |
---|
| 719 | { |
---|
| 720 | length--; // cancel the character |
---|
| 721 | |
---|
| 722 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 723 | (unsigned int)(&string_cancel), |
---|
| 724 | 3, |
---|
[647] | 725 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 726 | 0 ); |
---|
[709] | 727 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 728 | } |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | // test buffer overflow |
---|
| 732 | if ( length >= 32 ) |
---|
| 733 | { |
---|
| 734 | overflow = 1; |
---|
| 735 | done = 1; |
---|
| 736 | } |
---|
| 737 | } // end while characters |
---|
| 738 | |
---|
| 739 | // string to int conversion with overflow detection |
---|
| 740 | if ( overflow == 0 ) |
---|
| 741 | { |
---|
| 742 | for (i = 0; (i < length) && (overflow == 0) ; i++) |
---|
| 743 | { |
---|
| 744 | dec = dec * 10 + (buf[i] - 0x30); |
---|
| 745 | if (dec < save) overflow = 1; |
---|
| 746 | save = dec; |
---|
| 747 | } |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | // final evaluation |
---|
| 751 | if ( overflow == 0 ) |
---|
| 752 | { |
---|
| 753 | // return value |
---|
| 754 | *val = dec; |
---|
| 755 | } |
---|
| 756 | else |
---|
| 757 | { |
---|
| 758 | // cancel all echo characters |
---|
| 759 | for (i = 0; i < length ; i++) |
---|
| 760 | { |
---|
| 761 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 762 | (unsigned int)(&string_cancel), |
---|
| 763 | 3, |
---|
[647] | 764 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 765 | 0 ); |
---|
[709] | 766 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 767 | } |
---|
| 768 | // echo character '0' |
---|
| 769 | string_byte = 0x30; |
---|
| 770 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 771 | (unsigned int)(&string_byte), |
---|
| 772 | 1, |
---|
[647] | 773 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 774 | 0 ); |
---|
[709] | 775 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 776 | |
---|
| 777 | // return 0 value |
---|
| 778 | *val = 0; |
---|
| 779 | } |
---|
[647] | 780 | } // end giet_tty_getw() |
---|
[295] | 781 | |
---|
| 782 | |
---|
[258] | 783 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 784 | // TIMER related system calls |
---|
[258] | 785 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 786 | |
---|
[295] | 787 | /////////////////////// |
---|
[438] | 788 | void giet_timer_alloc() |
---|
[258] | 789 | { |
---|
[438] | 790 | if ( sys_call( SYSCALL_TIM_ALLOC, |
---|
[713] | 791 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_ALLOC"); |
---|
[258] | 792 | } |
---|
[295] | 793 | |
---|
[438] | 794 | //////////////////////////////////////////// |
---|
| 795 | void giet_timer_start( unsigned int period ) |
---|
| 796 | { |
---|
| 797 | if ( sys_call( SYSCALL_TIM_START, |
---|
| 798 | period, |
---|
[713] | 799 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_START"); |
---|
[438] | 800 | } |
---|
| 801 | |
---|
[295] | 802 | ////////////////////// |
---|
| 803 | void giet_timer_stop() |
---|
[258] | 804 | { |
---|
[438] | 805 | if ( sys_call( SYSCALL_TIM_STOP, |
---|
[713] | 806 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_STOP"); |
---|
[258] | 807 | } |
---|
| 808 | |
---|
| 809 | |
---|
| 810 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 811 | // Frame buffer related system calls |
---|
[258] | 812 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 813 | |
---|
[713] | 814 | //////////////////////////////////////// |
---|
| 815 | void giet_fbf_size( unsigned int* width, |
---|
| 816 | unsigned int* height ) |
---|
| 817 | { |
---|
| 818 | sys_call( SYSCALL_FBF_SIZE, |
---|
| 819 | (unsigned int)width, |
---|
| 820 | (unsigned int)height, |
---|
| 821 | 0, 0 ); |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | ///////////////////// |
---|
| 825 | void giet_fbf_alloc() |
---|
| 826 | { |
---|
| 827 | if ( sys_call( SYSCALL_FBF_ALLOC, |
---|
| 828 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_ALLOC"); |
---|
| 829 | } |
---|
| 830 | |
---|
[722] | 831 | //////////////////////////////////////////// |
---|
| 832 | void giet_fbf_cma_alloc( unsigned int nbufs ) |
---|
[258] | 833 | { |
---|
[438] | 834 | if ( sys_call( SYSCALL_FBF_CMA_ALLOC, |
---|
[722] | 835 | nbufs, |
---|
| 836 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_ALLOC"); |
---|
[258] | 837 | } |
---|
[295] | 838 | |
---|
[722] | 839 | /////////////////////////////////////////////// |
---|
| 840 | void giet_fbf_cma_init_buf( unsigned int index, |
---|
| 841 | void* buf_vaddr, |
---|
| 842 | void* sts_vaddr ) |
---|
[258] | 843 | { |
---|
[614] | 844 | if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF, |
---|
[722] | 845 | index, |
---|
| 846 | (unsigned int)buf_vaddr, |
---|
| 847 | (unsigned int)sts_vaddr, |
---|
| 848 | 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF"); |
---|
[614] | 849 | } |
---|
| 850 | |
---|
[722] | 851 | ///////////////////////// |
---|
| 852 | void giet_fbf_cma_start() |
---|
[614] | 853 | { |
---|
[438] | 854 | if ( sys_call( SYSCALL_FBF_CMA_START, |
---|
[722] | 855 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_START"); |
---|
[258] | 856 | } |
---|
[295] | 857 | |
---|
[722] | 858 | /////////////////////////////////////////////// |
---|
| 859 | void giet_fbf_cma_display( unsigned int index ) |
---|
[258] | 860 | { |
---|
[438] | 861 | if ( sys_call( SYSCALL_FBF_CMA_DISPLAY, |
---|
[722] | 862 | index, |
---|
[713] | 863 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_DISPLAY"); |
---|
[258] | 864 | } |
---|
[295] | 865 | |
---|
[722] | 866 | ///////////////////////////////////////////// |
---|
| 867 | void giet_fbf_cma_check( unsigned int index ) |
---|
| 868 | { |
---|
| 869 | if ( sys_call( SYSCALL_FBF_CMA_CHECK, |
---|
| 870 | index, |
---|
| 871 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_CHECK"); |
---|
| 872 | } |
---|
| 873 | |
---|
[295] | 874 | //////////////////////// |
---|
[438] | 875 | void giet_fbf_cma_stop() |
---|
[258] | 876 | { |
---|
[438] | 877 | if ( sys_call( SYSCALL_FBF_CMA_STOP, |
---|
[722] | 878 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_STOP"); |
---|
[258] | 879 | } |
---|
| 880 | |
---|
[438] | 881 | ////////////////////////////////////////////// |
---|
| 882 | void giet_fbf_sync_write( unsigned int offset, |
---|
| 883 | void * buffer, |
---|
| 884 | unsigned int length ) |
---|
| 885 | { |
---|
| 886 | if ( sys_call( SYSCALL_FBF_SYNC_WRITE, |
---|
| 887 | offset, |
---|
| 888 | (unsigned int)buffer, |
---|
| 889 | length, |
---|
[713] | 890 | 0 ) ) giet_pthread_exit("ERROR in FBF_SYNC_WRITE"); |
---|
[438] | 891 | } |
---|
[258] | 892 | |
---|
[438] | 893 | ///////////////////////////////////////////// |
---|
| 894 | void giet_fbf_sync_read( unsigned int offset, |
---|
| 895 | void * buffer, |
---|
| 896 | unsigned int length ) |
---|
| 897 | { |
---|
| 898 | if ( sys_call( SYSCALL_FBF_SYNC_READ, |
---|
| 899 | offset, |
---|
| 900 | (unsigned int)buffer, |
---|
| 901 | length, |
---|
[713] | 902 | 0 ) ) giet_pthread_exit("ERROR in FBF_SYNC_READ"); |
---|
[438] | 903 | } |
---|
| 904 | |
---|
| 905 | |
---|
[258] | 906 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 907 | // NIC related system calls |
---|
[258] | 908 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 909 | |
---|
[709] | 910 | ////////////////////////////////////////// |
---|
| 911 | void giet_nic_rx_alloc( unsigned int xmax, |
---|
| 912 | unsigned int ymax ) |
---|
[258] | 913 | { |
---|
[709] | 914 | if ( sys_call( SYSCALL_NIC_ALLOC, |
---|
| 915 | 1, // RX |
---|
| 916 | xmax, |
---|
| 917 | ymax, |
---|
| 918 | 0 ) ) giet_pthread_exit("error in giet_nic_rx_alloc()"); |
---|
[258] | 919 | } |
---|
[295] | 920 | |
---|
[709] | 921 | ////////////////////////////////////////// |
---|
| 922 | void giet_nic_tx_alloc( unsigned int xmax, |
---|
| 923 | unsigned int ymax ) |
---|
[258] | 924 | { |
---|
[709] | 925 | if ( sys_call( SYSCALL_NIC_ALLOC, |
---|
| 926 | 0, // TX |
---|
| 927 | xmax, |
---|
| 928 | ymax, |
---|
| 929 | 0 ) ) giet_pthread_exit("error in giet_nic_tx_alloc()"); |
---|
[450] | 930 | } |
---|
| 931 | |
---|
[709] | 932 | //////////////////////// |
---|
| 933 | void giet_nic_rx_start() |
---|
[450] | 934 | { |
---|
[461] | 935 | if ( sys_call( SYSCALL_NIC_START, |
---|
[709] | 936 | 1, // RX |
---|
| 937 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()"); |
---|
[450] | 938 | } |
---|
| 939 | |
---|
[709] | 940 | //////////////////////// |
---|
| 941 | void giet_nic_tx_start() |
---|
[450] | 942 | { |
---|
[461] | 943 | if ( sys_call( SYSCALL_NIC_START, |
---|
[709] | 944 | 0, // TX |
---|
| 945 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()"); |
---|
[450] | 946 | } |
---|
| 947 | |
---|
[709] | 948 | ///////////////////////////////////// |
---|
| 949 | void giet_nic_rx_move( void* buffer ) |
---|
[450] | 950 | { |
---|
[461] | 951 | if ( sys_call( SYSCALL_NIC_MOVE, |
---|
[709] | 952 | 1, // RX |
---|
[438] | 953 | (unsigned int)buffer, |
---|
[709] | 954 | 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_move()"); |
---|
[258] | 955 | } |
---|
| 956 | |
---|
[709] | 957 | ///////////////////////////////////// |
---|
| 958 | void giet_nic_tx_move( void* buffer ) |
---|
[438] | 959 | { |
---|
[461] | 960 | if ( sys_call( SYSCALL_NIC_MOVE, |
---|
[709] | 961 | 0, // TX |
---|
[438] | 962 | (unsigned int)buffer, |
---|
[709] | 963 | 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_move()"); |
---|
[438] | 964 | } |
---|
| 965 | |
---|
[709] | 966 | /////////////////////// |
---|
| 967 | void giet_nic_rx_stop() |
---|
[450] | 968 | { |
---|
[461] | 969 | if ( sys_call( SYSCALL_NIC_STOP, |
---|
[709] | 970 | 1, // RX |
---|
| 971 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()"); |
---|
[450] | 972 | } |
---|
| 973 | |
---|
[709] | 974 | /////////////////////// |
---|
| 975 | void giet_nic_tx_stop() |
---|
[450] | 976 | { |
---|
[461] | 977 | if ( sys_call( SYSCALL_NIC_STOP, |
---|
[709] | 978 | 0, // TX |
---|
| 979 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()"); |
---|
[450] | 980 | } |
---|
| 981 | |
---|
[709] | 982 | //////////////////////// |
---|
| 983 | void giet_nic_rx_stats() |
---|
[461] | 984 | { |
---|
| 985 | if ( sys_call( SYSCALL_NIC_STATS, |
---|
[709] | 986 | 1, // RX |
---|
| 987 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()"); |
---|
[461] | 988 | } |
---|
[450] | 989 | |
---|
[709] | 990 | //////////////////////// |
---|
| 991 | void giet_nic_tx_stats() |
---|
[461] | 992 | { |
---|
| 993 | if ( sys_call( SYSCALL_NIC_STATS, |
---|
[709] | 994 | 0, // TX |
---|
| 995 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()"); |
---|
[461] | 996 | } |
---|
| 997 | |
---|
[709] | 998 | //////////////////////// |
---|
| 999 | void giet_nic_rx_clear() |
---|
[461] | 1000 | { |
---|
| 1001 | if ( sys_call( SYSCALL_NIC_CLEAR, |
---|
[709] | 1002 | 1, // RX |
---|
| 1003 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()"); |
---|
[461] | 1004 | } |
---|
| 1005 | |
---|
[709] | 1006 | //////////////////////// |
---|
| 1007 | void giet_nic_tx_clear() |
---|
[461] | 1008 | { |
---|
| 1009 | if ( sys_call( SYSCALL_NIC_CLEAR, |
---|
[709] | 1010 | 0, // TX |
---|
| 1011 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()"); |
---|
[461] | 1012 | } |
---|
| 1013 | |
---|
| 1014 | |
---|
| 1015 | |
---|
[295] | 1016 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 1017 | // FAT related system calls |
---|
[295] | 1018 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 1019 | |
---|
[588] | 1020 | ///////////////////////////////////////// |
---|
| 1021 | int giet_fat_open( char* pathname, |
---|
| 1022 | unsigned int flags ) |
---|
[295] | 1023 | { |
---|
[588] | 1024 | return sys_call( SYSCALL_FAT_OPEN, |
---|
| 1025 | (unsigned int)pathname, |
---|
| 1026 | flags, |
---|
| 1027 | 0, 0 ); |
---|
[295] | 1028 | } |
---|
[258] | 1029 | |
---|
[588] | 1030 | ///////////////////////////////////////// |
---|
| 1031 | int giet_fat_close( unsigned int fd_id ) |
---|
[295] | 1032 | { |
---|
[588] | 1033 | return sys_call( SYSCALL_FAT_CLOSE, |
---|
| 1034 | fd_id, |
---|
| 1035 | 0, 0, 0 ); |
---|
[295] | 1036 | } |
---|
| 1037 | |
---|
[588] | 1038 | ///////////////////////////////////////////// |
---|
[623] | 1039 | int giet_fat_file_info( unsigned int fd_id, |
---|
| 1040 | struct fat_file_info_s* info ) |
---|
[295] | 1041 | { |
---|
[588] | 1042 | return sys_call( SYSCALL_FAT_FINFO, |
---|
| 1043 | fd_id, |
---|
[623] | 1044 | (unsigned int)info, |
---|
| 1045 | 0, 0 ); |
---|
[295] | 1046 | } |
---|
| 1047 | |
---|
[588] | 1048 | /////////////////////////////////////// |
---|
| 1049 | int giet_fat_read( unsigned int fd_id, |
---|
| 1050 | void* buffer, |
---|
| 1051 | unsigned int count ) |
---|
| 1052 | { |
---|
| 1053 | return sys_call( SYSCALL_FAT_READ, |
---|
| 1054 | fd_id, |
---|
| 1055 | (unsigned int)buffer, |
---|
| 1056 | count, |
---|
[709] | 1057 | 0 ); // no physical addressing required |
---|
[588] | 1058 | } |
---|
| 1059 | |
---|
| 1060 | //////////////////////////////////////// |
---|
| 1061 | int giet_fat_write( unsigned int fd_id, |
---|
[295] | 1062 | void* buffer, |
---|
[588] | 1063 | unsigned int count ) |
---|
[258] | 1064 | { |
---|
[295] | 1065 | return sys_call( SYSCALL_FAT_WRITE, |
---|
[588] | 1066 | fd_id, |
---|
[295] | 1067 | (unsigned int)buffer, |
---|
[588] | 1068 | count, |
---|
[709] | 1069 | 0 ); // no physical addressing required |
---|
[258] | 1070 | } |
---|
[295] | 1071 | |
---|
[588] | 1072 | //////////////////////////////////////// |
---|
| 1073 | int giet_fat_lseek( unsigned int fd_id, |
---|
[295] | 1074 | unsigned int offset, |
---|
| 1075 | unsigned int whence ) |
---|
[258] | 1076 | { |
---|
[588] | 1077 | return sys_call( SYSCALL_FAT_LSEEK, |
---|
| 1078 | fd_id, |
---|
| 1079 | offset, |
---|
| 1080 | whence, |
---|
| 1081 | 0 ); |
---|
[258] | 1082 | } |
---|
[295] | 1083 | |
---|
[588] | 1084 | //////////////////////////////////////////// |
---|
| 1085 | int giet_fat_remove( char* pathname, |
---|
| 1086 | unsigned int should_be_dir ) |
---|
[258] | 1087 | { |
---|
[588] | 1088 | return sys_call( SYSCALL_FAT_REMOVE, |
---|
| 1089 | (unsigned int)pathname, |
---|
| 1090 | should_be_dir, |
---|
| 1091 | 0, 0 ); |
---|
[258] | 1092 | } |
---|
[295] | 1093 | |
---|
| 1094 | ///////////////////////////////////// |
---|
[588] | 1095 | int giet_fat_rename( char* old_path, |
---|
| 1096 | char* new_path ) |
---|
[258] | 1097 | { |
---|
[588] | 1098 | return sys_call( SYSCALL_FAT_RENAME, |
---|
| 1099 | (unsigned int)old_path, |
---|
| 1100 | (unsigned int)new_path, |
---|
| 1101 | 0, 0 ); |
---|
[258] | 1102 | } |
---|
[295] | 1103 | |
---|
[588] | 1104 | //////////////////////////////////// |
---|
| 1105 | int giet_fat_mkdir( char* pathname ) |
---|
| 1106 | { |
---|
| 1107 | return sys_call( SYSCALL_FAT_MKDIR, |
---|
| 1108 | (unsigned int)pathname, |
---|
| 1109 | 0, 0, 0 ); |
---|
| 1110 | } |
---|
[295] | 1111 | |
---|
[659] | 1112 | //////////////////////////////////// |
---|
| 1113 | int giet_fat_opendir( char* pathname ) |
---|
| 1114 | { |
---|
| 1115 | return sys_call( SYSCALL_FAT_OPENDIR, |
---|
| 1116 | (unsigned int)pathname, |
---|
| 1117 | 0, 0, 0 ); |
---|
| 1118 | } |
---|
| 1119 | |
---|
| 1120 | //////////////////////////////////// |
---|
| 1121 | int giet_fat_closedir( unsigned int fd_id ) |
---|
| 1122 | { |
---|
| 1123 | return sys_call( SYSCALL_FAT_CLOSEDIR, |
---|
| 1124 | (unsigned int)fd_id, |
---|
| 1125 | 0, 0, 0 ); |
---|
| 1126 | } |
---|
| 1127 | |
---|
| 1128 | //////////////////////////////////// |
---|
| 1129 | int giet_fat_readdir( unsigned int fd_id, |
---|
| 1130 | fat_dirent_t* entry ) |
---|
| 1131 | { |
---|
| 1132 | return sys_call( SYSCALL_FAT_READDIR, |
---|
| 1133 | (unsigned int)fd_id, |
---|
| 1134 | (unsigned int)entry, |
---|
| 1135 | 0, 0 ); |
---|
| 1136 | } |
---|
| 1137 | |
---|
[295] | 1138 | |
---|
| 1139 | |
---|
[390] | 1140 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 1141 | // Miscellaneous system calls |
---|
[390] | 1142 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 1143 | |
---|
[501] | 1144 | ///////////////////////////////////////////////// |
---|
| 1145 | void giet_procs_number( unsigned int* x_size, |
---|
| 1146 | unsigned int* y_size, |
---|
| 1147 | unsigned int* nprocs ) |
---|
[438] | 1148 | { |
---|
[501] | 1149 | if ( sys_call( SYSCALL_PROCS_NUMBER, |
---|
| 1150 | (unsigned int)x_size, |
---|
| 1151 | (unsigned int)y_size, |
---|
| 1152 | (unsigned int)nprocs, |
---|
[709] | 1153 | 0 ) ) giet_pthread_exit("error in giet_procs_number()"); |
---|
[438] | 1154 | } |
---|
| 1155 | |
---|
[295] | 1156 | //////////////////////////////////////////////////// |
---|
| 1157 | void giet_vobj_get_vbase( char* vspace_name, |
---|
| 1158 | char* vobj_name, |
---|
[438] | 1159 | unsigned int* vbase ) |
---|
[258] | 1160 | { |
---|
[295] | 1161 | if ( sys_call( SYSCALL_VOBJ_GET_VBASE, |
---|
| 1162 | (unsigned int) vspace_name, |
---|
| 1163 | (unsigned int) vobj_name, |
---|
[438] | 1164 | (unsigned int) vbase, |
---|
[709] | 1165 | 0 ) ) giet_pthread_exit("error in giet_vobj_get_vbase()"); |
---|
[258] | 1166 | } |
---|
[260] | 1167 | |
---|
[438] | 1168 | //////////////////////////////////////////////////// |
---|
| 1169 | void giet_vobj_get_length( char* vspace_name, |
---|
| 1170 | char* vobj_name, |
---|
| 1171 | unsigned int* length ) |
---|
[260] | 1172 | { |
---|
[438] | 1173 | if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, |
---|
| 1174 | (unsigned int) vspace_name, |
---|
| 1175 | (unsigned int) vobj_name, |
---|
| 1176 | (unsigned int) length, |
---|
[709] | 1177 | 0 ) ) giet_pthread_exit("error in giet_vobj_get_length()"); |
---|
[260] | 1178 | } |
---|
| 1179 | |
---|
[295] | 1180 | ///////////////////////////////////////// |
---|
| 1181 | void giet_heap_info( unsigned int* vaddr, |
---|
[368] | 1182 | unsigned int* length, |
---|
| 1183 | unsigned int x, |
---|
| 1184 | unsigned int y ) |
---|
[258] | 1185 | { |
---|
[709] | 1186 | sys_call( SYSCALL_HEAP_INFO, |
---|
| 1187 | (unsigned int)vaddr, |
---|
| 1188 | (unsigned int)length, |
---|
| 1189 | x, |
---|
| 1190 | y ); |
---|
[258] | 1191 | } |
---|
| 1192 | |
---|
[390] | 1193 | ///////////////////////////////////////// |
---|
| 1194 | void giet_get_xy( void* ptr, |
---|
| 1195 | unsigned int* px, |
---|
| 1196 | unsigned int* py ) |
---|
| 1197 | { |
---|
| 1198 | if ( sys_call( SYSCALL_GET_XY, |
---|
| 1199 | (unsigned int)ptr, |
---|
| 1200 | (unsigned int)px, |
---|
| 1201 | (unsigned int)py, |
---|
[709] | 1202 | 0 ) ) giet_pthread_exit("error in giet_get_xy()"); |
---|
[390] | 1203 | } |
---|
| 1204 | |
---|
[258] | 1205 | // Local Variables: |
---|
| 1206 | // tab-width: 4 |
---|
| 1207 | // c-basic-offset: 4 |
---|
| 1208 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 1209 | // indent-tabs-mode: nil |
---|
| 1210 | // End: |
---|
| 1211 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 1212 | |
---|