176580237SAl Viro /* 276580237SAl Viro * include/asm-xtensa/uaccess.h 376580237SAl Viro * 476580237SAl Viro * User space memory access functions 576580237SAl Viro * 676580237SAl Viro * These routines provide basic accessing functions to the user memory 776580237SAl Viro * space for the kernel. This header file provides functions such as: 876580237SAl Viro * 976580237SAl Viro * This file is subject to the terms and conditions of the GNU General Public 1076580237SAl Viro * License. See the file "COPYING" in the main directory of this archive 1176580237SAl Viro * for more details. 1276580237SAl Viro * 1376580237SAl Viro * Copyright (C) 2001 - 2005 Tensilica Inc. 1476580237SAl Viro */ 1576580237SAl Viro 1676580237SAl Viro #ifndef _XTENSA_ASM_UACCESS_H 1776580237SAl Viro #define _XTENSA_ASM_UACCESS_H 1876580237SAl Viro 1976580237SAl Viro #include <linux/errno.h> 2076580237SAl Viro #include <asm/types.h> 2176580237SAl Viro 2276580237SAl Viro #define VERIFY_READ 0 2376580237SAl Viro #define VERIFY_WRITE 1 2476580237SAl Viro 2576580237SAl Viro #include <asm/current.h> 2676580237SAl Viro #include <asm/asm-offsets.h> 2776580237SAl Viro #include <asm/processor.h> 2876580237SAl Viro 2976580237SAl Viro /* 3076580237SAl Viro * These assembly macros mirror the C macros in asm/uaccess.h. They 3176580237SAl Viro * should always have identical functionality. See 3276580237SAl Viro * arch/xtensa/kernel/sys.S for usage. 3376580237SAl Viro */ 3476580237SAl Viro 3576580237SAl Viro #define KERNEL_DS 0 3676580237SAl Viro #define USER_DS 1 3776580237SAl Viro 3876580237SAl Viro #define get_ds (KERNEL_DS) 3976580237SAl Viro 4076580237SAl Viro /* 4176580237SAl Viro * get_fs reads current->thread.current_ds into a register. 4276580237SAl Viro * On Entry: 4376580237SAl Viro * <ad> anything 4476580237SAl Viro * <sp> stack 4576580237SAl Viro * On Exit: 4676580237SAl Viro * <ad> contains current->thread.current_ds 4776580237SAl Viro */ 4876580237SAl Viro .macro get_fs ad, sp 4976580237SAl Viro GET_CURRENT(\ad,\sp) 5076580237SAl Viro #if THREAD_CURRENT_DS > 1020 5176580237SAl Viro addi \ad, \ad, TASK_THREAD 5276580237SAl Viro l32i \ad, \ad, THREAD_CURRENT_DS - TASK_THREAD 5376580237SAl Viro #else 5476580237SAl Viro l32i \ad, \ad, THREAD_CURRENT_DS 5576580237SAl Viro #endif 5676580237SAl Viro .endm 5776580237SAl Viro 5876580237SAl Viro /* 5976580237SAl Viro * set_fs sets current->thread.current_ds to some value. 6076580237SAl Viro * On Entry: 6176580237SAl Viro * <at> anything (temp register) 6276580237SAl Viro * <av> value to write 6376580237SAl Viro * <sp> stack 6476580237SAl Viro * On Exit: 6576580237SAl Viro * <at> destroyed (actually, current) 6676580237SAl Viro * <av> preserved, value to write 6776580237SAl Viro */ 6876580237SAl Viro .macro set_fs at, av, sp 6976580237SAl Viro GET_CURRENT(\at,\sp) 7076580237SAl Viro s32i \av, \at, THREAD_CURRENT_DS 7176580237SAl Viro .endm 7276580237SAl Viro 7376580237SAl Viro /* 7476580237SAl Viro * kernel_ok determines whether we should bypass addr/size checking. 7576580237SAl Viro * See the equivalent C-macro version below for clarity. 7676580237SAl Viro * On success, kernel_ok branches to a label indicated by parameter 7776580237SAl Viro * <success>. This implies that the macro falls through to the next 7876580237SAl Viro * insruction on an error. 7976580237SAl Viro * 8076580237SAl Viro * Note that while this macro can be used independently, we designed 8176580237SAl Viro * in for optimal use in the access_ok macro below (i.e., we fall 8276580237SAl Viro * through on error). 8376580237SAl Viro * 8476580237SAl Viro * On Entry: 8576580237SAl Viro * <at> anything (temp register) 8676580237SAl Viro * <success> label to branch to on success; implies 8776580237SAl Viro * fall-through macro on error 8876580237SAl Viro * <sp> stack pointer 8976580237SAl Viro * On Exit: 9076580237SAl Viro * <at> destroyed (actually, current->thread.current_ds) 9176580237SAl Viro */ 9276580237SAl Viro 9376580237SAl Viro #if ((KERNEL_DS != 0) || (USER_DS == 0)) 9476580237SAl Viro # error Assembly macro kernel_ok fails 9576580237SAl Viro #endif 9676580237SAl Viro .macro kernel_ok at, sp, success 9776580237SAl Viro get_fs \at, \sp 9876580237SAl Viro beqz \at, \success 9976580237SAl Viro .endm 10076580237SAl Viro 10176580237SAl Viro /* 10276580237SAl Viro * user_ok determines whether the access to user-space memory is allowed. 10376580237SAl Viro * See the equivalent C-macro version below for clarity. 10476580237SAl Viro * 10576580237SAl Viro * On error, user_ok branches to a label indicated by parameter 10676580237SAl Viro * <error>. This implies that the macro falls through to the next 10776580237SAl Viro * instruction on success. 10876580237SAl Viro * 10976580237SAl Viro * Note that while this macro can be used independently, we designed 11076580237SAl Viro * in for optimal use in the access_ok macro below (i.e., we fall 11176580237SAl Viro * through on success). 11276580237SAl Viro * 11376580237SAl Viro * On Entry: 11476580237SAl Viro * <aa> register containing memory address 11576580237SAl Viro * <as> register containing memory size 11676580237SAl Viro * <at> temp register 11776580237SAl Viro * <error> label to branch to on error; implies fall-through 11876580237SAl Viro * macro on success 11976580237SAl Viro * On Exit: 12076580237SAl Viro * <aa> preserved 12176580237SAl Viro * <as> preserved 12276580237SAl Viro * <at> destroyed (actually, (TASK_SIZE + 1 - size)) 12376580237SAl Viro */ 12476580237SAl Viro .macro user_ok aa, as, at, error 12576580237SAl Viro movi \at, __XTENSA_UL_CONST(TASK_SIZE) 12676580237SAl Viro bgeu \as, \at, \error 12776580237SAl Viro sub \at, \at, \as 12876580237SAl Viro bgeu \aa, \at, \error 12976580237SAl Viro .endm 13076580237SAl Viro 13176580237SAl Viro /* 13276580237SAl Viro * access_ok determines whether a memory access is allowed. See the 13376580237SAl Viro * equivalent C-macro version below for clarity. 13476580237SAl Viro * 13576580237SAl Viro * On error, access_ok branches to a label indicated by parameter 13676580237SAl Viro * <error>. This implies that the macro falls through to the next 13776580237SAl Viro * instruction on success. 13876580237SAl Viro * 13976580237SAl Viro * Note that we assume success is the common case, and we optimize the 14076580237SAl Viro * branch fall-through case on success. 14176580237SAl Viro * 14276580237SAl Viro * On Entry: 14376580237SAl Viro * <aa> register containing memory address 14476580237SAl Viro * <as> register containing memory size 14576580237SAl Viro * <at> temp register 14676580237SAl Viro * <sp> 14776580237SAl Viro * <error> label to branch to on error; implies fall-through 14876580237SAl Viro * macro on success 14976580237SAl Viro * On Exit: 15076580237SAl Viro * <aa> preserved 15176580237SAl Viro * <as> preserved 15276580237SAl Viro * <at> destroyed 15376580237SAl Viro */ 15476580237SAl Viro .macro access_ok aa, as, at, sp, error 15576580237SAl Viro kernel_ok \at, \sp, .Laccess_ok_\@ 15676580237SAl Viro user_ok \aa, \as, \at, \error 15776580237SAl Viro .Laccess_ok_\@: 15876580237SAl Viro .endm 15976580237SAl Viro 16076580237SAl Viro #endif /* _XTENSA_ASM_UACCESS_H */ 161