Sebastian,<br><br>The _Thread_Heir->Registers are ok into the _Context_Switch() call, sp and lr both sensible.<br><br>At the 'mrs r2, cpsr' line sp is 0x40001b2c (rubbish) and pc sensible.<br><br>In _restore, after the 'ldmia r1, ...' instruction the sp and lr are loaded with the correct values from _Thread_Heir->Registers.<br>
<br>Its the 'msr cpsr, r2' messes up the sp and lr<br><br><br><br><br><div class="gmail_quote">On 25 February 2013 08:04, Sebastian Huber <span dir="ltr"><<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</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 02/22/2013 06:31 PM, Matthew J Fletcher wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
 >Which code is at address 0x7fffe369 - 1?  The context will be initialized in<br>
the function >_Thread_Load_environment().<br>
<br>
I believe that's the issue, there is no code at that address, code starts at<br>
0x81000000<br>
<br>
In _Thread_Start(), i can see that the_thread->Start.entry_point is set to<br>
0x81007219, which is the Init() function.<br>
</blockquote>
<br></div>
This Start structure is irrelevant for the context switch.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I can also see _Thread_Load_environment() set the stack and the entry point<br>
correctly, the _Thread_Heir->Registers contains the correct information into<br>
passed into _Context_Switch.<br>
<br>
But by the 'bx lr' line in _restore the sp and lr registers are showing the<br>
wrong values, well gdb says they are wrong anyway, the sp is now 0x40001c80<br>
which is not even ram, and the lr is before code space.<br>
</blockquote>
<br></div>
Are the values (sp and lr) of heir context correct on entry of the first _CPU_Context_switch()?<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Doing a single instruction step sets the pc to 0x7fffe368, so it looks like its<br>
branched to that address, the next instruction will fault as its just some rubbish.<br>
<br>
Is it possible this code is wrong for the arm7tdmi ? its not exactly cutting<br>
edge now, there are commends in the context switch code that it was tested on a<br>
arm7tdmi but with different instructions, was this code diffrent in the past ?<br>
</blockquote>
<br></div>
The context switch code is unchanged since 2002 and it works well.  I suppose something is wrong with the call to _CPU_Context_switch() or the heir context.  I can only help you with the latest RTEMS master branch since this is what I am using.<div class="HOEnZb">
<div class="h5"><br>
<br>
-- <br>
Sebastian Huber, embedded brains GmbH<br>
<br>
Address : Dornierstr. 4, D-82178 Puchheim, Germany<br>
Phone   : <a href="tel:%2B49%2089%20189%2047%2041-16" value="+4989189474116" target="_blank">+49 89 189 47 41-16</a><br>
Fax     : <a href="tel:%2B49%2089%20189%2047%2041-09" value="+4989189474109" target="_blank">+49 89 189 47 41-09</a><br>
E-Mail  : <a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-<u></u>brains.de</a><br>
PGP     : Public key available on request.<br>
<br>
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div><br>regards</div><div>---</div><div>Matthew J Fletcher</div><br>