Skip to contentSkip to conversation

mipsIV support for mips-linux-user

Qemu-devel Vince Weaver 2 participants 7 messages Mar 29, 2009 – Apr 9, 2009

lore
Share & tools
lore
#0 lore raw

Hello

I have some 32-bit mips binaries compiled with -mips4 -O3.

These run fine on an actual mips r12k system I have, but fail with default mips-linux-user (0.10.1).

This is because by default mips-linux-user does not have support enabled for mipsIV instructions. This is because MIPS_HFLAG_COP1X is not enabled on any of the cpus supported by mips-linux-user.

So my question, what is the correct way to fix this? Add a R4000 class
CPU that can be seen with mips-linux-user? Or should the default for user operation just enable this because it supports more binaries?

Vince

#1 lore raw
Quoted 7 lines · Vince Weaver

Hello

I have some 32-bit mips binaries compiled with -mips4 -O3.

These run fine on an actual mips r12k system I have, but fail with default mips-linux-user (0.10.1).

Quoted 7 lines

This is because by default mips-linux-user does not have support enabled for mipsIV instructions. This is because MIPS_HFLAG_COP1X is not enabled on any of the cpus supported by mips-linux-user.

So my question, what is the correct way to fix this? Add a R4000 class CPU that can be seen with mips-linux-user? Or should the default for user operation just enable this because it supports more binaries?

Did you try with a MIPS32R2 CPU? It should have COP1X instructions.

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

Hello

I have some 32-bit mips binaries compiled with -mips4 -O3.

These run fine on an actual mips r12k system I have, but fail with default mips-linux-user (0.10.1).

This is because by default mips-linux-user does not have support enabled for mipsIV instructions. This is because MIPS_HFLAG_COP1X is not enabled on any of the cpus supported by mips-linux-user.

Quoted 5 lines
Quoted 3 lines

So my question, what is the correct way to fix this? Add a R4000 class CPU that can be seen with mips-linux-user? Or should the default for user operation just enable this because it supports more binaries?

Did you try with a MIPS32R2 CPU? It should have COP1X instructions.

I tried all of the variants listed with -cpu ?

no -cpu specified = fails at first cop1x insn

MIPS '4Kc'	  = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4Km'	  = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEcR1'     = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEmR1'     = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEc'       = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEm'       = segfaults invalid "cfc1    v1,$31" instruction
MIPS '24Kc'       = segfaults invalid "cfc1    v1,$31" instruction
MIPS '24Kf'       = fails at first cop1x insn
MIPS '34Kf'       = fails at first cop1x insn

If I modify the check for cop1x to always return valid, running with no -cpu runs the program successfully to completion.

This might be some mistake in the cpu feature selection logic. The code is a bit hard to follow, especially as I don't have a good document specifying which CPUs have which features, especially since the real machines I have access to for comparison are SGI R4600, R5000 and R12000 machines.

Vince

#3 lore raw
Quoted 34 lines · Vince Weaver
Quoted 12 lines · Aurelien Jarno
Quoted 11 lines · Vince Weaver

Hello

I have some 32-bit mips binaries compiled with -mips4 -O3.

These run fine on an actual mips r12k system I have, but fail with default mips-linux-user (0.10.1).

This is because by default mips-linux-user does not have support enabled for mipsIV instructions. This is because MIPS_HFLAG_COP1X is not enabled on any of the cpus supported by mips-linux-user.

Quoted 5 lines
Quoted 3 lines

So my question, what is the correct way to fix this? Add a R4000 class CPU that can be seen with mips-linux-user? Or should the default for user operation just enable this because it supports more binaries?

Did you try with a MIPS32R2 CPU? It should have COP1X instructions.

I tried all of the variants listed with -cpu ?

no -cpu specified = fails at first cop1x insn

MIPS '4Kc'	  = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4Km'	  = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEcR1'     = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEmR1'     = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEc'       = segfaults invalid "cfc1    v1,$31" instruction
MIPS '4KEm'       = segfaults invalid "cfc1    v1,$31" instruction
MIPS '24Kc'       = segfaults invalid "cfc1    v1,$31" instruction
MIPS '24Kf'       = fails at first cop1x insn
MIPS '34Kf'       = fails at first cop1x insn
Quoted 9 lines

If I modify the check for cop1x to always return valid, running with no -cpu runs the program successfully to completion.

This might be some mistake in the cpu feature selection logic. The code is a bit hard to follow, especially as I don't have a good document specifying which CPUs have which features, especially since the real machines I have access to for comparison are SGI R4600, R5000 and R12000 machines.

Do you have the end of qemu.log when running your code with -d in_asm,op?

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

Do you have the end of qemu.log when running your code with -d in_asm,op?

The first cop1x instruction happens relatively deep into the program, so the debugging dump is pretty larege. How far back do you want?

It looks like no matter what cpu option I pick, the HFLAGS is set to 0x0022 (which is only the usermode and FPU flags).

Because of this the generated assembly in the debug output unconditionally generates an illegal instruction exception the first time a cop1x instruction is executed (in my case, "msub.d")

I've been digging through the qemu mips code, and I can't seem to find where the hflags are set in the usermode case.

The only place that sets the MIPS_HFLAG_COP1X is in exec.h, "compute_hflags()" but that doesn't ever seem to be called if CONFIG_USER_ONLY

Vince

#5 lore raw
Quoted 7 lines · Vince Weaver
Quoted 1 line · Aurelien Jarno

Do you have the end of qemu.log when running your code with -d in_asm,op?

The first cop1x instruction happens relatively deep into the program, so the debugging dump is pretty larege. How far back do you want?

Quoted 6 lines

It looks like no matter what cpu option I pick, the HFLAGS is set to 0x0022 (which is only the usermode and FPU flags).

Because of this the generated assembly in the debug output unconditionally generates an illegal instruction exception the first time a cop1x instruction is executed (in my case, "msub.d")

This instruction is clearly marked as MIPS64 only in the manual.

Quoted 6 lines

I've been digging through the qemu mips code, and I can't seem to find where the hflags are set in the usermode case.

The only place that sets the MIPS_HFLAG_COP1X is in exec.h, "compute_hflags()" but that doesn't ever seem to be called if CONFIG_USER_ONLY

I think this should be enabled in cpu_reset(), where env->hflags is setup for user mode.

But I am actually concern about the results you get when enabling MIPS_HFLAG_COP1X. If your program is expecting to have the FPU in 64-bit mode you may have really strange results. Did you check them?

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

Because of this the generated assembly in the debug output unconditionally generates an illegal instruction exception the first time a cop1x instruction is executed (in my case, "msub.d")

This instruction is clearly marked as MIPS64 only in the manual.

I'm running MIPSIV compiled o32 binaries. Even though the binaries
are 32-bits, they are running on a 64-bit enabled OS. (I have actual r12k and r5k machines running Debian Linux. They have 64-bit kernels but 32-bit userspace).

mips-linux-user can run these executables fine if you hack it so that cop1x instructions are enabled.

Perhaps the proper solution is to run the binaries under mips64-linux-user, but there you run into the 64-bit qemu-linux-user can't load 32-bit ELF files problem. I'm also not sure if mips64-linux-user implements the o32 syscalls.

Quoted 2 lines

I think this should be enabled in cpu_reset(), where env->hflags is setup for user mode.

That's currently what I am doing to enable these binaries to run.

Quoted 3 lines

But I am actually concern about the results you get when enabling MIPS_HFLAG_COP1X. If your program is expecting to have the FPU in 64-bit mode you may have really strange results. Did you check them?

I'm running the Spec2k benchmarks and the results are as close as can be expected to the actual hardware.

Vince