1 /* SPDX-License-Identifier: GPL-2.0 */
3 * __put_user functions.
5 * (C) Copyright 2005 Linus Torvalds
6 * (C) Copyright 2005 Andi Kleen
7 * (C) Copyright 2008 Glauber Costa
9 * These functions have a non-standard call interface
10 * to make them more efficient, especially as they
11 * return an error value in addition to the "real"
14 #include <linux/linkage.h>
15 #include <asm/thread_info.h>
16 #include <asm/errno.h>
19 #include <asm/export.h>
25 * Inputs: %eax[:%edx] contains the data
26 * %ecx contains the address
28 * Outputs: %ecx is error code (0 or -EFAULT)
30 * Clobbers: %ebx needed for task pointer
32 * These functions should not modify any other registers,
33 * as they get called from within inline assembly.
36 #ifdef CONFIG_X86_5LEVEL
37 #define LOAD_TASK_SIZE_MINUS_N(n) \
38 ALTERNATIVE __stringify(mov $((1 << 47) - 4096 - (n)),%rbx), \
39 __stringify(mov $((1 << 56) - 4096 - (n)),%rbx), X86_FEATURE_LA57
41 #define LOAD_TASK_SIZE_MINUS_N(n) \
42 mov $(TASK_SIZE_MAX - (n)),%_ASM_BX
46 SYM_FUNC_START(__put_user_1)
47 LOAD_TASK_SIZE_MINUS_N(0)
51 1: movb %al,(%_ASM_CX)
55 SYM_FUNC_END(__put_user_1)
56 EXPORT_SYMBOL(__put_user_1)
58 SYM_FUNC_START(__put_user_nocheck_1)
61 2: movb %al,(%_ASM_CX)
65 SYM_FUNC_END(__put_user_nocheck_1)
66 EXPORT_SYMBOL(__put_user_nocheck_1)
68 SYM_FUNC_START(__put_user_2)
69 LOAD_TASK_SIZE_MINUS_N(1)
73 3: movw %ax,(%_ASM_CX)
77 SYM_FUNC_END(__put_user_2)
78 EXPORT_SYMBOL(__put_user_2)
80 SYM_FUNC_START(__put_user_nocheck_2)
83 4: movw %ax,(%_ASM_CX)
87 SYM_FUNC_END(__put_user_nocheck_2)
88 EXPORT_SYMBOL(__put_user_nocheck_2)
90 SYM_FUNC_START(__put_user_4)
91 LOAD_TASK_SIZE_MINUS_N(3)
95 5: movl %eax,(%_ASM_CX)
99 SYM_FUNC_END(__put_user_4)
100 EXPORT_SYMBOL(__put_user_4)
102 SYM_FUNC_START(__put_user_nocheck_4)
105 6: movl %eax,(%_ASM_CX)
109 SYM_FUNC_END(__put_user_nocheck_4)
110 EXPORT_SYMBOL(__put_user_nocheck_4)
112 SYM_FUNC_START(__put_user_8)
113 LOAD_TASK_SIZE_MINUS_N(7)
114 cmp %_ASM_BX,%_ASM_CX
117 7: mov %_ASM_AX,(%_ASM_CX)
119 8: movl %edx,4(%_ASM_CX)
124 SYM_FUNC_END(__put_user_8)
125 EXPORT_SYMBOL(__put_user_8)
127 SYM_FUNC_START(__put_user_nocheck_8)
130 9: mov %_ASM_AX,(%_ASM_CX)
132 10: movl %edx,4(%_ASM_CX)
137 SYM_FUNC_END(__put_user_nocheck_8)
138 EXPORT_SYMBOL(__put_user_nocheck_8)
140 SYM_CODE_START_LOCAL(.Lbad_put_user_clac)
145 SYM_CODE_END(.Lbad_put_user_clac)
147 _ASM_EXTABLE_UA(1b, .Lbad_put_user_clac)
148 _ASM_EXTABLE_UA(2b, .Lbad_put_user_clac)
149 _ASM_EXTABLE_UA(3b, .Lbad_put_user_clac)
150 _ASM_EXTABLE_UA(4b, .Lbad_put_user_clac)
151 _ASM_EXTABLE_UA(5b, .Lbad_put_user_clac)
152 _ASM_EXTABLE_UA(6b, .Lbad_put_user_clac)
153 _ASM_EXTABLE_UA(7b, .Lbad_put_user_clac)
154 _ASM_EXTABLE_UA(9b, .Lbad_put_user_clac)
156 _ASM_EXTABLE_UA(8b, .Lbad_put_user_clac)
157 _ASM_EXTABLE_UA(10b, .Lbad_put_user_clac)