Skip to contentSkip to conversation

overflow and register size mismatch in sh4-softmmu

Qemu-devel Carlo Marcelo Arenas Belon 2 participants 2 messages Nov 11, 2007

lore
Share & tools
lore
#0 lore raw

as shown by the following warning when compiling HEAD :

qemu/target-sh4/translate.c: In function `cpu_sh4_reset':
qemu/target-sh4/translate.c:139: warning: overflow in implicit constant conversion

the problem was introduced in version 1.11 of that file and is being triggered by the fact that the following assignment :

  env->fp_status.float_rounding_mode = float_round_to_zero;

is trying to assign the value of float_round_to_zero which is defined in softfloat-native.h as :

  enum {
    float_round_nearest_even = FE_TONEAREST,
    float_round_down = FE_DOWNWARD,
    float_round_up = FE_UPWARD,
    float_round_to_zero = FE_TOWARDZERO
  };

where FE_TOWARDZERO = 0xc00 and sizeof(env->fp_status.float_rounding_mode) == 1 as shown by :

  typedef struct float_status {
    signed char float_rounding_mode;
    signed char floatx80_rounding_precision;
  } float_status;

float_status fp_status;

the following patch changes the logic to use a helper function just like other targets and has been tested in x86 and amd64 to compile correctly, but I have no way to test it and should be ideally validated by anyone that knows the sh4 emulation better and has a way to confirm that it is functionally equivalent.

Carlo

---
Index: target-sh4/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/translate.c,v retrieving revision 1.19

translate.c +1 -1
diff -u -r1.19 translate.c
@@ -136,7 +136,7 @@
     env->fp_status.float_rounding_mode = float_round_nearest_even; /* ?! */
 #else
     env->fpscr = 0x00040001; /* CPU reset value according to SH4 manual */
-    env->fp_status.float_rounding_mode = float_round_to_zero;
+    set_float_rounding_mode(float_round_to_zero, &env->fp_status);
 #endif
     env->mmucr = 0;
 }
#1 lore raw

translate.c line 139

Quoted 9 lines · Carlo Marcelo Arenas Belon

as shown by the following warning when compiling HEAD :

qemu/target-sh4/translate.c: In function `cpu_sh4_reset':
qemu/target-sh4/translate.c:139: warning: overflow in implicit constant
conversion
...
the following patch changes the logic to use a helper function

translate.c +1 -1
-    env->fp_status.float_rounding_mode = float_round_to_zero;
+    set_float_rounding_mode(float_round_to_zero, &env->fp_status);

This is just hiding the bug.

Paul