<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>在 2013-1-11,11:16,"Peter Teoh" <<a href="mailto:htmldeveloper@gmail.com">htmldeveloper@gmail.com</a>> 写道:<br><br></div><blockquote type="cite"><div>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-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<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" target="_blank" style="color:rgb(17,85,204)">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="background-color:rgb(255,255,255)"><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 class="Apple-tab-span" style="white-space:pre">        </span>bne<span class="Apple-tab-span" style="white-space:pre">        </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">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><font face="Arial, Lucida Grande, sans-serif"><br></font></div></div></div></blockquote><div><br></div><div> The link you provided is obviously specific for X86, rather than ARM.</div><div>Rajat mentioned that there is no definition of linkage in arch/arm. This should be true.</div><div><br></div><div> And as I know, arm use register r7 to pass system call number, and use register r0~r3 to pass parameters. This is used by Google when they implement system call in Android. </div><div> And for calling C function from assembly code is also platform specific, in ARM, it has fixed standard ABI which defines the details about how assembly code calls C function, you can never ask GCC to compile C function by passing parameters on stack and then assume this function can be called from assembly code which is implemented by other developers who obeys standard ARM ABI.</div><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div><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 class="im">On Fri, Jan 4, 2013 at 3:41 PM, Rajat Sharma <<a href="mailto:fs.rajat@gmail.com">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 class="HOEnZb"><div class="h5">><br>
><br>
><br>
> On Fri, Jan 4, 2013 at 2:24 PM, 卜弋天 <<a href="mailto:buyit@live.cn">buyit@live.cn</a>> wrote:<br>
>><br>
>><br>
>><br>
>> 在 2013-1-4,15:38,"Rajat Sharma" <<a href="mailto:fs.rajat@gmail.com">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">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">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">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">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">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">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">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>-- <br>Regards,<br>Peter Teoh
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Kernelnewbies mailing list</span><br><span><a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a></span><br><span><a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a></span><br></div></blockquote></body></html>