syscall_32.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __ASM_SH_SYSCALL_32_H
  2. #define __ASM_SH_SYSCALL_32_H
  3. #include <linux/kernel.h>
  4. #include <linux/sched.h>
  5. #include <asm/ptrace.h>
  6. /* The system call number is given by the user in %g1 */
  7. static inline long syscall_get_nr(struct task_struct *task,
  8. struct pt_regs *regs)
  9. {
  10. return (regs->tra >= 0) ? regs->regs[3] : -1L;
  11. }
  12. static inline void syscall_rollback(struct task_struct *task,
  13. struct pt_regs *regs)
  14. {
  15. /*
  16. * XXX: This needs some thought. On SH we don't
  17. * save away the original r0 value anywhere.
  18. */
  19. }
  20. static inline bool syscall_has_error(struct pt_regs *regs)
  21. {
  22. return (regs->sr & 0x1) ? true : false;
  23. }
  24. static inline void syscall_set_error(struct pt_regs *regs)
  25. {
  26. regs->sr |= 0x1;
  27. }
  28. static inline void syscall_clear_error(struct pt_regs *regs)
  29. {
  30. regs->sr &= ~0x1;
  31. }
  32. static inline long syscall_get_error(struct task_struct *task,
  33. struct pt_regs *regs)
  34. {
  35. return syscall_has_error(regs) ? regs->regs[0] : 0;
  36. }
  37. static inline long syscall_get_return_value(struct task_struct *task,
  38. struct pt_regs *regs)
  39. {
  40. return regs->regs[0];
  41. }
  42. static inline void syscall_set_return_value(struct task_struct *task,
  43. struct pt_regs *regs,
  44. int error, long val)
  45. {
  46. if (error) {
  47. syscall_set_error(regs);
  48. regs->regs[0] = -error;
  49. } else {
  50. syscall_clear_error(regs);
  51. regs->regs[0] = val;
  52. }
  53. }
  54. static inline void syscall_get_arguments(struct task_struct *task,
  55. struct pt_regs *regs,
  56. unsigned int i, unsigned int n,
  57. unsigned long *args)
  58. {
  59. /*
  60. * Do this simply for now. If we need to start supporting
  61. * fetching arguments from arbitrary indices, this will need some
  62. * extra logic. Presently there are no in-tree users that depend
  63. * on this behaviour.
  64. */
  65. BUG_ON(i);
  66. /* Argument pattern is: R4, R5, R6, R7, R0, R1 */
  67. switch (n) {
  68. case 6: args[5] = regs->regs[1];
  69. case 5: args[4] = regs->regs[0];
  70. case 4: args[3] = regs->regs[7];
  71. case 3: args[2] = regs->regs[6];
  72. case 2: args[1] = regs->regs[5];
  73. case 1: args[0] = regs->regs[4];
  74. break;
  75. default:
  76. BUG();
  77. }
  78. }
  79. static inline void syscall_set_arguments(struct task_struct *task,
  80. struct pt_regs *regs,
  81. unsigned int i, unsigned int n,
  82. const unsigned long *args)
  83. {
  84. /* Same note as above applies */
  85. BUG_ON(i);
  86. switch (n) {
  87. case 6: regs->regs[1] = args[5];
  88. case 5: regs->regs[0] = args[4];
  89. case 4: regs->regs[7] = args[3];
  90. case 3: regs->regs[6] = args[2];
  91. case 2: regs->regs[5] = args[1];
  92. case 1: regs->regs[4] = args[0];
  93. break;
  94. default:
  95. BUG();
  96. }
  97. }
  98. #endif /* __ASM_SH_SYSCALL_32_H */