]> begriffs open source - freertos/blob - portable/IAR/RXv2/port_asm.s
Add SMP in the License Header (#402)
[freertos] / portable / IAR / RXv2 / port_asm.s
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #include "PriorityDefinitions.h"
29
30         PUBLIC _prvStartFirstTask
31         PUBLIC ___interrupt_27
32
33         EXTERN _pxCurrentTCB
34         EXTERN _vTaskSwitchContext
35
36         RSEG CODE:CODE(4)
37
38 _prvStartFirstTask:
39
40                 /* When starting the scheduler there is nothing that needs moving to the
41                 interrupt stack because the function is not called from an interrupt.
42                 Just ensure the current stack is the user stack. */
43                 SETPSW          U
44
45                 /* Obtain the location of the stack associated with which ever task
46                 pxCurrentTCB is currently pointing to. */
47                 MOV.L           #_pxCurrentTCB, R15
48                 MOV.L           [R15], R15
49                 MOV.L           [R15], R0
50
51                 /* Restore the registers from the stack of the task pointed to by
52                 pxCurrentTCB. */
53                 POP                     R15
54
55                 /* Accumulator low 32 bits. */
56                 MVTACLO         R15, A0
57                 POP                     R15
58
59                 /* Accumulator high 32 bits. */
60                 MVTACHI         R15, A0
61                 POP                     R15
62
63                 /* Accumulator guard. */
64                 MVTACGU         R15, A0
65                 POP                     R15
66
67                 /* Accumulator low 32 bits. */
68                 MVTACLO         R15, A1
69                 POP                     R15
70
71                 /* Accumulator high 32 bits. */
72                 MVTACHI         R15, A1
73                 POP                     R15
74
75                 /* Accumulator guard. */
76                 MVTACGU         R15, A1
77                 POP                     R15
78
79                 /* Floating point status word. */
80                 MVTC            R15, FPSW
81
82                 /* R1 to R15 - R0 is not included as it is the SP. */
83                 POPM            R1-R15
84
85                 /* This pops the remaining registers. */
86                 RTE
87                 NOP
88                 NOP
89
90 /*-----------------------------------------------------------*/
91
92 /* The software interrupt - overwrite the default 'weak' definition. */
93 ___interrupt_27:
94
95                 /* Re-enable interrupts. */
96                 SETPSW          I
97
98                 /* Move the data that was automatically pushed onto the interrupt stack when
99                 the interrupt occurred from the interrupt stack to the user stack.
100
101                 R15 is saved before it is clobbered. */
102                 PUSH.L          R15
103
104                 /* Read the user stack pointer. */
105                 MVFC            USP, R15
106
107                 /* Move the address down to the data being moved. */
108                 SUB             #12, R15
109                 MVTC            R15, USP
110
111                 /* Copy the data across, R15, then PC, then PSW. */
112                 MOV.L           [ R0 ], [ R15 ]
113                 MOV.L           4[ R0 ], 4[ R15 ]
114                 MOV.L           8[ R0 ], 8[ R15 ]
115
116                 /* Move the interrupt stack pointer to its new correct position. */
117                 ADD             #12, R0
118
119                 /* All the rest of the registers are saved directly to the user stack. */
120                 SETPSW          U
121
122                 /* Save the rest of the general registers (R15 has been saved already). */
123                 PUSHM           R1-R14
124
125                 /* Save the FPSW and accumulator. */
126                 MVFC            FPSW, R15
127                 PUSH.L          R15
128                 MVFACGU         #0, A1, R15
129                 PUSH.L          R15
130                 MVFACHI         #0, A1, R15
131                 PUSH.L          R15
132                 /* Low order word. */
133                 MVFACLO         #0, A1, R15
134                 PUSH.L          R15
135                 MVFACGU         #0, A0, R15
136                 PUSH.L          R15
137                 MVFACHI         #0, A0, R15
138                 PUSH.L          R15
139                 /* Low order word. */
140                 MVFACLO         #0, A0, R15
141                 PUSH.L          R15
142
143                 /* Save the stack pointer to the TCB. */
144                 MOV.L           #_pxCurrentTCB, R15
145                 MOV.L           [ R15 ], R15
146                 MOV.L           R0, [ R15 ]
147
148                 /* Ensure the interrupt mask is set to the syscall priority while the kernel
149                 structures are being accessed. */
150                 MVTIPL          #configMAX_SYSCALL_INTERRUPT_PRIORITY
151
152                 /* Select the next task to run. */
153                 BSR.A           _vTaskSwitchContext
154
155                 /* Reset the interrupt mask as no more data structure access is required. */
156                 MVTIPL          #configKERNEL_INTERRUPT_PRIORITY
157
158                 /* Load the stack pointer of the task that is now selected as the Running
159                 state task from its TCB. */
160                 MOV.L           #_pxCurrentTCB,R15
161                 MOV.L           [ R15 ], R15
162                 MOV.L           [ R15 ], R0
163
164                 /* Restore the context of the new task.  The PSW (Program Status Word) and
165                 PC will be popped by the RTE instruction. */
166                 POP             R15
167
168                 /* Accumulator low 32 bits. */
169                 MVTACLO R15, A0
170                 POP             R15
171
172                 /* Accumulator high 32 bits. */
173                 MVTACHI R15, A0
174                 POP             R15
175
176                 /* Accumulator guard. */
177                 MVTACGU R15, A0
178                 POP             R15
179
180                 /* Accumulator low 32 bits. */
181                 MVTACLO R15, A1
182                 POP             R15
183
184                 /* Accumulator high 32 bits. */
185                 MVTACHI R15, A1
186                 POP             R15
187
188                 /* Accumulator guard. */
189                 MVTACGU R15, A1
190                 POP             R15
191                 MVTC            R15, FPSW
192                 POPM            R1-R15
193                 RTE
194                 NOP
195                 NOP
196
197 /*-----------------------------------------------------------*/
198
199                 END
200