blob: 929bbacd697e2a8f0bfe5bb46e50233e31a62c92 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Steven J. Hillb1bac372013-03-25 13:41:47 -05006 * Copyright (C) 1996, 1998, 1999, 2004 by Ralf Baechle
7 * Copyright (C) 1999 Silicon Graphics, Inc.
8 * Copyright (C) 2011 MIPS Technologies, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10#include <asm/asm.h>
Sam Ravnborg048eb582005-09-09 22:32:31 +020011#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/regdef.h>
13
14#define EX(insn,reg,addr,handler) \
159: insn reg, addr; \
16 .section __ex_table,"a"; \
17 PTR 9b, handler; \
18 .previous
19
20/*
21 * Return the size of a string (including the ending 0)
22 *
23 * Return 0 for error
24 */
Markos Chandras5cc49492014-01-02 15:55:58 +000025 .macro __BUILD_STRLEN_ASM func
26LEAF(__strlen_\func\()_asm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
28 and v0, a0
Markos Chandras5cc49492014-01-02 15:55:58 +000029 bnez v0, .Lfault\@
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 move v0, a0
Markos Chandras053970542014-01-02 16:04:38 +000032.ifeqs "\func", "kernel"
Markos Chandras5cc49492014-01-02 15:55:58 +0000331: EX(lbu, v1, (v0), .Lfault\@)
Markos Chandras053970542014-01-02 16:04:38 +000034.else
351: EX(lbue, v1, (v0), .Lfault\@)
36.endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 PTR_ADDIU v0, 1
Steven J. Hillb1bac372013-03-25 13:41:47 -050038 bnez v1, 1b
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 PTR_SUBU v0, a0
40 jr ra
Markos Chandras5cc49492014-01-02 15:55:58 +000041 END(__strlen_\func\()_asm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Markos Chandras5cc49492014-01-02 15:55:58 +000043.Lfault\@: move v0, zero
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 jr ra
Markos Chandras5cc49492014-01-02 15:55:58 +000045 .endm
46
Markos Chandras053970542014-01-02 16:04:38 +000047#ifndef CONFIG_EVA
48 /* Set aliases */
49 .global __strlen_user_asm
Markos Chandras053970542014-01-02 16:04:38 +000050 .set __strlen_user_asm, __strlen_kernel_asm
Markos Chandras053970542014-01-02 16:04:38 +000051#endif
52
53__BUILD_STRLEN_ASM kernel
54
55#ifdef CONFIG_EVA
56
57 .set push
58 .set eva
Markos Chandras5cc49492014-01-02 15:55:58 +000059__BUILD_STRLEN_ASM user
Markos Chandras053970542014-01-02 16:04:38 +000060 .set pop
61#endif