syscall.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /****************************************************************************
  2. * arch/misoc/include/lm32/syscall.h
  3. *
  4. * Copyright (C) 2016 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. * Ramtin Amin <keytwo@gmail.com>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. /* This file should never be included directed but, rather, only indirectly
  37. * through include/syscall.h or include/sys/sycall.h
  38. */
  39. #ifndef __ARCH_MISOC_INCLUDE_LM32_SYSCALL_H
  40. #define __ARCH_MISOC_INCLUDE_LM32_SYSCALL_H
  41. /****************************************************************************
  42. * Included Files
  43. ****************************************************************************/
  44. #include <nuttx/config.h>
  45. #ifndef __ASSEMBLY__
  46. # include <stdint.h>
  47. #endif
  48. /****************************************************************************
  49. * Pre-processor Definitions
  50. ****************************************************************************/
  51. #define SYS_syscall 0x00
  52. /* Configuration ********************************************************************/
  53. /* SYS call 1 and 2 are defined for internal use by the LM32 port (see
  54. * arch/miscoc/include/lm32/syscall.h). In addition, SYS call 3 is the return from
  55. * a SYS call in kernel mode. The first four syscall values must, therefore, be
  56. * reserved (0 is not used).
  57. */
  58. #ifdef CONFIG_BUILD_KERNEL
  59. # ifndef CONFIG_SYS_RESERVED
  60. # error "CONFIG_SYS_RESERVED must be defined to the value 4"
  61. # elif CONFIG_SYS_RESERVED != 4
  62. # error "CONFIG_SYS_RESERVED must have the value 4"
  63. # endif
  64. #endif
  65. /* sys_call macros ******************************************************************/
  66. #ifndef __ASSEMBLY__
  67. /* Context switching system calls ***************************************************/
  68. /* SYS call 0: (not used) */
  69. /* SYS call 1:
  70. *
  71. * void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function;
  72. */
  73. #define SYS_restore_context (1)
  74. #define up_fullcontextrestore(restoreregs) \
  75. (void)sys_call1(SYS_restore_context, (uintptr_t)restoreregs)
  76. /* SYS call 2:
  77. *
  78. * void up_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
  79. */
  80. #define SYS_switch_context (2)
  81. #define up_switchcontext(saveregs, restoreregs) \
  82. (void)sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)
  83. #ifdef CONFIG_BUILD_KERNEL
  84. /* SYS call 3:
  85. *
  86. * void up_syscall_return(void);
  87. */
  88. #define SYS_syscall_return (3)
  89. #define up_syscall_return() (void)sys_call0(SYS_syscall_return)
  90. #endif
  91. #endif /* __ASSEMBLY__ */
  92. /****************************************************************************
  93. * Public Types
  94. ****************************************************************************/
  95. /****************************************************************************
  96. * Inline functions
  97. ****************************************************************************/
  98. #ifndef __ASSEMBLY__
  99. /****************************************************************************
  100. * Public Data
  101. ****************************************************************************/
  102. /****************************************************************************
  103. * Public Function Prototypes
  104. ****************************************************************************/
  105. #ifdef __cplusplus
  106. #define EXTERN extern "C"
  107. extern "C"
  108. {
  109. #else
  110. #define EXTERN extern
  111. #endif
  112. /****************************************************************************
  113. * Name: up_syscall0
  114. *
  115. * Description:
  116. * System call SYS_ argument and no additional parameters.
  117. *
  118. ****************************************************************************/
  119. uintptr_t sys_call0(unsigned int nbr);
  120. /****************************************************************************
  121. * Name: up_syscall1
  122. *
  123. * Description:
  124. * System call SYS_ argument and one additional parameter.
  125. *
  126. ****************************************************************************/
  127. uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1);
  128. /****************************************************************************
  129. * Name: up_syscall2
  130. *
  131. * Description:
  132. * System call SYS_ argument and two additional parameters.
  133. *
  134. ****************************************************************************/
  135. uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1, uintptr_t parm2);
  136. /****************************************************************************
  137. * Name: up_syscall3
  138. *
  139. * Description:
  140. * System call SYS_ argument and three additional parameters.
  141. *
  142. ****************************************************************************/
  143. uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1, uintptr_t parm2,
  144. uintptr_t parm3);
  145. /****************************************************************************
  146. * Name: up_syscall4
  147. *
  148. * Description:
  149. * System call SYS_ argument and four additional parameters.
  150. *
  151. ****************************************************************************/
  152. uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1, uintptr_t parm2,
  153. uintptr_t parm3, uintptr_t parm4);
  154. /****************************************************************************
  155. * Name: up_syscall5
  156. *
  157. * Description:
  158. * System call SYS_ argument and five additional parameters.
  159. *
  160. ****************************************************************************/
  161. uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1, uintptr_t parm2,
  162. uintptr_t parm3, uintptr_t parm4, uintptr_t parm5);
  163. #undef EXTERN
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif /* __ASSEMBLY__ */
  168. #endif /* __ARCH_MISOC_INCLUDE_LM32_SYSCALL_H */