xref: /linux/arch/xtensa/include/asm/asm-uaccess.h (revision 0be3ff0c)
1 /*
2  * include/asm-xtensa/uaccess.h
3  *
4  * User space memory access functions
5  *
6  * These routines provide basic accessing functions to the user memory
7  * space for the kernel. This header file provides functions such as:
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file "COPYING" in the main directory of this archive
11  * for more details.
12  *
13  * Copyright (C) 2001 - 2005 Tensilica Inc.
14  */
15 
16 #ifndef _XTENSA_ASM_UACCESS_H
17 #define _XTENSA_ASM_UACCESS_H
18 
19 #include <linux/errno.h>
20 #include <asm/types.h>
21 
22 #include <asm/current.h>
23 #include <asm/asm-offsets.h>
24 #include <asm/processor.h>
25 
26 /*
27  * user_ok determines whether the access to user-space memory is allowed.
28  * See the equivalent C-macro version below for clarity.
29  *
30  * On error, user_ok branches to a label indicated by parameter
31  * <error>.  This implies that the macro falls through to the next
32  * instruction on success.
33  *
34  * Note that while this macro can be used independently, we designed
35  * in for optimal use in the access_ok macro below (i.e., we fall
36  * through on success).
37  *
38  * On Entry:
39  * 	<aa>	register containing memory address
40  * 	<as>	register containing memory size
41  * 	<at>	temp register
42  * 	<error>	label to branch to on error; implies fall-through
43  * 		macro on success
44  * On Exit:
45  * 	<aa>	preserved
46  * 	<as>	preserved
47  * 	<at>	destroyed (actually, (TASK_SIZE + 1 - size))
48  */
49 	.macro	user_ok	aa, as, at, error
50 	movi	\at, __XTENSA_UL_CONST(TASK_SIZE)
51 	bgeu	\as, \at, \error
52 	sub	\at, \at, \as
53 	bgeu	\aa, \at, \error
54 	.endm
55 
56 /*
57  * access_ok determines whether a memory access is allowed.  See the
58  * equivalent C-macro version below for clarity.
59  *
60  * On error, access_ok branches to a label indicated by parameter
61  * <error>.  This implies that the macro falls through to the next
62  * instruction on success.
63  *
64  * Note that we assume success is the common case, and we optimize the
65  * branch fall-through case on success.
66  *
67  * On Entry:
68  * 	<aa>	register containing memory address
69  * 	<as>	register containing memory size
70  * 	<at>	temp register
71  * 	<sp>
72  * 	<error>	label to branch to on error; implies fall-through
73  * 		macro on success
74  * On Exit:
75  * 	<aa>	preserved
76  * 	<as>	preserved
77  * 	<at>	destroyed
78  */
79 	.macro	access_ok  aa, as, at, sp, error
80 	user_ok    \aa, \as, \at, \error
81 .Laccess_ok_\@:
82 	.endm
83 
84 #endif	/* _XTENSA_ASM_UACCESS_H */
85