@samitouri / QOSamiQemu / commits / a84e627c5f

target/i386: Convert to translate_for_debug

The get_phys_addr_attrs_debug method of SysemuCPUOps is used only by x86 and microblaze. Convert x86 to the newer translate_for_debug method, as a step towards being able to remove get_phys_addr_attrs_debug. The new API allows us to tell the caller the actual size of the mapping via lg_page_size, so we do that, although no caller will care since it's always at least TARGET_PAGE_BITS. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260528161450.3564396-3-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Peter Maydell committed May 28, 2026 at 17:14 UTC a84e627c5f352b7faf1930ba18221d8eef1893c8
4 files changed +21 -18
target/i386/cpu.c
+1 -1
@@ -10877,7 +10877,7 @@ static const struct SysemuCPUOps i386_sysemu_ops = {
10877 .has_work = x86_cpu_has_work,
10878 .get_memory_mapping = x86_cpu_get_memory_mapping,
10879 .get_paging_enabled = x86_cpu_get_paging_enabled,
10880 - .get_phys_addr_attrs_debug = x86_cpu_get_phys_addr_attrs_debug,
10880 + .translate_for_debug = x86_cpu_translate_for_debug,
10881 .asidx_from_attrs = x86_asidx_from_attrs,
10882 .get_crash_info = x86_cpu_get_crash_info,
10883 .write_elf32_note = x86_cpu_write_elf32_note,
target/i386/cpu.h
+2 -2
@@ -2581,8 +2581,8 @@ int cpu_x86_support_mca_broadcast(CPUX86State *env);
2581 #ifndef CONFIG_USER_ONLY
2582 int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request);
2583
2584 -hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cpu, vaddr addr,
2585 - MemTxAttrs *attrs);
2584 +bool x86_cpu_translate_for_debug(CPUState *cpu, vaddr addr,
2585 + TranslateForDebugResult *result);
2586 int cpu_get_pic_interrupt(CPUX86State *s);
2587
2588 /* MS-DOS compatibility mode FPU exception support */
target/i386/helper.c
+17 -14
@@ -252,8 +252,8 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
252 }
253
254 #if !defined(CONFIG_USER_ONLY)
255 -hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
256 - MemTxAttrs *attrs)
255 +bool x86_cpu_translate_for_debug(CPUState *cs, vaddr addr,
256 + TranslateForDebugResult *result)
257 {
258 X86CPU *cpu = X86_CPU(cs);
259 CPUX86State *env = &cpu->env;
@@ -263,8 +263,6 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
263 uint32_t page_offset;
264 int page_size;
265
266 - *attrs = cpu_get_mem_attrs(env);
267 -
266 a20_mask = x86_get_a20_mask(env);
267 if (!(env->cr[0] & CR0_PG_MASK)) {
268 pte = addr & a20_mask;
@@ -283,7 +281,7 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
281 /* test virtual address sign extension */
282 sext = la57 ? (int64_t)addr >> 56 : (int64_t)addr >> 47;
283 if (sext != 0 && sext != -1) {
286 - return -1;
284 + return false;
285 }
286
287 if (la57) {
@@ -291,7 +289,7 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
289 (((addr >> 48) & 0x1ff) << 3)) & a20_mask;
290 pml5e = x86_ldq_phys(cs, pml5e_addr);
291 if (!(pml5e & PG_PRESENT_MASK)) {
294 - return -1;
292 + return false;
293 }
294 } else {
295 pml5e = env->cr[3];
@@ -301,13 +299,13 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
299 (((addr >> 39) & 0x1ff) << 3)) & a20_mask;
300 pml4e = x86_ldq_phys(cs, pml4e_addr);
301 if (!(pml4e & PG_PRESENT_MASK)) {
304 - return -1;
302 + return false;
303 }
304 pdpe_addr = ((pml4e & PG_ADDRESS_MASK) +
305 (((addr >> 30) & 0x1ff) << 3)) & a20_mask;
306 pdpe = x86_ldq_phys(cs, pdpe_addr);
307 if (!(pdpe & PG_PRESENT_MASK)) {
310 - return -1;
308 + return false;
309 }
310 if (pdpe & PG_PSE_MASK) {
311 page_size = 1024 * 1024 * 1024;
@@ -322,14 +320,14 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
320 a20_mask;
321 pdpe = x86_ldq_phys(cs, pdpe_addr);
322 if (!(pdpe & PG_PRESENT_MASK))
325 - return -1;
323 + return false;
324 }
325
326 pde_addr = ((pdpe & PG_ADDRESS_MASK) +
327 (((addr >> 21) & 0x1ff) << 3)) & a20_mask;
328 pde = x86_ldq_phys(cs, pde_addr);
329 if (!(pde & PG_PRESENT_MASK)) {
332 - return -1;
330 + return false;
331 }
332 if (pde & PG_PSE_MASK) {
333 /* 2 MB page */
@@ -343,7 +341,7 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
341 pte = x86_ldq_phys(cs, pte_addr);
342 }
343 if (!(pte & PG_PRESENT_MASK)) {
346 - return -1;
344 + return false;
345 }
346 } else {
347 uint32_t pde;
@@ -352,7 +350,7 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
350 pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & a20_mask;
351 pde = x86_ldl_phys(cs, pde_addr);
352 if (!(pde & PG_PRESENT_MASK))
355 - return -1;
353 + return false;
354 if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
355 pte = pde | ((pde & 0x1fe000LL) << (32 - 13));
356 page_size = 4096 * 1024;
@@ -361,7 +359,7 @@ hwaddr x86_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
359 pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & a20_mask;
360 pte = x86_ldl_phys(cs, pte_addr);
361 if (!(pte & PG_PRESENT_MASK)) {
364 - return -1;
362 + return false;
363 }
364 page_size = 4096;
365 }
@@ -373,7 +371,12 @@ out:
371 #endif
372 pte &= PG_ADDRESS_MASK & ~(page_size - 1);
373 page_offset = addr & (page_size - 1);
376 - return pte | page_offset;
374 +
375 + result->attrs = cpu_get_mem_attrs(env);
376 + result->attrs.debug = 1;
377 + result->physaddr = pte | page_offset;
378 + result->lg_page_size = ctz64(page_size);
379 + return true;
380 }
381
382 typedef struct MCEInjectionParams {
target/i386/whpx/whpx-all.c
+1 -1
@@ -247,7 +247,7 @@ struct whpx_register_set {
247 * e. Let the affected CPU run in the exclusive mode.
248 * f. Restore the original handler and the exception exit bitmap.
249 * Note that handling all corner cases related to IDT/GDT is harder
250 - * than it may seem. See x86_cpu_get_phys_addr_attrs_debug() for a
250 + * than it may seem. See x86_cpu_translate_for_debug() for a
251 * rough idea.
252 *
253 * 3. In order to properly support guest-level debugging in parallel with