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