1/***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12/**************************************************************************/
13/**************************************************************************/
14/**                                                                       */
15/** ThreadX Component                                                     */
16/**                                                                       */
17/**   Thread                                                              */
18/**                                                                       */
19/**************************************************************************/
20/**************************************************************************/
21#ifdef TX_INCLUDE_USER_DEFINE_FILE
22#include "tx_user.h"
23#endif
24
25    .syntax unified
26#if defined(THUMB_MODE)
27    .thumb
28#else
29    .arm
30#endif
31
32INT_MASK        =   0x0C0
33IRQ_MASK        =   0x080
34#ifdef TX_ENABLE_FIQ_SUPPORT
35FIQ_MASK        =   0x040
36#endif
37
38    .text
39    .align 2
40/**************************************************************************/
41/*                                                                        */
42/*  FUNCTION                                               RELEASE        */
43/*                                                                        */
44/*    _tx_thread_interrupt_control                         ARMv7-A        */
45/*                                                           6.4.0        */
46/*  AUTHOR                                                                */
47/*                                                                        */
48/*    William E. Lamie, Microsoft Corporation                             */
49/*                                                                        */
50/*  DESCRIPTION                                                           */
51/*                                                                        */
52/*    This function is responsible for changing the interrupt lockout     */
53/*    posture of the system.                                              */
54/*                                                                        */
55/*  INPUT                                                                 */
56/*                                                                        */
57/*    new_posture                           New interrupt lockout posture */
58/*                                                                        */
59/*  OUTPUT                                                                */
60/*                                                                        */
61/*    old_posture                           Old interrupt lockout posture */
62/*                                                                        */
63/*  CALLS                                                                 */
64/*                                                                        */
65/*    None                                                                */
66/*                                                                        */
67/*  CALLED BY                                                             */
68/*                                                                        */
69/*    Application Code                                                    */
70/*                                                                        */
71/*  RELEASE HISTORY                                                       */
72/*                                                                        */
73/*    DATE              NAME                      DESCRIPTION             */
74/*                                                                        */
75/*  09-30-2020     William E. Lamie         Initial Version 6.1           */
76/*  04-25-2022     Zhen Kong                Updated comments,             */
77/*                                            resulting in version 6.1.11 */
78/*  10-31-2023     Tiejun Zhou              Modified comment(s), added    */
79/*                                            #include tx_user.h,         */
80/*                                            resulting in version 6.3.0  */
81/*  12-31-2023     Yajun Xia                Modified comment(s),          */
82/*                                            Added thumb mode support,   */
83/*                                            resulting in version 6.4.0  */
84/*                                                                        */
85/**************************************************************************/
86#if defined(THUMB_MODE)
87    .thumb_func
88#endif
89    .global _tx_thread_interrupt_control
90    .type   _tx_thread_interrupt_control,function
91_tx_thread_interrupt_control:
92    MRS     r1, CPSR                            // Pickup current CPSR
93
94#ifdef TX_ENABLE_FIQ_SUPPORT
95    CPSID   if                                  // Disable IRQ and FIQ
96#else
97    CPSID   i                                   // Disable IRQ
98#endif
99
100    TST     r0, #IRQ_MASK
101    BNE     no_irq
102    CPSIE   i
103no_irq:
104#ifdef TX_ENABLE_FIQ_SUPPORT
105    TST     r0, #FIQ_MASK
106    BNE     no_fiq
107    CPSIE   f
108no_fiq:
109#endif
110
111    AND     r0, r1, #INT_MASK
112    BX      lr
113