<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Calling a function in kernel initialization code</title><link>https://community.arm.com/developer/tools-software/tools/f/armds-forum/1063/calling-a-function-in-kernel-initialization-code</link><description> Note: This was originally posted on 3rd September 2012 at http://forums.arm.com As part of a project I&amp;#39;m trying to modify the entry point to an ARM Linux kernel through the file entry-common.S. I&amp;#39;m not quite familiar with the ARM architecture but I&amp;#39;m</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Calling a function in kernel initialization code</title><link>https://community.arm.com/thread/3262?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 11:07:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d5f33fd6-6338-4a32-98fb-72cf4f5fd3d6</guid><dc:creator>Peter Harris</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 3rd September 2012 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I&amp;#39;m not 100% sure for Linux - the calling conventions are a little arcane for some of the entry point stuff, but I think the issue is the:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;adr lr,a2cont&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Normally for ARM the lr contains the return address, so assuming the sys call entry has something valid there (I would expect it to) then you&amp;#39;ve just corrupted the valid return address that was in the link register. You have to save it to stack, and then restore it after your handler returns.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;*EDIT* &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Looking at the original Linux code I&amp;#39;m not sure that&amp;#39;s the problem - it corrupts lr too. Are you sure the handler you are jumping to is doing the right thing?&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling a function in kernel initialization code</title><link>https://community.arm.com/thread/3261?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 11:07:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2a815901-877f-4ceb-aec0-ae96a4d63fc8</guid><dc:creator>Jerry Fan</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 10th September 2012 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Please make sure that your &amp;quot;system call&amp;quot;&amp;#160; will return with &amp;quot;mov pc, lr&amp;quot; .&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling a function in kernel initialization code</title><link>https://community.arm.com/thread/3260?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 11:07:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e1d2f11a-066e-448b-ae67-a3cfaa1c633c</guid><dc:creator>Hussain M</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 4th September 2012 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;br /&gt;*EDIT* &lt;br /&gt;&lt;br /&gt;Looking at the original Linux code I&amp;#39;m not sure that&amp;#39;s the problem - it corrupts lr too. Are you sure the handler you are jumping to is doing the right thing?&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;For testing, it&amp;#39;s like a system call function and does nothing, it just returns an integer.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling a function in kernel initialization code</title><link>https://community.arm.com/thread/3259?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 11:07:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1dc37ede-2be3-4a80-8585-178ca4723650</guid><dc:creator>Hussain M</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 3rd September 2012 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;I&amp;#39;m not 100% sure for Linux - the calling conventions are a little arcane for some of the entry point stuff, but I think the issue is the:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;adr lr,a2cont&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Normally for ARM the lr contains the return address, so assuming the sys call entry has something valid there (I would expect it to) then you&amp;#39;ve just corrupted the valid return address that was in the link register. You have to save it to stack, and then restore it after your handler returns.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Thanks for the answer. By this line: &lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;adr lr,a2cont&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I was basically trying to have a return address to resume execution from, when the call returns. That is why, I added the label a2cont and loaded its address to the lr register. Later on in the original Linux code: &lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;adr lr, BSYM(ret_fast_syscall)&amp;#160; @ return address&lt;br /&gt;&lt;/code&gt;&lt;span&gt; &lt;/span&gt;&lt;br /&gt;&lt;span&gt;the authors load the desired return address before making the actual system call.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>