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