1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * include/asm-xtensa/uaccess.h 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * User space memory access functions 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * These routines provide basic accessing functions to the user memory 7*4882a593Smuzhiyun * space for the kernel. This header file provides functions such as: 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public 10*4882a593Smuzhiyun * License. See the file "COPYING" in the main directory of this archive 11*4882a593Smuzhiyun * for more details. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * Copyright (C) 2001 - 2005 Tensilica Inc. 14*4882a593Smuzhiyun */ 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun #ifndef _XTENSA_ASM_UACCESS_H 17*4882a593Smuzhiyun #define _XTENSA_ASM_UACCESS_H 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun #include <linux/errno.h> 20*4882a593Smuzhiyun #include <asm/types.h> 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun #include <asm/current.h> 23*4882a593Smuzhiyun #include <asm/asm-offsets.h> 24*4882a593Smuzhiyun #include <asm/processor.h> 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun /* 27*4882a593Smuzhiyun * These assembly macros mirror the C macros in asm/uaccess.h. They 28*4882a593Smuzhiyun * should always have identical functionality. See 29*4882a593Smuzhiyun * arch/xtensa/kernel/sys.S for usage. 30*4882a593Smuzhiyun */ 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun #define KERNEL_DS 0 33*4882a593Smuzhiyun #define USER_DS 1 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /* 36*4882a593Smuzhiyun * get_fs reads current->thread.current_ds into a register. 37*4882a593Smuzhiyun * On Entry: 38*4882a593Smuzhiyun * <ad> anything 39*4882a593Smuzhiyun * <sp> stack 40*4882a593Smuzhiyun * On Exit: 41*4882a593Smuzhiyun * <ad> contains current->thread.current_ds 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun .macro get_fs ad, sp 44*4882a593Smuzhiyun GET_CURRENT(\ad,\sp) 45*4882a593Smuzhiyun #if THREAD_CURRENT_DS > 1020 46*4882a593Smuzhiyun addi \ad, \ad, TASK_THREAD 47*4882a593Smuzhiyun l32i \ad, \ad, THREAD_CURRENT_DS - TASK_THREAD 48*4882a593Smuzhiyun #else 49*4882a593Smuzhiyun l32i \ad, \ad, THREAD_CURRENT_DS 50*4882a593Smuzhiyun #endif 51*4882a593Smuzhiyun .endm 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun /* 54*4882a593Smuzhiyun * set_fs sets current->thread.current_ds to some value. 55*4882a593Smuzhiyun * On Entry: 56*4882a593Smuzhiyun * <at> anything (temp register) 57*4882a593Smuzhiyun * <av> value to write 58*4882a593Smuzhiyun * <sp> stack 59*4882a593Smuzhiyun * On Exit: 60*4882a593Smuzhiyun * <at> destroyed (actually, current) 61*4882a593Smuzhiyun * <av> preserved, value to write 62*4882a593Smuzhiyun */ 63*4882a593Smuzhiyun .macro set_fs at, av, sp 64*4882a593Smuzhiyun GET_CURRENT(\at,\sp) 65*4882a593Smuzhiyun s32i \av, \at, THREAD_CURRENT_DS 66*4882a593Smuzhiyun .endm 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun /* 69*4882a593Smuzhiyun * kernel_ok determines whether we should bypass addr/size checking. 70*4882a593Smuzhiyun * See the equivalent C-macro version below for clarity. 71*4882a593Smuzhiyun * On success, kernel_ok branches to a label indicated by parameter 72*4882a593Smuzhiyun * <success>. This implies that the macro falls through to the next 73*4882a593Smuzhiyun * insruction on an error. 74*4882a593Smuzhiyun * 75*4882a593Smuzhiyun * Note that while this macro can be used independently, we designed 76*4882a593Smuzhiyun * in for optimal use in the access_ok macro below (i.e., we fall 77*4882a593Smuzhiyun * through on error). 78*4882a593Smuzhiyun * 79*4882a593Smuzhiyun * On Entry: 80*4882a593Smuzhiyun * <at> anything (temp register) 81*4882a593Smuzhiyun * <success> label to branch to on success; implies 82*4882a593Smuzhiyun * fall-through macro on error 83*4882a593Smuzhiyun * <sp> stack pointer 84*4882a593Smuzhiyun * On Exit: 85*4882a593Smuzhiyun * <at> destroyed (actually, current->thread.current_ds) 86*4882a593Smuzhiyun */ 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun #if ((KERNEL_DS != 0) || (USER_DS == 0)) 89*4882a593Smuzhiyun # error Assembly macro kernel_ok fails 90*4882a593Smuzhiyun #endif 91*4882a593Smuzhiyun .macro kernel_ok at, sp, success 92*4882a593Smuzhiyun get_fs \at, \sp 93*4882a593Smuzhiyun beqz \at, \success 94*4882a593Smuzhiyun .endm 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun /* 97*4882a593Smuzhiyun * user_ok determines whether the access to user-space memory is allowed. 98*4882a593Smuzhiyun * See the equivalent C-macro version below for clarity. 99*4882a593Smuzhiyun * 100*4882a593Smuzhiyun * On error, user_ok branches to a label indicated by parameter 101*4882a593Smuzhiyun * <error>. This implies that the macro falls through to the next 102*4882a593Smuzhiyun * instruction on success. 103*4882a593Smuzhiyun * 104*4882a593Smuzhiyun * Note that while this macro can be used independently, we designed 105*4882a593Smuzhiyun * in for optimal use in the access_ok macro below (i.e., we fall 106*4882a593Smuzhiyun * through on success). 107*4882a593Smuzhiyun * 108*4882a593Smuzhiyun * On Entry: 109*4882a593Smuzhiyun * <aa> register containing memory address 110*4882a593Smuzhiyun * <as> register containing memory size 111*4882a593Smuzhiyun * <at> temp register 112*4882a593Smuzhiyun * <error> label to branch to on error; implies fall-through 113*4882a593Smuzhiyun * macro on success 114*4882a593Smuzhiyun * On Exit: 115*4882a593Smuzhiyun * <aa> preserved 116*4882a593Smuzhiyun * <as> preserved 117*4882a593Smuzhiyun * <at> destroyed (actually, (TASK_SIZE + 1 - size)) 118*4882a593Smuzhiyun */ 119*4882a593Smuzhiyun .macro user_ok aa, as, at, error 120*4882a593Smuzhiyun movi \at, __XTENSA_UL_CONST(TASK_SIZE) 121*4882a593Smuzhiyun bgeu \as, \at, \error 122*4882a593Smuzhiyun sub \at, \at, \as 123*4882a593Smuzhiyun bgeu \aa, \at, \error 124*4882a593Smuzhiyun .endm 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun /* 127*4882a593Smuzhiyun * access_ok determines whether a memory access is allowed. See the 128*4882a593Smuzhiyun * equivalent C-macro version below for clarity. 129*4882a593Smuzhiyun * 130*4882a593Smuzhiyun * On error, access_ok branches to a label indicated by parameter 131*4882a593Smuzhiyun * <error>. This implies that the macro falls through to the next 132*4882a593Smuzhiyun * instruction on success. 133*4882a593Smuzhiyun * 134*4882a593Smuzhiyun * Note that we assume success is the common case, and we optimize the 135*4882a593Smuzhiyun * branch fall-through case on success. 136*4882a593Smuzhiyun * 137*4882a593Smuzhiyun * On Entry: 138*4882a593Smuzhiyun * <aa> register containing memory address 139*4882a593Smuzhiyun * <as> register containing memory size 140*4882a593Smuzhiyun * <at> temp register 141*4882a593Smuzhiyun * <sp> 142*4882a593Smuzhiyun * <error> label to branch to on error; implies fall-through 143*4882a593Smuzhiyun * macro on success 144*4882a593Smuzhiyun * On Exit: 145*4882a593Smuzhiyun * <aa> preserved 146*4882a593Smuzhiyun * <as> preserved 147*4882a593Smuzhiyun * <at> destroyed 148*4882a593Smuzhiyun */ 149*4882a593Smuzhiyun .macro access_ok aa, as, at, sp, error 150*4882a593Smuzhiyun kernel_ok \at, \sp, .Laccess_ok_\@ 151*4882a593Smuzhiyun user_ok \aa, \as, \at, \error 152*4882a593Smuzhiyun .Laccess_ok_\@: 153*4882a593Smuzhiyun .endm 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun #endif /* _XTENSA_ASM_UACCESS_H */ 156