1*0f4c859eSApple OSS Distributions/* 2*0f4c859eSApple OSS Distributions * Copyright (c) 2012 Apple Computer, Inc. All rights reserved. 3*0f4c859eSApple OSS Distributions * 4*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*0f4c859eSApple OSS Distributions * 6*0f4c859eSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*0f4c859eSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*0f4c859eSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*0f4c859eSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*0f4c859eSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*0f4c859eSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*0f4c859eSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*0f4c859eSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*0f4c859eSApple OSS Distributions * 15*0f4c859eSApple OSS Distributions * Please obtain a copy of the License at 16*0f4c859eSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*0f4c859eSApple OSS Distributions * 18*0f4c859eSApple OSS Distributions * The Original Code and all software distributed under the License are 19*0f4c859eSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*0f4c859eSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*0f4c859eSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*0f4c859eSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*0f4c859eSApple OSS Distributions * Please see the License for the specific language governing rights and 24*0f4c859eSApple OSS Distributions * limitations under the License. 25*0f4c859eSApple OSS Distributions * 26*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*0f4c859eSApple OSS Distributions * 28*0f4c859eSApple OSS Distributions * This file implements the following functions for the arm64 architecture: 29*0f4c859eSApple OSS Distributions * 30*0f4c859eSApple OSS Distributions * void bzero(void *buffer, size_t length); 31*0f4c859eSApple OSS Distributions * void __bzero(void *buffer, size_t length); 32*0f4c859eSApple OSS Distributions * void *memset(void *buffer, int value, size_t length); 33*0f4c859eSApple OSS Distributions * 34*0f4c859eSApple OSS Distributions * The first two zero-fill a buffer. The third fills the buffer with the low 35*0f4c859eSApple OSS Distributions * byte of its second argument. 36*0f4c859eSApple OSS Distributions */ 37*0f4c859eSApple OSS Distributions 38*0f4c859eSApple OSS Distributions#include "asm.h" 39*0f4c859eSApple OSS Distributions 40*0f4c859eSApple OSS Distributions.globl _bzero 41*0f4c859eSApple OSS Distributions.globl ___bzero 42*0f4c859eSApple OSS Distributions.globl _memset 43*0f4c859eSApple OSS Distributions.globl _secure_memset 44*0f4c859eSApple OSS Distributions 45*0f4c859eSApple OSS Distributions/***************************************************************************** 46*0f4c859eSApple OSS Distributions * bzero entrypoint * 47*0f4c859eSApple OSS Distributions *****************************************************************************/ 48*0f4c859eSApple OSS Distributions 49*0f4c859eSApple OSS Distributions.text 50*0f4c859eSApple OSS Distributions.align 4 51*0f4c859eSApple OSS Distributions_bzero: 52*0f4c859eSApple OSS Distributions___bzero: 53*0f4c859eSApple OSS Distributions ARM64_STACK_PROLOG 54*0f4c859eSApple OSS Distributions PUSH_FRAME 55*0f4c859eSApple OSS Distributions mov x2, x1 56*0f4c859eSApple OSS Distributions eor x1, x1, x1 57*0f4c859eSApple OSS Distributions mov x3, x0 58*0f4c859eSApple OSS Distributions cmp x2, #128 59*0f4c859eSApple OSS Distributions b.cc L_memsetSmall 60*0f4c859eSApple OSS Distributions 61*0f4c859eSApple OSS Distributions/***************************************************************************** 62*0f4c859eSApple OSS Distributions * Large buffer zero engine * 63*0f4c859eSApple OSS Distributions *****************************************************************************/ 64*0f4c859eSApple OSS Distributions 65*0f4c859eSApple OSS DistributionsL_bzeroLarge: 66*0f4c859eSApple OSS Distributions// Write the first 64 bytes of the buffer without regard to alignment, then 67*0f4c859eSApple OSS Distributions// advance x3 to point to a cacheline-aligned location within the buffer, and 68*0f4c859eSApple OSS Distributions// decrement the length accordingly. 69*0f4c859eSApple OSS Distributions stp x1, x1, [x0] 70*0f4c859eSApple OSS Distributions stp x1, x1, [x0, #16] 71*0f4c859eSApple OSS Distributions stp x1, x1, [x0, #32] 72*0f4c859eSApple OSS Distributions stp x1, x1, [x0, #48] 73*0f4c859eSApple OSS Distributions add x3, x0, #64 74*0f4c859eSApple OSS Distributions and x3, x3, #-64 75*0f4c859eSApple OSS Distributions add x2, x2, x0 // end of buffer 76*0f4c859eSApple OSS Distributions add x4, x3, #64 // end of first cacheline to zero 77*0f4c859eSApple OSS Distributions subs x2, x2, x4 // if the end of the buffer comes first, jump 78*0f4c859eSApple OSS Distributions b.ls 1f // directly to the cleanup pass. 79*0f4c859eSApple OSS Distributions0: dc zva, x3 // zero cacheline 80*0f4c859eSApple OSS Distributions add x3, x3, #64 // increment pointer 81*0f4c859eSApple OSS Distributions subs x2, x2, #64 // decrement length 82*0f4c859eSApple OSS Distributions b.hi 0b 83*0f4c859eSApple OSS Distributions1: add x3, x3, x2 // back up pointer to (end of buffer) - 64. 84*0f4c859eSApple OSS Distributions stp x1, x1, [x3] // and store 64 bytes to reach end of buffer. 85*0f4c859eSApple OSS Distributions stp x1, x1, [x3, #16] 86*0f4c859eSApple OSS Distributions stp x1, x1, [x3, #32] 87*0f4c859eSApple OSS Distributions stp x1, x1, [x3, #48] 88*0f4c859eSApple OSS Distributions POP_FRAME 89*0f4c859eSApple OSS Distributions ARM64_STACK_EPILOG 90*0f4c859eSApple OSS Distributions 91*0f4c859eSApple OSS Distributions/***************************************************************************** 92*0f4c859eSApple OSS Distributions * memset entrypoint * 93*0f4c859eSApple OSS Distributions *****************************************************************************/ 94*0f4c859eSApple OSS Distributions 95*0f4c859eSApple OSS Distributions.align 4 96*0f4c859eSApple OSS Distributions/* 97*0f4c859eSApple OSS Distributions * It is important that secure_memset remains defined in assembly to avoid 98*0f4c859eSApple OSS Distributions * compiler optimizations. 99*0f4c859eSApple OSS Distributions */ 100*0f4c859eSApple OSS Distributions_secure_memset: 101*0f4c859eSApple OSS Distributions_memset: 102*0f4c859eSApple OSS Distributions ARM64_STACK_PROLOG 103*0f4c859eSApple OSS Distributions PUSH_FRAME 104*0f4c859eSApple OSS Distributions and x1, x1, #0xff 105*0f4c859eSApple OSS Distributions orr x3, xzr,#0x0101010101010101 106*0f4c859eSApple OSS Distributions mul x1, x1, x3 107*0f4c859eSApple OSS Distributions mov x3, x0 108*0f4c859eSApple OSS Distributions cmp x2, #64 109*0f4c859eSApple OSS Distributions b.cc L_memsetSmall 110*0f4c859eSApple OSS Distributions 111*0f4c859eSApple OSS Distributions/***************************************************************************** 112*0f4c859eSApple OSS Distributions * Large buffer store engine * 113*0f4c859eSApple OSS Distributions *****************************************************************************/ 114*0f4c859eSApple OSS Distributions 115*0f4c859eSApple OSS DistributionsL_memsetLarge: 116*0f4c859eSApple OSS Distributions// Write the first 64 bytes of the buffer without regard to alignment, then 117*0f4c859eSApple OSS Distributions// advance x3 to point to an aligned location within the buffer, and 118*0f4c859eSApple OSS Distributions// decrement the length accordingly. 119*0f4c859eSApple OSS Distributions stp x1, x1, [x0] 120*0f4c859eSApple OSS Distributions add x3, x0, #16 121*0f4c859eSApple OSS Distributions and x3, x3, #-16 122*0f4c859eSApple OSS Distributions add x2, x2, x0 // end of buffer 123*0f4c859eSApple OSS Distributions add x4, x3, #64 // end of first aligned 64-byte store 124*0f4c859eSApple OSS Distributions subs x2, x2, x4 // if the end of the buffer comes first, jump 125*0f4c859eSApple OSS Distributions b.ls 1f // directly to the cleanup store. 126*0f4c859eSApple OSS Distributions0: stnp x1, x1, [x3] 127*0f4c859eSApple OSS Distributions stnp x1, x1, [x3, #16] 128*0f4c859eSApple OSS Distributions stnp x1, x1, [x3, #32] 129*0f4c859eSApple OSS Distributions stnp x1, x1, [x3, #48] 130*0f4c859eSApple OSS Distributions add x3, x3, #64 131*0f4c859eSApple OSS Distributions subs x2, x2, #64 132*0f4c859eSApple OSS Distributions b.hi 0b 133*0f4c859eSApple OSS Distributions1: add x3, x3, x2 // back up pointer to (end of buffer) - 64. 134*0f4c859eSApple OSS Distributions stp x1, x1, [x3] 135*0f4c859eSApple OSS Distributions stp x1, x1, [x3, #16] 136*0f4c859eSApple OSS Distributions stp x1, x1, [x3, #32] 137*0f4c859eSApple OSS Distributions stp x1, x1, [x3, #48] 138*0f4c859eSApple OSS Distributions POP_FRAME 139*0f4c859eSApple OSS Distributions ARM64_STACK_EPILOG 140*0f4c859eSApple OSS Distributions 141*0f4c859eSApple OSS Distributions/***************************************************************************** 142*0f4c859eSApple OSS Distributions * Small buffer store engine * 143*0f4c859eSApple OSS Distributions *****************************************************************************/ 144*0f4c859eSApple OSS Distributions 145*0f4c859eSApple OSS Distributions0: str x1, [x3],#8 146*0f4c859eSApple OSS DistributionsL_memsetSmall: 147*0f4c859eSApple OSS Distributions subs x2, x2, #8 148*0f4c859eSApple OSS Distributions b.cs 0b 149*0f4c859eSApple OSS Distributions adds x2, x2, #8 150*0f4c859eSApple OSS Distributions b.eq 2f 151*0f4c859eSApple OSS Distributions1: strb w1, [x3],#1 152*0f4c859eSApple OSS Distributions subs x2, x2, #1 153*0f4c859eSApple OSS Distributions b.ne 1b 154*0f4c859eSApple OSS Distributions2: POP_FRAME 155*0f4c859eSApple OSS Distributions ARM64_STACK_EPILOG 156*0f4c859eSApple OSS Distributions 157