[Fwd: Modes, stack setup for "no-OS" ARM app]

Mark Salter msalter@redhat.com
Tue Apr 20 14:50:00 GMT 2004


>>>>> Toralf Lund writes:

> Actually, the libgloss redboot-crt0.S doesn't set up more than one sp, 
> either - but perhaps there is additional setup within RedBoot itself?

redboot-crt0.s assumes that the program is being run on top of RedBoot
where RedBoot handles low-level exceptions, etc.

RedBoot operates almost entirely in supervisor mode on the ARM. Minimal
mode-specific stacks are used by exception handlers to save a small
amount of state before switching to supervisor mode. For instance:

 undefined_instruction:
        ldr     sp,.__undef_exception_stack     // get good stack
        stmfd   sp!,{r0-r5}                     // save some supervisor regs
        mrs     r1,spsr
        tst     r1,#CPSR_THUMB_ENABLE
        subeq   r0,lr,#4                // PC at time of interrupt (ARM)
        subne   r0,lr,#2                // PC at time of interrupt (thumb)
        mov     r2,#CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION
        mov     r3,sp
        b       call_exception_handler

And the first insns in call_exception handler are:

        mrs     r4,cpsr                 // switch to Supervisor Mode
        bic     r4,r4,#CPSR_MODE_BITS
        orr     r4,r4,#CPSR_SUPERVISOR_MODE
        msr     cpsr,r4


The __undef_exception stack is simply 32 words of bss:

        .section ".bss"
        .rept   32
        .long   0
        .endr
  __undef_exception_stack:


--Mark




More information about the Newlib mailing list