@@ -193,12 +193,19 @@ void HELPER(divu)(CPUM68KState *env, uint32_t word)
quot = num / den;
rem = num % den;
flags = 0;
- if (word && quot > 0xffff)
- flags |= CCF_V;
- if (quot == 0)
- flags |= CCF_Z;
- else if ((int32_t)quot < 0)
- flags |= CCF_N;
+ if (word && quot > 0xffff) {
+ /* real 68040 keep Z and N on overflow,
+ * whereas documentation says "undefined"
+ */
+ flags |= CCF_V | (env->cc_dest & (CCF_Z|CCF_N));
+ } else {
+ if (quot == 0) {
+ flags |= CCF_Z;
+ } else if ((int16_t)quot < 0) {
+ flags |= CCF_N;
+ }
+ }
+
env->div1 = quot;
env->div2 = rem;
env->cc_dest = flags;
@@ -220,12 +227,19 @@ void HELPER(divs)(CPUM68KState *env, uint32_t word)
quot = num / den;
rem = num % den;
flags = 0;
- if (word && quot != (int16_t)quot)
- flags |= CCF_V;
- if (quot == 0)
- flags |= CCF_Z;
- else if (quot < 0)
- flags |= CCF_N;
+ if (word && quot != (int16_t)quot) {
+ /* real 68040 keep Z and N on overflow,
+ * whereas documentation says "undefined"
+ */
+ flags |= CCF_V | (env->cc_dest & (CCF_Z|CCF_N));
+ } else {
+ if (quot == 0) {
+ flags |= CCF_Z;
+ } else if ((int16_t)quot < 0) {
+ flags |= CCF_N;
+ }
+ }
+
env->div1 = quot;
env->div2 = rem;
env->cc_dest = flags;
This allows to compare simulation results with a real 68040. Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- target-m68k/op_helper.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)