]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v4_2/src/microblaze_scrub.S
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v4_2 / src / microblaze_scrub.S
1 /******************************************************************************
2 *
3 * Copyright (C) 2012 - 2014 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 * microblaze_scrub ()
32 *
33 *    Scrub LMB memory and all internal BRAMs (data cache, instruction cache,
34 *    MMU UTLB and branch target cache) in MicroBlaze to reduce the possibility
35 *    of an uncorrectable error when fault tolerance support is enabled.
36 *
37 *    This routine assumes that the processor is in privileged mode when it is
38 *    called, if the MMU is enabled.
39 *
40 *    Call this routine regularly from a timer interrupt.
41 *
42 *    Parameters:
43 *       None
44 *
45 *
46 *******************************************************************************/
47
48 #include "xparameters.h"
49
50 /* Define if fault tolerance is used */
51 #ifdef XPAR_MICROBLAZE_FAULT_TOLERANT
52   #if XPAR_MICROBLAZE_FAULT_TOLERANT > 0
53     #define FAULT_TOLERANT
54   #endif
55 #endif
56
57 /* Define if LMB is used and can be scrubbed */
58 #if defined(XPAR_MICROBLAZE_D_LMB) &&            \
59             defined(XPAR_DLMB_CNTLR_BASEADDR) && \
60             defined(XPAR_DLMB_CNTLR_HIGHADDR)
61   #if XPAR_MICROBLAZE_D_LMB == 1
62     #define HAS_SCRUBBABLE_LMB
63     #define DLMB_MASK (XPAR_DLMB_CNTLR_HIGHADDR - XPAR_DLMB_CNTLR_BASEADDR)
64   #endif
65 #endif
66
67 /* Set default cache line lengths */
68 #ifndef XPAR_MICROBLAZE_DCACHE_LINE_LEN
69   #define XPAR_MICROBLAZE_DCACHE_LINE_LEN   4
70 #endif
71
72 #ifndef XPAR_MICROBLAZE_ICACHE_LINE_LEN
73   #define XPAR_MICROBLAZE_ICACHE_LINE_LEN   4
74 #endif
75
76 /* Define if internal Data Cache BRAMs are used */
77 #if defined(XPAR_MICROBLAZE_USE_DCACHE) && defined(XPAR_MICROBLAZE_DCACHE_BYTE_SIZE)
78   #if XPAR_MICROBLAZE_USE_DCACHE == 1 && XPAR_MICROBLAZE_DCACHE_BYTE_SIZE > 1024
79     #define HAS_BRAM_DCACHE
80     #define DCACHE_INCREMENT (XPAR_MICROBLAZE_DCACHE_LINE_LEN * 4)
81     #define DCACHE_MASK (XPAR_MICROBLAZE_DCACHE_BYTE_SIZE - 1)
82   #endif
83 #endif
84
85 /* Define if internal Instruction Cache BRAMs are used */
86 #if defined(XPAR_MICROBLAZE_USE_ICACHE) && defined(XPAR_MICROBLAZE_CACHE_BYTE_SIZE)
87   #if XPAR_MICROBLAZE_USE_ICACHE == 1 && XPAR_MICROBLAZE_CACHE_BYTE_SIZE > 1024
88     #define HAS_BRAM_ICACHE
89     #define ICACHE_INCREMENT (XPAR_MICROBLAZE_ICACHE_LINE_LEN * 4)
90     #define ICACHE_MASK (XPAR_MICROBLAZE_CACHE_BYTE_SIZE - 1)
91   #endif
92 #endif
93
94 /* Define if internal MMU UTLB BRAM is used */
95 #ifdef XPAR_MICROBLAZE_USE_MMU
96   #if XPAR_MICROBLAZE_USE_MMU > 1
97     #define HAS_BRAM_MMU_UTLB
98   #endif
99 #endif
100
101 /* Define if internal BTC BRAM is used, and match BTC clear to a complete cache scrub */
102 #if defined(XPAR_MICROBLAZE_USE_BRANCH_TARGET_CACHE) && \
103     defined(XPAR_MICROBLAZE_BRANCH_TARGET_CACHE_SIZE)
104   #if XPAR_MICROBLAZE_USE_BRANCH_TARGET_CACHE == 1
105     #if XPAR_MICROBLAZE_BRANCH_TARGET_CACHE_SIZE == 0 || \
106         XPAR_MICROBLAZE_BRANCH_TARGET_CACHE_SIZE >  4
107       #define HAS_BRAM_BRANCH_TARGET_CACHE
108       #ifdef HAS_BRAM_DCACHE
109         #define BTC_MASK_D (XPAR_MICROBLAZE_DCACHE_BYTE_SIZE/DCACHE_INCREMENT-1)
110       #else
111         #define BTC_MASK_D 256
112       #endif
113       #ifdef HAS_BRAM_ICACHE
114         #define BTC_MASK_I (XPAR_MICROBLAZE_CACHE_BYTE_SIZE/ICACHE_INCREMENT-1)
115       #else
116         #define BTC_MASK_I 256
117       #endif
118       #if BTC_MASK_D > BTC_MASK_I
119         #define BTC_MASK BTC_MASK_D
120       #else
121         #define BTC_MASK BTC_MASK_I
122       #endif
123     #endif
124   #endif
125 #endif
126
127 /* Define index offsets to persistent data used by this routine */
128 #define DLMB_INDEX_OFFSET     0
129 #define DCACHE_INDEX_OFFSET   4
130 #define ICACHE_INDEX_OFFSET   8
131 #define MMU_INDEX_OFFSET      12
132 #define BTC_CALL_COUNT_OFFSET 16
133
134         .text
135         .globl  microblaze_scrub
136         .ent    microblaze_scrub
137         .align  2
138
139 microblaze_scrub:
140 #ifdef FAULT_TOLERANT
141         la      r6, r0, L_persistent_data               /* Get pointer to data */
142
143 #ifdef HAS_SCRUBBABLE_LMB
144 L_dlmb:
145         lwi     r5, r6, DLMB_INDEX_OFFSET               /* Get dlmb index */
146         lw      r7, r5, r0                              /* Load and store */
147         sw      r7, r5, r0
148         addik   r5, r5, 4                               /* Increment and save dlmb index */
149         andi    r5, r5, DLMB_MASK
150         swi     r5, r6, DLMB_INDEX_OFFSET
151 #endif /* HAS_SCRUBBABLE_LMB */
152
153 #ifdef HAS_BRAM_DCACHE
154 L_dcache:
155         lwi     r5, r6, DCACHE_INDEX_OFFSET             /* Get dcache line index */
156         wdc     r5, r0                                  /* Invalidate data cache line */
157         addik   r5, r5, DCACHE_INCREMENT                /* Increment and save entry index */
158         andi    r5, r5, DCACHE_MASK
159         swi     r5, r6, DCACHE_INDEX_OFFSET
160 #endif /* HAS_BRAM_DCACHE */
161
162 #ifdef HAS_BRAM_ICACHE
163 L_icache:
164         lwi     r5, r6, ICACHE_INDEX_OFFSET             /* Get icache line index */
165         wic     r5, r0                                  /* Invalidate data cache line */
166         addik   r5, r5, ICACHE_INCREMENT                /* Increment and save entry index */
167         andi    r5, r5, ICACHE_MASK
168         swi     r5, r6, ICACHE_INDEX_OFFSET
169 #endif /* HAS_BRAM_ICACHE */
170
171 #ifdef HAS_BRAM_MMU_UTLB
172 L_mmu:
173         lwi     r5, r6, MMU_INDEX_OFFSET                /* Get UTLB entry index */
174         mts     rtlbx, r5                               /* Access next entry in UTLB */
175         mts     rtlbhi, r0                              /* Clear the UTLB entry */
176
177         addik   r5, r5, 1                               /* Increment and save entry index */
178         andi    r5, r5, 0x3F
179         swi     r5, r6, MMU_INDEX_OFFSET
180 #endif /* HAS_BRAM_MMU_UTLB */
181
182 #ifdef HAS_BRAM_BRANCH_TARGET_CACHE
183 L_btc:
184         lwi     r5, r6, BTC_CALL_COUNT_OFFSET           /* Get BTC call count offset */
185         addik   r5, r5, 1                               /* Increment and save call count */
186         andi    r5, r5, BTC_MASK
187         swi     r5, r6, BTC_CALL_COUNT_OFFSET
188
189         bnei    r5, L_skip_btc_scrub                    /* Skip scrub unless count wrap */
190         bri     4                                       /* Clear branch target cache */
191 L_skip_btc_scrub:
192 #endif /* HAS_BRAM_BRANCH_TARGET_CACHE */
193
194 #endif /* FAULT_TOLERANT */
195 L_done:
196         rtsd    r15, 8                                  /* Return */
197         nop
198         .end    microblaze_scrub
199
200         /* Persistent data used by this routine */
201         .data
202         .align  2
203 L_persistent_data:
204         .long   0                                       /* dlmb index      */
205         .long   0                                       /* dcache index    */
206         .long   0                                       /* icache index    */
207         .long   0                                       /* mmu entry index */
208         .long   0                                       /* btc call count  */