From: 54weasels <54weasels@gmail.com>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu, 54weasels <54weasels@gmail.com>
Subject: [PATCH v4 5/6] target/m68k: Implement custom MMU intercept hook
Date: Mon, 17 Aug 2026 19:22:21 -0700 [thread overview]
Message-ID: <20260818022225.31801-6-54weasels@gmail.com> (raw)
In-Reply-To: <20260818022225.31801-1-54weasels@gmail.com>
High 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/20260503015756.99176-1-54weasels@gmail.com/) and has been split into atomic components.
---
target/m68k/cpu.h | 7 ++++
target/m68k/helper.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index 42d34502fc..d4ecb1c3ef 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -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;
diff --git a/target/m68k/helper.c b/target/m68k/helper.c
index f3ee95441a..1eef6dcaaf 100644
--- a/target/m68k/helper.c
+++ b/target/m68k/helper.c
@@ -920,6 +920,21 @@ hwaddr m68k_cpu_get_phys_addr_debug(CPUState *cs, vaddr addr)
int access_type;
target_ulong page_size;
+ access_type = ACCESS_DATA | ACCESS_DEBUG;
+ if (env->sr & SR_S) {
+ access_type |= ACCESS_SUPER;
+ }
+
+ if (env->custom_mmu_get_physical_address) {
+ hwaddr custom_page_size;
+ if (env->custom_mmu_get_physical_address(env, &phys_addr, &prot, addr,
+ access_type,
+ &custom_page_size) == 0) {
+ return phys_addr;
+ }
+ return -1;
+ }
+
if ((env->mmu.tcr & M68K_TCR_ENABLED) == 0) {
/* MMU disabled */
return addr;
@@ -1001,6 +1016,80 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
}
}
+ if (env->custom_mmu_get_physical_address) {
+ hwaddr custom_page_size;
+
+ /* Delegate translation to external board-specific MMU if registered */
+ ret = env->custom_mmu_get_physical_address(env, &physical, &prot,
+ address, access_type,
+ &custom_page_size);
+
+ if (likely(ret == 0)) {
+ tlb_set_page(cs, address & TARGET_PAGE_MASK,
+ physical & TARGET_PAGE_MASK, prot,
+ mmu_idx, custom_page_size);
+ return true;
+ }
+
+ if (probe) {
+ return false;
+ }
+
+ /* page fault */
+ cs->exception_index = EXCP_ACCESS;
+ env->mmu.ar = address;
+
+ if (m68k_feature(env, M68K_FEATURE_M68040)) {
+ env->mmu.ssw = M68K_ATC_040;
+ switch (size) {
+ case 1:
+ env->mmu.ssw |= M68K_BA_SIZE_BYTE;
+ break;
+ case 2:
+ env->mmu.ssw |= M68K_BA_SIZE_WORD;
+ break;
+ case 4:
+ env->mmu.ssw |= M68K_BA_SIZE_LONG;
+ break;
+ }
+ env->mmu.ssw |= M68K_TM_040_DATA;
+ } else {
+ /* M68020/030 Special Status Word (SSW) */
+ uint16_t ssw = 0x0100; /* DF - Data Fault */
+ switch (size) {
+ case 1:
+ ssw |= 0x0010;
+ break;
+ case 2:
+ ssw |= 0x0020;
+ break;
+ case 3:
+ ssw |= 0x0030;
+ break;
+ case 4:
+ ssw |= 0x0000;
+ break;
+ }
+ if (qemu_access_type != MMU_DATA_STORE) {
+ ssw |= 0x0040; /* RW - Read */
+ }
+ /* Function Code */
+ uint8_t fc;
+ if (mmu_idx >= MMU_MOVES_FC_BASE) {
+ fc = mmu_idx - MMU_MOVES_FC_BASE;
+ } else {
+ if (mmu_idx == MMU_KERNEL_IDX) {
+ fc = (qemu_access_type == MMU_INST_FETCH) ? 6 : 5;
+ } else {
+ fc = (qemu_access_type == MMU_INST_FETCH) ? 2 : 1;
+ }
+ }
+ ssw |= (fc & 7);
+ env->mmu.ssw = ssw;
+ }
+ cpu_loop_exit_restore(cs, retaddr);
+ }
+
if ((env->mmu.tcr & M68K_TCR_ENABLED) == 0) {
/* MMU disabled */
tlb_set_page(cs, address & TARGET_PAGE_MASK,
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-08-18 2:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 2:22 [PATCH v4 0/6] Implement missing functionality and hooks in mk68k to support upcoming sun3 impl 54weasels
2026-08-18 2:22 ` [PATCH v4 1/6] target/m68k: Add dummy CAAR register 54weasels
2026-08-18 2:22 ` [PATCH v4 2/6] target/m68k: Fix fsave/frestore for 68881 FPU 54weasels
2026-08-18 10:52 ` BALATON Zoltan
2026-08-20 4:37 ` Purr Box
2026-08-20 9:55 ` BALATON Zoltan
2026-08-18 2:22 ` [PATCH v4 3/6] target/m68k: Fix NMI pending for Level 7 interrupts 54weasels
2026-08-18 10:56 ` BALATON Zoltan
2026-08-20 7:37 ` Purr Box
2026-08-18 2:22 ` [PATCH v4 4/6] target/m68k: Extract Function Codes during TLB fills 54weasels
2026-08-18 2:22 ` 54weasels [this message]
2026-08-18 2:22 ` [PATCH v4 6/6] target/m68k: Implement Physical Bus Error and Stack 54weasels
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818022225.31801-6-54weasels@gmail.com \
--to=54weasels@gmail.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.