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> |
| 28 | #include <asm/page.h> |
| 29 | #include <asm/errno.h> |
| 30 | #include <asm/offset.h> |
| 31 | #include <asm/thread_info.h> |
| 32 | |
| 33 | .text |
| 34 | .p2align 4 |
| 35 | .globl __put_user_1 |
| 36 | __put_user_1: |
| 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 |
| 43 | |
| 44 | .p2align 4 |
| 45 | .globl __put_user_2 |
| 46 | __put_user_2: |
| 47 | GET_THREAD_INFO(%r8) |
| 48 | addq $1,%rcx |
| 49 | jc bad_put_user |
| 50 | cmpq threadinfo_addr_limit(%r8),%rcx |
| 51 | jae bad_put_user |
| 52 | 2: movw %dx,-1(%rcx) |
| 53 | xorl %eax,%eax |
| 54 | ret |
| 55 | |
| 56 | .p2align 4 |
| 57 | .globl __put_user_4 |
| 58 | __put_user_4: |
| 59 | GET_THREAD_INFO(%r8) |
| 60 | addq $3,%rcx |
| 61 | jc bad_put_user |
| 62 | cmpq threadinfo_addr_limit(%r8),%rcx |
| 63 | jae bad_put_user |
| 64 | 3: movl %edx,-3(%rcx) |
| 65 | xorl %eax,%eax |
| 66 | ret |
| 67 | |
| 68 | .p2align 4 |
| 69 | .globl __put_user_8 |
| 70 | __put_user_8: |
| 71 | GET_THREAD_INFO(%r8) |
| 72 | addq $7,%rcx |
| 73 | jc bad_put_user |
| 74 | cmpq threadinfo_addr_limit(%r8),%rcx |
| 75 | jae bad_put_user |
| 76 | 4: movq %rdx,-7(%rcx) |
| 77 | xorl %eax,%eax |
| 78 | ret |
| 79 | |
| 80 | bad_put_user: |
| 81 | movq $(-EFAULT),%rax |
| 82 | ret |
| 83 | |
| 84 | .section __ex_table,"a" |
| 85 | .quad 1b,bad_put_user |
| 86 | .quad 2b,bad_put_user |
| 87 | .quad 3b,bad_put_user |
| 88 | .quad 4b,bad_put_user |
| 89 | .previous |