]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D3x_Xplained_IAR/AtmelFiles/libchip_sama5d3x/cp15/cp15_asm_iar.s
Start of SAMA5D3 XPlained demo.
[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 #define __ASSEMBLY__\r
77 \r
78 \r
79 /*----------------------------------------------------------------------------\r
80  *        Functions to access CP15 coprocessor register\r
81  *----------------------------------------------------------------------------*/\r
82         PUBLIC  CP15_ReadID\r
83         PUBLIC  CP15_ReadControl\r
84         PUBLIC  CP15_WriteControl\r
85         PUBLIC  CP15_WriteDomainAccessControl\r
86         PUBLIC  CP15_WriteTTB\r
87         PUBLIC  CP15_InvalidateIcacheInnerSharable\r
88         PUBLIC  CP15_InvalidateBTBinnerSharable\r
89         PUBLIC  CP15_InvalidateIcache\r
90         PUBLIC  CP15_InvalidateIcacheByMva\r
91         PUBLIC  CP15_FlushBTB\r
92         PUBLIC  CP15_FlushBTBbyMva\r
93         PUBLIC  CP15_InvalidateDcacheLineByMva\r
94         PUBLIC  CP15_InvalidateDcacheLineBySetWay\r
95         PUBLIC  CP15_CleanDCacheByMva\r
96         PUBLIC  CP15_CleanDCacheBySetWay\r
97         PUBLIC  CP15_CleanDCacheMva\r
98         PUBLIC  CP15_CleanInvalidateDcacheLineByMva\r
99         PUBLIC  CP15_CleanInvalidateDcacheLine\r
100         PUBLIC  CP15_coherent_dcache_for_dma\r
101         PUBLIC  CP15_invalidate_dcache_for_dma\r
102         PUBLIC  CP15_clean_dcache_for_dma\r
103         PUBLIC  CP15_flush_dcache_for_dma\r
104         PUBLIC  CP15_flush_kern_dcache_for_dma\r
105 \r
106 /** \r
107  * \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.\r
108  *  Reading from this register returns the device ID, the cache type, or the TCM status\r
109  *   depending on the value of Opcode_2 used. \r
110  */\r
111         SECTION .CP15_ReadID:DATA:NOROOT(2)\r
112         PUBLIC   CP15_ReadID\r
113 CP15_ReadID:\r
114         mov     r0, #0\r
115         mrc     p15, 0, r0, c0, c0, 0\r
116         bx      lr\r
117 \r
118 /** \r
119  * \brief Register c1 is the Control Register for the ARM926EJ-S processor.\r
120  * This register specifies the configuration used to enable and disable the\r
121  * caches and MMU. It is recommended that you access this register using a\r
122  * read-modify-write sequence\r
123  */\r
124         SECTION .CP15_ReadControl:CODE:NOROOT(2)\r
125         PUBLIC   CP15_ReadControl\r
126 CP15_ReadControl:\r
127         mov     r0, #0\r
128         mrc     p15, 0, r0, c1, c0, 0   \r
129         bx      lr\r
130 \r
131         SECTION .CP15_WriteControl:CODE:NOROOT(2)\r
132         PUBLIC   CP15_WriteControl\r
133 CP15_WriteControl:\r
134         mcr     p15, 0, r0, c1, c0, 0\r
135         nop\r
136         nop\r
137         nop\r
138         nop\r
139         nop\r
140         nop\r
141         nop\r
142         nop\r
143         bx      lr\r
144 \r
145        SECTION .CP15_WriteDomainAccessControl:CODE:NOROOT(2)\r
146        PUBLIC   CP15_WriteDomainAccessControl\r
147 CP15_WriteDomainAccessControl:\r
148         mcr     p15, 0, r0, c3, c0, 0\r
149         nop\r
150         nop\r
151         nop\r
152         nop\r
153         nop\r
154         nop\r
155         nop\r
156         nop\r
157         bx      lr\r
158  \r
159 /** \r
160  * \brief  ARMv7A architecture supports two translation tables\r
161  * Configure translation table base (TTB) control register cp15,c2\r
162  * to a value of all zeros, indicates we are using TTB register 0.\r
163  * write the address of our page table base to TTB register 0.\r
164  */\r
165         SECTION .CP15_WriteTTB:CODE:NOROOT(2)\r
166         PUBLIC   CP15_WriteTTB\r
167 CP15_WriteTTB:\r
168        mcr     p15, 0, r0, c2, c0, 0\r
169        nop\r
170        nop\r
171        nop\r
172        nop\r
173        nop\r
174        nop\r
175        nop\r
176        nop\r
177        bx     lr\r
178 \r
179 /**\r
180  * \brief Invalidate I cache predictor array inner Sharable\r
181  */\r
182         SECTION .CP15_InvalidateIcacheInnerSharable:CODE:NOROOT(2)\r
183         PUBLIC   CP15_InvalidateIcacheInnerSharable\r
184 CP15_InvalidateIcacheInnerSharable:\r
185         mov     r0, #0\r
186         mcr     p15, 0, r0, c7, c1, 0\r
187         bx      lr\r
188 \r
189 /**\r
190  * \brief Invalidate entire branch predictor array inner Sharable\r
191  */\r
192         SECTION .CP15_InvalidateBTBinnerSharable:CODE:NOROOT(2)\r
193         PUBLIC   CP15_InvalidateBTBinnerSharable\r
194 CP15_InvalidateBTBinnerSharable:\r
195         mov     r0, #0\r
196         mcr     p15, 0, r0, c7, c1, 6\r
197         bx      lr\r
198 \r
199 /**\r
200  * \brief Invalidate all instruction caches to PoU, also flushes branch target cache\r
201  */\r
202         SECTION .CP15_InvalidateIcache:CODE:NOROOT(2)\r
203         PUBLIC   CP15_InvalidateIcache\r
204 CP15_InvalidateIcache:\r
205         mov     r0, #0\r
206         mcr     p15, 0, r0, c7, c5, 0\r
207         bx      lr\r
208 \r
209 /**\r
210  * \brief Invalidate instruction caches by VA to PoU\r
211  */\r
212         SECTION .CP15_InvalidateIcacheByMva:CODE:NOROOT(2)\r
213         PUBLIC   CP15_InvalidateIcacheByMva\r
214 CP15_InvalidateIcacheByMva:\r
215         mov     r0, #0\r
216         mcr     p15, 0, r0, c7, c5, 1\r
217         bx      lr\r
218 \r
219 /**\r
220  * \brief Flush entire branch predictor array\r
221  */\r
222         SECTION .CP15_FlushBTB:CODE:NOROOT(2)\r
223         PUBLIC   CP15_FlushBTB\r
224 CP15_FlushBTB:\r
225         mov     r0, #0\r
226         mcr     p15, 0, r0, c7, c5, 6\r
227         bx      lr\r
228 \r
229 /**\r
230  * \brief Flush branch predictor array entry by MVA\r
231  */\r
232         SECTION .CP15_FlushBTBbyMva:CODE:NOROOT(2)\r
233         PUBLIC   CP15_FlushBTBbyMva\r
234 CP15_FlushBTBbyMva:\r
235         mov     r0, #0\r
236         mcr     p15, 0, r0, c7, c5, 7\r
237         bx      lr\r
238 \r
239 /**\r
240  * \brief Invalidate data cache line by VA to Poc\r
241  */\r
242         SECTION .CP15_InvalidateDcacheLineByMva:CODE:NOROOT(2)\r
243         PUBLIC   CP15_InvalidateDcacheLineByMva\r
244 CP15_InvalidateDcacheLineByMva:\r
245         mov     r0, #0\r
246         mcr     p15, 0, r0, c7, c6, 1\r
247         bx      lr\r
248 \r
249 /**\r
250  * \brief Invalidate data cache line by set/way\r
251  */\r
252         SECTION .CP15_InvalidateDcacheLineBySetWay:CODE:NOROOT(2)\r
253         PUBLIC   CP15_InvalidateDcacheLineBySetWay\r
254 CP15_InvalidateDcacheLineBySetWay:\r
255         mov     r0, #0\r
256         mcr     p15, 0, r0, c7, c6, 2\r
257         bx      lr\r
258 \r
259 /**\r
260  * \brief Clean data cache line by MVA\r
261  */\r
262         SECTION .CP15_CleanDCacheByMva:CODE:NOROOT(2)\r
263         PUBLIC   CP15_CleanDCacheByMva\r
264 CP15_CleanDCacheByMva:\r
265         mov     r0, #0\r
266         mcr     p15, 0, r0, c7, c10, 1\r
267         bx      lr\r
268 \r
269 /**\r
270  * \brief Clean data cache line by Set/way\r
271  */\r
272         SECTION .CP15_CleanDCacheBySetWay:CODE:NOROOT(2)\r
273         PUBLIC   CP15_CleanDCacheBySetWay\r
274 CP15_CleanDCacheBySetWay:\r
275         mov     r0, #0\r
276         mcr     p15, 0, r0, c7, c10, 2\r
277         bx      lr\r
278 \r
279 /**\r
280  * \brief Clean unified cache line by MVA \r
281  */\r
282         SECTION .CP15_CleanDCacheMva:CODE:NOROOT(2)\r
283         PUBLIC   CP15_CleanDCacheMva\r
284 CP15_CleanDCacheMva:\r
285         mov     r0, #0\r
286         mcr     p15, 0, r0, c7, c11, 1\r
287         bx      lr\r
288 \r
289 /**\r
290  * \brief Clean and invalidate data cache line by VA to PoC\r
291  */\r
292         SECTION .CP15_CleanInvalidateDcacheLineByMva:CODE:NOROOT(2)\r
293         PUBLIC   CP15_CleanInvalidateDcacheLineByMva\r
294 CP15_CleanInvalidateDcacheLineByMva:\r
295         mov     r0, #0\r
296         mcr     p15, 0, r0, c7, c14, 1 \r
297         bx      lr\r
298 \r
299 /**\r
300  * \brief Clean and Incalidate data cache line by Set/Way\r
301  */\r
302         SECTION .CP15_CleanInvalidateDcacheLine:CODE:NOROOT(2)\r
303         PUBLIC   CP15_CleanInvalidateDcacheLine\r
304 CP15_CleanInvalidateDcacheLine:\r
305         mov     r0, #0\r
306         mcr     p15, 0, r0, c7, c14, 2\r
307         bx      lr\r
308 \r
309 /**\r
310  * \brief Ensure that the I and D caches are coherent within specified\r
311  *      region.  This is typically used when code has been written to\r
312  *      a memory region, and will be executed.\r
313  * \param start virtual start address of region\r
314  * \param end virtual end address of region\r
315  */\r
316         SECTION .CP15_coherent_dcache_for_dma:CODE:NOROOT(2)\r
317         PUBLIC   CP15_coherent_dcache_for_dma\r
318 CP15_coherent_dcache_for_dma:\r
319 //      dcache_line_size r2, r3\r
320  \r
321         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
322         lsr     r3, r3, #16\r
323         and     r3, r3, #0xf                  // cache line size encoding\r
324         mov     r2, #4                        // bytes per word\r
325         mov     r2, r2, lsl r3                // actual cache line size\r
326 \r
327         sub     r3, r2, #1\r
328         bic     r12, r0, r3\r
329 loop1:\r
330         mcr     p15, 0, r12, c7, c11, 1       // clean D line to the point of unification\r
331         add     r12, r12, r2\r
332         cmp     r12, r1\r
333         blo     loop1\r
334         dsb\r
335 \r
336 // .macro  icache_line_size, reg, tmp\r
337         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
338         and     r3, r3, #0xf                  // cache line size encoding\r
339         mov     r2, #4                        // bytes per word\r
340         mov     r2, r2, lsl r3                // actual cache line size\r
341 \r
342         sub     r3, r2, #1\r
343         bic     r12, r0, r3\r
344 loop2:\r
345         mcr     p15, 0, r12, c7, c5, 1        // invalidate I line\r
346         add     r12, r12, r2\r
347         cmp     r12, r1\r
348         blo     loop2\r
349         mov     r0, #0\r
350         mcr     p15, 0, r0, c7, c1, 6         //invalidate BTB Inner Shareable\r
351         mcr      p15, 0, r0, c7, c5, 6        // invalidate BTB\r
352         dsb\r
353         isb\r
354         bx      lr\r
355 \r
356 \r
357 /**\r
358  * \brief Invalidate the data cache within the specified region; we will\r
359  *      be performing a DMA operation in this region and we want to\r
360  *      purge old data in the cache.\r
361  * \param start virtual start address of region\r
362  * \param end virtual end address of region\r
363  */\r
364         SECTION .CP15_invalidate_dcache_for_dma:CODE:NOROOT(2)\r
365         PUBLIC   CP15_invalidate_dcache_for_dma\r
366 CP15_invalidate_dcache_for_dma:\r
367 \r
368 //      dcache_line_size r2, r3\r
369         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
370         lsr     r3, r3, #16\r
371         and     r3, r3, #0xf                  // cache line size encoding\r
372         mov     r2, #4                        // bytes per word\r
373         mov     r2, r2, lsl r3                // actual cache line size\r
374 \r
375         sub     r3, r2, #1\r
376         tst     r0, r3\r
377         bic     r0, r0, r3\r
378 \r
379         mcrne   p15, 0, r0, c7, c14, 1         // clean & invalidate D / U line\r
380 \r
381         tst     r1, r3\r
382         bic     r1, r1, r3\r
383         mcrne   p15, 0, r1, c7, c14, 1         // clean & invalidate D / U line\r
384 loop3:\r
385         mcr     p15, 0, r0, c7, c6, 1          // invalidate D / U line\r
386         add     r0, r0, r2\r
387         cmp     r0, r1\r
388         blo     loop3\r
389         dsb\r
390         bx      lr\r
391 \r
392 \r
393 /**\r
394  * \brief Clean the data cache within the specified region\r
395  * \param start virtual start address of region\r
396  * \param end virtual end address of region\r
397  */\r
398         SECTION .CP15_clean_dcache_for_dma:CODE:NOROOT(2)\r
399         PUBLIC   CP15_clean_dcache_for_dma\r
400 CP15_clean_dcache_for_dma:\r
401 //      dcache_line_size r2, r3\r
402         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
403         lsr     r3, r3, #16\r
404         and     r3, r3, #0xf                  // cache line size encoding\r
405         mov     r2, #4                        // bytes per word\r
406         mov     r2, r2, lsl r3                // actual cache line size\r
407 \r
408         sub     r3, r2, #1\r
409         bic     r0, r0, r3\r
410 loop4:\r
411         mcr     p15, 0, r0, c7, c10, 1        // clean D / U line\r
412         add     r0, r0, r2\r
413         cmp     r0, r1\r
414         blo     loop4\r
415         dsb\r
416         bx      lr\r
417 \r
418 \r
419 /**\r
420  * \brief Flush the data cache within the specified region\r
421  * \param start virtual start address of region\r
422  * \param end virtual end address of region\r
423  */\r
424         SECTION .CP15_flush_dcache_for_dma:CODE:NOROOT(2)\r
425         PUBLIC   CP15_flush_dcache_for_dma\r
426 CP15_flush_dcache_for_dma:\r
427 //        dcache_line_size r2, r3\r
428         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
429         lsr     r3, r3, #16\r
430         and     r3, r3, #0xf                  // cache line size encoding\r
431         mov     r2, #4                        // bytes per word\r
432         mov     r2, r2, lsl r3                // actual cache line size\r
433         sub     r3, r2, #1\r
434         bic     r0, r0, r3\r
435 loop5:\r
436         mcr     p15, 0, r0, c7, c14, 1         // clean & invalidate D / U line\r
437         add     r0, r0, r2\r
438         cmp     r0, r1\r
439         blo     loop5\r
440         dsb\r
441         bx      lr\r
442 \r
443 \r
444 /**\r
445  * \brief CP15_flush_kern_dcache_for_dma\r
446  * Ensure that the data held in the page kaddr is written back to the page in question.\r
447  * \param start virtual start address of region\r
448  * \param end virtual end address of region\r
449  */\r
450         SECTION .CP15_flush_kern_dcache_for_dma:CODE:NOROOT(2)\r
451         PUBLIC   CP15_flush_kern_dcache_for_dma\r
452 CP15_flush_kern_dcache_for_dma:\r
453 //       dcache_line_size r2, r3\r
454         mrc     p15, 0, r3, c0, c0, 1         // read ctr\r
455         lsr     r3, r3, #16\r
456         and     r3, r3, #0xf                  // cache line size encoding\r
457         mov     r2, #4                        // bytes per word\r
458         mov     r2, r2, lsl r3                // actual cache line size\r
459 \r
460         add     r1, r0, r1\r
461         sub     r3, r2, #1\r
462         bic     r0, r0, r3\r
463 \r
464         mcr     p15, 0, r0, c7, c14, 1        // clean & invalidate D line / unified line\r
465         add     r0, r0, r2\r
466         cmp     r0, r1\r
467         blo     1b\r
468         dsb\r
469         bx      lr\r
470         END\r
471 \r