Modes, stack setup for "no-OS" ARM app

Toralf Lund
Mon Apr 19 22:48:00 GMT 2004

Michael K. Elwood wrote:

> At 09:56 AM 4/16/2004 +0200, Toralf Lund wrote:
>> I've been wondering about how I should handle processor modes and set 
>> up stack pointers etc. for my newlib-based ARM application running on 
>> a "bare" system (no OS, no debug monitor.) Unlike the default crt0, 
>> mine will definitely have to set up stack pointers for more than one 
>> mode, since I use interrupts actively. Also, I'm not quite sure what 
>> mode the application itself ought to run under. I need to access 
>> "privileged" registers etc. during the init phase at least, so some 
>> bits have to run in Supervisor or System, but do I want to do 
>> *everything* in one of those modes?
>> Some issues related to this (in no particular order):
>>   1. Once User mode is entered, there is no easy way back, as far as I
>>      know, so I can't simply switch to that mode e.g. to set up the
>>      stack, if I want SVC or System later.
> There is a reasonably easy way back. Use the SWI instruction.

Wouldn't that require the setup of the appropriate exception vector? Not 
necessarily straight forward in this context...

>>   2. System is ARM version 4 and above, so perhaps I shouldn't use that
>>      in my crt0, which I intend to be very general.
>>   3. As far as I can tell, there is no way to access the user mode
>>      stack pointer e.g. from supervisor mode, at least when using gas.
> Use the STM instruction with ^ after the register list (see section 
> 4.1.43 of the ARM Architecture Reference Manual, 2nd ed.). If you 
> don't have this book yet, you really need to get it. HTH.

Ah, yes. Never noticed that variant... I think perhaps the other 
sections concerned with processor modes and register sets ought to 
mention it, though...


> With best regards,

More information about the Newlib mailing list