syscall_32.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 R3 */
  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 long syscall_get_error(struct task_struct *task,
  21. struct pt_regs *regs)
  22. {
  23. return IS_ERR_VALUE(regs->regs[0]) ? regs->regs[0] : 0;
  24. }
  25. static inline long syscall_get_return_value(struct task_struct *task,
  26. struct pt_regs *regs)
  27. {
  28. return regs->regs[0];
  29. }
  30. static inline void syscall_set_return_value(struct task_struct *task,
  31. struct pt_regs *regs,
  32. int error, long val)
  33. {
  34. if (error)
  35. regs->regs[0] = -error;
  36. else
  37. regs->regs[0] = val;
  38. }
  39. static inline void syscall_get_arguments(struct task_struct *task,
  40. struct pt_regs *regs,
  41. unsigned int i, unsigned int n,
  42. unsigned long *args)
  43. {
  44. /*
  45. * Do this simply for now. If we need to start supporting
  46. * fetching arguments from arbitrary indices, this will need some
  47. * extra logic. Presently there are no in-tree users that depend
  48. * on this behaviour.
  49. */
  50. BUG_ON(i);
  51. /* Argument pattern is: R4, R5, R6, R7, R0, R1 */
  52. switch (n) {
  53. case 6: args[5] = regs->regs[1];
  54. case 5: args[4] = regs->regs[0];
  55. case 4: args[3] = regs->regs[7];
  56. case 3: args[2] = regs->regs[6];
  57. case 2: args[1] = regs->regs[5];
  58. case 1: args[0] = regs->regs[4];
  59. break;
  60. default:
  61. BUG();
  62. }
  63. }
  64. static inline void syscall_set_arguments(struct task_struct *task,
  65. struct pt_regs *regs,
  66. unsigned int i, unsigned int n,
  67. const unsigned long *args)
  68. {
  69. /* Same note as above applies */
  70. BUG_ON(i);
  71. switch (n) {
  72. case 6: regs->regs[1] = args[5];
  73. case 5: regs->regs[0] = args[4];
  74. case 4: regs->regs[7] = args[3];
  75. case 3: regs->regs[6] = args[2];
  76. case 2: regs->regs[5] = args[1];
  77. case 1: regs->regs[4] = args[0];
  78. break;
  79. default:
  80. BUG();
  81. }
  82. }
  83. #endif /* __ASM_SH_SYSCALL_32_H */