syscall.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /****************************************************************************
  2. * arch/x86_64/include/intel64/syscall.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /* This file should never be included directly but, rather, only indirectly
  21. * through include/syscall.h or include/sys/sycall.h
  22. */
  23. #ifndef __ARCH_X86_64_INCLUDE_INTEL64_SYSCALL_H
  24. #define __ARCH_X86_64_INCLUDE_INTEL64_SYSCALL_H
  25. /****************************************************************************
  26. * Included Files
  27. ****************************************************************************/
  28. #include <nuttx/config.h>
  29. #include <stdint.h>
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /****************************************************************************
  34. * Public Types
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Public Data
  38. ****************************************************************************/
  39. /****************************************************************************
  40. * Public Function Prototypes
  41. ****************************************************************************/
  42. #ifndef __ASSEMBLY__
  43. #ifdef __cplusplus
  44. #define EXTERN extern "C"
  45. extern "C"
  46. {
  47. #else
  48. #define EXTERN extern
  49. #endif
  50. void enable_syscall(void);
  51. void syscall_entry(void);
  52. uint64_t syscall_handler(unsigned long nbr, uintptr_t parm1, uintptr_t parm2,
  53. uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
  54. uintptr_t parm6);
  55. uint64_t linux_interface(unsigned long nbr, uintptr_t parm1, uintptr_t parm2,
  56. uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
  57. uintptr_t parm6);
  58. /* SWI with SYS_ call number and six parameters */
  59. static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
  60. uintptr_t parm2, uintptr_t parm3,
  61. uintptr_t parm4, uintptr_t parm5,
  62. uintptr_t parm6);
  63. /* SWI with SYS_ call number and no parameters */
  64. static inline uintptr_t sys_call0(unsigned int nbr)
  65. {
  66. return sys_call6(nbr, 0, 0, 0, 0, 0, 0);
  67. }
  68. /* SWI with SYS_ call number and one parameter */
  69. static inline uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)
  70. {
  71. return sys_call6(nbr, parm1, 0, 0, 0, 0, 0);
  72. }
  73. /* SWI with SYS_ call number and two parameters */
  74. static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1,
  75. uintptr_t parm2)
  76. {
  77. return sys_call6(nbr, parm1, parm2, 0, 0, 0, 0);
  78. }
  79. /* SWI with SYS_ call number and three parameters */
  80. static inline uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
  81. uintptr_t parm2, uintptr_t parm3)
  82. {
  83. return sys_call6(nbr, parm1, parm2, parm3, 0, 0, 0);
  84. }
  85. /* SWI with SYS_ call number and four parameters */
  86. static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1,
  87. uintptr_t parm2, uintptr_t parm3,
  88. uintptr_t parm4)
  89. {
  90. return sys_call6(nbr, parm1, parm2, parm3, parm4, 0, 0);
  91. }
  92. /* SWI with SYS_ call number and five parameters */
  93. static inline uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1,
  94. uintptr_t parm2, uintptr_t parm3,
  95. uintptr_t parm4, uintptr_t parm5)
  96. {
  97. return sys_call6(nbr, parm1, parm2, parm3, parm4, parm5, 0);
  98. }
  99. static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
  100. uintptr_t parm2, uintptr_t parm3,
  101. uintptr_t parm4, uintptr_t parm5,
  102. uintptr_t parm6)
  103. {
  104. register uint64_t reg0 __asm__("rax") = (uint64_t)(nbr);
  105. register uint64_t reg1 __asm__("rdi") = (uint64_t)(parm1);
  106. register uint64_t reg2 __asm__("rsi") = (uint64_t)(parm2);
  107. register uint64_t reg3 __asm__("rdx") = (uint64_t)(parm3);
  108. register uint64_t reg4 __asm__("r10") = (uint64_t)(parm4);
  109. register uint64_t reg5 __asm__("r8") = (uint64_t)(parm5);
  110. register uint64_t reg6 __asm__("r9") = (uint64_t)(parm6);
  111. __asm__ __volatile__
  112. (
  113. "syscall"
  114. : "=r"(reg0)
  115. : "r"(reg0), "r"(reg1), "r"(reg2),
  116. "r"(reg3), "r"(reg4), "r"(reg5), "r"(reg6)
  117. : "memory"
  118. );
  119. return reg0;
  120. }
  121. #undef EXTERN
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif
  126. #endif /* __ARCH_X86_64_INCLUDE_INTEL64_SYSCALL_H */