Changeset 743 for soft/giet_vm/giet_libs/stdio.c
- Timestamp:
- Dec 12, 2015, 7:10:24 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/stdio.c
r735 r743 1 ////////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////////////// 2 2 // File : stdio.c 3 3 // Date : 01/04/2010 4 4 // Author : alain greiner & Joel Porquet 5 5 // Copyright (c) UPMC-LIP6 6 ////////////////////////////////////////////////////////////////////////////// 6 ///////////////////////////////////////////////////////////////////////////////////// 7 7 8 8 #include <stdarg.h> … … 10 10 #include <giet_config.h> 11 11 12 ////////////////////////////////////////////////////////////////////////////// 13 // MIPS32 related system calls 14 ////////////////////////////////////////////////////////////////////////////// 15 16 //////////////////////////////////////////// 17 void giet_proc_xyp( unsigned int* cluster_x, 18 unsigned int* cluster_y, 19 unsigned int* lpid ) 20 { 21 sys_call( SYSCALL_PROC_XYP, 22 (unsigned int)cluster_x, 23 (unsigned int)cluster_y, 24 (unsigned int)lpid, 25 0 ); 26 } 27 28 //////////////////////////// 29 unsigned int giet_proctime() 30 { 31 return (unsigned int)sys_call( SYSCALL_PROC_TIME, 32 0, 0, 0, 0 ); 33 } 34 35 //////////////////////// 36 unsigned int giet_rand() 37 { 38 unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME, 39 0, 0, 0, 0); 40 if ((x & 0xF) > 7) 41 { 42 return (x*x & 0xFFFF); 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 } 43 45 } 44 else 45 { 46 return (x*x*x & 0xFFFF); 47 } 48 } 49 50 ////////////////////////////////////////////////////////////////////////////// 51 // Threads related system calls 52 ////////////////////////////////////////////////////////////////////////////// 53 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 ) 63 { 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 ); 77 } 78 79 //////////////////////////////////////// 80 int giet_pthread_join( pthread_t trdid, 81 void** ptr ) 82 { 83 return sys_call( SYSCALL_PTHREAD_JOIN, 84 trdid, 85 (unsigned int)ptr, 86 0, 0 ); 87 } 88 89 /////////////////////////////////////// 90 int giet_pthread_kill( pthread_t trdid, 91 int signal ) 92 { 93 return sys_call( SYSCALL_PTHREAD_KILL, 94 trdid, 95 signal, 96 0, 0 ); 97 } 98 99 ///////////////////////// 100 void giet_pthread_yield() 101 { 102 sys_call( SYSCALL_PTHREAD_YIELD, 103 0, 0, 0, 0 ); 104 } 105 106 ///////////////////////////////////////////////// 107 void giet_pthread_assert( unsigned int condition, 108 char* string ) 109 { 110 if ( condition == 0 ) giet_pthread_exit( string ); 111 } 112 113 //////////////////////////////////////////////// 114 void giet_pthread_control( unsigned int command, 115 char* vspace_name, 116 char* thread_name ) 117 { 118 int ret = sys_call( SYSCALL_PTHREAD_CONTROL, 119 command, 120 (unsigned int) vspace_name, 121 (unsigned int) thread_name, 122 0 ); 123 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 } 144 } 145 146 147 ////////////////////////////////////////////////////////////////////////////// 148 // Applications related system calls 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 167 /////////////////////////////////////////// 168 void giet_applications_status( char* name ) 169 { 170 sys_call( SYSCALL_APPS_STATUS, 171 (unsigned int)name, 172 0, 0, 0 ); 173 } 174 175 ////////////////////////////////////////////////////////////////////////////// 176 // Coprocessors related system calls 177 ////////////////////////////////////////////////////////////////////////////// 178 179 /////////////////////////////////////////////////// 180 void giet_coproc_alloc( unsigned int cluster_xy, 181 unsigned int coproc_type, 182 unsigned int* coproc_info ) 183 { 184 if ( sys_call( SYSCALL_COPROC_ALLOC, 185 cluster_xy, 186 coproc_type, 187 (unsigned int)coproc_info, 188 0 ) ) 189 giet_pthread_exit("error in giet_coproc_alloc()"); 190 } 191 192 ////////////////////////////////////////////////// 193 void giet_coproc_release( unsigned int cluster_xy, 194 unsigned int coproc_type ) 195 { 196 if ( sys_call( SYSCALL_COPROC_RELEASE, 197 cluster_xy, 198 coproc_type, 199 0 , 0 ) ) 200 giet_pthread_exit("error in giet_coproc_release()"); 201 } 202 203 ////////////////////////////////////////////////////////////////// 204 void giet_coproc_channel_init( unsigned int cluster_xy, 205 unsigned int coproc_type, 206 unsigned int channel, 207 giet_coproc_channel_t* desc ) 208 { 209 if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT, 210 cluster_xy, 211 coproc_type, 212 channel, 213 (unsigned int)desc ) ) 214 giet_pthread_exit("error in giet_coproc_channel_init()"); 215 } 216 217 ////////////////////////////////////////////// 218 void giet_coproc_run( unsigned int cluster_xy, 219 unsigned int coproc_type ) 220 { 221 if ( sys_call( SYSCALL_COPROC_RUN, 222 cluster_xy, 223 coproc_type, 224 0 , 0 ) ) 225 giet_pthread_exit("error in giet_coproc_run()"); 226 } 227 228 //////////////////////////////////////////////////// 229 void giet_coproc_completed( unsigned int cluster_xy, 230 unsigned int coproc_type ) 231 { 232 if ( sys_call( SYSCALL_COPROC_COMPLETED, 233 cluster_xy, 234 coproc_type, 235 0 , 0 ) ) 236 giet_pthread_exit("error in giet_coproc_completed"); 237 } 238 239 240 ////////////////////////////////////////////////////////////////////////////// 241 // TTY device related system calls 242 ////////////////////////////////////////////////////////////////////////////// 243 244 ////////////////////////////////////////// 245 void giet_tty_alloc( unsigned int shared ) 246 { 247 if ( sys_call( SYSCALL_TTY_ALLOC, 248 shared, 249 0, 0, 0 ) ) giet_pthread_exit("error in giet_tty_alloc()"); 250 } 251 252 //////////////////////////////////////////////////////////////////////// 253 static int __printf( char* format, unsigned int channel, va_list* args) 254 { 255 int ret; // return value from the syscall 256 enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers; 257 258 printf_text: 259 260 while (*format) 261 { 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, 270 0); 271 272 if (ret != i) goto return_error; 273 274 format += i; 275 } 276 if (*format == '%') 277 { 278 format++; 279 modifiers = NO_MOD; 280 goto printf_arguments; 281 } 282 } 283 284 return 0; 285 286 printf_arguments: 287 288 { 289 char buf[30]; 290 char * pbuf; 291 unsigned int len = 0; 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 292 55 static const char HexaTab[] = "0123456789ABCDEF"; 293 56 unsigned int i; 294 57 295 / * Ignored fields : width and precision */296 for ( ; *format >= '0' && *format <= '9'; format++);297 298 switch (*format ++)299 { 300 case (' %'):58 // Ignore fields width and precision 59 for ( ; *format >= '0' && *format <= '9'; format++ ); 60 61 switch (*format) 62 { 63 case ('c'): // char conversion 301 64 { 302 len = 1; 303 pbuf = "%"; 65 int val = va_arg( *args, int ); 66 buf[0] = val; 67 pbuf = buf; 68 len = 1; 304 69 break; 305 70 } 306 case (' c'): /* char conversion */71 case ('d'): // decimal signed integer 307 72 { 308 73 int val = va_arg( *args, int ); 309 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning310 311 len = 1;312 buf[0] = val;313 pbuf = &buf[0];314 break;315 }316 case ('d'): /* decimal signed integer */317 {318 int val = va_arg( *args, int );319 320 if (modifiers == LL_MOD) goto return_error; // 64 bits not supported321 322 74 if (val < 0) 323 75 { 76 TO_STREAM( '-' ); 324 77 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 78 } 332 79 for(i = 0; i < 10; i++) 333 80 { 81 334 82 buf[9 - i] = HexaTab[val % 10]; 335 83 if (!(val /= 10)) break; … … 339 87 break; 340 88 } 341 case ('u'): / * decimal unsigned integer */89 case ('u'): // decimal unsigned integer 342 90 { 343 if (modifiers != LL_MOD) //32 bits integer 344 { 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; 354 } 355 //64 bits : base 10 unsupported : continue to hexa 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; 356 100 } 357 case ('x'): 358 case (' X'): /* hexadecimal integer */101 case ('x'): // 32 bits hexadecimal 102 case ('l'): // 64 bits hexadecimal 359 103 { 104 unsigned int imax; 360 105 unsigned long long val; 361 int imax; 362 363 if (modifiers == LL_MOD) // 64 bits 106 107 if ( *format == 'l' ) // 64 bits 364 108 { 365 109 val = va_arg( *args, unsigned long long); 366 367 // if asked to print in base 10, can do only if it fits in 32 bits368 if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL)))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 110 imax = 16; 383 111 } 384 else //32 bits112 else // 32 bits 385 113 { 386 114 val = va_arg( *args, unsigned int); … … 388 116 } 389 117 390 ret = sys_call(SYSCALL_TTY_WRITE, 391 (unsigned int)"0x", 392 2, 393 channel, 394 0); 395 if (ret != 2) goto return_error; 118 TO_STREAM( '0' ); 119 TO_STREAM( 'x' ); 396 120 397 121 for(i = 0; i < imax; i++) … … 407 131 { 408 132 char* str = va_arg( *args, char* ); 409 410 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning 411 412 while (str[len]) 413 { 414 len++; 415 } 133 while (str[len]) { len++; } 416 134 pbuf = str; 417 135 break; … … 419 137 case ('e'): 420 138 case ('f'): 421 case ('g'): / * IEEE754 64 bits */139 case ('g'): // IEEE754 64 bits 422 140 { 423 141 union … … 429 147 val.d = va_arg( *args, double ); 430 148 431 unsigned long long digits = val.ull & 0xFFFFFFFFFFFFFULL; //get mantissa 432 433 unsigned int 434 base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52), //get exposant 435 intp = (unsigned int)val.d, //get integer part of the float 436 decp; 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 437 159 438 160 int isvalue = 0; 439 161 440 if (base == 0x7FF) // special value441 { 442 if (digits & 0xFFFFFFFFFFFFFULL) 162 if (base == 0x7FF) // special values 163 { 164 if (digits & 0xFFFFFFFFFFFFFULL) // Not a Number 443 165 { 444 /* Not a Number */445 166 buf[0] = 'N'; 446 167 buf[1] = 'a'; … … 449 170 pbuf = buf; 450 171 } 451 else 172 else // infinite 452 173 { 453 174 /* inf */ … … 462 183 } 463 184 464 if (val.ull & 0x8000000000000000ULL) 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; 185 if (val.ull & 0x8000000000000000ULL) // negative 186 { 187 TO_STREAM( '-' ); 473 188 val.d = val.d * -1; 474 189 } 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 486 if (val.d > 0xFFFFFFFF) 487 { 488 /* overflow */ 190 else // positive 191 { 192 TO_STREAM( '+' ); 193 } 194 195 if (val.d > 0xFFFFFFFF) // overflow 196 { 489 197 buf[0] = 'B'; 490 198 buf[1] = 'I'; … … 517 225 if (!isvalue) 518 226 { 519 if (val.d != 0) 227 if (val.d != 0) // underflow 520 228 { 521 /* underflow */522 229 buf[0] = 'T'; 523 230 buf[1] = 'I'; … … 531 238 break; 532 239 } 533 case ('l'):534 switch (modifiers)535 {536 case NO_MOD:537 modifiers = L_MOD;538 goto printf_arguments;539 240 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 551 default: 552 goto return_error; 553 } 554 555 ret = sys_call(SYSCALL_TTY_WRITE, 556 (unsigned int)pbuf, 557 len, 558 channel, 559 0); 560 if (ret != len) goto return_error; 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 } 561 254 562 goto printf_text;255 goto xprintf_text; 563 256 } 564 257 565 return_error: 566 return 1; 567 } // end __printf() 568 258 } // end xprintf() 259 260 261 ////////////////////////////////////////////////////////////////////////////// 262 // MIPS32 related system calls 263 ////////////////////////////////////////////////////////////////////////////// 264 265 //////////////////////////////////////////// 266 void giet_proc_xyp( unsigned int* cluster_x, 267 unsigned int* cluster_y, 268 unsigned int* lpid ) 269 { 270 sys_call( SYSCALL_PROC_XYP, 271 (unsigned int)cluster_x, 272 (unsigned int)cluster_y, 273 (unsigned int)lpid, 274 0 ); 275 } 276 277 //////////////////////////// 278 unsigned int giet_proctime() 279 { 280 return (unsigned int)sys_call( SYSCALL_PROC_TIME, 281 0, 0, 0, 0 ); 282 } 283 284 //////////////////////// 285 unsigned int giet_rand() 286 { 287 unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME, 288 0, 0, 0, 0); 289 if ((x & 0xF) > 7) 290 { 291 return (x*x & 0xFFFF); 292 } 293 else 294 { 295 return (x*x*x & 0xFFFF); 296 } 297 } 298 299 ////////////////////////////////////////////////////////////////////////////// 300 // Threads related system calls 301 ////////////////////////////////////////////////////////////////////////////// 302 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 ) 312 { 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 ); 326 } 327 328 //////////////////////////////////////// 329 int giet_pthread_join( pthread_t trdid, 330 void** ptr ) 331 { 332 return sys_call( SYSCALL_PTHREAD_JOIN, 333 trdid, 334 (unsigned int)ptr, 335 0, 0 ); 336 } 337 338 /////////////////////////////////////// 339 int giet_pthread_kill( pthread_t trdid, 340 int signal ) 341 { 342 return sys_call( SYSCALL_PTHREAD_KILL, 343 trdid, 344 signal, 345 0, 0 ); 346 } 347 348 ///////////////////////// 349 void giet_pthread_yield() 350 { 351 sys_call( SYSCALL_PTHREAD_YIELD, 352 0, 0, 0, 0 ); 353 } 354 355 ///////////////////////////////////////////////// 356 void giet_pthread_assert( unsigned int condition, 357 char* string ) 358 { 359 if ( condition == 0 ) giet_pthread_exit( string ); 360 } 361 362 //////////////////////////////////////////////// 363 void giet_pthread_control( unsigned int command, 364 char* vspace_name, 365 char* thread_name ) 366 { 367 int ret = sys_call( SYSCALL_PTHREAD_CONTROL, 368 command, 369 (unsigned int) vspace_name, 370 (unsigned int) thread_name, 371 0 ); 372 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 } 393 } 394 395 396 ////////////////////////////////////////////////////////////////////////////// 397 // Applications related system calls 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 416 /////////////////////////////////////////// 417 void giet_applications_status( char* name ) 418 { 419 sys_call( SYSCALL_APPS_STATUS, 420 (unsigned int)name, 421 0, 0, 0 ); 422 } 423 424 ////////////////////////////////////////////////////////////////////////////// 425 // Coprocessors related system calls 426 ////////////////////////////////////////////////////////////////////////////// 427 428 /////////////////////////////////////////////////// 429 void giet_coproc_alloc( unsigned int cluster_xy, 430 unsigned int coproc_type, 431 unsigned int* coproc_info ) 432 { 433 if ( sys_call( SYSCALL_COPROC_ALLOC, 434 cluster_xy, 435 coproc_type, 436 (unsigned int)coproc_info, 437 0 ) ) 438 giet_pthread_exit("error in giet_coproc_alloc()"); 439 } 440 441 ////////////////////////////////////////////////// 442 void giet_coproc_release( unsigned int cluster_xy, 443 unsigned int coproc_type ) 444 { 445 if ( sys_call( SYSCALL_COPROC_RELEASE, 446 cluster_xy, 447 coproc_type, 448 0 , 0 ) ) 449 giet_pthread_exit("error in giet_coproc_release()"); 450 } 451 452 ////////////////////////////////////////////////////////////////// 453 void giet_coproc_channel_init( unsigned int cluster_xy, 454 unsigned int coproc_type, 455 unsigned int channel, 456 giet_coproc_channel_t* desc ) 457 { 458 if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT, 459 cluster_xy, 460 coproc_type, 461 channel, 462 (unsigned int)desc ) ) 463 giet_pthread_exit("error in giet_coproc_channel_init()"); 464 } 465 466 ////////////////////////////////////////////// 467 void giet_coproc_run( unsigned int cluster_xy, 468 unsigned int coproc_type ) 469 { 470 if ( sys_call( SYSCALL_COPROC_RUN, 471 cluster_xy, 472 coproc_type, 473 0 , 0 ) ) 474 giet_pthread_exit("error in giet_coproc_run()"); 475 } 476 477 //////////////////////////////////////////////////// 478 void giet_coproc_completed( unsigned int cluster_xy, 479 unsigned int coproc_type ) 480 { 481 if ( sys_call( SYSCALL_COPROC_COMPLETED, 482 cluster_xy, 483 coproc_type, 484 0 , 0 ) ) 485 giet_pthread_exit("error in giet_coproc_completed"); 486 } 487 488 489 ////////////////////////////////////////////////////////////////////////////// 490 // TTY device related system calls 491 ////////////////////////////////////////////////////////////////////////////// 492 493 ////////////////////////////////////////// 494 void giet_tty_alloc( unsigned int shared ) 495 { 496 if ( sys_call( SYSCALL_TTY_ALLOC, 497 shared, 498 0, 0, 0 ) ) giet_pthread_exit("error in giet_tty_alloc()"); 499 } 569 500 570 501 //////////////////////////////////////// 571 502 void giet_tty_printf( char* format, ...) 572 503 { 573 va_list args; 504 va_list args; 505 char stream[4096]; 506 unsigned int length; 574 507 575 508 va_start( args, format ); 576 int ret = __printf(format, 0xFFFFFFFF, &args);509 length = xprintf( stream, 4096, format, &args ); 577 510 va_end( args ); 578 511 579 if (ret) 580 { 581 giet_pthread_exit("error in giet_tty_printf()"); 582 } 583 } // end giet_tty_printf() 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()"); 519 520 } 584 521 585 522 ///////////////////////////////// … … 664 601 buf[index] = 0; 665 602 666 } // end giet_tty_gets()603 } 667 604 668 605 /////////////////////////////////////// … … 778 715 *val = 0; 779 716 } 780 } // end giet_tty_getw()717 } 781 718 782 719 … … 1126 1063 } 1127 1064 1128 //////////////////////////////////// 1065 ////////////////////////////////////////// 1129 1066 int giet_fat_readdir( unsigned int fd_id, 1130 1067 fat_dirent_t* entry ) … … 1136 1073 } 1137 1074 1075 ///////////////////////////////////////// 1076 int giet_fat_fprintf( unsigned int fd_id, 1077 char* format, 1078 ... ); 1079 { 1080 va_list args; 1081 char stream[4096]; 1082 unsigned int length; 1083 1084 va_start( args, format ); 1085 count = xprintf( stream, 4096, format, &args ); 1086 va_end( args ); 1087 1088 if ( length == 0xFFFFFFFF ) giet_pthread_exit("illegal format in giet_fat_fprintf()"); 1089 1090 return sys_call( SYSCALL_FAT_WRITE, 1091 fd_id, 1092 (unsigned int)stream, 1093 count, 1094 0 ); // no physical addressing required 1095 } 1138 1096 1139 1097
Note: See TracChangeset
for help on using the changeset viewer.