Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.1
      1 /* $NetBSD: locore.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
      2 /*-
      3  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Matt Thomas of 3am Software Foundry.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef _RISCV_LOCORE_H_
     32 #define _RISCV_LOCORE_H_
     33 
     34 #include <sys/lwp.h>
     35 #include <sys/userret.h>
     36 
     37 #include <riscv/reg.h>
     38 #include <riscv/sysreg.h>
     39 
     40 struct trapframe {
     41 	struct reg tf_regs;
     42 	register_t tf_badvaddr;
     43 	uint32_t tf_cause;		// 32-bit register
     44 	uint32_t tf_sr;			// 32-bit register
     45 #define tf_reg		tf_regs.r_reg
     46 #define tf_pc		tf_regs.r_pc
     47 #define tf_ra		tf_reg[_X_RA]
     48 #define tf_s0		tf_reg[_X_S0]
     49 #define tf_s1		tf_reg[_X_S1]
     50 #define tf_s2		tf_reg[_X_S2]
     51 #define tf_s3		tf_reg[_X_S3]
     52 #define tf_s4		tf_reg[_X_S4]
     53 #define tf_s5		tf_reg[_X_S5]
     54 #define tf_s6		tf_reg[_X_S6]
     55 #define tf_s7		tf_reg[_X_S7]
     56 #define tf_s8		tf_reg[_X_S8]
     57 #define tf_s9		tf_reg[_X_S9]
     58 #define tf_s10		tf_reg[_X_S10]
     59 #define tf_s11		tf_reg[_X_S11]
     60 #define tf_sp		tf_reg[_X_SP]
     61 #define tf_tp		tf_reg[_X_TP]
     62 #define tf_v0		tf_reg[_X_V0]
     63 #define tf_v1		tf_reg[_X_V1]
     64 #define tf_a0		tf_reg[_X_A0]
     65 #define tf_a1		tf_reg[_X_A1]
     66 #define tf_a2		tf_reg[_X_A2]
     67 #define tf_a3		tf_reg[_X_A3]
     68 #define tf_a4		tf_reg[_X_A4]
     69 #define tf_a5		tf_reg[_X_A5]
     70 #define tf_a6		tf_reg[_X_A6]
     71 #define tf_a7		tf_reg[_X_A7]
     72 #define tf_t0		tf_reg[_X_T0]
     73 #define tf_t1		tf_reg[_X_T1]
     74 #define tf_t2		tf_reg[_X_T2]
     75 #define tf_t3		tf_reg[_X_T3]
     76 #define tf_t4		tf_reg[_X_T4]
     77 #define tf_gp		tf_reg[_X_GP]
     78 };
     79 
     80 // For COMPAT_NETBDS32 coredumps
     81 struct trapframe32 {
     82 	struct reg32 tf_regs;
     83 	register32_t tf_badvaddr;
     84 	uint32_t tf_cause;		// 32-bit register
     85 	uint32_t tf_sr;			// 32-bit register
     86 };
     87 
     88 struct faultbuf {
     89 	register_t fb_reg[_X_SP+1];
     90 	register_t fb_v0;
     91 	uint32_t fb_sr;
     92 };
     93 
     94 CTASSERT(sizeof(label_t) == sizeof(struct faultbuf));
     95 
     96 struct mainbus_attach_args {
     97 	const char *maa_name;
     98 	u_int maa_instance;
     99 };
    100 
    101 #ifdef _KERNEL
    102 extern int cpu_printfataltraps;
    103 extern const pcu_ops_t pcu_fpu_ops;
    104 
    105 static inline vaddr_t
    106 stack_align(vaddr_t sp)
    107 {
    108 	return sp & ~STACK_ALIGNBYTES;
    109 }
    110 
    111 static inline void
    112 userret(struct lwp *l)
    113 {
    114 	mi_userret(l);
    115 }
    116 
    117 static inline void
    118 fpu_load(void)
    119 {
    120 	pcu_load(&pcu_fpu_ops);
    121 }
    122 
    123 static inline void
    124 fpu_save(void)
    125 {
    126 	pcu_save(&pcu_fpu_ops);
    127 }
    128 
    129 static inline void
    130 fpu_discard(void)
    131 {
    132 	pcu_discard(&pcu_fpu_ops, false);
    133 }
    134 
    135 static inline void
    136 fpu_replace(void)
    137 {
    138 	pcu_discard(&pcu_fpu_ops, true);
    139 }
    140 
    141 static inline bool
    142 fpu_valid_p(void)
    143 {
    144 	return pcu_valid_p(&pcu_fpu_ops);
    145 }
    146 
    147 void	__syncicache(const void *, size_t);
    148 
    149 int	cpu_set_onfault(struct faultbuf *, register_t) __returns_twice;
    150 void	cpu_jump_onfault(struct trapframe *, struct faultbuf *);
    151 
    152 static inline void
    153 cpu_unset_onfault(void)
    154 {
    155 	curlwp->l_md.md_onfault = NULL;
    156 }
    157 
    158 static inline struct faultbuf *
    159 cpu_disable_onfault(void)
    160 {
    161 	struct faultbuf * const fb = curlwp->l_md.md_onfault;
    162 	curlwp->l_md.md_onfault = NULL;
    163 	return fb;
    164 }
    165 
    166 static inline void
    167 cpu_enable_onfault(struct faultbuf *fb)
    168 {
    169 	curlwp->l_md.md_onfault = fb;
    170 }
    171 
    172 void	cpu_intr(struct trapframe */*tf*/, register_t /*epc*/,
    173 	    register_t /*status*/, register_t /*cause*/,
    174 	    register_t /*badvaddr*/);
    175 void	cpu_trap(struct trapframe */*tf*/, register_t /*epc*/,
    176 	    register_t /*status*/, register_t /*cause*/,
    177 	    register_t /*badvaddr*/);
    178 void	cpu_ast(struct trapframe *);
    179 void	cpu_fast_switchto(struct lwp *, int);
    180 
    181 void	cpu_lwp_trampoline(void);
    182 
    183 void *	cpu_sendsig_getframe(struct lwp *, int, bool *);
    184 
    185 #endif
    186 
    187 #endif /* _RISCV_LOCORE_H_ */
    188