syscall.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Magic syscall break down functions
  3. *
  4. * Copyright 2010 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef __ASM_BLACKFIN_SYSCALL_H__
  9. #define __ASM_BLACKFIN_SYSCALL_H__
  10. /*
  11. * Blackfin syscalls are simple:
  12. * enter:
  13. * p0: syscall number
  14. * r{0,1,2,3,4,5}: syscall args 0,1,2,3,4,5
  15. * exit:
  16. * r0: return/error value
  17. */
  18. #include <linux/err.h>
  19. #include <linux/sched.h>
  20. #include <asm/ptrace.h>
  21. static inline long
  22. syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  23. {
  24. return regs->p0;
  25. }
  26. static inline void
  27. syscall_rollback(struct task_struct *task, struct pt_regs *regs)
  28. {
  29. regs->p0 = regs->orig_p0;
  30. }
  31. static inline long
  32. syscall_get_error(struct task_struct *task, struct pt_regs *regs)
  33. {
  34. return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
  35. }
  36. static inline long
  37. syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
  38. {
  39. return regs->r0;
  40. }
  41. static inline void
  42. syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  43. int error, long val)
  44. {
  45. regs->r0 = error ? -error : val;
  46. }
  47. /**
  48. * syscall_get_arguments()
  49. * @task: unused
  50. * @regs: the register layout to extract syscall arguments from
  51. * @i: first syscall argument to extract
  52. * @n: number of syscall arguments to extract
  53. * @args: array to return the syscall arguments in
  54. *
  55. * args[0] gets i'th argument, args[n - 1] gets the i+n-1'th argument
  56. */
  57. static inline void
  58. syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  59. unsigned int i, unsigned int n, unsigned long *args)
  60. {
  61. /*
  62. * Assume the ptrace layout doesn't change -- r5 is first in memory,
  63. * then r4, ..., then r0. So we simply reverse the ptrace register
  64. * array in memory to store into the args array.
  65. */
  66. long *aregs = &regs->r0 - i;
  67. BUG_ON(i > 5 || i + n > 6);
  68. while (n--)
  69. *args++ = *aregs--;
  70. }
  71. /* See syscall_get_arguments() comments */
  72. static inline void
  73. syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
  74. unsigned int i, unsigned int n, const unsigned long *args)
  75. {
  76. long *aregs = &regs->r0 - i;
  77. BUG_ON(i > 5 || i + n > 6);
  78. while (n--)
  79. *aregs-- = *args++;
  80. }
  81. #endif