Changeset 641 for trunk/user/ksh/ksh.c


Ignore:
Timestamp:
Oct 10, 2019, 1:42:04 PM (5 years ago)
Author:
alain
Message:
  • Fix several bugs.
  • Introduce the "stat" command in KSH.

This almos-mkh version sucessfully executed the FFT application
(65536 complex points) on the TSAR architecture from 1 to 64 cores.

File:
1 edited

Legend:

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

    r640 r641  
    123123
    124124#if DEBUG_CMD_CAT
    125 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__);
     125snprintf( string , 128 , "[ksh] %s enters" , __FUNCTION__);
    126126display_string( string );
    127127#endif
     
    138138
    139139#if DEBUG_CMD_CAT
    140 snprintf( string , 128 , "[ksh] in %s : after strcpy" , __FUNCTION__ );
     140snprintf( string , 128 , "[ksh] %s : after strcpy" , __FUNCTION__ );
    141141display_string( string );
    142142#endif
     
    180180
    181181#if DEBUG_CMD_CAT
    182 snprintf( string , 128 , "[ksh] %s : size = %d", __FUNCTION__, size );
     182snprintf( string , 128 , "[ksh] %s : size = %d",
     183__FUNCTION__, size );
    183184display_string( string );
    184185#endif
     
    206207
    207208#if DEBUG_CMD_CAT
    208 snprintf( string , 128 , "[ksh] %s : maped file %d to buffer %x", __FUNCTION__, fd , buf );
     209snprintf( string , 128 , "[ksh] %s : mapped file %d to buffer %x",
     210__FUNCTION__, fd , buf );
    209211display_string( string );
    210212#endif
     
    213215    write( 1 , buf , size );
    214216
    215     // unmap te file
     217    // unmap the file
    216218    if( munmap( buf , size ) )
    217219    {
     
    220222
    221223#if DEBUG_CMD_CAT
    222 snprintf( string , 128 , "[ksh] %s : unmaped file %d from buffer %x", __FUNCTION__, fd , buf );
     224snprintf( string , 128 , "[ksh] %s : unmapped file %d from buffer %x",
     225__FUNCTION__, fd , buf );
    223226display_string( string );
    224227#endif
     
    852855
    853856#if DEBUG_CMD_LS
    854 snprintf( string , 128 , "[ksh] %s : directory <%s> open / DIR %x\n",
     857snprintf( string , 128 , "[ksh] %s : directory <%s> open / DIR %x",
    855858__FUNCTION__, pathname , dir );
    856859display_string( string );
     
    875878
    876879#if DEBUG_CMD_LS
    877 snprintf( string , 128 , "[ksh] %s : directory <%s> closed\n",
     880snprintf( string , 128 , "[ksh] %s : directory <%s> closed",
    878881__FUNCTION__, pathname );
    879882display_string( string );
     
    10201023    sem_post( &semaphore );
    10211024
    1022 }  // end_cmd_rm()
     1025}  // end cmd_rm()
     1026
     1027///////////////////////////////////////////////
     1028static void cmd_stat( int argc , char **argv )
     1029{
     1030    struct stat    st;
     1031    unsigned int   size;
     1032
     1033        if (argc != 2)
     1034    {
     1035                printf("  usage: %s pathname\n", argv[0]);
     1036        }
     1037    else
     1038    {
     1039            strcpy( pathname , argv[1] );
     1040
     1041        if ( stat( pathname , &st ) )
     1042        {
     1043                    printf("  error: cannot stat <%s>\n", argv[2] );
     1044                }
     1045        else
     1046        {
     1047            // get file size
     1048            size = st.st_size;
     1049
     1050            // print file stat info
     1051            printf("   <%s> : %d bytes\n", pathname, size );
     1052        }
     1053        }
     1054
     1055    // release semaphore to get next command
     1056    sem_post( &semaphore );
     1057
     1058}  // end cmd_stat()
    10231059
    10241060///////////////////////////////////////////////
     
    11031139        { "rm",      "remove a file from file system",                  cmd_rm      },
    11041140        { "rmdir",   "remove a directory from file system",             cmd_rmdir   },
     1141        { "stat",    "print infos on a given file",                     cmd_stat    },
    11051142        { "trace",   "activate trace for a given core",                 cmd_trace   },
    11061143        { "untrace", "desactivate trace for a given core",              cmd_untrace },
     
    11491186
    11501187#if DEBUG_EXECUTE
    1151 snprintf( string , 128 , "\n[ksh] in %s : argc = %d / arg0 = %s / arg1 = %s\n",
     1188snprintf( string , 128 , "\n[ksh] in %s : argc = %d / arg0 = %s / arg1 = %s",
    11521189__FUNCTION__ , argc , argv[0], argv[1] );
    11531190#endif
     
    11871224        char           cmd[CMD_MAX_SIZE];               // buffer for one command
    11881225
    1189 /* 1. first direct command
     1226
     1227
     1228// 1. first direct command
    11901229if( sem_wait( &semaphore ) )
    11911230{
     
    11951234else
    11961235{
    1197     printf("\n[ksh] load bin/user/sort.elf\n");
     1236    strcpy( cmd , "load bin/user/fft.elf" );
     1237    printf("[ksh] %s\n", cmd );
     1238    execute( cmd );
    11981239}
    1199 
    1200 strcpy( cmd , "load bin/user/sort.elf" );
    1201 execute( cmd );
    1202 */
    1203 
    1204 
    1205 
    1206 // 2. second direct command
     1240//
     1241
     1242
     1243
     1244/* 2. second direct command
    12071245if( sem_wait( &semaphore ) )
    12081246{
     
    12121250else
    12131251{
    1214     printf("\n[ksh] load bin/user/fft.elf\n");
     1252    strcpy( cmd , "cat home/p_fft_dqt_16384_1_2" );
     1253    printf("[ksh] %s\n", cmd );
     1254    execute( cmd );
    12151255}
    1216 
    1217 strcpy( cmd , "load bin/user/fft.elf" );
    1218 execute( cmd );
    1219 //
    1220 
     1256*/
    12211257
    12221258
     
    12531289        {
    12541290            // initialize command buffer
    1255             // memset( cmd , 0x20 , sizeof(cmd) );   // TODO useful ?
    12561291            count       = 0;
    12571292            state       = NORMAL;
     
    14591494
    14601495#if DEBUG_MAIN
    1461 snprintf( string , 128 , "\n[ksh] main thread started on core[%x,%d]\n", cxy , lid );
     1496snprintf( string , 128 , "\n[ksh] main thread started on core[%x,%d]", cxy , lid );
    14621497display_string( string );
    14631498#endif
     
    14711506
    14721507#if DEBUG_MAIN
    1473 snprintf( string , 128 , "\n[ksh] main initialized semaphore\n" );
     1508snprintf( string , 128 , "\n[ksh] main initialized semaphore" );
    14741509display_string( string );
    14751510#endif
     
    14851520                    NULL );
    14861521#if DEBUG_MAIN
    1487 snprintf( string , 128 , "\n[ksh] main thread launched interactive thread %x\n", trdid );
     1522snprintf( string , 128 , "\n[ksh] main thread launched interactive thread %x", trdid );
    14881523display_string( string );
    14891524#endif
Note: See TracChangeset for help on using the changeset viewer.