18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// Copyright (C) 2005-2017 Andes Technology Corporation 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <linux/linkage.h> 58c2ecf20Sopenharmony_ci#include <asm/assembler.h> 68c2ecf20Sopenharmony_ci#include <asm/errno.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* Prototype: int __arch_clear_user(void *addr, size_t sz) 98c2ecf20Sopenharmony_ci * Purpose : clear some user memory 108c2ecf20Sopenharmony_ci * Params : addr - user memory address to clear 118c2ecf20Sopenharmony_ci * : sz - number of bytes to clear 128c2ecf20Sopenharmony_ci * Returns : number of bytes NOT cleared 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci .text 158c2ecf20Sopenharmony_ci .align 5 168c2ecf20Sopenharmony_ciENTRY(__arch_clear_user) 178c2ecf20Sopenharmony_ci add $r5, $r0, $r1 188c2ecf20Sopenharmony_ci beqz $r1, clear_exit 198c2ecf20Sopenharmony_ci xor $p1, $p1, $p1 ! Use $p1=0 to clear mem 208c2ecf20Sopenharmony_ci srli $p0, $r1, #2 ! $p0 = number of word to clear 218c2ecf20Sopenharmony_ci andi $r1, $r1, #3 ! Bytes less than a word to copy 228c2ecf20Sopenharmony_ci beqz $p0, byte_clear ! Only less than a word to clear 238c2ecf20Sopenharmony_ciword_clear: 248c2ecf20Sopenharmony_ciUSER( smw.bim,$p1, [$r0], $p1) ! Clear the word 258c2ecf20Sopenharmony_ci addi $p0, $p0, #-1 ! Decrease word count 268c2ecf20Sopenharmony_ci bnez $p0, word_clear ! Continue looping to clear all words 278c2ecf20Sopenharmony_ci beqz $r1, clear_exit ! No left bytes to copy 288c2ecf20Sopenharmony_cibyte_clear: 298c2ecf20Sopenharmony_ciUSER( sbi.bi, $p1, [$r0], #1) ! Clear the byte 308c2ecf20Sopenharmony_ci addi $r1, $r1, #-1 ! Decrease byte count 318c2ecf20Sopenharmony_ci bnez $r1, byte_clear ! Continue looping to clear all left bytes 328c2ecf20Sopenharmony_ciclear_exit: 338c2ecf20Sopenharmony_ci move $r0, $r1 ! Set return value 348c2ecf20Sopenharmony_ci ret 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci .section .fixup,"ax" 378c2ecf20Sopenharmony_ci .align 0 388c2ecf20Sopenharmony_ci9001: 398c2ecf20Sopenharmony_ci sub $r0, $r5, $r0 ! Bytes left to copy 408c2ecf20Sopenharmony_ci ret 418c2ecf20Sopenharmony_ci .previous 428c2ecf20Sopenharmony_ciENDPROC(__arch_clear_user) 43