Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * __put_user functions. |
| 3 | * |
| 4 | * (C) Copyright 1998 Linus Torvalds |
| 5 | * (C) Copyright 2005 Andi Kleen |
| 6 | * |
| 7 | * These functions have a non-standard call interface |
| 8 | * to make them more efficient, especially as they |
| 9 | * return an error value in addition to the "real" |
| 10 | * return value. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * __put_user_X |
| 15 | * |
| 16 | * Inputs: %rcx contains the address |
| 17 | * %rdx contains new value |
| 18 | * |
| 19 | * Outputs: %rax is error code (0 or -EFAULT) |
| 20 | * |
| 21 | * %r8 is destroyed. |
| 22 | * |
| 23 | * These functions should not modify any other registers, |
| 24 | * as they get called from within inline assembly. |
| 25 | */ |
| 26 | |
| 27 | #include <linux/linkage.h> |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 28 | #include <asm/dwarf2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/page.h> |
| 30 | #include <asm/errno.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 31 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/thread_info.h> |
| 33 | |
| 34 | .text |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 35 | ENTRY(__put_user_1) |
| 36 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | GET_THREAD_INFO(%r8) |
| 38 | cmpq threadinfo_addr_limit(%r8),%rcx |
| 39 | jae bad_put_user |
| 40 | 1: movb %dl,(%rcx) |
| 41 | xorl %eax,%eax |
| 42 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 43 | CFI_ENDPROC |
| 44 | ENDPROC(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 46 | ENTRY(__put_user_2) |
| 47 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | GET_THREAD_INFO(%r8) |
| 49 | addq $1,%rcx |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 50 | jc 20f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | cmpq threadinfo_addr_limit(%r8),%rcx |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 52 | jae 20f |
Alexander Nyberg | efab773 | 2005-04-22 10:22:07 -0700 | [diff] [blame] | 53 | decq %rcx |
| 54 | 2: movw %dx,(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | xorl %eax,%eax |
| 56 | ret |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 57 | 20: decq %rcx |
| 58 | jmp bad_put_user |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 59 | CFI_ENDPROC |
| 60 | ENDPROC(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 62 | ENTRY(__put_user_4) |
| 63 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | GET_THREAD_INFO(%r8) |
| 65 | addq $3,%rcx |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 66 | jc 30f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | cmpq threadinfo_addr_limit(%r8),%rcx |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 68 | jae 30f |
Alexander Nyberg | efab773 | 2005-04-22 10:22:07 -0700 | [diff] [blame] | 69 | subq $3,%rcx |
| 70 | 3: movl %edx,(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | xorl %eax,%eax |
| 72 | ret |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 73 | 30: subq $3,%rcx |
| 74 | jmp bad_put_user |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 75 | CFI_ENDPROC |
| 76 | ENDPROC(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 78 | ENTRY(__put_user_8) |
| 79 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | GET_THREAD_INFO(%r8) |
| 81 | addq $7,%rcx |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 82 | jc 40f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | cmpq threadinfo_addr_limit(%r8),%rcx |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 84 | jae 40f |
Alexander Nyberg | efab773 | 2005-04-22 10:22:07 -0700 | [diff] [blame] | 85 | subq $7,%rcx |
| 86 | 4: movq %rdx,(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | xorl %eax,%eax |
| 88 | ret |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 89 | 40: subq $7,%rcx |
| 90 | jmp bad_put_user |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 91 | CFI_ENDPROC |
| 92 | ENDPROC(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | bad_put_user: |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 95 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | movq $(-EFAULT),%rax |
| 97 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 98 | CFI_ENDPROC |
| 99 | END(bad_put_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | .section __ex_table,"a" |
| 102 | .quad 1b,bad_put_user |
| 103 | .quad 2b,bad_put_user |
| 104 | .quad 3b,bad_put_user |
| 105 | .quad 4b,bad_put_user |
| 106 | .previous |