blob: 2b003d313480fba488ed80fc8b58d069b8ff37d7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * __get_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 * __get_user_X
15 *
16 * Inputs: %rcx contains the address.
17 * The register is modified, but all changes are undone
18 * before returning because the C code doesn't know about it.
19 *
20 * Outputs: %rax is error code (0 or -EFAULT)
21 * %rdx contains zero-extended value
22 *
23 * %r8 is destroyed.
24 *
25 * These functions should not modify any other registers,
26 * as they get called from within inline assembly.
27 */
28
29#include <linux/linkage.h>
Jan Beulich8d379da2006-09-26 10:52:32 +020030#include <asm/dwarf2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/page.h>
32#include <asm/errno.h>
Sam Ravnborge2d5df92005-09-09 21:28:48 +020033#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/thread_info.h>
35
36 .text
Jan Beulich8d379da2006-09-26 10:52:32 +020037ENTRY(__get_user_1)
38 CFI_STARTPROC
Glauber Costaedf10162008-06-13 16:35:52 -030039 GET_THREAD_INFO(%rdx)
40 cmpq threadinfo_addr_limit(%rdx),%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 jae bad_get_user
Glauber Costaedf10162008-06-13 16:35:52 -0300421: movzb (%rax),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 xorl %eax,%eax
44 ret
Jan Beulich8d379da2006-09-26 10:52:32 +020045 CFI_ENDPROC
46ENDPROC(__get_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Jan Beulich8d379da2006-09-26 10:52:32 +020048ENTRY(__get_user_2)
49 CFI_STARTPROC
Glauber Costaedf10162008-06-13 16:35:52 -030050 GET_THREAD_INFO(%rdx)
51 addq $1,%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 jc 20f
Glauber Costaedf10162008-06-13 16:35:52 -030053 cmpq threadinfo_addr_limit(%rdx),%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 jae 20f
Glauber Costaedf10162008-06-13 16:35:52 -030055 decq %rax
562: movzwl (%rax),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 xorl %eax,%eax
58 ret
Glauber Costaedf10162008-06-13 16:35:52 -03005920: decq %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 jmp bad_get_user
Jan Beulich8d379da2006-09-26 10:52:32 +020061 CFI_ENDPROC
62ENDPROC(__get_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Jan Beulich8d379da2006-09-26 10:52:32 +020064ENTRY(__get_user_4)
65 CFI_STARTPROC
Glauber Costaedf10162008-06-13 16:35:52 -030066 GET_THREAD_INFO(%rdx)
67 addq $3,%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 jc 30f
Glauber Costaedf10162008-06-13 16:35:52 -030069 cmpq threadinfo_addr_limit(%rdx),%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 jae 30f
Glauber Costaedf10162008-06-13 16:35:52 -030071 subq $3,%rax
723: movl (%rax),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 xorl %eax,%eax
74 ret
Glauber Costaedf10162008-06-13 16:35:52 -03007530: subq $3,%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 jmp bad_get_user
Jan Beulich8d379da2006-09-26 10:52:32 +020077 CFI_ENDPROC
78ENDPROC(__get_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Jan Beulich8d379da2006-09-26 10:52:32 +020080ENTRY(__get_user_8)
81 CFI_STARTPROC
Glauber Costaedf10162008-06-13 16:35:52 -030082 GET_THREAD_INFO(%rdx)
83 addq $7,%rax
Alexander Nyberg3a6fd752005-04-21 07:59:51 -070084 jc 40f
Glauber Costaedf10162008-06-13 16:35:52 -030085 cmpq threadinfo_addr_limit(%rdx),%rax
Alexander Nyberg3a6fd752005-04-21 07:59:51 -070086 jae 40f
Glauber Costaedf10162008-06-13 16:35:52 -030087 subq $7,%rax
884: movq (%rax),%rdx
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 xorl %eax,%eax
90 ret
Glauber Costaedf10162008-06-13 16:35:52 -03009140: subq $7,%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 jmp bad_get_user
Jan Beulich8d379da2006-09-26 10:52:32 +020093 CFI_ENDPROC
94ENDPROC(__get_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96bad_get_user:
Jan Beulich8d379da2006-09-26 10:52:32 +020097 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 xorl %edx,%edx
99 movq $(-EFAULT),%rax
100 ret
Jan Beulich8d379da2006-09-26 10:52:32 +0200101 CFI_ENDPROC
102END(bad_get_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104.section __ex_table,"a"
105 .quad 1b,bad_get_user
106 .quad 2b,bad_get_user
107 .quad 3b,bad_get_user
108 .quad 4b,bad_get_user
109.previous