syscall_32.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. case 0:
  61. break;
  62. default:
  63. BUG();
  64. }
  65. }
  66. static inline void syscall_set_arguments(struct task_struct *task,
  67. struct pt_regs *regs,
  68. unsigned int i, unsigned int n,
  69. const unsigned long *args)
  70. {
  71. /* Same note as above applies */
  72. BUG_ON(i);
  73. switch (n) {
  74. case 6: regs->regs[1] = args[5];
  75. case 5: regs->regs[0] = args[4];
  76. case 4: regs->regs[7] = args[3];
  77. case 3: regs->regs[6] = args[2];
  78. case 2: regs->regs[5] = args[1];
  79. case 1: regs->regs[4] = args[0];
  80. break;
  81. default:
  82. BUG();
  83. }
  84. }
  85. #endif /* __ASM_SH_SYSCALL_32_H */