asm-uaccess.h 4.1 KB

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