Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Re: [lpc2000] GNU inline assembler return value

Re: [lpc2000] GNU inline assembler return value

2005-07-11 by 42Bastian Schick

xjag74 <detlef.weidner@...> schrieb am Mon, 11 Jul 2005 15:00:32 
-0000:

> Hi,
>
> I wonder why GCC don't compile that simple code:
>
> static inline unsigned StackPointerValue(void)
> {
>  unsigned long val;
>  asm volatile (" str R13, retval");
>  return val;
> }
>
> When I try to compile the following error appears:
> "Internal_relocation (type: OFFSET_IMM) not fixed up"

gcc (or better gas) does not know anything about retval, so it takes it
as external and gets confused.

This works:

long sp(void)
{
   long val;
   asm(" mov %r0,sp":"=r"(val));
   return val;
}


>
> What does that mean? How can I get that running?
>
> Best regards
> XJAG74
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>



-- 
42Bastian Schick

Re: [lpc2000] GNU inline assembler return value

2005-07-11 by Bill Knight

On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:

>Hi,

>I wonder why GCC don't compile that simple code:

>static inline unsigned StackPointerValue(void)
>{
> unsigned long val;
> asm volatile (" str R13, retval");
> return val;
>}

>When I try to compile the following error appears:
>"Internal_relocation (type: OFFSET_IMM) not fixed up"

>What does that mean? How can I get that running?


1st, 'retval' is not 'val'

I haven't compiled this but try

static inline unsigned StackPointerValue(void)

 unsigned long retval;
 asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs */ );
 return retval;


Regards
-Bill Knight
R O SoftWare &
http://www.theARMPatch.com

Re: [lpc2000] GNU inline assembler return value

2005-07-11 by Richard Duits

Copying one register to another is done with the "mov" instruction:

unsigned long retval;
asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
return retval;

An alternative in this case would be:

unsigned long stackptr __asm("sp");
return stackptr;

Regards,
Richard Duits


Bill Knight wrote:
Show quoted textHide quoted text
> On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
>
> >Hi,
>
> >I wonder why GCC don't compile that simple code:
>
> >static inline unsigned StackPointerValue(void)
> >{
> > unsigned long val;
> > asm volatile (" str R13, retval");
> > return val;
> >}
>
> >When I try to compile the following error appears:
> >"Internal_relocation (type: OFFSET_IMM) not fixed up"
>
> >What does that mean? How can I get that running?
>
>
> 1st, 'retval' is not 'val'
>
> I haven't compiled this but try
>
> static inline unsigned StackPointerValue(void)
>
> unsigned long retval;
> asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs */ );
> return retval;
>
>
> Regards
> -Bill Knight
> R O SoftWare &
> http://www.theARMPatch.com
>
>
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
>     *  Visit your group "lpc2000
>       <http://groups.yahoo.com/group/lpc2000>" on the web.
>        
>     *  To unsubscribe from this group, send an email to:
>        lpc2000-unsubscribe@yahoogroups.com
>       <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>        
>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>

Re: [lpc2000] GNU inline assembler return value

2005-07-11 by Richard Duits

I made a few errors in this short post...
Destination register should be on the left:

unsigned long retval
asm volatile ("mov %0, sp" : "=r" (retval) : /* no inputs */ );
return retval;

and the __asm keyword only works if you include the register keyword and 
this will generate a warning about using an uninitialized variable:

register unsigned long stackptr __asm("sp");
return stackptr;

Regards,
Richard Duits


Richard Duits wrote:
Show quoted textHide quoted text
> Copying one register to another is done with the "mov" instruction:
>
> unsigned long retval
> asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
> return retval;
>
> An alternative in this case would be:
>
> unsigned long stackptr __asm("sp");
> return stackptr;
>
> Regards,
> Richard Duits
>
>
> Bill Knight wrote:
>
> > On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
> >
> > >Hi,
> >
> > >I wonder why GCC don't compile that simple code:
> >
> > >static inline unsigned StackPointerValue(void)
> > >{
> > > unsigned long val;
> > > asm volatile (" str R13, retval");
> > > return val;
> > >}
> >
> > >When I try to compile the following error appears:
> > >"Internal_relocation (type: OFFSET_IMM) not fixed up"
> >
> > >What does that mean? How can I get that running?
> >
> >
> > 1st, 'retval' is not 'val'
> >
> > I haven't compiled this but try
> >
> > static inline unsigned StackPointerValue(void)
> >
> > unsigned long retval;
> > asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs */ );
> > return retval;
> >
> >
> > Regards
> > -Bill Knight
> > R O SoftWare &
> > http://www.theARMPatch.com
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> > YAHOO! GROUPS LINKS
> >
> >     *  Visit your group "lpc2000
> >       <http://groups.yahoo.com/group/lpc2000>" on the web.
> >       
> >     *  To unsubscribe from this group, send an email to:
> >        lpc2000-unsubscribe@yahoogroups.com
> >       <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
> >       
> >     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> >       Service <http://docs.yahoo.com/info/terms/>.
> >
> >
> > ------------------------------------------------------------------------
> >
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
>     *  Visit your group "lpc2000
>       <http://groups.yahoo.com/group/lpc2000>" on the web.
>        
>     *  To unsubscribe from this group, send an email to:
>        lpc2000-unsubscribe@yahoogroups.com
>       <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>        
>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>

Re: [lpc2000] GNU inline assembler return value

2005-07-11 by Bill Knight

yes, I blew it.  Didn't check the docs and had my head on a totally
different project.  Saw the correct answer shortly after posting mine.

-Bill
Show quoted textHide quoted text
On Mon, 11 Jul 2005 19:22:53 +0200, Richard Duits wrote:

>Copying one register to another is done with the "mov" instruction:

>unsigned long retval;
>asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
>return retval;

>An alternative in this case would be:

>unsigned long stackptr __asm("sp");
>return stackptr;

>Regards,
>Richard Duits


>Bill Knight wrote:

>> On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
>>
>> >Hi,
>>
>> >I wonder why GCC don't compile that simple code:
>>
>> >static inline unsigned StackPointerValue(void)
>> >{
>> > unsigned long val;
>> > asm volatile (" str R13, retval");
>> > return val;
>> >}
>>
>> >When I try to compile the following error appears:
>> >"Internal_relocation (type: OFFSET_IMM) not fixed up"
>>
>> >What does that mean? How can I get that running?
>>
>>
>> 1st, 'retval' is not 'val'
>>
>> I haven't compiled this but try
>>
>> static inline unsigned StackPointerValue(void)
>>
>> unsigned long retval;
>> asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs */ );
>> return retval;
>>
>>
>> Regards
>> -Bill Knight
>> R O SoftWare &
>> http://www.theARMPatch.com
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>> YAHOO! GROUPS LINKS
>>
>>     *  Visit your group "lpc2000
>>       <http://groups.yahoo.com/group/lpc2000>" on the web.
>>        
>>     *  To unsubscribe from this group, send an email to:
>>        lpc2000-unsubscribe@yahoogroups.com
>>       <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>>        
>>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>>       Service <http://docs.yahoo.com/info/terms/>.
>>
>>
>> ------------------------------------------------------------------------
>>



> 
>Yahoo! Groups Links



>

Re: GNU inline assembler return value

2005-07-12 by xjag74

Thank you, that's it!
For GCC you have to type:

  static inline unsigned StackPointerValue(void)
  {
    register unsigned long stackptr asm("sp");
    return stackptr;
  }

Regards
xjag


--- In lpc2000@yahoogroups.com, "Bill Knight" <BillK@t...> wrote:
> yes, I blew it.  Didn't check the docs and had my head on a totally
> different project.  Saw the correct answer shortly after posting 
mine.
> 
> -Bill
> 
> 
> On Mon, 11 Jul 2005 19:22:53 +0200, Richard Duits wrote:
> 
> >Copying one register to another is done with the "mov" instruction:
> 
> >unsigned long retval;
> >asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
> >return retval;
> 
> >An alternative in this case would be:
> 
> >unsigned long stackptr __asm("sp");
> >return stackptr;
> 
> >Regards,
> >Richard Duits
> 
> 
> >Bill Knight wrote:
> 
> >> On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
> >>
> >> >Hi,
> >>
> >> >I wonder why GCC don't compile that simple code:
> >>
> >> >static inline unsigned StackPointerValue(void)
> >> >{
> >> > unsigned long val;
> >> > asm volatile (" str R13, retval");
> >> > return val;
> >> >}
> >>
> >> >When I try to compile the following error appears:
> >> >"Internal_relocation (type: OFFSET_IMM) not fixed up"
> >>
> >> >What does that mean? How can I get that running?
> >>
> >>
> >> 1st, 'retval' is not 'val'

yes, I know it was late ;-)

> >>
> >> I haven't compiled this but try
> >>
> >> static inline unsigned StackPointerValue(void)
> >>
> >> unsigned long retval;
> >> asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs */ );
> >> return retval;
> >>
> >>
> >> Regards
> >> -Bill Knight
> >> R O SoftWare &
> >> http://www.theARMPatch.com
> >>
> >>
> >>
> >>
> >> -----------------------------------------------------------------
-------
> >> YAHOO! GROUPS LINKS
> >>
> >>     *  Visit your group "lpc2000
> >>       <http://groups.yahoo.com/group/lpc2000>" on the web.
> >>        
> >>     *  To unsubscribe from this group, send an email to:
> >>        lpc2000-unsubscribe@yahoogroups.com
> >>       <mailto:lpc2000-unsubscribe@yahoogroups.com?
subject=Unsubscribe>
> >>        
> >>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms 
of
> >>       Service <http://docs.yahoo.com/info/terms/>.
> >>
> >>
> >> -----------------------------------------------------------------
-------
Show quoted textHide quoted text
> >>
> 
> 
> 
> > 
> >Yahoo! Groups Links
> 
> 
> 
> >

Re: GNU inline assembler return value

2005-07-12 by xjag74

Now I realized that the interrupts use another stack (IRQ stack) than 
a normal routine (User stack).

Is it possible to read the User stack pointer within the ISR?

What I try to do is to capture the SP every timer1 ISR entry (200us) 
and to store the maximum value to figure out if the stack collides 
with the data area.

The stack check option of the GNU compiler is not working.

Regards
xjag




--- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> wrote:
> Thank you, that's it!
> For GCC you have to type:
> 
>   static inline unsigned StackPointerValue(void)
>   {
>     register unsigned long stackptr asm("sp");
>     return stackptr;
>   }
> 
> Regards
> xjag
> 
> 
> --- In lpc2000@yahoogroups.com, "Bill Knight" <BillK@t...> wrote:
> > yes, I blew it.  Didn't check the docs and had my head on a 
totally
> > different project.  Saw the correct answer shortly after posting 
> mine.
> > 
> > -Bill
> > 
> > 
> > On Mon, 11 Jul 2005 19:22:53 +0200, Richard Duits wrote:
> > 
> > >Copying one register to another is done with the "mov" 
instruction:
> > 
> > >unsigned long retval;
> > >asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
> > >return retval;
> > 
> > >An alternative in this case would be:
> > 
> > >unsigned long stackptr __asm("sp");
> > >return stackptr;
> > 
> > >Regards,
> > >Richard Duits
> > 
> > 
> > >Bill Knight wrote:
> > 
> > >> On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
> > >>
> > >> >Hi,
> > >>
> > >> >I wonder why GCC don't compile that simple code:
> > >>
> > >> >static inline unsigned StackPointerValue(void)
> > >> >{
> > >> > unsigned long val;
> > >> > asm volatile (" str R13, retval");
> > >> > return val;
> > >> >}
> > >>
> > >> >When I try to compile the following error appears:
> > >> >"Internal_relocation (type: OFFSET_IMM) not fixed up"
> > >>
> > >> >What does that mean? How can I get that running?
> > >>
> > >>
> > >> 1st, 'retval' is not 'val'
> 
> yes, I know it was late ;-)
> 
> > >>
> > >> I haven't compiled this but try
> > >>
> > >> static inline unsigned StackPointerValue(void)
> > >>
> > >> unsigned long retval;
> > >> asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs 
*/ );
> > >> return retval;
> > >>
> > >>
> > >> Regards
> > >> -Bill Knight
> > >> R O SoftWare &
> > >> http://www.theARMPatch.com
> > >>
> > >>
> > >>
> > >>
> > >> ---------------------------------------------------------------
--
> -------
> > >> YAHOO! GROUPS LINKS
> > >>
> > >>     *  Visit your group "lpc2000
> > >>       <http://groups.yahoo.com/group/lpc2000>" on the web.
> > >>        
> > >>     *  To unsubscribe from this group, send an email to:
> > >>        lpc2000-unsubscribe@yahoogroups.com
> > >>       <mailto:lpc2000-unsubscribe@yahoogroups.com?
> subject=Unsubscribe>
> > >>        
> > >>     *  Your use of Yahoo! Groups is subject to the Yahoo! 
Terms 
> of
> > >>       Service <http://docs.yahoo.com/info/terms/>.
> > >>
> > >>
> > >> ---------------------------------------------------------------
--
Show quoted textHide quoted text
> -------
> > >>
> > 
> > 
> > 
> > > 
> > >Yahoo! Groups Links
> > 
> > 
> > 
> > >

Re: GNU inline assembler return value

2005-07-12 by brendanmurphy37

Xjag,

If you're looking for possible stack overrun, have you tried 
initialising the stack area to a particular value (e.g. 0xdead)? By 
looking at memory you can determine easily if it has been 
overrunning. This is a useful technique for determining how much 
stack space is actually required on a given system: you can 
overdimension at the start, look at how much is actually used and re-
dimension accordingly (leaving some safety margin in).

Our standard start-up code writes different values to each of the 
three stacks (supervisor, IRQ and FIQ stacks), as an aid to 
debugging. I'll dig this code out if it helps.

Brendan

--- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> wrote:
> Now I realized that the interrupts use another stack (IRQ stack) 
than 
> a normal routine (User stack).
> 
> Is it possible to read the User stack pointer within the ISR?
> 
> What I try to do is to capture the SP every timer1 ISR entry 
(200us) 
> and to store the maximum value to figure out if the stack collides 
> with the data area.
> 
> The stack check option of the GNU compiler is not working.
> 
> Regards
> xjag
> 
> 
> 
> 
> --- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> 
wrote:
> > Thank you, that's it!
> > For GCC you have to type:
> > 
> >   static inline unsigned StackPointerValue(void)
> >   {
> >     register unsigned long stackptr asm("sp");
> >     return stackptr;
> >   }
> > 
> > Regards
> > xjag
> > 
> > 
> > --- In lpc2000@yahoogroups.com, "Bill Knight" <BillK@t...> wrote:
> > > yes, I blew it.  Didn't check the docs and had my head on a 
> totally
> > > different project.  Saw the correct answer shortly after 
posting 
> > mine.
> > > 
> > > -Bill
> > > 
> > > 
> > > On Mon, 11 Jul 2005 19:22:53 +0200, Richard Duits wrote:
> > > 
> > > >Copying one register to another is done with the "mov" 
> instruction:
> > > 
> > > >unsigned long retval;
> > > >asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
> > > >return retval;
> > > 
> > > >An alternative in this case would be:
> > > 
> > > >unsigned long stackptr __asm("sp");
> > > >return stackptr;
> > > 
> > > >Regards,
> > > >Richard Duits
> > > 
> > > 
> > > >Bill Knight wrote:
> > > 
> > > >> On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
> > > >>
> > > >> >Hi,
> > > >>
> > > >> >I wonder why GCC don't compile that simple code:
> > > >>
> > > >> >static inline unsigned StackPointerValue(void)
> > > >> >{
> > > >> > unsigned long val;
> > > >> > asm volatile (" str R13, retval");
> > > >> > return val;
> > > >> >}
> > > >>
> > > >> >When I try to compile the following error appears:
> > > >> >"Internal_relocation (type: OFFSET_IMM) not fixed up"
> > > >>
> > > >> >What does that mean? How can I get that running?
> > > >>
> > > >>
> > > >> 1st, 'retval' is not 'val'
> > 
> > yes, I know it was late ;-)
> > 
> > > >>
> > > >> I haven't compiled this but try
> > > >>
> > > >> static inline unsigned StackPointerValue(void)
> > > >>
> > > >> unsigned long retval;
> > > >> asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs 
> */ );
> > > >> return retval;
> > > >>
> > > >>
> > > >> Regards
> > > >> -Bill Knight
> > > >> R O SoftWare &
> > > >> http://www.theARMPatch.com
> > > >>
> > > >>
> > > >>
> > > >>
> > > >> -------------------------------------------------------------
--
> --
> > -------
> > > >> YAHOO! GROUPS LINKS
> > > >>
> > > >>     *  Visit your group "lpc2000
> > > >>       <http://groups.yahoo.com/group/lpc2000>" on the web.
> > > >>        
> > > >>     *  To unsubscribe from this group, send an email to:
> > > >>        lpc2000-unsubscribe@yahoogroups.com
> > > >>       <mailto:lpc2000-unsubscribe@yahoogroups.com?
> > subject=Unsubscribe>
> > > >>        
> > > >>     *  Your use of Yahoo! Groups is subject to the Yahoo! 
> Terms 
> > of
> > > >>       Service <http://docs.yahoo.com/info/terms/>.
> > > >>
> > > >>
> > > >> -------------------------------------------------------------
--
Show quoted textHide quoted text
> --
> > -------
> > > >>
> > > 
> > > 
> > > 
> > > > 
> > > >Yahoo! Groups Links
> > > 
> > > 
> > > 
> > > >

Re: [lpc2000] Re: GNU inline assembler return value

2005-07-12 by Charles Manning

On Tuesday 12 July 2005 23:32, xjag74 wrote:
> Now I realized that the interrupts use another stack (IRQ stack) than
> a normal routine (User stack).
>
> Is it possible to read the User stack pointer within the ISR?
>
> What I try to do is to capture the SP every timer1 ISR entry (200us)
> and to store the maximum value to figure out if the stack collides
> with the data area.
>
> The stack check option of the GNU compiler is not working.
>
> Regards
> xjag

I think a better way to do this is to fill the stack area with a pattern and 
see how much of the area is changed once the program has run for a bit.

Re: GNU inline assembler return value

2005-07-13 by xjag74

All right, thank you Charles and Brendan (parallel replies),
if that's the usual way then I'll code test pattern writing before 
RAM copying in the startup.s file.

Regards
xjag

--- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> wrote:
> Now I realized that the interrupts use another stack (IRQ stack) 
than 
> a normal routine (User stack).
> 
> Is it possible to read the User stack pointer within the ISR?
> 
> What I try to do is to capture the SP every timer1 ISR entry 
(200us) 
> and to store the maximum value to figure out if the stack collides 
> with the data area.
> 
> The stack check option of the GNU compiler is not working.
> 
> Regards
> xjag
> 
> 
> 
> 
> --- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> 
wrote:
> > Thank you, that's it!
> > For GCC you have to type:
> > 
> >   static inline unsigned StackPointerValue(void)
> >   {
> >     register unsigned long stackptr asm("sp");
> >     return stackptr;
> >   }
> > 
> > Regards
> > xjag
> > 
> > 
> > --- In lpc2000@yahoogroups.com, "Bill Knight" <BillK@t...> wrote:
> > > yes, I blew it.  Didn't check the docs and had my head on a 
> totally
> > > different project.  Saw the correct answer shortly after 
posting 
> > mine.
> > > 
> > > -Bill
> > > 
> > > 
> > > On Mon, 11 Jul 2005 19:22:53 +0200, Richard Duits wrote:
> > > 
> > > >Copying one register to another is done with the "mov" 
> instruction:
> > > 
> > > >unsigned long retval;
> > > >asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
> > > >return retval;
> > > 
> > > >An alternative in this case would be:
> > > 
> > > >unsigned long stackptr __asm("sp");
> > > >return stackptr;
> > > 
> > > >Regards,
> > > >Richard Duits
> > > 
> > > 
> > > >Bill Knight wrote:
> > > 
> > > >> On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
> > > >>
> > > >> >Hi,
> > > >>
> > > >> >I wonder why GCC don't compile that simple code:
> > > >>
> > > >> >static inline unsigned StackPointerValue(void)
> > > >> >{
> > > >> > unsigned long val;
> > > >> > asm volatile (" str R13, retval");
> > > >> > return val;
> > > >> >}
> > > >>
> > > >> >When I try to compile the following error appears:
> > > >> >"Internal_relocation (type: OFFSET_IMM) not fixed up"
> > > >>
> > > >> >What does that mean? How can I get that running?
> > > >>
> > > >>
> > > >> 1st, 'retval' is not 'val'
> > 
> > yes, I know it was late ;-)
> > 
> > > >>
> > > >> I haven't compiled this but try
> > > >>
> > > >> static inline unsigned StackPointerValue(void)
> > > >>
> > > >> unsigned long retval;
> > > >> asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs 
> */ );
> > > >> return retval;
> > > >>
> > > >>
> > > >> Regards
> > > >> -Bill Knight
> > > >> R O SoftWare &
> > > >> http://www.theARMPatch.com
> > > >>
> > > >>
> > > >>
> > > >>
> > > >> -------------------------------------------------------------
--
> --
> > -------
> > > >> YAHOO! GROUPS LINKS
> > > >>
> > > >>     *  Visit your group "lpc2000
> > > >>       <http://groups.yahoo.com/group/lpc2000>" on the web.
> > > >>        
> > > >>     *  To unsubscribe from this group, send an email to:
> > > >>        lpc2000-unsubscribe@yahoogroups.com
> > > >>       <mailto:lpc2000-unsubscribe@yahoogroups.com?
> > subject=Unsubscribe>
> > > >>        
> > > >>     *  Your use of Yahoo! Groups is subject to the Yahoo! 
> Terms 
> > of
> > > >>       Service <http://docs.yahoo.com/info/terms/>.
> > > >>
> > > >>
> > > >> -------------------------------------------------------------
--
Show quoted textHide quoted text
> --
> > -------
> > > >>
> > > 
> > > 
> > > 
> > > > 
> > > >Yahoo! Groups Links
> > > 
> > > 
> > > 
> > > >

Re: GNU inline assembler return value

2005-07-13 by brendanmurphy37

Hi,

Below is a simple startup sequence that fills the stack areas and 
initialises overall state, before jumping to 'C'.

Please don't bother pointing out there are more efficient ways of 
doing this: I know there are. It gets the job done....

Note that this is designed to work with a GNU link file which 
reserves the space for the stacks as follows:

/* next section is .bss, which is uninitialised data */
.bss : 
{
 __start_bss = . ;

/* include all uninitialised writable data */

 *(.bss)

/* include ramaining uninitialised data */

 *(COMMON)

 __end_bss = . ;

/* required allignment for stacks */

. =  ALIGN(0x10) ;

/* allocate room for supervisor stack */

 __tos_svc = . ;

 . += 0x800 ;

 __stack_svc = . ;

 /* allocate room for interrupt stack */

 __tos_irq = . ;

 . += 0x200 ;

 __stack_irq = . ;

/* allocate room for fast interrupt stack */

 __tos_fiq = . ;

  . += 0x100 ;

 __stack_fiq = . ;

} > ram

Hope this of some use to people.

Regards
Brendan

/* define values to use to zap stacks */

SVC_STACK_VALUE	= 0xaaaaaaaa
IRQ_STACK_VALUE	= 0xbbbbbbbb
FIQ_STACK_VALUE	= 0xcccccccc

/*
 * Exception vector table, common to all ARM-based systems 
 *
 * See ARM Architecture Reference Manual, Programmer's Model section 
for
 * details. Table entries just jump to handlers (using full 32-bit 
addressing)
 */

_int_vectors:	
	
ldr		pc, do_reset_addr
ldr		pc, do_reset_addr
ldr		pc, do_reset_addr
ldr		pc, do_reset_addr
ldr		pc, do_reset_addr
nop
ldr		pc, do_reset_addr
ldr		pc, do_reset_addr

/* table of interrupt handler adresses */

do_reset_addr:	.long	do_reset

/*
 * System reset handler
 */

do_reset:

/*
 * Set stack pointers for all modes used (supervisor, IRQ and FIQ)
 */

msr	cpsr_c, #0xd3	 /* ensure we're in supervisor mode */
ldr	sp, =__stack_svc /* set supervisor mode stack pointer */

msr	cpsr_c, #0xd2	 /* enter IRQ mode, with interrupts disabled 
*/
ldr	sp, =__stack_irq /* set IRQ mode stack pointer */

msr	cpsr_c, #0xd1	 /* enter FIQ mode, with interrupts disabled 
*/
ldr	sp, =__stack_fiq /* set FIQ mode stack pointer */

/* now zap all stacks with distinctive pattern, to help detect 
overflow */

ldr	r0, =__tos_svc		
ldr	r1, =__stack_svc
ldr	r2, =SVC_STACK_VALUE
bl	zap_mem

ldr	r0, =__tos_irq		
ldr	r1, =__stack_irq
ldr	r2, =IRQ_STACK_VALUE
bl	zap_mem

ldr	r0, =__tos_fiq		
ldr	r1, =__stack_fiq
ldr	r2, =FIQ_STACK_VALUE
bl	zap_mem

/*
 * Enable interrupts, enter supervisor mode and branch to start
 * of 'C' code
 */

msr	cpsr_c, #0xc3		/* I=1 F=1 T=0 MODE=supervisor */
b	main

/*
 * Function to zap a block of memory with specified value
 * Note that block MUST be word alligned
 *
 * r0: start of block
 * r1: end of block
 * r2: value to load
 * lr: return address
 */

zap_mem:

	cmp		r0, r1
	strlo	r2, [r0], #4
	blo		zap_mem 
	mov		pc, lr



--- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> wrote:
> All right, thank you Charles and Brendan (parallel replies),
> if that's the usual way then I'll code test pattern writing before 
> RAM copying in the startup.s file.
> 
> Regards
> xjag
> 
> --- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> 
wrote:
> > Now I realized that the interrupts use another stack (IRQ stack) 
> than 
> > a normal routine (User stack).
> > 
> > Is it possible to read the User stack pointer within the ISR?
> > 
> > What I try to do is to capture the SP every timer1 ISR entry 
> (200us) 
> > and to store the maximum value to figure out if the stack 
collides 
Show quoted textHide quoted text
> > with the data area.
> > 
> > The stack check option of the GNU compiler is not working.
> > 
> > Regards
> > xjag
> > 
> > 
> > 
> >

Re: GNU inline assembler return value

2005-07-14 by brendanmurphy37

OK - before anyone points it out, the comment in the code below just 
before the call to "main" is wrong: interrupts are disabled (as you'd 
expect, before anything has been setup) before jumping to "main".

Just goes to prove the point about never trusting comments, only the 
code....

By the way, memory and other hardware initialisation is all done 
in 'C' in this case: the less assembler the better, I think.

Brendan

--- In lpc2000@yahoogroups.com, "brendanmurphy37" 
<brendan.murphy@i...> wrote:
> 
> Hi,
> 
> Below is a simple startup sequence that fills the stack areas and 
> initialises overall state, before jumping to 'C'.
> 
> Please don't bother pointing out there are more efficient ways of 
> doing this: I know there are. It gets the job done....
> 
> Note that this is designed to work with a GNU link file which 
> reserves the space for the stacks as follows:
> 
> /* next section is .bss, which is uninitialised data */
> .bss : 
> {
>  __start_bss = . ;
> 
> /* include all uninitialised writable data */
> 
>  *(.bss)
> 
> /* include ramaining uninitialised data */
> 
>  *(COMMON)
> 
>  __end_bss = . ;
> 
> /* required allignment for stacks */
> 
> . =  ALIGN(0x10) ;
> 
> /* allocate room for supervisor stack */
> 
>  __tos_svc = . ;
> 
>  . += 0x800 ;
> 
>  __stack_svc = . ;
> 
>  /* allocate room for interrupt stack */
> 
>  __tos_irq = . ;
> 
>  . += 0x200 ;
> 
>  __stack_irq = . ;
> 
> /* allocate room for fast interrupt stack */
> 
>  __tos_fiq = . ;
> 
>   . += 0x100 ;
> 
>  __stack_fiq = . ;
> 
> } > ram
> 
> Hope this of some use to people.
> 
> Regards
> Brendan
> 
> /* define values to use to zap stacks */
> 
> SVC_STACK_VALUE	= 0xaaaaaaaa
> IRQ_STACK_VALUE	= 0xbbbbbbbb
> FIQ_STACK_VALUE	= 0xcccccccc
> 
> /*
>  * Exception vector table, common to all ARM-based systems 
>  *
>  * See ARM Architecture Reference Manual, Programmer's Model 
section 
> for
>  * details. Table entries just jump to handlers (using full 32-bit 
> addressing)
>  */
> 
> _int_vectors:	
> 	
> ldr		pc, do_reset_addr
> ldr		pc, do_reset_addr
> ldr		pc, do_reset_addr
> ldr		pc, do_reset_addr
> ldr		pc, do_reset_addr
> nop
> ldr		pc, do_reset_addr
> ldr		pc, do_reset_addr
> 
> /* table of interrupt handler adresses */
> 
> do_reset_addr:	.long	do_reset
> 
> /*
>  * System reset handler
>  */
> 
> do_reset:
> 
> /*
>  * Set stack pointers for all modes used (supervisor, IRQ and FIQ)
>  */
> 
> msr	cpsr_c, #0xd3	 /* ensure we're in supervisor mode */
> ldr	sp, =__stack_svc /* set supervisor mode stack pointer */
> 
> msr	cpsr_c, #0xd2	 /* enter IRQ mode, with interrupts disabled 
> */
> ldr	sp, =__stack_irq /* set IRQ mode stack pointer */
> 
> msr	cpsr_c, #0xd1	 /* enter FIQ mode, with interrupts disabled 
> */
> ldr	sp, =__stack_fiq /* set FIQ mode stack pointer */
> 
> /* now zap all stacks with distinctive pattern, to help detect 
> overflow */
> 
> ldr	r0, =__tos_svc		
> ldr	r1, =__stack_svc
> ldr	r2, =SVC_STACK_VALUE
> bl	zap_mem
> 
> ldr	r0, =__tos_irq		
> ldr	r1, =__stack_irq
> ldr	r2, =IRQ_STACK_VALUE
> bl	zap_mem
> 
> ldr	r0, =__tos_fiq		
> ldr	r1, =__stack_fiq
> ldr	r2, =FIQ_STACK_VALUE
> bl	zap_mem
> 
> /*
>  * Enable interrupts, enter supervisor mode and branch to start
>  * of 'C' code
>  */
> 
> msr	cpsr_c, #0xc3		/* I=1 F=1 T=0 MODE=supervisor */
> b	main
> 
> /*
>  * Function to zap a block of memory with specified value
>  * Note that block MUST be word alligned
>  *
>  * r0: start of block
>  * r1: end of block
>  * r2: value to load
>  * lr: return address
>  */
> 
> zap_mem:
> 
> 	cmp		r0, r1
> 	strlo	r2, [r0], #4
> 	blo		zap_mem 
> 	mov		pc, lr
> 
> 
> 
> --- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> 
wrote:
> > All right, thank you Charles and Brendan (parallel replies),
> > if that's the usual way then I'll code test pattern writing 
before 
> > RAM copying in the startup.s file.
> > 
> > Regards
> > xjag
> > 
> > --- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> 
> wrote:
> > > Now I realized that the interrupts use another stack (IRQ 
stack) 
Show quoted textHide quoted text
> > than 
> > > a normal routine (User stack).
> > > 
> > > Is it possible to read the User stack pointer within the ISR?
> > > 
> > > What I try to do is to capture the SP every timer1 ISR entry 
> > (200us) 
> > > and to store the maximum value to figure out if the stack 
> collides 
> > > with the data area.
> > > 
> > > The stack check option of the GNU compiler is not working.
> > > 
> > > Regards
> > > xjag
> > > 
> > > 
> > > 
> > >

Re: [lpc2000] Re: GNU inline assembler return value

2005-07-15 by 42Bastian Schick

brendan

> By the way, memory and other hardware initialisation is all done
> in 'C' in this case: the less assembler the better, I think.

But be really careful to use C before the C startup. This might work
on this chip with this compiler but fail on another.

(Seen e.g. on a V850 where some registers hold constant like 0xff and 
0xffff
for masking.)

BTW: My opion adds one point:
If assembler then in a separate file, not inline.

-- 
42Bastian Schick

Re: GNU inline assembler return value

2005-07-15 by brendanmurphy37

Hi,

Thanks for the comment, though I'm not sure what you mean by "C
startup"

Just to clarify:

- we use GCC as compiler for LPC2000
- we don't use any standard libraries: this avoids the most common 
argument against GCC of large size overhead
- the startup is the assembler I included in previous e-mail
- the first thing the "main" does (in 'C') is to copy initialised
data 
from flash to RAM, and clear out uninitialised data: after that it's 
fully initialised
- all hardware setup is done from 'C', using MACROs to typecast the 
register addresses to volatile integer pointers
- only other assembler used is a dispatcher for IRQ interrupts 
(allowing nested interrupts), and the usual very small functions to 
enable/disable interrupts etc.

I couldn't agree more with inline assebler: much better in a separate 
assembler file.

Also, we don't use any special keywords for interrupt handlers:
they're 
just declared as regular 'C' functions: the assembler dispatcher code 
takes are of any special issues, such as additional register saves
etc.)

All this is geared to making the 'C' code as clean and "portable" as 
possible, reducing dependencies on special compiler/dev tool features 
as much as possible.

I'm not sure on you comment on the V850 as well: we use this 
archiecture a lot. By the way, I'd highly recommend GCC for
generating 
code that actually matches the source: we use IAR for V850 and have
had 
a couple of very bad experiences of the compiler generating incorrect 
code at high optimisation levels.

No doubt you've guessed I'm a bit wary of tools that come with large 
amounts of built-in or generated code to "make things easier". Great 
for playing around with a new system with, but if problems arise
(which 
they will in any significant development), they're more a hinderence 
than anything.

I guess I'm getting a bit "off-topic" here: though hopefully the
above 
will be food for thought for some, though. 

Thoughts anyone, on any of the above?

Brendan.

--- In lpc2000@yahoogroups.com, 42Bastian Schick <bastian42@m...>
wrote:
> brendan
> 
> > By the way, memory and other hardware initialisation is all done
> > in 'C' in this case: the less assembler the better, I think.
> 
> But be really careful to use C before the C startup. This might work
> on this chip with this compiler but fail on another.
> 
> (Seen e.g. on a V850 where some registers hold constant like 0xff
and 
Show quoted textHide quoted text
> 0xffff
> for masking.)
> 
> BTW: My opion adds one point:
> If assembler then in a separate file, not inline.
> 
> -- 
> 42Bastian Schick

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.