asm-uaccess.h 4.2 KB

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