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 *****************************************************************************/
60 /*****************************************************************************
61 * Large buffer zero engine *
62 *****************************************************************************/
65 // Write the first 64 bytes of the buffer without regard to alignment, then
66 // advance x3 to point to a cacheline-aligned location within the buffer, and
67 // decrement the length accordingly.
74 add x2, x2, x0 // end of buffer
75 add x4, x3, #64 // end of first cacheline to zero
76 subs x2, x2, x4 // if the end of the buffer comes first, jump
77 b.ls 1f // directly to the cleanup pass.
78 0: dc zva, x3 // zero cacheline
79 add x3, x3, #64 // increment pointer
80 subs x2, x2, #64 // decrement length
82 1: add x3, x3, x2 // back up pointer to (end of buffer) - 64.
83 stp x1, x1, [x3] // and store 64 bytes to reach end of buffer.
90 /*****************************************************************************
92 *****************************************************************************/
96 * It is important that secure_memset remains defined in assembly to avoid
97 * compiler optimizations.
103 orr x3, xzr,#0x0101010101010101
109 /*****************************************************************************
110 * Large buffer store engine *
111 *****************************************************************************/
114 // Write the first 64 bytes of the buffer without regard to alignment, then
115 // advance x3 to point to an aligned location within the buffer, and
116 // decrement the length accordingly.
120 add x2, x2, x0 // end of buffer
121 add x4, x3, #64 // end of first aligned 64-byte store
122 subs x2, x2, x4 // if the end of the buffer comes first, jump
123 b.ls 1f // directly to the cleanup store.
125 stnp x1, x1, [x3, #16]
126 stnp x1, x1, [x3, #32]
127 stnp x1, x1, [x3, #48]
131 1: add x3, x3, x2 // back up pointer to (end of buffer) - 64.
133 stp x1, x1, [x3, #16]
134 stp x1, x1, [x3, #32]
135 stp x1, x1, [x3, #48]
139 /*****************************************************************************
140 * Small buffer store engine *
141 *****************************************************************************/