All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user/hppa: Detect glibc ABORT_INSTRUCTION and EXCP_BREAK handler
@ 2022-10-27  6:58 Helge Deller
  2022-11-02 16:14 ` Laurent Vivier
  0 siblings, 1 reply; 2+ messages in thread
From: Helge Deller @ 2022-10-27  6:58 UTC (permalink / raw)
  To: Laurent Vivier, Richard Henderson, qemu-devel

The glibc on the hppa platform uses the "iitlbp %r0,(%sr0, %r0)"
assembler instruction as ABORT_INSTRUCTION.
If this (in userspace context) illegal assembler statement is found,
dump the registers and report the failure to userspace the same way as
the Linux kernel on physical hardware.

For other illegal instructions report TARGET_ILL_ILLOPC instead of
TARGET_ILL_ILLOPN as si_code.

Additionally add the missing EXCP_BREAK exception handler which occurs
when the "break x,y" assembler instruction is executed and report
EXCP_ASSIST traps.

Signed-off-by: Helge Deller <deller@gmx.de>

diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index 98c51e9b8b..a42c34e549 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -196,15 +196,20 @@ void cpu_loop(CPUHPPAState *env)
             force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
             break;
         case EXCP_ILL:
-            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
-            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
+            EXCP_DUMP(env, "qemu: EXCP_ILL exception %#x\n", trapnr);
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->iaoq_f);
             break;
         case EXCP_PRIV_OPR:
-            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
-            force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
+            /* check for glibc ABORT_INSTRUCTION "iitlbp %r0,(%sr0, %r0)" */
+            EXCP_DUMP(env, "qemu: EXCP_PRIV_OPR exception %#x\n", trapnr);
+            if (env->cr[CR_IIR] == 0x04000000) {
+		    force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->iaoq_f);
+            } else {
+		    force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
+            }
             break;
         case EXCP_PRIV_REG:
-            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
+            EXCP_DUMP(env, "qemu: EXCP_PRIV_REG exception %#x\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVREG, env->iaoq_f);
             break;
         case EXCP_OVERFLOW:
@@ -216,6 +221,10 @@ void cpu_loop(CPUHPPAState *env)
         case EXCP_ASSIST:
             force_sig_fault(TARGET_SIGFPE, 0, env->iaoq_f);
             break;
+        case EXCP_BREAK:
+            EXCP_DUMP(env, "qemu: EXCP_BREAK exception %#x\n", trapnr);
+            force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->iaoq_f & ~3);
+            break;
         case EXCP_DEBUG:
             force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->iaoq_f);
             break;


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] linux-user/hppa: Detect glibc ABORT_INSTRUCTION and EXCP_BREAK handler
  2022-10-27  6:58 [PATCH] linux-user/hppa: Detect glibc ABORT_INSTRUCTION and EXCP_BREAK handler Helge Deller
@ 2022-11-02 16:14 ` Laurent Vivier
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Vivier @ 2022-11-02 16:14 UTC (permalink / raw)
  To: Helge Deller, Richard Henderson, qemu-devel

Le 27/10/2022 à 08:58, Helge Deller a écrit :
> The glibc on the hppa platform uses the "iitlbp %r0,(%sr0, %r0)"
> assembler instruction as ABORT_INSTRUCTION.
> If this (in userspace context) illegal assembler statement is found,
> dump the registers and report the failure to userspace the same way as
> the Linux kernel on physical hardware.
> 
> For other illegal instructions report TARGET_ILL_ILLOPC instead of
> TARGET_ILL_ILLOPN as si_code.
> 
> Additionally add the missing EXCP_BREAK exception handler which occurs
> when the "break x,y" assembler instruction is executed and report
> EXCP_ASSIST traps.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> 
> diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
> index 98c51e9b8b..a42c34e549 100644
> --- a/linux-user/hppa/cpu_loop.c
> +++ b/linux-user/hppa/cpu_loop.c
> @@ -196,15 +196,20 @@ void cpu_loop(CPUHPPAState *env)
>               force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
>               break;
>           case EXCP_ILL:
> -            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
> -            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
> +            EXCP_DUMP(env, "qemu: EXCP_ILL exception %#x\n", trapnr);
> +            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->iaoq_f);
>               break;
>           case EXCP_PRIV_OPR:
> -            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
> -            force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
> +            /* check for glibc ABORT_INSTRUCTION "iitlbp %r0,(%sr0, %r0)" */
> +            EXCP_DUMP(env, "qemu: EXCP_PRIV_OPR exception %#x\n", trapnr);
> +            if (env->cr[CR_IIR] == 0x04000000) {
> +		    force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->iaoq_f);
> +            } else {
> +		    force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
> +            }
>               break;
>           case EXCP_PRIV_REG:
> -            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
> +            EXCP_DUMP(env, "qemu: EXCP_PRIV_REG exception %#x\n", trapnr);
>               force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVREG, env->iaoq_f);
>               break;
>           case EXCP_OVERFLOW:
> @@ -216,6 +221,10 @@ void cpu_loop(CPUHPPAState *env)
>           case EXCP_ASSIST:
>               force_sig_fault(TARGET_SIGFPE, 0, env->iaoq_f);
>               break;
> +        case EXCP_BREAK:
> +            EXCP_DUMP(env, "qemu: EXCP_BREAK exception %#x\n", trapnr);
> +            force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->iaoq_f & ~3);
> +            break;
>           case EXCP_DEBUG:
>               force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->iaoq_f);
>               break;
> 

Applied to my linux-user-for-7.2 branch.

Thanks,
Laurent




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-02 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27  6:58 [PATCH] linux-user/hppa: Detect glibc ABORT_INSTRUCTION and EXCP_BREAK handler Helge Deller
2022-11-02 16:14 ` Laurent Vivier

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.