<div dir="ltr">> asmlinkage is defined for almost all arch:<div></div><div>> grep asmlinkage arch/arm/*/* and u got the answer.<br><br></div><div>I didn't see a definition of macro atleast in linux source I was browsing (3.2.0), Could you please point out to any one you have found.<br>
<br></div><div>Alternatively I tried more precise search:<br>linux-source-3.2.0$ grep -R "#define asmlinkage" arch/arm/<br><br></div><div>No output. Although similar search gave following result for x86:<br><br>
linux-source-3.2.0$ grep -R "#define asmlinkage" arch/x86/<br>arch/x86/include/asm/linkage.h:#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))<br>arch/x86/include/asm/linkage.h:#define asmlinkage_protect(n, ret, args...) \<br>
<br></div><div>Typically it should be defined in arch specific linkage.h file only, for arm there was none I found. If none is found, default definition is given from inlucde/linux/linkage.h which is nop:<br><br>#ifndef asmlinkage<br>
#define asmlinkage CPP_ASMLINKAGE<br>#endif<br><br></div><div>CPP_ASMLINKAGE is just extern C stuff:<br><br>#ifdef __cplusplus<br>#define CPP_ASMLINKAGE extern "C"<br>#else<br>#define CPP_ASMLINKAGE<br>#endif<br>
<br></div><div>Indeed the only meaningful definition I found for x86_32 only in arch/x86/include/asm/linkage.h:<br><br>#ifdef CONFIG_X86_32<br>#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))<br></div><div><br>
</div><div>regparm controls number or integer arguments passed to a function. And it is specific to x86 only according to gcc manuals.<br><br></div><div>Hence the above wiki FAQ seems valid for x86_32 arch, although it should specifically mention this arch dependence to avoid confusion on public forums.<br>
<br></div><div>-Rajat<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 11, 2013 at 8:43 AM, Peter Teoh <span dir="ltr"><<a href="mailto:htmldeveloper@gmail.com" target="_blank">htmldeveloper@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">asmlinkage is defined for almost all arch:<div><br></div><div>grep asmlinkage arch/arm/*/* and u got the answer.</div><div>
<br></div><div>It seemed that:</div><div><br><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<font face="Arial, Lucida Grande, sans-serif"><span style="font-size:12px;line-height:15px"> </span></font><font face="Arial, Lucida Grande, sans-serif"><span style="font-size:12px;line-height:15px"><a href="http://kernelnewbies.org/FAQ/asmlinkage" style="color:rgb(17,85,204)" target="_blank">http://kernelnewbies.org/FAQ/asmlinkage</a></span></font></div>
<div><font face="Arial, Lucida Grande, sans-serif"><br></font></div><div><font face="Arial, Lucida Grande, sans-serif">gave the impression that asmlinkage is only for system call, or associated with it. Not really, nothing to do with system call actually.</font></div>
<div><font face="Arial, Lucida Grande, sans-serif"><br></font></div><div><font face="Arial, Lucida Grande, sans-serif">Even though majority (or ALL) of syscall are defined with asmlinkage, but there are many that are not, eg, in arch/arm subdirectory:</font></div>
<div><font face="Arial, Lucida Grande, sans-serif"><br></font></div><div><div style><div><span style="font-size:12px;line-height:15px;color:rgb(34,34,34);font-family:Arial,'Lucida Grande',sans-serif">kernel/irq.c:asmlinkage void __exception_irq_entry</span></div>
<div><font color="#222222" face="Arial, Lucida Grande, sans-serif"><span style="font-size:12px;line-height:15px">kernel/process.c:asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");</span></font></div>
<div><span style="font-size:12px;line-height:15px;color:rgb(34,34,34);font-family:Arial,'Lucida Grande',sans-serif">kernel/smp.c:asmlinkage void __cpuinit secondary_start_kernel(void)</span></div><div><font color="#222222" face="Arial, Lucida Grande, sans-serif"><span style="font-size:12px;line-height:15px">kernel/smp.c:asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)</span></font></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">just a few examples. Essentially, it is just declared so that the name, for example, "do_IPI" can be called from assembly, for example in the following pair (arch/arm assumed):</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div><div><div><font color="#222222" face="arial, sans-serif">/kernel/smp.c:</font></div><div><font color="#222222" face="arial, sans-serif">asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)</font></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">./include/asm/entry-macro-multi.S:</font></div><div><font color="#222222" face="arial, sans-serif"><span style="white-space:pre-wrap">        </span>bne<span style="white-space:pre-wrap">        </span>do_IPI</font></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">More info:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><a href="http://stackoverflow.com/questions/10060168/is-asmlinkage-required-for-a-c-function-to-be-called-from-assembly" target="_blank">http://stackoverflow.com/questions/10060168/is-asmlinkage-required-for-a-c-function-to-be-called-from-assembly</a></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">From above, asmlinkage is also NOT the only way......</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div></div></div><div><div class="h5"><div><font face="Arial, Lucida Grande, sans-serif"><br></font></div><div class="gmail_quote">On Fri, Jan 4, 2013 at 6:29 PM, anish singh <span dir="ltr"><<a href="mailto:anish198519851985@gmail.com" target="_blank">anish198519851985@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Fri, Jan 4, 2013 at 3:41 PM, Rajat Sharma <<a href="mailto:fs.rajat@gmail.com" target="_blank">fs.rajat@gmail.com</a>> wrote:<br>
>> Is this correct for all architectures?<br>
><br>
> I guess not, asmlinkage is undefined for arm, so I assume this mechanism is<br>
> not there for arm.<br>
</div>then how do they do it?<br>
<div><div>><br>
><br>
><br>
> On Fri, Jan 4, 2013 at 2:24 PM, ²·ß®Ìì <<a href="mailto:buyit@live.cn" target="_blank">buyit@live.cn</a>> wrote:<br>
>><br>
>><br>
>><br>
>> ÔÚ 2013-1-4£¬15:38£¬"Rajat Sharma" <<a href="mailto:fs.rajat@gmail.com" target="_blank">fs.rajat@gmail.com</a>> дµÀ£º<br>
>><br>
>> > So with asmlinkage we request compiler to put args on stack. What is<br>
>> > advantage of this to start_kernel or in general to other functions ?<br>
>><br>
>> See its about implementation ease and little of performance too. Assuming<br>
>> the default model of keeping arguments in registers is used. lets say<br>
>> arguments are assumed to be in registers R1, R2, R3, R4, R5, R6 and beyond<br>
>> that in stack. Since system call number is a transparent argument which is<br>
>> chopped off when calling the actual kernel handler and if R1 had the system<br>
>> call number, then you have to shift all register values and stack arguments<br>
>> too.<br>
>><br>
>> Is this correct for all architectures?<br>
>><br>
>> As I remembered, ARM uses SWI instruction to implement the system call,<br>
>> it will pass system call number by register R7, and use normal register<br>
>> R0~R3 to pass parameters.<br>
>><br>
>><br>
>><br>
>> Now consider that all arguments are pushed on stack (as enforced by<br>
>> asmlinkage), you have all function argument in the beginning of the stack<br>
>> and the system call number on top of the stack. you just need to pop out<br>
>> stack top to remove system call number from function argument.<br>
>><br>
>> You might argue that why not always keep system call number on stack top<br>
>> and use registers for function arguments? But thats part of the compiler ABI<br>
>> and if you had fewer arguments lets say 2 only and used up R1 and R2 only,<br>
>> you may not jump to stack top directly for storing system call as its turn<br>
>> for R3 as argument.<br>
>><br>
>> So, isn't it simpler implementation with everything on stack?<br>
>><br>
>> -Rajat<br>
>><br>
>><br>
>> On Fri, Jan 4, 2013 at 12:13 PM, Rahul Bedarkar <<a href="mailto:rpal143@gmail.com" target="_blank">rpal143@gmail.com</a>> wrote:<br>
>>><br>
>>> Thanks. So with asmlinkage we request compiler to put args on stack. What<br>
>>> is advantage of this to start_kernel or in general to other functions ?<br>
>>><br>
>>> Regards,<br>
>>> Rahul<br>
>>><br>
>>><br>
>>> On Thu, Jan 3, 2013 at 9:34 PM, Mulyadi Santosa<br>
>>> <<a href="mailto:mulyadi.santosa@gmail.com" target="_blank">mulyadi.santosa@gmail.com</a>> wrote:<br>
>>>><br>
>>>> On Thu, Jan 3, 2013 at 7:40 PM, Rahul Bedarkar <<a href="mailto:rpal143@gmail.com" target="_blank">rpal143@gmail.com</a>><br>
>>>> wrote:<br>
>>>> > Hi,<br>
>>>> ><br>
>>>> > I was searching for asmlinkage and found that it is already explained<br>
>>>> > at<br>
>>>> > <a href="http://kernelnewbies.org/FAQ/asmlinkage" target="_blank">http://kernelnewbies.org/FAQ/asmlinkage</a><br>
>>>> ><br>
>>>> > But I didn't get this. Can someone tell me about it in brief ?<br>
>>>><br>
>>>> the point is, parameters which is usually passed via stack, is passed<br>
>>>> using different way.<br>
>>>><br>
>>>> A good example is system call.... they are passed using registers IIRC<br>
>>>><br>
>>>><br>
>>>> --<br>
>>>> regards,<br>
>>>><br>
>>>> Mulyadi Santosa<br>
>>>> Freelance Linux trainer and consultant<br>
>>>><br>
>>>> blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>
>>>> training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a><br>
>>><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> Kernelnewbies mailing list<br>
>>> <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
>>> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
>>><br>
>><br>
>> _______________________________________________<br>
>> Kernelnewbies mailing list<br>
>> <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
>> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
><br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br>Regards,<br>Peter Teoh
</font></span></div>
</blockquote></div><br></div>