]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/i386/support.s
Remove the unused fuwintr() and suiwintr() functions.
[FreeBSD/FreeBSD.git] / sys / i386 / i386 / support.s
1 /*-
2  * Copyright (c) 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #include <machine/asmacros.h>
33 #include <machine/cputypes.h>
34 #include <machine/pmap.h>
35 #include <machine/specialreg.h>
36
37 #include "assym.inc"
38
39 #define IDXSHIFT        10
40
41         .text
42
43 /*
44  * bcopy family
45  * void bzero(void *buf, u_int len)
46  */
47 ENTRY(bzero)
48         pushl   %edi
49         movl    8(%esp),%edi
50         movl    12(%esp),%ecx
51         xorl    %eax,%eax
52         shrl    $2,%ecx
53         rep
54         stosl
55         movl    12(%esp),%ecx
56         andl    $3,%ecx
57         rep
58         stosb
59         popl    %edi
60         ret
61 END(bzero)
62
63 ENTRY(sse2_pagezero)
64         pushl   %ebx
65         movl    8(%esp),%ecx
66         movl    %ecx,%eax
67         addl    $4096,%eax
68         xor     %ebx,%ebx
69         jmp     1f
70         /*
71          * The loop takes 14 bytes.  Ensure that it doesn't cross a 16-byte
72          * cache line.
73          */
74         .p2align 4,0x90
75 1:
76         movnti  %ebx,(%ecx)
77         movnti  %ebx,4(%ecx)
78         addl    $8,%ecx
79         cmpl    %ecx,%eax
80         jne     1b
81         sfence
82         popl    %ebx
83         ret
84 END(sse2_pagezero)
85
86 ENTRY(i686_pagezero)
87         pushl   %edi
88         pushl   %ebx
89
90         movl    12(%esp),%edi
91         movl    $1024,%ecx
92
93         ALIGN_TEXT
94 1:
95         xorl    %eax,%eax
96         repe
97         scasl
98         jnz     2f
99
100         popl    %ebx
101         popl    %edi
102         ret
103
104         ALIGN_TEXT
105
106 2:
107         incl    %ecx
108         subl    $4,%edi
109
110         movl    %ecx,%edx
111         cmpl    $16,%ecx
112
113         jge     3f
114
115         movl    %edi,%ebx
116         andl    $0x3f,%ebx
117         shrl    %ebx
118         shrl    %ebx
119         movl    $16,%ecx
120         subl    %ebx,%ecx
121
122 3:
123         subl    %ecx,%edx
124         rep
125         stosl
126
127         movl    %edx,%ecx
128         testl   %edx,%edx
129         jnz     1b
130
131         popl    %ebx
132         popl    %edi
133         ret
134 END(i686_pagezero)
135
136 /* fillw(pat, base, cnt) */
137 ENTRY(fillw)
138         pushl   %edi
139         movl    8(%esp),%eax
140         movl    12(%esp),%edi
141         movl    16(%esp),%ecx
142         rep
143         stosw
144         popl    %edi
145         ret
146 END(fillw)
147
148 ENTRY(bcopyb)
149         pushl   %esi
150         pushl   %edi
151         movl    12(%esp),%esi
152         movl    16(%esp),%edi
153         movl    20(%esp),%ecx
154         movl    %edi,%eax
155         subl    %esi,%eax
156         cmpl    %ecx,%eax                       /* overlapping && src < dst? */
157         jb      1f
158         rep
159         movsb
160         popl    %edi
161         popl    %esi
162         ret
163
164         ALIGN_TEXT
165 1:
166         addl    %ecx,%edi                       /* copy backwards. */
167         addl    %ecx,%esi
168         decl    %edi
169         decl    %esi
170         std
171         rep
172         movsb
173         popl    %edi
174         popl    %esi
175         cld
176         ret
177 END(bcopyb)
178
179 /*
180  * bcopy(src, dst, cnt)
181  *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
182  */
183 ENTRY(bcopy)
184         pushl   %ebp
185         movl    %esp,%ebp
186         pushl   %esi
187         pushl   %edi
188         movl    8(%ebp),%esi
189         movl    12(%ebp),%edi
190         movl    16(%ebp),%ecx
191
192         movl    %edi,%eax
193         subl    %esi,%eax
194         cmpl    %ecx,%eax                       /* overlapping && src < dst? */
195         jb      1f
196
197         shrl    $2,%ecx                         /* copy by 32-bit words */
198         rep
199         movsl
200         movl    16(%ebp),%ecx
201         andl    $3,%ecx                         /* any bytes left? */
202         rep
203         movsb
204         popl    %edi
205         popl    %esi
206         popl    %ebp
207         ret
208
209         ALIGN_TEXT
210 1:
211         addl    %ecx,%edi                       /* copy backwards */
212         addl    %ecx,%esi
213         decl    %edi
214         decl    %esi
215         andl    $3,%ecx                         /* any fractional bytes? */
216         std
217         rep
218         movsb
219         movl    16(%ebp),%ecx                   /* copy remainder by 32-bit words */
220         shrl    $2,%ecx
221         subl    $3,%esi
222         subl    $3,%edi
223         rep
224         movsl
225         popl    %edi
226         popl    %esi
227         cld
228         popl    %ebp
229         ret
230 END(bcopy)
231
232 /*
233  * Note: memcpy does not support overlapping copies
234  */
235 ENTRY(memcpy)
236         pushl   %edi
237         pushl   %esi
238         movl    12(%esp),%edi
239         movl    16(%esp),%esi
240         movl    20(%esp),%ecx
241         movl    %edi,%eax
242         shrl    $2,%ecx                         /* copy by 32-bit words */
243         rep
244         movsl
245         movl    20(%esp),%ecx
246         andl    $3,%ecx                         /* any bytes left? */
247         rep
248         movsb
249         popl    %esi
250         popl    %edi
251         ret
252 END(memcpy)
253
254 /*
255  * copystr(from, to, maxlen, int *lencopied) - MP SAFE
256  */
257 ENTRY(copystr)
258         pushl   %esi
259         pushl   %edi
260
261         movl    12(%esp),%esi                   /* %esi = from */
262         movl    16(%esp),%edi                   /* %edi = to */
263         movl    20(%esp),%edx                   /* %edx = maxlen */
264         incl    %edx
265 1:
266         decl    %edx
267         jz      4f
268         lodsb
269         stosb
270         orb     %al,%al
271         jnz     1b
272
273         /* Success -- 0 byte reached */
274         decl    %edx
275         xorl    %eax,%eax
276         jmp     6f
277 4:
278         /* edx is zero -- return ENAMETOOLONG */
279         movl    $ENAMETOOLONG,%eax
280
281 6:
282         /* set *lencopied and return %eax */
283         movl    20(%esp),%ecx
284         subl    %edx,%ecx
285         movl    24(%esp),%edx
286         testl   %edx,%edx
287         jz      7f
288         movl    %ecx,(%edx)
289 7:
290         popl    %edi
291         popl    %esi
292         ret
293 END(copystr)
294
295 ENTRY(bcmp)
296         pushl   %edi
297         pushl   %esi
298         movl    12(%esp),%edi
299         movl    16(%esp),%esi
300         movl    20(%esp),%edx
301
302         movl    %edx,%ecx
303         shrl    $2,%ecx
304         repe
305         cmpsl
306         jne     1f
307
308         movl    %edx,%ecx
309         andl    $3,%ecx
310         repe
311         cmpsb
312 1:
313         setne   %al
314         movsbl  %al,%eax
315         popl    %esi
316         popl    %edi
317         ret
318 END(bcmp)
319
320 /*
321  * Handling of special 386 registers and descriptor tables etc
322  */
323 /* void lgdt(struct region_descriptor *rdp); */
324 ENTRY(lgdt)
325         /* reload the descriptor table */
326         movl    4(%esp),%eax
327         lgdt    (%eax)
328
329         /* flush the prefetch q */
330         jmp     1f
331         nop
332 1:
333         /* reload "stale" selectors */
334         movl    $KDSEL,%eax
335         movl    %eax,%ds
336         movl    %eax,%es
337         movl    %eax,%gs
338         movl    %eax,%ss
339         movl    $KPSEL,%eax
340         movl    %eax,%fs
341
342         /* reload code selector by turning return into intersegmental return */
343         movl    (%esp),%eax
344         pushl   %eax
345         movl    $KCSEL,4(%esp)
346         MEXITCOUNT
347         lret
348 END(lgdt)
349
350 /* ssdtosd(*ssdp,*sdp) */
351 ENTRY(ssdtosd)
352         pushl   %ebx
353         movl    8(%esp),%ecx
354         movl    8(%ecx),%ebx
355         shll    $16,%ebx
356         movl    (%ecx),%edx
357         roll    $16,%edx
358         movb    %dh,%bl
359         movb    %dl,%bh
360         rorl    $8,%ebx
361         movl    4(%ecx),%eax
362         movw    %ax,%dx
363         andl    $0xf0000,%eax
364         orl     %eax,%ebx
365         movl    12(%esp),%ecx
366         movl    %edx,(%ecx)
367         movl    %ebx,4(%ecx)
368         popl    %ebx
369         ret
370 END(ssdtosd)
371
372 /* void reset_dbregs() */
373 ENTRY(reset_dbregs)
374         movl    $0,%eax
375         movl    %eax,%dr7       /* disable all breakpoints first */
376         movl    %eax,%dr0
377         movl    %eax,%dr1
378         movl    %eax,%dr2
379         movl    %eax,%dr3
380         movl    %eax,%dr6
381         ret
382 END(reset_dbregs)
383
384 /*****************************************************************************/
385 /* setjump, longjump                                                         */
386 /*****************************************************************************/
387
388 ENTRY(setjmp)
389         movl    4(%esp),%eax
390         movl    %ebx,(%eax)                     /* save ebx */
391         movl    %esp,4(%eax)                    /* save esp */
392         movl    %ebp,8(%eax)                    /* save ebp */
393         movl    %esi,12(%eax)                   /* save esi */
394         movl    %edi,16(%eax)                   /* save edi */
395         movl    (%esp),%edx                     /* get rta */
396         movl    %edx,20(%eax)                   /* save eip */
397         xorl    %eax,%eax                       /* return(0); */
398         ret
399 END(setjmp)
400
401 ENTRY(longjmp)
402         movl    4(%esp),%eax
403         movl    (%eax),%ebx                     /* restore ebx */
404         movl    4(%eax),%esp                    /* restore esp */
405         movl    8(%eax),%ebp                    /* restore ebp */
406         movl    12(%eax),%esi                   /* restore esi */
407         movl    16(%eax),%edi                   /* restore edi */
408         movl    20(%eax),%edx                   /* get rta */
409         movl    %edx,(%esp)                     /* put in return frame */
410         xorl    %eax,%eax                       /* return(1); */
411         incl    %eax
412         ret
413 END(longjmp)
414
415 /*
416  * Support for reading MSRs in the safe manner.  (Instead of panic on #gp,
417  * return an error.)
418  */
419 ENTRY(rdmsr_safe)
420 /* int rdmsr_safe(u_int msr, uint64_t *data) */
421         movl    PCPU(CURPCB),%ecx
422         movl    $msr_onfault,PCB_ONFAULT(%ecx)
423
424         movl    4(%esp),%ecx
425         rdmsr
426         movl    8(%esp),%ecx
427         movl    %eax,(%ecx)
428         movl    %edx,4(%ecx)
429         xorl    %eax,%eax
430
431         movl    PCPU(CURPCB),%ecx
432         movl    %eax,PCB_ONFAULT(%ecx)
433
434         ret
435
436 /*
437  * Support for writing MSRs in the safe manner.  (Instead of panic on #gp,
438  * return an error.)
439  */
440 ENTRY(wrmsr_safe)
441 /* int wrmsr_safe(u_int msr, uint64_t data) */
442         movl    PCPU(CURPCB),%ecx
443         movl    $msr_onfault,PCB_ONFAULT(%ecx)
444
445         movl    4(%esp),%ecx
446         movl    8(%esp),%eax
447         movl    12(%esp),%edx
448         wrmsr
449         xorl    %eax,%eax
450
451         movl    PCPU(CURPCB),%ecx
452         movl    %eax,PCB_ONFAULT(%ecx)
453
454         ret
455
456 /*
457  * MSR operations fault handler
458  */
459         ALIGN_TEXT
460 msr_onfault:
461         movl    PCPU(CURPCB),%ecx
462         movl    $0,PCB_ONFAULT(%ecx)
463         movl    $EFAULT,%eax
464         ret
465
466 ENTRY(handle_ibrs_entry)
467         ret
468 END(handle_ibrs_entry)
469
470 ENTRY(handle_ibrs_exit)
471         ret
472 END(handle_ibrs_exit)