Merge from vendor branch LESS:
[dragonfly.git] / sys / platform / pc32 / i386 / bzero.s
1 /*
2  * Copyright (c) 2003,2004 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sys/platform/pc32/i386/bzero.s,v 1.5 2006/10/23 15:42:45 dillon Exp $
35  */
36 /*
37  * void bzero(void *buf, u_int len)     (arguments passed on stack)
38  */
39
40 #include "use_npx.h"
41
42 #include <machine/asmacros.h>
43 #include <machine/cputypes.h>
44 #include <machine/pmap.h>
45 #include <machine/specialreg.h>
46
47 #include "assym.s"
48
49         .text
50
51 /*
52  * NOTE: GCC-4.x may call memset directly, we can't use an indirect pointer.
53  */
54 ENTRY(memset)
55         pushl   %edi
56         movl    4+4(%esp),%edi
57         movl    12+4(%esp),%ecx
58         movzbl  8+4(%esp),%eax
59         movl    %eax,%edx
60         shll    $8,%edx
61         orl     %edx,%eax
62         movl    %eax,%edx
63         shll    $16,%edx
64         orl     %edx,%eax
65         jmp     2f
66
67 /*
68  * Ignore inefficiencies due to alignment.  Most callers will supply
69  * reasonably aligned pointers.
70  */
71 ENTRY(bzero)
72         pushl   %edi
73         subl    %eax,%eax
74         movl    4+4(%esp),%edi
75         movl    8+4(%esp),%ecx
76         jmp     2f
77         SUPERALIGN_TEXT
78 1:
79         movl    %eax,(%edi)
80         movl    %eax,4(%edi)
81         addl    $8,%edi
82 2:
83         subl    $8,%ecx
84         jae     1b
85         addl    $8,%ecx
86         jz      3f
87         cld
88         rep
89         stosb
90 3:
91         popl    %edi
92         ret
93
94 ENTRY(i686_pagezero)
95         pushl   %edi
96         pushl   %ebx
97
98         movl    12(%esp), %edi
99         movl    $1024, %ecx
100         cld
101
102         ALIGN_TEXT
103 1:
104         xorl    %eax, %eax
105         repe
106         scasl   
107         jnz     2f
108
109         popl    %ebx
110         popl    %edi
111         ret
112
113         ALIGN_TEXT
114
115 2:
116         incl    %ecx
117         subl    $4, %edi
118
119         movl    %ecx, %edx
120         cmpl    $16, %ecx
121
122         jge     3f
123
124         movl    %edi, %ebx
125         andl    $0x3f, %ebx
126         shrl    %ebx
127         shrl    %ebx
128         movl    $16, %ecx
129         subl    %ebx, %ecx
130
131 3:
132         subl    %ecx, %edx
133         rep
134         stosl
135
136         movl    %edx, %ecx
137         testl   %edx, %edx
138         jnz     1b
139
140         popl    %ebx
141         popl    %edi
142         ret
143