blob: 40be22625bc52552a265d1ebd13807fd9f77fced [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>
Paul Burtond6cb6712016-11-07 11:14:14 +000012#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/regdef.h>
14
15#define EX(insn,reg,addr,handler) \
169: insn reg, addr; \
17 .section __ex_table,"a"; \
18 PTR 9b, handler; \
19 .previous
20
21/*
22 * Return the size of a string (including the ending 0)
23 *
24 * Return 0 for error
25 */
Markos Chandras5cc49492014-01-02 15:55:58 +000026 .macro __BUILD_STRLEN_ASM func
27LEAF(__strlen_\func\()_asm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
29 and v0, a0
Markos Chandras5cc49492014-01-02 15:55:58 +000030 bnez v0, .Lfault\@
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 move v0, a0
Markos Chandras053970542014-01-02 16:04:38 +000033.ifeqs "\func", "kernel"
Markos Chandras5cc49492014-01-02 15:55:58 +0000341: EX(lbu, v1, (v0), .Lfault\@)
Markos Chandras053970542014-01-02 16:04:38 +000035.else
361: EX(lbue, v1, (v0), .Lfault\@)
37.endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 PTR_ADDIU v0, 1
Steven J. Hillb1bac372013-03-25 13:41:47 -050039 bnez v1, 1b
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 PTR_SUBU v0, a0
41 jr ra
Markos Chandras5cc49492014-01-02 15:55:58 +000042 END(__strlen_\func\()_asm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Markos Chandras5cc49492014-01-02 15:55:58 +000044.Lfault\@: move v0, zero
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 jr ra
Markos Chandras5cc49492014-01-02 15:55:58 +000046 .endm
47
Markos Chandras053970542014-01-02 16:04:38 +000048#ifndef CONFIG_EVA
49 /* Set aliases */
50 .global __strlen_user_asm
Markos Chandras053970542014-01-02 16:04:38 +000051 .set __strlen_user_asm, __strlen_kernel_asm
Arnd Bergmannb6689702017-01-17 16:18:35 +010052EXPORT_SYMBOL(__strlen_user_asm)
Markos Chandras053970542014-01-02 16:04:38 +000053#endif
54
55__BUILD_STRLEN_ASM kernel
Arnd Bergmannb6689702017-01-17 16:18:35 +010056EXPORT_SYMBOL(__strlen_kernel_asm)
Markos Chandras053970542014-01-02 16:04:38 +000057
58#ifdef CONFIG_EVA
59
60 .set push
61 .set eva
Markos Chandras5cc49492014-01-02 15:55:58 +000062__BUILD_STRLEN_ASM user
Markos Chandras053970542014-01-02 16:04:38 +000063 .set pop
Arnd Bergmannb6689702017-01-17 16:18:35 +010064EXPORT_SYMBOL(__strlen_user_asm)
Markos Chandras053970542014-01-02 16:04:38 +000065#endif