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

📄 scpu.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

/************************************************************************
 *
 *  scpu.c
 *
 *  Monitor command for configuring cpu (cache, MMU etc.)
 *
 *  This feature is present specifically to support configuration
 *  testing of the core in a lead vehicle, and is not supported
 *  in any other environment.  Attempting to use this feature
 *  outside of the scope of a lead vehicle is a violation of the
 *  MIPS Architecture, and may cause unpredictable operation of
 *  the processor.
 *
 *  Configurable cache only :
 *
 *      scpu ( [-i|-d]+ [-a|-u|(-r|-p)+]    ) |
 *           ( (-i|-d) <bpw> [<assoc>] [-p] ) |
 *           ( (-i|-d) <assoc> [<bpw>] [-p] )
 *
 *  Configurable MMU only :
 *
 *      scpu [-a|-u|(-r|-p)+] | ( (tlb|fixed) [-p] )
 *
 *  Configurable cache and MMU
 *
 *      scpu ( [-i|-d|-m]+ [-a|-u|(-r|-p)+] ) |
 *           ( (-i|-d) <bpw> [<assoc>] [-p] ) |
 *           ( (-i|-d) <assoc> [<bpw>] [-p] ) |
 *           ( (tlb|fixed) [-p]		    )
 *
 *
 * ######################################################################
 *
 * Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved. 
 * 
 * Unpublished rights reserved under the Copyright Laws of the United States of 
 * America. 
 * 
 * This document contains information that is proprietary to MIPS Technologies, 
 * Inc. ("MIPS Technologies"). Any copying, modifying or use of this information 
 * (in whole or in part) which is not expressly permitted in writing by MIPS 
 * Technologies or a contractually-authorized third party is strictly 
 * prohibited. At a minimum, this information is protected under unfair 
 * competition laws and the expression of the information contained herein is 
 * protected under federal copyright laws. Violations thereof may result in 
 * criminal penalties and fines. 
 * MIPS Technologies or any contractually-authorized third party reserves the 
 * right to change the information contained in this document to improve 
 * function, design or otherwise. MIPS Technologies does not assume any 
 * liability arising out of the application or use of this information. Any 
 * license under patent rights or any other intellectual property rights owned 
 * by MIPS Technologies or third parties shall be conveyed by MIPS Technologies 
 * or any contractually-authorized third party in a separate license agreement 
 * between the parties. 
 * The information contained in this document constitutes one or more of the 
 * following: commercial computer software, commercial computer software 
 * documentation or other commercial items. If the user of this information, 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 information, 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 information 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 information from MIPS Technologies or any 
 * contractually-authorized third party. 
 *
 ************************************************************************/


/************************************************************************
 *  Include files
 ************************************************************************/

#include <sysdefs.h>
#include <syscon_api.h>
#include <env_api.h>
#include <sys_api.h>
#include <shell_api.h>
#include <mips.h>
#include "shell.h"
#include <stdio.h>
#include <string.h>

/************************************************************************
 *  Definitions
 ************************************************************************/

typedef struct
{
    bool   icache;	/* Select I-cache		     */
    bool   dcache;	/* Select D-cache		     */
    bool   mmu;		/* Select MMU			     */
    bool   available;   /* List available settings	     */
    bool   update;	/* Update from environment variables */
    bool   reset;	/* Set to hardware reset values      */
    bool   permanent;	/* Commit to flash		     */
    UINT32 bpw;		/* Bytes per way		     */
    UINT32 assoc;	/* Associativity (number of ways)    */
    UINT32 mmu_type;	/* MMU type			     */
#define MMU_TLB	   0
#define MMU_FIXED  1
}
t_parms;


/************************************************************************
 *  Public variables
 ************************************************************************/

/************************************************************************
 *  Static variables
 ************************************************************************/


static t_cmd_option options[] =
{
  { "a", "Display available configurations." },
  { "u", "Configure based on environment variable." },
  { "r", "Reset configuration to hardware reset value." },
  { "p", "Commit configuration to environment variable." },

  /* Space for cache/mmu options */
  { NULL, NULL },
  { NULL, NULL },
  { NULL, NULL }
};
#define OPTION_COUNT_BASIC	(sizeof(options)/sizeof(t_cmd_option) - 3)

static t_cmd_option options_enhanced[] =
{
#define OPTION_ICACHE   0
  { "i", "Display/configure instruction-cache settings." },
#define OPTION_DCACHE   1
  { "d", "Display/configure data-cache settings." },
#define OPTION_MMU	2
  { "m", "Display/configure MMU type." }
};

static bool cache_configurable, mmu_configurable;

static UINT32 *i_bpw_array,   i_bpw_count;
static UINT32 *d_bpw_array,   d_bpw_count;
static UINT32 *i_assoc_array, i_assoc_count;
static UINT32 *d_assoc_array, d_assoc_count;

/************************************************************************
 *  Static function prototypes
 ************************************************************************/

/************************************************************************
 *  Implementation : Static functions
 ************************************************************************/

static UINT32
get_options(
    UINT32    argc,
    char      **argv,
    t_parms   *parms );

static void
disp_available( 
    bool icache,
    bool dcache,
    bool mmu
);

static void
disp_current( 
    bool	       icache,
    bool	       dcache,
    bool	       mmu,
    t_sys_cpu_decoded  *setting );

static UINT32
store_current( 
    bool	       icache,
    bool	       dcache,
    bool	       mmu,
    t_sys_cpu_decoded  *setting );

static bool
legal_bpw(
    bool   icache, 
    UINT32 bpw );

static bool
legal_assoc( 
    bool   icache,
    UINT32 bpw );


/************************************************************************
 *                          scpu
 ************************************************************************/
static MON_FUNC(scpu)
{
    t_parms            parms;
    UINT32	       rc;
    t_sys_array	       sys_array;
    UINT32	       config, config1;
    bool	       mmu_tlb;
    t_sys_cpu_decoded  decoded;
    t_sys_cpu_decoded  setting;

    /* Determine available settings */

    SYSCON_read( SYSCON_CPU_ICACHE_AVAIL_BPW_ID,
		 &sys_array,
		 sizeof(t_sys_array) );
    i_bpw_count = sys_array.count;
    i_bpw_array = sys_array.array;

    SYSCON_read( SYSCON_CPU_DCACHE_AVAIL_BPW_ID,
		 &sys_array,
		 sizeof(t_sys_array) );
    d_bpw_count = sys_array.count;
    d_bpw_array = sys_array.array;

    SYSCON_read( SYSCON_CPU_ICACHE_AVAIL_ASSOC_ID,
		 &sys_array,
		 sizeof(t_sys_array) );
    i_assoc_count = sys_array.count;
    i_assoc_array = sys_array.array;

    SYSCON_read( SYSCON_CPU_DCACHE_AVAIL_ASSOC_ID,
		 &sys_array,
		 sizeof(t_sys_array) );
    d_assoc_count = sys_array.count;
    d_assoc_array = sys_array.array;

    /* Get options */

    rc = get_options( argc, argv, &parms );

    if( rc != OK )
        return rc;
    else
    {
	SYSCON_read( parms.reset ?
		         SYSCON_CPU_CP0_CONFIG1_RESET_ID :
			 SYSCON_CPU_CP0_CONFIG1_ID,
		     &config1,
		     sizeof(UINT32) );

	SYSCON_read( parms.reset ?
		         SYSCON_CPU_CP0_CONFIG_RESET_ID :
		         SYSCON_CPU_CP0_CONFIG_ID,
		     &config,
		     sizeof(UINT32) );

	setting.i_bpw   = CACHE_CALC_BPW(REGFIELD( config1, C0_CONFIG1_IL ),
					 REGFIELD( config1, C0_CONFIG1_IS ));

	setting.i_assoc = CACHE_CALC_ASSOC(REGFIELD( config1, C0_CONFIG1_IA ));

	setting.d_bpw   = CACHE_CALC_BPW(REGFIELD( config1, C0_CONFIG1_DL ),
				         REGFIELD( config1, C0_CONFIG1_DS ));

	setting.d_assoc = CACHE_CALC_ASSOC(REGFIELD( config1, C0_CONFIG1_DA ));

        setting.mmu_tlb = ((config >> 8) & 1) ? FALSE : TRUE;


	/**** Actions ****/

	if( parms.available )
	{
	    disp_available( parms.icache, parms.dcache, parms.mmu );
	    return OK;
        }

	if( !parms.update && !parms.reset && !parms.permanent &&
	    (parms.bpw == -1) && (parms.assoc == -1)          &&
	    (parms.mmu_type == -1) )
        {
	    /* Request for display of current settings */
	    disp_current( parms.icache,
			  parms.dcache,
			  parms.mmu,
			  &setting );

	    return OK;
	}      

	if( parms.permanent &&
	    !parms.reset &&
	    (parms.bpw == -1) && (parms.assoc == -1) &&
	    (parms.mmu_type == -1) )
	{
	    /*  "scpu [-i|-d|-m] -p" command.
	     *  Store current configuration (i, d or both) in
	     *  environment variable(s).
	     */
	    return store_current( parms.icache,
				  parms.dcache,
				  parms.mmu,
				  &setting );
	}

	if( !parms.reset )
	{
	    /**** Update or Set request ****/

	    if( parms.update )
	    {
	        if( !env_get( "cpuconfig", NULL, (void *)&decoded,
			      sizeof(t_sys_cpu_decoded) ) )
		{
		    return SHELL_ERROR_VAR_FLASH;
		}
	    }

	    /* Setup I-Cache */

	    if( parms.icache )
	    {
	        if( parms.update )
	        {
		    setting.i_bpw   = decoded.i_bpw;
		    setting.i_assoc = decoded.i_assoc;
	        }
		else
		{
	            if(parms.bpw != -1)   setting.i_bpw   = parms.bpw;
	            if(parms.assoc != -1) setting.i_assoc = parms.assoc;
		}
            }

	    /* Setup D-Cache */

	    if( parms.dcache )
	    {
	        if( parms.update )
	        {
		    setting.d_bpw   = decoded.d_bpw;
		    setting.d_assoc = decoded.d_assoc;
	        }
		else
		{
	            if(parms.bpw != -1)   setting.d_bpw   = parms.bpw;
	            if(parms.assoc != -1) setting.d_assoc = parms.assoc;
		}
            }

	    /* Setup TLB */

	    if( parms.mmu )
	    {
	        if( parms.update )
	        {
		    setting.mmu_tlb = decoded.mmu_tlb;
	        }
		else
		{
	            setting.mmu_tlb = (parms.mmu_type == MMU_TLB) ?
				          TRUE : FALSE;
		}
	    }
        }

	/* Configure */
	sys_cpu_config( parms.icache,
			parms.dcache,
			parms.mmu,
			&setting );

	if( parms.permanent )
	{
	    return store_current( parms.icache,
			          parms.dcache,
				  parms.mmu,
				  &setting );
	}

	return OK;
    }
}


static UINT32
get_options(
    UINT32    argc,
    char      **argv,
    t_parms   *parms )
{
    t_shell_option decode;
    UINT32	   type;
    UINT32	   arg;
    bool	   ok    = TRUE;
    UINT32	   error = SHELL_ERROR_SYNTAX;
    UINT32	   count = 0;
    UINT32	   integer1, integer2;
    UINT32	   i;

    /* Setup default */
    parms->available  = FALSE;
    parms->update     = FALSE;
    parms->reset      = FALSE;
    parms->permanent  = FALSE;
    parms->icache     = FALSE;
    parms->dcache     = FALSE;
    parms->mmu	      = FALSE;
    parms->bpw	      = -1;
    parms->assoc      = -1;
    parms->mmu_type   = -1;

    for( arg = 1; 
	          ok && 
	          (arg < argc) && 
                  shell_decode_token( argv[arg], &type, &decode );
         arg++ )
    {
	switch( type )
	{
	  case SHELL_TOKEN_OPTION :
	    
	    if(      strcmp( decode.option, "a" ) == 0 )
	    {
		parms->available = TRUE;
	    }
	    else if( strcmp( decode.option, "u" ) == 0 )
	    {
		parms->update    = TRUE;
	    }
	    else if( strcmp( decode.option, "r" ) == 0 )
	    {
		parms->reset     = TRUE;
	    }
	    else if( strcmp( decode.option, "p" ) == 0 )
	    {
		parms->permanent = TRUE;
	    }
	    else if( cache_configurable && 
		     (strcmp( decode.option, "i" ) == 0) )
	    {
		parms->icache    = TRUE;
	    }
	    else if( cache_configurable && 
		     (strcmp( decode.option, "d" ) == 0) )
	    {
		parms->dcache    = TRUE;
	    }
	    else if( mmu_configurable && cache_configurable &&
		     (strcmp( decode.option, "m" ) == 0) )
	    {
	        parms->mmu       = TRUE;
	    }
	    else
	    {
		error	         = SHELL_ERROR_OPTION;
		shell_error_data = argv[arg];
		ok		 = FALSE;
		break;		      
	    }

⌨️ 快捷键说明

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