[PATCH] Trap and Emulate changes

Raymond Mao raymondmaoca at gmail.com
Thu Feb 12 08:04:29 PST 2026


Hi Anup,

On Thu, Feb 12, 2026 at 10:41 AM Anup Patel <apatel at ventanamicro.com> wrote:
>
> On Thu, Feb 12, 2026 at 8:38 PM Scott Bambrough <scott at 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 at ventanamicro.com> wrote:
> >>
> >> On Wed, Feb 11, 2026 at 3:30 PM <dave.patel at riscstar.com> wrote:
> >> >
> >> > From: Dave Patel <dave.patel at riscstar.com>
> >> >
> >> > Signed-off-by: Dave Patel <dave.patel at 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 at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list