2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1990 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_capsicum.h"
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/capsicum.h>
43 #include <sys/sysproto.h>
44 #include <sys/syscall.h>
45 #include <sys/sysent.h>
47 #include <vm/vm_extern.h>
49 #include <machine/cpu.h>
50 #include <machine/sysarch.h>
51 #include <machine/machdep.h>
52 #include <machine/vmparam.h>
54 #ifndef _SYS_SYSPROTO_H_
62 static int arm32_sync_icache (struct thread *, void *);
63 static int arm32_drain_writebuf(struct thread *, void *);
66 sync_icache(uintptr_t addr, size_t len)
72 * Align starting address to even number because value of "1"
73 * is used as return value for success.
78 /* Break whole range to pages. */
80 size = PAGE_SIZE - (addr & PAGE_MASK);
81 size = min(size, len);
82 rv = dcache_wb_pou_checked(addr, size);
83 if (rv == 1) /* see dcache_wb_pou_checked() */
84 rv = icache_inv_pou_checked(addr, size);
86 if (!useracc((void *)addr, size, VM_PROT_READ)) {
90 /* Valid but unmapped page - skip it. */
96 /* Invalidate branch predictor buffer. */
102 arm32_sync_icache(struct thread *td, void *args)
104 struct arm_sync_icache_args ua;
109 if ((error = copyin(args, &ua, sizeof(ua))) != 0)
113 td->td_retval[0] = 0;
118 * Validate arguments. Address and length are unsigned,
119 * so we can use wrapped overflow check.
121 if (((ua.addr + ua.len) < ua.addr) ||
122 ((ua.addr + ua.len) > VM_MAXUSER_ADDRESS)) {
123 ksiginfo_init_trap(&ksi);
124 ksi.ksi_signo = SIGSEGV;
125 ksi.ksi_code = SEGV_ACCERR;
126 ksi.ksi_addr = (void *)max(ua.addr, VM_MAXUSER_ADDRESS);
127 trapsignal(td, &ksi);
131 rv = sync_icache(ua.addr, ua.len);
133 ksiginfo_init_trap(&ksi);
134 ksi.ksi_signo = SIGSEGV;
135 ksi.ksi_code = SEGV_MAPERR;
136 ksi.ksi_addr = (void *)rv;
137 trapsignal(td, &ksi);
141 td->td_retval[0] = 0;
146 arm32_drain_writebuf(struct thread *td, void *args)
151 cpu_l2cache_drain_writebuf();
152 td->td_retval[0] = 0;
157 arm32_set_tp(struct thread *td, void *args)
165 arm32_get_tp(struct thread *td, void *args)
168 td->td_retval[0] = (register_t)get_tls();
173 sysarch(struct thread *td, struct sysarch_args *uap)
177 #ifdef CAPABILITY_MODE
179 * When adding new operations, add a new case statement here to
180 * explicitly indicate whether or not the operation is safe to
181 * perform in capability mode.
183 if (IN_CAPABILITY_MODE(td)) {
185 case ARM_SYNC_ICACHE:
186 case ARM_DRAIN_WRITEBUF:
189 case ARM_GET_VFPSTATE:
194 if (KTRPOINT(td, KTR_CAPFAIL))
195 ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL);
203 case ARM_SYNC_ICACHE:
204 error = arm32_sync_icache(td, uap->parms);
206 case ARM_DRAIN_WRITEBUF:
207 error = arm32_drain_writebuf(td, uap->parms);
210 error = arm32_set_tp(td, uap->parms);
213 error = arm32_get_tp(td, uap->parms);
215 case ARM_GET_VFPSTATE:
216 error = arm_get_vfpstate(td, uap->parms);