^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 1996, 1998, 1999, 2004 by Ralf Baechle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 1999 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/regdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define EX(insn,reg,addr,handler) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 9: insn reg, addr; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .section __ex_table,"a"; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) PTR 9b, handler; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Return the size of a string including the ending NUL character up to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * maximum of a1 or 0 in case of error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Note: for performance reasons we deliberately accept that a user may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * make strlen_user and strnlen_user access the first few KSEG0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * bytes. There's nothing secret there. On 64-bit accessing beyond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * the maximum is a tad hairier ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .macro __BUILD_STRNLEN_ASM func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) LEAF(__strnlen_\func\()_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) and v0, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) bnez v0, .Lfault\@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) move v0, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) PTR_ADDU a1, a0 # stop pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #ifdef CONFIG_CPU_DADDI_WORKAROUNDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .set noat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) li AT, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) beq v0, a1, 1f # limit reached?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .ifeqs "\func", "kernel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) EX(lb, t0, (v0), .Lfault\@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) EX(lbe, t0, (v0), .Lfault\@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .set noreorder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) bnez t0, 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) PTR_ADDIU v0, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) PTR_ADDU v0, AT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .set at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .set reorder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) PTR_SUBU v0, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) jr ra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) END(__strnlen_\func\()_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .Lfault\@:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) move v0, zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) jr ra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #ifndef CONFIG_EVA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Set aliases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .global __strnlen_user_asm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .set __strnlen_user_asm, __strnlen_kernel_asm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) EXPORT_SYMBOL(__strnlen_user_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) __BUILD_STRNLEN_ASM kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) EXPORT_SYMBOL(__strnlen_kernel_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #ifdef CONFIG_EVA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .set push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .set eva
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) __BUILD_STRNLEN_ASM user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .set pop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) EXPORT_SYMBOL(__strnlen_user_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #endif