2 * Copyright (c) 2012 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 * This file implements the following functions for the arm64 architecture:
30 * void bzero(void *buffer, size_t length);
31 * void __bzero(void *buffer, size_t length);
32 * void *memset(void *buffer, int value, size_t length);
34 * The first two zero-fill a buffer. The third fills the buffer with the low
35 * byte of its second argument.
45 /*****************************************************************************
47 *****************************************************************************/
61 /*****************************************************************************
62 * Large buffer zero engine *
63 *****************************************************************************/
66 // Write the first 64 bytes of the buffer without regard to alignment, then
67 // advance x3 to point to a cacheline-aligned location within the buffer, and
68 // decrement the length accordingly.
75 add x2, x2, x0 // end of buffer
76 add x4, x3, #64 // end of first cacheline to zero
77 subs x2, x2, x4 // if the end of the buffer comes first, jump
78 b.ls 1f // directly to the cleanup pass.
79 0: dc zva, x3 // zero cacheline
80 add x3, x3, #64 // increment pointer
81 subs x2, x2, #64 // decrement length
83 1: add x3, x3, x2 // back up pointer to (end of buffer) - 64.
84 stp x1, x1, [x3] // and store 64 bytes to reach end of buffer.
91 /*****************************************************************************
93 *****************************************************************************/
97 * It is important that secure_memset remains defined in assembly to avoid
98 * compiler optimizations.
105 orr x3, xzr,#0x0101010101010101
111 /*****************************************************************************
112 * Large buffer store engine *
113 *****************************************************************************/
116 // Write the first 64 bytes of the buffer without regard to alignment, then
117 // advance x3 to point to an aligned location within the buffer, and
118 // decrement the length accordingly.
122 add x2, x2, x0 // end of buffer
123 add x4, x3, #64 // end of first aligned 64-byte store
124 subs x2, x2, x4 // if the end of the buffer comes first, jump
125 b.ls 1f // directly to the cleanup store.
127 stnp x1, x1, [x3, #16]
128 stnp x1, x1, [x3, #32]
129 stnp x1, x1, [x3, #48]
133 1: add x3, x3, x2 // back up pointer to (end of buffer) - 64.
135 stp x1, x1, [x3, #16]
136 stp x1, x1, [x3, #32]
137 stp x1, x1, [x3, #48]
141 /*****************************************************************************
142 * Small buffer store engine *
143 *****************************************************************************/