2 * SPDX-License-Identifier: BSD-2-Clause
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
31 #include <machine/asmacros.h>
32 #include <machine/cputypes.h>
33 #include <machine/pmap.h>
34 #include <machine/specialreg.h>
39 * Fast path for copyout code. We switch to user space %cr3 and perform
40 * move operation between user memory and copyout buffer, located in the
41 * trampoline area. We must switch to trampoline stack, because both
42 * user and kernel buffer accesses might cause page fault.
44 * Page fault handler expects %edx to point to the onfault routine.
45 * Handler switches to idlePTD and calls the routine.
46 * The routine must restore the stack, enable interrupts, and
47 * return to the caller, informing it about failure.
58 movl 20(%ebp),%ebx /* KCR3 */
59 /* bcopy(%esi = kaddr, %edi = PCPU(copyout_buf), %ecx = len) */
63 movl $copyout_fault,%edx
66 movl PCPU(COPYOUT_BUF),%edi
69 movl 16(%ebp),%ecx /* len */
70 movl PCPU(COPYOUT_BUF),%esi /* kaddr */
71 movl 12(%ebp),%edi /* uaddr */
72 movl PCPU(TRAMPSTK),%esp
73 movl PCPU(CURPCB),%edx
74 movl PCB_CR3(%edx),%edx /* UCR3 */
76 movl $copyout_fault,%edx
77 /* bcopy(%esi = PCPU(copyout_buf), %edi = udaddr, %ecx = len) */
98 movl 20(%ebp),%ebx /* KCR3 */
99 movl PCPU(CURPCB),%eax
100 movl PCB_CR3(%eax),%edx /* UCR3 */
101 movl 16(%ebp),%ecx /* len */
102 movl 8(%ebp),%esi /* udaddr */
106 movl PCPU(COPYOUT_BUF),%edi /* kaddr */
107 movl PCPU(TRAMPSTK),%esp
109 movl $copyout_fault,%edx
110 /* bcopy(%esi = udaddr, %edi = PCPU(copyout_buf), %ecx = len) */
116 /* bcopy(%esi = PCPU(copyout_buf), %edi = kaddr, %ecx = len) */
119 movl PCPU(COPYOUT_BUF),%esi
148 movl 8(%ebp),%ecx /* from */
149 movl PCPU(CURPCB),%eax
150 movl PCB_CR3(%eax),%eax
155 movl PCPU(TRAMPSTK),%esp
157 pf_x3: movl (%ecx),%eax
177 movl 8(%ebp),%ecx /* from */
178 movl PCPU(CURPCB),%eax
179 movl PCB_CR3(%eax),%eax
184 movl PCPU(TRAMPSTK),%esp
186 pf_x4: movzwl (%ecx),%eax
203 movl 8(%ebp),%ecx /* from */
204 movl PCPU(CURPCB),%eax
205 movl PCB_CR3(%eax),%eax
210 movl PCPU(TRAMPSTK),%esp
212 pf_x5: movzbl (%ecx),%eax
241 movl PCPU(CURPCB),%eax
242 movl PCB_CR3(%eax),%eax
244 movl 8(%ebp),%ecx /* to */
245 movl 12(%ebp),%edi /* val */
249 movl PCPU(TRAMPSTK),%esp
251 pf_x6: movl %edi,(%ecx)
269 movl PCPU(CURPCB),%eax
270 movl PCB_CR3(%eax),%eax
272 movl 8(%ebp),%ecx /* to */
273 movl 12(%ebp),%edi /* val */
277 movl PCPU(TRAMPSTK),%esp
279 pf_x7: movw %di,(%ecx)
297 movl PCPU(CURPCB),%eax
298 movl PCB_CR3(%eax),%eax
300 movl 8(%ebp),%ecx /* to */
301 movl 12(%ebp),%edi /* val */
305 movl PCPU(TRAMPSTK),%esp
308 pf_x8: movb %al,(%ecx)