ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / x86_64 / lib / putuser.S
1 /*
2  * __put_user functions.
3  *
4  * (C) Copyright 1998 Linus Torvalds
5  *
6  * These functions have a non-standard call interface
7  * to make them more efficient.
8  */
9
10 /*
11  * __put_user_X
12  *
13  * Inputs:      %rax contains the address
14  *              %rdx contains the value
15  *
16  * Outputs:     %rax is error code (0 or -EFAULT)
17  *              %rbx is corrupted (will contain "current_task").
18  *
19  * These functions should not modify any other registers,
20  * as they get called from within inline assembly.
21  */
22
23 /* FIXME: putuser.S should be really merged with getuser.S, and preprocessor should be used to keep code duplication lower */
24
25 #include <linux/linkage.h>
26 #include <asm/page.h>
27 #include <asm/errno.h>
28 #include <asm/offset.h>
29 #include <asm/thread_info.h>
30
31 .text
32 .p2align
33 .globl __put_user_1
34 __put_user_1:
35         GET_THREAD_INFO(%rbx)
36         cmpq threadinfo_addr_limit(%rbx),%rax
37         jae bad_put_user
38 1:      movb %dl,(%rax)
39         xorq %rax,%rax
40         ret
41
42 .p2align
43 .globl __put_user_2
44 __put_user_2:
45         GET_THREAD_INFO(%rbx) 
46         addq $1,%rax
47         jc              bad_put_user
48         cmpq    threadinfo_addr_limit(%rbx),%rax
49         jae     bad_put_user
50 2:      movw %dx,-1(%rax)
51         xorq %rax,%rax
52         ret
53
54 .p2align
55 .globl __put_user_4
56 __put_user_4:
57         GET_THREAD_INFO(%rbx) 
58         addq $3,%rax
59         jc              bad_put_user
60         cmpq    threadinfo_addr_limit(%rbx),%rax
61         jae     bad_put_user
62 3:      movl %edx,-3(%rax)
63         xorq %rax,%rax
64         ret
65
66 .p2align
67 .globl __put_user_8
68 __put_user_8:
69         GET_THREAD_INFO(%rbx) 
70         addq $7,%rax
71         jc      bad_put_user
72         cmpq    threadinfo_addr_limit(%rbx),%rax
73         jae     bad_put_user
74 4:      movq %rdx,-7(%rax)
75         xorq %rax,%rax
76         ret
77
78 ENTRY(bad_put_user)     
79 bad_put_user:
80         movq $(-EFAULT),%rax
81         ret
82
83 .section __ex_table,"a"
84         .quad 1b,bad_put_user
85         .quad 2b,bad_put_user
86         .quad 3b,bad_put_user
87         .quad 4b,bad_put_user   
88 .previous