blob: d0ddb4937a296a076334c4fef2aacd7cc44e162b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
* 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_hart.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_sse_inject_event(SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP);
}
void sbi_double_trap_init(struct sbi_scratch *scratch)
{
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSDBLTRP))
sbi_sse_add_event(SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP, NULL);
}
|