]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D3x_Xplained_IAR/AtmelFiles/libchip_sama5d3x/cp15/cp15_asm_iar.s
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D3x_Xplained_IAR / AtmelFiles / libchip_sama5d3x / cp15 / cp15_asm_iar.s
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2012, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES// LOSS OF USE, DATA,\r
23  * OR PROFITS// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 \r
31 /** \file */\r
32 \r
33 \r
34 /** \file */\r
35 /**\r
36  * \addtogroup cp15_cache Cache Operations\r
37  *\r
38  * \section Usage\r
39  *\r
40  * They are performed as MCR instructions and only operate on a level 1 cache associated with\r
41  * ATM v7 processor.\r
42  * The supported operations are:\r
43  * <ul>\r
44  * <li> Any of these operations can be applied to\r
45  *  -# any data cache\r
46  *  -# any unified cache.\r
47  * <li> Invalidate by MVA\r
48  *   Performs an invalidate of a data or unified cache line based on the address it contains.\r
49  * <li> Invalidate by set/way\r
50  *   Performs an invalidate of a data or unified cache line based on its location in the cache hierarchy.\r
51  * <li> Clean by MVA\r
52  *   Performs a clean of a data or unified cache line based on the address it contains.\r
53  * <li> Clean by set/way\r
54  *   Performs a clean of a data or unified cache line based on its location in the cache hierarchy.\r
55  * <li> Clean and Invalidate by MVA\r
56  *   Performs a clean and invalidate of a data or unified cache line based on the address it contains.\r
57  * <li> Clean and Invalidate by set/way\r
58  *   Performs a clean and invalidate of a data or unified cache line based on its location in the cache hierarchy.\r
59  * </ul>\r
60  *\r
61  * Related files:\n\r
62  * \ref cp15.h\n\r
63  * \ref cp15_arm_iar.s \n\r
64  */\r
65 \r
66 \r
67         MODULE  ?cp15\r
68 \r
69         //// Forward declaration of sections.\r
70         SECTION IRQ_STACK:DATA:NOROOT(2)\r
71         SECTION CSTACK:DATA:NOROOT(3)\r
72 \r
73 /*----------------------------------------------------------------------------\r
74  *        Headers\r
75  *----------------------------------------------------------------------------*/\r
76 \r
77 \r
78 /*----------------------------------------------------------------------------\r
79  *        Functions to access CP15 coprocessor register\r
80  *----------------------------------------------------------------------------*/\r
81         PUBLIC  CP15_ReadID\r
82         PUBLIC  CP15_ReadControl\r
83         PUBLIC  CP15_WriteControl\r
84         PUBLIC  CP15_WriteDomainAccessControl\r
85         PUBLIC  CP15_WriteTTB\r
86         PUBLIC  CP15_InvalidateIcacheInnerSharable\r
87         PUBLIC  CP15_InvalidateBTBinnerSharable\r
88         PUBLIC  CP15_InvalidateIcache\r
89         PUBLIC  CP15_InvalidateIcacheByMva\r
90         PUBLIC  CP15_FlushBTB\r
91         PUBLIC  CP15_FlushBTBbyMva\r
92         PUBLIC  CP15_InvalidateDcacheLineByMva\r
93         PUBLIC  CP15_InvalidateDcacheLineBySetWay\r
94         PUBLIC  CP15_CleanDCacheByMva\r
95         PUBLIC  CP15_CleanDCacheBySetWay\r
96         PUBLIC  CP15_CleanDCacheMva\r
97         PUBLIC  CP15_CleanInvalidateDcacheLineByMva\r
98         PUBLIC  CP15_CleanInvalidateDcacheLine\r
99         PUBLIC  CP15_coherent_dcache_for_dma\r
100         PUBLIC  CP15_invalidate_dcache_for_dma\r
101         PUBLIC  CP15_clean_dcache_for_dma\r
102         PUBLIC  CP15_flush_dcache_for_dma\r
103         PUBLIC  CP15_flush_kern_dcache_for_dma\r
104 \r
105 /**\r
106  * \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.\r
107  *  Reading from this register returns the device ID, the cache type, or the TCM status\r
108  *   depending on the value of Opcode_2 used.\r
109  */\r
110         SECTION .CP15_ReadID:DATA:NOROOT(2)\r
111         PUBLIC   CP15_ReadID\r
112 CP15_ReadID:\r
113         mov     r0, #0\r
114         mrc     p15, 0, r0, c0, c0, 0\r
115         bx      lr\r
116 \r
117 /**\r
118  * \brief Register c1 is the Control Register for the ARM926EJ-S processor.\r
119  * This register specifies the configuration used to enable and disable the\r
120  * caches and MMU. It is recommended that you access this register using a\r
121  * read-modify-write sequence\r
122  */\r
123         SECTION .CP15_ReadControl:CODE:NOROOT(2)\r
124         PUBLIC   CP15_ReadControl\r
125 CP15_ReadControl:\r
126         mov     r0, #0\r
127         mrc     p15, 0, r0, c1, c0, 0\r
128         bx      lr\r
129 \r
130         SECTION .CP15_WriteControl:CODE:NOROOT(2)\r
131         PUBLIC   CP15_WriteControl\r
132 CP15_WriteControl:\r
133         mcr     p15, 0, r0, c1, c0, 0\r
134         nop\r
135         nop\r
136         nop\r
137         nop\r
138         nop\r
139         nop\r
140         nop\r
141         nop\r
142         bx      lr\r
143 \r
144        SECTION .CP15_WriteDomainAccessControl:CODE:NOROOT(2)\r
145        PUBLIC   CP15_WriteDomainAccessControl\r
146 CP15_WriteDomainAccessControl:\r
147         mcr     p15, 0, r0, c3, c0, 0\r
148         nop\r
149         nop\r
150         nop\r
151         nop\r
152         nop\r
153         nop\r
154         nop\r
155         nop\r
156         bx      lr\r
157 \r
158 /**\r
159  * \brief  ARMv7A architecture supports two translation tables\r
160  * Configure translation table base (TTB) control register cp15,c2\r
161  * to a value of all zeros, indicates we are using TTB register 0.\r
162  * write the address of our page table base to TTB register 0.\r
163  */\r
164         SECTION .CP15_WriteTTB:CODE:NOROOT(2)\r
165         PUBLIC   CP15_WriteTTB\r
166 CP15_WriteTTB:\r
167        mcr     p15, 0, r0, c2, c0, 0\r
168        nop\r
169        nop\r
170        nop\r
171        nop\r
172        nop\r
173        nop\r
174        nop\r
175        nop\r
176        bx     lr\r
177 \r
178 /**\r
179  * \brief Invalidate I cache predictor array inner Sharable\r
180  */\r
181         SECTION .CP15_InvalidateIcacheInnerSharable:CODE:NOROOT(2)\r
182         PUBLIC   CP15_InvalidateIcacheInnerSharable\r
183 CP15_InvalidateIcacheInnerSharable:\r
184         mov     r0, #0\r
185         mcr     p15, 0, r0, c7, c1, 0\r
186         bx      lr\r
187 \r
188 /**\r
189  * \brief Invalidate entire branch predictor array inner Sharable\r
190  */\r
191         SECTION .CP15_InvalidateBTBinnerSharable:CODE:NOROOT(2)\r
192         PUBLIC   CP15_InvalidateBTBinnerSharable\r
193 CP15_InvalidateBTBinnerSharable:\r
194         mov     r0, #0\r
195         mcr     p15, 0, r0, c7, c1, 6\r
196         bx      lr\r
197 \r
198 /**\r
199  * \brief Invalidate all instruction caches to PoU, also flushes branch target cache\r
200  */\r
201         SECTION .CP15_InvalidateIcache:CODE:NOROOT(2)\r
202         PUBLIC   CP15_InvalidateIcache\r
203 CP15_InvalidateIcache:\r
204         mov     r0, #0\r
205         mcr     p15, 0, r0, c7, c5, 0\r
206         bx      lr\r
207 \r
208 /**\r
209  * \brief Invalidate instruction caches by VA to PoU\r
210  */\r
211         SECTION .CP15_InvalidateIcacheByMva:CODE:NOROOT(2)\r
212         PUBLIC   CP15_InvalidateIcacheByMva\r
213 CP15_InvalidateIcacheByMva:\r
214         mov     r0, #0\r
215         mcr     p15, 0, r0, c7, c5, 1\r
216         bx      lr\r
217 \r
218 /**\r
219  * \brief Flush entire branch predictor array\r
220  */\r
221         SECTION .CP15_FlushBTB:CODE:NOROOT(2)\r
222         PUBLIC   CP15_FlushBTB\r
223 CP15_FlushBTB:\r
224         mov     r0, #0\r
225         mcr     p15, 0, r0, c7, c5, 6\r
226         bx      lr\r
227 \r
228 /**\r
229  * \brief Flush branch predictor array entry by MVA\r
230  */\r
231         SECTION .CP15_FlushBTBbyMva:CODE:NOROOT(2)\r
232         PUBLIC   CP15_FlushBTBbyMva\r
233 CP15_FlushBTBbyMva:\r
234         mov     r0, #0\r
235         mcr     p15, 0, r0, c7, c5, 7\r
236         bx      lr\r
237 \r
238 /**\r
239  * \brief Invalidate data cache line by VA to Poc\r
240  */\r
241         SECTION .CP15_InvalidateDcacheLineByMva:CODE:NOROOT(2)\r
242         PUBLIC   CP15_InvalidateDcacheLineByMva\r
243 CP15_InvalidateDcacheLineByMva:\r
244         mov     r0, #0\r
245         mcr     p15, 0, r0, c7, c6, 1\r
246         bx      lr\r
247 \r
248 /**\r
249  * \brief Invalidate data cache line by set/way\r
250  */\r
251         SECTION .CP15_InvalidateDcacheLineBySetWay:CODE:NOROOT(2)\r
252         PUBLIC   CP15_InvalidateDcacheLineBySetWay\r
253 CP15_InvalidateDcacheLineBySetWay:\r
254         mov     r0, #0\r
255         mcr     p15, 0, r0, c7, c6, 2\r
256         bx      lr\r
257 \r
258 /**\r
259  * \brief Clean data cache line by MVA\r
260  */\r
261         SECTION .CP15_CleanDCacheByMva:CODE:NOROOT(2)\r
262         PUBLIC   CP15_CleanDCacheByMva\r
263 CP15_CleanDCacheByMva:\r
264         mov     r0, #0\r
265         mcr     p15, 0, r0, c7, c10, 1\r
266         bx      lr\r
267 \r
268 /**\r
269  * \brief Clean data cache line by Set/way\r
270  */\r
271         SECTION .CP15_CleanDCacheBySetWay:CODE:NOROOT(2)\r
272         PUBLIC   CP15_CleanDCacheBySetWay\r
273 CP15_CleanDCacheBySetWay:\r
274         mov     r0, #0\r
275         mcr     p15, 0, r0, c7, c10, 2\r
276         bx      lr\r
277 \r
278 /**\r
279  * \brief Clean unified cache line by MVA\r
280  */\r
281         SECTION .CP15_CleanDCacheMva:CODE:NOROOT(2)\r
282         PUBLIC   CP15_CleanDCacheMva\r
283 CP15_CleanDCacheMva:\r
284         mov     r0, #0\r
285         mcr     p15, 0, r0, c7, c11, 1\r
286         bx      lr\r
287 \r
288 /**\r
289  * \brief Clean and invalidate data cache line by VA to PoC\r
290  */\r
291         SECTION .CP15_CleanInvalidateDcacheLineByMva:CODE:NOROOT(2)\r
292         PUBLIC   CP15_CleanInvalidateDcacheLineByMva\r
293 CP15_CleanInvalidateDcacheLineByMva:\r
294         mov     r0, #0\r
295         mcr     p15, 0, r0, c7, c14, 1\r
296         bx      lr\r
297 \r
298 /**\r
299  * \brief Clean and Incalidate data cache line by Set/Way\r
300  */\r
301         SECTION .CP15_CleanInvalidateDcacheLine:CODE:NOROOT(2)\r
302         PUBLIC   CP15_CleanInvalidateDcacheLine\r
303 CP15_CleanInvalidateDcacheLine:\r
304         mov     r0, #0\r
305         mcr     p15, 0, r0, c7, c14, 2\r
306         bx      lr\r
307 \r
308 /**\r
309  * \brief Ensure that the I and D caches are coherent within specified\r
310  *      region.  This is typically used when code has been written to\r
311  *      a memory region, and will be executed.\r
312  * \param start virtual start address of region\r
313  * \param end virtual end address of region\r
314  */\r
315         SECTION .CP15_coherent_dcache_for_dma:CODE:NOROOT(2)\r
316         PUBLIC   CP15_coherent_dcache_for_dma\r
317 CP15_coherent_dcache_for_dma:\r
318 //      dcache_line_size r2, r3\r
319 \r
320         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
321         lsr     r3, r3, #16\r
322         and     r3, r3, #0xf                  // cache line size encoding\r
323         mov     r2, #4                        // bytes per word\r
324         mov     r2, r2, lsl r3                // actual cache line size\r
325 \r
326         sub     r3, r2, #1\r
327         bic     r12, r0, r3\r
328 loop1:\r
329         mcr     p15, 0, r12, c7, c11, 1       // clean D line to the point of unification\r
330         add     r12, r12, r2\r
331         cmp     r12, r1\r
332         blo     loop1\r
333         dsb\r
334 \r
335 // .macro  icache_line_size, reg, tmp\r
336         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
337         and     r3, r3, #0xf                  // cache line size encoding\r
338         mov     r2, #4                        // bytes per word\r
339         mov     r2, r2, lsl r3                // actual cache line size\r
340 \r
341         sub     r3, r2, #1\r
342         bic     r12, r0, r3\r
343 loop2:\r
344         mcr     p15, 0, r12, c7, c5, 1        // invalidate I line\r
345         add     r12, r12, r2\r
346         cmp     r12, r1\r
347         blo     loop2\r
348         mov     r0, #0\r
349         mcr     p15, 0, r0, c7, c1, 6         //invalidate BTB Inner Shareable\r
350         mcr      p15, 0, r0, c7, c5, 6        // invalidate BTB\r
351         dsb\r
352         isb\r
353         bx      lr\r
354 \r
355 \r
356 /**\r
357  * \brief Invalidate the data cache within the specified region; we will\r
358  *      be performing a DMA operation in this region and we want to\r
359  *      purge old data in the cache.\r
360  * \param start virtual start address of region\r
361  * \param end virtual end address of region\r
362  */\r
363         SECTION .CP15_invalidate_dcache_for_dma:CODE:NOROOT(2)\r
364         PUBLIC   CP15_invalidate_dcache_for_dma\r
365 CP15_invalidate_dcache_for_dma:\r
366 \r
367 //      dcache_line_size r2, r3\r
368         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
369         lsr     r3, r3, #16\r
370         and     r3, r3, #0xf                  // cache line size encoding\r
371         mov     r2, #4                        // bytes per word\r
372         mov     r2, r2, lsl r3                // actual cache line size\r
373 \r
374         sub     r3, r2, #1\r
375         tst     r0, r3\r
376         bic     r0, r0, r3\r
377 \r
378         mcrne   p15, 0, r0, c7, c14, 1         // clean & invalidate D / U line\r
379 \r
380         tst     r1, r3\r
381         bic     r1, r1, r3\r
382         mcrne   p15, 0, r1, c7, c14, 1         // clean & invalidate D / U line\r
383 loop3:\r
384         mcr     p15, 0, r0, c7, c6, 1          // invalidate D / U line\r
385         add     r0, r0, r2\r
386         cmp     r0, r1\r
387         blo     loop3\r
388         dsb\r
389         bx      lr\r
390 \r
391 \r
392 /**\r
393  * \brief Clean the data cache within the specified region\r
394  * \param start virtual start address of region\r
395  * \param end virtual end address of region\r
396  */\r
397         SECTION .CP15_clean_dcache_for_dma:CODE:NOROOT(2)\r
398         PUBLIC   CP15_clean_dcache_for_dma\r
399 CP15_clean_dcache_for_dma:\r
400 //      dcache_line_size r2, r3\r
401         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
402         lsr     r3, r3, #16\r
403         and     r3, r3, #0xf                  // cache line size encoding\r
404         mov     r2, #4                        // bytes per word\r
405         mov     r2, r2, lsl r3                // actual cache line size\r
406 \r
407         sub     r3, r2, #1\r
408         bic     r0, r0, r3\r
409 loop4:\r
410         mcr     p15, 0, r0, c7, c10, 1        // clean D / U line\r
411         add     r0, r0, r2\r
412         cmp     r0, r1\r
413         blo     loop4\r
414         dsb\r
415         bx      lr\r
416 \r
417 \r
418 /**\r
419  * \brief Flush the data cache within the specified region\r
420  * \param start virtual start address of region\r
421  * \param end virtual end address of region\r
422  */\r
423         SECTION .CP15_flush_dcache_for_dma:CODE:NOROOT(2)\r
424         PUBLIC   CP15_flush_dcache_for_dma\r
425 CP15_flush_dcache_for_dma:\r
426 //        dcache_line_size r2, r3\r
427         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
428         lsr     r3, r3, #16\r
429         and     r3, r3, #0xf                  // cache line size encoding\r
430         mov     r2, #4                        // bytes per word\r
431         mov     r2, r2, lsl r3                // actual cache line size\r
432         sub     r3, r2, #1\r
433         bic     r0, r0, r3\r
434 loop5:\r
435         mcr     p15, 0, r0, c7, c14, 1         // clean & invalidate D / U line\r
436         add     r0, r0, r2\r
437         cmp     r0, r1\r
438         blo     loop5\r
439         dsb\r
440         bx      lr\r
441 \r
442 \r
443 /**\r
444  * \brief CP15_flush_kern_dcache_for_dma\r
445  * Ensure that the data held in the page kaddr is written back to the page in question.\r
446  * \param start virtual start address of region\r
447  * \param end virtual end address of region\r
448  */\r
449         SECTION .CP15_flush_kern_dcache_for_dma:CODE:NOROOT(2)\r
450         PUBLIC   CP15_flush_kern_dcache_for_dma\r
451 CP15_flush_kern_dcache_for_dma:\r
452 //       dcache_line_size r2, r3\r
453         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
454         lsr     r3, r3, #16\r
455         and     r3, r3, #0xf                  // cache line size encoding\r
456         mov     r2, #4                        // bytes per word\r
457         mov     r2, r2, lsl r3                // actual cache line size\r
458 \r
459         add     r1, r0, r1\r
460         sub     r3, r2, #1\r
461         bic     r0, r0, r3\r
462 \r
463         mcr     p15, 0, r0, c7, c14, 1        // clean & invalidate D line / unified line\r
464         add     r0, r0, r2\r
465         cmp     r0, r1\r
466         blo     1b\r
467         dsb\r
468         bx      lr\r
469         END\r
470 \r