forked from Mirrors/opensbi
		
	lib: Move instruction encoding macros to riscv_encoding.h
This patch moves all instruction encoding macros to riscv_encoding.h. Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
		@@ -16,56 +16,6 @@
 | 
			
		||||
#include <sbi/sbi_trap.h>
 | 
			
		||||
#include <sbi/sbi_unpriv.h>
 | 
			
		||||
 | 
			
		||||
#define SH_RD			7
 | 
			
		||||
#define SH_RS1			15
 | 
			
		||||
#define SH_RS2			20
 | 
			
		||||
#define SH_RS2C			2
 | 
			
		||||
 | 
			
		||||
#define RV_X(x, s, n)		(((x) >> (s)) & ((1 << (n)) - 1))
 | 
			
		||||
#define RVC_LW_IMM(x)		((RV_X(x, 6, 1) << 2) | \
 | 
			
		||||
				 (RV_X(x, 10, 3) << 3) | \
 | 
			
		||||
				 (RV_X(x, 5, 1) << 6))
 | 
			
		||||
#define RVC_LD_IMM(x)		((RV_X(x, 10, 3) << 3) | \
 | 
			
		||||
				 (RV_X(x, 5, 2) << 6))
 | 
			
		||||
#define RVC_LWSP_IMM(x)		((RV_X(x, 4, 3) << 2) | \
 | 
			
		||||
				 (RV_X(x, 12, 1) << 5) | \
 | 
			
		||||
				 (RV_X(x, 2, 2) << 6))
 | 
			
		||||
#define RVC_LDSP_IMM(x)		((RV_X(x, 5, 2) << 3) | \
 | 
			
		||||
				 (RV_X(x, 12, 1) << 5) | \
 | 
			
		||||
				 (RV_X(x, 2, 3) << 6))
 | 
			
		||||
#define RVC_SWSP_IMM(x)		((RV_X(x, 9, 4) << 2) | \
 | 
			
		||||
				 (RV_X(x, 7, 2) << 6))
 | 
			
		||||
#define RVC_SDSP_IMM(x)		((RV_X(x, 10, 3) << 3) | \
 | 
			
		||||
				 (RV_X(x, 7, 3) << 6))
 | 
			
		||||
#define RVC_RS1S(insn)		(8 + RV_X(insn, SH_RD, 3))
 | 
			
		||||
#define RVC_RS2S(insn)		(8 + RV_X(insn, SH_RS2C, 3))
 | 
			
		||||
#define RVC_RS2(insn)		RV_X(insn, SH_RS2C, 5)
 | 
			
		||||
 | 
			
		||||
#define SHIFT_RIGHT(x, y)	((y) < 0 ? ((x) << -(y)) : ((x) >> (y)))
 | 
			
		||||
 | 
			
		||||
#define REG_MASK		\
 | 
			
		||||
((1 << (5 + LOG_REGBYTES)) - (1 << LOG_REGBYTES))
 | 
			
		||||
 | 
			
		||||
#define REG_OFFSET(insn, pos)	\
 | 
			
		||||
(SHIFT_RIGHT((insn), (pos) - LOG_REGBYTES) & REG_MASK)
 | 
			
		||||
 | 
			
		||||
#define REG_PTR(insn, pos, regs)\
 | 
			
		||||
(ulong *)((ulong)(regs) + REG_OFFSET(insn, pos))
 | 
			
		||||
 | 
			
		||||
#define GET_RM(insn)		(((insn) >> 12) & 7)
 | 
			
		||||
 | 
			
		||||
#define GET_RS1(insn, regs)	(*REG_PTR(insn, SH_RS1, regs))
 | 
			
		||||
#define GET_RS2(insn, regs)	(*REG_PTR(insn, SH_RS2, regs))
 | 
			
		||||
#define GET_RS1S(insn, regs)	(*REG_PTR(RVC_RS1S(insn), 0, regs))
 | 
			
		||||
#define GET_RS2S(insn, regs)	(*REG_PTR(RVC_RS2S(insn), 0, regs))
 | 
			
		||||
#define GET_RS2C(insn, regs)	(*REG_PTR(insn, SH_RS2C, regs))
 | 
			
		||||
#define GET_SP(regs)		(*REG_PTR(2, 0, regs))
 | 
			
		||||
#define SET_RD(insn, regs, val)	(*REG_PTR(insn, SH_RD, regs) = (val))
 | 
			
		||||
#define IMM_I(insn)		((s32)(insn) >> 20)
 | 
			
		||||
#define IMM_S(insn)		(((s32)(insn) >> 25 << 5) | \
 | 
			
		||||
				 (s32)(((insn) >> 7) & 0x1f))
 | 
			
		||||
#define MASK_FUNCT3		0x7000
 | 
			
		||||
 | 
			
		||||
typedef int (*illegal_insn_func)(ulong insn,
 | 
			
		||||
				 u32 hartid, ulong mcause,
 | 
			
		||||
				 struct sbi_trap_regs *regs,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user