syscall.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright Altera Corporation (C) <2014>. All rights reserved
  4. */
  5. #ifndef __ASM_NIOS2_SYSCALL_H__
  6. #define __ASM_NIOS2_SYSCALL_H__
  7. #include <uapi/linux/audit.h>
  8. #include <linux/err.h>
  9. #include <linux/sched.h>
  10. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  11. {
  12. return regs->r2;
  13. }
  14. static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)
  15. {
  16. regs->r2 = nr;
  17. }
  18. static inline void syscall_rollback(struct task_struct *task,
  19. struct pt_regs *regs)
  20. {
  21. regs->r2 = regs->orig_r2;
  22. regs->r7 = regs->orig_r7;
  23. }
  24. static inline long syscall_get_error(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. return regs->r7 ? regs->r2 : 0;
  28. }
  29. static inline long syscall_get_return_value(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. return regs->r2;
  33. }
  34. static inline void syscall_set_return_value(struct task_struct *task,
  35. struct pt_regs *regs, int error, long val)
  36. {
  37. if (error) {
  38. /* error < 0, but nios2 uses > 0 return value */
  39. regs->r2 = -error;
  40. regs->r7 = 1;
  41. } else {
  42. regs->r2 = val;
  43. regs->r7 = 0;
  44. }
  45. }
  46. static inline void syscall_get_arguments(struct task_struct *task,
  47. struct pt_regs *regs, unsigned long *args)
  48. {
  49. *args++ = regs->r4;
  50. *args++ = regs->r5;
  51. *args++ = regs->r6;
  52. *args++ = regs->r7;
  53. *args++ = regs->r8;
  54. *args = regs->r9;
  55. }
  56. static inline void syscall_set_arguments(struct task_struct *task,
  57. struct pt_regs *regs, const unsigned long *args)
  58. {
  59. regs->r4 = *args++;
  60. regs->r5 = *args++;
  61. regs->r6 = *args++;
  62. regs->r7 = *args++;
  63. regs->r8 = *args++;
  64. regs->r9 = *args;
  65. }
  66. static inline int syscall_get_arch(struct task_struct *task)
  67. {
  68. return AUDIT_ARCH_NIOS2;
  69. }
  70. #endif