Skip to contentSkip to conversation

qemu regression 0.7.2 -> 0.8.0 (ARM user emulation)

Qemu-devel Anderson Lizardo 3 participants 4 messages Mar 2, 2006 – Mar 11, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

I was having some issues with the latest qemu (ARM user emulation), which I tracked down to the following reduced test case:

#include <stdio.h>
int main(void)

{
        float a, b;
        a = 0.1f;
        b = 0.8f;
        printf("a < b: %d\n", (a < b));
        return 0;
}

Compile it with an ARM cross-compiler and run it with "qemu-arm". It should print

a < b: 1

for qemu 0.7.2 and

a < b: 0

for 0.8.0. Obviously, the first one is right.

Tested with the following setup:
qemu 0.7.2/0.8.0
arm-linux-gnu-gcc (GCC) 3.4.5
glibc 2.3.5

--
Anderson Lizardo
Embedded Linux Lab - 10LE
Nokia Institute of Technology - INdT
Manaus - Brazil

#1 lore raw

Hi!

Quoted 5 lines · Anderson Lizardo

I was having some issues with the latest qemu (ARM user emulation), which I tracked down to the following reduced test case:

#include <stdio.h>
int main(void)

Quoted 7 lines
{
        float a, b;
        a = 0.1f;
        b = 0.8f;
        printf("a < b: %d\n", (a < b));
        return 0;
}

This fails because of a bug in the glue code between NWFPE and QEMU. (It relies on a specific layout of the CPUARMState structure.)

Fix attached.

CU
Uli

linux-user/main.c +1 -1
diff -ru qemu-0.8.0/linux-user/main.c qemu-0.8.0.fixed/linux-user/main.c
@@ -345,7 +345,7 @@
                 /* we get the opcode */
                 opcode = ldl_raw((uint8_t *)env->regs[15]);
                 
-                if (EmulateAll(opcode, &ts->fpa, env->regs) == 0) {
+                if (EmulateAll(opcode, &ts->fpa, env) == 0) {
                     info.si_signo = SIGILL;
                     info.si_errno = 0;
                     info.si_code = TARGET_ILL_ILLOPN;
target-arm/nwfpe/fpa11.c +2 -2
diff -ru qemu-0.8.0/target-arm/nwfpe/fpa11.c qemu-0.8.0.fixed/target-arm/nwfpe/fpa11.c
@@ -36,7 +36,7 @@
 unsigned int EmulateCPRT(const unsigned int);
 
 FPA11* qemufpa=0;
-unsigned int* user_registers=0;
+CPUARMState* user_registers=0;
 
 /* Reset the FPA11 chip.  Called to initialize and reset the emulator. */
 void resetFPA11(void)
@@ -137,7 +137,7 @@
 }
 
 /* Emulate the instruction in the opcode. */
-unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, unsigned int* qregs)
+unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs)
 {
   unsigned int nRc = 0;
 //  unsigned long flags;
target-arm/nwfpe/fpa11.h +7 -22
diff -ru qemu-0.8.0/target-arm/nwfpe/fpa11.h qemu-0.8.0.fixed/target-arm/nwfpe/fpa11.h
@@ -26,6 +26,8 @@
 #include <stdio.h>
 #include <errno.h>
 
+#include <cpu.h>
+
 #define GET_FPA11() (qemufpa)
 
 /*
@@ -33,7 +35,7 @@
  * stack+task struct.  Use the same method as 'current' uses to
  * reach them.
  */
-extern unsigned int *user_registers;
+extern CPUARMState *user_registers;
 
 #define GET_USERREG() (user_registers)
 
@@ -94,7 +96,7 @@
 
 static inline unsigned int readRegister(unsigned int reg)
 {
-    return (user_registers[(reg)]);
+    return (user_registers->regs[(reg)]);
 }
 
 static inline void writeRegister(unsigned int x, unsigned int y)
@@ -102,34 +104,17 @@
 #if 0
 	printf("writing %d to r%d\n",y,x);
 #endif
-        user_registers[(x)]=(y);
+        user_registers->regs[(x)]=(y);
 }
 
 static inline void writeConditionCodes(unsigned int x)
 {
-#if 0
-unsigned	int y;
-unsigned    int ZF;
-	printf("setting flags to %x from %x\n",x,user_registers[16]);
-#endif
-	user_registers[16]=(x);	// cpsr
-	user_registers[17]=(x>>29)&1;	// cf
-	user_registers[18]=(x<<3)&(1<<31);	// vf
-	user_registers[19]=x&(1<<31);	// nzf
-	if(!(x&(1<<30))) user_registers[19]++;	// nzf must be non-zero for zf to be cleared
-
-#if 0
-        ZF = (user_registers[19] == 0);
-        y=user_registers[16] | (user_registers[19] & 0x80000000) | (ZF << 30) | 
-                    (user_registers[17] << 29) | ((user_registers[18] & 0x80000000) >> 3);
-        if(y != x)
-        	printf("GODDAM SHIIIIIIIIIIIIIIIIT! %x %x nzf %x zf %x\n",x,y,user_registers[19],ZF);
-#endif                    
+        cpsr_write(user_registers,x,~CPSR_M);
 }
 
 #define REG_PC 15
 
-unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, unsigned int* qregs);
+unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs);
 
 /* included only for get_user/put_user macros */
 #include "qemu.h"
#2 lore raw
Quoted 14 lines · Ulrich Hecht
Quoted 5 lines · Anderson Lizardo

I was having some issues with the latest qemu (ARM user emulation), which I tracked down to the following reduced test case:

#include <stdio.h>
int main(void)

Quoted 7 lines
{
        float a, b;
        a = 0.1f;
        b = 0.8f;
        printf("a < b: %d\n", (a < b));
        return 0;
}
Quoted 4 lines

This fails because of a bug in the glue code between NWFPE and QEMU. (It relies on a specific layout of the CPUARMState structure.)

Fix attached.

This patch seems to fix the specific problem I was having. Just waiting to see it on CVS...

Thanks!
--
Anderson Lizardo
Embedded Linux Lab - 10LE
Nokia Institute of Technology - INdT
Manaus - Brazil

#3 lore raw
In reply to Ulrich Hecht
Quoted 16 lines · Ulrich Hecht

Hi!

Quoted 5 lines · Anderson Lizardo

I was having some issues with the latest qemu (ARM user emulation), which I tracked down to the following reduced test case:

#include <stdio.h>
int main(void)

Quoted 7 lines
{
        float a, b;
        a = 0.1f;
        b = 0.8f;
        printf("a < b: %d\n", (a < b));
        return 0;
}
Quoted 4 lines

This fails because of a bug in the glue code between NWFPE and QEMU. (It relies on a specific layout of the CPUARMState structure.)
...
+ cpsr_write(user_registers,x,~CPSR_M);

This should be CPSR_NZCV. Applied with that change.

Paul