From a9bdc4c95e402599e4184d4814800668479adb2b Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Fri, 16 Feb 2024 17:58:11 -0800 Subject: [PATCH 1/5] target: hppa: Fix unaligned double word accesses for hppa64 Unaligned 64-bit accesses were found in Linux to clobber carry bits, resulting in bad results if an arithmetic operation involving a carry bit was executed after an unaligned 64-bit operation. hppa 2.0 defines additional carry bits in PSW register bits 32..39. When restoring PSW after executing an unaligned instruction trap, those bits were not cleared and ended up to be active all the time. Since there are no bits other than the upper carry bits needed in the upper 32 bit of env->psw and since those are stored in env->psw_cb, just clear the entire upper 32 bit when storing psw to solve the problem unconditionally. Fixes: 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64") Cc: Richard Henderson Cc: Charlie Jenkins Cc: Helge Deller Reviewed-by: Richard Henderson Signed-off-by: Guenter Roeck Signed-off-by: Helge Deller --- target/hppa/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/hppa/helper.c b/target/hppa/helper.c index 859644c47a..9d217d051c 100644 --- a/target/hppa/helper.c +++ b/target/hppa/helper.c @@ -76,7 +76,8 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ulong psw) } psw &= ~reserved; - env->psw = psw & ~(PSW_N | PSW_V | PSW_CB); + env->psw = psw & (uint32_t)~(PSW_N | PSW_V | PSW_CB); + env->psw_n = (psw / PSW_N) & 1; env->psw_v = -((psw / PSW_V) & 1); From 5ccd50172a80ef9fe695714744b0747d7419b2c4 Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Sat, 2 Mar 2024 22:02:38 +0100 Subject: [PATCH 2/5] target/hppa: Restore unwind_breg before calculating ior When calculating the IOR for the exception handlers, the current unwind_breg value is needed on 64-bit hppa machines. Restore that value by calling cpu_restore_state() earlier, which in turn calls hppa_restore_state_to_opc() which restores the unwind_breg for the current instruction. Signed-off-by: Helge Deller Fixes: 3824e0d643f3 ("target/hppa: Export function hppa_set_ior_and_isr()") Reviewed-by: Richard Henderson --- target/hppa/cpu.c | 3 ++- target/hppa/mem_helper.c | 3 ++- target/hppa/op_helper.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index afe73d4474..3831cb6db2 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -121,9 +121,10 @@ void hppa_cpu_do_unaligned_access(CPUState *cs, vaddr addr, CPUHPPAState *env = &cpu->env; cs->exception_index = EXCP_UNALIGN; + cpu_restore_state(cs, retaddr); hppa_set_ior_and_isr(env, addr, MMU_IDX_MMU_DISABLED(mmu_idx)); - cpu_loop_exit_restore(cs, retaddr); + cpu_loop_exit(cs); } #endif /* CONFIG_USER_ONLY */ diff --git a/target/hppa/mem_helper.c b/target/hppa/mem_helper.c index 66b8fa7d72..3fc895c1c2 100644 --- a/target/hppa/mem_helper.c +++ b/target/hppa/mem_helper.c @@ -348,9 +348,10 @@ raise_exception_with_ior(CPUHPPAState *env, int excp, uintptr_t retaddr, CPUState *cs = env_cpu(env); cs->exception_index = excp; + cpu_restore_state(cs, retaddr); hppa_set_ior_and_isr(env, addr, mmu_disabled); - cpu_loop_exit_restore(cs, retaddr); + cpu_loop_exit(cs); } void hppa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c index b1f24a5aad..480fe80844 100644 --- a/target/hppa/op_helper.c +++ b/target/hppa/op_helper.c @@ -351,11 +351,12 @@ target_ulong HELPER(probe)(CPUHPPAState *env, target_ulong addr, excp = hppa_get_physical_address(env, addr, mmu_idx, 0, &phys, &prot, NULL); if (excp >= 0) { + cpu_restore_state(env_cpu(env), GETPC()); hppa_set_ior_and_isr(env, addr, MMU_IDX_MMU_DISABLED(mmu_idx)); if (excp == EXCP_DTLB_MISS) { excp = EXCP_NA_DTLB_MISS; } - hppa_dynamic_excp(env, excp, GETPC()); + helper_excp(env, excp); } return (want & prot) != 0; #endif From 19f9c0442ebf28acf96d0e12ab500afbe53c8fa3 Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Sat, 2 Mar 2024 22:27:01 +0100 Subject: [PATCH 3/5] pc-bios/meson: Add hppa-firmware64.img blob Add the missing 64-bit hppa firmware blob so that it gets installed. Signed-off-by: Helge Deller Fixes: 7c0dfcf9395e ("target/hppa: Update SeaBIOS-hppa to version 16") Reviewed-by: Richard Henderson --- pc-bios/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/pc-bios/meson.build b/pc-bios/meson.build index e67fa433a1..0760612bea 100644 --- a/pc-bios/meson.build +++ b/pc-bios/meson.build @@ -73,6 +73,7 @@ blobs = [ 'qemu_vga.ndrv', 'edk2-licenses.txt', 'hppa-firmware.img', + 'hppa-firmware64.img', 'opensbi-riscv32-generic-fw_dynamic.bin', 'opensbi-riscv64-generic-fw_dynamic.bin', 'npcm7xx_bootrom.bin', From 2536c15adcf6232e5f649405db76876620610652 Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Sat, 2 Mar 2024 22:28:04 +0100 Subject: [PATCH 4/5] pc-bios/README: Add information about hppa-firmware Signed-off-by: Helge Deller Reviewed-by: Richard Henderson --- pc-bios/README | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pc-bios/README b/pc-bios/README index b8a0210d24..7ffb2f43a4 100644 --- a/pc-bios/README +++ b/pc-bios/README @@ -75,3 +75,9 @@ initialize and run boot images stored in SPI flash, but may grow more features over time as needed. The source code is available at: https://github.com/google/vbootrom + +- hppa-firmware.img (32-bit) and hppa-firmware64.img (64-bit) are firmware + files for the HP-PARISC (hppa) architecture. + They are built form the SeaBIOS-hppa sources, which is a fork of SeaBIOS + adapted for hppa. + SeaBIOS-hppa is available at https://github.com/hdeller/seabios-hppa From 839a88e8bd1a1efe05844c39a59985482894f4de Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Sat, 2 Mar 2024 22:53:32 +0100 Subject: [PATCH 5/5] roms/hppa: Add build rules for hppa-firmware Signed-off-by: Helge Deller Suggested-by: Michael Tokarev Reviewed-by: Richard Henderson --- roms/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/roms/Makefile b/roms/Makefile index 67f709ba2d..8e5d8d26a9 100644 --- a/roms/Makefile +++ b/roms/Makefile @@ -68,6 +68,7 @@ default help: @echo " opensbi32-generic -- update OpenSBI for 32-bit generic machine" @echo " opensbi64-generic -- update OpenSBI for 64-bit generic machine" @echo " qboot -- update qboot" + @echo " hppa-firmware -- update 32- and 64-bit hppa firmware" @echo " clean -- delete the files generated by the previous" \ "build targets" @@ -177,6 +178,11 @@ npcm7xx_bootrom: $(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix) cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin +hppa-firmware: + $(MAKE) -C seabios-hppa parisc + cp seabios-hppa/out/hppa-firmware.img ../pc-bios/ + cp seabios-hppa/out-64/hppa-firmware64.img ../pc-bios/ + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C ipxe/src veryclean @@ -189,3 +195,4 @@ clean: $(MAKE) -C opensbi clean $(MAKE) -C qboot clean $(MAKE) -C vbootrom clean + $(MAKE) -C seabios-hppa clean