xref: /linux/arch/arm/lib/copy_from_user.S (revision f3a8b6645dc2e60d11f20c1c23afd964ff4e55ae)
1/*
2 *  linux/arch/arm/lib/copy_from_user.S
3 *
4 *  Author:	Nicolas Pitre
5 *  Created:	Sep 29, 2005
6 *  Copyright:	MontaVista Software, Inc.
7 *
8 *  This program is free software; you can redistribute it and/or modify
9 *  it under the terms of the GNU General Public License version 2 as
10 *  published by the Free Software Foundation.
11 */
12
13#include <linux/linkage.h>
14#include <asm/assembler.h>
15#include <asm/unwind.h>
16#include <asm/export.h>
17
18/*
19 * Prototype:
20 *
21 *	size_t arm_copy_from_user(void *to, const void *from, size_t n)
22 *
23 * Purpose:
24 *
25 *	copy a block to kernel memory from user memory
26 *
27 * Params:
28 *
29 *	to = kernel memory
30 *	from = user memory
31 *	n = number of bytes to copy
32 *
33 * Return value:
34 *
35 *	Number of bytes NOT copied.
36 */
37
38#ifndef CONFIG_THUMB2_KERNEL
39#define LDR1W_SHIFT	0
40#else
41#define LDR1W_SHIFT	1
42#endif
43#define STR1W_SHIFT	0
44
45	.macro ldr1w ptr reg abort
46	ldrusr	\reg, \ptr, 4, abort=\abort
47	.endm
48
49	.macro ldr4w ptr reg1 reg2 reg3 reg4 abort
50	ldr1w \ptr, \reg1, \abort
51	ldr1w \ptr, \reg2, \abort
52	ldr1w \ptr, \reg3, \abort
53	ldr1w \ptr, \reg4, \abort
54	.endm
55
56	.macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
57	ldr4w \ptr, \reg1, \reg2, \reg3, \reg4, \abort
58	ldr4w \ptr, \reg5, \reg6, \reg7, \reg8, \abort
59	.endm
60
61	.macro ldr1b ptr reg cond=al abort
62	ldrusr	\reg, \ptr, 1, \cond, abort=\abort
63	.endm
64
65	.macro str1w ptr reg abort
66	W(str) \reg, [\ptr], #4
67	.endm
68
69	.macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
70	stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
71	.endm
72
73	.macro str1b ptr reg cond=al abort
74	str\cond\()b \reg, [\ptr], #1
75	.endm
76
77	.macro enter reg1 reg2
78	mov	r3, #0
79	stmdb	sp!, {r0, r2, r3, \reg1, \reg2}
80	.endm
81
82	.macro usave reg1 reg2
83	UNWIND(	.save {r0, r2, r3, \reg1, \reg2}	)
84	.endm
85
86	.macro exit reg1 reg2
87	add	sp, sp, #8
88	ldmfd	sp!, {r0, \reg1, \reg2}
89	.endm
90
91	.text
92
93ENTRY(arm_copy_from_user)
94
95#include "copy_template.S"
96
97ENDPROC(arm_copy_from_user)
98EXPORT_SYMBOL(arm_copy_from_user)
99
100	.pushsection .fixup,"ax"
101	.align 0
102	copy_abort_preamble
103	ldmfd	sp!, {r1, r2, r3}
104	sub	r0, r0, r1
105	rsb	r0, r0, r2
106	copy_abort_end
107	.popsection
108
109