2 * Copyright (C) 2002 Benno Rice
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * Copyright (C) 1993 Wolfgang Solfrank.
27 * Copyright (C) 1993 TooLs GmbH.
28 * All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by TooLs GmbH.
41 * 4. The name of TooLs GmbH may not be used to endorse or promote products
42 * derived from this software without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
50 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
52 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #include <sys/cdefs.h>
57 __FBSDID("$FreeBSD$");
59 #include <sys/param.h>
60 #include <sys/systm.h>
65 #include <vm/vm_map.h>
67 #include <machine/pcb.h>
68 #include <machine/vmparam.h>
71 int setfault(faultbuf); /* defined in locore.S */
74 is_uaddr(const void *addr)
76 int rv = ((vm_offset_t)addr <= VM_MAXUSER_ADDRESS) ? 1 : 0;
82 copyout(const void *kaddr, void *udaddr, size_t len)
87 if (!is_uaddr(udaddr))
93 td->td_pcb->pcb_onfault = NULL;
97 bcopy(kaddr, udaddr, len);
99 td->td_pcb->pcb_onfault = NULL;
104 copyin(const void *udaddr, void *kaddr, size_t len)
109 if (!is_uaddr(udaddr) || is_uaddr(kaddr))
115 td->td_pcb->pcb_onfault = NULL;
119 bcopy(udaddr, kaddr, len);
121 td->td_pcb->pcb_onfault = NULL;
126 copyinstr(const void *udaddr, void *kaddr, size_t len, size_t *done)
135 if (!is_uaddr(udaddr) || is_uaddr(kaddr))
141 td->td_pcb->pcb_onfault = NULL;
150 for (l = 0; len-- > 0; l++) {
165 td->td_pcb->pcb_onfault = NULL;
170 subyte(void *addr, int byte)
181 td->td_pcb->pcb_onfault = NULL;
185 *(char *)addr = (char)byte;
187 td->td_pcb->pcb_onfault = NULL;
192 suword(void *addr, long word)
203 td->td_pcb->pcb_onfault = NULL;
207 *(long *)addr = word;
209 td->td_pcb->pcb_onfault = NULL;
214 suword32(void *addr, int32_t word)
217 return (suword(addr, (long)word));
222 fubyte(const void *addr)
234 td->td_pcb->pcb_onfault = NULL;
238 val = *(const u_char *)addr;
240 td->td_pcb->pcb_onfault = NULL;
245 fuword(const void *addr)
257 td->td_pcb->pcb_onfault = NULL;
261 val = *(const long *)addr;
263 td->td_pcb->pcb_onfault = NULL;
268 fuword32(const void *addr)
271 return ((int32_t)fuword(addr));
275 casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval)
278 return (casuword((volatile u_long *)base, oldval, newval));
282 casuword(volatile u_long *addr, u_long old, u_long new)
288 if (!((vm_offset_t)addr <= VM_MAXUSER_ADDRESS))
294 td->td_pcb->pcb_onfault = NULL;
299 "1:\tlwarx %0, 0, %2\n\t" /* load old value */
300 "cmplw %3, %0\n\t" /* compare */
301 "bne 2f\n\t" /* exit if not equal */
302 "stwcx. %4, 0, %2\n\t" /* attempt to store */
303 "bne- 1b\n\t" /* spin if failed */
304 "b 3f\n\t" /* we've succeeded */
306 "stwcx. %0, 0, %2\n\t" /* clear reservation (74xx) */
308 : "=&r" (val), "=m" (*addr)
309 : "r" (addr), "r" (old), "r" (new), "m" (*addr)
312 td->td_pcb->pcb_onfault = NULL;