Changeset 682
- Timestamp:
- Jan 3, 2021, 11:32:52 PM (4 years ago)
- Location:
- trunk/user
- Files:
-
- 23 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/chat/chat.c
r676 r682 159 159 unsigned long long start_cycle; 160 160 161 // check arguments162 if( argc == 0 )163 {164 printf("\n[chat error] cannot get process argument / pid %x\n", getpid() );165 exit( 1 );166 }167 168 // get process index 0/1169 is_0 = (strcmp( "0" , argv[0] ) == 0);170 171 161 // get start cycle 172 162 get_cycle( &start_cycle ); 163 164 // check arguments 165 if( argc != 1 || argv[0] == NULL ) 166 { 167 printf("\n[chat error] : pid %x / argc %d / argv %x / argv[0] %x / cycle %d\n", 168 getpid() , argc , argv , argv[0] , (unsigned int)start_cycle ); 169 170 exit( -1 ); 171 } 172 173 // get process index 0/1 174 is_0 = (atoi( argv[0] ) == 0); 173 175 174 176 ////////////////////////// -
trunk/user/convol/convol.c
r676 r682 702 702 if( INTERACTIVE_MODE ) 703 703 { 704 char byte;705 704 printf("\n[convol] press any key to to delete FBF windows and exit\n"); 706 getc ( &byte);705 getchar(); 707 706 } 708 707 -
trunk/user/init/init.c
r676 r682 7 7 // It uses the fork/exec syscalls to create N KSH child processes 8 8 // (one child process per user TXT terminal). 9 // Then calls the wait() function to block, and recreate any child KSH process9 // Then it calls the wait() function to block, and recreate any child KSH process 10 10 // that has been deleted, using a new fork/exec. 11 11 /////////////////////////////////////////////////////////////////////////////////////// … … 31 31 int status; // used by the wait syscall 32 32 char string[64]; // log messages on kernel TXT0 33 unsigned int cxy; // target cluster identifier 33 34 34 35 #if DEBUG_PROCESS_INIT … … 36 37 #endif 37 38 38 // get number of TXT channels from hard configuration39 // get number of TXT channels and number of clusters 39 40 hard_config_t config; 40 41 … … 42 43 43 44 unsigned int txt_channels = config.txt_channels; 45 unsigned int x_size = config.x_size; 46 unsigned int y_size = config.y_size; 47 unsigned int n_clusters = x_size * y_size; 44 48 45 49 // check number of TXT channels … … 52 56 } 53 57 58 cxy = 0; 59 54 60 // create the KSH processes (one per user terminal) 55 61 for( i = 1 ; i < txt_channels ; i++ ) 56 62 { 63 // compute target cluster 64 cxy = (cxy + 1) % n_clusters; 65 66 // select target cluster 67 if( place_fork( cxy ) ) 68 { 69 // INIT display error message 70 snprintf( string , 64 , 71 "\n[init ERROR] cannot place fork for child[%d] => suicide" , i ); 72 display_string( string ); 73 74 // INIT suicide 75 exit( EXIT_FAILURE ); 76 } 77 78 57 79 // INIT process fork process CHILD[i] 58 80 ret_fork = fork(); … … 94 116 // INIT display CHILD[i] process PID 95 117 snprintf( string , 64 , 96 "\n[init] (pid 0x1) create ksh[%d] (pid %x)", i , ret_fork ); 97 display_string( string ); 98 99 // wait signal from KSH[i] before creating KSH[i+1] 100 pause(); 118 "[init] (pid 0x1) create ksh[%d] (pid %x)", i , ret_fork ); 119 display_string( string ); 101 120 } 102 121 } … … 104 123 #if DEBUG_PROCESS_INIT 105 124 { 125 // keep blocked for 2 seconds 126 // to allow all KSH[i] process 127 // to be launched before display 128 129 sleep( 2 ); 130 106 131 unsigned int x; // cluster x coordinate 107 132 unsigned int y; // cluster y coordinate -
trunk/user/ksh/ksh.c
r676 r682 52 52 #include <shared_syscalls.h> 53 53 54 #define BUF_MAX_SIZE (4096) // max number of bytes for k <-> u data transfer 54 55 #define CMD_MAX_SIZE (256) // max number of characters in one command 55 56 #define LOG_DEPTH (32) // max number of registered commands … … 760 761 unsigned int background; // background execution if non zero 761 762 unsigned int place; // user placement if non zero 762 char * arg[5]; // array of pointers on main threadarguments763 unsigned int args_nr; // number of ar uments in this array764 765 char undef[] = { "undefined" };763 char * arg[5]; // array of pointers on process arguments 764 unsigned int args_nr; // number of arguments in this array 765 766 arg[4] = NULL; 766 767 767 768 // arguments analysis of argv[] array that contains at most 8 strings: 768 // - the two first arguments ("cmd_ type" & "elf_path") are mandatory769 // - the two first arguments ("cmd_load" & "elf_path") are mandatory 769 770 // - the six next ("-pcxy","arg0","arg1","arg2","arg3","&") are optional 770 771 … … 775 776 background = 0; 776 777 place = 0; 777 arg[0] = undef;778 arg[1] = undef;779 arg[2] = undef;780 arg[3] = undef;778 arg[0] = NULL; 779 arg[1] = NULL; 780 arg[2] = NULL; 781 arg[3] = NULL; 781 782 args_nr = 0; 782 783 } … … 788 789 background = 1; 789 790 place = 0xFF000000 | atoi( argv[2] + 2 ); 790 arg[0] = (argc > 4) ? argv[3] : undef;791 arg[1] = (argc > 5) ? argv[4] : undef;792 arg[2] = (argc > 6) ? argv[5] : undef;793 arg[3] = (argc > 7) ? argv[6] : undef;791 arg[0] = (argc > 4) ? argv[3] : NULL; 792 arg[1] = (argc > 5) ? argv[4] : NULL; 793 arg[2] = (argc > 6) ? argv[5] : NULL; 794 arg[3] = (argc > 7) ? argv[6] : NULL; 794 795 args_nr = argc - 4; 795 796 } … … 801 802 background = 0; 802 803 place = 0xFF000000 | atoi( argv[2] + 2 ); 803 arg[0] = (argc > 3) ? argv[3] : undef;804 arg[1] = (argc > 4) ? argv[4] : undef;805 arg[2] = (argc > 5) ? argv[5] : undef;806 arg[3] = (argc > 6) ? argv[6] : undef;804 arg[0] = (argc > 3) ? argv[3] : NULL; 805 arg[1] = (argc > 4) ? argv[4] : NULL; 806 arg[2] = (argc > 5) ? argv[5] : NULL; 807 arg[3] = (argc > 6) ? argv[6] : NULL; 807 808 args_nr = argc - 3; 808 809 } … … 814 815 background = 1; 815 816 place = 0; 816 arg[0] = (argc > 3) ? argv[2] : undef;817 arg[1] = (argc > 4) ? argv[3] : undef;818 arg[2] = (argc > 5) ? argv[4] : undef;819 arg[3] = (argc > 6) ? argv[5] : undef;817 arg[0] = (argc > 3) ? argv[2] : NULL; 818 arg[1] = (argc > 4) ? argv[3] : NULL; 819 arg[2] = (argc > 5) ? argv[4] : NULL; 820 arg[3] = (argc > 6) ? argv[5] : NULL; 820 821 args_nr = argc - 3; 821 822 } … … 825 826 background = 0; 826 827 place = 0; 827 arg[0] = (argc > 2) ? argv[2] : undef;828 arg[1] = (argc > 3) ? argv[3] : undef;829 arg[2] = (argc > 4) ? argv[4] : undef;830 arg[3] = (argc > 5) ? argv[5] : undef;828 arg[0] = (argc > 2) ? argv[2] : NULL; 829 arg[1] = (argc > 3) ? argv[3] : NULL; 830 arg[2] = (argc > 4) ? argv[4] : NULL; 831 arg[3] = (argc > 5) ? argv[5] : NULL; 831 832 args_nr = argc - 2; 832 833 } … … 836 837 background = 0; 837 838 place = 0; 838 arg[0] = undef;839 arg[1] = undef;840 arg[2] = undef;841 arg[3] = undef;839 arg[0] = NULL; 840 arg[1] = NULL; 841 arg[2] = NULL; 842 arg[3] = NULL; 842 843 args_nr = 0; 843 844 } … … 858 859 859 860 #if DEBUG_CMD_LOAD 861 if( place ) 860 862 printf("\n[ksh] %s : path <%s> / place %x / args_nr %d / bg %d\n" 861 863 " arg0 %s / arg1 %s / arg2 %s / arg3 %s\n", 862 __FUNCTION__, elf_path , place , args_nr , background , arg[0] , arg[1] , arg[2] , arg[3] ); 863 #endif 864 865 // set NULL pointers in args[] array 866 if ( arg[0] == undef ) arg[0] = NULL; 867 else if( arg[1] == undef ) arg[1] = NULL; 868 else if( arg[2] == undef ) arg[2] = NULL; 869 else if( arg[3] == undef ) arg[3] = NULL; 870 else arg[4] = NULL; 864 __FUNCTION__, elf_path, place & 0xFFFF, args_nr, background, arg[0], arg[1], arg[2], arg[3] ); 865 866 else 867 printf("\n[ksh] %s : path <%s> / args_nr %d / bg %d\n" 868 " arg0 %s / arg1 %s / arg2 %s / arg3 %s\n", 869 __FUNCTION__, elf_path, args_nr, background, arg[0], arg[1], arg[2], arg[3] ); 870 #endif 871 871 872 872 // set target cluster if required … … 899 899 if( ret_exec ) 900 900 { 901 printf(" error: child process unable to exec <%s>\n", pathname);901 printf(" error: child process unable to exec <%s>\n", elf_path ); 902 902 exit( 0 ); 903 903 } … … 952 952 953 953 #if DEBUG_CMD_LS 954 printf("\n[ksh] %s : directory <%s> open / DIR %x ", __FUNCTION__, pathname , dir );954 printf("\n[ksh] %s : directory <%s> open / DIR %x\n", __FUNCTION__, pathname , dir ); 955 955 #endif 956 956 … … 1034 1034 unsigned int x; 1035 1035 unsigned int y; 1036 unsigned int error; 1037 1038 char u_buf[BUF_MAX_SIZE]; 1036 1039 1037 1040 #if DEBUG_CMD_PS … … 1056 1059 for( y = 0 ; y < y_size ; y++ ) 1057 1060 { 1061 int cxy = HAL_CXY_FROM_XY(x,y); 1058 1062 1059 1063 #if DEBUG_CMD_PS 1060 printf("\n[ksh] %s : call display_cluster_process()", __FUNCTION__ ); 1061 #endif 1062 1063 // display only owned processes 1064 display_cluster_processes( HAL_CXY_FROM_XY(x,y), 1 ); 1064 printf("\n[ksh] %s : call get_processes() in cluster %x", __FUNCTION__ , cxy ); 1065 #endif 1066 // write all owned processes in cxy to u_buf buffer 1067 // one single NUL terminated string / one line per process) 1068 error = get_processes( cxy, 1069 1, // owned only 1070 u_buf, 1071 BUF_MAX_SIZE ); 1072 if( error ) 1073 { 1074 printf(" ... too much processes in cluster %x\n", cxy ); 1075 } 1076 1077 // display processes owned by cluster cxy 1078 printf("%s" , u_buf ); 1065 1079 } 1066 1080 } … … 1299 1313 #endif 1300 1314 1301 // scan the list of commands to match typed command1315 // scan the list of commands to match cmd_type (contained in argv[0] 1302 1316 int found = 0; 1303 1317 for ( i = 0 ; (command[i].name != NULL) && (found == 0) ; i++ ) … … 1313 1327 if (!found) 1314 1328 { 1315 printf(" error : undefined command <%s>\n", argv[0]);1329 printf(" error : undefined command type <%s>\n", argv[0]); 1316 1330 1317 1331 // release semaphore to get next command … … 1332 1346 1333 1347 1334 / *direct command to help debug1335 1336 if( getpid() == 2 )1348 // direct command to help debug 1349 1350 if( getpid() == 0x2) 1337 1351 { 1338 1352 if( sem_wait( &semaphore ) ) … … 1343 1357 else 1344 1358 { 1345 strcpy( cmd , "load bin/user/chat.elf 0" );1359 strcpy( cmd , "load bin/user/tcp_chat.elf 1 0xbbbbbbbb 0xaaaaaaaa 0xcc" ); 1346 1360 printf("[ksh] %s\n", cmd ); 1347 1361 execute( cmd ); … … 1349 1363 } 1350 1364 1351 else if( getpid() ==3 )1365 if( getpid() == 0x3 ) 1352 1366 { 1353 1367 if( sem_wait( &semaphore ) ) … … 1358 1372 else 1359 1373 { 1360 strcpy( cmd , "load bin/user/ chat.elf 1" );1374 strcpy( cmd , "load bin/user/tcp_chat.elf 0 0xaaaaaaaa 0xbbbbbbbb 0xcc" ); 1361 1375 printf("[ksh] %s\n", cmd ); 1362 1376 execute( cmd ); … … 1364 1378 } 1365 1379 1366 */1380 // 1367 1381 1368 1382 enum fsm_states … … 1611 1625 #endif 1612 1626 1613 // signal INIT process 1614 kill( 1 , SIGCONT ); 1615 1616 // enter infinite loop monitoring children processes termination 1627 // enter infinite loop monitoring children termination 1617 1628 while( 1 ) 1618 1629 {
Note: See TracChangeset
for help on using the changeset viewer.