Skip to content

Commit faf1f68

Browse files
author
Leon Alrae
committed
target-mips: add Config5.SBRI
SDBBP instruction Reserved Instruction control. The purpose of this field is to restrict availability of SDBBP to kernel mode operation. If the bit is set then SDBBP instruction can only be executed in kernel mode. User execution of SDBBP will cause a Reserved Instruction exception. Additionally add missing Config4 and Config5 cases for dm{f,t}c0. Signed-off-by: Leon Alrae <leon.alrae@imgtec.com> Reviewed-by: Yongbok Kim <yongbok.kim@imgtec.com>
1 parent 460c81f commit faf1f68

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

target-mips/cpu.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ struct CPUMIPSState {
410410
#define CP0C5_CV 29
411411
#define CP0C5_EVA 28
412412
#define CP0C5_MSAEn 27
413+
#define CP0C5_SBRI 6
413414
#define CP0C5_UFR 2
414415
#define CP0C5_NFExists 0
415416
int32_t CP0_Config6;
@@ -461,7 +462,7 @@ struct CPUMIPSState {
461462
#define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */
462463
uint32_t hflags; /* CPU State */
463464
/* TMASK defines different execution modes */
464-
#define MIPS_HFLAG_TMASK 0x1807FF
465+
#define MIPS_HFLAG_TMASK 0x5807FF
465466
#define MIPS_HFLAG_MODE 0x00007 /* execution modes */
466467
/* The KSU flags must be the lowest bits in hflags. The flag order
467468
must be the same as defined for CP0 Status. This allows to use
@@ -505,6 +506,7 @@ struct CPUMIPSState {
505506
#define MIPS_HFLAG_DSPR2 0x100000 /* Enable access to MIPS DSPR2 resources. */
506507
/* Extra flag about HWREna register. */
507508
#define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
509+
#define MIPS_HFLAG_SBRI 0x400000 /* R6 SDBBP causes RI excpt. in user mode */
508510
target_ulong btarget; /* Jump / branch target */
509511
target_ulong bcond; /* Branch condition (if needed) */
510512

@@ -760,7 +762,8 @@ static inline void compute_hflags(CPUMIPSState *env)
760762
{
761763
env->hflags &= ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 |
762764
MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU |
763-
MIPS_HFLAG_AWRAP | MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2);
765+
MIPS_HFLAG_AWRAP | MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2 |
766+
MIPS_HFLAG_SBRI);
764767
if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
765768
!(env->CP0_Status & (1 << CP0St_ERL)) &&
766769
!(env->hflags & MIPS_HFLAG_DM)) {
@@ -796,6 +799,10 @@ static inline void compute_hflags(CPUMIPSState *env)
796799
if (env->CP0_Status & (1 << CP0St_FR)) {
797800
env->hflags |= MIPS_HFLAG_F64;
798801
}
802+
if (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_KM) &&
803+
(env->CP0_Config5 & (1 << CP0C5_SBRI))) {
804+
env->hflags |= MIPS_HFLAG_SBRI;
805+
}
799806
if (env->insn_flags & ASE_DSPR2) {
800807
/* Enables access MIPS DSP resources, now our cpu is DSP ASER2,
801808
so enable to access DSPR2 resources. */

target-mips/translate.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6225,6 +6225,14 @@ static void gen_dmfc0(DisasContext *ctx, TCGv arg, int reg, int sel)
62256225
gen_mfc0_load32(arg, offsetof(CPUMIPSState, CP0_Config3));
62266226
rn = "Config3";
62276227
break;
6228+
case 4:
6229+
gen_mfc0_load32(arg, offsetof(CPUMIPSState, CP0_Config4));
6230+
rn = "Config4";
6231+
break;
6232+
case 5:
6233+
gen_mfc0_load32(arg, offsetof(CPUMIPSState, CP0_Config5));
6234+
rn = "Config5";
6235+
break;
62286236
/* 6,7 are implementation dependent */
62296237
case 6:
62306238
gen_mfc0_load32(arg, offsetof(CPUMIPSState, CP0_Config6));
@@ -6843,6 +6851,16 @@ static void gen_dmtc0(DisasContext *ctx, TCGv arg, int reg, int sel)
68436851
/* ignored */
68446852
rn = "Config3";
68456853
break;
6854+
case 4:
6855+
/* currently ignored */
6856+
rn = "Config4";
6857+
break;
6858+
case 5:
6859+
gen_helper_mtc0_config5(cpu_env, arg);
6860+
rn = "Config5";
6861+
/* Stop translation as we may have switched the execution mode */
6862+
ctx->bstate = BS_STOP;
6863+
break;
68466864
/* 6,7 are implementation dependent */
68476865
default:
68486866
rn = "Invalid config selector";
@@ -15801,7 +15819,11 @@ static void decode_opc_special_r6(CPUMIPSState *env, DisasContext *ctx)
1580115819
}
1580215820
break;
1580315821
case R6_OPC_SDBBP:
15804-
generate_exception(ctx, EXCP_DBp);
15822+
if (ctx->hflags & MIPS_HFLAG_SBRI) {
15823+
generate_exception(ctx, EXCP_RI);
15824+
} else {
15825+
generate_exception(ctx, EXCP_DBp);
15826+
}
1580515827
break;
1580615828
#if defined(TARGET_MIPS64)
1580715829
case OPC_DLSA:

0 commit comments

Comments
 (0)