| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /* Copyright (C) 2021 Rain */
- /* This file is part of XNIX. */
- /*
- XNIX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) and later version.
- */
- /*
- XNIX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- /*
- You should have received a copy of the GNU General Public License
- along with XNIX. If not, see <https://www.gnu.org/licenses/>.
- */
- #ifndef INCLUDED_ARGS_H
- #define INCLUDED_ARGS_H
- #include <kernel/types.h>
- #include <arch/sys.h>
- /*
- * arguments in 64 bit:
- * %rdi, %rsi, %rdx, %rcx, %r8, %9, and stack.
- * */
- #define get_arg(type, argno) ({ \
- __uint64_t __res; \
- if (argno < 7) { \
- if (argno == 1) \
- __res = get_rdi(); \
- else if (argno == 2) \
- __res = get_rsi(); \
- else if (argno == 3) \
- __res = get_rdx(); \
- else if (argno == 4) \
- __res = get_rcx(); \
- else if (argno == 5) \
- __res = get_r8(); \
- else if (argno == 6) \
- __res = get_r9(); \
- } \
- else { \
- argno -= 6; \
- __uint64_t *p = (__uint64_t *) \
- get_rsp(); \
- __res = p[argno]; \
- } \
- (type) __res; \
- })
- #endif
|