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