m68k: Add Sun-3 Machine Emulation
cover m68k: Add Sun-3 Machine Emulation
This implements a barebones Sun 3/60 that can boot a standard firmware, pass all the diagnostic tests and fully netboot both NetBSD 10 and SunOS 4.1.1
It has the minimum necessary devices: memory/MMU, diagnostic and error registers, interrupt, TOD clock, DMA, IDprom and configuration eeprom. I/O is the console serial and lance ethernet. There are a few modifications needed to emulate a proper 68020, support another external MMU and sun3 specific ways of u sing the escc and ethernet devices. Next steps are implementing SCSI, graphics, and patching through the keyboard and mouse.
This is part of the Sun 3/60 preservation project: https://github.com/54weasels/sun3_60
54weasels (7):
target/m68k: Implement Physical Bus Error exception handling hw/net/lance: Add Sun-3 Native DMA byte-swapping support hw/char/escc: Expose diagnostic RS232 I/O routing hw/timer: Introduce Intersil 7170 RTC implementation hw/m68k: Overhaul Sun-3 MMU and Boot PROM mapping tests/qtest: Add Sun-3 hardware interaction tests tests/functional: Add Sun-3 firmware boot and diagnostic test
hw/char/escc.c | 33 +- hw/m68k/Kconfig | 8 + hw/m68k/meson.build | 1 + hw/m68k/sun3.c | 499 ++++++++++++++++++++ hw/m68k/sun3_eeprom_data.h | 259 ++++++++++ hw/m68k/sun3mmu.c | 705 ++++++++++++++++++++++++++++ hw/net/lance.c | 111 ++++- hw/net/meson.build | 3 +- hw/timer/Kconfig | 3 + hw/timer/intersil7170.c | 216 +++++++++ hw/timer/meson.build | 1 + include/hw/char/escc.h | 3 + include/hw/m68k/sun3mmu.h | 65 +++ include/hw/net/lance.h | 3 + include/hw/timer/intersil7170.h | 9 + target/m68k/cpu.c | 5 +- target/m68k/cpu.h | 18 +- target/m68k/helper.c | 130 ++++- target/m68k/op_helper.c | 176 ++++--- target/m68k/translate.c | 31 +- tests/functional/m68k/meson.build | 1 + tests/functional/m68k/test_sun3.py | 34 ++ tests/functional/qemu_test/asset.py | 11 +- tests/qtest/meson.build | 1 + tests/qtest/sun3-test.c | 67 +++ 25 files changed, 2294 insertions(+), 99 deletions(-) create mode 100644 hw/m68k/sun3.c create mode 100644 hw/m68k/sun3_eeprom_data.h create mode 100644 hw/m68k/sun3mmu.c create mode 100644 hw/timer/intersil7170.c create mode 100644 include/hw/m68k/sun3mmu.h create mode 100644 include/hw/timer/intersil7170.h create mode 100755 tests/functional/m68k/test_sun3.py create mode 100644 tests/qtest/sun3-test.c
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/7 target/m68k: Implement Physical Bus Error exception handling
The M68020 natively maps hardware Bus Error (BERR) timeouts into a Long Bus Cycle Fault (Format 0xB). This commit adds the memory exception routing to natively synthesize these EXCP_ACCESS cycle faults. It also implements the double-fault / watchdog reset behavior required for Sun-3 hardware diagnostics, properly handles FSAVE/FRESTORE for 68881 FPU stubs, and properly constructs the 84-byte internal bus fault frame.
--- target/m68k/cpu.c | 5 +- target/m68k/cpu.h | 18 +++- target/m68k/helper.c | 130 ++++++++++++++++++++++++++++- target/m68k/op_helper.c | 176 ++++++++++++++++++++++++++-------------- target/m68k/translate.c | 31 +++++-- 5 files changed, 283 insertions(+), 77 deletions(-)
target/m68k/cpu.c +3 -2
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * QEMU Motorola 68k CPU *
@@ -51,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 +14 -4
@@ -149,10 +149,18 @@ 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; +/* 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;
@@ -601,12 +609,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 +128 -2
168 lines not on this page · raw message
target/m68k/op_helper.c +115 -61
219 lines not on this page · raw message
target/m68k/translate.c +23 -8
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * m68k translation *
@@ -163,10 +164,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);
@@ -5364,11 +5367,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 +5394,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 1/7] target/m68k: Implement Physical Bus Error exception handling
Hi!
Thanks for your patches ... some comments inline below...
Am Sat, 2 May 2026 18:57:50 -0700
schrieb 54weasels <[email protected]>:
Quoted 16 lines
The M68020 natively maps hardware Bus Error (BERR) timeouts into a Long Bus Cycle Fault (Format
0xB). This commit adds the memory exception routing to natively synthesize theseEXCP_ACCESScycle faults. It also implements the double-fault / watchdog reset behavior required for Sun-3 hardware diagnostics, properly handles FSAVE/FRESTORE for 68881 FPU stubs, and properly constructs the 84-byte internal bus fault frame.Signed-off-by 54weasels <[email protected]>--- target/m68k/cpu.c | 5 +- target/m68k/cpu.h | 18 +++- target/m68k/helper.c | 130 ++++++++++++++++++++++++++++- target/m68k/op_helper.c | 176 ++++++++++++++++++++++++++-------------- target/m68k/translate.c | 31 +++++-- 5 files changed, 283 insertions(+), 77 deletions(-)target/m68k/cpu.c +0
-0
target/m68k/cpu.c line 1
Quoted 1 line
target/m68k/cpu.c +1
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
Looking at the comment at the top of this file, it clearly states that this file is licensed under the Lesser GPL, so this change is wrong.
target/m68k/cpu.c static TCGTBCPUState m68k_get_tb_cpu_state(CPUState *cs) · line 56
Quoted 11 lines
target/m68k/cpu.c +2
-2/* * QEMU Motorola 68k CPU * @@ -51,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 ;
Wrong indentation now?
Quoted 3 lines
target/m68k/cpu.c +0
-0}if (M68K_SR_TRACE (env->sr) ==M68K_SR_TRACE_ANY_INS ) { flags |=TB_FLAGS_TRACE ;
...
Quoted 146 lines
target/m68k/op_helper.c +70
-48@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * M68K helper routines * @@ -25,6 +26,7 @@#include "qemu/plugin.h" #if !defined(CONFIG_USER_ONLY ) +#include "system/runstate.h" static void cf_rte (CPUM68KState *env) {@@ -73,6 +75,12 @@ throwaway:case 7 : sp +=52 ;break ; +case 0xa :/* Short Bus Cycle Fault (Format 0xA) */ + sp +=32 -8 ;/* 32 bytes total - 8 bytes header = 24 bytes */ +break ; +case 0xb :/* Long Bus Cycle Fault (Format 0xB) */ + sp +=92 -8 ;/* 92 bytes total - 8 bytes header = 84 bytes */ +break ; } } env->aregs[7 ] = sp;@@ -342,56 +350,80 @@ static void m68k_interrupt_all(CPUM68KState *env, int is_hw)switch (cs->exception_index) {case EXCP_ACCESS :if (env->mmu.fault) { -cpu_abort (cs,"DOUBLE MMU FAULT\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"M68K: Double MMU Fault. Halting CPU and requesting reset.\n" ); +qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); + cs->halted =1 ; + cs->exception_index =EXCP_HLT ; +cpu_loop_exit (cs); } env->mmu.fault = true; -/* push data 3 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* push data 2 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* push data 1 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 1 / push data 0 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 1 address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 2 data */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 2 address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 3 data */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 3 address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); -/* fault address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); -/* write back 1 status */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 2 status */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 3 status */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* special status word */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp, env->mmu.ssw,MMU_KERNEL_IDX ,0 ); -/* effective address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); - -do_stack_frame (env, &sp,7 , oldsr,0 , env->pc); + +if (m68k_feature (env,M68K_FEATURE_M68040 )) { +/* push data 3 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* push data 2 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* push data 1 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 1 / push data 0 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 1 address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 2 data */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 2 address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 3 data */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 3 address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); +/* fault address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); +/* write back 1 status */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 2 status */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 3 status */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* special status word */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp, env->mmu.ssw,MMU_KERNEL_IDX ,0 ); +/* effective address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); + +do_stack_frame (env, &sp,7 , oldsr,0 , env->pc); + }else { +/* M68020 Long Bus Cycle Fault (Format 0xB) */ +/* +* 84 bytes of internal state are pushed before the generic +* 8-byte header +*/ + sp -=84 ;
target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw) · line 426
Quoted 10 lines
target/m68k/op_helper.c +10
-0+for (int i =0 ; i <84 ; i +=4 ) { +cpu_stl_be_mmuidx_ra (env, sp + i,0 ,MMU_KERNEL_IDX ,0 ); + } +/* Offset 0x02 from internal frame: SSW */ +cpu_stw_be_mmuidx_ra (env, sp +2 , env->mmu.ssw,MMU_KERNEL_IDX ,0 ); +/* Offset 0x08 from internal frame: Fault Address */ +cpu_stl_be_mmuidx_ra (env, sp +8 , env->mmu.ar,MMU_KERNEL_IDX ,0 ); + +do_stack_frame (env, &sp,0xb , oldsr,0 , env->pc); + }
Your patch got quite big already and does multiple things at once ... could you maybe split independent parts like the above fixup for the stack frame layout into a separate patch, so that this can get reviewed more easily?
target/m68k/translate.c line 1
Quoted 6 lines
target/m68k/translate.c +1
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
This file is also LPGL, not GPL.
Thomas
Re: [PATCH 1/7] target/m68k: Implement Physical Bus Error exception handling
Thanks for the feedback, I'll perform the clean-ups and start splitting some stuff up. If you have more suggestions for how it'll be easiest to cut, let me know.
I'll resubmit a new patch and reference this one asap.
Thanks again,
Dan.
Quoted 237 lines · Thomas Huth
Hi!
Thanks for your patches ... some comments inline below...
Am Sat, 2 May 2026 18:57:50 -0700
schrieb 54weasels <[email protected]>:Quoted 1 line
The M68020 natively maps hardware Bus Error (BERR) timeouts into a Long
Bus Cycle Fault (Format
0xB). This commit adds the memory exception routing to natively synthesize theseEXCP_ACCESScycle faults. It also implements the double-fault / watchdog reset behavior required for Sun-3 hardware diagnostics, properly handles FSAVE/FRESTORE for 68881 FPU stubs, and properly constructs the 84-byte internal bus fault frame.Quoted 15 lines
Signed-off-by 54weasels <[email protected]>--- target/m68k/cpu.c | 5 +- target/m68k/cpu.h | 18 +++- target/m68k/helper.c | 130 ++++++++++++++++++++++++++++- target/m68k/op_helper.c | 176 ++++++++++++++++++++++++++-------------- target/m68k/translate.c | 31 +++++-- 5 files changed, 283 insertions(+), 77 deletions(-)target/m68k/cpu.c +0
-0target/m68k/cpu.c line 1
Quoted 1 line
target/m68k/cpu.c +1
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ Looking at the comment at the top of this file, it clearly states that this file is licensed under the Lesser GPL, so this change is wrong.
target/m68k/cpu.c static TCGTBCPUState m68k_get_tb_cpu_state(CPUState
Quoted 4 lines
target/m68k/cpu.c +0
-0/* * QEMU Motorola 68k CPU * @@ -51,8 +52,8 @@ static TCGTBCPUState m68k_get_tb_cpu_state(CPUState*cs)
target/m68k/cpu.c static TCGTBCPUState m68k_get_tb_cpu_state(CPUState *cs)
Quoted 4 lines
target/m68k/cpu.c +0
-1flags = (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;target/m68k/cpu.c static TCGTBCPUState m68k_get_tb_cpu_state(CPUState · line 55
Quoted 1 line
target/m68k/cpu.c +0
-1- flags |= (env->dfc << (TB_FLAGS_DFC_S_BIT - 2)) &
TB_FLAGS_DFC_S;target/m68k/cpu.c static TCGTBCPUState m68k_get_tb_cpu_state(CPUState *cs) · line 56
Quoted 2 lines
target/m68k/cpu.c +2
-0+ flags |= (env->sfc <<TB_FLAGS_SFC_S_BIT ) &TB_FLAGS_SFC_S ; + flags |= (env->dfc <<TB_FLAGS_DFC_S_BIT ) &TB_FLAGS_DFC_S ;Wrong indentation now?
Quoted 3 lines
target/m68k/cpu.c +0
-0}if (M68K_SR_TRACE (env->sr) ==M68K_SR_TRACE_ANY_INS ) { flags |=TB_FLAGS_TRACE ;...
Quoted 18 lines
target/m68k/op_helper.c +2
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * M68K helper routines * @@ -25,6 +26,7 @@#include "qemu/plugin.h" #if !defined(CONFIG_USER_ONLY ) +#include "system/runstate.h" static void cf_rte (CPUM68KState *env) {target/m68k/op_helper.c throwaway: · line 79
Quoted 5 lines
target/m68k/op_helper.c +2
-0@@ -73,6 +75,12 @@ throwaway:case 7 : sp +=52 ;break ; +case 0xa :/* Short Bus Cycle Fault (Format 0xA) */ + sp +=32 -8 ;/* 32 bytes total - 8 bytes header = 24 bytes */
target/m68k/op_helper.c throwaway:
Quoted 3 lines
target/m68k/op_helper.c +3
-0+break ; +case 0xb :/* Long Bus Cycle Fault (Format 0xB) */ + sp +=92 -8 ;/* 92 bytes total - 8 bytes header = 84 bytes */
target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env,
Quoted 5 lines
target/m68k/op_helper.c +1
-0+break ; } } env->aregs[7 ] = sp;@@ -342,56 +350,80 @@ static void m68k_interrupt_all(CPUM68KState *env,int
is_hw)target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
Quoted 6 lines
target/m68k/op_helper.c +2
-1switch (cs->exception_index) {case EXCP_ACCESS :if (env->mmu.fault) { -cpu_abort (cs,"DOUBLE MMU FAULT\n" ); + qemu_log_mask(LOG_GUEST_ERROR, + "M68K: Double MMU Fault. Halting CPU andrequesting reset.\n");
Quoted 72 lines
target/m68k/op_helper.c +23
-47+qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); + cs->halted =1 ; + cs->exception_index =EXCP_HLT ; +cpu_loop_exit (cs); } env->mmu.fault = true; -/* push data 3 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* push data 2 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* push data 1 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 1 / push data 0 */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 1 address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 2 data */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 2 address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 3 data */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 3 address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); -/* fault address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); -/* write back 1 status */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 2 status */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* write back 3 status */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); -/* special status word */ - sp -=2 ; -cpu_stw_be_mmuidx_ra (env, sp, env->mmu.ssw,MMU_KERNEL_IDX ,0 ); -/* effective address */ - sp -=4 ; -cpu_stl_be_mmuidx_ra (env, sp, env->mmu.ar,MMU_KERNEL_IDX ,0 ); - -do_stack_frame (env, &sp,7 , oldsr,0 , env->pc); + +if (m68k_feature (env,M68K_FEATURE_M68040 )) { +/* push data 3 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* push data 2 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* push data 1 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 1 / push data 0 */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 1 address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 2 data */ + sp -=4 ;target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
Quoted 10 lines
target/m68k/op_helper.c +10
-0+cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 2 address */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 3 data */ + sp -=4 ; +cpu_stl_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 3 address */ + sp -=4 ; + cpu_stl_be_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX,0);
target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
Quoted 3 lines
target/m68k/op_helper.c +3
-0+/* fault address */ + sp -=4 ; + cpu_stl_be_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX,0);
target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
Quoted 12 lines
target/m68k/op_helper.c +12
-0+/* write back 1 status */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 2 status */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* write back 3 status */ + sp -=2 ; +cpu_stw_be_mmuidx_ra (env, sp,0 ,MMU_KERNEL_IDX ,0 ); +/* special status word */ + sp -=2 ; + cpu_stw_be_mmuidx_ra(env, sp, env->mmu.ssw, MMU_KERNEL_IDX,0);
target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
Quoted 3 lines
target/m68k/op_helper.c +3
-0+/* effective address */ + sp -=4 ; + cpu_stl_be_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX,0);
Quoted 4 lines
target/m68k/op_helper.c +4
-0+ +do_stack_frame (env, &sp,7 , oldsr,0 , env->pc); + }else { +/* M68020 Long Bus Cycle Fault (Format 0xB) */ target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
Quoted 10 lines
target/m68k/op_helper.c +10
-0+/* +* 84 bytes of internal state are pushed before the generic +* 8-byte header +*/ + sp -=84 ; +for (int i =0 ; i <84 ; i +=4 ) { +cpu_stl_be_mmuidx_ra (env, sp + i,0 ,MMU_KERNEL_IDX ,0 ); + } +/* Offset 0x02 from internal frame: SSW */ + cpu_stw_be_mmuidx_ra(env, sp + 2, env->mmu.ssw,
MMU_KERNEL_IDX, 0);target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, · line 423
Quoted 2 lines
target/m68k/op_helper.c +2
-0+/* Offset 0x08 from internal frame: Fault Address */ + cpu_stl_be_mmuidx_ra(env, sp + 8, env->mmu.ar,
MMU_KERNEL_IDX, 0);target/m68k/op_helper.c static void m68k_interrupt_all(CPUM68KState *env, int is_hw) · line 426
Quoted 3 lines
target/m68k/op_helper.c +3
-0+ +do_stack_frame (env, &sp,0xb , oldsr,0 , env->pc); + }Your patch got quite big already and does multiple things at once ... could you maybe split independent parts like the above fixup for the stack frame layout into a separate patch, so that this can get reviewed more easily?
target/m68k/translate.c line 1
Quoted 6 lines
target/m68k/translate.c +1
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ This file is also LPGL, not GPL.
Thomas
PATCH 2/7 hw/net/lance: Add Sun-3 Native DMA byte-swapping support
In reply to 54weaselsThe Sun-3 hardware physically byte-swaps the D0-D7 and D8-D15 DMA lanes between the Little-Endian LANCE controller and the Big-Endian Sun-3 memory. This commit intercepts the LANCE DMA reads/writes by injecting a phys_mem override in pcnet.c specifically for the Sun-3 instance, dynamically neutralizing the hardcoded internal initblk swap and properly mapping the payload payloads.
--- hw/net/lance.c | 111 ++++++++++++++++++++++++++++++++++++++--- hw/net/meson.build | 3 +- include/hw/net/lance.h | 3 ++ 3 files changed, 109 insertions(+), 8 deletions(-)
hw/net/lance.c +104 -7
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * QEMU AMD PC-Net II (Am79C970A) emulation *
@@ -22,7 +23,8 @@* THE SOFTWARE. */ -/* This software was written to be compatible with the specification: +/* +* This software was written to be compatible with the specification: * AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet * AMD Publication# 19436 Rev:E Amendment/0 Issue Date: June 2000 */
@@ -44,8 +46,73 @@#include "hw/core/qdev-properties.h" #include "trace.h" #include "system/system.h" +#include "system/address-spaces.h" +#include "system/dma.h" + +/* +* LANCE Native DMA Read Hook +* +* Sun-3 Hardware intrinsically byte-swaps the D0-D7 and D8-D15 DMA lanes +* between the Little-Endian LANCE controller and the Big-Endian Sun-3 memory. +* We MUST model this manually. pcnet.c passes CSR_BSWP(s) for payloads +* (correctly bypassing the swap if LANCE internally neutralizes it). +* However, pcnet.c hardcodes do_bswap=1 for the `initblk` structure +* (len 24/28). +* We dynamically intercept the `initblk` fetch by cross-referencing CSR_IADR to +* enforce the hardware swap reliably. Because this branch is only taken when +* `dma_mr` is explicitly provided by the machine, this quirk is safely isolated +* to the Sun-3 and does not impact SPARC (which uses `ledma`). +*/ +static void lance_dma_read (void *dma_opaque,hwaddr addr, +uint8_t *buf,int len,int do_bswap) +{ +SysBusPCNetState *d =SYSBUS_PCNET (dma_opaque); +PCNetState *s = &d->state; + +dma_memory_read (&d->dma_as, addr, buf, len,MEMTXATTRS_UNSPECIFIED ); + +uint32_t bcr_ssize32 = (s->bcr[20 ] &0x0100 ); +hwaddr iadr = (s->csr[1 ] | ((uint32_t )s->csr[2 ] <<16 )); +if (!bcr_ssize32) { + iadr |= ((0xff00 & (uint32_t )s->csr[2 ]) <<16 ); + } +int internal_bswap = do_bswap; +if (addr == iadr && (len ==24 || len ==28 )) { + internal_bswap =0 ;/* Force hardware swap natively for initblk */ + } +if (!internal_bswap) { +for (int i =0 ; i < (len & ~1 ); i +=2 ) { +uint8_t tmp = buf[i]; + buf[i] = buf[i +1 ]; + buf[i +1 ] = tmp; + } + } +} + +/* LANCE Native DMA Write Hook */ +static void lance_dma_write (void *dma_opaque,hwaddr addr, +uint8_t *buf,int len,int do_bswap) +{ +SysBusPCNetState *s =SYSBUS_PCNET (dma_opaque); + +if (!do_bswap) { +uint8_t *swapped_buf =g_malloc (len); +for (int i =0 ; i < (len & ~1 ); i +=2 ) { + swapped_buf[i] = buf[i +1 ]; + swapped_buf[i +1 ] = buf[i]; + } +if (len &1 ) { + swapped_buf[len -1 ] = buf[len -1 ]; + } +dma_memory_write (&s->dma_as, addr, swapped_buf, len, +MEMTXATTRS_UNSPECIFIED ); +g_free (swapped_buf); + }else { +dma_memory_write (&s->dma_as, addr, buf, len,MEMTXATTRS_UNSPECIFIED ); + } +}static void parent_lance_reset (void *opaque,int irq,int level) {SysBusPCNetState *d = opaque;
@@ -59,7 +126,15 @@ static void lance_mem_write(void *opaque, hwaddr addr,SysBusPCNetState *d = opaque;trace_lance_mem_writew (addr, val &0xffff ); -pcnet_ioport_writew (&d->state, addr, val &0xffff ); +if (size ==1 ) { +uint16_t orig =pcnet_ioport_readw (&d->state, addr & ~1 ); +if (addr &1 ) {/* LSB in Big Endian */ + val = (orig &0xff00 ) | (val &0xff ); + }else {/* MSB in Big Endian */ + val = (orig &0x00ff ) | ((val &0xff ) <<8 ); + } + } +pcnet_ioport_writew (&d->state, addr & ~1 , val &0xffff ); } static uint64_t lance_mem_read(void *opaque, hwaddr addr,
@@ -68,18 +143,28 @@ static uint64_t lance_mem_read(void *opaque, hwaddr addr,SysBusPCNetState *d = opaque;uint32_t val; - val =pcnet_ioport_readw (&d->state, addr); -trace_lance_mem_readw (addr, val &0xffff ); + val =pcnet_ioport_readw (&d->state, addr & ~1 ); +if (size ==1 ) { +if (addr &1 ) { + val = val &0xff ; + }else { + val = (val >>8 ) &0xff ; + } + }return val &0xffff ; }static const MemoryRegionOps lance_mem_ops = { .read = lance_mem_read, .write = lance_mem_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_BIG_ENDIAN , .valid = { - .min_access_size =2 , - .max_access_size =2 , + .min_access_size =1 , + .max_access_size =4 , + }, + .impl = { + .min_access_size =1 , + .max_access_size =4 , }, };
@@ -115,8 +200,18 @@ static void lance_realize(DeviceState *dev, Error **errp)sysbus_init_irq (sbd, &s->irq); +if (d->dma_mr) { +address_space_init (&d->dma_as, d->dma_mr,"lance-dma" ); + s->phys_mem_read = lance_dma_read; + s->phys_mem_write = lance_dma_write; + s->dma_opaque =DEVICE (d); + }else { +#if defined(TARGET_SPARC ) s->phys_mem_read = ledma_memory_read; s->phys_mem_write = ledma_memory_write; +#endif + } +pcnet_common_init (dev, s, &net_lance_info); }
@@ -140,6 +235,8 @@ static void lance_instance_init(Object *obj)static const Property lance_properties[] = {DEFINE_PROP_LINK ("dma" , SysBusPCNetState, state.dma_opaque, TYPE_DEVICE, DeviceState *), +DEFINE_PROP_LINK ("dma_mr" , SysBusPCNetState, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *),DEFINE_NIC_PROPERTIES (SysBusPCNetState, state.conf), };
hw/net/meson.build +2 -1
@@ -31,7 +31,8 @@ system_ss.add(when: 'CONFIG_MARVELL_88W8618', if_true: files('mv88w8618_eth.c')) system_ss.add(when: 'CONFIG_CADENCE', if_true: files('cadence_gem.c')) system_ss.add(when: 'CONFIG_STELLARIS_ENET', if_true: files('stellaris_enet.c')) -system_ss.add(when: 'CONFIG_LANCE', if_true: files('lance.c')) +# LANCE uses target-specific memory types (e.g., target_ulong) and must be compiled per-target. +specific_ss.add(when: 'CONFIG_LANCE', if_true: files('lance.c')) system_ss.add(when: 'CONFIG_LASI_82596', if_true: files('lasi_i82596.c')) system_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c')) system_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c'))
include/hw/net/lance.h +3 -0
@@ -31,6 +31,7 @@#include "net/net.h" #include "hw/net/pcnet.h" +#include "system/memory.h" #include "hw/core/sysbus.h" #include "qom/object.h"
@@ -43,6 +44,8 @@ struct SysBusPCNetState {SysBusDevice parent_obj;PCNetState state; +MemoryRegion *dma_mr; + AddressSpace dma_as; };#endif
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 3/7 hw/char/escc: Expose diagnostic RS232 I/O routing
In reply to 54weaselsThis adds proper initialization and routing hooks for the ESCC serial controller to support the specific diagnostic RS232 UART mappings expected by the Sun-3 Boot PROM.
--- hw/char/escc.c | 33 ++++++++++++++++++++++++--------- include/hw/char/escc.h | 3 +++ 2 files changed, 27 insertions(+), 9 deletions(-)
hw/char/escc.c +24 -9
@@ -313,7 +313,8 @@ static void escc_soft_reset_chn(ESCCChannelState *s) s->rregs[R_STATUS ] &=STATUS_DCD |STATUS_SYNC |STATUS_CTS |STATUS_BRK ; s->rregs[R_STATUS ] |=STATUS_TXEMPTY |STATUS_TXUNDRN ; -if (s->disabled) { +if (s->disabled || s->parent->force_hw_ready) { +/* Force assert to satisfy Sun-3 PROM Flow Control */ s->rregs[R_STATUS ] |=STATUS_DCD |STATUS_SYNC |STATUS_CTS ; } s->rregs[R_SPEC ] &=SPEC_ALLSENT ;
@@ -653,7 +654,8 @@ static void escc_mem_write(void *opaque, hwaddr addr, s->txint =0 ;escc_update_irq (s); s->tx = val; -if (s->wregs[W_TXCTRL2 ] &TXCTRL2_TXEN ) {/* tx enabled */ +if (s->parent->force_hw_ready || (s->wregs[W_TXCTRL2 ] &TXCTRL2_TXEN )) { +/* tx consistently forced enabled for Sun-3 boot PROM hooks */ if (s->wregs[W_MISC2 ] &MISC2_LCL_LOOP ) {serial_receive_byte (s, s->tx); }else if (qemu_chr_fe_backend_connected (&s->chr)) {
@@ -691,6 +693,12 @@ static uint64_t escc_mem_read(void *opaque, hwaddr addr,case SERIAL_CTRL :trace_escc_mem_readb_ctrl (CHN_C (s), s->reg, s->rregs[s->reg]); ret = s->rregs[s->reg]; +if (s->reg ==R_STATUS ) { +if (serial->force_hw_ready) { + ret |=STATUS_DCD |STATUS_SYNC |STATUS_CTS ; +/* Force Flow Control PINs */ + } + } s->reg =0 ;return ret;case SERIAL_DATA :
@@ -715,6 +723,10 @@ static const MemoryRegionOps escc_mem_ops = { .write = escc_mem_write, .endianness = DEVICE_NATIVE_ENDIAN, .valid = { + .min_access_size = 1, + .max_access_size =4 , + }, + .impl = { .min_access_size =1 , .max_access_size = 1, },
@@ -1067,16 +1079,17 @@ static void escc_realize(DeviceState *dev, Error **errp) s->chn[0 ].disabled = s->disabled; s->chn[1 ].disabled = s->disabled; +uint32_t escc_size = s->mmio_size ? s->mmio_size :\ + (ESCC_SIZE << s->it_shift);memory_region_init_io (&s->mmio,OBJECT (dev), &escc_mem_ops, s,"escc" , -ESCC_SIZE << s->it_shift); + escc_size);for (i =0 ; i <2 ; i++) { -if (qemu_chr_fe_backend_connected (&s->chn[i].chr)) { - s->chn[i].clock = s->frequency /2 ; -qemu_chr_fe_set_handlers (&s->chn[i].chr, serial_can_receive, - serial_receive1, serial_event,NULL , - &s->chn[i],NULL , true); - } + s->chn[i].parent = s; + s->chn[i].clock = s->frequency /2 ; +qemu_chr_fe_set_handlers (&s->chn[i].chr, serial_can_receive, + serial_receive1, serial_event,NULL , + &s->chn[i],NULL , true); }if (s->chn[0 ].type == escc_mouse) {
@@ -1093,7 +1106,9 @@ static const Property escc_properties[] = {DEFINE_PROP_UINT32 ("frequency" , ESCCState, frequency,0 ),DEFINE_PROP_UINT32 ("it_shift" , ESCCState, it_shift,0 ),DEFINE_PROP_BOOL ("bit_swap" , ESCCState, bit_swap, false), +DEFINE_PROP_BOOL ("force-hw-ready" , ESCCState, force_hw_ready, false),DEFINE_PROP_UINT32 ("disabled" , ESCCState, disabled,0 ), +DEFINE_PROP_UINT32 ("mmio_size" , ESCCState, mmio_size,0 ),DEFINE_PROP_UINT32 ("chnBtype" , ESCCState, chn[0 ].type,0 ),DEFINE_PROP_UINT32 ("chnAtype" , ESCCState, chn[1 ].type,0 ), DEFINE_PROP_CHR("chrB", ESCCState, chn[0].chr),
include/hw/char/escc.h +3 -0
@@ -49,6 +49,7 @@ typedef struct ESCCChannelState {int sunmouse_dx;int sunmouse_dy;int sunmouse_buttons; +ESCCState *parent; } ESCCChannelState;struct ESCCState {
@@ -57,9 +58,11 @@ struct ESCCState {struct ESCCChannelState chn[2 ];uint32_t it_shift;bool bit_swap; +bool force_hw_ready;MemoryRegion mmio;uint32_t disabled;uint32_t frequency; + uint32_t mmio_size; };#endif
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 4/7 hw/timer: Introduce Intersil 7170 RTC implementation
In reply to 54weaselsThis adds the Intersil 7170 Time-of-Day clock / CMOS RAM chip. It implements the register map, alarm interrupt logic, and persistent 32-byte battery-backed NVRAM used by the Sun-3 architecture for storing the MAC address, EEPROM checksums, and boot parameters.
--- hw/timer/Kconfig | 3 + hw/timer/intersil7170.c | 216 ++++++++++++++++++++++++++++++++ hw/timer/meson.build | 1 + include/hw/timer/intersil7170.h | 9 ++ 4 files changed, 229 insertions(+) create mode 100644 hw/timer/intersil7170.c create mode 100644 include/hw/timer/intersil7170.h
hw/timer/Kconfig +3 -0
@@ -65,3 +65,6 @@ config STELLARIS_GPTM config AVR_TIMER16 bool + +config INTERSIL7170 + bool
hw/timer/intersil7170.c new file +216 -0
216 lines not on this page · raw message
hw/timer/meson.build +1 -0
@@ -15,6 +15,7 @@ system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_pwm.c')) system_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_gptimer.c')) system_ss.add(when: 'CONFIG_HPET_C', if_true: files('hpet.c')) system_ss.add(when: 'CONFIG_I8254', if_true: files('i8254_common.c', 'i8254.c')) +system_ss.add(when: 'CONFIG_INTERSIL7170', if_true: files('intersil7170.c')) system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_epit.c')) system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpt.c')) system_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gictimer.c'))
include/hw/timer/intersil7170.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef HW_TIMER_INTERSIL7170_H +#define HW_TIMER_INTERSIL7170_H + +#define TYPE_INTERSIL_7170 "intersil7170" + +typedef struct Intersil7170State Intersil7170State ; + +#endif
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 5/7 hw/m68k: Overhaul Sun-3 MMU and Boot PROM mapping
In reply to 54weaselsThis heavily refactors the Sun-3 machine initialization to support its proprietary Custom MMU implementation, which replaces the standard Motorola 68851 MMU. It maps the diagnostic EEPROM, sets the correct 28-bit address bus masks, implements the OBIO aliasing rules for the Boot PROM, and connects the newly added LANCE, ESCC, and Intersil 7170 peripherals.
--- hw/m68k/Kconfig | 8 + hw/m68k/meson.build | 1 + hw/m68k/sun3.c | 499 ++++++++++++++++++++++++++ hw/m68k/sun3_eeprom_data.h | 259 ++++++++++++++ hw/m68k/sun3mmu.c | 705 +++++++++++++++++++++++++++++++++++++ include/hw/m68k/sun3mmu.h | 65 ++++ 6 files changed, 1537 insertions(+) create mode 100644 hw/m68k/sun3.c create mode 100644 hw/m68k/sun3_eeprom_data.h create mode 100644 hw/m68k/sun3mmu.c create mode 100644 include/hw/m68k/sun3mmu.h
hw/m68k/Kconfig +8 -0
@@ -46,3 +46,11 @@ config M68K_VIRT select GOLDFISH_TTY select GOLDFISH_RTC select VIRTIO_MMIO + +config SUN3 + bool + default y + depends on M68K + select ESCC + select LANCE + select INTERSIL7170
hw/m68k/meson.build +1 -0
@@ -3,6 +3,7 @@ m68k_ss.add(when: 'CONFIG_AN5206', if_true: files('an5206.c', 'mcf5206.c')) m68k_ss.add(when: 'CONFIG_MCF5208', if_true: files('mcf5208.c', 'mcf_intc.c')) m68k_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('next-kbd.c', 'next-cube.c')) m68k_ss.add(when: 'CONFIG_Q800', if_true: files('q800.c', 'q800-glue.c')) +m68k_ss.add(when: 'CONFIG_SUN3', if_true: files('sun3.c', 'sun3mmu.c')) m68k_ss.add(when: 'CONFIG_M68K_VIRT', if_true: files('virt.c')) hw_arch += {'m68k': m68k_ss}
hw/m68k/sun3.c new file +499 -0
499 lines not on this page · raw message
hw/m68k/sun3_eeprom_data.h new file +259 -0
259 lines not on this page · raw message
hw/m68k/sun3mmu.c new file +705 -0
705 lines not on this page · raw message
include/hw/m68k/sun3mmu.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 6/7 tests/qtest: Add Sun-3 hardware interaction tests
In reply to 54weaselsThis adds basic architectural and register validation for the newly assembled Sun-3 machine.
--- tests/qtest/meson.build | 1 + tests/qtest/sun3-test.c | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/qtest/sun3-test.c
tests/qtest/meson.build +1 -0
@@ -154,6 +154,7 @@ qtests_loongarch64 = qtests_filter + \ 'cpu-plug-test'] qtests_m68k = ['boot-serial-test'] + \ + ['sun3-test'] + \ qtests_filter qtests_microblaze = ['boot-serial-test'] + \
tests/qtest/sun3-test.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 7/7 tests/functional: Add Sun-3 firmware boot and diagnostic test
In reply to 54weaselsThis adds an integration test that downloads the Sun-3/60 Boot PROM, initializes the machine, and ensures the self-test successfully routes to TTY A.
--- tests/functional/m68k/meson.build | 1 + tests/functional/m68k/test_sun3.py | 34 +++++++++++++++++++++++++++++ tests/functional/qemu_test/asset.py | 11 +++++----- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 tests/functional/m68k/test_sun3.py
tests/functional/m68k/meson.build +1 -0
@@ -9,5 +9,6 @@ tests_m68k_system_thorough = [ 'nextcube', 'replay', 'q800', + 'sun3', 'tuxrun', ]
tests/functional/m68k/test_sun3.py new file +34 -0
@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +#!/usr/bin/env python3 +# +# Functional test that boots a Sun-3 machine and checks its serial console. +# +# Copyright (c) 2026 +# + + +import os +from qemu_test import QemuSystemTest, Asset +from qemu_test import wait_for_console_pattern + +class Sun3Machine(QemuSystemTest): + timeout = 60 + + ASSET_PROM = Asset( + 'https://github.com/54weasels/sun3_60/raw/main/bootprom/boot_1810_01.BIN', + '471bf34cc9313814726c2e3506d85a13291603e37b45aaffa71bc1154a2d4851' + ) + + def test_m68k_sun3_boot(self): + self.set_machine('sun3') + prom_path = self.ASSET_PROM.fetch() + + # Sun-3 maps TTY A to serial_hd(3) + self.vm.set_console(console_index=3) + self.vm.add_args('-bios', prom_path) + self.vm.launch() + + wait_for_console_pattern(self, '>') + +if __name__ == '__main__': + QemuSystemTest.main()
tests/functional/qemu_test/asset.py +6 -5
@@ -223,11 +223,12 @@ def fetch(self): raise AssetError(self, "Download retries exceeded", transient=True) try: - # Set these just for informational purposes - os.setxattr(str(tmp_cache_file), "user.qemu-asset-url", - self.url.encode('utf8')) - os.setxattr(str(tmp_cache_file), "user.qemu-asset-hash", - self.hash.encode('utf8')) + if hasattr(os, 'setxattr'): + # Set these just for informational purposes + os.setxattr(str(tmp_cache_file), "user.qemu-asset-url", + self.url.encode('utf8')) + os.setxattr(str(tmp_cache_file), "user.qemu-asset-hash", + self.hash.encode('utf8')) except OSError as e: self.log.debug("Unable to set xattr on %s: %s", tmp_cache_file, e)
Signature · 1 line
2.50.1 (Apple Git-155)