* [PATCH] Trap and Emulate changes @ 2026-02-11 10:00 dave.patel 2026-02-12 14:58 ` Anup Patel 0 siblings, 1 reply; 6+ messages in thread From: dave.patel @ 2026-02-11 10:00 UTC (permalink / raw) To: opensbi Cc: Scott Bambrough, Dave Patel, Ray Mao, Robin Randhawa, Anup Patel, Samuel Holland, Anup Patel, Dhaval, Peter Lin From: Dave Patel <dave.patel@riscstar.com> Signed-off-by: Dave Patel <dave.patel@riscstar.com> --- lib/sbi/sbi_illegal_insn.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index fa82264a..88079e39 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -110,10 +110,33 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) return 0; } +static int sbi_get_emulated_irq_insn(ulong insn, struct sbi_trap_regs *regs) +{ + ulong rs1_val = GET_RS1(insn, regs); + ulong rs2_val = GET_RS2(insn, regs); + //ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); + ulong irq_val; + + /* + // This is were the emualted irq vlaue is fetched + if (prev_mode == PRV_S && sbi_emulate_irq_read(&irq_val)) + return truly_illegal_insn(insn, regs); + */ + + // For testing + irq_val = rs1_val + rs2_val; + + SET_RD(insn, regs, irq_val); + + regs->mepc += 4; + + return 0; +} + static const illegal_insn_func illegal_insn_table[32] = { truly_illegal_insn, /* 0 */ truly_illegal_insn, /* 1 */ - truly_illegal_insn, /* 2 */ + sbi_get_emulated_irq_insn, /* 2 */ misc_mem_opcode_insn, /* 3 */ truly_illegal_insn, /* 4 */ truly_illegal_insn, /* 5 */ -- 2.43.0 -- opensbi mailing list opensbi@lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Trap and Emulate changes 2026-02-11 10:00 [PATCH] Trap and Emulate changes dave.patel @ 2026-02-12 14:58 ` Anup Patel [not found] ` <CAL2H45cQm_O-K-6weC-xeGNB0+yCHjQe1msS+JwHdKLKecM5CA@mail.gmail.com> 0 siblings, 1 reply; 6+ messages in thread From: Anup Patel @ 2026-02-12 14:58 UTC (permalink / raw) To: dave.patel Cc: opensbi, Scott Bambrough, Ray Mao, Robin Randhawa, Anup Patel, Samuel Holland, Anup Patel, Dhaval, Peter Lin On Wed, Feb 11, 2026 at 3:30 PM <dave.patel@riscstar.com> wrote: > > From: Dave Patel <dave.patel@riscstar.com> > > Signed-off-by: Dave Patel <dave.patel@riscstar.com> > --- > lib/sbi/sbi_illegal_insn.c | 25 ++++++++++++++++++++++++- > 1 file changed, 24 insertions(+), 1 deletion(-) > > diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c > index fa82264a..88079e39 100644 > --- a/lib/sbi/sbi_illegal_insn.c > +++ b/lib/sbi/sbi_illegal_insn.c > @@ -110,10 +110,33 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) > return 0; > } > > +static int sbi_get_emulated_irq_insn(ulong insn, struct sbi_trap_regs *regs) > +{ > + ulong rs1_val = GET_RS1(insn, regs); > + ulong rs2_val = GET_RS2(insn, regs); > + //ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); > + ulong irq_val; > + > + /* > + // This is were the emualted irq vlaue is fetched > + if (prev_mode == PRV_S && sbi_emulate_irq_read(&irq_val)) > + return truly_illegal_insn(insn, regs); > + */ > + > + // For testing > + irq_val = rs1_val + rs2_val; > + > + SET_RD(insn, regs, irq_val); > + > + regs->mepc += 4; > + > + return 0; > +} > + > static const illegal_insn_func illegal_insn_table[32] = { > truly_illegal_insn, /* 0 */ > truly_illegal_insn, /* 1 */ > - truly_illegal_insn, /* 2 */ > + sbi_get_emulated_irq_insn, /* 2 */ We can't pick arbitrary instruction encoding for trap-n-emulation of an interrupt controller. If the goal is to trap-n-emulate an MMIO device then use PMP based access faults. Regards Anup -- opensbi mailing list opensbi@lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAL2H45cQm_O-K-6weC-xeGNB0+yCHjQe1msS+JwHdKLKecM5CA@mail.gmail.com>]
* Re: [PATCH] Trap and Emulate changes [not found] ` <CAL2H45cQm_O-K-6weC-xeGNB0+yCHjQe1msS+JwHdKLKecM5CA@mail.gmail.com> @ 2026-02-12 15:40 ` Anup Patel 2026-02-12 16:04 ` Raymond Mao [not found] ` <CAEigVW8cs7=f0xk-QZN2vKTTg-=dU9eoof=RrMHqzj9t8Yi=4Q@mail.gmail.com> 0 siblings, 2 replies; 6+ messages in thread From: Anup Patel @ 2026-02-12 15:40 UTC (permalink / raw) To: Scott Bambrough Cc: dave.patel, opensbi, Ray Mao, Robin Randhawa, Anup Patel, Samuel Holland, Anup Patel, Dhaval, Peter Lin On Thu, Feb 12, 2026 at 8:38 PM Scott Bambrough <scott@riscstar.com> wrote: > > Is PMP universally available? Yes, PMP is not universally available plus we might not have enough PMP regions. Cleaner approach is to use an "ecall" based paravirt interrupt controller. Regards, Anup > Scott > > On Thu, Feb 12, 2026 at 9:58 AM Anup Patel <apatel@ventanamicro.com> wrote: >> >> On Wed, Feb 11, 2026 at 3:30 PM <dave.patel@riscstar.com> wrote: >> > >> > From: Dave Patel <dave.patel@riscstar.com> >> > >> > Signed-off-by: Dave Patel <dave.patel@riscstar.com> >> > --- >> > lib/sbi/sbi_illegal_insn.c | 25 ++++++++++++++++++++++++- >> > 1 file changed, 24 insertions(+), 1 deletion(-) >> > >> > diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c >> > index fa82264a..88079e39 100644 >> > --- a/lib/sbi/sbi_illegal_insn.c >> > +++ b/lib/sbi/sbi_illegal_insn.c >> > @@ -110,10 +110,33 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) >> > return 0; >> > } >> > >> > +static int sbi_get_emulated_irq_insn(ulong insn, struct sbi_trap_regs *regs) >> > +{ >> > + ulong rs1_val = GET_RS1(insn, regs); >> > + ulong rs2_val = GET_RS2(insn, regs); >> > + //ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); >> > + ulong irq_val; >> > + >> > + /* >> > + // This is were the emualted irq vlaue is fetched >> > + if (prev_mode == PRV_S && sbi_emulate_irq_read(&irq_val)) >> > + return truly_illegal_insn(insn, regs); >> > + */ >> > + >> > + // For testing >> > + irq_val = rs1_val + rs2_val; >> > + >> > + SET_RD(insn, regs, irq_val); >> > + >> > + regs->mepc += 4; >> > + >> > + return 0; >> > +} >> > + >> > static const illegal_insn_func illegal_insn_table[32] = { >> > truly_illegal_insn, /* 0 */ >> > truly_illegal_insn, /* 1 */ >> > - truly_illegal_insn, /* 2 */ >> > + sbi_get_emulated_irq_insn, /* 2 */ >> >> We can't pick arbitrary instruction encoding for >> trap-n-emulation of an interrupt controller. >> >> If the goal is to trap-n-emulate an MMIO device >> then use PMP based access faults. >> >> Regards >> Anup -- opensbi mailing list opensbi@lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Trap and Emulate changes 2026-02-12 15:40 ` Anup Patel @ 2026-02-12 16:04 ` Raymond Mao [not found] ` <CAEigVW8cs7=f0xk-QZN2vKTTg-=dU9eoof=RrMHqzj9t8Yi=4Q@mail.gmail.com> 1 sibling, 0 replies; 6+ messages in thread From: Raymond Mao @ 2026-02-12 16:04 UTC (permalink / raw) To: Anup Patel Cc: Scott Bambrough, dave.patel, opensbi, Ray Mao, Robin Randhawa, Anup Patel, Samuel Holland, Anup Patel, Dhaval, Peter Lin Hi Anup, On Thu, Feb 12, 2026 at 10:41 AM Anup Patel <apatel@ventanamicro.com> wrote: > > On Thu, Feb 12, 2026 at 8:38 PM Scott Bambrough <scott@riscstar.com> wrote: > > > > Is PMP universally available? > > Yes, PMP is not universally available plus we might > not have enough PMP regions. > > Cleaner approach is to use an "ecall" based paravirt > interrupt controller. > ecall is already in the plan, bare-metal app will use the ecall to pop an VIRQ from the queue it belongs to. So do you mean to use a trap handler in S-domain to fire the ecall when a MMIO address (simulates CLAIMI) is accessed? But that means the emulation is implemented in the bare-metal app side, and other apps need to integrate the same work. The original idea is to do the emulation in M-mode, so that all S-mode SW can stay unchanged. Regards, Raymond > Regards, > Anup > > > Scott > > > > On Thu, Feb 12, 2026 at 9:58 AM Anup Patel <apatel@ventanamicro.com> wrote: > >> > >> On Wed, Feb 11, 2026 at 3:30 PM <dave.patel@riscstar.com> wrote: > >> > > >> > From: Dave Patel <dave.patel@riscstar.com> > >> > > >> > Signed-off-by: Dave Patel <dave.patel@riscstar.com> > >> > --- > >> > lib/sbi/sbi_illegal_insn.c | 25 ++++++++++++++++++++++++- > >> > 1 file changed, 24 insertions(+), 1 deletion(-) > >> > > >> > diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c > >> > index fa82264a..88079e39 100644 > >> > --- a/lib/sbi/sbi_illegal_insn.c > >> > +++ b/lib/sbi/sbi_illegal_insn.c > >> > @@ -110,10 +110,33 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) > >> > return 0; > >> > } > >> > > >> > +static int sbi_get_emulated_irq_insn(ulong insn, struct sbi_trap_regs *regs) > >> > +{ > >> > + ulong rs1_val = GET_RS1(insn, regs); > >> > + ulong rs2_val = GET_RS2(insn, regs); > >> > + //ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); > >> > + ulong irq_val; > >> > + > >> > + /* > >> > + // This is were the emualted irq vlaue is fetched > >> > + if (prev_mode == PRV_S && sbi_emulate_irq_read(&irq_val)) > >> > + return truly_illegal_insn(insn, regs); > >> > + */ > >> > + > >> > + // For testing > >> > + irq_val = rs1_val + rs2_val; > >> > + > >> > + SET_RD(insn, regs, irq_val); > >> > + > >> > + regs->mepc += 4; > >> > + > >> > + return 0; > >> > +} > >> > + > >> > static const illegal_insn_func illegal_insn_table[32] = { > >> > truly_illegal_insn, /* 0 */ > >> > truly_illegal_insn, /* 1 */ > >> > - truly_illegal_insn, /* 2 */ > >> > + sbi_get_emulated_irq_insn, /* 2 */ > >> > >> We can't pick arbitrary instruction encoding for > >> trap-n-emulation of an interrupt controller. > >> > >> If the goal is to trap-n-emulate an MMIO device > >> then use PMP based access faults. > >> > >> Regards > >> Anup > > -- > opensbi mailing list > opensbi@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/opensbi -- opensbi mailing list opensbi@lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAEigVW8cs7=f0xk-QZN2vKTTg-=dU9eoof=RrMHqzj9t8Yi=4Q@mail.gmail.com>]
* Re: [PATCH] Trap and Emulate changes [not found] ` <CAEigVW8cs7=f0xk-QZN2vKTTg-=dU9eoof=RrMHqzj9t8Yi=4Q@mail.gmail.com> @ 2026-02-12 16:13 ` Anup Patel 0 siblings, 0 replies; 6+ messages in thread From: Anup Patel @ 2026-02-12 16:13 UTC (permalink / raw) To: Dave Patel Cc: Scott Bambrough, opensbi, Ray Mao, Robin Randhawa, Anup Patel, Samuel Holland, Anup Patel, Dhaval, Peter Lin On Thu, Feb 12, 2026 at 9:23 PM Dave Patel <dave.patel@riscstar.com> wrote: > > Thanks Scott, Thanks Anup. Very much appreciated. > > We have already been using ecall, I can extend it to use it for paravirt for 'IRQ'. > > The only downside is ecall is an extension rather than trap and emulate (though it resides within trap and emulate functionality). You don't need to define a new SBI extension for paravirt interrupt controller. OpenSBI can emulate RPMI System MSI over SBI MPXY channel as the paravirt interrupt controller. There are some improvements required in the RPMI System MSI service group to achieve this which I will propose soon. Regards, Anup > > Thanks for the feedback. > > Thanks and regards > Dave > > On Thu, Feb 12, 2026 at 3:40 PM Anup Patel <apatel@ventanamicro.com> wrote: >> >> On Thu, Feb 12, 2026 at 8:38 PM Scott Bambrough <scott@riscstar.com> wrote: >> > >> > Is PMP universally available? >> >> Yes, PMP is not universally available plus we might >> not have enough PMP regions. >> >> Cleaner approach is to use an "ecall" based paravirt >> interrupt controller. >> >> Regards, >> Anup >> >> > Scott >> > >> > On Thu, Feb 12, 2026 at 9:58 AM Anup Patel <apatel@ventanamicro.com> wrote: >> >> >> >> On Wed, Feb 11, 2026 at 3:30 PM <dave.patel@riscstar.com> wrote: >> >> > >> >> > From: Dave Patel <dave.patel@riscstar.com> >> >> > >> >> > Signed-off-by: Dave Patel <dave.patel@riscstar.com> >> >> > --- >> >> > lib/sbi/sbi_illegal_insn.c | 25 ++++++++++++++++++++++++- >> >> > 1 file changed, 24 insertions(+), 1 deletion(-) >> >> > >> >> > diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c >> >> > index fa82264a..88079e39 100644 >> >> > --- a/lib/sbi/sbi_illegal_insn.c >> >> > +++ b/lib/sbi/sbi_illegal_insn.c >> >> > @@ -110,10 +110,33 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) >> >> > return 0; >> >> > } >> >> > >> >> > +static int sbi_get_emulated_irq_insn(ulong insn, struct sbi_trap_regs *regs) >> >> > +{ >> >> > + ulong rs1_val = GET_RS1(insn, regs); >> >> > + ulong rs2_val = GET_RS2(insn, regs); >> >> > + //ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); >> >> > + ulong irq_val; >> >> > + >> >> > + /* >> >> > + // This is were the emualted irq vlaue is fetched >> >> > + if (prev_mode == PRV_S && sbi_emulate_irq_read(&irq_val)) >> >> > + return truly_illegal_insn(insn, regs); >> >> > + */ >> >> > + >> >> > + // For testing >> >> > + irq_val = rs1_val + rs2_val; >> >> > + >> >> > + SET_RD(insn, regs, irq_val); >> >> > + >> >> > + regs->mepc += 4; >> >> > + >> >> > + return 0; >> >> > +} >> >> > + >> >> > static const illegal_insn_func illegal_insn_table[32] = { >> >> > truly_illegal_insn, /* 0 */ >> >> > truly_illegal_insn, /* 1 */ >> >> > - truly_illegal_insn, /* 2 */ >> >> > + sbi_get_emulated_irq_insn, /* 2 */ >> >> >> >> We can't pick arbitrary instruction encoding for >> >> trap-n-emulation of an interrupt controller. >> >> >> >> If the goal is to trap-n-emulate an MMIO device >> >> then use PMP based access faults. >> >> >> >> Regards >> >> Anup -- opensbi mailing list opensbi@lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] Trap and Emulate changes @ 2026-02-10 10:31 dave.patel 0 siblings, 0 replies; 6+ messages in thread From: dave.patel @ 2026-02-10 10:31 UTC (permalink / raw) To: opensbi Cc: Scott Bambrough, Dave Patel, Ray Mao, Robin Randhawa, Anup Patel, Samuel Holland, Anup Patel, Dhaval, Peter Lin From: Dave Patel <dave.patel@riscstar.com> Signed-off-by: Dave Patel <dave.patel@riscstar.com> --- lib/sbi/sbi_illegal_insn.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index fa82264a..88079e39 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -110,10 +110,33 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) return 0; } +static int sbi_get_emulated_irq_insn(ulong insn, struct sbi_trap_regs *regs) +{ + ulong rs1_val = GET_RS1(insn, regs); + ulong rs2_val = GET_RS2(insn, regs); + //ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); + ulong irq_val; + + /* + // This is were the emualted irq vlaue is fetched + if (prev_mode == PRV_S && sbi_emulate_irq_read(&irq_val)) + return truly_illegal_insn(insn, regs); + */ + + // For testing + irq_val = rs1_val + rs2_val; + + SET_RD(insn, regs, irq_val); + + regs->mepc += 4; + + return 0; +} + static const illegal_insn_func illegal_insn_table[32] = { truly_illegal_insn, /* 0 */ truly_illegal_insn, /* 1 */ - truly_illegal_insn, /* 2 */ + sbi_get_emulated_irq_insn, /* 2 */ misc_mem_opcode_insn, /* 3 */ truly_illegal_insn, /* 4 */ truly_illegal_insn, /* 5 */ -- 2.43.0 -- opensbi mailing list opensbi@lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-02-12 16:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-11 10:00 [PATCH] Trap and Emulate changes dave.patel
2026-02-12 14:58 ` Anup Patel
[not found] ` <CAL2H45cQm_O-K-6weC-xeGNB0+yCHjQe1msS+JwHdKLKecM5CA@mail.gmail.com>
2026-02-12 15:40 ` Anup Patel
2026-02-12 16:04 ` Raymond Mao
[not found] ` <CAEigVW8cs7=f0xk-QZN2vKTTg-=dU9eoof=RrMHqzj9t8Yi=4Q@mail.gmail.com>
2026-02-12 16:13 ` Anup Patel
-- strict thread matches above, loose matches on Subject: below --
2026-02-10 10:31 dave.patel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox