summaryrefslogtreecommitdiff
path: root/ports/rxv2/ccrx/src/tx_thread_stack_build.src
blob: 38da71c9231961d0d1288468598bdee3652fc461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
;/**************************************************************************/
;/*                                                                        */
;/*       Copyright (c) Microsoft Corporation. All rights reserved.        */
;/*                                                                        */
;/*       This software is licensed under the Microsoft Software License   */
;/*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
;/*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
;/*       and in the root directory of this software.                      */
;/*                                                                        */
;/**************************************************************************/
;
;
;/**************************************************************************/
;/**************************************************************************/
;/**                                                                       */ 
;/** ThreadX Component                                                     */ 
;/**                                                                       */
;/**   Thread                                                              */
;/**                                                                       */
;/**************************************************************************/
;/**************************************************************************/
;
;
;#define TX_SOURCE_CODE
;
;
;/* Include necessary system files.  */
;
;#include "tx_api.h"
;#include "tx_thread.h"
;
;
    .SECTION    P,CODE
;/**************************************************************************/ 
;/*                                                                        */ 
;/*  FUNCTION                                               RELEASE        */ 
;/*                                                                        */ 
;/*    _tx_thread_stack_build                               RX/CCRX        */
;/*                                                           6.1.3        */
;/*  AUTHOR                                                                */ 
;/*                                                                        */ 
;/*    William E. Lamie, Microsoft Corporation                             */
;/*                                                                        */ 
;/*  DESCRIPTION                                                           */ 
;/*                                                                        */ 
;/*    This function builds a stack frame on the supplied thread's stack.  */
;/*    The stack frame results in a fake interrupt return to the supplied  */
;/*    function pointer.                                                   */ 
;/*                                                                        */ 
;/*  INPUT                                                                 */ 
;/*                                                                        */ 
;/*    thread_ptr                            Pointer to thread control blk */
;/*    function_ptr                          Pointer to return function    */
;/*                                                                        */ 
;/*  OUTPUT                                                                */ 
;/*                                                                        */ 
;/*    None                                                                */
;/*                                                                        */ 
;/*  CALLS                                                                 */ 
;/*                                                                        */ 
;/*    None                                                                */
;/*                                                                        */ 
;/*  CALLED BY                                                             */ 
;/*                                                                        */ 
;/*    _tx_thread_create                     Create thread service         */
;/*                                                                        */ 
;/*  RELEASE HISTORY                                                       */ 
;/*                                                                        */ 
;/*    DATE              NAME                      DESCRIPTION             */ 
;/*                                                                        */ 
;/*  12-31-2020     William E. Lamie         Initial Version 6.1.3         */
;/*                                                                        */ 
;/**************************************************************************/ 
;VOID   _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID))
;{
    .GLB __tx_thread_stack_build
__tx_thread_stack_build:
;
;       
;    /* Build an interrupt frame.  The form of the fake interrupt stack
;       on the Renesas RX should look like the following after it is built:
;       
;  Stack Top:           1       Interrupt stack frame type
;                       ACC0
;                       ACC1
;                       R6
;                       R7
;                       R8
;                       R9
;                       R10
;                       R11
;                       R12
;                       R13
;                       FPSW
;                       R14
;                       R15
;                       R3
;                       R4
;                       R5
;                       R1
;                       R2
;                       PC
;                       PSW

;
;    Stack Bottom: (higher memory address)  */
;
    MOV.L   16[R1],R3               ; Pickup end of stack area
    BCLR    #0, R3                  ; mask for 4-byte alignment
    BCLR    #1, R3
;
;    /* Build the stack frame.  */
;
    MOV.L #30000h, R4
    MOV.L R4, [-R3]                         ; initial PSW (SVC mode, U flag set)
    MOV.L R2, [-R3]                         ; initial PC
    MOV.L #0, R4
    MOV.L R4,[-R3]                          ; initial R2 ...
    MOV.L R4,[-R3]                          ; initial R1 ...    
    MOV.L R4,[-R3]                          ; initial R5 ...
    MOV.L R4,[-R3]                          ; initial R4 ...
    MOV.L R4,[-R3]                          ; initial R3 ...    
    MOV.L R4,[-R3]                          ; initial R15 ...
    MOV.L R4,[-R3]                          ; initial R14 ...
    MVFC  FPSW, r4
    MOV.L R4, [-R3]                         ; initial FPSW
    MOV.L #0, R4
    MOV.L R4,[-R3]                          ; initial R13 ...   
    MOV.L R4,[-R3]                          ; initial R12 ...
    MOV.L R4,[-R3]                          ; initial R11 ...
    MOV.L R4,[-R3]                          ; initial R10 ...   
    MOV.L R4,[-R3]                          ; initial R9 ...
    MOV.L R4,[-R3]                          ; initial R8 ...
    MOV.L R4,[-R3]                          ; initial R7 ...    
    MOV.L R4,[-R3]                          ; initial R6 ...

    MOV.L R4,[-R3]                          ; Accumulator 1
    MOV.L R4,[-R3]
    MOV.L R4,[-R3]

    MOV.L R4,[-R3]                          ; Accumulator 0
    MOV.L R4,[-R3]
    MOV.L R4,[-R3]

    MOV.L #1, R4
    MOV.L R4,[-R3]                           ; indicate interrupt stack frame
;    /* Setup stack pointer.  */
;    thread_ptr -> tx_thread_stack_ptr =  R1;   
    MOV.L R3, 8[R1]
                                            ; store initial SP in thread control block
    RTS
                                 
;}
    .END