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