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