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    .text
24;/**************************************************************************/
25;/*                                                                        */
26;/*  FUNCTION                                               RELEASE        */
27;/*                                                                        */
28;/*    _tx_thread_stack_build                               RXv1/GNURX     */
29;/*                                                           6.1.11       */
30;/*  AUTHOR                                                                */
31;/*                                                                        */
32;/*    William E. Lamie, Microsoft Corporation                             */
33;/*                                                                        */
34;/*  DESCRIPTION                                                           */
35;/*                                                                        */
36;/*    This function builds a stack frame on the supplied thread's stack.  */
37;/*    The stack frame results in a fake interrupt return to the supplied  */
38;/*    function pointer.                                                   */
39;/*                                                                        */
40;/*  INPUT                                                                 */
41;/*                                                                        */
42;/*    thread_ptr                            Pointer to thread control blk */
43;/*    function_ptr                          Pointer to return function    */
44;/*                                                                        */
45;/*  OUTPUT                                                                */
46;/*                                                                        */
47;/*    None                                                                */
48;/*                                                                        */
49;/*  CALLS                                                                 */
50;/*                                                                        */
51;/*    None                                                                */
52;/*                                                                        */
53;/*  CALLED BY                                                             */
54;/*                                                                        */
55;/*    _tx_thread_create                     Create thread service         */
56;/*                                                                        */
57;/*  RELEASE HISTORY                                                       */
58;/*                                                                        */
59;/*    DATE              NAME                      DESCRIPTION             */
60;/*                                                                        */
61;/*  08-02-2021     William E. Lamie         Initial Version 6.1.8         */
62;/*  10-15-2021     William E. Lamie         Modified comment(s), and      */
63;/*                                            removed unnecessary stack   */
64;/*                                            type placement,             */
65;/*                                            resulting in version 6.1.9  */
66;/*  01-31-2022     William E. Lamie         Modified comment(s),          */
67;/*                                            resulting in version 6.1.10 */
68;/*  04-25-2022     William E. Lamie         Modified comment(s),          */
69;/*                                            resulting in version 6.1.11 */
70;/*                                                                        */
71;/**************************************************************************/
72;VOID   _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID))
73;{
74    .global __tx_thread_stack_build
75__tx_thread_stack_build:
76;
77;
78;    /* Build an interrupt frame.  The form of the fake interrupt stack
79;       on the Renesas RX should look like the following after it is built:
80;
81;  Stack Top:           ACC0
82;                       R6
83;                       R7
84;                       R8
85;                       R9
86;                       R10
87;                       R11
88;                       R12
89;                       R13
90;                       FPSW
91;                       R14
92;                       R15
93;                       R3
94;                       R4
95;                       R5
96;                       R1
97;                       R2
98;                       PC
99;                       PSW
100
101;
102;    Stack Bottom: (higher memory address)  */
103;
104    MOV.L   16[R1],R3                            ; Pickup end of stack area
105    BCLR    #0, R3                               ; Mask for 4-byte alignment
106    BCLR    #1, R3
107;
108;    /* Build the stack frame.  */
109;
110    MOV.L #30000h, R4
111    MOV.L R4, [-R3]                              ; Initial PSW (SVC mode, U flag set)
112    MOV.L R2, [-R3]                              ; Initial PC
113    MOV.L #0, R4
114    MOV.L R4,[-R3]                               ; Initial R2 ...
115    MOV.L R4,[-R3]                               ; Initial R1 ...
116    MOV.L R4,[-R3]                               ; Initial R5 ...
117    MOV.L R4,[-R3]                               ; Initial R4 ...
118    MOV.L R4,[-R3]                               ; Initial R3 ...
119    MOV.L R4,[-R3]                               ; Initial R15 ...
120    MOV.L R4,[-R3]                               ; Initial R14 ...
121    MOV.L R4,[-R3]                               ; Initial R13 ...
122    MOV.L R4,[-R3]                               ; Initial R12 ...
123    MOV.L R4,[-R3]                               ; Initial R11 ...
124    MOV.L R4,[-R3]                               ; Initial R10 ...
125    MOV.L R4,[-R3]                               ; Initial R9 ...
126    MOV.L R4,[-R3]                               ; Initial R8 ...
127    MOV.L R4,[-R3]                               ; Initial R7 ...
128    MOV.L R4,[-R3]                               ; Initial R6 ...
129
130    MOV.L R4,[-R3]                               ; Accumulator 0
131    MOV.L R4,[-R3]
132
133;    /* Setup stack pointer.  */
134;    thread_ptr -> tx_thread_stack_ptr =  R1;
135    MOV.L R3, 8[R1]
136                                                 ; Store initial SP in thread control block
137    RTS
138
139;}
140    .end
141