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

📄 cache_config.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
字号:

/************************************************************************
 *
 *  cache_config.c
 *
 *  Shell command for enabling/disabling caches by setting K0 field
 *  of CONFIG register.
 *
 *  cache [on|off]
 *
 *
 * ######################################################################
 *
 * 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 <sys_api.h>
#include <syscon_api.h>
#include <mips.h>
#include <string.h>
#include <shell_api.h>
#include "shell.h"

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

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

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

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

static UINT32 
get_options(
    UINT32 argc,
    char   **argv,
    bool   *display,
    bool   *cache_on );

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

/************************************************************************
 *                          cache
 ************************************************************************/
static MON_FUNC(cache)
{
    UINT32 rc;
    bool   display, cache_on;
    UINT32 config;

    rc = get_options( argc, argv, &display, &cache_on );

    if( rc != OK )
        return rc;
    else
    {
        if( display )
	{
	    SYSCON_read(
	        SYSCON_CPU_CP0_CONFIG_ID,
		(void *)&config,
		sizeof(UINT32) );
	    
	    SHELL_PUTS( 
	        ( REGFIELD( config, C0_CONFIG_K0 ) == C0_CONFIG_K0_UNCACHED ) ?
		    "Uncached\n" : "Cached\n" );
        }
	else
	{
            sys_cpu_k0_config( cache_on ? 
			         C0_CONFIG_K0_NONCOHERENT : 
			         C0_CONFIG_K0_UNCACHED );
	}
    }

    return OK;
}


/************************************************************************
 *                          get_options
 ************************************************************************/
static UINT32
get_options(
    UINT32 argc,
    char   **argv,
    bool   *display,
    bool   *cache_on )
{
    t_shell_option decode;
    UINT32	   type;

    if( argc == 1 )
    {
        *display = TRUE;
	return OK;
    }
    else
        *display = FALSE;

    if( argc != 2 ) 
        return SHELL_ERROR_SYNTAX;
    else
    {
        shell_decode_token( argv[1], &type, &decode );

	switch( type )
	{
	  case SHELL_TOKEN_OPTION :
	    shell_error_data = argv[1];
	    return SHELL_ERROR_OPTION;
	  case SHELL_TOKEN_STRING :
	    if( strcmp( decode.string, "on" ) == 0 )
	    {
	        *cache_on = TRUE;
		return OK;
	    }
	    else if( strcmp( decode.string, "off" ) == 0 )
	    {
	        *cache_on = FALSE;
		return OK;
	    }
	    else
	        return SHELL_ERROR_SYNTAX;
	  default :
	    return SHELL_ERROR_SYNTAX;
        }
    }
}


/* Command definition for cache */
static t_cmd cmd_def =
{
    "cache",
    cache,
    "cache [on|off]",

    "Enable/disable caches by setting K0 field of CPU CONFIG register.\n"
    "The command will flush D-cache before the K0 field is modified.\n"
    "If no parameter is supplied, the current cache setting is displayed.",

    NULL,
    0,
    FALSE
};


/************************************************************************
 *  Implementation : Public functions
 ************************************************************************/

/************************************************************************
 *
 *                          shell_cache_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_cache_init( void )
{
    return &cmd_def;
}

⌨️ 快捷键说明

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