forked from Mirrors/opensbi
lib: sbi: add Ssdbltrp ISA extension support
Add Ssdbltrp trap handler support for S-mode double trap handling. If the trap is received while in VS-mode, then the trap is redirected to S-mode. If caught while in HS-mode, then an error is returned to the top trap handler which will panic. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
This commit is contained in:

committed by
Anup Patel

parent
80656bdb1d
commit
9c78593269
30
lib/sbi/sbi_double_trap.c
Normal file
30
lib/sbi/sbi_double_trap.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2024 Rivos Inc.
|
||||
*
|
||||
* Authors:
|
||||
* Clément Léger <clement.leger@rivosinc.com>
|
||||
*/
|
||||
|
||||
#include <sbi/sbi_console.h>
|
||||
#include <sbi/sbi_ecall_interface.h>
|
||||
#include <sbi/sbi_error.h>
|
||||
#include <sbi/sbi_sse.h>
|
||||
#include <sbi/sbi_trap.h>
|
||||
|
||||
int sbi_double_trap_handler(struct sbi_trap_context *tcntx)
|
||||
{
|
||||
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||
const struct sbi_trap_info *trap = &tcntx->trap;
|
||||
bool prev_virt = sbi_regs_from_virt(regs);
|
||||
|
||||
if (sbi_mstatus_prev_mode(regs->mstatus) != PRV_S)
|
||||
return SBI_ERR_INVALID_PARAM;
|
||||
|
||||
/* Exception was taken in VS-mode, redirect it to S-mode */
|
||||
if (prev_virt)
|
||||
return sbi_trap_redirect(regs, trap);
|
||||
|
||||
return SBI_ENOTSUPP;
|
||||
}
|
Reference in New Issue
Block a user