📄 scpu.c
字号:
} else { error = SHELL_ERROR_OPTION; shell_error_data = argv[arg]; ok = FALSE; break; } break; case SHELL_TOKEN_NUMBER : if( !cache_configurable ) ok = FALSE; else if( count == 0 ) integer1 = decode.number; else if( count == 1 ) integer2 = decode.number; else ok = FALSE; count++; break; case SHELL_TOKEN_STRING : if( !mmu_configurable || (parms->mmu_type != -1) ) ok = FALSE; else { if( strcmp( decode.string, "tlb" ) == 0 ) parms->mmu_type = MMU_TLB; else if( strcmp( decode.string, "fixed" ) == 0 ) parms->mmu_type = MMU_FIXED; else ok = FALSE; } break; default : /* Should not happen */ ok = FALSE; break; } } if( !ok ) return error; if( !parms->icache && !parms->dcache && !parms->mmu && ( parms->mmu_type == -1 ) ) { parms->icache = cache_configurable; parms->dcache = cache_configurable; parms->mmu = mmu_configurable; } /* Verify */ if( parms->available ) { if( parms->update || parms->reset || parms->permanent || (count != 0) || (parms->mmu_type != -1) ) { return SHELL_ERROR_SYNTAX; } else return OK; } if( parms->update ) { if( parms->reset || parms->permanent || (count != 0) || (parms->mmu_type != -1) ) { return SHELL_ERROR_SYNTAX; } else return OK; } if( parms->reset ) { if( (count != 0) || (parms->mmu_type != -1) ) { return SHELL_ERROR_SYNTAX; } else return OK; } if( count != 0 ) { if( parms->mmu || (parms->mmu_type != -1) ) return SHELL_ERROR_SYNTAX; /* Must select one and only one cache (i/d) */ if( parms->icache && parms->dcache ) return SHELL_ERROR_SYNTAX; if( !parms->icache && !parms->dcache ) return SHELL_ERROR_SYNTAX; if( legal_bpw( parms->icache, integer1 ) ) parms->bpw = integer1; else if( legal_assoc( parms->icache, integer1 ) ) parms->assoc = integer1; else return SHELL_ERROR_ILLEGAL_CACHE_CFG; if( count == 2 ) { if( parms->bpw == -1 ) { if( legal_bpw( parms->icache, integer2 ) ) parms->bpw = integer2; else return SHELL_ERROR_ILLEGAL_CACHE_CFG; } else { if( legal_assoc( parms->icache, integer2 ) ) parms->assoc = integer2; else return SHELL_ERROR_ILLEGAL_CACHE_CFG; } } } if( parms->mmu_type != -1 ) { if( parms->mmu ) return SHELL_ERROR_SYNTAX; else { parms->mmu = TRUE; return OK; } } return OK;}static boollegal_bpw( bool icache, UINT32 bpw ){ UINT32 count; UINT32 *array; UINT32 i; count = icache ? i_bpw_count : d_bpw_count; array = icache ? i_bpw_array : d_bpw_array; for( i=0; (i<count) && (bpw != array[i]); i++ ); return (i == count) ? FALSE : TRUE;}static boollegal_assoc( bool icache, UINT32 assoc ){ UINT32 count; UINT32 *array; UINT32 i; count = icache ? i_assoc_count : d_assoc_count; array = icache ? i_assoc_array : d_assoc_array; for( i=0; (i<count) && (assoc != array[i]); i++ ); return (i == count) ? FALSE : TRUE;}static voiddisp_available( bool icache, bool dcache, bool mmu ){ UINT32 i; char msg[200]; SHELL_PUTS( "Available settings :\n" ); /* I-cache */ if( icache ) { /* BPW */ sprintf( msg, " I-Cache bytes per way :" ); for( i = 0; i<i_bpw_count; i++ ) { sprintf( &msg[strlen(msg)], (i == 0) ? " 0x%x" : ", 0x%x" , i_bpw_array[i] ); } sprintf( &msg[strlen(msg)], "\n" ); SHELL_PUTS( msg ); /* ASSOC */ sprintf( msg, " I-Cache associativity :" ); for( i = 0; i<i_assoc_count; i++ ) { sprintf( &msg[strlen(msg)], (i == 0) ? " %d" : ", %d" , i_assoc_array[i] ); } sprintf( &msg[strlen(msg)], "\n" ); SHELL_PUTS( msg ); } /* D-cache */ if( dcache ) { /* BPW */ sprintf( msg, " D-Cache bytes per way :" ); for( i = 0; i<d_bpw_count; i++ ) { sprintf( &msg[strlen(msg)], (i == 0) ? " 0x%x" : ", 0x%x" , d_bpw_array[i] ); } sprintf( &msg[strlen(msg)], "\n" ); SHELL_PUTS( msg ); /* ASSOC */ sprintf( msg, " D-Cache associativity :" ); for( i = 0; i<d_assoc_count; i++ ) { sprintf( &msg[strlen(msg)], (i == 0) ? " %d" : ", %d" , d_assoc_array[i] ); } sprintf( &msg[strlen(msg)], "\n" ); SHELL_PUTS( msg ); } /* MMU */ if( mmu ) { SHELL_PUTS( " MMU types : tlb, fixed\n" ); }}static UINT32store_current( bool icache, bool dcache, bool mmu, t_sys_cpu_decoded *setting ){ char s[80]; t_sys_cpu_decoded decoded; if( !env_get( "cpuconfig", NULL, (void *)&decoded, sizeof(t_sys_cpu_decoded) ) ) { return SHELL_ERROR_VAR_FLASH; } if( icache ) { decoded.i_bpw = setting->i_bpw; decoded.i_assoc = setting->i_assoc; } if( dcache ) { decoded.d_bpw = setting->d_bpw; decoded.d_assoc = setting->d_assoc; } if( mmu ) { decoded.mmu_tlb = setting->mmu_tlb; } env_setup_cpuconfig( s, &decoded ); return env_set( "cpuconfig", s, ENV_ATTR_RW, NULL, NULL );}static voiddisp_current( bool icache, bool dcache, bool mmu, t_sys_cpu_decoded *setting ){ char msg[80]; SHELL_PUTS( "Current settings :\n" ); if( icache ) { sprintf( msg, " I-Cache bytes per way = 0x%x\n", setting->i_bpw ); SHELL_PUTS( msg ); sprintf( msg, " I-Cache associativity = %d\n", setting->i_assoc ); SHELL_PUTS( msg ); } if( dcache ) { sprintf( msg, " D-Cache bytes per way = 0x%x\n", setting->d_bpw ); SHELL_PUTS( msg ); sprintf( msg, " D-Cache associativity = %d\n", setting->d_assoc ); SHELL_PUTS( msg ); } if( mmu ) { SHELL_PUTS( " MMU = " ); SHELL_PUTS( setting->mmu_tlb ? "tlb\n" : "fixed\n" ); }}static char synopsis_cache[] = "scpu ( [-i|-d]+ [-a|-u|(-r|-p)+] ) |\n" " ( (-i|-d) <bpw> [<assoc>] [-p] ) |\n" " ( (-i|-d) <assoc> [<bpw>] [-p] )";static char synopsis_mmu[] = "scpu [-a|-u|(-r|-p)+] | ( (tlb|fixed) [-p] )";static char synopsis_cache_mmu[] = "scpu ( [-i|-d|-m]+ [-a|-u|(-r|-p)+] ) |\n" " ( (-i|-d) <bpw> [<assoc>] [-p] ) |\n" " ( (-i|-d) <assoc> [<bpw>] [-p] ) |\n" " ( (tlb|fixed) [-p] )";static t_cmd cmd_def ={ "scpu", scpu, NULL, "Configure or view current cpu configuration.\n\n" "scpu does not by default modify the semi-permanent scpu\n" "setting recorded in the environment variable 'cpuconfig'.\n" "By default, cpuconfig is an empty string, implying processor\n" "specific hardware reset configuration.\n" "Use the '-p' option if you want to set the environment variable.\n" "Use 'unsetenv cpuconfig' if you wish to reset cpuconfig to an\n" "empty string.\n\n" "The following operations are available :\n\n" "Display available settings.\n" "Display current configuration.\n" "Edit configuration.\n" "Setup configuration based on environment variable.\n" "Reset configuration to hardware default.\n" "Store current configuration in environment variable.\n\n" "'scpu' without options or parameters displays the current\n" "configuration.", options, 0, FALSE};/************************************************************************ * Implementation : Public functions ************************************************************************//************************************************************************ * * shell_scpu_init * Description : * ------------- * * Initialise command * * Return values : * --------------- * * void * ************************************************************************/t_cmd *shell_scpu_init( bool cache, bool mmu ){ cache_configurable = cache; mmu_configurable = mmu; cmd_def.option_count = OPTION_COUNT_BASIC; if( cache ) { memcpy( &options[ cmd_def.option_count++ ], &options_enhanced[ OPTION_ICACHE ], sizeof( t_cmd_option ) ); memcpy( &options[ cmd_def.option_count++ ], &options_enhanced[ OPTION_DCACHE ], sizeof( t_cmd_option ) ); cmd_def.syntax = synopsis_cache; } if( mmu ) { if( cache ) { memcpy( &options[ cmd_def.option_count++ ], &options_enhanced[ OPTION_MMU ], sizeof( t_cmd_option ) ); } cmd_def.syntax = cache ? synopsis_cache_mmu : synopsis_mmu; } return &cmd_def;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -