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