When I read the softirq of Linux, I found the following code:
asm volatile ("swi 0x0 @ syscall " #name \
: "=r" (_a1) \
: "r" (_nr) ASM_ARGS_##nr \
: "memory"); \
_a1; })
I knew “r” (_nr)
is the input list, but what does ASM_ARGS_##nr
mean?
CodePudding user response:
The operator ##
is being used for the concatenation of identifiers within a preprocessor macro, as can be seen by the line continuation character \
, ASM_ARGS_
or nr
or both of them are arguments of that macro.
The whole macro will probably look similar to this fragment (that I found in another question):
#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
#define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
#define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
#define LOADREGS_5(a1, a2, a3, a4, a5) \
register int _v1 asm ("v1") = (int) (a5); \
LOADREGS_4 (a1, a2, a3, a4)
#define LOADREGS_6(a1, a2, a3, a4, a5, a6) \
register int _v2 asm ("v2") = (int) (a6); \
LOADREGS_5 (a1, a2, a3, a4, a5)
#define MYLIBC_SYSCALL(name, nargs, args...) \
({ \
unsigned int retval; \
{ \
register int _a1 asm ("r0"), _nargs asm ("r7"); \
LOADREGS_##nargs(args) \
_nargs = __NR_##name; \
asm volatile ( \
"swi 0x0" \
:"=r"(_a1) \
:"r"(_nargs) ASM_ARGS_##nargs \
: "memory" ); \
But this fragment will help to understand your question about ##
. Here ASM_ARGS_##nargs
results in the combination of the argument nargs
(which is an integer literal between 0
and 3
) as to get an expression like ASM_ARGS_0
, ASM_ARGS_1
and so on, which itself is a macro. In fact, ASM_ARGS_0
will probably be replaced by nothing, and ASM_ARGS_3 will be replaced by
, "r" (_a1), "r" (_a2), "r" (_a3)
.