syscall.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright Altera Corporation (C) <2014>. All rights reserved
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_NIOS2_SYSCALL_H__
  17. #define __ASM_NIOS2_SYSCALL_H__
  18. #include <linux/err.h>
  19. #include <linux/sched.h>
  20. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  21. {
  22. return regs->r2;
  23. }
  24. static inline void syscall_rollback(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. regs->r2 = regs->orig_r2;
  28. regs->r7 = regs->orig_r7;
  29. }
  30. static inline long syscall_get_error(struct task_struct *task,
  31. struct pt_regs *regs)
  32. {
  33. return regs->r7 ? regs->r2 : 0;
  34. }
  35. static inline long syscall_get_return_value(struct task_struct *task,
  36. struct pt_regs *regs)
  37. {
  38. return regs->r2;
  39. }
  40. static inline void syscall_set_return_value(struct task_struct *task,
  41. struct pt_regs *regs, int error, long val)
  42. {
  43. if (error) {
  44. /* error < 0, but nios2 uses > 0 return value */
  45. regs->r2 = -error;
  46. regs->r7 = 1;
  47. } else {
  48. regs->r2 = val;
  49. regs->r7 = 0;
  50. }
  51. }
  52. static inline void syscall_get_arguments(struct task_struct *task,
  53. struct pt_regs *regs, unsigned int i, unsigned int n,
  54. unsigned long *args)
  55. {
  56. BUG_ON(i + n > 6);
  57. switch (i) {
  58. case 0:
  59. if (!n--)
  60. break;
  61. *args++ = regs->r4;
  62. case 1:
  63. if (!n--)
  64. break;
  65. *args++ = regs->r5;
  66. case 2:
  67. if (!n--)
  68. break;
  69. *args++ = regs->r6;
  70. case 3:
  71. if (!n--)
  72. break;
  73. *args++ = regs->r7;
  74. case 4:
  75. if (!n--)
  76. break;
  77. *args++ = regs->r8;
  78. case 5:
  79. if (!n--)
  80. break;
  81. *args++ = regs->r9;
  82. case 6:
  83. if (!n--)
  84. break;
  85. default:
  86. BUG();
  87. }
  88. }
  89. static inline void syscall_set_arguments(struct task_struct *task,
  90. struct pt_regs *regs, unsigned int i, unsigned int n,
  91. const unsigned long *args)
  92. {
  93. BUG_ON(i + n > 6);
  94. switch (i) {
  95. case 0:
  96. if (!n--)
  97. break;
  98. regs->r4 = *args++;
  99. case 1:
  100. if (!n--)
  101. break;
  102. regs->r5 = *args++;
  103. case 2:
  104. if (!n--)
  105. break;
  106. regs->r6 = *args++;
  107. case 3:
  108. if (!n--)
  109. break;
  110. regs->r7 = *args++;
  111. case 4:
  112. if (!n--)
  113. break;
  114. regs->r8 = *args++;
  115. case 5:
  116. if (!n--)
  117. break;
  118. regs->r9 = *args++;
  119. case 6:
  120. if (!n)
  121. break;
  122. default:
  123. BUG();
  124. }
  125. }
  126. #endif