[PATCH 3/3] firmware: fw_base.S: Add common NMI trap handler
Radim Krcmar
rkrcmar at qti.qualcomm.com
Mon Feb 2 06:49:23 PST 2026
2026-01-29T00:13:43-08:00, Nylon Chen <nylon.chen at sifive.com>:
> Add rnmi_handler assembly wrapper and sbi_rnmi_trap_handler default
> C handler. The default handler prints diagnostics and hangs the hart.
>
> Co-developed-by: Zong Li <zong.li at sifive.com>
> Signed-off-by: Zong Li <zong.li at sifive.com>
> Suggested-by: Nick Hu <nick.hu at sifive.com>
> Suggested-by: Samuel Holland <samuel.holland at sifive.com>
> Signed-off-by: Nylon Chen <nylon.chen at sifive.com>
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang at sifive.com>
> ---
> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> @@ -643,6 +643,70 @@ memcmp:
> + .section .entry, "ax", %progbits
> + .align 4
> + .globl sbi_rnmi_vector
> +sbi_rnmi_vector:
> + /* Swap SP with MNSCRATCH */
> + csrrw sp, CSR_MNSCRATCH, sp
> +
> + /* Allocate space for full trap registers structure */
> + addi sp, sp, -(SBI_TRAP_REGS_SIZE)
[2/3] did:
rnmi_context_offset = sbi_scratch_alloc_offset(SBI_TRAP_REGS_SIZE);
rnmi_ctx = sbi_scratch_offset_ptr(scratch, rnmi_context_offset);
rnmi_sp = (unsigned long)rnmi_ctx + SBI_TRAP_REGS_SIZE;
csr_write(CSR_MNSCRATCH, rnmi_sp);
We can avoid the add/subtract dance, since it produces rnmi_ctx.
A bigger issue is that it leaves 0 bytes for the stack of the callback.
Is there a reason not to reuse the existing M-mode stack?
Thanks.
More information about the opensbi
mailing list