Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  arch/xtensa/lib/strnlen_user.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Public License.  See the file "COPYING" in the main directory of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  this archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Returns strnlen, including trailing zero terminator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Zero indicates error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  Copyright (C) 2002 Tensilica Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/asmmacro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * size_t __strnlen_user(const char *s, size_t len)
^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) #ifdef __XTENSA_EB__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) # define MASK0 0xff000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) # define MASK1 0x00ff0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) # define MASK2 0x0000ff00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) # define MASK3 0x000000ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) # define MASK0 0x000000ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) # define MASK1 0x0000ff00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) # define MASK2 0x00ff0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) # define MASK3 0xff000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) # Register use:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #   a2/ src
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #   a3/ len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #   a4/ tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #   a5/ mask0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #   a6/ mask1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #   a7/ mask2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #   a8/ mask3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #   a9/ tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #   a10/ tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) ENTRY(__strnlen_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	abi_entry_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	# a2/ s, a3/ len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	addi	a4, a2, -4	# because we overincrement at the end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				# we compensate with load offsets of 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	movi	a5, MASK0	# mask for byte 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	movi	a6, MASK1	# mask for byte 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	movi	a7, MASK2	# mask for byte 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	movi	a8, MASK3	# mask for byte 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	bbsi.l	a2, 0, .L1mod2	# if only  8-bit aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	bbsi.l	a2, 1, .L2mod4	# if only 16-bit aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * String is word-aligned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) .Laligned:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	srli	a10, a3, 2	# number of loop iterations with 4B per loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #if XCHAL_HAVE_LOOPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	loopnez	a10, .Ldone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	beqz	a10, .Ldone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	slli	a10, a10, 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	add	a10, a10, a4	# a10 = end of last 4B chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #endif /* XCHAL_HAVE_LOOPS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) .Loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) EX(10f)	l32i	a9, a4, 4		# get next word of string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	addi	a4, a4, 4		# advance string pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	bnone	a9, a5, .Lz0		# if byte 0 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	bnone	a9, a6, .Lz1		# if byte 1 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	bnone	a9, a7, .Lz2		# if byte 2 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	bnone	a9, a8, .Lz3		# if byte 3 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #if !XCHAL_HAVE_LOOPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	blt	a4, a10, .Loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) .Ldone:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) EX(10f)	l32i	a9, a4, 4	# load 4 bytes for remaining checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	bbci.l	a3, 1, .L100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	# check two more bytes (bytes 0, 1 of word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	addi	a4, a4, 2	# advance string pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	bnone	a9, a5, .Lz0	# if byte 0 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	bnone	a9, a6, .Lz1	# if byte 1 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) .L100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	bbci.l	a3, 0, .L101
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	# check one more byte (byte 2 of word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	# Actually, we don't need to check.  Zero or nonzero, we'll add one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	# Do not add an extra one for the NULL terminator since we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	#  exhausted the original len parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	addi	a4, a4, 1	# advance string pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) .L101:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	sub	a2, a4, a2	# compute length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	abi_ret_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) # NOTE that in several places below, we point to the byte just after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) # the zero byte in order to include the NULL terminator in the count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .Lz3:	# byte 3 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	addi	a4, a4, 3	# point to zero byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .Lz0:	# byte 0 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	addi	a4, a4, 1	# point just beyond zero byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	sub	a2, a4, a2	# subtract to get length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	abi_ret_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .Lz1:	# byte 1 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	addi	a4, a4, 1+1	# point just beyond zero byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	sub	a2, a4, a2	# subtract to get length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	abi_ret_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .Lz2:	# byte 2 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	addi	a4, a4, 2+1	# point just beyond zero byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	sub	a2, a4, a2	# subtract to get length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	abi_ret_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .L1mod2:	# address is odd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) EX(10f)	l8ui	a9, a4, 4		# get byte 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	addi	a4, a4, 1		# advance string pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	beqz	a9, .Lz3		# if byte 0 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	bbci.l	a4, 1, .Laligned	# if string pointer is now word-aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .L2mod4:	# address is 2 mod 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	addi	a4, a4, 2	# advance ptr for aligned access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) EX(10f)	l32i	a9, a4, 0	# get word with first two bytes of string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	bnone	a9, a7, .Lz2	# if byte 2 (of word, not string) is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	bany	a9, a8, .Laligned # if byte 3 (of word, not string) is nonzero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	# byte 3 is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	addi	a4, a4, 3+1	# point just beyond zero byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	sub	a2, a4, a2	# subtract to get length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	abi_ret_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ENDPROC(__strnlen_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	.section .fixup, "ax"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	.align	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	movi	a2, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	abi_ret_default