📄 cp0.c
字号:
/************************************************************************
*
* cp0.c
*
* Read/Write CP0 register
*
* cp0 [<name> [<value>]]
*
*
* ######################################################################
*
* 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 <string.h>
#include <stdio.h>
#include <shell_api.h>
#include <syscon_api.h>
#include "shell.h"
/************************************************************************
* Definitions
************************************************************************/
typedef struct
{
char *name;
UINT32 id;
}
t_cp0_reg;
/************************************************************************
* Public variables
************************************************************************/
/************************************************************************
* Static variables
************************************************************************/
static t_cp0_reg regs[] =
{
{ "badvaddr", SYSCON_CPU_CP0_BADVADDR_ID },
{ "cacheerr", SYSCON_CPU_CP0_CACHEERR_ID },
{ "cause", SYSCON_CPU_CP0_CAUSE_ID },
{ "compare", SYSCON_CPU_CP0_COMPARE_ID },
{ "config", SYSCON_CPU_CP0_CONFIG_ID },
{ "config1", SYSCON_CPU_CP0_CONFIG1_ID },
{ "context", SYSCON_CPU_CP0_CONTEXT_ID },
{ "count", SYSCON_CPU_CP0_COUNT_ID },
{ "datahi1", SYSCON_CPU_CP0_DATAHI1_ID },
{ "datalo1", SYSCON_CPU_CP0_DATALO1_ID },
{ "debug", SYSCON_CPU_CP0_DEBUG_ID },
{ "depc", SYSCON_CPU_CP0_DEPC_ID },
{ "desave", SYSCON_CPU_CP0_DESAVE_ID },
{ "ecc", SYSCON_CPU_CP0_ECC_ID },
{ "entryhi", SYSCON_CPU_CP0_ENTRYHI_ID },
{ "entrylo0", SYSCON_CPU_CP0_ENTRYLO0_ID },
{ "entrylo1", SYSCON_CPU_CP0_ENTRYLO1_ID },
{ "epc", SYSCON_CPU_CP0_EPC_ID },
{ "errorepc", SYSCON_CPU_CP0_ERROREPC_ID },
{ "index", SYSCON_CPU_CP0_INDEX_ID },
{ "lladdr", SYSCON_CPU_CP0_LLADDR_ID },
{ "pagemask", SYSCON_CPU_CP0_PAGEMASK_ID },
{ "perfcount", SYSCON_CPU_CP0_PERFCOUNT_ID },
{ "prid", SYSCON_CPU_CP0_PRID_ID },
{ "random", SYSCON_CPU_CP0_RANDOM_ID },
{ "status", SYSCON_CPU_CP0_STATUS_ID },
{ "taghi0", SYSCON_CPU_CP0_TAGHI0_ID },
{ "taglo0", SYSCON_CPU_CP0_TAGLO0_ID },
{ "watchhi", SYSCON_CPU_CP0_WATCHHI_ID },
{ "watchlo", SYSCON_CPU_CP0_WATCHLO_ID },
{ "wired", SYSCON_CPU_CP0_WIRED_ID }
};
#define REG_COUNT (sizeof(regs)/sizeof(t_cp0_reg))
/************************************************************************
* Static function prototypes
************************************************************************/
static UINT32
get_options(
UINT32 argc,
char **argv,
char **reg,
UINT32 *value,
bool *read );
/************************************************************************
* Implementation : Static functions
************************************************************************/
/************************************************************************
* cp0
************************************************************************/
static MON_FUNC(cp0)
{
char *reg;
UINT32 value;
bool read;
UINT32 i;
char msg[80];
UINT32 rc;
UINT32 printed = 0;
/* Options */
rc = get_options( argc, argv, ®, &value, &read );
if( rc != OK )
return rc;
if( !reg )
{
SHELL_PUTC( '\n' );
for(i=0; i< REG_COUNT; i++ )
{
if( SYSCON_read( regs[i].id, &value, sizeof(UINT32) ) == OK )
{
if( (printed % 2) == 0 )
{
if( SHELL_PUTS( regs[i].name ) )
return OK;
sprintf( msg, "= 0x%08x", value );
if( SHELL_PUTS_INDENT( msg, 10 ) )
return OK;
}
else
{
if( SHELL_PUTS_INDENT( regs[i].name, 25 ) )
return OK;
sprintf( msg, "= 0x%08x\n", value );
if( SHELL_PUTS_INDENT( msg, 35 ) )
return OK;
}
printed++;
}
}
SHELL_PUTS( (i % 2) ? "\n\n" : "\n" );
}
else
{
for( i=0;
(strcmp(reg, regs[i].name) != 0) &&
(i < REG_COUNT);
i++ );
if( i == REG_COUNT )
return SHELL_ERROR_UNKNOWN_CP0_REG;
if(read)
{
if( SYSCON_read( regs[i].id, &value, sizeof(UINT32) ) == OK )
{
if( SHELL_PUTS( regs[i].name ) )
return OK;
sprintf( msg, " = 0x%08x\n", value );
if( SHELL_PUTS( msg ) )
return OK;
}
else
return SHELL_ERROR_UNKNOWN_CP0_REG;
}
else
{
if( SYSCON_write( regs[i].id, &value, sizeof(UINT32) ) != OK )
return SHELL_ERROR_RO_CP0_REG;
}
}
return OK;
}
/************************************************************************
* get_options
************************************************************************/
static UINT32
get_options(
UINT32 argc,
char **argv,
char **reg,
UINT32 *value,
bool *read )
{
t_shell_option decode;
UINT32 type;
UINT32 arg;
bool ok = TRUE;
UINT32 error = SHELL_ERROR_SYNTAX;
/* Defaults */
*reg = NULL;
*read = TRUE;
for( arg = 1;
ok &&
(arg < argc) &&
shell_decode_token( argv[arg], &type, &decode );
arg++ )
{
switch( type )
{
case SHELL_TOKEN_OPTION :
error = SHELL_ERROR_OPTION;
shell_error_data = argv[arg];
ok = FALSE;
break;
case SHELL_TOKEN_NUMBER :
if( *read )
{
*value = decode.number;
*read = FALSE;
}
else
{
ok = FALSE;
}
break;
default :
if( *reg )
ok = FALSE;
else
*reg = argv[arg];
break;
}
}
if( ok && (*reg == NULL) && !(*read) )
ok = FALSE;
return ok ? OK : error;
}
/* Command definition for help */
static t_cmd cmd_def =
{
"cp0",
cp0,
"cp0 [<name> [<value>]]",
"Read/write CP0 register(s).\n\n"
"If no arguments are applied, all CP0 registers are shown.\n"
"If the name of a CP0 register is applied, this register is\n"
"written or read depending on whether a value is applied or not.\n"
"Writing a CP0 register takes effect immediately and should\n"
"be done with care since it may crash YAMON.\n"
"Some of the CP0 registers are optional and not available for\n"
"all CPUs.\n\n"
"Settings of CP0 registers are also applied to user applications\n"
"(started with 'go' or 'gdb') except for STATUS, for which the\n"
"IE field is cleared.\n"
"Also, TLB related registers as well as COUNT and COMPARE are\n"
"undefined when user application is first started.",
NULL,
0,
FALSE
};
/************************************************************************
* Implementation : Public functions
************************************************************************/
/************************************************************************
*
* shell_cp0_init
* Description :
* -------------
*
* Initialise command
*
* Return values :
* ---------------
*
* void
*
************************************************************************/
t_cmd *
shell_cp0_init( void )
{
return &cmd_def;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -