kernel - Fix some rare pmap races in i386 and x86_64.
[dragonfly.git] / sys / platform / pc32 / i386 / bzero.s
blob1dd1bb6a925f787383b7236d3c0b8f7d9a2e5732
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:
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.
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.
34 * $DragonFly: src/sys/platform/pc32/i386/bzero.s,v 1.5 2006/10/23 15:42:45 dillon Exp $
37 * void bzero(void *buf, u_int len) (arguments passed on stack)
40 #include "use_npx.h"
42 #include <machine/asmacros.h>
43 #include <machine/cputypes.h>
44 #include <machine/pmap.h>
45 #include <machine/specialreg.h>
47 #include "assym.s"
49 .text
52 * NOTE: GCC-4.x may call memset directly, we can't use an indirect pointer.
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
68 * Ignore inefficiencies due to alignment. Most callers will supply
69 * reasonably aligned pointers.
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
79 movl %eax,(%edi)
80 movl %eax,4(%edi)
81 addl $8,%edi
83 subl $8,%ecx
84 jae 1b
85 addl $8,%ecx
86 jz 3f
87 cld
88 rep
89 stosb
91 popl %edi
92 ret
94 ENTRY(i686_pagezero)
95 pushl %edi
96 pushl %ebx
98 movl 12(%esp), %edi
99 movl $1024, %ecx
102 ALIGN_TEXT
104 xorl %eax, %eax
105 repe
106 scasl
107 jnz 2f
109 popl %ebx
110 popl %edi
113 ALIGN_TEXT
116 incl %ecx
117 subl $4, %edi
119 movl %ecx, %edx
120 cmpl $16, %ecx
122 jge 3f
124 movl %edi, %ebx
125 andl $0x3f, %ebx
126 shrl %ebx
127 shrl %ebx
128 movl $16, %ecx
129 subl %ebx, %ecx
132 subl %ecx, %edx
134 stosl
136 movl %edx, %ecx
137 testl %edx, %edx
138 jnz 1b
140 popl %ebx
141 popl %edi