blob: 7f951c8f76c45186bfb44ad5308a27e8ebe38db1 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19
20/*
21 * __put_user_X
22 *
23 * Inputs: %eax[:%edx] contains the data
24 * %ecx contains the address
25 *
26 * Outputs: %eax is error code (0 or -EFAULT)
27 *
28 * These functions should not modify any other registers,
29 * as they get called from within inline assembly.
30 */
31
Jan Beulich00e065e2007-05-02 19:27:05 +020032#define ENTER CFI_STARTPROC ; \
Glauber Costa2528de42008-06-24 17:36:31 -030033 GET_THREAD_INFO(%_ASM_BX)
Glauber Costa268cf042008-06-24 12:40:55 -030034#define EXIT ret ; \
Jan Beulich00e065e2007-05-02 19:27:05 +020035 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37.text
Jan Beulich00e065e2007-05-02 19:27:05 +020038ENTRY(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030040 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 jae bad_put_user
Glauber Costa2528de42008-06-24 17:36:31 -0300421: movb %al,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030043 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020045ENDPROC(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Jan Beulich00e065e2007-05-02 19:27:05 +020047ENTRY(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030049 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
50 sub $1,%_ASM_BX
51 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 jae bad_put_user
Glauber Costa2528de42008-06-24 17:36:31 -0300532: movw %ax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030054 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020056ENDPROC(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Jan Beulich00e065e2007-05-02 19:27:05 +020058ENTRY(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030060 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
61 sub $3,%_ASM_BX
62 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 jae bad_put_user
Glauber Costa2528de42008-06-24 17:36:31 -0300643: movl %eax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030065 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020067ENDPROC(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Jan Beulich00e065e2007-05-02 19:27:05 +020069ENTRY(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 ENTER
Glauber Costa2528de42008-06-24 17:36:31 -030071 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
72 sub $7,%_ASM_BX
73 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 jae bad_put_user
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300754: mov %_ASM_AX,(%_ASM_CX)
76#ifdef CONFIG_X86_32
Glauber Costa2528de42008-06-24 17:36:31 -0300775: movl %edx,4(%_ASM_CX)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030078#endif
Glauber Costaefea5052008-06-24 16:59:05 -030079 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020081ENDPROC(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83bad_put_user:
Glauber Costa268cf042008-06-24 12:40:55 -030084 CFI_STARTPROC
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030085 movl $-EFAULT,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020087END(bad_put_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
H. Peter Anvina53a96e2012-04-20 12:19:52 -070089 _ASM_EXTABLE(1b,bad_put_user)
90 _ASM_EXTABLE(2b,bad_put_user)
91 _ASM_EXTABLE(3b,bad_put_user)
92 _ASM_EXTABLE(4b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030093#ifdef CONFIG_X86_32
H. Peter Anvina53a96e2012-04-20 12:19:52 -070094 _ASM_EXTABLE(5b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030095#endif