| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 | * | 
|  | 6 | * Copyright (c) 1996, 1999 by Ralf Baechle | 
|  | 7 | */ | 
|  | 8 | #include <linux/errno.h> | 
|  | 9 | #include <asm/asm.h> | 
| Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 10 | #include <asm/asm-offsets.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/regdef.h> | 
|  | 12 |  | 
|  | 13 | #define EX(insn,reg,addr,handler)			\ | 
|  | 14 | 9:	insn	reg, addr;				\ | 
|  | 15 | .section __ex_table,"a";			\ | 
|  | 16 | PTR	9b, handler;				\ | 
|  | 17 | .previous | 
|  | 18 |  | 
|  | 19 | /* | 
|  | 20 | * Returns: -EFAULT if exception before terminator, N if the entire | 
|  | 21 | * buffer filled, else strlen. | 
|  | 22 | */ | 
|  | 23 |  | 
|  | 24 | /* | 
|  | 25 | * Ugly special case have to check: we might get passed a user space | 
|  | 26 | * pointer which wraps into the kernel space.  We don't deal with that.  If | 
|  | 27 | * it happens at most some bytes of the exceptions handlers will be copied. | 
|  | 28 | */ | 
|  | 29 |  | 
|  | 30 | LEAF(__strncpy_from_user_asm) | 
|  | 31 | LONG_L		v0, TI_ADDR_LIMIT($28)	# pointer ok? | 
|  | 32 | and		v0, a1 | 
| Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 33 | bnez		v0, .Lfault | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
|  | 35 | FEXPORT(__strncpy_from_user_nocheck_asm) | 
|  | 36 | move		v0, zero | 
|  | 37 | move		v1, a1 | 
|  | 38 | .set		noreorder | 
| Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 39 | 1:	EX(lbu, t0, (v1), .Lfault) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | PTR_ADDIU	v1, 1 | 
| Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 41 | R10KCBARRIER(0(ra)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | beqz		t0, 2f | 
|  | 43 | sb		t0, (a0) | 
|  | 44 | PTR_ADDIU	v0, 1 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | .set		reorder | 
| Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 46 | PTR_ADDIU	a0, 1 | 
|  | 47 | bne		v0, a2, 1b | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | 2:	PTR_ADDU	t0, a1, v0 | 
|  | 49 | xor		t0, a1 | 
| Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 50 | bltz		t0, .Lfault | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | jr		ra			# return n | 
|  | 52 | END(__strncpy_from_user_asm) | 
|  | 53 |  | 
| Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 54 | .Lfault:	li		v0, -EFAULT | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | jr		ra | 
|  | 56 |  | 
|  | 57 | .section	__ex_table,"a" | 
| Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 58 | PTR		1b, .Lfault | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | .previous |