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
23    RETURN_MASK = 0x000000000000000F
24    SET_SR_MASK = 0xFFFFFFFFFFFFFFF0
25
26    .section .text
27/**************************************************************************/
28/*                                                                        */
29/*  FUNCTION                                               RELEASE        */
30/*                                                                        */
31/*    _tx_thread_interrupt_control                       RISC-V64/GNU     */
32/*                                                           6.2.1        */
33/*  AUTHOR                                                                */
34/*                                                                        */
35/*    Scott Larson, Microsoft Corporation                                 */
36/*                                                                        */
37/*  DESCRIPTION                                                           */
38/*                                                                        */
39/*    This function is responsible for changing the interrupt lockout     */
40/*    posture of the system.                                              */
41/*                                                                        */
42/*  INPUT                                                                 */
43/*                                                                        */
44/*    new_posture                           New interrupt lockout posture */
45/*                                                                        */
46/*  OUTPUT                                                                */
47/*                                                                        */
48/*    old_posture                           Old interrupt lockout posture */
49/*                                                                        */
50/*  CALLS                                                                 */
51/*                                                                        */
52/*    None                                                                */
53/*                                                                        */
54/*  CALLED BY                                                             */
55/*                                                                        */
56/*    Application Code                                                    */
57/*                                                                        */
58/*  RELEASE HISTORY                                                       */
59/*                                                                        */
60/*    DATE              NAME                      DESCRIPTION             */
61/*                                                                        */
62/*  03-08-2023      Scott Larson            Initial Version 6.2.1         */
63/*                                                                        */
64/**************************************************************************/
65/* UINT   _tx_thread_interrupt_control(UINT new_posture)
66{  */
67    .global  _tx_thread_interrupt_control
68_tx_thread_interrupt_control:
69    /* Pickup current interrupt lockout posture.  */
70
71    csrr    t0, mstatus
72    mv      t1, t0                                      // Save original mstatus for return
73
74    /* Apply the new interrupt posture.  */
75
76    li      t2, SET_SR_MASK                             // Build set SR mask
77    and     t0, t0, t2                                  // Isolate interrupt lockout bits
78    or      t0, t0, a0                                  // Put new lockout bits in
79    csrw    mstatus, t0
80    andi    a0, t1, RETURN_MASK                         // Return original mstatus.
81    ret
82/* }  */
83