Changeset 165 for soft/giet_vm/libs/stdio.c
- Timestamp:
- Jul 4, 2012, 2:51:18 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/libs/stdio.c
r160 r165 17 17 #define SYSCALL_TTY_WRITE 0x02 18 18 #define SYSCALL_TTY_READ 0x03 19 #define SYSCALL_TIMER_WRITE 0x0420 #define SYSCALL_TIMER_READ 0x0521 19 #define SYSCALL_GCD_WRITE 0x06 22 20 #define SYSCALL_GCD_READ 0x07 … … 37 35 38 36 ////////////////////////////////////////////////////////////////////////////////// 39 // 37 // sys_call() 40 38 // This generic C function is used to implement all system calls. 39 // It writes the system call arguments in the proper registers, 40 // and tells GCC what has been modified by system call execution. 41 41 ////////////////////////////////////////////////////////////////////////////////// 42 42 static inline unsigned int sys_call( unsigned int call_no, … … 83 83 84 84 //////////////////////////////////////////////////////////////////////////////////// 85 // procid() 85 // giet_procid() 86 //////////////////////////////////////////////////////////////////////////////////// 86 87 // This function returns the processor identifier. 87 88 //////////////////////////////////////////////////////////////////////////////////// 88 unsigned int procid()89 unsigned int giet_procid() 89 90 { 90 91 return sys_call(SYSCALL_PROCID, … … 92 93 } 93 94 //////////////////////////////////////////////////////////////////////////////////// 94 // proctime() 95 // giet_proctime() 96 //////////////////////////////////////////////////////////////////////////////////// 95 97 // This function returns the local processor time (clock cycles since boot) 96 98 //////////////////////////////////////////////////////////////////////////////////// 97 unsigned int proctime()99 unsigned int giet_proctime() 98 100 { 99 101 return sys_call(SYSCALL_PROCTIME, … … 104 106 105 107 //////////////////////////////////////////////////////////////////////////////////// 106 // tty_putc() 108 // giet_tty_putc() 109 //////////////////////////////////////////////////////////////////////////////////// 107 110 // This function displays a single ascii character on a terminal. 108 111 // The terminal index must be defined in the task context in the boot phase. … … 110 113 // - Returns 1 if the character has been written, 0 otherwise. 111 114 //////////////////////////////////////////////////////////////////////////////////// 112 unsigned int tty_putc(char byte)115 unsigned int giet_tty_putc(char byte) 113 116 { 114 117 return sys_call(SYSCALL_TTY_WRITE, … … 118 121 } 119 122 //////////////////////////////////////////////////////////////////////////////////// 120 // tty_puts() 123 // giet_tty_puts() 124 //////////////////////////////////////////////////////////////////////////////////// 121 125 // This function displays a string on a terminal. 122 126 // The terminal index must be defined in the task context in the boot phase. … … 125 129 // - Returns the number of written characters. 126 130 //////////////////////////////////////////////////////////////////////////////////// 127 unsigned int tty_puts(char *buf)131 unsigned int giet_tty_puts(char *buf) 128 132 { 129 133 unsigned int length = 0; … … 138 142 } 139 143 //////////////////////////////////////////////////////////////////////////////////// 140 // tty_putw() 144 // giet_tty_putw() 145 //////////////////////////////////////////////////////////////////////////////////// 141 146 // This function displays the value of a 32-bit word with decimal characters. 142 147 // The terminal index must be defined in the task context in the boot phase. … … 144 149 // Returns the number of written characters (should be equal to ten). 145 150 //////////////////////////////////////////////////////////////////////////////////// 146 unsigned int tty_putw(unsigned int val)151 unsigned int giet_tty_putw(unsigned int val) 147 152 { 148 153 char buf[10]; … … 160 165 161 166 //////////////////////////////////////////////////////////////////////////////////// 162 // tty_getc() 167 // giet_tty_getc_no_irq() 168 //////////////////////////////////////////////////////////////////////////////////// 163 169 // This blocking function fetches a single ascii character from a terminal. 164 170 // The terminal index must be defined in the task context in the boot phase. … … 166 172 // - Returns necessarily 0 when completed. 167 173 //////////////////////////////////////////////////////////////////////////////////// 168 unsigned int tty_getc(char *byte)174 unsigned int giet_tty_getc_no_irq(char *byte) 169 175 { 170 176 unsigned int ret = 0; … … 179 185 } 180 186 //////////////////////////////////////////////////////////////////////////////////// 181 // tty_getc_irq() 187 // giet_tty_getc() 188 //////////////////////////////////////////////////////////////////////////////////// 182 189 // This blocking function fetches a single ascii character from a terminal. 183 190 // The terminal index must be defined in the task context in the boot phase. … … 185 192 // - Returns 0 when completed. 186 193 //////////////////////////////////////////////////////////////////////////////////// 187 unsigned int tty_getc_irq(char *byte)194 unsigned int giet_tty_getc(char *byte) 188 195 { 189 196 unsigned int ret = 0; … … 198 205 } 199 206 //////////////////////////////////////////////////////////////////////////////////// 200 // tty_gets_irq() 207 // giet_tty_gets() 208 //////////////////////////////////////////////////////////////////////////////////// 201 209 // This blocking function fetches a string from a terminal to a fixed length buffer. 202 210 // The terminal index must be defined in the task context in the boot phase. … … 211 219 // removed from the target buffer. 212 220 //////////////////////////////////////////////////////////////////////////////////// 213 unsigned int tty_gets_irq(char *buf, unsigned int bufsize) 221 unsigned int giet_tty_gets( char* buf, 222 unsigned int bufsize ) 214 223 { 215 224 unsigned int ret; … … 240 249 } 241 250 //////////////////////////////////////////////////////////////////////////////////// 242 // tty_getw_irq() 251 // giet_tty_getw() 252 //////////////////////////////////////////////////////////////////////////////////// 243 253 // This blocking function fetches a string of decimal characters (most 244 254 // significant digit first) to build a 32-bit unsigned integer. … … 256 266 // bits range, the zero value is returned. 257 267 //////////////////////////////////////////////////////////////////////////////////// 258 unsigned int tty_getw_irq(unsigned int *val)268 unsigned int giet_tty_getw(unsigned int *val) 259 269 { 260 270 unsigned char buf[32]; … … 281 291 buf[max] = byte; 282 292 max++; 283 tty_putc(byte);293 giet_tty_putc(byte); 284 294 } 285 295 else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */ … … 292 302 { 293 303 max--; /* cancel the character */ 294 tty_putc(0x08);295 tty_putc(0x20);296 tty_putc(0x08);304 giet_tty_putc(0x08); 305 giet_tty_putc(0x20); 306 giet_tty_putc(0x08); 297 307 } 298 308 } … … 301 311 for (i = 0; i < max; i++) /* cancel the string */ 302 312 { 303 tty_putc(0x08);304 tty_putc(0x20);305 tty_putc(0x08);313 giet_tty_putc(0x08); 314 giet_tty_putc(0x20); 315 giet_tty_putc(0x08); 306 316 } 307 tty_putc(0x30);317 giet_tty_putc(0x30); 308 318 *val = 0; /* return 0 value */ 309 319 return 0; … … 329 339 for (i = 0; i < max; i++) /* cancel the string */ 330 340 { 331 tty_putc(0x08);332 tty_putc(0x20);333 tty_putc(0x08);334 } 335 tty_putc(0x30);341 giet_tty_putc(0x08); 342 giet_tty_putc(0x20); 343 giet_tty_putc(0x08); 344 } 345 giet_tty_putc(0x30); 336 346 *val = 0; /* return 0 value */ 337 347 } … … 339 349 } 340 350 //////////////////////////////////////////////////////////////////////////////////// 341 // tty_printf() 351 // giet_tty_printf() 352 //////////////////////////////////////////////////////////////////////////////////// 342 353 // This function is a simplified version of the mutek_printf() function. 343 354 // The terminal index must be defined in the calling task context. … … 351 362 // - Returns 0 if success, > 0 if error. 352 363 //////////////////////////////////////////////////////////////////////////////////// 353 unsigned int tty_printf(char *format, ...)364 unsigned int giet_tty_printf(char *format, ...) 354 365 { 355 366 va_list ap; … … 450 461 } 451 462 452 ///// Timer device related system calls ///// 453 454 #define TIMER_VALUE 0 455 #define TIMER_MODE 1 456 #define TIMER_PERIOD 2 457 #define TIMER_RESETIRQ 3 458 459 /* 460 * timer_set_mode() 461 * 462 * This function defines the operation mode of a timer. The possible values for 463 * this mode are: 464 * - 0x0 : Timer not activated 465 * - 0x1 : Timer activated, but no interrupt is generated 466 * - 0x3 : Timer activarted and periodic interrupts generated 467 * 468 * - Returns 0 if success, > 0 if error. 469 */ 470 unsigned int timer_set_mode(unsigned int val) 471 { 472 return sys_call(SYSCALL_TIMER_WRITE, 473 TIMER_MODE, 474 val, 475 0, 0); 476 } 477 478 /* 479 * timer_set_period() 480 * 481 * This function defines the period value of a timer to enable a periodic 482 * interrupt. 483 * - Returns 0 if success, > 0 if error. 484 */ 485 unsigned int timer_set_period(unsigned int val) 486 { 487 return sys_call(SYSCALL_TIMER_WRITE, 488 TIMER_PERIOD, 489 val, 490 0, 0); 491 } 492 493 /* 494 * timer_reset_irq() 495 * 496 * This function resets the interrupt signal issued by a timer. 497 * - Returns 0 if success, > 0 if error. 498 */ 499 unsigned int timer_reset_irq() 500 { 501 return sys_call(SYSCALL_TIMER_WRITE, 502 TIMER_RESETIRQ, 503 0, 0, 0); 504 } 505 506 /* 507 * timer_get_time() 508 * 509 * This function returns the current timing value of a timer. 510 * - Returns 0 if success, > 0 if error. 511 */ 512 unsigned int timer_get_time(unsigned int *time) 513 { 514 return sys_call(SYSCALL_TIMER_READ, 515 TIMER_VALUE, 516 (unsigned int)time, 517 0, 0); 518 } 519 520 ///// GCD (Greatest Common Divider) device related system calls 463 ///// GCD (Greatest Common Divider) related system calls 521 464 522 465 #define GCD_OPA 0 … … 526 469 527 470 ////////////////////////////////////////////////////////////////////////////////// 528 // gcd_set_opa() 471 // giet_gcd_set_opa() 472 ////////////////////////////////////////////////////////////////////////////////// 529 473 // This function sets the operand A in the GCD coprocessor. 530 474 // - Returns 0 if success, > 0 if error. 531 475 ////////////////////////////////////////////////////////////////////////////////// 532 unsigned int g cd_set_opa(unsigned int val)476 unsigned int giet_gcd_set_opa(unsigned int val) 533 477 { 534 478 return sys_call(SYSCALL_GCD_WRITE, … … 538 482 } 539 483 ////////////////////////////////////////////////////////////////////////////////// 540 // gcd_set_opb() 484 // giet_gcd_set_opb() 485 ////////////////////////////////////////////////////////////////////////////////// 541 486 // This function sets operand B in the GCD coprocessor. 542 487 // - Returns 0 if success, > 0 if error. 543 488 ////////////////////////////////////////////////////////////////////////////////// 544 unsigned int g cd_set_opb(unsigned int val)489 unsigned int giet_gcd_set_opb(unsigned int val) 545 490 { 546 491 return sys_call(SYSCALL_GCD_WRITE, … … 550 495 } 551 496 ////////////////////////////////////////////////////////////////////////////////// 552 // gcd_start() 497 // giet_gcd_start() 498 ////////////////////////////////////////////////////////////////////////////////// 553 499 // This function starts the computation in the GCD coprocessor. 554 500 // - Returns 0 if success, > 0 if error. 555 501 ////////////////////////////////////////////////////////////////////////////////// 556 unsigned int g cd_start()502 unsigned int giet_gcd_start() 557 503 { 558 504 return sys_call(SYSCALL_GCD_WRITE, … … 561 507 } 562 508 ////////////////////////////////////////////////////////////////////////////////// 563 // gcd_get_status() 509 // giet_gcd_get_status() 510 ////////////////////////////////////////////////////////////////////////////////// 564 511 // This function gets the status fromn the GCD coprocessor. 565 512 // - The value is 0 when the coprocessor is idle (computation completed). 566 513 ////////////////////////////////////////////////////////////////////////////////// 567 unsigned int g cd_get_status(unsigned int *val)514 unsigned int giet_gcd_get_status(unsigned int *val) 568 515 { 569 516 return sys_call(SYSCALL_GCD_READ, … … 573 520 } 574 521 ////////////////////////////////////////////////////////////////////////////////// 575 // gcd_get_result() 522 // giet_gcd_get_result() 523 ////////////////////////////////////////////////////////////////////////////////// 576 524 // This function gets the result of the computation from the GCD coprocessor. 577 525 ////////////////////////////////////////////////////////////////////////////////// 578 unsigned int g cd_get_result(unsigned int *val)526 unsigned int giet_gcd_get_result(unsigned int *val) 579 527 { 580 528 return sys_call(SYSCALL_GCD_READ, … … 587 535 588 536 ////////////////////////////////////////////////////////////////////////////////// 589 // ioc_write() 537 // giet_ioc_write() 538 ////////////////////////////////////////////////////////////////////////////////// 590 539 // Transfer data from a memory buffer to a file on the block_device. 591 540 // lba : Logical Block Address (first block index) … … 594 543 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 595 544 ////////////////////////////////////////////////////////////////////////////////// 596 unsigned int ioc_write(unsigned int lba, void *buffer, unsigned int count) 545 unsigned int giet_ioc_write( unsigned int lba, 546 void* buffer, 547 unsigned int count) 597 548 { 598 549 return sys_call(SYSCALL_IOC_WRITE, … … 603 554 } 604 555 ////////////////////////////////////////////////////////////////////////////////// 605 // ioc_read() 556 // giet_ioc_read() 557 ////////////////////////////////////////////////////////////////////////////////// 606 558 // Transfer data from a file on the block_device to a memory buffer. 607 559 // lba : Logical Block Address (first block index) … … 610 562 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 611 563 ////////////////////////////////////////////////////////////////////////////////// 612 unsigned int ioc_read(unsigned int lba, void *buffer, unsigned int count) 564 unsigned int giet_ioc_read( unsigned int lba, 565 void* buffer, 566 unsigned int count ) 613 567 { 614 568 return sys_call(SYSCALL_IOC_READ, … … 619 573 } 620 574 ////////////////////////////////////////////////////////////////////////////////// 621 // ioc_completed() 575 // giet_ioc_completed() 576 ////////////////////////////////////////////////////////////////////////////////// 622 577 // This blocking function returns 0 when the I/O transfer is 623 578 // successfully completed, and returns 1 if an address error has been detected. 624 579 ////////////////////////////////////////////////////////////////////////////////// 625 unsigned int ioc_completed()580 unsigned int giet_ioc_completed() 626 581 { 627 582 return sys_call(SYSCALL_IOC_COMPLETED, … … 632 587 633 588 ////////////////////////////////////////////////////////////////////////////////// 634 // fb_sync_write() 589 // giet_fb_sync_write() 590 ////////////////////////////////////////////////////////////////////////////////// 635 591 // This blocking function use a memory copy strategy to transfer data from a 636 592 // user buffer to the frame buffer device in kernel space. … … 640 596 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 641 597 ////////////////////////////////////////////////////////////////////////////////// 642 unsigned int fb_sync_write(unsigned int offset, void *buffer, unsigned int length) 598 unsigned int giet_fb_sync_write( unsigned int offset, 599 void* buffer, 600 unsigned int length ) 643 601 { 644 602 return sys_call(SYSCALL_FB_SYNC_WRITE, … … 649 607 } 650 608 ////////////////////////////////////////////////////////////////////////////////// 651 // fb_sync_read() 609 // giet_fb_sync_read() 610 ////////////////////////////////////////////////////////////////////////////////// 652 611 // This blocking function use a memory copy strategy to transfer data from the 653 612 // frame buffer device in kernel space to an user buffer. … … 657 616 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 658 617 ////////////////////////////////////////////////////////////////////////////////// 659 unsigned int fb_sync_read(unsigned int offset, void *buffer, unsigned int length) 618 unsigned int giet_fb_sync_read( unsigned int offset, 619 void* buffer, 620 unsigned int length ) 660 621 { 661 622 return sys_call(SYSCALL_FB_SYNC_READ, … … 666 627 } 667 628 ////////////////////////////////////////////////////////////////////////////////// 668 // fb_write() 629 // giet_fb_write() 630 ////////////////////////////////////////////////////////////////////////////////// 669 631 // This non-blocking function use the DMA coprocessor to transfer data from a 670 632 // user buffer to the frame buffer device in kernel space. … … 676 638 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 677 639 ////////////////////////////////////////////////////////////////////////////////// 678 unsigned int fb_write(unsigned int offset, void *buffer, unsigned int length) 640 unsigned int giet_fb_write( unsigned int offset, 641 void* buffer, 642 unsigned int length ) 679 643 { 680 644 return sys_call(SYSCALL_FB_WRITE, … … 685 649 } 686 650 ////////////////////////////////////////////////////////////////////////////////// 687 // fb_read() 651 // giet_fb_read() 652 ////////////////////////////////////////////////////////////////////////////////// 688 653 // This non-blocking function use the DMA coprocessor to transfer data from the 689 654 // frame buffer device in kernel space to an user buffer. … … 695 660 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 696 661 ////////////////////////////////////////////////////////////////////////////////// 697 unsigned int fb_read( unsigned intoffset,698 void *buffer,699 unsigned intlength )662 unsigned int giet_fb_read( unsigned int offset, 663 void* buffer, 664 unsigned int length ) 700 665 { 701 666 return sys_call(SYSCALL_FB_READ, … … 706 671 } 707 672 ////////////////////////////////////////////////////////////////////////////////// 708 // fb_completed() 673 // giet_fb_completed() 674 ////////////////////////////////////////////////////////////////////////////////// 709 675 // This blocking function returns when the transfer is completed. 710 676 // - Returns 0 if success, > 0 if error. 711 677 ////////////////////////////////////////////////////////////////////////////////// 712 unsigned int fb_completed()678 unsigned int giet_fb_completed() 713 679 { 714 680 return sys_call(SYSCALL_FB_COMPLETED, … … 716 682 } 717 683 718 ///// Platform or mappingrelated system calls /////719 720 ////////////////////////////////////////////////////////////////////////////////// 721 // mwmr_base()722 // TODO!723 // This function returns in argument bufferthe virtual base address724 // of a MWMR communication channel, identified by the two arguments725 // vspace_name and channel_name.726 // As the GIET does not support dynamic allocation, the MWMR channel727 // must be declared in the mapping_info data structure to be initialised728 // in the boot phase.729 // - Returns the address if success, 0 if error ( channel not defined ) 730 ////////////////////////////////////////////////////////////////////////////////// 731 unsigned int vobj_get_vbase( char* vspace_name, char* vobj_name, 732 unsigned int vobj_type, unsigned int* vobj_buffer)684 ///// Miscellaneous related system calls ///// 685 686 ////////////////////////////////////////////////////////////////////////////////// 687 // giet_vobj_get_vbase() 688 ////////////////////////////////////////////////////////////////////////////////// 689 // This function writes in argument (vobj_vaddr) the virtual base address 690 // of a vobj (defined in the mapping_info data structure), identified by 691 // the two arguments (vspace_name and vobj_name). 692 // The (vobj_type) argument is redundant, and used for coherence checking. 693 // - Returns the address if success, 0 if error ( not defined or wrong type ) 694 ////////////////////////////////////////////////////////////////////////////////// 695 unsigned int giet_vobj_get_vbase( char* vspace_name, 696 char* vobj_name, 697 unsigned int vobj_type, 698 unsigned int* vobj_vaddr ) 733 699 { 734 700 return sys_call(SYSCALL_VOBJ_GET_VBASE, … … 736 702 (unsigned int)vobj_name, 737 703 (unsigned int)vobj_type, 738 (unsigned int)vobj_buffer); 739 } 740 //////////////////////////////////////////////////////////////////////////////////// 741 // proc_number() 704 (unsigned int)vobj_vaddr); 705 } 706 707 //////////////////////////////////////////////////////////////////////////////////// 708 // giet_proc_number() 709 //////////////////////////////////////////////////////////////////////////////////// 742 710 // This function returns in the buffer argument the number of processors 743 711 // in the cluster specified by the cluster_id argument. 744 712 // - Returns 0 if success, > 0 if error ( cluster index too large ) 745 713 //////////////////////////////////////////////////////////////////////////////////// 746 unsigned int proc_number( unsigned intcluster_id,747 unsigned int*buffer )714 unsigned int giet_proc_number( unsigned int cluster_id, 715 unsigned int* buffer ) 748 716 { 749 717 return sys_call(SYSCALL_PROC_NUMBER, … … 756 724 757 725 ////////////////////////////////////////////////////////////////////////////////// 758 // exit() 726 // giet_task_exit() 727 ////////////////////////////////////////////////////////////////////////////////// 759 728 // This function stops execution of the calling task with a TTY message, 760 729 // and enter an infinite loop. 761 730 // The task is blocked, but it still consume processor cycles ... 762 731 ////////////////////////////////////////////////////////////////////////////////// 763 void exit() 764 { 765 unsigned int proc_index = procid(); 732 void giet_exit() 733 { 766 734 sys_call(SYSCALL_EXIT, 767 proc_index, 768 0, 0, 0); 735 0, 0, 0, 0); 769 736 } 770 737 /////////////////////////////////////////////////////////////////////////////////// 771 // 738 // giet_rand() 772 739 // This function returns a pseudo-random value derived from the processor cycle 773 740 // count. This value is comprised between 0 & 65535. 774 741 /////////////////////////////////////////////////////////////////////////////////// 775 unsigned int rand()742 unsigned int giet_rand() 776 743 { 777 744 unsigned int x = sys_call(SYSCALL_PROCTIME, … … 783 750 } 784 751 ////////////////////////////////////////////////////////////////////////////////// 785 // 752 // giet_ctx_switch() 786 753 // The user task calling this function is descheduled and 787 754 // the processor is allocated to another task. 788 755 ////////////////////////////////////////////////////////////////////////////////// 789 unsigned int ctx_switch()756 unsigned int giet_ctx_switch() 790 757 { 791 758 return sys_call(SYSCALL_CTX_SWITCH,
Note: See TracChangeset
for help on using the changeset viewer.