args.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef INCLUDED_ARGS_H
  20. #define INCLUDED_ARGS_H
  21. #include <kernel/types.h>
  22. #include <arch/sys.h>
  23. /*
  24. * arguments in 64 bit:
  25. * %rdi, %rsi, %rdx, %rcx, %r8, %9, and stack.
  26. * */
  27. #define get_arg(type, argno) ({ \
  28. __uint64_t __res; \
  29. if (argno < 7) { \
  30. if (argno == 1) \
  31. __res = get_rdi(); \
  32. else if (argno == 2) \
  33. __res = get_rsi(); \
  34. else if (argno == 3) \
  35. __res = get_rdx(); \
  36. else if (argno == 4) \
  37. __res = get_rcx(); \
  38. else if (argno == 5) \
  39. __res = get_r8(); \
  40. else if (argno == 6) \
  41. __res = get_r9(); \
  42. } \
  43. else { \
  44. argno -= 6; \
  45. __uint64_t *p = (__uint64_t *) \
  46. get_rsp(); \
  47. __res = p[argno]; \
  48. } \
  49. (type) __res; \
  50. })
  51. #endif