Changeset 228 for soft/giet_vm/libs/stdio.c
- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/libs/stdio.c
r218 r228 21 21 #define SYSCALL_GCD_WRITE 0x06 22 22 #define SYSCALL_GCD_READ 0x07 23 #define SYSCALL_TASK_ID 0x09 23 24 #define SYSCALL_CTX_SWITCH 0x0D 24 25 #define SYSCALL_EXIT 0x0E … … 32 33 #define SYSCALL_IOC_READ 0x16 33 34 #define SYSCALL_IOC_COMPLETED 0x17 34 #define SYSCALL_VOBJ_GET_VBASE 35 #define SYSCALL_VOBJ_GET_VBASE 0x1A 35 36 #define SYSCALL_NIC_WRITE 0x1B 36 37 #define SYSCALL_NIC_READ 0x1C … … 43 44 // and tells GCC what has been modified by system call execution. 44 45 ////////////////////////////////////////////////////////////////////////////////// 45 static inline unsigned int sys_call( unsigned int call_no, 46 unsigned int arg_0, 47 unsigned int arg_1, 48 unsigned int arg_2, 49 unsigned int arg_3) 50 { 46 static inline unsigned int sys_call(unsigned int call_no, 47 unsigned int arg_0, 48 unsigned int arg_1, 49 unsigned int arg_2, 50 unsigned int arg_3) { 51 51 register unsigned int reg_no_and_output asm("v0") = call_no; 52 register unsigned int reg_a0 53 register unsigned int reg_a1 54 register unsigned int reg_a2 55 register unsigned int reg_a3 52 register unsigned int reg_a0 asm("a0") = arg_0; 53 register unsigned int reg_a1 asm("a1") = arg_1; 54 register unsigned int reg_a2 asm("a2") = arg_2; 55 register unsigned int reg_a3 asm("a3") = arg_3; 56 56 57 57 asm volatile( … … 59 59 : "=r" (reg_no_and_output) /* output argument */ 60 60 : "r" (reg_a0), /* input arguments */ 61 62 63 64 61 "r" (reg_a1), 62 "r" (reg_a2), 63 "r" (reg_a3), 64 "r" (reg_no_and_output) 65 65 : "memory", 66 66 /* These persistant registers will be saved on the stack by the … … 83 83 } 84 84 85 ///// 85 ///// MIPS32 related system calls ///// 86 86 87 87 //////////////////////////////////////////////////////////////////////////////////// … … 90 90 // This function returns the processor identifier. 91 91 //////////////////////////////////////////////////////////////////////////////////// 92 unsigned int giet_procid() 93 { 94 return sys_call(SYSCALL_PROCID, 95 0, 0, 0, 0); 96 } 92 unsigned int giet_procid() { 93 return sys_call(SYSCALL_PROCID, 0, 0, 0, 0); 94 } 95 96 97 97 //////////////////////////////////////////////////////////////////////////////////// 98 98 // giet_proctime() … … 100 100 // This function returns the local processor time (clock cycles since boot) 101 101 //////////////////////////////////////////////////////////////////////////////////// 102 unsigned int giet_proctime() 103 { 104 return sys_call(SYSCALL_PROCTIME, 105 0, 0, 0, 0); 106 } 107 108 ////// TTY device related system calls ///// 102 unsigned int giet_proctime() { 103 return sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 104 } 105 106 107 ////// TTY device related system calls ///// 109 108 110 109 //////////////////////////////////////////////////////////////////////////////////// … … 116 115 // - Returns 1 if the character has been written, 0 otherwise. 117 116 //////////////////////////////////////////////////////////////////////////////////// 118 unsigned int giet_tty_putc(char byte) 119 { 120 return sys_call(SYSCALL_TTY_WRITE, 121 (unsigned int)(&byte), 122 1, 123 0,0); 124 } 117 unsigned int giet_tty_putc(char byte) { 118 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) (&byte), 1, 0, 0); 119 } 120 121 125 122 //////////////////////////////////////////////////////////////////////////////////// 126 123 // giet_tty_puts() … … 132 129 // - Returns the number of written characters. 133 130 //////////////////////////////////////////////////////////////////////////////////// 134 unsigned int giet_tty_puts(char *buf) 135 { 131 unsigned int giet_tty_puts(char * buf) { 136 132 unsigned int length = 0; 137 while (buf[length] != 0) 138 { 133 while (buf[length] != 0) { 139 134 length++; 140 135 } 141 return sys_call(SYSCALL_TTY_WRITE, 142 (unsigned int)buf, 143 length, 144 0,0); 145 } 136 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) buf, length, 0, 0); 137 } 138 139 146 140 //////////////////////////////////////////////////////////////////////////////////// 147 141 // giet_tty_putw() … … 152 146 // Returns the number of written characters (should be equal to ten). 153 147 //////////////////////////////////////////////////////////////////////////////////// 154 unsigned int giet_tty_putw(unsigned int val) 155 { 148 unsigned int giet_tty_putw(unsigned int val) { 156 149 char buf[10]; 157 150 unsigned int i; 158 for (i = 0; i < 10; i++) 159 { 160 buf[9-i] = (val % 10) + 0x30; 151 for (i = 0; i < 10; i++) { 152 buf[9 - i] = (val % 10) + 0x30; 161 153 val = val / 10; 162 154 } 163 return sys_call(SYSCALL_TTY_WRITE, 164 (unsigned int)buf, 165 10, 166 0,0); 167 } 155 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) buf, 10, 0, 0); 156 } 157 158 168 159 //////////////////////////////////////////////////////////////////////////////////// 169 160 // giet_tty_getc() … … 174 165 // - Returns 0 when completed. 175 166 //////////////////////////////////////////////////////////////////////////////////// 176 unsigned int giet_tty_getc(char *byte) 177 { 167 unsigned int giet_tty_getc(char * byte) { 178 168 unsigned int ret = 0; 179 while (ret == 0) 180 { 181 ret = sys_call(SYSCALL_TTY_READ, 182 (unsigned int)byte, 183 1, 184 0,0); 169 while (ret == 0) { 170 ret = sys_call(SYSCALL_TTY_READ, (unsigned int)byte, 1, 0, 0); 185 171 } 186 172 return 0; 187 173 } 174 175 188 176 //////////////////////////////////////////////////////////////////////////////////// 189 177 // giet_tty_gets() … … 201 189 // removed from the target buffer. 202 190 //////////////////////////////////////////////////////////////////////////////////// 203 unsigned int giet_tty_gets( char* buf, 204 unsigned int bufsize ) 205 { 191 unsigned int giet_tty_gets(char * buf, unsigned int bufsize) { 206 192 unsigned int ret; 207 193 unsigned char byte; 208 194 unsigned int index = 0; 209 195 210 while (index < (bufsize - 1)) 211 { 196 while (index < (bufsize - 1)) { 212 197 do { 213 ret = sys_call(SYSCALL_TTY_READ, 214 (unsigned int)(&byte), 215 1, 216 0,0); 198 ret = sys_call(SYSCALL_TTY_READ, (unsigned int) (&byte), 1, 0, 0); 217 199 } while (ret != 1); 218 200 219 if ( byte == 0x0A )201 if (byte == 0x0A) { 220 202 break; /* LF */ 221 else if ((byte == 0x7F) && (index > 0)) 203 } 204 else if ((byte == 0x7F) && (index > 0)) { 222 205 index--; /* DEL */ 223 else224 {206 } 207 else { 225 208 buf[index] = byte; 226 209 index++; … … 230 213 return 0; 231 214 } 215 216 232 217 //////////////////////////////////////////////////////////////////////////////////// 233 218 // giet_tty_getw() … … 248 233 // bits range, the zero value is returned. 249 234 //////////////////////////////////////////////////////////////////////////////////// 250 unsigned int giet_tty_getw(unsigned int *val) 251 { 235 unsigned int giet_tty_getw(unsigned int * val) { 252 236 unsigned char buf[32]; 253 237 unsigned char byte; … … 260 244 unsigned int ret; 261 245 262 while (done == 0) 263 { 246 while (done == 0) { 264 247 do { 265 ret = sys_call(SYSCALL_TTY_READ, 266 (unsigned int)(&byte), 267 1, 268 0,0); 248 ret = sys_call(SYSCALL_TTY_READ, (unsigned int) (&byte), 1, 0, 0); 269 249 } while (ret != 1); 270 250 271 if ((byte > 0x2F) && (byte < 0x3A)) /* decimal character */272 {251 if ((byte > 0x2F) && (byte < 0x3A)) { 252 /* decimal character */ 273 253 buf[max] = byte; 274 254 max++; 275 255 giet_tty_putc(byte); 276 256 } 277 else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */278 {257 else if ((byte == 0x0A) || (byte == 0x0D)) { 258 /* LF or CR character */ 279 259 done = 1; 280 260 } 281 else if (byte == 0x7F) /* DEL character */ 282 { 283 if (max > 0) 284 { 261 else if (byte == 0x7F) { 262 /* DEL character */ 263 if (max > 0) { 285 264 max--; /* cancel the character */ 286 265 giet_tty_putc(0x08); … … 289 268 } 290 269 } 291 if (max == 32) /* decimal string overflow */292 {293 for (i = 0; i < max; i++) /* cancel the string */294 {270 if (max == 32) { 271 /* decimal string overflow */ 272 for (i = 0; i < max; i++) { 273 /* cancel the string */ 295 274 giet_tty_putc(0x08); 296 275 giet_tty_putc(0x20); … … 304 283 305 284 /* string conversion */ 306 for (i = 0; i < max; i++) 307 { 285 for (i = 0; i < max; i++) { 308 286 dec = dec * 10 + (buf[i] - 0x30); 309 if (dec < save) 287 if (dec < save) { 310 288 overflow = 1; 289 } 311 290 save = dec; 312 291 } 313 292 314 293 /* check overflow */ 315 if (overflow == 0) 316 { 294 if (overflow == 0) { 317 295 *val = dec; /* return decimal value */ 318 296 } 319 else 320 { 321 for (i = 0; i < max; i++) /* cancel the string */ 322 { 297 else { 298 for (i = 0; i < max; i++) { 299 /* cancel the string */ 323 300 giet_tty_putc(0x08); 324 301 giet_tty_putc(0x20); … … 330 307 return 0; 331 308 } 309 310 332 311 //////////////////////////////////////////////////////////////////////////////////// 333 312 // giet_tty_printf() … … 344 323 // - Returns 0 if success, > 0 if error. 345 324 //////////////////////////////////////////////////////////////////////////////////// 346 unsigned int giet_tty_printf(char *format, ...) 347 { 325 unsigned int giet_tty_printf(char * format, ...) { 348 326 va_list ap; 349 327 va_start(ap, format); … … 354 332 while (*format) { 355 333 unsigned int i; 356 for (i = 0; format[i] && format[i] != '%'; i++) 357 ; 334 for (i = 0; format[i] && format[i] != '%'; i++); 358 335 if (i) { 359 ret = sys_call(SYSCALL_TTY_WRITE, 360 (unsigned int)format, 361 i, 362 0,0); 363 if (ret != i) 336 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) format, i, 0, 0); 337 if (ret != i) { 364 338 return 1; /* return error */ 339 } 365 340 format += i; 366 341 } … … 377 352 378 353 { 379 int 380 char 381 char *pbuf;382 unsigned int 383 static const char 384 unsigned int 354 int val = va_arg(ap, long); 355 char buf[20]; 356 char * pbuf; 357 unsigned int len = 0; 358 static const char HexaTab[] = "0123456789ABCDEF"; 359 unsigned int i; 385 360 386 361 switch (*format++) { … … 393 368 if (val < 0) { 394 369 val = -val; 395 ret = sys_call(SYSCALL_TTY_WRITE, 396 (unsigned int)"-", 397 1, 398 0,0); 399 if (ret != 1) 370 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int)"-", 1, 0, 0); 371 if (ret != 1) { 400 372 return 1; /* return error */ 373 } 401 374 } 402 375 case ('u'): /* decimal unsigned integer */ 403 for( i=0 ; i<10 ; i++) { 404 buf[9-i] = HexaTab[val % 10]; 405 if (!(val /= 10)) break; 376 for(i = 0; i < 10; i++) { 377 buf[9 - i] = HexaTab[val % 10]; 378 if (!(val /= 10)) { 379 break; 380 } 406 381 } 407 len = i +1;408 pbuf = &buf[9 -i];382 len = i + 1; 383 pbuf = &buf[9 - i]; 409 384 break; 410 385 case ('x'): /* hexadecimal integer */ 411 ret = sys_call(SYSCALL_TTY_WRITE, 412 (unsigned int)"0x", 413 2, 414 0,0); 415 if (ret != 2) 386 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) "0x", 2, 0, 0); 387 if (ret != 2) { 416 388 return 1; /* return error */ 417 for( i=0 ; i<8 ; i++) {418 buf[7-i] = HexaTab[val % 16U];419 if (!(val /= 16U)) break;420 389 } 421 len = i+1; 422 pbuf = &buf[7-i]; 390 for(i = 0; i < 8; i++) { 391 buf[7 - i] = HexaTab[val % 16U]; 392 if (!(val /= 16U)) { 393 break; 394 } 395 } 396 len = i + 1; 397 pbuf = &buf[7 - i]; 423 398 break; 424 399 case ('s'): /* string */ 425 400 { 426 char *str = (char*)val; 427 while ( str[len] ) len++; 428 pbuf = (char*)val; 401 char * str = (char *) val; 402 while (str[len]) { 403 len++; 404 } 405 pbuf = (char *) val; 429 406 } 430 407 break; … … 433 410 } 434 411 435 ret = sys_call(SYSCALL_TTY_WRITE, 436 (unsigned int)pbuf, 437 len, 438 0,0); 439 if (ret != len) 412 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) pbuf, len, 0, 0); 413 if (ret != len) { 440 414 return 1; 415 } 441 416 goto printf_text; 442 417 } … … 453 428 // - Returns 0 if success, > 0 if error. 454 429 ////////////////////////////////////////////////////////////////////////////////// 455 unsigned int giet_timer_start() 456 { 457 return sys_call(SYSCALL_TIMER_START, 458 0,0,0,0); 459 } 430 unsigned int giet_timer_start() { 431 return sys_call(SYSCALL_TIMER_START, 0, 0, 0, 0); 432 } 433 434 460 435 ////////////////////////////////////////////////////////////////////////////////// 461 436 // giet_timer_stop() … … 464 439 // - Returns 0 if success, > 0 if error. 465 440 ////////////////////////////////////////////////////////////////////////////////// 466 unsigned int giet_timer_stop() 467 { 468 return sys_call(SYSCALL_TIMER_STOP, 469 0,0,0,0); 470 } 441 unsigned int giet_timer_stop() { 442 return sys_call(SYSCALL_TIMER_STOP, 0, 0, 0, 0); 443 } 444 471 445 472 446 ///// GCD (Greatest Common Divider) related system calls … … 483 457 // - Returns 0 if success, > 0 if error. 484 458 ////////////////////////////////////////////////////////////////////////////////// 485 unsigned int giet_gcd_set_opa(unsigned int val) 486 { 487 return sys_call(SYSCALL_GCD_WRITE, 488 GCD_OPA, 489 val, 490 0, 0); 491 } 492 ////////////////////////////////////////////////////////////////////////////////// 493 // giet_gcd_set_opb() 459 unsigned int giet_gcd_set_opa(unsigned int val) { 460 return sys_call(SYSCALL_GCD_WRITE, GCD_OPA, val, 0, 0); 461 } 462 463 464 ////////////////////////////////////////////////////////////////////////////////// 465 // giet_gcd_set_opb() 494 466 ////////////////////////////////////////////////////////////////////////////////// 495 467 // This function sets operand B in the GCD coprocessor. 496 468 // - Returns 0 if success, > 0 if error. 497 469 ////////////////////////////////////////////////////////////////////////////////// 498 unsigned int giet_gcd_set_opb(unsigned int val) 499 { 500 return sys_call(SYSCALL_GCD_WRITE, 501 GCD_OPB, 502 val, 503 0, 0); 504 } 505 ////////////////////////////////////////////////////////////////////////////////// 506 // giet_gcd_start() 470 unsigned int giet_gcd_set_opb(unsigned int val) { 471 return sys_call(SYSCALL_GCD_WRITE, GCD_OPB, val, 0, 0); 472 } 473 474 475 ////////////////////////////////////////////////////////////////////////////////// 476 // giet_gcd_start() 507 477 ////////////////////////////////////////////////////////////////////////////////// 508 478 // This function starts the computation in the GCD coprocessor. 509 479 // - Returns 0 if success, > 0 if error. 510 480 ////////////////////////////////////////////////////////////////////////////////// 511 unsigned int giet_gcd_start() 512 { 513 return sys_call(SYSCALL_GCD_WRITE, 514 GCD_START, 515 0, 0, 0); 516 } 517 ////////////////////////////////////////////////////////////////////////////////// 518 // giet_gcd_get_status() 481 unsigned int giet_gcd_start() { 482 return sys_call(SYSCALL_GCD_WRITE, GCD_START, 0, 0, 0); 483 } 484 485 486 ////////////////////////////////////////////////////////////////////////////////// 487 // giet_gcd_get_status() 519 488 ////////////////////////////////////////////////////////////////////////////////// 520 489 // This function gets the status fromn the GCD coprocessor. 521 490 // - The value is 0 when the coprocessor is idle (computation completed). 522 491 ////////////////////////////////////////////////////////////////////////////////// 523 unsigned int giet_gcd_get_status(unsigned int *val) 524 { 525 return sys_call(SYSCALL_GCD_READ, 526 GCD_STATUS, 527 (unsigned int)val, 528 0, 0); 529 } 530 ////////////////////////////////////////////////////////////////////////////////// 531 // giet_gcd_get_result() 492 unsigned int giet_gcd_get_status(unsigned int * val) { 493 return sys_call(SYSCALL_GCD_READ, GCD_STATUS, (unsigned int) val, 0, 0); 494 } 495 496 497 ////////////////////////////////////////////////////////////////////////////////// 498 // giet_gcd_get_result() 532 499 ////////////////////////////////////////////////////////////////////////////////// 533 500 // This function gets the result of the computation from the GCD coprocessor. 534 501 ////////////////////////////////////////////////////////////////////////////////// 535 unsigned int giet_gcd_get_result(unsigned int *val) 536 { 537 return sys_call(SYSCALL_GCD_READ, 538 GCD_OPA, 539 (unsigned int)val, 540 0, 0); 541 } 502 unsigned int giet_gcd_get_result(unsigned int * val) { 503 return sys_call(SYSCALL_GCD_READ, GCD_OPA, (unsigned int) val, 0, 0); 504 } 505 542 506 543 507 ///// Block device related system calls ///// 544 508 545 509 ////////////////////////////////////////////////////////////////////////////////// 546 // 510 // giet_ioc_write() 547 511 ////////////////////////////////////////////////////////////////////////////////// 548 512 // Transfer data from a memory buffer to a file on the block_device. … … 552 516 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 553 517 ////////////////////////////////////////////////////////////////////////////////// 554 unsigned int giet_ioc_write( unsigned int lba, 555 void* buffer, 556 unsigned int count) 557 { 558 return sys_call(SYSCALL_IOC_WRITE, 559 lba, 560 (unsigned int)buffer, 561 count, 562 0); 563 } 518 unsigned int giet_ioc_write( unsigned int lba, void * buffer, unsigned int count) { 519 return sys_call(SYSCALL_IOC_WRITE, lba, (unsigned int) buffer, count, 0); 520 } 521 522 564 523 ////////////////////////////////////////////////////////////////////////////////// 565 524 // giet_ioc_read() … … 571 530 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 572 531 ////////////////////////////////////////////////////////////////////////////////// 573 unsigned int giet_ioc_read( unsigned int lba, 574 void* buffer, 575 unsigned int count ) 576 { 577 return sys_call(SYSCALL_IOC_READ, 578 lba, 579 (unsigned int)buffer, 580 count, 581 0); 582 } 532 unsigned int giet_ioc_read(unsigned int lba, void * buffer, unsigned int count) { 533 return sys_call(SYSCALL_IOC_READ, lba, (unsigned int) buffer, count, 0); 534 } 535 536 583 537 ////////////////////////////////////////////////////////////////////////////////// 584 538 // giet_ioc_completed() … … 587 541 // successfully completed, and returns 1 if an address error has been detected. 588 542 ////////////////////////////////////////////////////////////////////////////////// 589 unsigned int giet_ioc_completed() 590 { 591 return sys_call(SYSCALL_IOC_COMPLETED, 592 0, 0, 0, 0); 593 } 543 unsigned int giet_ioc_completed() { 544 return sys_call(SYSCALL_IOC_COMPLETED, 0, 0, 0, 0); 545 } 546 594 547 595 548 ///// Frame buffer device related system calls ///// … … 605 558 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 606 559 ////////////////////////////////////////////////////////////////////////////////// 607 unsigned int giet_fb_sync_write( unsigned int offset, 608 void* buffer, 609 unsigned int length ) 610 { 611 return sys_call(SYSCALL_FB_SYNC_WRITE, 612 offset, 613 (unsigned int)buffer, 614 length, 615 0); 616 } 560 unsigned int giet_fb_sync_write(unsigned int offset, void * buffer, unsigned int length) { 561 return sys_call(SYSCALL_FB_SYNC_WRITE, offset, (unsigned int) buffer, length, 0); 562 } 563 564 617 565 ////////////////////////////////////////////////////////////////////////////////// 618 566 // giet_fb_sync_read() … … 625 573 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 626 574 ////////////////////////////////////////////////////////////////////////////////// 627 unsigned int giet_fb_sync_read( unsigned int offset, 628 void* buffer, 629 unsigned int length ) 630 { 631 return sys_call(SYSCALL_FB_SYNC_READ, 632 offset, 633 (unsigned int)buffer, 634 length, 635 0); 636 } 575 unsigned int giet_fb_sync_read(unsigned int offset, void * buffer, unsigned int length) { 576 return sys_call(SYSCALL_FB_SYNC_READ, offset, (unsigned int) buffer, length, 0); 577 } 578 579 637 580 ////////////////////////////////////////////////////////////////////////////////// 638 581 // giet_fb_write() … … 647 590 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 648 591 ////////////////////////////////////////////////////////////////////////////////// 649 unsigned int giet_fb_write( unsigned int offset, 650 void* buffer, 651 unsigned int length ) 652 { 653 return sys_call(SYSCALL_FB_WRITE, 654 offset, 655 (unsigned int)buffer, 656 length, 657 0); 658 } 592 unsigned int giet_fb_write(unsigned int offset, void * buffer, unsigned int length) { 593 return sys_call(SYSCALL_FB_WRITE, offset, (unsigned int) buffer, length, 0); 594 } 595 596 659 597 ////////////////////////////////////////////////////////////////////////////////// 660 598 // giet_fb_read() … … 669 607 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 670 608 ////////////////////////////////////////////////////////////////////////////////// 671 unsigned int giet_fb_read( unsigned int offset, 672 void* buffer, 673 unsigned int length ) 674 { 675 return sys_call(SYSCALL_FB_READ, 676 offset, 677 (unsigned int)buffer, 678 length, 679 0); 680 } 609 unsigned int giet_fb_read(unsigned int offset, void * buffer, unsigned int length) { 610 return sys_call(SYSCALL_FB_READ, offset, (unsigned int) buffer, length, 0); 611 } 612 613 681 614 ////////////////////////////////////////////////////////////////////////////////// 682 615 // giet_fb_completed() … … 685 618 // - Returns 0 if success, > 0 if error. 686 619 ////////////////////////////////////////////////////////////////////////////////// 687 unsigned int giet_fb_completed() 688 { 689 return sys_call(SYSCALL_FB_COMPLETED, 690 0, 0, 0, 0); 691 } 620 unsigned int giet_fb_completed() { 621 return sys_call(SYSCALL_FB_COMPLETED, 0, 0, 0, 0); 622 } 623 692 624 693 625 ////////////////////////////////////////////////////////////////////////////////// … … 704 636 ////////////////////////////////////////////////////////////////////////////////// 705 637 706 unsigned int giet_nic_write( unsigned int offset, 707 void* buffer, 708 unsigned int length ) 709 { 710 return sys_call(SYSCALL_NIC_WRITE, 711 offset, 712 (unsigned int)buffer, 713 length, 714 0); 715 } 638 unsigned int giet_nic_write(unsigned int offset, void * buffer, unsigned int length) { 639 return sys_call(SYSCALL_NIC_WRITE, offset, (unsigned int) buffer, length, 0); 640 } 641 716 642 717 643 ////////////////////////////////////////////////////////////////////////////////// … … 728 654 ////////////////////////////////////////////////////////////////////////////////// 729 655 730 unsigned int giet_nic_read( unsigned int offset, 731 void* buffer, 732 unsigned int length ) 733 { 734 return sys_call(SYSCALL_NIC_READ, 735 offset, 736 (unsigned int)buffer, 737 length, 738 0); 739 } 656 unsigned int giet_nic_read(unsigned int offset, void * buffer, unsigned int length) { 657 return sys_call(SYSCALL_NIC_READ, offset, (unsigned int) buffer, length, 0); 658 } 659 740 660 741 661 ////////////////////////////////////////////////////////////////////////////////// … … 745 665 // - Returns 0 if success, > 0 if error. 746 666 ////////////////////////////////////////////////////////////////////////////////// 747 unsigned int giet_nic_completed() 748 { 749 return sys_call(SYSCALL_NIC_COMPLETED, 750 0, 0, 0, 0); 751 } 667 unsigned int giet_nic_completed() { 668 return sys_call(SYSCALL_NIC_COMPLETED, 0, 0, 0, 0); 669 } 670 752 671 753 672 ///// Miscellaneous related system calls ///// … … 762 681 // - Returns the address if success, 0 if error ( not defined or wrong type ) 763 682 ////////////////////////////////////////////////////////////////////////////////// 764 unsigned int giet_vobj_get_vbase( char* vspace_name, 765 char* vobj_name, 766 unsigned int vobj_type, 767 unsigned int* vobj_vaddr ) 768 { 683 unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr) { 769 684 return sys_call(SYSCALL_VOBJ_GET_VBASE, 770 (unsigned int)vspace_name, 771 (unsigned int)vobj_name, 772 (unsigned int)vobj_type, 773 (unsigned int)vobj_vaddr); 774 } 685 (unsigned int) vspace_name, 686 (unsigned int) vobj_name, 687 (unsigned int) vobj_type, 688 (unsigned int) vobj_vaddr); 689 } 690 775 691 776 692 //////////////////////////////////////////////////////////////////////////////////// … … 781 697 // - Returns 0 if success, > 0 if error ( cluster index too large ) 782 698 //////////////////////////////////////////////////////////////////////////////////// 783 unsigned int giet_proc_number( unsigned int cluster_id, 784 unsigned int* buffer ) 785 { 786 return sys_call(SYSCALL_PROC_NUMBER, 787 cluster_id, 788 (unsigned int)buffer, 789 0, 0); 790 } 699 unsigned int giet_proc_number(unsigned int cluster_id, unsigned int * buffer) { 700 return sys_call(SYSCALL_PROC_NUMBER, cluster_id, (unsigned int) buffer, 0, 0); 701 } 702 791 703 792 704 ///// Miscellaneous system calls ///// … … 799 711 // The task is blocked, but it still consume processor cycles ... 800 712 ////////////////////////////////////////////////////////////////////////////////// 801 void giet_exit() 802 { 803 sys_call(SYSCALL_EXIT, 804 0, 0, 0, 0); 805 } 713 void giet_exit() { 714 sys_call(SYSCALL_EXIT, 0, 0, 0, 0); 715 } 716 717 806 718 /////////////////////////////////////////////////////////////////////////////////// 807 719 // giet_rand() … … 809 721 // count. This value is comprised between 0 & 65535. 810 722 /////////////////////////////////////////////////////////////////////////////////// 811 unsigned int giet_rand() 812 { 813 unsigned int x = sys_call(SYSCALL_PROCTIME, 814 0, 0, 0, 0); 815 if((x & 0xF) > 7) 723 unsigned int giet_rand() { 724 unsigned int x = sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 725 if ((x & 0xF) > 7) { 816 726 return (x*x & 0xFFFF); 817 else 727 } 728 else { 818 729 return (x*x*x & 0xFFFF); 819 } 820 ////////////////////////////////////////////////////////////////////////////////// 821 // giet_ctx_switch() 730 } 731 } 732 733 734 ////////////////////////////////////////////////////////////////////////////////// 735 // giet_context_switch() 822 736 // The user task calling this function is descheduled and 823 737 // the processor is allocated to another task. 824 738 ////////////////////////////////////////////////////////////////////////////////// 825 unsigned int giet_ctx_switch() 826 { 827 return sys_call(SYSCALL_CTX_SWITCH, 828 0, 0, 0, 0); 829 } 830 831 739 unsigned int giet_context_switch() { 740 return sys_call(SYSCALL_CTX_SWITCH, 0, 0, 0, 0); 741 } 742 743 ////////////////////////////////////////////////////////////////////////////////// 744 // giet_get_task_id() 745 // The user task calling this function is descheduled and 746 // the processor is allocated to another task. 747 ////////////////////////////////////////////////////////////////////////////////// 748 unsigned int giet_task_id() { 749 return sys_call(SYSCALL_TASK_ID, 0, 0, 0, 0); 750 } 751 752 753 // Local Variables: 754 // tab-width: 4 755 // c-basic-offset: 4 756 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 757 // indent-tabs-mode: nil 758 // End: 759 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 760
Note: See TracChangeset
for help on using the changeset viewer.