M68k for 11.0 patches
The following changes since commit b254e486242466dad881fc2bbfa215f1b67cd30f:
Merge tag 'pull-riscv-to-apply-20260109' of https://github.com/alistair23/qemu into staging (2026-01-10 10:31:57 +1100)
are available in the Git repository at:
https://github.com/vivier/qemu-m68k.git tags/m68k-for-11.0-pull-request
for you to fetch changes up to cad529260a8503b79d76589f1427ee592e31a801:
target/m68k: Improve CHK and CHK2; implement CMP2 (2026-01-12 16:26:48 +0100)
----------------------------------------------------------------
Pull request for M68K emulation (20250113)
----------------------------------------------------------------
Laurent Vivier (2):
m68k: fix CAS2 writeback when Dc1==Dc2
m68k: link.l is only available with 68020+
William Hooper (1):
target/m68k: Improve CHK and CHK2; implement CMP2
target/m68k/cpu.h | 2 + target/m68k/helper.h | 5 +- target/m68k/cpu.c | 3 +- target/m68k/op_helper.c | 20 +++++--- target/m68k/translate.c | 33 +++++++++---- tests/tcg/m68k/trap.c | 105 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 144 insertions(+), 24 deletions(-)
Signature · 1 line
2.52.0
[PULL 2/3] m68k: link.l is only available with 68020+
Base 68000 only supports word size.
Message-ID: <[email protected]>
--- target/m68k/cpu.h | 2 ++ target/m68k/cpu.c | 3 ++- target/m68k/translate.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
target/m68k/cpu.h +2 -0
@@ -555,6 +555,8 @@ enum m68k_features {M68K_FEATURE_MOVEFROMSR_PRIV ,/* Exception frame with format+vector (from 68010) */ M68K_FEATURE_EXCEPTION_FORMAT_VEC , +/* LINK.L (680[2346]0, and CPU32) */ + M68K_FEATURE_LINKL, };static inline bool m68k_feature (CPUM68KState *env,int feature)
target/m68k/cpu.c +2 -1
@@ -235,7 +235,7 @@ static void m68010_cpu_initfn(Object *obj)/* * Adds BFCHG, BFCLR, BFEXTS, BFEXTU, BFFFO, BFINS, BFSET, BFTST, CAS, CAS2, -* CHK2, CMP2, DIVSL, DIVUL, EXTB, PACK, TRAPcc, UNPK. +* CHK2, CMP2, DIVSL, DIVUL, EXTB, LINKL, PACK, TRAPcc, UNPK. * * 68020/30 only: * CALLM, cpBcc, cpDBcc, cpGEN, cpRESTORE, cpSAVE, cpScc, cpTRAPcc
@@ -260,6 +260,7 @@ static void m68020_cpu_initfn(Object *obj)m68k_set_feature (env,M68K_FEATURE_MSP );m68k_set_feature (env,M68K_FEATURE_UNALIGNED_DATA );m68k_set_feature (env,M68K_FEATURE_TRAPCC ); +m68k_set_feature (env,M68K_FEATURE_LINKL ); }/*
target/m68k/translate.c +1 -1
@@ -5829,7 +5829,7 @@ void register_m68k_insns (CPUM68KState *env) BASE(move_to_sr, 46c0, ffc0);#endif INSN (nbcd,4800 , ffc0,M68K ); -INSN (linkl,4808 , fff8,M68K ); +INSN (linkl,4808 , fff8,LINKL );BASE (pea,4840 , ffc0);BASE (swap,4840 , fff8);INSN (bkpt,4848 , fff8,BKPT );
Signature · 1 line
2.52.0
[PULL 1/3] m68k: fix CAS2 writeback when Dc1==Dc2
In reply to Laurent VivierAccording to Programmer's Reference Manual, if Dc1 and Dc2 specify the same data register and the comparison fails, memory operand 1 is stored in the data register.
The current helpers wrote Dc1 then Dc2, leaving operand 2 in the shared register.
Swap the writeback order for cas2w/cas2l so memory operand 1 wins.
Message-ID: <[email protected]>
--- target/m68k/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/m68k/op_helper.c +2 -2
@@ -799,8 +799,8 @@ void HELPER(cas2w)(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2) env->cc_v = c2; } env->cc_op =CC_OP_CMPW ; - env->dregs[Dc1] =deposit32 (env->dregs[Dc1],0 ,16 , l1); env->dregs[Dc2] =deposit32 (env->dregs[Dc2],0 ,16 , l2); + env->dregs[Dc1] =deposit32 (env->dregs[Dc1],0 ,16 , l1); } static void do_cas2l(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2,
@@ -861,8 +861,8 @@ static void do_cas2l(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2, env->cc_v = c2; } env->cc_op =CC_OP_CMPL ; - env->dregs[Dc1] = l1; env->dregs[Dc2] = l2; + env->dregs[Dc1] = l1; }void HELPER (cas2l )(CPUM68KState *env,uint32_t regs,uint32_t a1,uint32_t a2)
Signature · 1 line
2.52.0
[PULL 3/3] target/m68k: Improve CHK and CHK2; implement CMP2
In reply to Laurent VivierFrom: William Hooper <[email protected]>
Some CHK2 (Check Register Against Bounds) instructions, such as opcode 02FA, cause spurious illegal instruction exceptions, despite being valid on Motorola MC68020 and later processors and used in existing software.
With this patch, QEMU:
- Translates CHK2 and CMP2 (Compare Register Against Bounds) instructions [1] having any valid size or effective address. CHK2 and CMP2 use the same opcodes but differ in bit 11 of the extension word. (BITREV or BYTEREV instructions for ColdFire family processors [2], which use similar opcodes, are not captured, however.)
- Implements CMP2, which "is identical to CHK2 except that it sets condition codes rather than taking an exception" [1].
- Populates the correct "logical address of the instruction following the instruction that caused the trap" [3] in the exception stack frame for CHK and CHK2 exceptions, according to the number of words in the instruction, including extension words, rather than default lengths.
An existing test for CHK2 is enabled, and tests are added for CHK, CHK2, and CMP2.
References:
[1] Motorola M68000 Family Programmer's Reference Manual (M68000PM/AD),
Rev. 1, 1992, pages 4-72 to 4-73 and 4-82 to 4-83.
[2] Freescale Semiconductor, ColdFire Family Programmer's Reference Manual
(CFPRM), Rev. 3, 2005, pages 4-19 and 4-26.[3] Motorola M68040 User's Manual (M68040UM/AD), 1993, page 8-8.
Message-ID: <[email protected]>
--- target/m68k/helper.h | 5 +- target/m68k/op_helper.c | 16 ++++-- target/m68k/translate.c | 31 ++++++++---- tests/tcg/m68k/trap.c | 105 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 137 insertions(+), 20 deletions(-)
target/m68k/helper.h +3 -2
@@ -123,8 +123,9 @@ DEF_HELPER_FLAGS_4(bfclr_mem, TCG_CALL_NO_WG, i32, env, i32, s32, i32) DEF_HELPER_FLAGS_4(bfset_mem, TCG_CALL_NO_WG, i32, env, i32, s32, i32) DEF_HELPER_FLAGS_4(bfffo_mem, TCG_CALL_NO_WG, i64, env, i32, s32, i32) -DEF_HELPER_3(chk, void, env, s32, s32) -DEF_HELPER_4(chk2, void, env, s32, s32, s32) +DEF_HELPER_4(chk, void, env, s32, s32, int) +DEF_HELPER_5(chk2, void, env, s32, s32, s32, int) +DEF_HELPER_4(cmp2, void, env, s32, s32, s32)#if !defined(CONFIG_USER_ONLY )DEF_HELPER_3 (ptest, void, env, i32, i32)
target/m68k/op_helper.c +12 -4
@@ -1090,7 +1090,7 @@ uint64_t HELPER(bfffo_mem)(CPUM68KState *env, uint32_t addr,return n | ffo; } -void HELPER (chk )(CPUM68KState *env,int32_t val,int32_t ub) +void HELPER (chk )(CPUM68KState *env,int32_t val,int32_t ub,int ilen) {/* * From the specs:
@@ -1106,11 +1106,12 @@ void HELPER(chk)(CPUM68KState *env, int32_t val, int32_t ub) env->cc_c =0 <= ub ? val <0 || val > ub : val > ub && val <0 ;if (val <0 || val > ub) { -raise_exception_format2 (env,EXCP_CHK ,2 ,GETPC ()); +raise_exception_format2 (env,EXCP_CHK , ilen,GETPC ()); } } -void HELPER (chk2 )(CPUM68KState *env,int32_t val,int32_t lb,int32_t ub) +void HELPER (chk2 )(CPUM68KState *env,int32_t val,int32_t lb,int32_t ub, +int ilen) {/* * From the specs:
@@ -1127,6 +1128,13 @@ void HELPER(chk2)(CPUM68KState *env, int32_t val, int32_t lb, int32_t ub) env->cc_c = lb <= ub ? val < lb || val > ub : val > ub && val < lb;if (env->cc_c) { -raise_exception_format2 (env,EXCP_CHK ,4 ,GETPC ()); +raise_exception_format2 (env,EXCP_CHK , ilen,GETPC ()); } } + +void HELPER (cmp2 )(CPUM68KState *env,int32_t val,int32_t lb,int32_t ub) +{ +/* Identical to CHK2 (above) but doesn't raise an exception */ + env->cc_z = val != lb && val != ub; + env->cc_c = lb <= ub ? val < lb || val > ub : val > ub && val < lb; +}
target/m68k/translate.c +22 -9
@@ -4237,7 +4237,7 @@ DISAS_INSN(ff1)DISAS_INSN (chk) { -TCGv src, reg; +TCGv src, reg, ilen;int opsize;switch ((insn >>7 ) &3 ) {
@@ -4258,13 +4258,14 @@ DISAS_INSN(chk) reg =gen_extend (s,DREG (insn,9 ), opsize,1 );gen_flush_flags (s); -gen_helper_chk (tcg_env, reg, src); + ilen =tcg_constant_i32 (s->pc - s->base.pc_next); +gen_helper_chk (tcg_env, reg, src, ilen); }DISAS_INSN (chk2) {uint16_t ext; -TCGv addr1, addr2, bound1, bound2, reg; +TCGv addr1, addr2, bound1, bound2, reg, ilen;int opsize;switch ((insn >>9 ) &3 ) {
@@ -4283,10 +4284,6 @@ DISAS_INSN(chk2) } ext =read_im16 (env, s); -if ((ext &0x0800 ) ==0 ) { -gen_exception (s, s->base.pc_next,EXCP_ILLEGAL ); -return ; - } addr1 =gen_lea (env, s, insn,OS_UNSIZED ); addr2 =tcg_temp_new ();
@@ -4303,7 +4300,12 @@ DISAS_INSN(chk2) }gen_flush_flags (s); -gen_helper_chk2 (tcg_env, reg, bound1, bound2); +if ((ext &0x0800 ) ==0 ) { +gen_helper_cmp2 (tcg_env, reg, bound1, bound2); + }else { + ilen =tcg_constant_i32 (s->pc - s->base.pc_next); +gen_helper_chk2 (tcg_env, reg, bound1, bound2, ilen); + } }static void m68k_copy_line (TCGv dst,TCGv src,int index)
@@ -5770,8 +5772,11 @@ void register_m68k_insns (CPUM68KState *env)BASE (undef,0000 ,0000 );INSN (arith_im,0080 , fff8,CF_ISA_A );INSN (arith_im,0000 , ff00,M68K ); - INSN(chk2, 00c0, f9c0, CHK2); INSN(bitrev, 00c0, fff8, CF_ISA_APLUSC); + INSN(chk2, 00d0, fff8, CHK2); +INSN (chk2,00e8 , fff8,CHK2 ); + INSN(chk2, 00f0, fff8, CHK2); + INSN(chk2, 00f8, fffc, CHK2);BASE (bitop_reg,0100 , f1c0);BASE (bitop_reg,0140 , f1c0);BASE (bitop_reg,0180 , f1c0);
@@ -5781,12 +5786,20 @@ void register_m68k_insns (CPUM68KState *env)INSN (arith_im,0200 , ff00,M68K ); INSN(undef, 02c0, ffc0, M68K); INSN(byterev, 02c0, fff8, CF_ISA_APLUSC); + INSN(chk2, 02d0, fff8, CHK2); +INSN (chk2,02e8 , fff8,CHK2 ); + INSN(chk2, 02f0, fff8, CHK2); + INSN(chk2, 02f8, fffc, CHK2);INSN (arith_im,0480 , fff8,CF_ISA_A );INSN (arith_im,0400 , ff00,M68K ); INSN(undef, 04c0, ffc0, M68K);INSN (arith_im,0600 , ff00,M68K ); INSN(undef, 06c0, ffc0, M68K); INSN(ff1, 04c0, fff8, CF_ISA_APLUSC); + INSN(chk2, 04d0, fff8, CHK2); +INSN (chk2,04e8 , fff8,CHK2 ); + INSN(chk2, 04f0, fff8, CHK2); + INSN(chk2, 04f8, fffc, CHK2);INSN (arith_im,0680 , fff8,CF_ISA_A ); INSN(arith_im, 0c00, ff38, CF_ISA_A); INSN(arith_im, 0c00, ff00, M68K);
tests/tcg/m68k/trap.c +100 -5
125 lines not on this page · raw message
Signature · 1 line
2.52.0
Richard Henderson
AppliedQuoted 6 lines · Laurent Vivier
The following changes since commit
b254e486242466dad881fc2bbfa215f1b67cd30f:Merge tag 'pull-riscv-to-apply-20260109' ofhttps://github.com/alistair23/qemu into staging (2026-01-10 10:31:57 +1100)are available in the Git repository at:
Quoted 8 lines
https://github.com/vivier/qemu-m68k.git tags/m68k-for-11.0-pull-requestfor you to fetch changes up to
cad529260a8503b79d76589f1427ee592e31a801:target/m68k: Improve CHK and CHK2; implement CMP2 (2026-01-12 16:26:48 +0100)----------------------------------------------------------------
Pull request for M68K emulation (20250113)
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.0 as appropriate.
r~