^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, 1999 by Ralf Baechle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2011 MIPS Technologies, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/regdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define EX(insn,reg,addr,handler) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 9: insn reg, addr; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .section __ex_table,"a"; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) PTR 9b, handler; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) .previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Returns: -EFAULT if exception before terminator, N if the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * buffer filled, else strlen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Ugly special case have to check: we might get passed a user space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * pointer which wraps into the kernel space. We don't deal with that. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * it happens at most some bytes of the exceptions handlers will be copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .macro __BUILD_STRNCPY_ASM func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) LEAF(__strncpy_from_\func\()_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) and v0, a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) bnez v0, .Lfault\@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) move t0, zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) move v1, a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .ifeqs "\func","kernel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 1: EX(lbu, v0, (v1), .Lfault\@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 1: EX(lbue, v0, (v1), .Lfault\@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) PTR_ADDIU v1, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) R10KCBARRIER(0(ra))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) sb v0, (a0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) beqz v0, 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) PTR_ADDIU t0, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) PTR_ADDIU a0, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) bne t0, a2, 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 2: PTR_ADDU v0, a1, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) xor v0, a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) bltz v0, .Lfault\@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) move v0, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) jr ra # return n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) END(__strncpy_from_\func\()_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .Lfault\@:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) li v0, -EFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) jr ra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .section __ex_table,"a"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) PTR 1b, .Lfault\@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #ifndef CONFIG_EVA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Set aliases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .global __strncpy_from_user_asm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .set __strncpy_from_user_asm, __strncpy_from_kernel_asm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) EXPORT_SYMBOL(__strncpy_from_user_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) __BUILD_STRNCPY_ASM kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) EXPORT_SYMBOL(__strncpy_from_kernel_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #ifdef CONFIG_EVA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .set push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .set eva
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __BUILD_STRNCPY_ASM user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .set pop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) EXPORT_SYMBOL(__strncpy_from_user_asm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #endif