Changeset 647 for soft/giet_vm/giet_libs/stdio.c
- Timestamp:
- Jul 22, 2015, 1:09:15 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/stdio.c
r641 r647 49 49 50 50 ////////////////////////////////////////////////////////////////////////////// 51 ///////////////////// Task contextsystem calls /////////////////////////////51 ///////////////////// Task related system calls ///////////////////////////// 52 52 ////////////////////////////////////////////////////////////////////////////// 53 53 … … 73 73 } 74 74 75 ////////////////////////////// 76 void giet_exit( char* string ) 77 { 78 sys_call( SYSCALL_EXIT, 79 (unsigned int)string, 80 0, 0, 0 ); 81 } 82 83 ///////////////////////////////////////// 84 void giet_assert( unsigned int condition, 85 char* string ) 86 { 87 if ( condition == 0 ) giet_exit( string ); 88 } 89 90 ////////////////////////// 91 void giet_context_switch() 92 { 93 sys_call( SYSCALL_CTX_SWITCH, 94 0, 0, 0, 0 ); 95 } 96 97 ////////////////////////////////////////////////////////////////////////////// 98 ///////////////////// Applications system calls ///////////////////////////// 99 ////////////////////////////////////////////////////////////////////////////// 100 101 /////////////////////////////////////// 102 int giet_kill_application( char* name ) 103 { 104 return ( sys_call( SYSCALL_KILL_APP, 105 (unsigned int)name, 106 0, 0, 0 ) ); 107 } 108 109 /////////////////////////////////////// 110 int giet_exec_application( char* name ) 111 { 112 return ( sys_call( SYSCALL_EXEC_APP, 113 (unsigned int)name, 114 0, 0, 0 ) ); 115 } 75 116 76 117 ////////////////////////////////////////////////////////////////////////////// … … 515 556 unsigned int bufsize ) 516 557 { 517 int ret; 558 int ret; // return value from syscalls 518 559 unsigned char byte; 519 560 unsigned int index = 0; 561 unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS 520 562 521 563 while (index < (bufsize - 1)) 522 564 { 565 // get one character 523 566 do 524 567 { … … 526 569 (unsigned int)(&byte), 527 570 1, 528 0xFFFFFFFF, 571 0xFFFFFFFF, // channel index from task context 529 572 0); 530 573 if ( ret < 0 ) giet_exit("error in giet_tty_gets()"); … … 532 575 while (ret != 1); 533 576 534 if (byte == 0x0A) /* LF */ 577 // analyse character 578 if (byte == 0x0A) // LF special character 535 579 { 536 580 break; 537 581 } 538 else if ((byte == 0x7F) && (index > 0)) /* DEL */ 539 { 540 index--; 541 } 542 else 582 else if ( (byte == 0x7F) || // DEL special character 583 (byte == 0x08) ) // BS special character 584 { 585 if ( index > 0 ) 586 { 587 index--; 588 589 // cancel character 590 ret = sys_call( SYSCALL_TTY_WRITE, 591 (unsigned int)(&string_cancel), 592 3, 593 0XFFFFFFFF, // channel index from task context 594 0 ); 595 if ( ret < 0 ) giet_exit("error in giet_tty_gets()"); 596 } 597 } 598 else if ( (byte < 0x20) || (byte > 0x7F) ) // non printable characters 599 { 600 } 601 else // take all other characters 543 602 { 544 603 buf[index] = byte; 545 604 index++; 605 606 // echo 607 ret = sys_call( SYSCALL_TTY_WRITE, 608 (unsigned int)(&byte), 609 1, 610 0XFFFFFFFF, // channel index from task context 611 0 ); 612 if ( ret < 0 ) giet_exit("error in giet_tty_gets()"); 613 546 614 } 547 615 } 548 616 buf[index] = 0; 549 } 617 618 } // end giet_tty_gets() 550 619 551 620 /////////////////////////////////////// … … 561 630 unsigned int length = 0; 562 631 unsigned int i; 563 unsigned int channel = 0xFFFFFFFF;564 632 int ret; // return value from syscalls 565 633 … … 573 641 (unsigned int)(&string_byte), 574 642 1, 575 channel,643 0xFFFFFFFF, // channel index from task context 576 644 0); 577 645 if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); … … 580 648 581 649 // analyse character 582 if ((string_byte > 0x2F) && (string_byte < 0x3A)) / * decimal character */650 if ((string_byte > 0x2F) && (string_byte < 0x3A)) // decimal character 583 651 { 584 652 buf[length] = (unsigned char)string_byte; … … 589 657 (unsigned int)(&string_byte), 590 658 1, 591 channel,659 0xFFFFFFFF, // channel index from task context 592 660 0 ); 593 if ( ret < 0 ) giet_exit("error in giet_tty_get s()");594 } 595 else if (string_byte == 0x0A) / * LF character */661 if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); 662 } 663 else if (string_byte == 0x0A) // LF character 596 664 { 597 665 done = 1; 598 666 } 599 else if ( (string_byte == 0x7F) || / * DEL character */600 (string_byte == 0x08) ) / * BS character */667 else if ( (string_byte == 0x7F) || // DEL character 668 (string_byte == 0x08) ) // BS character 601 669 { 602 670 if ( length > 0 ) … … 607 675 (unsigned int)(&string_cancel), 608 676 3, 609 channel,677 0xFFFFFFFF, // channel index from task context 610 678 0 ); 611 679 if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); … … 646 714 (unsigned int)(&string_cancel), 647 715 3, 648 channel,716 0xFFFFFFFF, // channel index from task context 649 717 0 ); 650 718 if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); … … 655 723 (unsigned int)(&string_byte), 656 724 1, 657 channel,725 0xFFFFFFFF, // channel index from task context 658 726 0 ); 659 727 if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); … … 662 730 *val = 0; 663 731 } 664 } 732 } // end giet_tty_getw() 665 733 666 734 … … 999 1067 ///////////////////// Miscellaneous system calls ///////////////////////////////// 1000 1068 ////////////////////////////////////////////////////////////////////////////////// 1001 1002 //////////////////////////////1003 void giet_exit( char* string )1004 {1005 sys_call( SYSCALL_EXIT,1006 (unsigned int)string,1007 0, 0, 0 );1008 }1009 1010 //////////////////////////////1011 void giet_kill( char* name )1012 {1013 sys_call( SYSCALL_KILL_APP,1014 (unsigned int)name,1015 0, 0, 0 );1016 }1017 1018 //////////////////////////////1019 void giet_exec( char* name )1020 {1021 sys_call( SYSCALL_EXIT,1022 (unsigned int)name,1023 0, 0, 0 );1024 }1025 1026 /////////////////////////////////////////1027 void giet_assert( unsigned int condition,1028 char* string )1029 {1030 if ( condition == 0 ) giet_exit( string );1031 }1032 1033 //////////////////////////1034 void giet_context_switch()1035 {1036 sys_call( SYSCALL_CTX_SWITCH,1037 0, 0, 0, 0 );1038 }1039 1069 1040 1070 /////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.