diff options
| author | Anup Patel <apatel@ventanamicro.com> | 2024-03-11 14:40:12 +0530 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2024-03-19 11:31:22 +0530 |
| commit | abea949721bc635cfe39e34adc501d7be87db8ae (patch) | |
| tree | 35652f64f58ca8f33cc0545b05060b5fd65d879d /include | |
| parent | 60ffc154c84dfe93b23bd02566310deb153a4360 (diff) | |
| download | opensbi-abea949721bc635cfe39e34adc501d7be87db8ae.tar.gz opensbi-abea949721bc635cfe39e34adc501d7be87db8ae.tar.bz2 opensbi-abea949721bc635cfe39e34adc501d7be87db8ae.zip | |
lib: sbi: Introduce trap context
Club the struct sbi_trap_regs and struct sbi_trap_info a new
struct sbi_trap_context (aka trap context) which must be saved
by low-level trap handler before calling sbi_trap_handler().
To track nested traps, the struct sbi_scratch points to the current
trap context and the trap context has pointer to pervious context
of previous trap.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
Tested-by: Samuel Holland <samuel.holland@sifive.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/sbi/sbi_trap.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index a6032ab6..f7c170e6 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -112,9 +112,15 @@ /** Size (in bytes) of sbi_trap_info */ #define SBI_TRAP_INFO_SIZE SBI_TRAP_INFO_OFFSET(last) +/** Size (in bytes) of sbi_trap_context */ +#define SBI_TRAP_CONTEXT_SIZE (SBI_TRAP_REGS_SIZE + \ + SBI_TRAP_INFO_SIZE + \ + __SIZEOF_POINTER__) + #ifndef __ASSEMBLER__ #include <sbi/sbi_types.h> +#include <sbi/sbi_scratch.h> /** Representation of register state at time of trap/interrupt */ struct sbi_trap_regs { @@ -204,6 +210,16 @@ struct sbi_trap_info { unsigned long gva; }; +/** Representation of trap context saved on stack */ +struct sbi_trap_context { + /** Register state */ + struct sbi_trap_regs regs; + /** Trap details */ + struct sbi_trap_info trap; + /** Pointer to previous trap context */ + struct sbi_trap_context *prev_context; +}; + static inline unsigned long sbi_regs_gva(const struct sbi_trap_regs *regs) { /* @@ -223,7 +239,18 @@ static inline unsigned long sbi_regs_gva(const struct sbi_trap_regs *regs) int sbi_trap_redirect(struct sbi_trap_regs *regs, const struct sbi_trap_info *trap); -struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs); +static inline struct sbi_trap_context *sbi_trap_get_context(struct sbi_scratch *scratch) +{ + return (scratch) ? (void *)scratch->trap_context : NULL; +} + +static inline void sbi_trap_set_context(struct sbi_scratch *scratch, + struct sbi_trap_context *tcntx) +{ + scratch->trap_context = (unsigned long)tcntx; +} + +struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx); #endif |
