1/*
2 * linux/arch/unicore32/lib/copy_to_user.S
3 *
4 * Code specific to PKUnity SoC and UniCore ISA
5 *
6 * Copyright (C) 2001-2010 GUAN Xue-tao
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
16/*
17 * Prototype:
18 *
19 *	size_t __copy_to_user(void *to, const void *from, size_t n)
20 *
21 * Purpose:
22 *
23 *	copy a block to user memory from kernel memory
24 *
25 * Params:
26 *
27 *	to = user memory
28 *	from = kernel memory
29 *	n = number of bytes to copy
30 *
31 * Return value:
32 *
33 *	Number of bytes NOT copied.
34 */
35
36	.macro ldr1w ptr reg abort
37	ldw.w \reg, [\ptr]+, #4
38	.endm
39
40	.macro ldr4w ptr reg1 reg2 reg3 reg4 abort
41	ldm.w	(\reg1, \reg2, \reg3, \reg4), [\ptr]+
42	.endm
43
44	.macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
45	ldm.w (\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8), [\ptr]+
46	.endm
47
48	.macro ldr1b ptr reg cond=al abort
49	notcond	\cond, .+8
50	ldb.w \reg, [\ptr]+, #1
51	.endm
52
53	.macro str1w ptr reg abort
54	strusr	\reg, \ptr, 4, abort=\abort
55	.endm
56
57	.macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
58100:	stm.w (\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8), [\ptr]+
59
60	.pushsection __ex_table, "a"
61	.long 100b, \abort
62	.popsection
63	.endm
64
65	.macro str1b ptr reg cond=al abort
66	strusr	\reg, \ptr, 1, \cond, abort=\abort
67	.endm
68
69	.macro enter
70	mov	r3, #0
71	stm.w	(r0, r2, r3), [sp-]
72	.endm
73
74	.macro exit
75	add	sp, sp, #8
76	ldm.w	(r0), [sp]+
77	mov	pc, lr
78	.endm
79
80	.text
81
82WEAK(__copy_to_user)
83
84#include "copy_template.S"
85
86ENDPROC(__copy_to_user)
87
88	.pushsection .fixup,"ax"
89	.align 0
90	copy_abort_preamble
91	ldm.w	(r1, r2, r3), [sp]+
92	sub	r0, r0, r1
93	rsub	r0, r0, r2
94	copy_abort_end
95	.popsection
96
97