Changeset e7d3967 in rtems


Ignore:
Timestamp:
Mar 6, 2014, 2:16:01 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
909f61b
Parents:
6b115b3
git-author:
Sebastian Huber <sebastian.huber@…> (03/06/14 14:16:01)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/10/14 07:03:46)
Message:

arm: Fix stack alignment in interrupt handler

According to AAPCS, section 5.2.1.2, "Stack constraints at a public
interface" the stack must be 8 byte aligned. This was not the case
during interrupt processing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/cpu/arm/arm_exc_interrupt.S

    r6b115b3 re7d3967  
    88
    99/*
    10  * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2009-2014 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    4545
    4646#define SELF_CPU_CONTROL r7
     47#define SP_OF_INTERRUPTED_CONTEXT r9
    4748
    4849#define CONTEXT_LIST {r0, r1, r2, r3, EXCHANGE_LR, EXCHANGE_SPSR, SELF_CPU_CONTROL, r12}
    4950#define CONTEXT_SIZE 32
    50 
    51 #ifdef ARM_MULTILIB_VFP_D32
    52   #define VFP_CONTEXT_WITH_ALIGNMENT_SPACE (24 * 8 + 4 + 4)
    53 #endif
    5451
    5552.macro GET_SELF_CPU_CONTROL REG, TMP
     
    8279
    8380        /*
    84          * Save context.  We save the LR separately because it has to be
    85          * restored in SVC mode.  The other registers can be restored in INT
    86          * mode.
     81         * Save context.  We save the link register separately because it has
     82         * to be restored in SVC mode.  The other registers can be restored in
     83         * INT mode.  Ensure that stack remains 8 byte aligned.  Use register
     84         * necessary for the stack alignment for the stack pointer of the
     85         * interrupted context.
    8786         */
    8887        stmdb   sp!, CONTEXT_LIST
    89         stmdb   sp!, {lr}
     88        stmdb   sp!, {SP_OF_INTERRUPTED_CONTEXT, lr}
    9089
    9190#ifdef ARM_MULTILIB_VFP_D32
    9291        /* Save VFP context */
    93         sub     sp, #VFP_CONTEXT_WITH_ALIGNMENT_SPACE
    94         add     r1, sp, #4
    9592        vmrs    r0, FPSCR
    96         bic     r1, r1, #7
    97         vstmia  r1!, {d0-d7}
    98         vstmia  r1!, {d16-d31}
    99         str     r0, [r1]
     93        vstmdb  sp!, {d0-d7}
     94        vstmdb  sp!, {d16-d31}
     95        stmdb   sp!, {r0, r1}
    10096#endif
    10197
     
    113109
    114110        /* Switch stack if necessary and save original stack pointer */
    115         mov     r3, sp
     111        mov     SP_OF_INTERRUPTED_CONTEXT, sp
    116112        cmp     r2, #0
    117113        moveq   sp, r1
    118         stmdb   sp!, {r3}
    119114
    120115        /* Switch to THUMB instructions if necessary */
    121         SWITCH_FROM_ARM_TO_THUMB        r1
     116        SWITCH_FROM_ARM_TO_THUMB        r1
    122117
    123118        /* Increment interrupt nest and thread dispatch disable level */
     
    140135
    141136        /* Restore stack pointer */
    142         SWITCH_FROM_THUMB_TO_ARM
    143         ldr     sp, [sp]
    144         SWITCH_FROM_ARM_TO_THUMB        r0
     137        mov     sp, SP_OF_INTERRUPTED_CONTEXT
    145138
    146139        /* Check thread dispatch disable level */
     
    168161#ifdef ARM_MULTILIB_VFP_D32
    169162        /* Restore VFP context */
    170         add     r1, sp, #4
    171         bic     r1, r1, #7
    172         vldmia  r1!, {d0-d7}
    173         vldmia  r1!, {d16-d31}
    174         ldr     r0, [r1]
    175         add     sp, #VFP_CONTEXT_WITH_ALIGNMENT_SPACE
     163        ldmia   sp!, {r0, r1}
     164        vldmia  sp!, {d16-d31}
     165        vldmia  sp!, {d0-d7}
    176166        vmsr    FPSCR, r0
    177167#endif
    178168
    179         /* Restore link register */
    180         ldmia   sp!, {lr}
     169        /* Restore SP_OF_INTERRUPTED_CONTEXT register and link register */
     170        ldmia   sp!, {SP_OF_INTERRUPTED_CONTEXT, lr}
    181171
    182172        /*
Note: See TracChangeset for help on using the changeset viewer.