2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2018 The FreeBSD Foundation
6 * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
7 * under sponsorship from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <machine/asmacros.h>
34 #include <machine/cputypes.h>
35 #include <machine/pmap.h>
36 #include <machine/specialreg.h>
41 * Fast path for copyout code. We switch to user space %cr3 and perform
42 * move operation between user memory and copyout buffer, located in the
43 * trampoline area. We must switch to trampoline stack, because both
44 * user and kernel buffer accesses might cause page fault.
46 * Page fault handler expects %edx to point to the onfault routine.
47 * Handler switches to idlePTD and calls the routine.
48 * The routine must restore the stack, enable interrupts, and
49 * return to the caller, informing it about failure.
60 movl 20(%ebp),%ebx /* KCR3 */
61 /* bcopy(%esi = kaddr, %edi = PCPU(copyout_buf), %ecx = len) */
65 movl $copyout_fault,%edx
68 movl PCPU(COPYOUT_BUF),%edi
71 movl 16(%ebp),%ecx /* len */
72 movl PCPU(COPYOUT_BUF),%esi /* kaddr */
73 movl 12(%ebp),%edi /* uaddr */
74 movl PCPU(TRAMPSTK),%esp
75 movl PCPU(CURPCB),%edx
76 movl PCB_CR3(%edx),%edx /* UCR3 */
78 movl $copyout_fault,%edx
79 /* bcopy(%esi = PCPU(copyout_buf), %edi = udaddr, %ecx = len) */
100 movl 20(%ebp),%ebx /* KCR3 */
101 movl PCPU(CURPCB),%eax
102 movl PCB_CR3(%eax),%edx /* UCR3 */
103 movl 16(%ebp),%ecx /* len */
104 movl 8(%ebp),%esi /* udaddr */
108 movl PCPU(COPYOUT_BUF),%edi /* kaddr */
109 movl PCPU(TRAMPSTK),%esp
111 movl $copyout_fault,%edx
112 /* bcopy(%esi = udaddr, %edi = PCPU(copyout_buf), %ecx = len) */
118 /* bcopy(%esi = PCPU(copyout_buf), %edi = kaddr, %ecx = len) */
121 movl PCPU(COPYOUT_BUF),%esi
150 movl 8(%ebp),%ecx /* from */
151 movl PCPU(CURPCB),%eax
152 movl PCB_CR3(%eax),%eax
157 movl PCPU(TRAMPSTK),%esp
159 pf_x3: movl (%ecx),%eax
179 movl 8(%ebp),%ecx /* from */
180 movl PCPU(CURPCB),%eax
181 movl PCB_CR3(%eax),%eax
186 movl PCPU(TRAMPSTK),%esp
188 pf_x4: movzwl (%ecx),%eax
205 movl 8(%ebp),%ecx /* from */
206 movl PCPU(CURPCB),%eax
207 movl PCB_CR3(%eax),%eax
212 movl PCPU(TRAMPSTK),%esp
214 pf_x5: movzbl (%ecx),%eax
243 movl PCPU(CURPCB),%eax
244 movl PCB_CR3(%eax),%eax
246 movl 8(%ebp),%ecx /* to */
247 movl 12(%ebp),%edi /* val */
251 movl PCPU(TRAMPSTK),%esp
253 pf_x6: movl %edi,(%ecx)
271 movl PCPU(CURPCB),%eax
272 movl PCB_CR3(%eax),%eax
274 movl 8(%ebp),%ecx /* to */
275 movl 12(%ebp),%edi /* val */
279 movl PCPU(TRAMPSTK),%esp
281 pf_x7: movw %di,(%ecx)
299 movl PCPU(CURPCB),%eax
300 movl PCB_CR3(%eax),%eax
302 movl 8(%ebp),%ecx /* to */
303 movl 12(%ebp),%edi /* val */
307 movl PCPU(TRAMPSTK),%esp
310 pf_x8: movb %al,(%ecx)