1@/**************************************************************************/
2@/*                                                                        */
3@/*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4@/*                                                                        */
5@/*       This software is licensed under the Microsoft Software License   */
6@/*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7@/*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8@/*       and in the root directory of this software.                      */
9@/*                                                                        */
10@/**************************************************************************/
11@
12@
13@/**************************************************************************/
14@/**************************************************************************/
15@/**                                                                       */
16@/** ThreadX Component                                                     */
17@/**                                                                       */
18@/**   Thread                                                              */
19@/**                                                                       */
20@/**************************************************************************/
21@/**************************************************************************/
22#ifdef TX_INCLUDE_USER_DEFINE_FILE
23#include "tx_user.h"
24#endif
25
26#ifdef TX_ENABLE_FIQ_SUPPORT
27DISABLE_INTS    =       0xC0                    @ Disable IRQ/FIQ interrupts
28#else
29DISABLE_INTS    =       0x80                    @ Disable IRQ interrupts
30#endif
31MODE_MASK       =       0x1F                    @ Mode mask
32IRQ_MODE_BITS   =       0x12                    @ IRQ mode bits
33@
34@
35@/* No 16-bit Thumb mode veneer code is needed for _tx_thread_irq_nesting_end
36@   since it will never be called 16-bit mode.  */
37@
38    .arm
39    .text
40    .align 2
41@/**************************************************************************/
42@/*                                                                        */
43@/*  FUNCTION                                               RELEASE        */
44@/*                                                                        */
45@/*    _tx_thread_irq_nesting_end                           ARM9/GNU       */
46@/*                                                           6.2.1        */
47@/*  AUTHOR                                                                */
48@/*                                                                        */
49@/*    William E. Lamie, Microsoft Corporation                             */
50@/*                                                                        */
51@/*  DESCRIPTION                                                           */
52@/*                                                                        */
53@/*    This function is called by the application from IRQ mode after      */
54@/*    _tx_thread_irq_nesting_start has been called and switches the IRQ   */
55@/*    processing from system mode back to IRQ mode prior to the ISR       */
56@/*    calling _tx_thread_context_restore.  Note that this function        */
57@/*    assumes the system stack pointer is in the same position after      */
58@/*    nesting start function was called.                                  */
59@/*                                                                        */
60@/*    This function assumes that the system mode stack pointer was setup  */
61@/*    during low-level initialization (tx_initialize_low_level.s).        */
62@/*                                                                        */
63@/*    This function returns with IRQ interrupts disabled.                 */
64@/*                                                                        */
65@/*  INPUT                                                                 */
66@/*                                                                        */
67@/*    None                                                                */
68@/*                                                                        */
69@/*  OUTPUT                                                                */
70@/*                                                                        */
71@/*    None                                                                */
72@/*                                                                        */
73@/*  CALLS                                                                 */
74@/*                                                                        */
75@/*    None                                                                */
76@/*                                                                        */
77@/*  CALLED BY                                                             */
78@/*                                                                        */
79@/*    ISRs                                                                */
80@/*                                                                        */
81@/*  RELEASE HISTORY                                                       */
82@/*                                                                        */
83@/*    DATE              NAME                      DESCRIPTION             */
84@/*                                                                        */
85@/*  09-30-2020     William E. Lamie         Initial Version 6.1           */
86@/*  03-08-2023     Cindy Deng               Modified comment(s), added    */
87@/*                                            #include tx_user.h,         */
88@/*                                            resulting in version 6.2.1  */
89@/*                                                                        */
90@/**************************************************************************/
91@VOID   _tx_thread_irq_nesting_end(VOID)
92@{
93    .global  _tx_thread_irq_nesting_end
94    .type    _tx_thread_irq_nesting_end,function
95_tx_thread_irq_nesting_end:
96    MOV     r3,lr                               @ Save ISR return address
97    MRS     r0, CPSR                            @ Pickup the CPSR
98    ORR     r0, r0, #DISABLE_INTS               @ Build disable interrupt value
99    MSR     CPSR_cxsf, r0                       @ Disable interrupts
100    LDMIA   sp!, {r1, lr}                       @ Pickup saved lr (and r1 throw-away for
101                                                @   8-byte alignment logic)
102    BIC     r0, r0, #MODE_MASK                  @ Clear mode bits
103    ORR     r0, r0, #IRQ_MODE_BITS              @ Build IRQ mode CPSR
104    MSR     CPSR_cxsf, r0                       @ Reenter IRQ mode
105    MOV     pc, r3                              @ Return to caller
106@}
107
108