4b090dee8c45f955e8f5953277516b19fc04a8d6
[dragonfly.git] / sys / platform / pc32 / i386 / bzero.s
1 /*
2  * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
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  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $DragonFly: src/sys/platform/pc32/i386/bzero.s,v 1.1 2004/04/29 17:24:58 dillon Exp $
27  */
28 /*
29  * void bzero(void *buf, u_int len)     (arguments passed on stack)
30  */
31
32 #include "use_npx.h"
33
34 #include <machine/asmacros.h>
35 #include <machine/cputypes.h>
36 #include <machine/pmap.h>
37 #include <machine/specialreg.h>
38
39 #include "assym.s"
40
41         .text
42
43 ENTRY(generic_bzero)
44         pushl   %edi
45         subl    %eax,%eax
46         movl    4+4(%esp),%edi
47         movl    8+4(%esp),%ecx
48         jmp     2f
49         SUPERALIGN_TEXT
50 1:
51         movl    %eax,(%edi)
52         movl    %eax,4(%edi)
53         addl    $8,%edi
54 2:
55         subl    $8,%ecx
56         jae     1b
57         addl    $8,%ecx
58         jz      3f
59         cld
60         rep
61         stosb
62 3:
63         popl    %edi
64         ret
65
66 ENTRY(i686_pagezero)
67         pushl   %edi
68         pushl   %ebx
69
70         movl    12(%esp), %edi
71         movl    $1024, %ecx
72         cld
73
74         ALIGN_TEXT
75 1:
76         xorl    %eax, %eax
77         repe
78         scasl   
79         jnz     2f
80
81         popl    %ebx
82         popl    %edi
83         ret
84
85         ALIGN_TEXT
86
87 2:
88         incl    %ecx
89         subl    $4, %edi
90
91         movl    %ecx, %edx
92         cmpl    $16, %ecx
93
94         jge     3f
95
96         movl    %edi, %ebx
97         andl    $0x3f, %ebx
98         shrl    %ebx
99         shrl    %ebx
100         movl    $16, %ecx
101         subl    %ebx, %ecx
102
103 3:
104         subl    %ecx, %edx
105         rep
106         stosl
107
108         movl    %edx, %ecx
109         testl   %edx, %edx
110         jnz     1b
111
112         popl    %ebx
113         popl    %edi
114         ret
115