Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * __put_user functions. |
| 3 | * |
| 4 | * (C) Copyright 2005 Linus Torvalds |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 5 | * (C) Copyright 2005 Andi Kleen |
| 6 | * (C) Copyright 2008 Glauber Costa |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 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 Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 13 | #include <linux/linkage.h> |
| 14 | #include <asm/dwarf2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/thread_info.h> |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 16 | #include <asm/errno.h> |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 17 | #include <asm/asm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 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 Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 32 | #define ENTER CFI_STARTPROC ; \ |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 33 | GET_THREAD_INFO(%_ASM_BX) |
Glauber Costa | 268cf04 | 2008-06-24 12:40:55 -0300 | [diff] [blame] | 34 | #define EXIT ret ; \ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 35 | CFI_ENDPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | .text |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 38 | ENTRY(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 40 | cmp TI_addr_limit(%_ASM_BX),%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | jae bad_put_user |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 42 | 1: movb %al,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 43 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 45 | ENDPROC(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 47 | ENTRY(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 49 | mov TI_addr_limit(%_ASM_BX),%_ASM_BX |
| 50 | sub $1,%_ASM_BX |
| 51 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | jae bad_put_user |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 53 | 2: movw %ax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 54 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 56 | ENDPROC(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 58 | ENTRY(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 60 | mov TI_addr_limit(%_ASM_BX),%_ASM_BX |
| 61 | sub $3,%_ASM_BX |
| 62 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | jae bad_put_user |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 64 | 3: movl %eax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 65 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 67 | ENDPROC(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 69 | ENTRY(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 71 | mov TI_addr_limit(%_ASM_BX),%_ASM_BX |
| 72 | sub $7,%_ASM_BX |
| 73 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | jae bad_put_user |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 75 | 4: mov %_ASM_AX,(%_ASM_CX) |
| 76 | #ifdef CONFIG_X86_32 |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 77 | 5: movl %edx,4(%_ASM_CX) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 78 | #endif |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 79 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 81 | ENDPROC(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | bad_put_user: |
Glauber Costa | 268cf04 | 2008-06-24 12:40:55 -0300 | [diff] [blame] | 84 | CFI_STARTPROC |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 85 | movl $-EFAULT,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 87 | END(bad_put_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 89 | _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 Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 93 | #ifdef CONFIG_X86_32 |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 94 | _ASM_EXTABLE(5b,bad_put_user) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 95 | #endif |