Index: qemu/target-mips/translate.c =================================================================== --- qemu.orig/target-mips/translate.c 2008-05-25 10:19:32.000000000 +0100 +++ qemu/target-mips/translate.c 2008-05-25 10:19:48.000000000 +0100 @@ -1985,21 +1985,38 @@ static void gen_muldiv (DisasContext *ct tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1); { - TCGv r_tmp1 = new_tmp(); - TCGv r_tmp2 = new_tmp(); - TCGv r_tmp3 = new_tmp(); + int l2 = gen_new_label(); - tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]); - tcg_gen_trunc_tl_i32(r_tmp2, cpu_T[1]); - tcg_gen_div_i32(r_tmp3, r_tmp1, r_tmp2); - tcg_gen_rem_i32(r_tmp1, r_tmp1, r_tmp2); - tcg_gen_ext_i32_tl(cpu_T[0], r_tmp3); - tcg_gen_ext_i32_tl(cpu_T[1], r_tmp1); - gen_store_LO(cpu_T[0], 0); - gen_store_HI(cpu_T[1], 0); - dead_tmp(r_tmp1); - dead_tmp(r_tmp2); - dead_tmp(r_tmp3); + /* The handling of non-sign-extended values is unpredictable, + but it still shouldn't trigger a SIGFPE in the emulator. */ + tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); + tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], -1 << 31, l2); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[1], -1, l2); + { + tcg_gen_movi_tl(cpu_T[1], 0); + gen_store_LO(cpu_T[0], 0); + gen_store_HI(cpu_T[1], 0); + tcg_gen_br(l1); + } + gen_set_label(l2); + { + TCGv r_tmp1 = new_tmp(); + TCGv r_tmp2 = new_tmp(); + TCGv r_tmp3 = new_tmp(); + + tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]); + tcg_gen_trunc_tl_i32(r_tmp2, cpu_T[1]); + tcg_gen_div_i32(r_tmp3, r_tmp1, r_tmp2); + tcg_gen_rem_i32(r_tmp1, r_tmp1, r_tmp2); + tcg_gen_ext_i32_tl(cpu_T[0], r_tmp3); + tcg_gen_ext_i32_tl(cpu_T[1], r_tmp1); + gen_store_LO(cpu_T[0], 0); + gen_store_HI(cpu_T[1], 0); + dead_tmp(r_tmp1); + dead_tmp(r_tmp2); + dead_tmp(r_tmp3); + } } gen_set_label(l1); }