syscall.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef __ASM_SPARC_SYSCALL_H
  2. #define __ASM_SPARC_SYSCALL_H
  3. #include <uapi/linux/audit.h>
  4. #include <linux/kernel.h>
  5. #include <linux/sched.h>
  6. #include <asm/ptrace.h>
  7. #include <asm/thread_info.h>
  8. /*
  9. * The syscall table always contains 32 bit pointers since we know that the
  10. * address of the function to be called is (way) below 4GB. So the "int"
  11. * type here is what we want [need] for both 32 bit and 64 bit systems.
  12. */
  13. extern const unsigned int sys_call_table[];
  14. /* The system call number is given by the user in %g1 */
  15. static inline long syscall_get_nr(struct task_struct *task,
  16. struct pt_regs *regs)
  17. {
  18. int syscall_p = pt_regs_is_syscall(regs);
  19. return (syscall_p ? regs->u_regs[UREG_G1] : -1L);
  20. }
  21. static inline void syscall_rollback(struct task_struct *task,
  22. struct pt_regs *regs)
  23. {
  24. /* XXX This needs some thought. On Sparc we don't
  25. * XXX save away the original %o0 value somewhere.
  26. * XXX Instead we hold it in register %l5 at the top
  27. * XXX level trap frame and pass this down to the signal
  28. * XXX dispatch code which is the only place that value
  29. * XXX ever was needed.
  30. */
  31. }
  32. #ifdef CONFIG_SPARC32
  33. static inline bool syscall_has_error(struct pt_regs *regs)
  34. {
  35. return (regs->psr & PSR_C) ? true : false;
  36. }
  37. static inline void syscall_set_error(struct pt_regs *regs)
  38. {
  39. regs->psr |= PSR_C;
  40. }
  41. static inline void syscall_clear_error(struct pt_regs *regs)
  42. {
  43. regs->psr &= ~PSR_C;
  44. }
  45. #else
  46. static inline bool syscall_has_error(struct pt_regs *regs)
  47. {
  48. return (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)) ? true : false;
  49. }
  50. static inline void syscall_set_error(struct pt_regs *regs)
  51. {
  52. regs->tstate |= (TSTATE_XCARRY | TSTATE_ICARRY);
  53. }
  54. static inline void syscall_clear_error(struct pt_regs *regs)
  55. {
  56. regs->tstate &= ~(TSTATE_XCARRY | TSTATE_ICARRY);
  57. }
  58. #endif
  59. static inline long syscall_get_error(struct task_struct *task,
  60. struct pt_regs *regs)
  61. {
  62. long val = regs->u_regs[UREG_I0];
  63. return (syscall_has_error(regs) ? -val : 0);
  64. }
  65. static inline long syscall_get_return_value(struct task_struct *task,
  66. struct pt_regs *regs)
  67. {
  68. long val = regs->u_regs[UREG_I0];
  69. return val;
  70. }
  71. static inline void syscall_set_return_value(struct task_struct *task,
  72. struct pt_regs *regs,
  73. int error, long val)
  74. {
  75. if (error) {
  76. syscall_set_error(regs);
  77. regs->u_regs[UREG_I0] = -error;
  78. } else {
  79. syscall_clear_error(regs);
  80. regs->u_regs[UREG_I0] = val;
  81. }
  82. }
  83. static inline void syscall_get_arguments(struct task_struct *task,
  84. struct pt_regs *regs,
  85. unsigned int i, unsigned int n,
  86. unsigned long *args)
  87. {
  88. int zero_extend = 0;
  89. unsigned int j;
  90. #ifdef CONFIG_SPARC64
  91. if (test_tsk_thread_flag(task, TIF_32BIT))
  92. zero_extend = 1;
  93. #endif
  94. for (j = 0; j < n; j++) {
  95. unsigned long val = regs->u_regs[UREG_I0 + i + j];
  96. if (zero_extend)
  97. args[j] = (u32) val;
  98. else
  99. args[j] = val;
  100. }
  101. }
  102. static inline void syscall_set_arguments(struct task_struct *task,
  103. struct pt_regs *regs,
  104. unsigned int i, unsigned int n,
  105. const unsigned long *args)
  106. {
  107. unsigned int j;
  108. for (j = 0; j < n; j++)
  109. regs->u_regs[UREG_I0 + i + j] = args[j];
  110. }
  111. static inline int syscall_get_arch(void)
  112. {
  113. return is_32bit_task() ? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64;
  114. }
  115. #endif /* __ASM_SPARC_SYSCALL_H */