]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/i386/copyout_fast.s
i386 doreti: Fix calculation of stack frame size
[FreeBSD/FreeBSD.git] / sys / i386 / i386 / copyout_fast.s
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2018 The FreeBSD Foundation
5  *
6  * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
7  * under sponsorship from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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.
17  *
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
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32
33 #include <machine/asmacros.h>
34 #include <machine/cputypes.h>
35 #include <machine/pmap.h>
36 #include <machine/specialreg.h>
37
38 #include "assym.inc"
39
40         .text
41
42 ENTRY(copyout_fast)
43         pushl   %ebp
44         movl    %esp, %ebp
45         pushl   %esi
46         pushl   %edi
47         pushl   %ebx
48
49         movl    $copyout_fault,%edx
50         movl    20(%ebp),%ebx   /* KCR3 */
51
52         movl    PCPU(CURPCB),%eax
53         movl    PCB_CR3(%eax),%edi
54
55         cli
56         movl    PCPU(TRAMPSTK),%esi
57         movl    PCPU(COPYOUT_BUF),%eax
58         subl    $4,%esi
59         movl    %eax,(%esi)
60         movl    12(%ebp),%eax   /* udaddr */
61         subl    $4,%esi
62         movl    %eax,(%esi)
63         movl    16(%ebp),%eax   /* len */
64         subl    $4,%esi
65         movl    %eax,(%esi)
66
67         subl    $4, %esi
68         movl    %edi, (%esi)
69
70         movl    8(%ebp),%eax    /* kaddr */
71         subl    $4,%esi
72         movl    %eax,(%esi)
73         movl    PCPU(COPYOUT_BUF),%eax
74         subl    $4,%esi
75         movl    %eax,(%esi)
76         movl    16(%ebp),%eax   /* len */
77         subl    $4,%esi
78         movl    %eax,(%esi)
79
80         movl    %esp,%eax
81         movl    %esi,%esp
82
83         /* bcopy(%esi = kaddr, %edi = PCPU(copyout_buf), %ecx = len) */
84         popl    %ecx
85         popl    %edi
86         popl    %esi
87         rep; movsb
88
89         popl    %edi
90         movl    %edi,%cr3
91
92         /* bcopy(%esi = PCPU(copyout_buf), %edi = udaddr, %ecx = len) */
93         popl    %ecx
94         popl    %edi
95         popl    %esi
96 pf_x1:  rep; movsb
97
98         movl    %ebx,%cr3
99         movl    %eax,%esp
100         sti
101
102         xorl    %eax,%eax
103         popl    %ebx
104         popl    %edi
105         popl    %esi
106         leave
107         ret
108 END(copyout_fast)
109
110 ENTRY(copyin_fast)
111         pushl   %ebp
112         movl    %esp, %ebp
113         pushl   %esi
114         pushl   %edi
115         pushl   %ebx
116
117         movl    $copyout_fault,%edx
118         movl    20(%ebp),%ebx   /* KCR3 */
119
120         movl    PCPU(CURPCB),%eax
121         movl    PCB_CR3(%eax),%edi
122
123         cli
124         movl    PCPU(TRAMPSTK),%esi
125         movl    PCPU(COPYOUT_BUF),%eax
126         subl    $4,%esi
127         movl    %eax,(%esi)
128         movl    12(%ebp),%eax   /* kaddr */
129         subl    $4,%esi
130         movl    %eax,(%esi)
131         movl    16(%ebp),%eax   /* len */
132         subl    $4,%esi
133         movl    %eax,(%esi)
134
135         movl    8(%ebp),%eax    /* udaddr */
136         subl    $4,%esi
137         movl    %eax,(%esi)
138         movl    PCPU(COPYOUT_BUF),%eax
139         subl    $4,%esi
140         movl    %eax,(%esi)
141         movl    16(%ebp),%eax   /* len */
142         subl    $4,%esi
143         movl    %eax,(%esi)
144
145         movl    %esp,%eax
146         movl    %esi,%esp
147         movl    %edi,%cr3
148
149         /* bcopy(%esi = udaddr, %edi = PCPU(copyout_buf), %ecx = len) */
150         popl    %ecx
151         popl    %edi
152         popl    %esi
153 pf_x2:  rep; movsb
154
155         movl    %ebx,%cr3
156
157         /* bcopy(%esi = PCPU(copyout_buf), %edi = kaddr, %ecx = len) */
158         popl    %ecx
159         popl    %edi
160         popl    %esi
161         rep; movsb
162
163         movl    %eax,%esp
164         sti
165
166         xorl    %eax,%eax
167         popl    %ebx
168         popl    %edi
169         popl    %esi
170         leave
171         ret
172 END(copyin_fast)
173
174         ALIGN_TEXT
175 copyout_fault:
176         movl    %eax,%esp
177         sti
178         movl    $EFAULT,%eax
179         popl    %ebx
180         popl    %edi
181         popl    %esi
182         leave
183         ret
184
185 ENTRY(fueword_fast)
186         pushl   %ebp
187         movl    %esp,%ebp
188         pushl   %ebx
189         pushl   %esi
190         pushl   %edi
191         movl    8(%ebp),%ecx                    /* from */
192         movl    PCPU(CURPCB),%eax
193         movl    PCB_CR3(%eax),%eax
194         movl    $fusufault,%edx
195         movl    16(%ebp),%ebx
196         movl    %esp,%esi
197         cli
198         movl    PCPU(TRAMPSTK),%esp
199         movl    %eax,%cr3
200 pf_x3:  movl    (%ecx),%eax
201         movl    %ebx,%cr3
202         movl    %esi,%esp
203         sti
204         movl    12(%ebp),%edx
205         movl    %eax,(%edx)
206         xorl    %eax,%eax
207         popl    %edi
208         popl    %esi
209         popl    %ebx
210         leave
211         ret
212 END(fueword_fast)
213
214 ENTRY(fuword16_fast)
215         pushl   %ebp
216         movl    %esp,%ebp
217         pushl   %ebx
218         pushl   %esi
219         pushl   %edi
220         movl    8(%ebp),%ecx                    /* from */
221         movl    PCPU(CURPCB),%eax
222         movl    PCB_CR3(%eax),%eax
223         movl    $fusufault,%edx
224         movl    12(%ebp),%ebx
225         movl    %esp,%esi
226         cli
227         movl    PCPU(TRAMPSTK),%esp
228         movl    %eax,%cr3
229 pf_x4:  movzwl  (%ecx),%eax
230         movl    %ebx,%cr3
231         movl    %esi,%esp
232         sti
233         popl    %edi
234         popl    %esi
235         popl    %ebx
236         leave
237         ret
238 END(fuword16_fast)
239
240 ENTRY(fubyte_fast)
241         pushl   %ebp
242         movl    %esp,%ebp
243         pushl   %ebx
244         pushl   %esi
245         pushl   %edi
246         movl    8(%ebp),%ecx                    /* from */
247         movl    PCPU(CURPCB),%eax
248         movl    PCB_CR3(%eax),%eax
249         movl    $fusufault,%edx
250         movl    12(%ebp),%ebx
251         movl    %esp,%esi
252         cli
253         movl    PCPU(TRAMPSTK),%esp
254         movl    %eax,%cr3
255 pf_x5:  movzbl  (%ecx),%eax
256         movl    %ebx,%cr3
257         movl    %esi,%esp
258         sti
259         popl    %edi
260         popl    %esi
261         popl    %ebx
262         leave
263         ret
264 END(fubyte_fast)
265
266         ALIGN_TEXT
267 fusufault:
268         movl    %esi,%esp
269         sti
270         xorl    %eax,%eax
271         decl    %eax
272         popl    %edi
273         popl    %esi
274         popl    %ebx
275         leave
276         ret
277
278 ENTRY(suword_fast)
279         pushl   %ebp
280         movl    %esp,%ebp
281         pushl   %ebx
282         pushl   %esi
283         pushl   %edi
284         movl    PCPU(CURPCB),%eax
285         movl    PCB_CR3(%eax),%eax
286         movl    $fusufault,%edx
287         movl    8(%ebp),%ecx                    /* to */
288         movl    12(%ebp),%edi                   /* val */
289         movl    16(%ebp),%ebx
290         movl    %esp,%esi
291         cli
292         movl    PCPU(TRAMPSTK),%esp
293         movl    %eax,%cr3
294 pf_x6:  movl    %edi,(%ecx)
295         movl    %ebx,%cr3
296         movl    %esi,%esp
297         sti
298         xorl    %eax,%eax
299         popl    %edi
300         popl    %esi
301         popl    %ebx
302         leave
303         ret
304 END(suword_fast)
305
306 ENTRY(suword16_fast)
307         pushl   %ebp
308         movl    %esp,%ebp
309         pushl   %ebx
310         pushl   %esi
311         pushl   %edi
312         movl    PCPU(CURPCB),%eax
313         movl    PCB_CR3(%eax),%eax
314         movl    $fusufault,%edx
315         movl    8(%ebp),%ecx                    /* to */
316         movl    12(%ebp),%edi                   /* val */
317         movl    16(%ebp),%ebx
318         movl    %esp,%esi
319         cli
320         movl    PCPU(TRAMPSTK),%esp
321         movl    %eax,%cr3
322 pf_x7:  movw    %di,(%ecx)
323         movl    %ebx,%cr3
324         movl    %esi,%esp
325         sti
326         xorl    %eax,%eax
327         popl    %edi
328         popl    %esi
329         popl    %ebx
330         leave
331         ret
332 END(suword16_fast)
333
334 ENTRY(subyte_fast)
335         pushl   %ebp
336         movl    %esp,%ebp
337         pushl   %ebx
338         pushl   %esi
339         pushl   %edi
340         movl    PCPU(CURPCB),%eax
341         movl    PCB_CR3(%eax),%eax
342         movl    $fusufault,%edx
343         movl    8(%ebp),%ecx                    /* to */
344         movl    12(%ebp),%edi                   /* val */
345         movl    16(%ebp),%ebx
346         movl    %esp,%esi
347         cli
348         movl    PCPU(TRAMPSTK),%esp
349         movl    %eax,%cr3
350         movl    %edi,%eax
351 pf_x8:  movb    %al,(%ecx)
352         movl    %ebx,%cr3
353         movl    %esi,%esp
354         sti
355         xorl    %eax,%eax
356         popl    %edi
357         popl    %esi
358         popl    %ebx
359         leave
360         ret
361 END(subyte_fast)