Changeset 647 for soft/giet_vm/giet_libs
- Timestamp:
- Jul 22, 2015, 1:09:15 PM (9 years ago)
- Location:
- soft/giet_vm/giet_libs
- Files:
-
- 4 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 ///////////////////////////////////////////////// -
soft/giet_vm/giet_libs/stdio.h
r628 r647 170 170 171 171 ////////////////////////////////////////////////////////////////////////// 172 // Task contextsystem calls172 // Task related system calls 173 173 ////////////////////////////////////////////////////////////////////////// 174 174 … … 178 178 179 179 extern unsigned int giet_thread_id(); 180 181 extern void giet_exit( char* string ); 182 183 extern void giet_assert( unsigned int condition, 184 char* string ); 185 186 extern void giet_context_switch(); 187 188 ////////////////////////////////////////////////////////////////////////// 189 // Application related system calls 190 ////////////////////////////////////////////////////////////////////////// 191 192 extern int giet_kill_application( char* name ); 193 194 extern int giet_exec_application( char* name ); 180 195 181 196 ////////////////////////////////////////////////////////////////////////// … … 323 338 ////////////////////////////////////////////////////////////////////////// 324 339 325 extern void giet_exit( char* string );326 327 extern void giet_kill( char* name );328 329 extern void giet_exec( char* name );330 331 extern void giet_assert( unsigned int condition,332 char* string );333 334 extern void giet_context_switch();335 336 340 extern void giet_procs_number( unsigned int* x_size, 337 341 unsigned int* y_size, -
soft/giet_vm/giet_libs/stdlib.c
r580 r647 8 8 #include <stdlib.h> 9 9 10 ///////////////////////// //////////////////////////////////////////////////////////10 ///////////////////////// 11 11 int atoi(const char *str) 12 ///////////////////////////////////////////////////////////////////////////////////13 12 { 14 13 int res = 0; // Initialize result … … 31 30 } 32 31 33 //////////////////////////// ///////////////////////////////////////////////////////32 //////////////////////////// 34 33 double atof(const char *str) 35 ///////////////////////////////////////////////////////////////////////////////////36 34 { 37 35 const char *pstr = str; … … 77 75 } 78 76 79 /////////////////////////////////////////////////////////////// /////////////////////////77 /////////////////////////////////////////////////////////////// 80 78 void * memcpy(void *_dst, const void * _src, unsigned int size) 81 ////////////////////////////////////////////////////////////////////////////////////////82 79 { 83 80 unsigned int * dst = _dst; … … 102 99 } 103 100 104 ////////////////////////////////////////////////////////// //////////////////////////////101 ////////////////////////////////////////////////////////// 105 102 inline void * memset(void * dst, int s, unsigned int size) 106 ////////////////////////////////////////////////////////////////////////////////////////107 103 { 108 104 char * a = (char *) dst; … … 114 110 } 115 111 112 /////////////////////////////////// 113 unsigned int strlen( char* string ) 114 { 115 unsigned int i = 0; 116 while ( string[i] != 0 ) i++; 117 return i; 118 } 119 120 /////////////////////////////// 121 unsigned int strcmp( char * s1, 122 char * s2 ) 123 { 124 while (1) 125 { 126 if (*s1 != *s2) return 1; 127 if (*s1 == 0) break; 128 s1++, s2++; 129 } 130 return 0; 131 } 132 133 ///////////////////////// 134 char* strcpy( char* dest, 135 char* source ) 136 { 137 if (!dest || !source) return dest; 138 139 while (*source) 140 { 141 *(dest) = *(source); 142 dest++; 143 source++; 144 } 145 *dest = 0; 146 return dest; 147 } 148 116 149 // Local Variables: 117 150 // tab-width: 4 -
soft/giet_vm/giet_libs/stdlib.h
r580 r647 10 10 11 11 //////////////////////////////////////////////////////////////////////////////////////// 12 // This function translate a character string to a signed integer.12 // This function translates a character string to a signed integer. 13 13 // For a negative value, the first character must be a '-' (minus) character. 14 14 //////////////////////////////////////////////////////////////////////////////////////// … … 39 39 unsigned int size ); 40 40 41 //////////////////////////////////////////////////////////////////////////////////////// 42 // This function returns the number of characters in a string. 43 // The terminating NUL character is not taken into account. 44 //////////////////////////////////////////////////////////////////////////////////////// 45 unsigned int strlen( char* string ); 46 47 //////////////////////////////////////////////////////////////////////////////////////// 48 // This function compare the two s1 & s2 strings. 49 // It returns 0 if strings are identical (including the terminating NUL character). 50 // It returns 1 if they are not. 51 //////////////////////////////////////////////////////////////////////////////////////// 52 unsigned int strcmp( char* s1, 53 char* s2 ); 54 55 //////////////////////////////////////////////////////////////////////////////////////// 56 // This function copies the source string to the dest string. 57 // It returns a pointer on the dest string. 58 //////////////////////////////////////////////////////////////////////////////////////// 59 char* strcpy( char* dest, 60 char* source ); 61 41 62 #endif 42 63
Note: See TracChangeset
for help on using the changeset viewer.