I am writing a C function that will be invoked from assembly code.
(Specifically, I want to do some checking job in the path of system call handling in linux kernel, so I will call the c function before a system call is dispatched in entry_32.S)
I am confused with the "asmlinkage" modifier when defining my c function.
I know asmlinkage is to tell the compiler that the parameters will be passed through stack.
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
Questions:
(1) Is asmlinkage required when defining such a function that will be invoked from assembly code?
(2) what is the default calling convention in gcc. If I omit "asmlinkage" when defining a c function, does it imply _cdecl or fastcall?
(3) if the default calling convention is cdecl, why is asmlinkage needed, considering cdecl is equal to asmlinkage modifier? (am I correct here?)
(4) why are those system call functions all declared with asmlinkage. Can we copy the parameters to registers first, then call those system call functions? From my point of view, in x86, when issuing a system call, the parameters are readily saved in registers; then why bother to save then in stack to enforce such passing parameters via stack convention?
Finally, can anybody recommend some resources/books that I can refer to for such mix assembly/c programming?