Changeset 782 for soft/giet_vm/applications/shell
- Timestamp:
- Feb 7, 2016, 8:23:41 PM (9 years ago)
- Location:
- soft/giet_vm/applications/shell
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/shell/shell.c
r775 r782 1 1 /////////////////////////////////////////////////////////////////////////////////////// 2 // File : shell.c3 // Date : july 20154 // author : Clément Guérin2 // File : shell.c 3 // Date : july 2015 4 // authors : Clément Guérin and Alain Greiner 5 5 /////////////////////////////////////////////////////////////////////////////////////// 6 // Simple shell for GIET_VM.6 // Simple shell for the GIET_VM. 7 7 /////////////////////////////////////////////////////////////////////////////////////// 8 8 … … 10 10 #include "stdlib.h" 11 11 #include "malloc.h" 12 #include "string.h" 12 13 13 14 #define BUF_SIZE (256) // buffer for one command 14 15 #define MAX_ARGS (32) // max number of arguments in a command 16 #define FIFO_SIZE (1024) // FIFO depth for recursive ls 15 17 16 18 … … 47 49 } 48 50 51 49 52 ///////////////////////////////////////// 50 53 static void cmd_ls(int argc, char** argv) 51 54 { 52 int fd; 53 int rec; 54 char* pathname; 55 fat_dirent_t entry; 56 55 fat_dirent_t entry; 56 unsigned int recursive; 57 char* paths[FIFO_SIZE]; 58 unsigned int ptr = 0; 59 unsigned int ptw = 0; 60 61 // analyse arguments 57 62 if (argc == 2) 58 63 { 59 rec = 0; 60 pathname = argv[1]; 64 // allocate a buffer for root directory 65 // pathname, and push it in FIFO 66 paths[ptw] = malloc( strlen(argv[1]) ); 67 strcpy( paths[ptw] , argv[1] ); 68 69 giet_tty_printf("\n@@@ arg = %s / path = %s\n", argv[1] , paths[ptw] ); 70 71 ptw = (ptw + 1) % FIFO_SIZE; 72 73 // not recursive 74 recursive = 0; 61 75 } 62 76 else if ( (argc == 3) && (strcmp( argv[1] , "-r" ) == 0) ) 63 77 { 64 rec = 1; 65 pathname = argv[2]; 66 67 giet_tty_printf(" error : recursive mode not supported yet\n"); 68 return; 78 // allocate a buffer for root directory 79 // pathname, and push it in FIFO 80 paths[ptw] = malloc( strlen(argv[2]) ); 81 strcpy( paths[ptw] , argv[2] ); 82 ptw = (ptw + 1) % FIFO_SIZE; 83 84 // recursive 85 recursive = 1; 69 86 } 70 87 else … … 74 91 } 75 92 76 fd = giet_fat_opendir( pathname ); 77 78 if (fd < 0) 79 { 80 giet_tty_printf(" error : cannot open %s / err = %d)\n", argv[1], fd); 81 return; 82 } 83 84 while (giet_fat_readdir(fd, &entry) == 0) 85 { 86 if (entry.is_dir) giet_tty_printf("dir "); 87 else giet_tty_printf("file"); 88 89 giet_tty_printf(" | size = %d \t| cluster = %x \t| %s\n", 90 entry.size, entry.cluster, entry.name ); 91 } 92 93 giet_fat_closedir(fd); 94 } 93 // loop on registered directories 94 do 95 { 96 // open directory 97 int fd = giet_fat_opendir( paths[ptr] ); 98 if (fd < 0) 99 { 100 giet_tty_printf(" error : cannot open %s\n", paths[ptr] ); 101 return; 102 } 103 104 // display directory pathname 105 giet_tty_printf("*** %s ***\n", paths[ptr] ); 106 107 // loop on directory entries 108 while (giet_fat_readdir(fd, &entry) == 0) 109 { 110 // display entry 111 if ( entry.is_dir ) giet_tty_printf("dir "); 112 else giet_tty_printf("file"); 113 giet_tty_printf(" | size = %d \t| cluster = %x \t| %s\n", 114 entry.size, entry.cluster, entry.name ); 115 116 // allocate a buffer for subdirectory pathname 117 // and push it in FIFO if required 118 if ( entry.is_dir && recursive && 119 ( strcmp( entry.name , "." ) != 0 ) && 120 ( strcmp( entry.name , ".." ) != 0 ) ) 121 { 122 // check FIFO full 123 if ( ((ptr - ptw) % FIFO_SIZE) == 1 ) 124 { 125 giet_tty_printf(" sorry, not enough memory for recursive ls\n"); 126 return; 127 } 128 129 unsigned int length = strlen(paths[ptr]) + strlen(entry.name) + 2; 130 paths[ptw] = malloc( length ); 131 if ( strcmp( paths[ptr] , "/" ) == 0 ) 132 { 133 snprintf( paths[ptw] , length , "/%s" , entry.name ); 134 } 135 else 136 { 137 snprintf( paths[ptw] , length , "%s/%s" , paths[ptr] , entry.name ); 138 } 139 ptw = (ptw + 1) % FIFO_SIZE; 140 } 141 } // end loop on entries 142 143 // close directory 144 giet_fat_closedir(fd); 145 146 // release the directory pathname buffer 147 // and pop it from FIFO 148 free( paths[ptr] ); 149 ptr = (ptr + 1) % FIFO_SIZE; 150 151 } while ( ptr != ptw ); 152 153 } // end cmd_ls() 95 154 96 155 //////////////////////////////////////////// … … 504 563 giet_tty_alloc( 0 ); 505 564 giet_tty_printf( "~~~ shell ~~~\n\n" ); 565 566 // heap initialisation 567 unsigned int x_id; // x cluster coordinate 568 unsigned int y_id; // y cluster coordinate 569 unsigned int p_id; // local processor index 570 giet_proc_xyp( &x_id , &y_id , &p_id ); 571 heap_init( x_id , y_id ); 506 572 507 573 // display first prompt -
soft/giet_vm/applications/shell/shell.py
r768 r782 32 32 33 33 heap_base = 0x60000000 34 heap_size = 0x000 01000 # 4Kbytes34 heap_size = 0x00040000 # 256 Kbytes 35 35 36 36 mmap_base = 0x70000000 … … 57 57 local = False, big = True ) 58 58 59 # heap vseg (unused)59 # heap vseg 60 60 mapping.addVseg( vspace, 'shell_heap', heap_base, heap_size, 61 61 'C_WU', vtype = 'BUFFER', x = xmap , y = ymap , pseg = 'RAM',
Note: See TracChangeset
for help on using the changeset viewer.