1/* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include "asm.h" 32 33.syntax unified 34.arm 35 36// size_t _arm_clear_user(void *addr, size_t bytes) 37FUNCTION(_arm_clear_user) 38 push {r0-r6, lr} 39 cmp r1, #0 40 beq .Lclear_user_return 41 tst r0, #7 42 beq .Lclear_user_aligned 43 44.Lclear_user_byte: 45 mov r2, #0 460: strb r2, [r0], #1 47 subs r1, r1, #1 48 beq .Lclear_user_return 49 tst r0, #7 50 bne 0b 51 52.Lclear_user_aligned: 53 eor r3, r3 54 eor r4, r4 55 bics r2, r1, #15 56 bne .Lclear_user_16bytes 57 bics r2, r1, #7 58 bne .Lclear_user_8bytes 59 b .Lclear_user_remaining 60 61.Lclear_user_16bytes: 62 eor r5, r5 63 eor r6, r6 641: stmia r0!, {r3, r4, r5, r6} 65 subs r2, r2, #16 66 bne 1b 67 ands r1, r1, #15 68 beq .Lclear_user_return 69 bics r2, r1, #7 70 beq .Lclear_user_remaining 71 72.Lclear_user_8bytes: 732: stmia r0!, {r3, r4} 74 ands r1, r1, #7 75 beq .Lclear_user_return 76 77.Lclear_user_remaining: 78 mov r2, #0 793: strb r2, [r0], #1 80 subs r1, r1, #1 81 bne 3b 82 83.Lclear_user_return: 84 pop {r0-r6, lr} 85 mov r0, #0 86 bx lr 87 88.Lclear_user_err: 89 pop {r0, r1} 90 sub r0, r2, r0 91 sub r0, r1, r0 92 pop {r2-r6, lr} 93 bx lr 94 95.pushsection __exc_table, "a" 96 .long 0b, .Lclear_user_err 97 .long 1b, .Lclear_user_err 98 .long 2b, .Lclear_user_err 99 .long 3b, .Lclear_user_err 100.popsection 101