[PATCH v5 14/25] target/openrisc: call plugin trap callbacks

Julian Ganz posted 25 patches 6 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Helge Deller <deller@gmx.de>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Song Gao <gaosong@loongson.cn>, Laurent Vivier <laurent@vivier.eu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Stafford Horne <shorne@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Max Filippov <jcmvbkbc@gmail.com>
There is a newer version of this series
[PATCH v5 14/25] target/openrisc: call plugin trap callbacks
Posted by Julian Ganz 6 months ago
We recently introduced API for registering callbacks for trap related
events as well as the corresponding hook functions. Due to differences
between architectures, the latter need to be called from target specific
code.

This change places hooks for OpenRISC targets. We treat anything other
than resets, timer and device interrupts as exceptions.

Signed-off-by: Julian Ganz <neither@nut.email>
---
 target/openrisc/interrupt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c
index 486823094c..08f0ed9b89 100644
--- a/target/openrisc/interrupt.c
+++ b/target/openrisc/interrupt.c
@@ -25,11 +25,13 @@
 #ifndef CONFIG_USER_ONLY
 #include "hw/loader.h"
 #endif
+#include "qemu/plugin.h"
 
 void openrisc_cpu_do_interrupt(CPUState *cs)
 {
     CPUOpenRISCState *env = cpu_env(cs);
     int exception = cs->exception_index;
+    uint64_t last_pc = env->pc;
 
     env->epcr = env->pc;
 
@@ -98,6 +100,17 @@ void openrisc_cpu_do_interrupt(CPUState *cs)
         cpu_abort(cs, "Unhandled exception 0x%x\n", exception);
     }
 
+    switch (exception) {
+    case EXCP_RESET:
+    case EXCP_TICK:
+    case EXCP_INT:
+        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
+        break;
+    default:
+        qemu_plugin_vcpu_exception_cb(cs, last_pc);
+        break;
+    }
+
     cs->exception_index = -1;
 }
 
-- 
2.49.0
Re: [PATCH v5 14/25] target/openrisc: call plugin trap callbacks
Posted by Richard Henderson 5 months, 3 weeks ago
On 5/19/25 16:19, Julian Ganz wrote:
> We recently introduced API for registering callbacks for trap related
> events as well as the corresponding hook functions. Due to differences
> between architectures, the latter need to be called from target specific
> code.
> 
> This change places hooks for OpenRISC targets. We treat anything other
> than resets, timer and device interrupts as exceptions.
> 
> Signed-off-by: Julian Ganz <neither@nut.email>
> ---
>   target/openrisc/interrupt.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c
> index 486823094c..08f0ed9b89 100644
> --- a/target/openrisc/interrupt.c
> +++ b/target/openrisc/interrupt.c
> @@ -25,11 +25,13 @@
>   #ifndef CONFIG_USER_ONLY
>   #include "hw/loader.h"
>   #endif
> +#include "qemu/plugin.h"
>   
>   void openrisc_cpu_do_interrupt(CPUState *cs)
>   {
>       CPUOpenRISCState *env = cpu_env(cs);
>       int exception = cs->exception_index;
> +    uint64_t last_pc = env->pc;
>   
>       env->epcr = env->pc;
>   
> @@ -98,6 +100,17 @@ void openrisc_cpu_do_interrupt(CPUState *cs)
>           cpu_abort(cs, "Unhandled exception 0x%x\n", exception);
>       }
>   
> +    switch (exception) {
> +    case EXCP_RESET:

There are plenty of other EXCP_RESET uses that aren't marked as interrupt.
Bug?

Anyway, for this patch,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

> +    case EXCP_TICK:
> +    case EXCP_INT:
> +        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> +        break;
> +    default:
> +        qemu_plugin_vcpu_exception_cb(cs, last_pc);
> +        break;
> +    }
> +
>       cs->exception_index = -1;
>   }
>
Re: [PATCH v5 14/25] target/openrisc: call plugin trap callbacks
Posted by Julian Ganz 5 months, 3 weeks ago
Hi Richard,

> On 5/19/25 16:19, Julian Ganz wrote:
> > diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c
> > index 486823094c..08f0ed9b89 100644
> > --- a/target/openrisc/interrupt.c
> > +++ b/target/openrisc/interrupt.c
> > @@ -25,11 +25,13 @@
> >   #ifndef CONFIG_USER_ONLY
> >   #include "hw/loader.h"
> >   #endif
> > +#include "qemu/plugin.h"
> >   
> >   void openrisc_cpu_do_interrupt(CPUState *cs)
> >   {
> >       CPUOpenRISCState *env = cpu_env(cs);
> >       int exception = cs->exception_index;
> > +    uint64_t last_pc = env->pc;
> >   
> >       env->epcr = env->pc;
> >   
> > @@ -98,6 +100,17 @@ void openrisc_cpu_do_interrupt(CPUState *cs)
> >           cpu_abort(cs, "Unhandled exception 0x%x\n", exception);
> >       }
> >   
> > +    switch (exception) {
> > +    case EXCP_RESET:
> 
> There are plenty of other EXCP_RESET uses that aren't marked as interrupt.
> Bug?

Mh... I might not have been perfectly consistent with resets. We do expect
plugins to be notified of resets already, so we probably don't want to trigger
exception or interrupt callbacks.

I'll check and adjust for the next series.

Regards,
Julian