machdep.h revision 1.1 1 /* $NetBSD: machdep.h,v 1.1 2018/04/01 04:35:03 ryo Exp $ */
2
3 /*
4 * Copyright (c) 2017 Ryo Shimizu <ryo (at) nerv.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef _AARCH64_MACHDEP_H_
30 #define _AARCH64_MACHDEP_H_
31
32 #include <sys/proc.h>
33 #include <sys/lwp.h>
34 #include <sys/siginfo.h>
35
36 // initarm_common
37 #include <machine/bootconfig.h>
38
39
40 static inline paddr_t
41 aarch64_kern_vtophys(vaddr_t va)
42 {
43 extern u_long kern_vtopdiff;
44
45 return va - kern_vtopdiff;
46 }
47
48 static inline vaddr_t
49 aarch64_kern_phystov(paddr_t pa)
50 {
51 extern u_long kern_vtopdiff;
52
53 return pa + kern_vtopdiff;
54 }
55
56 #define KERN_VTOPHYS(va) aarch64_kern_vtophys(va)
57 #define KERN_PHYSTOV(pa) aarch64_kern_phystov(pa)
58
59 extern paddr_t physical_start;
60 extern paddr_t physical_end;
61
62 extern void (*cpu_reset_address0)(void);
63 extern void (*cpu_reset_address)(void);
64 extern void (*cpu_powerdown_address)(void);
65
66 extern char *booted_kernel;
67
68 vaddr_t initarm_common(vaddr_t, vsize_t, const struct boot_physmem *, size_t);
69
70 void parse_mi_bootargs(char *);
71 void dumpsys(void);
72
73 struct trapframe;
74
75 /* fault.c */
76 void data_abort_handler(struct trapframe *, uint32_t, const char *);
77
78 /* trap.c */
79 void lwp_trampoline(void);
80 void cpu_dosoftints(void);
81 void cpu_switchto_softint(struct lwp *, int);
82 void dosoftints(void);
83 void trap_doast(struct trapframe *);
84
85 void trap_el1t_sync(struct trapframe *);
86 void trap_el1t_irq(struct trapframe *);
87 void trap_el1t_fiq(struct trapframe *);
88 void trap_el1t_error(struct trapframe *);
89 void trap_el1h_sync(struct trapframe *);
90 void trap_el1h_fiq(struct trapframe *);
91 void trap_el1h_error(struct trapframe *);
92 void trap_el0_sync(struct trapframe *);
93 void trap_el0_fiq(struct trapframe *);
94 void trap_el0_error(struct trapframe *);
95 void trap_el0_32sync(struct trapframe *);
96 void trap_el0_32fiq(struct trapframe *);
97 void trap_el0_32error(struct trapframe *);
98 void interrupt(struct trapframe *);
99
100 void ucas_ras_check(struct trapframe *);
101
102 /* cpu_onfault */
103 int cpu_set_onfault(struct faultbuf *) __returns_twice;
104 void cpu_jump_onfault(struct trapframe *, const struct faultbuf *, int);
105
106 static inline void
107 cpu_unset_onfault(void)
108 {
109 curlwp->l_md.md_onfault = NULL;
110 }
111
112 static inline void
113 cpu_enable_onfault(struct faultbuf *fb)
114 {
115 curlwp->l_md.md_onfault = fb;
116 }
117
118 static inline struct faultbuf *
119 cpu_disable_onfault(void)
120 {
121 struct faultbuf * const fb = curlwp->l_md.md_onfault;
122 if (fb != NULL)
123 curlwp->l_md.md_onfault = NULL;
124 return fb;
125 }
126
127 /* fpu.c */
128 void fpu_attach(struct cpu_info *);
129 struct fpreg;
130 void load_fpregs(struct fpreg *);
131 void save_fpregs(struct fpreg *);
132
133 static inline void
134 do_trapsignal(struct lwp *l, int signo, int code, void *addr, int trap)
135 {
136 ksiginfo_t ksi;
137
138 KSI_INIT_TRAP(&ksi);
139 ksi.ksi_signo = signo;
140 ksi.ksi_code = code;
141 ksi.ksi_addr = addr;
142 ksi.ksi_trap = trap;
143 (*l->l_proc->p_emul->e_trapsignal)(l, &ksi);
144 }
145
146 #include <sys/pcu.h>
147
148 extern const pcu_ops_t pcu_fpu_ops;
149
150 static inline bool
151 fpu_used_p(lwp_t *l)
152 {
153 return pcu_valid_p(&pcu_fpu_ops, l);
154 }
155
156 static inline void
157 fpu_save(lwp_t *l)
158 {
159 pcu_save(&pcu_fpu_ops, l);
160 }
161
162 static inline void
163 fpu_load(lwp_t *l)
164 {
165 pcu_load(&pcu_fpu_ops);
166 }
167
168 static inline void
169 fpu_discard(lwp_t *l, bool usesw)
170 {
171 pcu_discard(&pcu_fpu_ops, l, usesw);
172 }
173
174 #endif /* _AARCH64_MACHDEP_H_ */
175