Yahoo Groups archive

Lpc2000

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

Message

RE: [lpc2000] Re: ARM_UCOS port and the use of stmfd/ldmfd

2005-09-21 by David Hawkins

> On Wednesday 21 September 2005 12:33, David Hawkins wrote:
> > > I guess you could do that, but that would add extra overhead to the
> > > SWI calls.
> > >
> > > AFAIK, the problem only applies to a few encodings of ldm/stm that you
> > > don't use in normal use anyway. Therefore I don't see much need to
> > > jump through hoops to accomodate it.
> >
> > Thats what I am trying to determine.
>
> >From a read of the ARMARM it would appear that the Bad Form only
> applies when
> you use stm(2)/ldm(2) in user/system mode because these provide a special
> "worm hole" to access the user/system registers - something that
> is pointless
> when you are already in sustem/user mode.
>
> >From what I can tell, this form would only be reasonably used
> when you are
> trying to access system/user registers when in a different
> protected mode.
> Example of this might be:
> 1) In an OS environment where you are using SWI as a trap to the OS.
> 2) Exception handler for data aborts/page swapping etc.
> 3) Perhaps as part of a scheduler in an RTOS.
>
> > > For calling APCS compilant (ie. C generated isrs) you do not have to
> > > save all registers, only r0..r3. The called function will save any
> > > other registers it needs itself.
> >
> > Right, but if you are running an RTOS, then the C generated ISR
> > code is insufficient, since a context switch may occur as a
> > consequence of the interrupt. So in uCOS-II you need to save
> > all processor context, service the interrupts, and then restore
> > to the highest priority task. Since you basically have to store
> > all registers, it would seem that the ldm/stm instructions would
> > be the desired ones to use.
>
> Unwrapped C generated code is definitely insufficient for many
> purposes, but perhaps you miss my point.
>
> The IRQ wrapper that calls a C function does not need to save all the
> registers. According to the APCS, the caller should preserve
> r0-r3,r12 (and
> r14) and the callee any others. Thus, the wrapper only needs to preserve
> r0-r3,r12,r14. The C function will save/restore any others itself.
>
> Of course if you trash other registers in the IRQ wrapper then
> you need to save those too.
>
> Of course, too, any context needed by the scheduler will need to save all
> registers.

Yep, understood. Thanks for the valuable discussion.

Cheers
Dave

Attachments

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.