summaryrefslogtreecommitdiff
path: root/sys/arch/aarch64/include/machdep.h
blob: 96d10e4b993e6a9ef418b3014138719e1fb05ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*	$NetBSD: machdep.h,v 1.18 2021/08/30 23:20:00 jmcneill Exp $	*/

/*
 * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _AARCH64_MACHDEP_H_
#define _AARCH64_MACHDEP_H_

#include <sys/proc.h>
#include <sys/lwp.h>
#include <sys/siginfo.h>

// initarm_common
#include <machine/bootconfig.h>

struct boot_physmem;

static inline paddr_t
aarch64_kern_vtophys(vaddr_t va)
{
	extern u_long kern_vtopdiff;

	return va - kern_vtopdiff;
}

static inline vaddr_t
aarch64_kern_phystov(paddr_t pa)
{
	extern u_long kern_vtopdiff;

	return pa + kern_vtopdiff;
}

#define KERN_VTOPHYS(va)	aarch64_kern_vtophys(va)
#define KERN_PHYSTOV(pa)	aarch64_kern_phystov(pa)

extern paddr_t physical_start;
extern paddr_t physical_end;
extern vaddr_t module_start;
extern vaddr_t module_end;

extern void (*cpu_reset_address0)(void);
extern void (*cpu_reset_address)(void);
extern void (*cpu_powerdown_address)(void);

extern char *booted_kernel;

/*
 * note that we use void * as all the platforms have different ideas on what
 * the structure is
 */
vaddr_t initarm(void *);

vaddr_t initarm_common(vaddr_t, vsize_t, const struct boot_physmem *, size_t);
void cpu_kernel_vm_init(paddr_t, psize_t);
void uartputc(int);

void parse_mi_bootargs(char *);
void dumpsys(void);

void cpu_startup_hook(void);
void cpu_startup_default(void);

struct trapframe;

/* fault.c */
void data_abort_handler(struct trapframe *, uint32_t);

/* trap.c */
void lwp_trampoline(void);
void configure_cpu_traps(void);
void cpu_dosoftints(void);
void cpu_switchto_softint(struct lwp *, int);
void dosoftints(void);
int fetch_arm_insn(uint64_t, uint64_t, uint32_t *);
void trap_doast(struct trapframe *);

void trap_el1t_sync(struct trapframe *);
void trap_el1t_irq(struct trapframe *);
void trap_el1t_fiq(struct trapframe *);
void trap_el1t_error(struct trapframe *);
void trap_el1h_sync(struct trapframe *);
void trap_el1h_fiq(struct trapframe *);
void trap_el1h_error(struct trapframe *);
void trap_el0_sync(struct trapframe *);
void trap_el0_fiq(struct trapframe *);
void trap_el0_error(struct trapframe *);
void trap_el0_32sync(struct trapframe *);
void trap_el0_32fiq(struct trapframe *);
void trap_el0_32error(struct trapframe *);
void cpu_irq(struct trapframe *);
void cpu_fiq(struct trapframe *);

/* cpu_onfault */
int cpu_set_onfault(struct faultbuf *) __returns_twice;
void cpu_jump_onfault(struct trapframe *, const struct faultbuf *, int);

#if defined(_KERNEL)
static inline void
cpu_unset_onfault(void)
{
	curlwp->l_md.md_onfault = NULL;
}

static inline void
cpu_enable_onfault(struct faultbuf *fb)
{
	curlwp->l_md.md_onfault = fb;
}

static inline struct faultbuf *
cpu_disable_onfault(void)
{
	struct faultbuf * const fb = curlwp->l_md.md_onfault;
	if (fb != NULL)
		curlwp->l_md.md_onfault = NULL;
	return fb;
}
#endif

/* exec_machdep.c */
void aarch64_setregs_ptrauth(struct lwp *, bool);

/* fpu.c */
void fpu_attach(struct cpu_info *);
struct fpreg;
void load_fpregs(const struct fpreg *);
void save_fpregs(struct fpreg *);

#ifdef TRAP_SIGDEBUG
#define do_trapsignal(l, signo, code, addr, trap) \
    do_trapsignal1(__func__, __LINE__, tf, l, signo, code, addr, trap)
#else
#define do_trapsignal(l, signo, code, addr, trap) \
    do_trapsignal1(l, signo, code, addr, trap)
#endif

void do_trapsignal1(
#ifdef TRAP_SIGDEBUG
    const char *func, size_t line, struct trapframe *tf,
#endif
    struct lwp *l, int signo, int code, void *addr, int trap);

const char *eclass_trapname(uint32_t);

#include <sys/pcu.h>

extern const pcu_ops_t pcu_fpu_ops;

static inline bool
fpu_used_p(lwp_t *l)
{
	return pcu_valid_p(&pcu_fpu_ops, l);
}

static inline void
fpu_save(lwp_t *l)
{
	pcu_save(&pcu_fpu_ops, l);
}

static inline void
fpu_load(lwp_t *l)
{
	pcu_load(&pcu_fpu_ops);
}

static inline void
fpu_discard(lwp_t *l, bool usesw)
{
	pcu_discard(&pcu_fpu_ops, l, usesw);
}

#endif /* _AARCH64_MACHDEP_H_ */