aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@linux-mips.org>2015-04-03 18:25:04 -0400
committerRalf Baechle <ralf@linux-mips.org>2015-04-07 19:09:15 -0400
commitd4f5b088937e2dae7528245c597dcab7e57eb5f3 (patch)
tree7ed0a69bbb9ce1b9a1d09bd4f007a61f091100db /arch/mips
parentcb5d4aad6844cdbe2f3b9f5d581ae1c9ec342009 (diff)
MIPS: math-emu: Factor out CFC1/CTC1 emulation
Move CFC1/CTC1 emulation code to separate functions to avoid excessive indentation in forthcoming changes. Adjust formatting in a minor way and remove extraneous round brackets. Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/9682/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r--arch/mips/math-emu/cp1emu.c76
1 files changed, 48 insertions, 28 deletions
diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
index fc6ce90d21f8..be983850eb39 100644
--- a/arch/mips/math-emu/cp1emu.c
+++ b/arch/mips/math-emu/cp1emu.c
@@ -840,6 +840,52 @@ do { \
840#define DPTOREG(dp, x) DITOREG((dp).bits, x) 840#define DPTOREG(dp, x) DITOREG((dp).bits, x)
841 841
842/* 842/*
843 * Emulate a CFC1 instruction.
844 */
845static inline void cop1_cfc(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
846 mips_instruction ir)
847{
848 u32 value;
849
850 if (MIPSInst_RD(ir) == FPCREG_CSR) {
851 value = ctx->fcr31;
852 pr_debug("%p gpr[%d]<-csr=%08x\n",
853 (void *)xcp->cp0_epc,
854 MIPSInst_RT(ir), value);
855 } else if (MIPSInst_RD(ir) == FPCREG_RID)
856 value = 0;
857 else
858 value = 0;
859 if (MIPSInst_RT(ir))
860 xcp->regs[MIPSInst_RT(ir)] = value;
861}
862
863/*
864 * Emulate a CTC1 instruction.
865 */
866static inline void cop1_ctc(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
867 mips_instruction ir)
868{
869 u32 value;
870
871 if (MIPSInst_RT(ir) == 0)
872 value = 0;
873 else
874 value = xcp->regs[MIPSInst_RT(ir)];
875
876 /* we only have one writable control reg
877 */
878 if (MIPSInst_RD(ir) == FPCREG_CSR) {
879 pr_debug("%p gpr[%d]->csr=%08x\n",
880 (void *)xcp->cp0_epc,
881 MIPSInst_RT(ir), value);
882
883 /* Don't write reserved bits. */
884 ctx->fcr31 = value & ~FPU_CSR_RSVD;
885 }
886}
887
888/*
843 * Emulate the single floating point instruction pointed at by EPC. 889 * Emulate the single floating point instruction pointed at by EPC.
844 * Two instructions if the instruction is in a branch delay slot. 890 * Two instructions if the instruction is in a branch delay slot.
845 */ 891 */
@@ -853,7 +899,6 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
853 int likely, pc_inc; 899 int likely, pc_inc;
854 u32 __user *wva; 900 u32 __user *wva;
855 u64 __user *dva; 901 u64 __user *dva;
856 u32 value;
857 u32 wval; 902 u32 wval;
858 u64 dval; 903 u64 dval;
859 int sig; 904 int sig;
@@ -1046,37 +1091,12 @@ emul:
1046 1091
1047 case cfc_op: 1092 case cfc_op:
1048 /* cop control register rd -> gpr[rt] */ 1093 /* cop control register rd -> gpr[rt] */
1049 if (MIPSInst_RD(ir) == FPCREG_CSR) { 1094 cop1_cfc(xcp, ctx, ir);
1050 value = ctx->fcr31;
1051 pr_debug("%p gpr[%d]<-csr=%08x\n",
1052 (void *) (xcp->cp0_epc),
1053 MIPSInst_RT(ir), value);
1054 }
1055 else if (MIPSInst_RD(ir) == FPCREG_RID)
1056 value = 0;
1057 else
1058 value = 0;
1059 if (MIPSInst_RT(ir))
1060 xcp->regs[MIPSInst_RT(ir)] = value;
1061 break; 1095 break;
1062 1096
1063 case ctc_op: 1097 case ctc_op:
1064 /* copregister rd <- rt */ 1098 /* copregister rd <- rt */
1065 if (MIPSInst_RT(ir) == 0) 1099 cop1_ctc(xcp, ctx, ir);
1066 value = 0;
1067 else
1068 value = xcp->regs[MIPSInst_RT(ir)];
1069
1070 /* we only have one writable control reg
1071 */
1072 if (MIPSInst_RD(ir) == FPCREG_CSR) {
1073 pr_debug("%p gpr[%d]->csr=%08x\n",
1074 (void *) (xcp->cp0_epc),
1075 MIPSInst_RT(ir), value);
1076
1077 /* Don't write reserved bits. */
1078 ctx->fcr31 = value & ~FPU_CSR_RSVD;
1079 }
1080 if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) { 1100 if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
1081 return SIGFPE; 1101 return SIGFPE;
1082 } 1102 }