Changeset 768 for soft


Ignore:
Timestamp:
Jan 20, 2016, 10:15:22 AM (8 years ago)
Author:
alain
Message:

Use the giet_fat_mmap() syscall to implement the cat command.

Location:
soft/giet_vm/applications/shell
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/shell/shell.c

    r747 r768  
    314314    }
    315315
    316     unsigned int     x,y,p;   // processor coordinates
     316    unsigned int     x,y,p;          // processor coordinates
    317317    unsigned int     fd;             // file descriptor
    318318    fat_file_info_t  info;           // file info
    319319    unsigned int     size;           // buffer size (file_size + 1)
    320     unsigned int     len;            // number of read bytes from file
    321     char*            buf;            // temporary buffer
     320    unsigned int     bytes;          // number of bytes to be mapped 
     321    char*            buf = NULL;     // temporary buffer
    322322
    323323    // get processor coordinates
     
    325325   
    326326    // open the file to display   
    327     fd = giet_fat_open( argv[1] , O_RDONLY );
     327    fd = giet_fat_open( argv[1] , 0 );
    328328    if (fd < 0)
    329329    {
     
    341341    size = info.size; 
    342342
     343    // extend size to 4 Kbytes boundary if required
     344    if ( (size+1) & 0xFFF)  bytes = (size & 0xFFFFF000) + 0x1000;
     345    else                    bytes = size + 1;
     346
     347    // map local buffer to Cache_file
     348    buf = giet_fat_mmap( NULL,
     349                         bytes,
     350                         MAP_PROT_READ | MAP_PROT_WRITE,
     351                         MAP_SHARED,
     352                         fd,
     353                         0 );
     354    if ( buf == NULL )
     355    {
     356        giet_tty_printf("  error : cannot map %s\n", argv[1] );
     357        goto exit;
     358    }
     359
     360/*
    343361    // allocate a temporary buffer for the file
    344362    heap_init( x , y );
     
    349367        goto exit;
    350368    }
    351     // load the file and set terminating '0'
     369    // load the file
    352370    len = giet_fat_read( fd , buf , size );
    353371    if ( len != size )
     
    357375        goto exit;
    358376    }
     377*/
     378    // set terminating '0'
    359379    buf[size] = 0;
    360380
    361381    // display the file content
    362     giet_tty_printf("\n%s", buf );
     382    giet_tty_printf("%s", buf );
    363383
    364384exit:
    365385    if ( fd >= 0 )     giet_fat_close( fd );
    366     if ( buf != NULL ) free( buf );
     386    if ( buf != NULL ) giet_fat_munmap( buf , bytes );
    367387}
    368388
  • soft/giet_vm/applications/shell/shell.py

    r712 r768  
    3434    heap_size  = 0x00001000     # 4 Kbytes
    3535
     36    mmap_base  = 0x70000000
     37    mmap_size  = 0x10000000     # 256 Mbytes (unmapped)
     38
    3639    # create vspace
    3740    vspace = mapping.addVspace( name = 'shell', startname = 'shell_data' , active = True )
     
    5760    mapping.addVseg( vspace, 'shell_heap', heap_base, heap_size,
    5861                     'C_WU', vtype = 'BUFFER', x = xmap , y = ymap , pseg = 'RAM',
     62                     local = False )
     63
     64    # mmap vseg           
     65    mapping.addVseg( vspace, 'shell_mmap', mmap_base, mmap_size,
     66                     'C_WU', vtype = 'MMAP', x = xmap , y = ymap , pseg = 'RAM',
    5967                     local = False )
    6068
Note: See TracChangeset for help on using the changeset viewer.