Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * __put_user functions. |
| 3 | * |
| 4 | * (C) Copyright 2005 Linus Torvalds |
| 5 | * |
| 6 | * These functions have a non-standard call interface |
| 7 | * to make them more efficient, especially as they |
| 8 | * return an error value in addition to the "real" |
| 9 | * return value. |
| 10 | */ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 11 | #include <linux/linkage.h> |
| 12 | #include <asm/dwarf2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/thread_info.h> |
| 14 | |
| 15 | |
| 16 | /* |
| 17 | * __put_user_X |
| 18 | * |
| 19 | * Inputs: %eax[:%edx] contains the data |
| 20 | * %ecx contains the address |
| 21 | * |
| 22 | * Outputs: %eax is error code (0 or -EFAULT) |
| 23 | * |
| 24 | * These functions should not modify any other registers, |
| 25 | * as they get called from within inline assembly. |
| 26 | */ |
| 27 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 28 | #define ENTER CFI_STARTPROC ; \ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 29 | GET_THREAD_INFO(%ebx) |
Glauber Costa | 268cf04 | 2008-06-24 12:40:55 -0300 | [diff] [blame] | 30 | #define EXIT ret ; \ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 31 | CFI_ENDPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | .text |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 34 | ENTRY(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | ENTER |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 36 | cmp TI_addr_limit(%ebx),%ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | jae bad_put_user |
| 38 | 1: movb %al,(%ecx) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 39 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 41 | ENDPROC(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 43 | ENTRY(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | ENTER |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 45 | mov TI_addr_limit(%ebx),%ebx |
| 46 | sub $1,%ebx |
| 47 | cmp %ebx,%ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | jae bad_put_user |
| 49 | 2: movw %ax,(%ecx) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 50 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 52 | ENDPROC(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 54 | ENTRY(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | ENTER |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 56 | mov TI_addr_limit(%ebx),%ebx |
| 57 | sub $3,%ebx |
| 58 | cmp %ebx,%ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | jae bad_put_user |
| 60 | 3: movl %eax,(%ecx) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 61 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 63 | ENDPROC(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 65 | ENTRY(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | ENTER |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 67 | mov TI_addr_limit(%ebx),%ebx |
| 68 | sub $7,%ebx |
| 69 | cmp %ebx,%ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | jae bad_put_user |
| 71 | 4: movl %eax,(%ecx) |
| 72 | 5: movl %edx,4(%ecx) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame^] | 73 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 75 | ENDPROC(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | bad_put_user: |
Glauber Costa | 268cf04 | 2008-06-24 12:40:55 -0300 | [diff] [blame] | 78 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | movl $-14,%eax |
| 80 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 81 | END(bad_put_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | .section __ex_table,"a" |
| 84 | .long 1b,bad_put_user |
| 85 | .long 2b,bad_put_user |
| 86 | .long 3b,bad_put_user |
| 87 | .long 4b,bad_put_user |
| 88 | .long 5b,bad_put_user |
| 89 | .previous |