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;
22
23    section .text:CODE:ROOT
24
25;/**************************************************************************/
26;/*                                                                        */
27;/*  FUNCTION                                               RELEASE        */
28;/*                                                                        */
29;/*    _tx_thread_stack_build                               RXv2/IAR       */
30;/*                                                           6.1.11       */
31;/*  AUTHOR                                                                */
32;/*                                                                        */
33;/*    William E. Lamie, Microsoft Corporation                             */
34;/*                                                                        */
35;/*  DESCRIPTION                                                           */
36;/*                                                                        */
37;/*    This function builds a stack frame on the supplied thread's stack.  */
38;/*    The stack frame results in a fake interrupt return to the supplied  */
39;/*    function pointer.                                                   */
40;/*                                                                        */
41;/*  INPUT                                                                 */
42;/*                                                                        */
43;/*    thread_ptr                            Pointer to thread control blk */
44;/*    function_ptr                          Pointer to return function    */
45;/*                                                                        */
46;/*  OUTPUT                                                                */
47;/*                                                                        */
48;/*    None                                                                */
49;/*                                                                        */
50;/*  CALLS                                                                 */
51;/*                                                                        */
52;/*    None                                                                */
53;/*                                                                        */
54;/*  CALLED BY                                                             */
55;/*                                                                        */
56;/*    _tx_thread_create                     Create thread service         */
57;/*                                                                        */
58;/*  RELEASE HISTORY                                                       */
59;/*                                                                        */
60;/*    DATE              NAME                      DESCRIPTION             */
61;/*                                                                        */
62;/*  12-30-2020     William E. Lamie         Initial Version 6.1.3         */
63;/*  10-15-2021     William E. Lamie         Modified comment(s), and      */
64;/*                                            removed unnecessary stack   */
65;/*                                            type placement,             */
66;/*                                            resulting in version 6.1.9  */
67;/*  01-31-2022     William E. Lamie         Modified comment(s),          */
68;/*                                            resulting in version 6.1.10 */
69;/*  04-25-2022     William E. Lamie         Modified comment(s),          */
70;/*                                            resulting in version 6.1.11 */
71;/*                                                                        */
72;/**************************************************************************/
73    public __tx_thread_stack_build
74__tx_thread_stack_build:
75;
76;
77;    /* Build an interrupt frame.  The form of the fake interrupt stack
78;       on the Renesas RX should look like the following after it is built:
79;
80;  Stack Top:           ACC0
81;                       ACC1
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    MVFC  FPSW, r4
122    MOV.L R4, [-R3]                              ; Initial FPSW
123    MOV.L #0, R4
124    MOV.L R4,[-R3]                               ; Initial R13 ...
125    MOV.L R4,[-R3]                               ; Initial R12 ...
126    MOV.L R4,[-R3]                               ; Initial R11 ...
127    MOV.L R4,[-R3]                               ; Initial R10 ...
128    MOV.L R4,[-R3]                               ; Initial R9 ...
129    MOV.L R4,[-R3]                               ; Initial R8 ...
130    MOV.L R4,[-R3]                               ; Initial R7 ...
131    MOV.L R4,[-R3]                               ; Initial R6 ...
132
133    MOV.L R4,[-R3]                               ; Accumulator 1
134    MOV.L R4,[-R3]
135    MOV.L R4,[-R3]
136
137    MOV.L R4,[-R3]                               ; Accumulator 0
138    MOV.L R4,[-R3]
139    MOV.L R4,[-R3]
140
141;    /* Setup stack pointer.  */
142;    thread_ptr -> tx_thread_stack_ptr =  R1;
143    MOV.L R3, 8[R1]
144                                                 ; Store initial SP in thread control block
145    RTS
146
147;}
148
149    END
150