Changeset 682 for trunk/user


Ignore:
Timestamp:
Jan 3, 2021, 11:32:52 PM (3 years ago)
Author:
alain
Message:

Introduce three new applications:

  • windows : to test the FBF windows kernel manager
  • udp_chat : chat application based on UDP sockets.
  • tcp_chat : chat application based on TCP sockets (including packet loss recovery).
Location:
trunk/user
Files:
23 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/chat/chat.c

    r676 r682  
    159159    unsigned long long   start_cycle;
    160160
    161     // check arguments
    162     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/1
    169     is_0 = (strcmp( "0" , argv[0] ) == 0);
    170 
    171161    // get  start cycle
    172162    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);
    173175
    174176    //////////////////////////
  • trunk/user/convol/convol.c

    r676 r682  
    702702    if( INTERACTIVE_MODE )
    703703    {
    704         char byte;
    705704        printf("\n[convol] press any key to to delete FBF windows and exit\n");
    706         getc( &byte );
     705        getchar();
    707706    }
    708707 
  • trunk/user/init/init.c

    r676 r682  
    77// It uses the fork/exec syscalls to create N KSH child processes
    88// (one child process per user TXT terminal).
    9 // Then calls the wait() function to block, and recreate any child KSH process
     9// Then it calls the wait() function to block, and recreate any child KSH process
    1010// that has been deleted, using a new fork/exec.
    1111///////////////////////////////////////////////////////////////////////////////////////
     
    3131    int           status;        // used by the wait syscall
    3232    char          string[64];    // log messages on kernel TXT0
     33    unsigned int  cxy;           // target cluster identifier
    3334
    3435#if DEBUG_PROCESS_INIT
     
    3637#endif
    3738
    38     // get number of TXT channels from hard configuration
     39    // get number of TXT channels and number of clusters
    3940    hard_config_t config;     
    4041
     
    4243
    4344    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;
    4448
    4549    // check number of TXT channels
     
    5256    }
    5357
     58    cxy = 0;
     59
    5460    // create the KSH processes (one per user terminal)
    5561    for( i = 1 ; i <  txt_channels ; i++ )
    5662    {
     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
    5779        // INIT process fork process CHILD[i]
    5880        ret_fork = fork();
     
    94116            // INIT display CHILD[i] process PID
    95117            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 );
    101120        }
    102121    }
     
    104123#if DEBUG_PROCESS_INIT
    105124{
     125    // keep blocked for 2 seconds
     126    // to allow all KSH[i] process
     127    // to be launched before display
     128
     129    sleep( 2 );
     130
    106131    unsigned int  x;             // cluster x coordinate
    107132    unsigned int  y;             // cluster y coordinate
  • trunk/user/ksh/ksh.c

    r676 r682  
    5252#include <shared_syscalls.h>
    5353
     54#define BUF_MAX_SIZE       (4096)   // max number of bytes for k <-> u data transfer
    5455#define CMD_MAX_SIZE       (256)    // max number of characters in one command
    5556#define LOG_DEPTH          (32)     // max number of registered commands
     
    760761    unsigned int         background;         // background execution if non zero
    761762    unsigned int         place;              // user placement if non zero
    762     char               * arg[5];             // array of pointers on main thread arguments
    763     unsigned int         args_nr;            // number of aruments in this array
    764 
    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;
    766767
    767768    // arguments analysis of argv[] array that contains at most 8 strings:
    768     // - the two first arguments ("cmd_type" & "elf_path") are mandatory
     769    // - the two first arguments ("cmd_load" & "elf_path") are mandatory
    769770    // - the six next ("-pcxy","arg0","arg1","arg2","arg3","&") are optional
    770771
     
    775776        background = 0;
    776777        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;
    781782        args_nr    = 0;
    782783    }
     
    788789        background = 1;
    789790        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;
    794795        args_nr    = argc - 4;
    795796    }
     
    801802        background = 0;
    802803        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;
    807808        args_nr    = argc - 3;
    808809    }
     
    814815        background = 1;
    815816        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;
    820821        args_nr    = argc - 3;
    821822    }
     
    825826        background = 0;
    826827        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;
    831832        args_nr    = argc - 2;
    832833    }
     
    836837        background = 0;
    837838        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;
    842843        args_nr    = 0;
    843844    }
     
    858859
    859860#if DEBUG_CMD_LOAD
     861if( place )
    860862printf("\n[ksh] %s : path <%s> / place %x / args_nr %d / bg %d\n"
    861863"                 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
     866else
     867printf("\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
    871871
    872872    // set target cluster if required
     
    899899        if( ret_exec )
    900900        {
    901             printf("  error: child process unable to exec <%s>\n", pathname );
     901            printf("  error: child process unable to exec <%s>\n", elf_path );
    902902            exit( 0 );
    903903        }   
     
    952952
    953953#if DEBUG_CMD_LS
    954 printf("\n[ksh] %s : directory <%s> open / DIR %x", __FUNCTION__, pathname , dir );
     954printf("\n[ksh] %s : directory <%s> open / DIR %x\n", __FUNCTION__, pathname , dir );
    955955#endif
    956956
     
    10341034    unsigned int x;
    10351035    unsigned int y;
     1036    unsigned int error;
     1037
     1038    char         u_buf[BUF_MAX_SIZE];
    10361039
    10371040#if DEBUG_CMD_PS
     
    10561059            for( y = 0 ; y < y_size ; y++ )
    10571060            {
     1061                int cxy = HAL_CXY_FROM_XY(x,y);
    10581062
    10591063#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 );
     1064printf("\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 );
    10651079            }
    10661080        }
     
    12991313#endif
    13001314
    1301     // scan the list of commands to match typed command
     1315    // scan the list of commands to match cmd_type (contained in argv[0]
    13021316    int found = 0;
    13031317    for ( i = 0 ; (command[i].name != NULL) && (found == 0) ; i++ )
     
    13131327        if (!found)
    13141328    {   
    1315         printf("  error : undefined command <%s>\n", argv[0]);
     1329        printf("  error : undefined command type <%s>\n", argv[0]);
    13161330
    13171331        // release semaphore to get next command
     
    13321346
    13331347
    1334 /*  direct command to help debug
    1335 
    1336     if( getpid() == 2 )
     1348//  direct command to help debug
     1349
     1350    if( getpid() == 0x2)
    13371351    {
    13381352        if( sem_wait( &semaphore ) )
     
    13431357        else
    13441358        {
    1345             strcpy( cmd , "load bin/user/chat.elf 0" );
     1359           strcpy( cmd , "load bin/user/tcp_chat.elf 1 0xbbbbbbbb 0xaaaaaaaa 0xcc" );
    13461360            printf("[ksh] %s\n", cmd );
    13471361            execute( cmd );
     
    13491363    }
    13501364
    1351     else if( getpid() == 3 )
     1365    if( getpid() == 0x3 )
    13521366    {
    13531367        if( sem_wait( &semaphore ) )
     
    13581372        else
    13591373        {
    1360             strcpy( cmd , "load bin/user/chat.elf 1" );
     1374            strcpy( cmd , "load bin/user/tcp_chat.elf 0 0xaaaaaaaa 0xbbbbbbbb 0xcc" );
    13611375            printf("[ksh] %s\n", cmd );
    13621376            execute( cmd );
     
    13641378    }
    13651379
    1366 */
     1380//
    13671381
    13681382        enum fsm_states
     
    16111625#endif
    16121626
    1613     // signal INIT process
    1614     kill( 1 , SIGCONT );
    1615    
    1616     // enter infinite loop monitoring children processes termination
     1627    // enter infinite loop monitoring children  termination
    16171628    while( 1 )
    16181629    {
Note: See TracChangeset for help on using the changeset viewer.