MIPS64 problem with ethernet
The ethernet device does not come up correctly on a 64 MIPS target with a 64 bit kernel.
I narrowed it down a bit, so I thought I might mention it.
If I add to the kernel the line:
printk("\nTest ~0UL == %lx\n", (~0UL));
It will print correctly on the real HW:
Test ~0UL == ffffffffffffffff
In qemu-system-mips64 it will only print:
Test ~0UL ==
The ethernet fails due to the failure of the computing of the test kcalloc() found in slab.h. if (n != 0 && size > ULONG_MAX / n)
Where n == 16, size == 8, and ULONG_MAX == (~0UL). I suspect some low level debugging of which op code translation is at fault would be next...
Jason.
Quoted 2 lines · Jason Wessel
The ethernet device does not come up correctly on a 64 MIPS target with a 64 bit kernel.
Which Ethernet card are you using? The pcnet one is working correctly here. I am using a 2.6.21.1 kernel.
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Quoted 9 lines · Aurelien Jarno
Quoted 2 lines · Jason Wessel
The ethernet device does not come up correctly on a 64 MIPS target with a 64 bit kernel.
Which Ethernet card are you using? The pcnet one is working correctly here. I am using a 2.6.21.1 kernel.
It works perfectly fine if I boot a 32bit kernel on the 64bit mips qemu with the pcnet32. It is when I boot the 64bit kernel on the 64bit mips qemu that I see the issue. The only difference I can see is the math operations in the kcalloc() inline because the sizes are different in 32 vs 64 of course. I too was using a 2.6.21.1 kernel with mips.org patches. Likely that I am using a different compiler though. Keeping in mind that the same kernel 32bit and 64bit kernels works fine on real hardware.
Jason.
Quoted 11 lines · Jason Wessel
Quoted 10 lines · Aurelien Jarno
Quoted 3 lines · Jason Wessel
The ethernet device does not come up correctly on a 64 MIPS target with a 64 bit kernel.
Which Ethernet card are you using? The pcnet one is working correctly here. I am using a 2.6.21.1 kernel.
Quoted 9 lines
It works perfectly fine if I boot a 32bit kernel on the 64bit mips qemu with the pcnet32. It is when I boot the 64bit kernel on the 64bit mips qemu that I see the issue. The only difference I can see is the math operations in the
kcalloc()inline because the sizes are different in 32 vs 64 of course. I too was using a 2.6.21.1 kernel with mips.org patches. Likely that I am using a different compiler though. Keeping in mind that the same kernel 32bit and 64bit kernels works fine on real hardware.
As discussed on IRC, the problem is only present on 32-bit hosts. It is due to the do_ddivu which is falsely implemented using lldiv and then by casting the result. The patch below uses / and % as on the 64-bit host code. It is maybe slower than lldiv, but at least it gives the correct result. This probably involves some libgcc code, so it is better to keep it in op_helper.c for 32-bit hosts.
Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.49
op_helper.c +2 -4
@@ -240,10 +240,8 @@ void do_ddiv (void)void do_ddivu (void ) {if (T1 !=0 ) { -/* XXX: lldivu? */ -lldiv_t res =lldiv (T0 ,T1 ); - env->LO = (uint64_t )res.quot; - env->HI = (uint64_t )res.rem; + env->LO =T0 /T1 ; + env->HI =T0 %T1 ; } }#endif
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
As discussed on IRC, the problem is only present on 32-bit hosts. It is due to the
do_ddivuwhich is falsely implemented using lldiv and then by casting the result. The patch below uses / and % as on the 64-bit host code. It is maybe slower than lldiv, but at least it gives the correct result. This probably involves some libgcc code, so it is better to keep it inop_helper.cfor 32-bit hosts.
With your change the ethernet does come up but it seems there is a further problem, perhaps with ddivu. My host is a 32bit host, and this does seem to work on a 64bit host or the real hardware. Doing something like an ls /proc does not work in the emulated target. The reason is that the compatibility syscalls are 32bit and there is some sign extension problem somewhere.
I put the following code in kernel/main/init.c as an illustration of the problem.
{
unsigned long v1 = 0xffffffff80731111;
unsigned int v2 = v1 + 1;
printk("v1 %lx v2 %08x\n", v1, v2);}
On the real hw it prints correctly as:
v1 ffffffff80731111 v2 80731112
On the emulated 64 bit + 64bit kernel on a 32 bit host it prints as:
v1 ffffffff80731111 v2 ffffffff80731112
This might be due to the ddivu in printk, but it could be elsewhere...
Jason.
Quoted 25 lines · Jason Wessel
Quoted 8 lines · Aurelien Jarno
As discussed on IRC, the problem is only present on 32-bit hosts. It is due to the
do_ddivuwhich is falsely implemented using lldiv and then by casting the result. The patch below uses / and % as on the 64-bit host code. It is maybe slower than lldiv, but at least it gives the correct result. This probably involves some libgcc code, so it is better to keep it inop_helper.cfor 32-bit hosts.With your change the ethernet does come up but it seems there is a further problem, perhaps with ddivu. My host is a 32bit host, and this does seem to work on a 64bit host or the real hardware. Doing something
like an ls /proc does not work in the emulated target. The reason is
that the compatibility syscalls are 32bit and there is some sign extension problem somewhere.I put the following code in
kernel/main/init.cas an illustration of the problem.{ unsigned long v1 = 0xffffffff80731111; unsigned int v2 = v1 + 1; printk("v1 %lx v2 %08x\n", v1, v2);}
Quoted 8 lines
On the real hw it prints correctly as:
v1ffffffff80731111v2 80731112On the emulated 64 bit + 64bit kernel on a 32 bit host it prints as:
v1ffffffff80731111v2ffffffff80731112This might be due to the ddivu in printk, but it could be elsewhere...
The problem is actually not specific to 32-bit hosts. It is a bug in the lwu instruction, which should not sign extend the loaded byte.
Please find below a patch to fix that.
Index: target-mips/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_mem.c,v retrieving revision 1.10
op_mem.c +1 -1
@@ -63,7 +63,7 @@ void glue(op_lw, MEMSUFFIX) (void)void glue (op_lwu ,MEMSUFFIX ) (void ) { -T0 =glue (ldl,MEMSUFFIX )(T0 ); +T0 = (uint32_t )glue (ldl,MEMSUFFIX )(T0 );RETURN (); }
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net