Fix mfc0 and dmtc0 instructions on MIPS64
PATCH 1/1 Fix mfc0 and dmtc0 instructions on MIPS64
Hi all,
The patch below fixes the mfc0 and dmtc0 instructions for the MIPS64 target:
- The mfc0 instruction should return the 32 lowest bits of the coprocessor 0 register sign extended to 64-bit.
- The mtc0 instruction should do the same as the dmtc0 instruction for 64-bit coprocessor registers instead of copying only the low 32 bits.
- The XContest register does not exists on MIPS32 CPU.
Note that this patch does not fix the mfc0 and dmtc0 instructions for the EntryHi coprocessor 0 register, as it would break the MIPS64 target. I will send the fix in a later patch.
Bye,
Aurelien
cpu.h +2 -0
@@ -212,7 +212,9 @@ struct CPUMIPSState {target_ulong CP0_LLAddr;target_ulong CP0_WatchLo;int32_t CP0_WatchHi; +#ifdef TARGET_MIPS64 target_ulong CP0_XContext; +#endif int32_t CP0_Framemask;int32_t CP0_Debug;#define CPDB_DBD 31
op.c +50 -98
354 lines not on this page · raw message
translate.c +63 -57
362 lines not on this page · raw message
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Quoted 8 lines · Aurelien Jarno
Hi all,
The patch below fixes the mfc0 and dmtc0 instructions for the MIPS64 target:
- The mfc0 instruction should return the 32 lowest bits of the coprocessor 0 register sign extended to 64-bit.
Agreed, and I think it doess already. (The places where you added casts read fron 32bit wide registers anyway.)
Quoted 2 lines
- The mtc0 instruction should do the same as the dmtc0 instruction for 64-bit coprocessor registers instead of copying only the low 32 bits.
I'm not entirely sure about this, but it feels wrong, as mtc0 should have the same behaviour as on 32bit CPUs. What prompted the change here?
Quoted 1 line
- The XContest register does not exists on MIPS32 CPU.
Indeed, but simply not wiring up the instruction decoding for 32bit should be good enough, no need to #ifdef everything.
Thiemo
Quoted 11 lines · Thiemo Seufer
Quoted 7 lines · Aurelien Jarno
Hi all,
The patch below fixes the mfc0 and dmtc0 instructions for the MIPS64 target:
- The mfc0 instruction should return the 32 lowest bits of the coprocessor 0 register sign extended to 64-bit.
Agreed, and I think it doess already. (The places where you added casts read fron 32bit wide registers anyway.)
Oops, I haven't seen before that those registers were declared as int32_t, so that the sign extension is already done.
Forget that part.
Quoted 5 lines
Quoted 2 lines
- The mtc0 instruction should do the same as the dmtc0 instruction for 64-bit coprocessor registers instead of copying only the low 32 bits.
I'm not entirely sure about this, but it feels wrong, as mtc0 should have the same behaviour as on 32bit CPUs. What prompted the change here?
The MIPS64 ISA manual:
Operation:
data GPR[rt]
if (Width(CPR[0,rd,sel]) = 64) then
CPR[0,rd,sel] data
else
CPR[0,rd,sel] data31..0endif
But it is also need if you need to run a 32-bit kernel on MIPS64. For example the EntryHi register is a 64-bit register, and the higher 32 bits (and most notably the R part of this register) has to be filled. This part is initialised when an exception occurs, so even if a 32-bit kernel don't know about it, it already holds the correct values.
Quoted 5 lines
Quoted 1 line
- The XContest register does not exists on MIPS32 CPU.
Indeed, but simply not wiring up the instruction decoding for 32bit should be good enough, no need to #ifdef everything.
Ok.
Bye,
Aurelien
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Quoted 34 lines · Aurelien Jarno
Quoted 11 lines · Thiemo Seufer
Quoted 7 lines · Aurelien Jarno
Hi all,
The patch below fixes the mfc0 and dmtc0 instructions for the MIPS64 target:
- The mfc0 instruction should return the 32 lowest bits of the coprocessor 0 register sign extended to 64-bit.
Agreed, and I think it doess already. (The places where you added casts read fron 32bit wide registers anyway.)
Oops, I haven't seen before that those registers were declared as
int32_t, so that the sign extension is already done.Forget that part.
Quoted 5 lines
Quoted 2 lines
- The mtc0 instruction should do the same as the dmtc0 instruction for 64-bit coprocessor registers instead of copying only the low 32 bits.
I'm not entirely sure about this, but it feels wrong, as mtc0 should have the same behaviour as on 32bit CPUs. What prompted the change here?
The MIPS64 ISA manual:
Operation:
data GPR[rt] if (Width(CPR[0,rd,sel]) = 64) then CPR[0,rd,sel] data else CPR[0,rd,sel] data31..0 endif
Quoted 12 lines
But it is also need if you need to run a 32-bit kernel on MIPS64. For example the EntryHi register is a 64-bit register, and the higher 32 bits (and most notably the R part of this register) has to be filled. This part is initialised when an exception occurs, so even if a 32-bit kernel don't know about it, it already holds the correct values.
Quoted 5 lines
Quoted 1 line
- The XContest register does not exists on MIPS32 CPU.
Indeed, but simply not wiring up the instruction decoding for 32bit should be good enough, no need to #ifdef everything.
Please find below an updated patch against the current CVS that take into account the remarks you made.
Bye,
Aurelien
Index: op.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op.c,v
retrieving revision 1.51
op.c +15 -63
@@ -1262,7 +1262,7 @@ void op_mtc0_entrylo0 (void) {/* Large physaddr not implemented */ /* 1k pages not implemented */ - env->CP0_EntryLo0 = (int32_t )T0 &0x3FFFFFFF ; + env->CP0_EntryLo0 =T0 &0x3FFFFFFF ;RETURN (); }
@@ -1270,7 +1270,7 @@ void op_mtc0_entrylo1 (void) {/* Large physaddr not implemented */ /* 1k pages not implemented */ - env->CP0_EntryLo1 = (int32_t )T0 &0x3FFFFFFF ; + env->CP0_EntryLo1 =T0 &0x3FFFFFFF ;RETURN (); }
@@ -1340,9 +1340,9 @@ void op_mtc0_status (void)uint32_t val, old;uint32_t mask = env->Status_rw_bitmask; -/* No reverse endianness, no MDMX/DSP, no 64bit ops, -no 64bit addressing implemented. */ - val = (int32_t )T0 & mask; +/* No reverse endianness, no MDMX/DSP, no 64bit ops +implemented. */ + val =T0 & mask; old = env->CP0_Status; if (!(val & (1 << CP0St_EXL)) && !(val & (1 << CP0St_ERL)) &&
@@ -1397,7 +1397,7 @@ void op_mtc0_cause (void)void op_mtc0_epc (void ) { - env->CP0_EPC = (int32_t )T0 ; + env->CP0_EPC =T0 ;RETURN (); }
@@ -1426,7 +1426,7 @@ void op_mtc0_watchlo0 (void) {/* Watch exceptions for instructions, data loads, data stores not implemented. */ - env->CP0_WatchLo = (int32_t )(T0 & ~0x7 ); + env->CP0_WatchLo = (T0 & ~0x7 );RETURN (); }
@@ -1455,7 +1455,7 @@ void op_mtc0_debug (void)void op_mtc0_depc (void ) { - env->CP0_DEPC = (int32_t )T0 ; + env->CP0_DEPC =T0 ;RETURN (); }
@@ -1491,7 +1491,7 @@ void op_mtc0_datahi (void)void op_mtc0_errorepc (void ) { - env->CP0_ErrorEPC = (int32_t )T0 ; + env->CP0_ErrorEPC =T0 ;RETURN (); }
@@ -1502,6 +1502,12 @@ void op_mtc0_desave (void) }#ifdef TARGET_MIPS64 +void op_mtc0_xcontext (void ) +{ + env->CP0_XContext = (env->CP0_XContext &0x1ffffffff ) | (T0 & ~0x1ffffffff ); +RETURN (); +} +void op_dmfc0_entrylo0 (void ) {T0 = env->CP0_EntryLo0;
@@ -1567,60 +1573,6 @@ void op_dmfc0_errorepc (void)T0 = env->CP0_ErrorEPC; RETURN(); } - -void op_dmtc0_entrylo0 (void ) -{ -/* Large physaddr not implemented */ -/* 1k pages not implemented */ - env->CP0_EntryLo0 =T0 &0x3FFFFFFF ; -RETURN (); -} - -void op_dmtc0_entrylo1 (void ) -{ -/* Large physaddr not implemented */ -/* 1k pages not implemented */ - env->CP0_EntryLo1 =T0 &0x3FFFFFFF ; -RETURN (); -} - -void op_dmtc0_context (void ) -{ - env->CP0_Context = (env->CP0_Context &0x007FFFFF ) | (T0 & ~0x007FFFFF ); -RETURN (); -} - -void op_dmtc0_epc (void ) -{ - env->CP0_EPC =T0 ; -RETURN (); -} - -void op_dmtc0_watchlo0 (void ) -{ -/* Watch exceptions for instructions, data loads, data stores -not implemented. */ - env->CP0_WatchLo =T0 & ~0x7 ; -RETURN (); -} - -void op_dmtc0_xcontext (void ) -{ - env->CP0_XContext = (env->CP0_XContext &0xffffffff ) | (T0 & ~0xffffffff ); -RETURN (); -} - -void op_dmtc0_depc (void ) -{ - env->CP0_DEPC =T0 ; -RETURN (); -} - -void op_dmtc0_errorepc (void ) -{ - env->CP0_ErrorEPC =T0 ; -RETURN (); -}#endif /* TARGET_MIPS64 */ /* CP1 functions */
Index: translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/translate.c,v retrieving revision 1.77
translate.c +57 -57
330 lines not on this page · raw message
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net