head 1.1; access; symbols; locks; strict; comment @ * @; 1.1 date 2026.11.20.16.43.05; author thorpej; state Exp; branches; next ; commitid yjCUxPi7WlXWEd4H; desc @@ 1.1 log @Two emulation patches: - hw/mc146818rtc.c -- replace previous patch with the one that fixes the same issue but is more correct by Philippe Mathieu-Daudé (also being upstreamed). - m68k/op_helper.c -- In the DIVS.L helper, special case INT_MIN / -1, which traps on some hosts and crashes Qemu (Qemu issue #2078). Bump PKGREVISION to 4. @ text @$NetBSD$ Patch for Qemu issue #2078. * Avoid integer division underflow that can cause arithmetic exception on the host system and crash Qemu. --- target/m68k/op_helper.c.orig 2026-10-28 19:57:39.000000000 +0000 +++ target/m68k/op_helper.c 2026-11-20 16:33:08.490830343 +0000 @@@@ -679,12 +679,22 @@@@ void HELPER(divsl)(CPUM68KState *env, in if (den == 0) { raise_exception_format2(env, EXCP_DIV0, ilen, GETPC()); } - quot = num / den; - rem = num % den; + if (unlikely(num == INT32_MIN) && den == -1) { + env->cc_v = -1; + /* + * real 68040 keeps N and unset Z on overflow, + * whereas documentation says "undefined" + */ + env->cc_z = 1; + return; + } else { + quot = num / den; + rem = num % den; - env->cc_z = quot; - env->cc_n = quot; - env->cc_v = 0; + env->cc_z = quot; + env->cc_n = quot; + env->cc_v = 0; + } if (m68k_feature(env, M68K_FEATURE_CF_ISA_A)) { if (numr == regr) { @