syscall_32.h 2.2 KB

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