Implement missing functionality and hooks in mk68k to support upcoming sun3 impl
v4 cover Implement missing functionality and hooks in mk68k to support upcoming sun3 impl
Extends the 68020 implementation to support the requirements of a sun3 machine.
This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into smaller parts.
54weasels (6):
target/m68k: Add dummy CAAR register target/m68k: Fix fsave/frestore for 68881 FPU target/m68k: Fix NMI pending for Level 7 interrupts target/m68k: Extract Function Codes during TLB fills target/m68k: Implement custom MMU intercept hook target/m68k: Implement Physical Bus Error and Stack
target/m68k/cpu.c | 4 +- target/m68k/cpu.h | 18 ++++- target/m68k/helper.c | 130 ++++++++++++++++++++++++++++- target/m68k/op_helper.c | 175 ++++++++++++++++++++++++++-------------- target/m68k/translate.c | 30 +++++-- 5 files changed, 280 insertions(+), 77 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v4 1/6 target/m68k: Add dummy CAAR register
High level description:
The Sun-3 ROM expects the Cache Control Register (CAAR) to exist on the 68020. Reading/writing this register currently aborts QEMU. This patch provides a dummy implementation that simply ignores writes and returns 0 on reads, allowing the ROM to continue booting.
Impact on existing functionality:
No impact on existing targets. ColdFire and Mac targets do not access CAAR in a way that currently aborts, and providing a safe dummy implementation ensures robustness across M68k boards.
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
--- target/m68k/helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
target/m68k/helper.c +6 -2
@@ -281,8 +281,10 @@ void HELPER(m68k_movec_to)(CPUM68KState *env, uint32_t reg, uint32_t val)return ; }break ; -/* Unimplemented Registers */ +/* Dummy implementation for CAAR */ case M68K_CR_CAAR : +return ; +/* Unimplemented Registers */ case M68K_CR_PCR :case M68K_CR_BUSCR : cpu_abort(env_cpu(env),
@@ -385,8 +387,10 @@ uint32_t HELPER(m68k_movec_from)(CPUM68KState *env, uint32_t reg)return env->mmu.ttr[M68K_DTTR1 ]; }break ; -/* Unimplemented Registers */ +/* Dummy implementation for CAAR */ case M68K_CR_CAAR : +return 0 ; +/* Unimplemented Registers */ case M68K_CR_PCR :case M68K_CR_BUSCR : cpu_abort(env_cpu(env), "Unimplemented control register read 0x%x\n",
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v4 2/6 target/m68k: Fix fsave/frestore for 68881 FPU
In reply to 54weaselsHigh level description:
The 68881/68882 FPUs require fsave/frestore instructions to read/write state frames. QEMU only fully implemented this for the 68040. The Sun-3 uses a 68881 FPU, and the boot ROM executes fsave to probe FPU presence. This patch adds basic 68881 FPU state frame handling (NULL frame) to accurately simulate an idle FPU state.
Impact on existing functionality:
Fixes FPU detection for 68881/68882 across all M68k boards without affecting 68040 specific state logic.
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
--- target/m68k/translate.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
target/m68k/translate.c +16 -4
@@ -5364,11 +5364,19 @@ DISAS_INSN(frestore)gen_exception (s, s->base.pc_next,EXCP_PRIVILEGE );return ; } -if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +if (m68k_feature (s->env,M68K_FEATURE_M68040 ) || +m68k_feature (s->env,M68K_FEATURE_FPU )) {SRC_EA (env, addr,OS_LONG ,0 ,NULL ); -/* FIXME: check the state frame */ +if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +/* FIXME: check the state frame */ + }else { +/* +* 68881/68882 FRESTORE: read the state frame +* (NULL frame is 4 bytes) +*/ + } }else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }
@@ -5383,8 +5391,12 @@ DISAS_INSN(fsave)/* always write IDLE */ TCGv idle =tcg_constant_i32 (0x41000000 ); DEST_EA(env, insn, OS_LONG, idle, NULL); + }else if (m68k_feature (s->env,M68K_FEATURE_FPU )) { +/* 68881/68882 FSAVE: always write NULL frame */ +TCGv null_frame =tcg_constant_i32 (0x00000000 ); +DEST_EA (env, insn,OS_LONG , null_frame,NULL ); }else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }#endif
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v4 2/6] target/m68k: Fix fsave/frestore for 68881 FPU
Quoted 5 lines · On Mon, 17 Aug 2026, 54weasels wrote:
High level description:
The 68881/68882 FPUs require fsave/frestore instructions to read/write state frames. QEMU only fully implemented this for the 68040. The Sun-3 uses a 68881 FPU, and the boot ROM executesfsaveto probe FPU presence. This patch adds basic 68881 FPU state frame handling (NULL frame) to accurately simulate an idle FPU state.Impact on existing functionality:
Fixes FPU detection for 68881/68882 across all M68k boards without affecting 68040 specific state logic.
Comments such as the next Context: should go below the --- as everything before that is part of the commit message. In QEMU a Context: tag is not commonly used so I think you want this as a comment not part of the commit message.
Quoted 10 lines
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
---target/m68k/translate.c| 20 ++++++++++++++++----1 file changed, 16 insertions(+), 4 deletions(-)target/m68k/translate.c +0
-0
target/m68k/translate.c DISAS_INSN(frestore) · line 5368
Quoted 6 lines
target/m68k/translate.c +2
-1@@ -5364,11 +5364,19 @@ DISAS_INSN(frestore)gen_exception (s, s->base.pc_next,EXCP_PRIVILEGE );return ; } -if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +if (m68k_feature (s->env,M68K_FEATURE_M68040 ) || +m68k_feature (s->env,M68K_FEATURE_FPU )) {
M68020+ (including M68040) has FPU set so no need to keep that test and can be replaced with M68K_FEATURE_FPU.
target/m68k/translate.c DISAS_INSN(frestore) · line 5372
Quoted 5 lines
target/m68k/translate.c +3
-1SRC_EA (env, addr,OS_LONG ,0 ,NULL ); -/* FIXME: check the state frame */ +if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +/* FIXME: check the state frame */ + }else {
What about M68060 or other CPUs with built-in FPU? As none of these do anything maybe the if/else is not needed and can just keep the FIXME comment?
Quoted 12 lines
target/m68k/translate.c +6
-1+/* +* 68881/68882 FRESTORE: read the state frame +* (NULL frame is 4 bytes) +*/ + } }else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }
target/m68k/translate.c DISAS_INSN(fsave) · line 5397
Quoted 7 lines
target/m68k/translate.c +4
-0@@ -5383,8 +5391,12 @@ DISAS_INSN(fsave)/* always write IDLE */ TCGv idle =tcg_constant_i32 (0x41000000 );DEST_EA (env, insn,OS_LONG , idle,NULL ); + }else if (m68k_feature (s->env,M68K_FEATURE_FPU )) { +/* 68881/68882 FSAVE: always write NULL frame */ +TCGv null_frame =tcg_constant_i32 (0x00000000 ); +DEST_EA (env, insn,OS_LONG , null_frame,NULL );
Same comment as above about CPUs with FPU. Maybe there should be only one block for M68K_FEATURE_FPU replacing M68K_FEATURE_M68040 and a switch for setting the frame value?
Regards,
BALATON Zoltan
Quoted 7 lines
target/m68k/translate.c +1
-1} else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }#endif
Re: [PATCH v4 2/6] target/m68k: Fix fsave/frestore for 68881 FPU
Hi Zoltan,
Thanks for the review!
I've refactored the logic for v5. I removed the redundant M68040 checks in frestore (keeping just the FIXME), and streamlined fsave so that it uniformly checks for M68K_FEATURE_FPU, writing an IDLE frame (0x41000000) for the 68040 and a NULL frame (0x00000000) for the 68881/68882. Also, thanks for the tip on the Context: tag. I've updated my script to inject it below the --- separator in the .patch files so it stays off the permanent git commit log while remaining visible to reviewers.
I'll wait a bit longer to see if there are comments on the rest of the series before spinning new patches.
Dan.
Quoted 85 lines · BALATON Zoltan
Quoted 2 lines · On Mon, 17 Aug 2026, 54weasels wrote:
High level description:
The 68881/68882 FPUs require fsave/frestore instructions to read/writestate frames. QEMU only fully implemented this for the 68040. The Sun-3 uses a 68881 FPU, and the boot ROM executes
fsaveto probe FPU presence. This patch adds basic 68881 FPU state frame handling (NULL frame) to accurately simulate an idle FPU state.Quoted 3 lines
Impact on existing functionality:
Fixes FPU detection for 68881/68882 across all M68k boards withoutaffecting 68040 specific state logic.
Comments such as the next Context: should go below the --- as everything before that is part of the commit message. In QEMU a Context: tag is not commonly used so I think you want this as a comment not part of the commit message.
Quoted 1 line
Context: This patch was originally submitted as part of the monolithic
Sun-3 Machine Emulation series (
https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.Quoted 9 lines
---
target/m68k/translate.c| 20 ++++++++++++++++----1 file changed, 16 insertions(+), 4 deletions(-)target/m68k/translate.c +0
-0target/m68k/translate.c DISAS_INSN(frestore) · line 5368
Quoted 6 lines
target/m68k/translate.c +2
-1@@ -5364,11 +5364,19 @@ DISAS_INSN(frestore)gen_exception (s, s->base.pc_next,EXCP_PRIVILEGE );return ; } -if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +if (m68k_feature (s->env,M68K_FEATURE_M68040 ) || +m68k_feature (s->env,M68K_FEATURE_FPU )) {M68020+ (including M68040) has FPU set so no need to keep that test and can be replaced with
M68K_FEATURE_FPU.target/m68k/translate.c DISAS_INSN(frestore) · line 5372
Quoted 5 lines
target/m68k/translate.c +3
-1SRC_EA (env, addr,OS_LONG ,0 ,NULL ); -/* FIXME: check the state frame */ +if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +/* FIXME: check the state frame */ + }else {What about M68060 or other CPUs with built-in FPU? As none of these do anything maybe the if/else is not needed and can just keep the FIXME comment?
Quoted 12 lines
target/m68k/translate.c +6
-1+/* +* 68881/68882 FRESTORE: read the state frame +* (NULL frame is 4 bytes) +*/ + } }else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }target/m68k/translate.c DISAS_INSN(fsave) · line 5397
Quoted 7 lines
target/m68k/translate.c +4
-0@@ -5383,8 +5391,12 @@ DISAS_INSN(fsave)/* always write IDLE */ TCGv idle =tcg_constant_i32 (0x41000000 );DEST_EA (env, insn,OS_LONG , idle,NULL ); + }else if (m68k_feature (s->env,M68K_FEATURE_FPU )) { +/* 68881/68882 FSAVE: always write NULL frame */ +TCGv null_frame =tcg_constant_i32 (0x00000000 ); +DEST_EA (env, insn,OS_LONG , null_frame,NULL );Same comment as above about CPUs with FPU. Maybe there should be only one block for
M68K_FEATURE_FPUreplacingM68K_FEATURE_M68040and a switch for setting the frame value?Regards,
BALATON ZoltanQuoted 7 lines
target/m68k/translate.c +1
-1} else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }#endif
Re: [PATCH v4 2/6] target/m68k: Fix fsave/frestore for 68881 FPU
Hello,
Quoted 10 lines · Purr Box
Hi Zoltan,
Thanks for the review!
I've refactored the logic for v5. I removed the redundant M68040 checks in frestore (keeping just the FIXME), and streamlined fsave so that it uniformly checks forM68K_FEATURE_FPU, writing an IDLE frame (0x41000000) for the 68040 and a NULL frame (0x00000000) for the 68881/68882. Also, thanks for the tip on the Context: tag. I've updated my script to inject it below the --- separator in the .patch files so it stays off the permanent git commit log while remaining visible to reviewers.
Update your script to also run qemu/scripts/checkpatch.pl or do that before submission. See https://www.qemu.org/docs/master/devel/submitting-a-patch.html
That should catch things like missing Signed-off-by that I've just noticed.
Regards,
BALATON Zoltan
Quoted 93 lines
I'll wait a bit longer to see if there are comments on the rest of the series before spinning new patches.
Dan.
Quoted 85 lines · BALATON Zoltan
Quoted 2 lines · On Mon, 17 Aug 2026, 54weasels wrote:
High level description:
The 68881/68882 FPUs require fsave/frestore instructions to read/writestate frames. QEMU only fully implemented this for the 68040. The Sun-3 uses a 68881 FPU, and the boot ROM executes
fsaveto probe FPU presence. This patch adds basic 68881 FPU state frame handling (NULL frame) to accurately simulate an idle FPU state.Quoted 3 lines
Impact on existing functionality:
Fixes FPU detection for 68881/68882 across all M68k boards withoutaffecting 68040 specific state logic.
Comments such as the next Context: should go below the --- as everything before that is part of the commit message. In QEMU a Context: tag is not commonly used so I think you want this as a comment not part of the commit message.
Quoted 1 line
Context: This patch was originally submitted as part of the monolithic
Sun-3 Machine Emulation series (
https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.Quoted 9 lines
---
target/m68k/translate.c| 20 ++++++++++++++++----1 file changed, 16 insertions(+), 4 deletions(-)target/m68k/translate.c +0
-0target/m68k/translate.c DISAS_INSN(frestore) · line 5368
Quoted 6 lines
target/m68k/translate.c +2
-1@@ -5364,11 +5364,19 @@ DISAS_INSN(frestore)gen_exception (s, s->base.pc_next,EXCP_PRIVILEGE );return ; } -if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +if (m68k_feature (s->env,M68K_FEATURE_M68040 ) || +m68k_feature (s->env,M68K_FEATURE_FPU )) {M68020+ (including M68040) has FPU set so no need to keep that test and can be replaced with
M68K_FEATURE_FPU.target/m68k/translate.c DISAS_INSN(frestore) · line 5372
Quoted 5 lines
target/m68k/translate.c +3
-1SRC_EA (env, addr,OS_LONG ,0 ,NULL ); -/* FIXME: check the state frame */ +if (m68k_feature (s->env,M68K_FEATURE_M68040 )) { +/* FIXME: check the state frame */ + }else {What about M68060 or other CPUs with built-in FPU? As none of these do anything maybe the if/else is not needed and can just keep the FIXME comment?
Quoted 12 lines
target/m68k/translate.c +6
-1+/* +* 68881/68882 FRESTORE: read the state frame +* (NULL frame is 4 bytes) +*/ + } }else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }target/m68k/translate.c DISAS_INSN(fsave) · line 5397
Quoted 7 lines
target/m68k/translate.c +4
-0@@ -5383,8 +5391,12 @@ DISAS_INSN(fsave)/* always write IDLE */ TCGv idle =tcg_constant_i32 (0x41000000 );DEST_EA (env, insn,OS_LONG , idle,NULL ); + }else if (m68k_feature (s->env,M68K_FEATURE_FPU )) { +/* 68881/68882 FSAVE: always write NULL frame */ +TCGv null_frame =tcg_constant_i32 (0x00000000 ); +DEST_EA (env, insn,OS_LONG , null_frame,NULL );Same comment as above about CPUs with FPU. Maybe there should be only one block for
M68K_FEATURE_FPUreplacingM68K_FEATURE_M68040and a switch for setting the frame value?Regards,
BALATON ZoltanQuoted 7 lines
target/m68k/translate.c +1
-1} else { -disas_undef (env, s, insn); +disas_undef_fpu (env, s, insn); } }#endif
PATCH v4 3/6 target/m68k: Fix NMI pending for Level 7 interrupts
In reply to 54weaselsHigh level description:
Level 7 interrupts are Non-Maskable Interrupts (NMI) on the M68k architecture. The hardware asserts an NMI only on the rising edge of the level 7 signal. The current QEMU implementation treats level 7 like a standard level interrupt. This patch ensures proper NMI edge-triggered semantics for level 7, which is strictly required by the Sun-3 keyboard/mouse NMI routing logic.
Impact on existing functionality:
Corrects NMI edge-triggering for all M68k boards, adhering closely to the Motorola specifications. Existing boards will now correctly require an edge transition to trigger consecutive NMIs.
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
--- target/m68k/cpu.h | 1 + target/m68k/helper.c | 6 ++++++ target/m68k/op_helper.c | 14 ++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-)
target/m68k/cpu.h +1 -0
@@ -148,6 +148,7 @@ typedef struct CPUArchState {int pending_vector;int pending_level; +bool nmi_pending;/* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields;
target/m68k/helper.c +6 -0
@@ -949,6 +949,12 @@ void m68k_set_irq_level(M68kCPU *cpu, int level, uint8_t vector)CPUState *cs =CPU (cpu);CPUM68KState *env = &cpu->env; +if (level ==7 && env->pending_level !=7 ) { + env->nmi_pending = true; + }else if (level !=7 ) { + env->nmi_pending = false; + } + env->pending_level = level; env->pending_vector = vector;if (level) {
target/m68k/op_helper.c +6 -8
@@ -522,14 +522,12 @@ bool m68k_cpu_exec_interrupt(CPUState *cs, int interrupt_request) {CPUM68KState *env =cpu_env (cs); -if (interrupt_request &CPU_INTERRUPT_HARD - && ((env->sr &SR_I ) >>SR_I_SHIFT ) < env->pending_level) { -/* -* Real hardware gets the interrupt vector via an IACK cycle -* at this point. Current emulated hardware doesn't rely on -* this, so we provide/save the vector when the interrupt is -* first signalled. -*/ +if (env->nmi_pending) { + env->nmi_pending = false; + cs->exception_index = env->pending_vector; +do_interrupt_m68k_hardirq (env); +return true; + }else if (((env->sr &SR_I ) >>SR_I_SHIFT ) < env->pending_level) { cs->exception_index = env->pending_vector;do_interrupt_m68k_hardirq (env);return true;
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v4 3/6] target/m68k: Fix NMI pending for Level 7 interrupts
Quoted 18 lines · On Mon, 17 Aug 2026, 54weasels wrote:
High level description:
Level 7 interrupts are Non-Maskable Interrupts (NMI) on the M68k architecture. The hardware asserts an NMI only on the rising edge of the level 7 signal. The current QEMU implementation treats level 7 like a standard level interrupt. This patch ensures proper NMI edge-triggered semantics for level 7, which is strictly required by the Sun-3 keyboard/mouse NMI routing logic.Impact on existing functionality:
Corrects NMI edge-triggering for all M68k boards, adhering closely to the Motorola specifications. Existing boards will now correctly require an edge transition to trigger consecutive NMIs.Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
---target/m68k/cpu.h | 1 + target/m68k/helper.c | 6 ++++++ target/m68k/op_helper.c | 14 ++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-)target/m68k/cpu.h +0
-0
target/m68k/cpu.h typedef struct CPUArchState { · line 151
Quoted 4 lines
target/m68k/cpu.h +1
-0@@ -148,6 +148,7 @@ typedef struct CPUArchState {int pending_vector;int pending_level; +bool nmi_pending;
What's the difference between nmi_pending and pending_level == 7? If nothing do we need a new variable for it or could just test pending_level?
Regards,
BALATON Zoltan
Quoted 45 lines
target/m68k/cpu.h +0
-0/* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields;target/m68k/helper.c +6
-0@@ -949,6 +949,12 @@ void m68k_set_irq_level(M68kCPU *cpu, int level, uint8_t vector)CPUState *cs =CPU (cpu);CPUM68KState *env = &cpu->env; +if (level ==7 && env->pending_level !=7 ) { + env->nmi_pending = true; + }else if (level !=7 ) { + env->nmi_pending = false; + } + env->pending_level = level; env->pending_vector = vector;if (level) {target/m68k/op_helper.c +6
-8@@ -522,14 +522,12 @@ bool m68k_cpu_exec_interrupt(CPUState *cs, int interrupt_request) {CPUM68KState *env =cpu_env (cs); -if (interrupt_request &CPU_INTERRUPT_HARD - && ((env->sr &SR_I ) >>SR_I_SHIFT ) < env->pending_level) { -/* -* Real hardware gets the interrupt vector via an IACK cycle -* at this point. Current emulated hardware doesn't rely on -* this, so we provide/save the vector when the interrupt is -* first signalled. -*/ +if (env->nmi_pending) { + env->nmi_pending = false; + cs->exception_index = env->pending_vector; +do_interrupt_m68k_hardirq (env); +return true; + }else if (((env->sr &SR_I ) >>SR_I_SHIFT ) < env->pending_level) { cs->exception_index = env->pending_vector;do_interrupt_m68k_hardirq (env);return true;
Re: [PATCH v4 3/6] target/m68k: Fix NMI pending for Level 7 interrupts
Hi Zoltan,
nmi_pending captures the edge transition, while pending_level == 7 reflects the current level. Level 7 interrupts are edge-triggered — only the transition from a level less than 7 to level 7 initiates an NMI. If we just tested pending_level == 7, then it would act as level-triggered (the SR.I < pending_level check passes on every re-entry from rte as long as Level 7 stays asserted), which violates the spec.
Concretely, nmi_pending:
- Is set true only on the rising edge: level == 7 && pending_level != 7
- Is cleared after the NMI is taken: nmi_pending = false
- Is not re-set if Level 7 remains continuously asserted
This matters on the Sun-3 where the PROM routes the Intersil 7170 clock to Level 7 (intreg=0x81). The IRQC re-evaluates on every clock tick, keeping pending_level == 7. Without the separate edge flag, the CPU would take a spurious NMI on every interrupt check instead of once per tick.
Thanks,
Dan.
Quoted 88 lines · BALATON Zoltan
Quoted 2 lines · On Mon, 17 Aug 2026, 54weasels wrote:
High level description:
Level 7 interrupts are Non-Maskable Interrupts (NMI) on the M68karchitecture. The hardware asserts an NMI only on the rising edge of the level 7 signal. The current QEMU implementation treats level 7 like a standard level interrupt. This patch ensures proper NMI edge-triggered semantics for level 7, which is strictly required by the Sun-3 keyboard/mouse NMI routing logic.
Quoted 3 lines
Impact on existing functionality:
Corrects NMI edge-triggering for all M68k boards, adhering closely tothe Motorola specifications. Existing boards will now correctly require an edge transition to trigger consecutive NMIs.
Quoted 2 lines
Context: This patch was originally submitted as part of the monolithic
Sun-3 Machine Emulation series (
https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.Quoted 11 lines
---
target/m68k/cpu.h | 1 + target/m68k/helper.c | 6 ++++++ target/m68k/op_helper.c | 14 ++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-)target/m68k/cpu.h +0
-0target/m68k/cpu.h typedef struct CPUArchState { · line 151
Quoted 4 lines
target/m68k/cpu.h +1
-0@@ -148,6 +148,7 @@ typedef struct CPUArchState {int pending_vector;int pending_level; +bool nmi_pending;What's the difference between
nmi_pendingandpending_level== 7? If nothing do we need a new variable for it or could just testpending_level?Regards,
BALATON Zoltantarget/m68k/helper.c void m68k_set_irq_level(M68kCPU *cpu, int level,
Quoted 7 lines
target/m68k/cpu.h +0
-0/* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields;target/m68k/helper.c +0
-0@@ -949,6 +949,12 @@ void m68k_set_irq_level(M68kCPU *cpu, int level,
uint8_tvector)target/m68k/op_helper.c bool m68k_cpu_exec_interrupt(CPUState *cs, int
Quoted 17 lines
target/m68k/helper.c +6
-0CPUState *cs =CPU (cpu);CPUM68KState *env = &cpu->env; +if (level ==7 && env->pending_level !=7 ) { + env->nmi_pending = true; + }else if (level !=7 ) { + env->nmi_pending = false; + } + env->pending_level = level; env->pending_vector = vector;if (level) {target/m68k/op_helper.c +0
-0@@ -522,14 +522,12 @@ bool m68k_cpu_exec_interrupt(CPUState *cs, int
interrupt_request)Quoted 21 lines
target/m68k/op_helper.c +6
-8{CPUM68KState *env =cpu_env (cs); -if (interrupt_request &CPU_INTERRUPT_HARD - && ((env->sr &SR_I ) >>SR_I_SHIFT ) < env->pending_level) { -/* -* Real hardware gets the interrupt vector via an IACK cycle -* at this point. Current emulated hardware doesn't rely on -* this, so we provide/save the vector when the interrupt is -* first signalled. -*/ +if (env->nmi_pending) { + env->nmi_pending = false; + cs->exception_index = env->pending_vector; +do_interrupt_m68k_hardirq (env); +return true; + }else if (((env->sr &SR_I ) >>SR_I_SHIFT ) < env->pending_level) { cs->exception_index = env->pending_vector;do_interrupt_m68k_hardirq (env);return true;
PATCH v4 4/6 target/m68k: Extract Function Codes during TLB fills
In reply to 54weaselsHigh level description:
The Motorola 68020 architecture utilizes 3-bit Function Codes (FC0-FC2) to distinguish between User/Supervisor Data and Program memory spaces during MMU translation. Previously, QEMU's TLB fills did not explicitly extract or pass these codes down to the translation hooks. This patch extracts the explicit Function Codes (either natively or via the moves instruction) and packs them into the access_type field. This is required for the upcoming Sun-3 emulation, whose external MMU hardware maps entirely different physical address spaces depending on the Function Code asserted on the bus.
Impact on existing functionality:
This change introduces no functional impact to existing ColdFire or Mac/Quadra m68k emulation targets. The extraction logic gracefully defaults to standard mapping modes for platforms that do not implement a custom MMU intercept hook, preserving existing TLB behavior.
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
--- target/m68k/cpu.c | 4 ++-- target/m68k/cpu.h | 10 ++++++---- target/m68k/helper.c | 26 ++++++++++++++++++++++++++ target/m68k/translate.c | 10 ++++++---- 4 files changed, 40 insertions(+), 10 deletions(-)
target/m68k/cpu.c +2 -2
@@ -52,8 +52,8 @@ static TCGTBCPUState m68k_get_tb_cpu_state(CPUState *cs) flags = (env->macsr >>4 ) &TB_FLAGS_MACSR ;if (env->sr &SR_S ) { flags |=TB_FLAGS_MSR_S ; - flags |= (env->sfc << (TB_FLAGS_SFC_S_BIT -2 )) &TB_FLAGS_SFC_S ; - flags |= (env->dfc << (TB_FLAGS_DFC_S_BIT -2 )) &TB_FLAGS_DFC_S ; + flags |= (env->sfc <<TB_FLAGS_SFC_S_BIT ) &TB_FLAGS_SFC_S ; + flags |= (env->dfc <<TB_FLAGS_DFC_S_BIT ) &TB_FLAGS_DFC_S ; }if (M68K_SR_TRACE (env->sr) ==M68K_SR_TRACE_ANY_INS ) { flags |=TB_FLAGS_TRACE ;
target/m68k/cpu.h +6 -4
@@ -601,12 +601,14 @@ void m68k_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,#define TB_FLAGS_MSR_S_BIT 13#define TB_FLAGS_MSR_S (1 << TB_FLAGS_MSR_S_BIT)#define TB_FLAGS_SFC_S_BIT 14 -#define TB_FLAGS_SFC_S (1 << TB_FLAGS_SFC_S_BIT) -#define TB_FLAGS_DFC_S_BIT 15 -#define TB_FLAGS_DFC_S (1 << TB_FLAGS_DFC_S_BIT) -#define TB_FLAGS_TRACE 16 +#define TB_FLAGS_SFC_S (7 << TB_FLAGS_SFC_S_BIT)/* 3 Bits reserved */ +#define TB_FLAGS_DFC_S_BIT 17 +#define TB_FLAGS_DFC_S (7 << TB_FLAGS_DFC_S_BIT)/* 3 Bits reserved */ +#define TB_FLAGS_TRACE 20#define TB_FLAGS_TRACE_BIT (1 << TB_FLAGS_TRACE) +#define MMU_MOVES_FC_BASE 2/* mmu_idx 2-9 correspond to FC 0-7 */ +void dump_mmu (CPUM68KState *env);#endif
target/m68k/helper.c +26 -0
@@ -975,6 +975,32 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size,int ret;target_ulong page_size; +if (qemu_access_type ==MMU_INST_FETCH ) { + access_type =ACCESS_CODE ; + }else { + access_type =ACCESS_DATA ; +if (qemu_access_type ==MMU_DATA_STORE ) { + access_type |=ACCESS_STORE ; + } + } + +/* Decode explicit Function Codes from moves instructions */ +if (mmu_idx >=MMU_MOVES_FC_BASE ) { +uint8_t fc = mmu_idx -MMU_MOVES_FC_BASE ; + access_type |= (fc <<8 );/* Pack explicit FC into access type */ +if (fc !=1 && fc !=2 ) { + access_type |=ACCESS_SUPER ; + } + }else { +/* Standard memory accesses map logically to normal M68K FCs */ +if (mmu_idx ==MMU_KERNEL_IDX ) { + access_type |=ACCESS_SUPER ; + access_type |= ((qemu_access_type ==MMU_INST_FETCH ?6 :5 ) <<8 ); + }else { + access_type |= ((qemu_access_type ==MMU_INST_FETCH ?2 :1 ) <<8 ); + } + } +if ((env->mmu.tcr &M68K_TCR_ENABLED ) ==0 ) {/* MMU disabled */ tlb_set_page(cs, address & TARGET_PAGE_MASK,
target/m68k/translate.c +6 -4
@@ -163,10 +163,12 @@ static void do_writebacks(DisasContext *s)#define IS_USER (s) 1#else #define IS_USER (s) (!(s->base.tb->flags & TB_FLAGS_MSR_S)) -#define SFC_INDEX (s) ((s->base.tb->flags & TB_FLAGS_SFC_S) ? \ - MMU_KERNEL_IDX : MMU_USER_IDX) -#define DFC_INDEX (s) ((s->base.tb->flags & TB_FLAGS_DFC_S) ? \ - MMU_KERNEL_IDX : MMU_USER_IDX) +#define SFC_INDEX (s) (MMU_MOVES_FC_BASE + \ + (((s)->base.tb->flags & TB_FLAGS_SFC_S) >> \ + TB_FLAGS_SFC_S_BIT)) +#define DFC_INDEX (s) (MMU_MOVES_FC_BASE + \ + (((s)->base.tb->flags & TB_FLAGS_DFC_S) >> \ + TB_FLAGS_DFC_S_BIT))#endif typedef void (*disas_proc )(CPUM68KState *env,DisasContext *s,uint16_t insn);
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v4 5/6 target/m68k: Implement custom MMU intercept hook
In reply to 54weaselsHigh level description:
Boards like the Sun-3 use an external custom MMU logic array rather than the standard 68851/68030 embedded MMU. This patch introduces a custom_mmu_get_physical_address opaque hook, allowing board initialization code to intercept TLB fills and delegate translation directly to the machine's external MMU implementation.
Impact on existing functionality:
Zero impact on existing boards. If the hook is not explicitly registered by the board initialization code, the standard 68k MMU translation pipeline executes normally.
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
--- target/m68k/cpu.h | 7 ++++ target/m68k/helper.c | 89 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+)
target/m68k/cpu.h +7 -0
@@ -153,6 +153,13 @@ typedef struct CPUArchState {/* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields; +/* Custom MMU intercept logic, if any (e.g. for Sun-3) */ +void *custom_mmu_opaque; +int (*custom_mmu_get_physical_address)(void *env,hwaddr *physical, +int *prot,vaddr address, +int access_type, +hwaddr *page_size); +/* Fields from here on are preserved across CPU reset. */ uint64_t features; } CPUM68KState;
target/m68k/helper.c +89 -0
101 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v4 6/6 target/m68k: Implement Physical Bus Error and Stack
In reply to 54weaselsHigh level description:
Physical memory timeouts (e.g., probing unpopulated memory locations) must generate a Bus Error exception, resulting in Format 0xA or 0xB stack frames on the 68020. The Sun-3 PROM probes memory sizes by intentionally causing bus errors and analyzing the Special Status Word (SSW) on the stack frame. This patch implements hardware-injected EXCP_ACCESS cycle generation and the corresponding 84-byte long stack frame teardown.
Impact on existing functionality:
Accurately populates the 68020 84-byte SSW stack frames. Older architectures (like 68000) safely ignore the hook and gracefully exit without generating the advanced frames.
Context: This patch was originally submitted as part of the monolithic Sun-3 Machine Emulation series (https://patchew.org/QEMU/[email protected]/) and has been split into atomic components.
--- target/m68k/helper.c | 1 + target/m68k/op_helper.c | 161 +++++++++++++++++++++++++++------------- 2 files changed, 109 insertions(+), 53 deletions(-)
target/m68k/helper.c +1 -0
@@ -29,6 +29,7 @@#include "system/memory.h" #include "gdbstub/helpers.h" #include "fpu/softfloat.h" +#include "qemu/log.h" #include "qemu/qemu-print.h" #define SIGNBIT (1u << 31)
target/m68k/op_helper.c +108 -53
195 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)