2 * include/asm-xtensa/uaccess.h
4 * User space memory access functions
6 * These routines provide basic accessing functions to the user memory
7 * space for the kernel. This header file provides functions such as:
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
13 * Copyright (C) 2001 - 2005 Tensilica Inc.
16 #ifndef _XTENSA_ASM_UACCESS_H
17 #define _XTENSA_ASM_UACCESS_H
19 #include <linux/errno.h>
20 #include <asm/types.h>
23 #define VERIFY_WRITE 1
25 #include <asm/current.h>
26 #include <asm/asm-offsets.h>
27 #include <asm/processor.h>
30 * These assembly macros mirror the C macros in asm/uaccess.h. They
31 * should always have identical functionality. See
32 * arch/xtensa/kernel/sys.S for usage.
38 #define get_ds (KERNEL_DS)
41 * get_fs reads current->thread.current_ds into a register.
46 * <ad> contains current->thread.current_ds
50 #if THREAD_CURRENT_DS > 1020
51 addi \ad, \ad, TASK_THREAD
52 l32i \ad, \ad, THREAD_CURRENT_DS - TASK_THREAD
54 l32i \ad, \ad, THREAD_CURRENT_DS
59 * set_fs sets current->thread.current_ds to some value.
61 * <at> anything (temp register)
65 * <at> destroyed (actually, current)
66 * <av> preserved, value to write
68 .macro set_fs at, av, sp
70 s32i \av, \at, THREAD_CURRENT_DS
74 * kernel_ok determines whether we should bypass addr/size checking.
75 * See the equivalent C-macro version below for clarity.
76 * On success, kernel_ok branches to a label indicated by parameter
77 * <success>. This implies that the macro falls through to the next
78 * insruction on an error.
80 * Note that while this macro can be used independently, we designed
81 * in for optimal use in the access_ok macro below (i.e., we fall
85 * <at> anything (temp register)
86 * <success> label to branch to on success; implies
87 * fall-through macro on error
90 * <at> destroyed (actually, current->thread.current_ds)
93 #if ((KERNEL_DS != 0) || (USER_DS == 0))
94 # error Assembly macro kernel_ok fails
96 .macro kernel_ok at, sp, success
102 * user_ok determines whether the access to user-space memory is allowed.
103 * See the equivalent C-macro version below for clarity.
105 * On error, user_ok branches to a label indicated by parameter
106 * <error>. This implies that the macro falls through to the next
107 * instruction on success.
109 * Note that while this macro can be used independently, we designed
110 * in for optimal use in the access_ok macro below (i.e., we fall
111 * through on success).
114 * <aa> register containing memory address
115 * <as> register containing memory size
117 * <error> label to branch to on error; implies fall-through
122 * <at> destroyed (actually, (TASK_SIZE + 1 - size))
124 .macro user_ok aa, as, at, error
125 movi \at, __XTENSA_UL_CONST(TASK_SIZE)
126 bgeu \as, \at, \error
128 bgeu \aa, \at, \error
132 * access_ok determines whether a memory access is allowed. See the
133 * equivalent C-macro version below for clarity.
135 * On error, access_ok branches to a label indicated by parameter
136 * <error>. This implies that the macro falls through to the next
137 * instruction on success.
139 * Note that we assume success is the common case, and we optimize the
140 * branch fall-through case on success.
143 * <aa> register containing memory address
144 * <as> register containing memory size
147 * <error> label to branch to on error; implies fall-through
154 .macro access_ok aa, as, at, sp, error
155 kernel_ok \at, \sp, .Laccess_ok_\@
156 user_ok \aa, \as, \at, \error
160 #endif /* _XTENSA_ASM_UACCESS_H */