blob: fc6ba17a7eec2a957fc2022d8a370bb1b9e5b15f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * __put_user functions.
3 *
4 * (C) Copyright 2005 Linus Torvalds
Glauber Costa5cbbc3b2008-06-24 17:40:14 -03005 * (C) Copyright 2005 Andi Kleen
6 * (C) Copyright 2008 Glauber Costa
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * These functions have a non-standard call interface
9 * to make them more efficient, especially as they
10 * return an error value in addition to the "real"
11 * return value.
12 */
Jan Beulich00e065e2007-05-02 19:27:05 +020013#include <linux/linkage.h>
14#include <asm/dwarf2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/thread_info.h>
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030016#include <asm/errno.h>
Glauber Costa2528de42008-06-24 17:36:31 -030017#include <asm/asm.h>
H. Peter Anvin63bcff22012-09-21 12:43:12 -070018#include <asm/smap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20
21/*
22 * __put_user_X
23 *
24 * Inputs: %eax[:%edx] contains the data
25 * %ecx contains the address
26 *
27 * Outputs: %eax is error code (0 or -EFAULT)
28 *
29 * These functions should not modify any other registers,
30 * as they get called from within inline assembly.
31 */
32
Jan Beulich00e065e2007-05-02 19:27:05 +020033#define ENTER CFI_STARTPROC ; \
Glauber Costa2528de42008-06-24 17:36:31 -030034 GET_THREAD_INFO(%_ASM_BX)
H. Peter Anvin63bcff22012-09-21 12:43:12 -070035#define EXIT ASM_CLAC ; \
36 ret ; \
Jan Beulich00e065e2007-05-02 19:27:05 +020037 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39.text
Jan Beulich00e065e2007-05-02 19:27:05 +020040ENTRY(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030042 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070044 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300451: movb %al,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030046 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020048ENDPROC(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Jan Beulich00e065e2007-05-02 19:27:05 +020050ENTRY(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030052 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
53 sub $1,%_ASM_BX
54 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070056 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300572: movw %ax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030058 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020060ENDPROC(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Jan Beulich00e065e2007-05-02 19:27:05 +020062ENTRY(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030064 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
65 sub $3,%_ASM_BX
66 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070068 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300693: movl %eax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030070 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020072ENDPROC(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Jan Beulich00e065e2007-05-02 19:27:05 +020074ENTRY(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030076 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
77 sub $7,%_ASM_BX
78 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070080 ASM_STAC
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300814: mov %_ASM_AX,(%_ASM_CX)
82#ifdef CONFIG_X86_32
Glauber Costa2528de42008-06-24 17:36:31 -0300835: movl %edx,4(%_ASM_CX)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030084#endif
Glauber Costaefea5052008-06-24 16:59:05 -030085 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020087ENDPROC(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89bad_put_user:
Glauber Costa268cf042008-06-24 12:40:55 -030090 CFI_STARTPROC
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030091 movl $-EFAULT,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020093END(bad_put_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
H. Peter Anvina53a96e2012-04-20 12:19:52 -070095 _ASM_EXTABLE(1b,bad_put_user)
96 _ASM_EXTABLE(2b,bad_put_user)
97 _ASM_EXTABLE(3b,bad_put_user)
98 _ASM_EXTABLE(4b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030099#ifdef CONFIG_X86_32
H. Peter Anvina53a96e2012-04-20 12:19:52 -0700100 _ASM_EXTABLE(5b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300101#endif