[En-Nut-Discussion] arm port (RFC: Changing ARM mode)

Harald Kipp harald.kipp at egnite.de
Tue Jan 13 19:14:51 CET 2009


Rocendo Bracamontes del toro wrote:

> If we want to switch to a different execution mode, this is my initial
> proposal:
> 
> .- Create a machine-dependent macro, this macro could be added just after
> the calling to a kernel function from a user thread. for example:
> 
>   void NutSleep (uint32_t ms)
>    {
>        ENTRY_KERNEL_MODE(); // change mode to supervisor when applicable
> 
>       ..... code execute at kernel level here ....
> 
>        EXIT_KERNEL_MODE(); exit supervisor mode, enter user mode when
> applicable
>   }
> 

I understand. And it sounds reasonable to me. On the other hand, it may
require several code changes and more extensive testing. For example, I
try to avoid 'goto' jumps and limit the number of 'return' statements to
one, located at the end of the function. There are many places, where I
broke this rule.

Btw. you are talking about supervisor, not system mode. Did I get this
right? Just asking because I recently had to find out, that I mixed them
up too often.



> Also for ISR's, would be great if we enhance the IRQ_ENTRY and IRQ_EXIT to
> swicth to "user mode", so all the ISR code will be execute under "user
> mode",  this implies to initilize the user stack on the cstartup.

Sounds reasonable to me as well. But again my question, why user and not
system mode?

Apart from the fact, that I follow your idea, I doubt if we should
introduce this in the next stable release. Currently I'd still prefer to
leave the runtime initialization in system mode, which, btw. will
automatically set the user stack. For example, let's look to
arch/arm/init/crtat91sam7sex_rom.S in CVS HEAD. Simply adding

msr     CPSR_c, #ARM_MODE_SYS | 0xC0

to section .init3 would do the trick. Actually that was the purpose of
this section and it is done for some older targets. The user stack
pointer will be set automatically at the end of section .init4.

On the other hand the number of places for the ENTER/EXIT macro may be
more limited than I assume.

More opinions?

Harald





More information about the En-Nut-Discussion mailing list