@samitouri / QOSamiQemu / commits / 2b581da051

target/hppa: Define PA[20|1X] physical address space size

When converting virtual to physical addresses, TARGET_PHYS_ADDR_SPACE_BITS is used under PA-RISC 2.0, and an explicit cast to uint32_t is used under PA-RISC 1.X. Replace the former with a more specific macro limited to mem_helper.c, and make the latter conversion explicit by defining the size of the physical address space for PA-RISC 1.X. Note: while 44 bits should be used for the 64-bit address space running a C3700, 40 bits is still chosen as this is expected by the SeaBIOS functional test. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Anton Johansson <anjo@rev.ng> Message-ID: <20260218-phys_addr-v6-1-a603bf363218@rev.ng> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Anton Johansson committed Dec 9, 2025 at 14:56 UTC 2b581da051094468706b86806629067ef49937de
2 files changed +28 -5
target/hppa/cpu.h
+1
@@ -336,6 +336,7 @@ static inline vaddr hppa_form_gva(CPUHPPAState *env, uint64_t spc,
336 return hppa_form_gva_mask(env->gva_offset_mask, spc, off);
337 }
338
339 +hwaddr hppa_abs_to_phys_pa1x(vaddr addr);
340 hwaddr hppa_abs_to_phys_pa2_w0(vaddr addr);
341 hwaddr hppa_abs_to_phys_pa2_w1(vaddr addr);
342
target/hppa/mem_helper.c
+27 -5
@@ -29,6 +29,28 @@
29 #include "hw/core/cpu.h"
30 #include "trace.h"
31
32 +/*
33 + * 64-bit (PA-RISC 2.0) machines are assumed to run PA-8700, and 32-bit
34 + * machines 7300LC. This should give 44 and 32 bits of physical address
35 + * space respectively.
36 + *
37 + * CPU model Physical address space bits
38 + * PA-7000--7300LC 32
39 + * PA-8000--8600 40
40 + * PA-8700--8900 44
41 + *
42 + * FIXME: However, the SeaBIOS firmware that is that tested against
43 + * uses 40-bit physical addresses, despite supposedly running a C3700
44 + * with a PA-8700 cpu, so use 40-bits for 64-bit.
45 + */
46 +#define HPPA_PHYS_ADDR_SPACE_BITS_PA20 40
47 +#define HPPA_PHYS_ADDR_SPACE_BITS_PA1X 32
48 +
49 +hwaddr hppa_abs_to_phys_pa1x(vaddr addr)
50 +{
51 + return extract64(addr, 0, HPPA_PHYS_ADDR_SPACE_BITS_PA1X);
52 +}
53 +
54 hwaddr hppa_abs_to_phys_pa2_w1(vaddr addr)
55 {
56 /*
@@ -42,8 +64,8 @@ hwaddr hppa_abs_to_phys_pa2_w1(vaddr addr)
64 * Since the supported physical address space is below 54 bits, the
65 * H-8 algorithm is moot and all that is left is to truncate.
66 */
45 - QEMU_BUILD_BUG_ON(TARGET_PHYS_ADDR_SPACE_BITS > 54);
46 - return sextract64(addr, 0, TARGET_PHYS_ADDR_SPACE_BITS);
67 + QEMU_BUILD_BUG_ON(HPPA_PHYS_ADDR_SPACE_BITS_PA20 > 54);
68 + return sextract64(addr, 0, HPPA_PHYS_ADDR_SPACE_BITS_PA20);
69 }
70
71 hwaddr hppa_abs_to_phys_pa2_w0(vaddr addr)
@@ -67,7 +89,7 @@ hwaddr hppa_abs_to_phys_pa2_w0(vaddr addr)
89 * is what can be seen on physical machines too.
90 */
91 addr = (uint32_t)addr;
70 - addr |= -1ull << (TARGET_PHYS_ADDR_SPACE_BITS - 4);
92 + addr |= -1ull << (HPPA_PHYS_ADDR_SPACE_BITS_PA20 - 4);
93 }
94 return addr;
95 }
@@ -217,7 +239,7 @@ int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx,
239 if (hppa_is_pa20(env)) {
240 phys = hppa_abs_to_phys_pa2_w0(addr);
241 } else {
220 - phys = (uint32_t)addr;
242 + phys = hppa_abs_to_phys_pa1x(addr);
243 }
244 break;
245 default:
@@ -558,7 +580,7 @@ static void itlbt_pa20(CPUHPPAState *env, target_ulong r1,
580 /* Align per the page size. */
581 ent->pa &= TARGET_PAGE_MASK << mask_shift;
582 /* Ignore the bits beyond physical address space. */
561 - ent->pa = sextract64(ent->pa, 0, TARGET_PHYS_ADDR_SPACE_BITS);
583 + ent->pa = sextract64(ent->pa, 0, HPPA_PHYS_ADDR_SPACE_BITS_PA20);
584
585 ent->t = extract64(r2, 61, 1);
586 ent->d = extract64(r2, 60, 1);