[PATCH] Trap and Emulate changes
Anup Patel
apatel at ventanamicro.com
Thu Feb 12 07:40:05 PST 2026
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.
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
More information about the opensbi
mailing list