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