SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
exception.c File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <types.h>
#include <mmu.h>
#include <timer.h>
#include <csr.h>
#include <common.h>
#include <log.h>
#include <sys-clic.h>
Include dependency graph for exception.c:

Classes

struct  pt_regs_t
 
struct  insn_fetch_t
 
union  endian_buf_t
 
struct  instruction_info_t
 

Macros

#define EXTRACT_FIELD(val, which)   (((val) & (which)) / ((which) & ~((which) -1)))
 
#define INSERT_FIELD(val, which, fieldval)   (((val) & ~(which)) | ((fieldval) * ((which) & ~((which) -1))))
 
#define _STRINGIFY(x)   #x
 
#define STRINGIFY(x)   _STRINGIFY(x)
 
#define DEFINE_MPRV_READ_FLAGS(name, type, insn, flags)
 
#define DEFINE_MPRV_READ(name, type, insn)   DEFINE_MPRV_READ_FLAGS(name, type, insn, 0x00020000)
 
#define DEFINE_MPRV_READ_MXR(name, type, insn)   DEFINE_MPRV_READ_FLAGS(name, type, insn, 0x00020000 | 0x00080000)
 
#define DEFINE_MPRV_WRITE(name, type, insn)
 

Functions

static const char * mstatus_to_previous_mode (unsigned long ms)
 
static void show_regs (struct pt_regs_t *regs)
 
static struct instruction_info_tmatch_instruction (unsigned long insn)
 
static int fetch_16bit_instruction (unsigned long vaddr, unsigned long *insn)
 
static int fetch_32bit_instruction (unsigned long vaddr, unsigned long *insn)
 
static void redirect_trap (void)
 
static void handle_misaligned (struct pt_regs_t *regs)
 
void riscv_handle_exception (struct pt_regs_t *regs)
 

Variables

static struct instruction_info_t insn_info []
 
static const char * interrupt_names []
 
static const char * exception_names []
 

Macro Definition Documentation

◆ _STRINGIFY

#define _STRINGIFY (   x)    #x

◆ DEFINE_MPRV_READ

#define DEFINE_MPRV_READ (   name,
  type,
  insn 
)    DEFINE_MPRV_READ_FLAGS(name, type, insn, 0x00020000)

◆ DEFINE_MPRV_READ_FLAGS

#define DEFINE_MPRV_READ_FLAGS (   name,
  type,
  insn,
  flags 
)
Value:
static inline type name(type *p) { \
size_t mprv = flags; \
type value; \
__asm__ __volatile__("csrs mstatus, %1\n" STRINGIFY(insn) " %0, 0(%2)\n" \
"csrc mstatus, %1\n" \
: "=&r"(value) \
: "r"(mprv), "r"(p) \
: "memory"); \
return value; \
}
char name[ANDR_BOOT_NAME_SIZE]
Definition bimage.c:76
static uint8_t value
Definition io.h:144
#define STRINGIFY(x)
Definition exception.c:35

◆ DEFINE_MPRV_READ_MXR

#define DEFINE_MPRV_READ_MXR (   name,
  type,
  insn 
)    DEFINE_MPRV_READ_FLAGS(name, type, insn, 0x00020000 | 0x00080000)

◆ DEFINE_MPRV_WRITE

#define DEFINE_MPRV_WRITE (   name,
  type,
  insn 
)
Value:
static inline void name(type *p, type value) { \
size_t mprv = 0x00020000; \
__asm__ __volatile__("csrs mstatus, %0\n" STRINGIFY(insn) " %1, 0(%2)\n" \
"csrc mstatus, %0\n" ::"r"(mprv), \
"r"(value), "r"(p) \
: "memory"); \
}

◆ EXTRACT_FIELD

#define EXTRACT_FIELD (   val,
  which 
)    (((val) & (which)) / ((which) & ~((which) -1)))

◆ INSERT_FIELD

#define INSERT_FIELD (   val,
  which,
  fieldval 
)    (((val) & ~(which)) | ((fieldval) * ((which) & ~((which) -1))))

◆ STRINGIFY

#define STRINGIFY (   x)    _STRINGIFY(x)

Function Documentation

◆ fetch_16bit_instruction()

static int fetch_16bit_instruction ( unsigned long  vaddr,
unsigned long *  insn 
)
static

◆ fetch_32bit_instruction()

static int fetch_32bit_instruction ( unsigned long  vaddr,
unsigned long *  insn 
)
static

◆ handle_misaligned()

static void handle_misaligned ( struct pt_regs_t regs)
static

◆ match_instruction()

static struct instruction_info_t * match_instruction ( unsigned long  insn)
static

◆ mstatus_to_previous_mode()

static const char * mstatus_to_previous_mode ( unsigned long  ms)
static

◆ redirect_trap()

static void redirect_trap ( void  )
static

◆ riscv_handle_exception()

void riscv_handle_exception ( struct pt_regs_t regs)

◆ show_regs()

static void show_regs ( struct pt_regs_t regs)
static

Variable Documentation

◆ exception_names

const char* exception_names[]
static
Initial value:
= {
"Instruction address misaligned",
"Instruction access fault",
"Illegal instruction",
"Breakpoint",
"Load address misaligned",
"Load access fault",
"Store address misaligned",
"Store access fault",
"Environment call from U-mode",
"Environment call from S-mode",
"Reserved (10)",
"Environment call from M-mode",
"Instruction page fault",
"Load page fault",
"Reserved (14)",
"Store page fault",
}

◆ insn_info

struct instruction_info_t insn_info[]
static

◆ interrupt_names

const char* interrupt_names[]
static
Initial value:
= {
"User software interrupt",
"Supervisor software interrupt",
"Hypervisor software interrupt",
"Machine software interrupt",
"User timer interrupt",
"Supervisor timer interrupt",
"Hypervisor timer interrupt",
"Machine timer interrupt",
"User external interrupt",
"Supervisor external interrupt",
"Hypervisor external interrupt",
"Machine external interrupt",
}