Skip to contentSkip to conversation

mips64-linux-user: Use MIPS64R2-generic as default cpu.

PATCH In review Aurelien Jarno 5 participants 10 messages Mar 5, 2013 – Aug 5, 2013 6 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 20 lines · Richard Henderson
---
 linux-user/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

I don't actually recall why this patch was in my old tree. It might just have been that I wanted a mips64r2 part for testing and didn't want to keep specifying -cpu on the command-line. OTOH, I don't see any reason not to emulate as many ISA extensions as possible by default.

r~

linux-user/main.c +0 -0
index 3a3be70..8c4dffd 100644

linux-user/main.c int main(int argc, char **argv, char **envp) · line 3533

Quoted 10 lines
linux-user/main.c +3 -1
@@ -3525,7 +3525,9 @@ int main(int argc, char **argv, char **envp)
         cpu_model = "Fujitsu MB86904";
 #endif
 #elif defined(TARGET_MIPS)
-#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
+#if defined(TARGET_ABI_MIPSN64)
+        cpu_model = "MIPS64R2-generic";
+#elif defined(TARGET_ABI_MIPSN32)
         cpu_model = "20Kc";
 #else
         cpu_model = "24Kf";

Why switching only N64 and not also for N32? The same way we should also switch the O32 one to 74Kf which also has DSP R2 and MIPS16.

That looks fine only as a first step, otherwise the idea of having an "any" CPU, as suggested by Peter, looks like a good idea. That said some instruction set conflicts so we can't enable all of them in such a CPU. The name "any" can be a bit misleading in that case. Is it also the case on other architectures?

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [Qemu-devel] [PATCH 08/10] target-mips: Fix check_cp1_64bitmode

Quoted 13 lines · Richard Henderson

COP1X refers to the availability of indexed memory operations, not whether the FPU has 64-bit registers.

---
 target-mips/translate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target-mips/translate.c +0 -0
index b3b8dc6..a39e118 100644

target-mips/translate.c static inline void check_cop1x(DisasContext *ctx) · line 1373

Quoted 9 lines
target-mips/translate.c +2 -1
@@ -1366,8 +1366,9 @@ static inline void check_cop1x(DisasContext *ctx)
 
 static inline void check_cp1_64bitmode(DisasContext *ctx)
 {
-    if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
+    if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64))) {
         generate_exception(ctx, EXCP_RI);
+    }
 }
 

I think this is wrong. This check comes from the following patch:

http://lists.gnu.org/archive/html/qemu-devel/2007-12/msg00581.html

In short check_cp1_64bitmode() is called for COP1X instructions (nabla ones) which need the FPU in 64-bit mode. COP1X instructions might not always been able and might have to be activated (CU3 on MIPS IV, 64-bit operations enabled on MIPS64R1), so checking the ISA is not enough.

Maybe the name is misleading, but IMHO the behavior is correct.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [Qemu-devel] [PATCH 09/10] mipsn32-linux-user: Restrict address space to 31-bits.

Quoted 22 lines · Richard Henderson
---
 linux-user/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
linux-user/main.c +1 -1
index 8c4dffd..25491ca 100644
@@ -46,10 +46,10 @@ int gdbstub_port;
 envlist_t *envlist;
 const char *cpu_model;
 unsigned long mmap_min_addr;
+
 #if defined(CONFIG_USE_GUEST_BASE)
 unsigned long guest_base;
 int have_guest_base;
-#if (TARGET_LONG_BITS == 32) && (HOST_LONG_BITS == 64)
 /*
  * When running 32-on-64 we should make sure we can fit all of the possible
  * guest address space into a contiguous chunk of virtual host memory.

linux-user/main.c int have_guest_base; · line 63

Quoted 10 lines
linux-user/main.c +3 -3
@@ -57,16 +57,16 @@ int have_guest_base;
  * This way we will never overlap with our own libraries or binaries or stack
  * or anything else that QEMU maps.
  */
-# ifdef TARGET_MIPS
+# if HOST_LONG_BITS == 64 \
+     && (defined(TARGET_ABI_MIPSO32) || defined(TARGET_ABI_MIPSN32))
 /* MIPS only supports 31 bits of virtual address space for user space */
-unsigned long reserved_va = 0x77000000;
-# else
+unsigned long reserved_va = 0x7f000000;

Is it really wanted to change 0x77 into 0x7f? If yes, I think the commit log should explain why.

Quoted 15 lines
linux-user/main.c +2 -2
+# elif (TARGET_LONG_BITS == 32) && (HOST_LONG_BITS == 64)
 unsigned long reserved_va = 0xf7000000;
-# endif
 #else
 unsigned long reserved_va;
 #endif
-#endif
+#endif /* CONFIG_USE_GUEST_BASE */
 
 static void usage(void);
 
Signature · 1 line
1.8.1.2
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#7 lore raw

Re: [Qemu-devel] [PATCH 09/10] mipsn32-linux-user: Restrict address space to 31-bits.

Quoted 28 lines · Aurelien Jarno
Quoted 27 lines · Richard Henderson
---
 linux-user/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
linux-user/main.c +2 -2
index 8c4dffd..25491ca 100644
@@ -46,10 +46,10 @@ int gdbstub_port;
 envlist_t *envlist;
 const char *cpu_model;
 unsigned long mmap_min_addr;
+
 #if defined(CONFIG_USE_GUEST_BASE)
 unsigned long guest_base;
 int have_guest_base;
-#if (TARGET_LONG_BITS == 32) && (HOST_LONG_BITS == 64)
 /*
  * When running 32-on-64 we should make sure we can fit all of the possible
  * guest address space into a contiguous chunk of virtual host memory.
@@ -57,16 +57,16 @@ int have_guest_base;
  * This way we will never overlap with our own libraries or binaries or stack
  * or anything else that QEMU maps.
  */
-# ifdef TARGET_MIPS
+# if HOST_LONG_BITS == 64 \
Quoted 9 lines

linux-user/main.c int have_guest_base; · line 63

Quoted 5 lines
linux-user/main.c +2 -2
+     && (defined(TARGET_ABI_MIPSO32) || defined(TARGET_ABI_MIPSN32))
 /* MIPS only supports 31 bits of virtual address space for user space */
-unsigned long reserved_va = 0x77000000;
-# else
+unsigned long reserved_va = 0x7f000000;

Is it really wanted to change 0x77 into 0x7f? If yes, I think the commit log should explain why.

Ping?

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#8 lore raw

Re: [Qemu-devel] [PATCH 09/10] mipsn32-linux-user: Restrict address space to 31-bits.

Quoted 11 lines · Aurelien Jarno
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +3 -3
-# ifdef TARGET_MIPS
+# if HOST_LONG_BITS == 64 \
+     && (defined(TARGET_ABI_MIPSO32) || defined(TARGET_ABI_MIPSN32))
 /* MIPS only supports 31 bits of virtual address space for user space */
-unsigned long reserved_va = 0x77000000;
-# else
+unsigned long reserved_va = 0x7f000000;

Is it really wanted to change 0x77 into 0x7f? If yes, I think the commit log should explain why.

Quoted 1 line

Ping?

As far as I could remember, that 0x77 was totally arbitrary too, and so I thought I'd "fix" it. I don't recall more, sorry.

r~

#9 lore raw

Re: [Qemu-devel] [PATCH 00/10] Support mips64/mipsn32-linux-user

In reply to a message not in the archive

Hi,

Quoted 10 lines · Richard Henderson

Peter's recent userland syscall testing has encouraged me to clean up and re-submit some ages-old patches to enable userland testing of the other mips abis.

Please review.

r~

Quoted 12 lines

Richard Henderson (10):
mips-linux-user: Delete n32 and n64 signal stubs
mips-linux-user: Share o32 code for n32 and n64 signals
mips-linux-user: Enable mips64 and mipsn32 linux-user targets
mips-linux-user: Save and restore fpu and dsp from sigcontext
mips-linux-user: Fix n32 and n64 syscalls
mips64-linux-user: Enable 64-bit address mode and fpu
mips64-linux-user: Use MIPS64R2-generic as default cpu.
target-mips: Fix check_cp1_64bitmode
mipsn32-linux-user: Restrict address space to 31-bits.
mipsn32-linux-user: Configure the architecture properly

I have applied patches 1, 2, 3, 4, 5, 6 and 10. I have taken the freedom the fix the typo in patch 4 and also the tabs in patch 10 found by Peter.

For patch 4, the remarks from Peter are valid, but they concerns already existing code. It might be nice to follow-up with the corresponding fixes.

For patches 7 to 9, please see my comments to the individual patch and follow up if needed with a new patch series. I'll try to work on a "any" cpu in the next days.

Thanks for the patches and to Peter for the review.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

PATCH 1/1 target-mips: 64-bit FPU for user-mode emulation.

Switch to 64-bit FPU only for n32 and n64 ABIs, but not o32. Fixup for commit 68473f15d4c9948986618f63828825beafcaf1cf.

---

Hi!

Quoted 21 lines · Richard Henderson
target-mips/translate.c +8 -0
index 3b77b53..b3b8dc6 100644
@@ -15972,6 +15972,14 @@ void cpu_state_reset(CPUMIPSState *env)
 
 #if defined(CONFIG_USER_ONLY)
     env->CP0_Status = (MIPS_HFLAG_UM << CP0St_KSU);
+# ifdef TARGET_MIPS64
+    /* Enable 64-bit register mode.  */
+    env->CP0_Status |= (1 << CP0St_PX);
+# endif
+# ifdef TARGET_ABI_MIPSN64
+    /* Enable 64-bit address mode.  */
+    env->CP0_Status |= (1 << CP0St_UX);
+# endif
     /* Enable access to the CPUNum, SYNCI_Step, CC, and CCRes RDHWR
        hardware registers.  */
     env->CP0_HWREna |= 0x0000000F;
@@ -15981,6 +15989,11 @@ void cpu_state_reset(CPUMIPSState *env)
     if (env->CP0_Config3 & (1 << CP0C3_DSPP)) {

target-mips/translate.c void cpu_state_reset(CPUMIPSState *env) · line 15999

Quoted 10 lines
target-mips/translate.c +5 -0
         env->CP0_Status |= (1 << CP0St_MX);
     }
+    /* Enable 64-bit FPU if the target cpu supports it.  */
+    env->active_fpu.fcr0 = env->cpu_model->CP1_fcr0;
+    if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
+        env->CP0_Status |= (1 << CP0St_FR);
+    }
 #else
     if (env->hflags & MIPS_HFLAG_BMASK) {
         /* If the exception was raised from a delay slot,

In my reading of the relevant documents, the latter change is not correct for o32, and empirically has "interesting" effects on the glibc math testsuite, for example. Keeping the FR register unset for o32 I'm proposing to fix with the following patch:

---
 target-mips/translate.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
translate.c +3 -1
index 0a53203..51837d4 100644
@@ -15962,10 +15962,12 @@ void cpu_state_reset(CPUMIPSState *env)
     if (env->CP0_Config3 & (1 << CP0C3_DSPP)) {
         env->CP0_Status |= (1 << CP0St_MX);
     }
-    /* Enable 64-bit FPU if the target cpu supports it.  */
+# if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
+    /* Enable 64-bit FPU if the target CPU supports it.  */
     if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
         env->CP0_Status |= (1 << CP0St_FR);
     }
+# endif
 #else
     if (env->hflags & MIPS_HFLAG_BMASK) {
         /* If the exception was raised from a delay slot,

Grüße,
Thomas

#12 lore raw

Re: [Qemu-devel] [PATCH] target-mips: 64-bit FPU for user-mode emulation.

Quoted 4 lines · Thomas Schwinge

In my reading of the relevant documents, the latter change is not correct for o32, and empirically has "interesting" effects on the glibc math testsuite, for example. Keeping the FR register unset for o32 I'm proposing to fix with the following patch:

Correct, unless (until?) the -mfp64 o32 ABI extension is implemented for
Linux, CP0.Status.FR must remain 0 for o32 programs.

translate.c void cpu_state_reset(CPUMIPSState *env) · line 15968

Quoted 13 lines
translate.c +2 -1
index 0a53203..51837d4 100644
@@ -15962,10 +15962,12 @@ void cpu_state_reset(CPUMIPSState *env)
     if (env->CP0_Config3 & (1 << CP0C3_DSPP)) {
         env->CP0_Status |= (1 << CP0St_MX);
     }
-    /* Enable 64-bit FPU if the target cpu supports it.  */
+# if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
+    /* Enable 64-bit FPU if the target CPU supports it.  */
     if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
         env->CP0_Status |= (1 << CP0St_FR);

This is not entirely correct, older 64-bit FPUs, i.e. any before the
MIPS32/MIPS64 rev. 2 ISA (e.g. R4000, R10000, 5Kf, etc.) won't have the CP1.FIR.F64 bit set; it was only defined at that ISA level because for earlier architecture revisions the type of the FPU could have been inferred from the type of the CPU. Therefore the condition has to be changed, perhaps the best way would simply be just checking in the CP0.Status mask if the FR bit is writable.

Also I suppose there must be an else clause here:

    } else {
        fprintf(stderr, "A 64-bit FPU required for NewABI emulation\n");
        exit(1);

or suchlike because the NewABI mandates full 64-bit FPU operation (or the condtion might be changed to an assertion instead and the emulated environment checked elsewhere earlier on, because a 64-bit CPU is required for NewABI operation anyway and a 64-bit CPU can't ever have a 32-bit FPU -- I don't know QEMU well enough to be sure offhand, please check).

translate.c void cpu_state_reset(CPUMIPSState *env) · line 15973

Quoted 5 lines
translate.c +1 -0
     }
+# endif
 #else
     if (env->hflags & MIPS_HFLAG_BMASK) {
         /* If the exception was raised from a delay slot,

Maciej

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: [Qemu-devel] [PATCH] target-mips: 64-bit FPU for user-mode emulation.

Will there be an update to this patch?
It would be nice to see this in for 1.6.

As of fp64 mode for o32/Rev2, it does not have to be resolved now.

Regards,
Petar

Quoted 4 lines · Thomas Schwinge

In my reading of the relevant documents, the latter change is not correct for o32, and empirically has "interesting" effects on the glibc math testsuite, for example. Keeping the FR register unset for o32 I'm proposing to fix with the following patch:

Correct, unless (until?) the -mfp64 o32 ABI extension is implemented for
Linux, CP0.Status.FR must remain 0 for o32 programs.

translate.c void cpu_state_reset(CPUMIPSState *env) · line 15968

Quoted 13 lines
translate.c +2 -1
index 0a53203..51837d4 100644
@@ -15962,10 +15962,12 @@ void cpu_state_reset(CPUMIPSState *env)
     if (env->CP0_Config3 & (1 << CP0C3_DSPP)) {
         env->CP0_Status |= (1 << CP0St_MX);
     }
-    /* Enable 64-bit FPU if the target cpu supports it.  */
+# if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
+    /* Enable 64-bit FPU if the target CPU supports it.  */
     if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
         env->CP0_Status |= (1 << CP0St_FR);

This is not entirely correct, older 64-bit FPUs, i.e. any before the
MIPS32/MIPS64 rev. 2 ISA (e.g. R4000, R10000, 5Kf, etc.) won't have the CP1.FIR.F64 bit set; it was only defined at that ISA level because for earlier architecture revisions the type of the FPU could have been inferred from the type of the CPU. Therefore the condition has to be changed, perhaps the best way would simply be just checking in the CP0.Status mask if the FR bit is writable.

Also I suppose there must be an else clause here:

    } else {
        fprintf(stderr, "A 64-bit FPU required for NewABI emulation\n");
        exit(1);

or suchlike because the NewABI mandates full 64-bit FPU operation (or the condtion might be changed to an assertion instead and the emulated environment checked elsewhere earlier on, because a 64-bit CPU is required for NewABI operation anyway and a 64-bit CPU can't ever have a 32-bit FPU -- I don't know QEMU well enough to be sure offhand, please check).

translate.c void cpu_state_reset(CPUMIPSState *env) · line 15973

Quoted 5 lines
translate.c +1 -0
     }
+# endif
 #else
     if (env->hflags & MIPS_HFLAG_BMASK) {
         /* If the exception was raised from a delay slot,

Maciej

#15 lore raw

Re: [Qemu-devel] [PATCH] target-mips: 64-bit FPU for user-mode emulation.

Hi!

Quoted 1 line · Petar Jovanovic

Will there be an update to this patch?

| Switch to 64-bit FPU only for n32 and n64 ABIs, but not o32.  Fixup for
| commit 68473f15d4c9948986618f63828825beafcaf1cf.
| [...]

My patch has to be reworked per Maciej's comments,
<http://news.gmane.org/find-root.php?message_id=%3Calpine.DEB.1.10.1306091926470.16287%40tp.orcam.me.uk%3E>,
which I have not yet managed to allocate the time to do, and can't tell when it's going to happen -- but I still have it on my TODO list.

Grüße,
Thomas