⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 env.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ * *  env.c * *  ENV module * *  This module implements YAMON environment variables. It will create *  default variables as well. * *  This file holds the generic part of the ENV module (except for TTY *  related parts, which are found in ./env_tty.c). * *  Platform specific parts are found in yamon/arch/env directory.  *  *  ENV uses the SYSENV module, which manages "raw" records. * * ###################################################################### * * mips_start_of_legal_notice *  * Copyright (c) 2004 MIPS Technologies, Inc. All rights reserved. * * * Unpublished rights (if any) reserved under the copyright laws of the * United States of America and other countries. * * This code is proprietary to MIPS Technologies, Inc. ("MIPS * Technologies"). Any copying, reproducing, modifying or use of this code * (in whole or in part) that is not expressly permitted in writing by MIPS * Technologies or an authorized third party is strictly prohibited. At a * minimum, this code is protected under unfair competition and copyright * laws. Violations thereof may result in criminal penalties and fines. * * MIPS Technologies reserves the right to change this code to improve * function, design or otherwise. MIPS Technologies does not assume any * liability arising out of the application or use of this code, or of any * error or omission in such code. Any warranties, whether express, * statutory, implied or otherwise, including but not limited to the implied * warranties of merchantability or fitness for a particular purpose, are * excluded. Except as expressly provided in any written license agreement * from MIPS Technologies or an authorized third party, the furnishing of * this code does not give recipient any license to any intellectual * property rights, including any patent rights, that cover this code. * * This code shall not be exported, reexported, transferred, or released, * directly or indirectly, in violation of the law of any country or * international law, regulation, treaty, Executive Order, statute, * amendments or supplements thereto. Should a conflict arise regarding the * export, reexport, transfer, or release of this code, the laws of the * United States of America shall be the governing law. * * This code constitutes one or more of the following: commercial computer * software, commercial computer software documentation or other commercial * items. If the user of this code, or any related documentation of any * kind, including related technical data or manuals, is an agency, * department, or other entity of the United States government * ("Government"), the use, duplication, reproduction, release, * modification, disclosure, or transfer of this code, or any related * documentation of any kind, is restricted in accordance with Federal * Acquisition Regulation 12.212 for civilian agencies and Defense Federal * Acquisition Regulation Supplement 227.7202 for military agencies. The use * of this code by the Government is further restricted in accordance with * the terms of the license agreement(s) and/or applicable contract terms * and conditions covering this code from MIPS Technologies or an authorized * third party. * * * *  * mips_end_of_legal_notice *  * ************************************************************************//************************************************************************ *  Include files ************************************************************************/#include <sysdefs.h>#include <sys_api.h>#include <syscon_api.h>#include <sysenv_api.h>#include <shell_api.h>  /* Due to env_print_all */#include <env_api.h>#include <env.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#include <syserror.h>#include <errno.h>/************************************************************************ *  Definitions ************************************************************************/typedef struct{    UINT32        index;    UINT8         attr;    char          *default_value;    t_env_decode  decode;    char	  data[SYS_USER_ENVIRONMENT_DATA_SIZE];}t_env_var_info;#define INDEX_NONE	      (SYS_USER_ENVIRONMENT_MAX_INDEX + 1)#define INDEX_REARRANGED      (SYS_USER_ENVIRONMENT_MAX_INDEX + 2)/************************************************************************ *  Public variables ************************************************************************//************************************************************************ *  Static variables ************************************************************************/static char* error_string[] ={    /* ERROR_ENV_VAR_NAME_LEN */    "Too long variable name",    /* ERROR_ENV_VAR_RO */	    "Read only variable",    /* ERROR_ENV_VAR_VALUE */	    "Illegal value",    /* ERROR_ENV_VAR_OVERFLOW */    "Too many environment variables",    /* ERROR_ENV_VAR_VAL_LEN */     "Too long variable string"};static char	       *default_cpuconfig = "";static bool            cache_configurable, mmu_configurable;static UINT32	       config_init;static t_env_var       env_vars[SYS_USER_ENVIRONMENT_MAX_INDEX + 2];static t_env_var_info  env_var_info[SYS_USER_ENVIRONMENT_MAX_INDEX + 1];static UINT32	       env_var_count;static bool            env_corrupted;/*  If TRUE, variables that are otherwise RO, may be written *  (used during initialisation of system variables). */static bool	       ext_priviliges = FALSE;/************************************************************************ *  Static function prototypes ************************************************************************/static bool decode_number(     char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size,		/* Size of decoded data			*/    UINT32 base );		/* Base (8/10/16)			*/static bool hex_s2num(     char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size );		/* Size of decoded data			*/static boolvalidate_cache(    bool   icache,		/* TRUE -> ICACHE, FALSE -> DCACHE      */    UINT32 bpw,    UINT32 assoc );static boolvalidate_cpuconfig(    char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size );		/* Size of decoded data			*/static INT32 error_lookup(     t_sys_error_string *param );static UINT32access_var(    char         *name,    char	 **value,    UINT8	 attr,    char	 *default_value,    t_env_decode decode );static voidset_env_var(    t_env_var      *env_var,    t_env_var_info *info );static boollookup_env(    char   *name,    UINT32 *index );static intcompare(    UINT32 *x,    UINT32 *y );static UINT32remove_var(    UINT32 index,    bool   user,    bool   system,    bool   error_on_ro );static UINT32 env_to_flash(    UINT32    index_local,    UINT32    *index_flash );static void env_remove_from_flash(     UINT32 index );#ifdef EBstatic voidconvert_endianness(     char *s );#endifstatic void re_init( void );/************************************************************************ *  Implementation : Static functions ************************************************************************//************************************************************************ * *                          decode_number *  Description : *  ------------- * *  Decode number * *  Return values : *  --------------- * *  TRUE -> OK, FALSE -> Failed * ************************************************************************/static bool decode_number(     char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size,		/* Size of decoded data			*/    UINT32 base )		/* Base (8/10/16)			*/{    char   *endp;    UINT32 number;    if( !raw )        return FALSE;    /* Do the decoding */    errno = 0;    number = strtoul( raw, &endp, base );    if( decoded )    {        switch( size )	{	  case sizeof(UINT8) :	    *(UINT8 *)decoded  = (UINT8)number;	    break;	  case sizeof(UINT16) :	    *(UINT16 *)decoded = (UINT16)number;	    break;	  case sizeof(UINT32) :	    *(UINT32 *)decoded = (UINT32)number;	    break;	  default :	    return FALSE;        }    }      return        ( errno || (*endp != '\0') ) ?	    FALSE : TRUE;}/************************************************************************ * *                          hex_s2num * *  Description : *  ------------- * *  Decode decimal number * *  Return values : *  --------------- * *  TRUE -> OK, FALSE -> Failed * ************************************************************************/static bool hex_s2num(     char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size )		/* Size of decoded data			*/{    return decode_number( raw, decoded, size, 16 );}/************************************************************************ * *                          validate_cache *  Description : *  ------------- * *  Validate cache setting * *  Return values : *  --------------- * *  TRUE -> OK, FALSE -> Failed * ************************************************************************/static boolvalidate_cache(    bool   icache,		/* TRUE -> ICACHE, FALSE -> DCACHE      */    UINT32 bpw,    UINT32 assoc ){    t_sys_array sys_array;    UINT32	i;    sys_cpu_cache_bpw( icache, &sys_array );    for( i=0; 	     ( i < sys_array.count ) &&	     ( bpw != sys_array.array[i] );	 i++ );        if( i == sys_array.count ) return FALSE;    sys_cpu_cache_assoc( icache, &sys_array );    for( i=0; 	     ( i < sys_array.count ) &&	     ( assoc != sys_array.array[i] );	 i++ );        if( i == sys_array.count ) return FALSE;    return TRUE;}/************************************************************************ * *                          validate_cpuconfig *  Description : *  ------------- * *  Validate and decode cpuconfig environment variable of format : * *  [<i_bpw>,<i_assoc>,<d_bpw>,<d_assoc>[,(tlb|fixed)]] | (tlb|fixed)  * *  Return values : *  --------------- * *  TRUE -> OK, FALSE -> Failed * ************************************************************************/static boolvalidate_cpuconfig(    char   *raw,		/* The string				*/    void   *decoded,		/* Decoded data				*/    UINT32 size )		/* Size of decoded data			*/{    char   *endp;    UINT32 i_bpw, i_assoc, d_bpw, d_assoc;    bool   mmu_tlb;        if( !raw ) return FALSE;    errno = 0;    if( *raw == '\0' )     {        i_bpw   = sys_icache_lines/sys_icache_assoc*sys_icache_linesize;         i_assoc = sys_icache_assoc;        d_bpw   = sys_dcache_lines/sys_dcache_assoc*sys_dcache_linesize;         d_assoc = sys_dcache_assoc;        mmu_tlb = ((config_init >> 8) & 1) ? FALSE : TRUE;    }    else    {        if( cache_configurable )        {            /* Get i_bpw */            i_bpw = (UINT32)strtoul( raw, &endp, 10 );            if( (*endp != ',') || errno )                return FALSE;            endp++; /* Skip ',' */            raw = endp;            if( *endp == ' ' )                return FALSE;            /* Get i_assoc */                i_assoc = (UINT32)strtoul( raw, &endp, 10 );            if( (*endp != ',') || errno )                return FALSE;            endp++; /* Skip ',' */            raw = endp;            if( *endp == ' ' )                return FALSE;            /* Get d_bpw */            d_bpw = (UINT32)strtoul( raw, &endp, 10 );            if( (*endp != ',') || errno )                return FALSE;            endp++; /* Skip ',' */            raw = endp;            if( *endp == ' ' )                return FALSE;            /* Get d_assoc */                d_assoc = (UINT32)strtoul( raw, &endp, 10 );	    if( errno )	        return FALSE;	    if( mmu_configurable )	    {                if( *endp != ',' )                    return FALSE;                endp++; /* Skip ',' */                raw = endp;                if( *endp == ' ' )                    return FALSE;            }   	    else	    {	        if( *endp != '\0' )	            return FALSE;            }            /* Validate I-cache */            if( !validate_cache( TRUE, i_bpw, i_assoc ) )                return FALSE;            /* Validate D-cache */            if( !validate_cache( FALSE, d_bpw, d_assoc ) )                return FALSE;         }         if( mmu_configurable )         {            /* Get mmu */            if( strcmp( raw, "tlb" ) == 0 )	        mmu_tlb = TRUE;            else if( strcmp( raw, "fixed" ) == 0 )	        mmu_tlb = FALSE;	    else	        return FALSE;         }    }    /* Store decoded data */    if( decoded )    {        if( size != sizeof( t_sys_cpu_decoded ) )	    return FALSE;	   	((t_sys_cpu_decoded *)decoded)->i_bpw   = i_bpw;	((t_sys_cpu_decoded *)decoded)->i_assoc = i_assoc;	((t_sys_cpu_decoded *)decoded)->d_bpw   = d_bpw;	((t_sys_cpu_decoded *)decoded)->d_assoc = d_assoc;	((t_sys_cpu_decoded *)decoded)->mmu_tlb = mmu_tlb;    }            return TRUE;}/************************************************************************ * *                          error_lookup *  Description : *  ------------- *  Lookup error code to error string(s) * *  Parameters : *  ------------ * *  'param',   INOUT,    variable of type, t_sys_error_string. * *  Return values : *  --------------- * * 'OK' = 0x00:  * ************************************************************************/static INT32 error_lookup(     t_sys_error_string *param ){    UINT32 t = SYSERROR_ID( param->syserror );    /* check for recognized error code */    if( t < sizeof(error_string)/sizeof(char *) )    {        param->count = 1;        /* fill in mandatory error message string */        param->strings[SYSCON_ERRORMSG_IDX] = error_string[t];    }    else        param->count = 0;    return OK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -