]> git.sur5r.net Git - freertos/blob
33cd25dac4ec388552a25a5169d8cb9c6239e4b4
[freertos] /
1 /******************************************************************************
2 *
3 * Copyright (C) 2004 - 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 ******************************************************************************/
32
33 #ifndef _MICROBLAZE_INTERFACE_H_
34 #define _MICROBLAZE_INTERFACE_H_
35
36 #include "xil_types.h"
37 #include "xil_assert.h"
38 #include "xil_exception.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 extern void microblaze_enable_interrupts(void);                 /* Enable Interrupts */
44 extern void microblaze_disable_interrupts(void);                /* Disable Interrupts */
45 extern void microblaze_enable_icache(void);                     /* Enable Instruction Cache */
46 extern void microblaze_disable_icache(void);                    /* Disable Instruction Cache */
47 extern void microblaze_enable_dcache(void);                     /* Enable Instruction Cache */
48 extern void microblaze_disable_dcache(void);                    /* Disable Instruction Cache */
49 extern void microblaze_enable_exceptions(void);                 /* Enable hardware exceptions */
50 extern void microblaze_disable_exceptions(void);                /* Disable hardware exceptions */
51 extern void microblaze_register_handler(XInterruptHandler Handler, void *DataPtr); /* Register top level interrupt handler */
52 extern void microblaze_register_exception_handler(u32 ExceptionId, Xil_ExceptionHandler Handler, void *DataPtr); /* Register exception handler */
53
54 extern void microblaze_invalidate_icache(void);         /* Invalidate the entire icache */
55 extern void microblaze_invalidate_dcache(void);         /* Invalidate the entire dcache */
56 extern void microblaze_flush_dcache(void);              /* Flush the whole dcache */
57 extern void microblaze_invalidate_icache_range(unsigned int cacheaddr, unsigned int len);   /* Invalidate a part of the icache */
58 extern void microblaze_invalidate_dcache_range(unsigned int cacheaddr, unsigned int len);   /* Invalidate a part of the dcache */
59 extern void microblaze_flush_dcache_range(unsigned int cacheaddr, unsigned int len);        /* Flush a part of the dcache */
60 extern void microblaze_scrub(void);                     /* Scrub LMB and internal BRAM */
61 extern void microblaze_invalidate_cache_ext(void);         /* Invalidate cache ext */
62 extern void microblaze_flush_cache_ext(void);         /* Flush cache ext */
63 extern void microblaze_flush_cache_ext_range(unsigned int cacheaddr,
64                         unsigned int len); /* Flush cache ext range */
65 extern void microblaze_invalidate_cache_ext_range(unsigned int cacheaddr,
66                         unsigned int len); /* Invalidate cache ext range */
67
68 /* Deprecated */
69 extern void microblaze_update_icache (int , int , int ) __attribute__((deprecated));
70 extern void microblaze_init_icache_range (int , int )  __attribute__((deprecated));
71 extern void microblaze_update_dcache (int , int , int )  __attribute__((deprecated));
72 extern void microblaze_init_dcache_range (int , int )  __attribute__((deprecated));
73
74 /* necessary for pre-processor */
75 #define stringify(s)    tostring(s)
76 #define tostring(s)     #s
77
78 /* FSL Access Macros */
79
80 /* Blocking Data Read and Write to FSL no. id */
81 #define getfsl(val, id)         asm volatile ("get\t%0,rfsl" stringify(id) : "=d" (val))
82 #define putfsl(val, id)         asm volatile ("put\t%0,rfsl" stringify(id) :: "d" (val))
83
84 /* Non-blocking Data Read and Write to FSL no. id */
85 #define ngetfsl(val, id)        asm volatile ("nget\t%0,rfsl" stringify(id) : "=d" (val))
86 #define nputfsl(val, id)        asm volatile ("nput\t%0,rfsl" stringify(id) :: "d" (val))
87
88 /* Blocking Control Read and Write to FSL no. id */
89 #define cgetfsl(val, id)        asm volatile ("cget\t%0,rfsl" stringify(id) : "=d" (val))
90 #define cputfsl(val, id)        asm volatile ("cput\t%0,rfsl" stringify(id) :: "d" (val))
91
92 /* Non-blocking Control Read and Write to FSL no. id */
93 #define ncgetfsl(val, id)       asm volatile ("ncget\t%0,rfsl" stringify(id) : "=d" (val))
94 #define ncputfsl(val, id)       asm volatile ("ncput\t%0,rfsl" stringify(id) :: "d" (val))
95
96 /* Polling versions of FSL access macros. This makes the FSL access interruptible */
97 #define getfsl_interruptible(val, id)       asm volatile ("\n1:\n\tnget\t%0,rfsl" stringify(id) "\n\t"   \
98                                                           "addic\tr18,r0,0\n\t"                \
99                                                           "bnei\tr18,1b\n"                     \
100                                                            : "=d" (val) :: "r18")
101
102 #define putfsl_interruptible(val, id)       asm volatile ("\n1:\n\tnput\t%0,rfsl" stringify(id) "\n\t"   \
103                                                           "addic\tr18,r0,0\n\t"                \
104                                                           "bnei\tr18,1b\n"                     \
105                                                           :: "d" (val) : "r18")
106
107 #define cgetfsl_interruptible(val, id)      asm volatile ("\n1:\n\tncget\t%0,rfsl" stringify(id) "\n\t"  \
108                                                           "addic\tr18,r0,0\n\t"                \
109                                                           "bnei\tr18,1b\n"                     \
110                                                           : "=d" (val) :: "r18")
111
112 #define cputfsl_interruptible(val, id)      asm volatile ("\n1:\n\tncput\t%0,rfsl" stringify(id) "\n\t"  \
113                                                           "addic\tr18,r0,0\n\t"                \
114                                                           "bnei\tr18,1b\n"                     \
115                                                           :: "d" (val) : "r18")
116 /* FSL valid and error check macros. */
117 #define fsl_isinvalid(result)               asm volatile ("addic\t%0,r0,0"  : "=d" (result))
118 #define fsl_iserror(error)                  asm volatile ("mfs\t%0,rmsr\n\t"  \
119                                                               "andi\t%0,%0,0x10" : "=d" (error))
120
121 /* Pseudo assembler instructions */
122 #define clz(v)          ({  unsigned int _rval;         \
123                             __asm__ __volatile__ (      \
124                                 "clz\t%0,%1\n" : "=d"(_rval): "d" (v) \
125                             );                          \
126                             _rval;                      \
127                         })
128
129 #define mbar(mask)      ({  __asm__ __volatile__ ("mbar\t" stringify(mask) ); })
130 #define mb_sleep()      ({  __asm__ __volatile__ ("sleep\t"); })
131
132 #define mb_swapb(v)             ({      unsigned int _rval;         \
133                                                         __asm__ __volatile__ (      \
134                                                                 "swapb\t%0,%1\n" : "=d"(_rval) : "d" (v) \
135                                                          );                          \
136                                                          _rval;                      \
137                                                 })
138
139 #define mb_swaph(v)             ({      unsigned int _rval;         \
140                                                         __asm__ __volatile__ (      \
141                                                                 "swaph\t%0,%1\n" : "=d"(_rval) : "d" (v) \
142                                                          );                          \
143                                                          _rval;                      \
144                                                 })
145
146 #define mfgpr(rn)       ({  unsigned int _rval;         \
147                             __asm__ __volatile__ (      \
148                                 "or\t%0,r0," stringify(rn) "\n" : "=d"(_rval) \
149                             );                          \
150                             _rval;                      \
151                         })
152
153 #define mfmsr()         ({  unsigned int _rval;         \
154                             __asm__ __volatile__ (      \
155                                 "mfs\t%0,rmsr\n" : "=d"(_rval) \
156                             );                          \
157                             _rval;                      \
158                         })
159
160 #define mfear()         ({  unsigned int _rval;         \
161                             __asm__ __volatile__ (      \
162                                 "mfs\t%0,rear\n" : "=d"(_rval) \
163                             );                          \
164                             _rval;                      \
165                         })
166
167 #define mfesr()         ({  unsigned int _rval;         \
168                             __asm__ __volatile__ (      \
169                                 "mfs\t%0,resr\n" : "=d"(_rval) \
170                             );                          \
171                             _rval;                      \
172                         })
173
174 #define mffsr()         ({  unsigned int _rval;         \
175                             __asm__ __volatile__ (      \
176                                 "mfs\t%0,rfsr\n" : "=d"(_rval) \
177                             );                          \
178                             _rval;                      \
179                         })
180
181 #define mfpvr(rn)       ({  unsigned int _rval;         \
182                             __asm__ __volatile__ (                          \
183                                 "mfs\t%0,rpvr" stringify(rn) "\n" : "=d"(_rval) \
184                             );                                              \
185                             _rval;                                          \
186                         })
187
188 #define mfbtr()         ({  unsigned int _rval;         \
189                             __asm__ __volatile__ (      \
190                                 "mfs\t%0,rbtr\n" : "=d"(_rval)  \
191                             );                                  \
192                             _rval;                              \
193                         })
194
195 #define mfedr()         ({  unsigned int _rval;         \
196                             __asm__ __volatile__ (      \
197                                 "mfs\t%0,redr\n" : "=d"(_rval)  \
198                             );                                  \
199                             _rval;                              \
200                         })
201
202 #define mfpid()         ({  unsigned int _rval;         \
203                             __asm__ __volatile__ (            \
204                                 "mfs\t%0,rpid\n" : "=d"(_rval)\
205                             );                                \
206                             _rval;                            \
207                         })
208
209 #define mfzpr()         ({  unsigned int _rval;         \
210                             __asm__ __volatile__ (                  \
211                                 "mfs\t%0,rzpr\n" : "=d"(_rval)      \
212                             );                                      \
213                             _rval;                                  \
214                         })
215
216 #define mftlbx()        ({  unsigned int _rval;         \
217                             __asm__ __volatile__ (                  \
218                                 "mfs\t%0,rtlbx\n" : "=d"(_rval)     \
219                             );                                      \
220                             _rval;                                  \
221                         })
222
223 #define mftlblo()       ({  unsigned int _rval;                     \
224                             __asm__ __volatile__ (                  \
225                                 "mfs\t%0,rtlblo\n" : "=d"(_rval)    \
226                             );                                      \
227                             _rval;                                  \
228                         })
229
230 #define mftlbhi()       ({  unsigned int _rval;         \
231                             __asm__ __volatile__ (                  \
232                                 "mfs\t%0,rtlbhi\n" : "=d"(_rval)    \
233                             );                                      \
234                             _rval;                                  \
235                         })
236
237 #define mfslr()         ({  unsigned int _rval;         \
238                             __asm__ __volatile__ (                  \
239                                 "mfs\t%0,rslr\n" : "=d"(_rval)    \
240                             );                                      \
241                             _rval;                                  \
242                         })
243
244 #define mfshr()         ({  unsigned int _rval;         \
245                             __asm__ __volatile__ (                  \
246                                 "mfs\t%0,rshr\n" : "=d"(_rval)    \
247                             );                                      \
248                             _rval;                                  \
249                         })
250
251 #define mtgpr(rn, v)    ({  __asm__ __volatile__ (                      \
252                                 "or\t" stringify(rn) ",r0,%0\n" :: "d" (v) \
253                             );                          \
254                         })
255
256 #define mtmsr(v)        ({  __asm__ __volatile__ (      \
257                                 "mts\trmsr,%0\n\tnop\n" :: "d" (v)      \
258                             );                          \
259                         })
260
261
262 #define mtfsr(v)        ({  __asm__ __volatile__ (      \
263                                 "mts\trfsr,%0\n\tnop\n" :: "d" (v)  \
264                             );                                      \
265                         })
266
267 #define mtpid(v)        ({  __asm__ __volatile__ (      \
268                                 "mts\trpid,%0\n\tnop\n" :: "d" (v)      \
269                             );                                      \
270                         })
271
272 #define mtzpr(v)        ({  __asm__ __volatile__ (                  \
273                                 "mts\trzpr,%0\n\tnop\n" :: "d" (v)      \
274                             );                                      \
275                         })
276
277 #define mttlbx(v)       ({  __asm__ __volatile__ (      \
278                                 "mts\trtlbx,%0\n\tnop\n" :: "d" (v)     \
279                             );                                      \
280                         })
281
282 #define mttlblo(v)      ({  __asm__ __volatile__ (      \
283                                 "mts\trtlblo,%0\n\tnop\n" :: "d" (v)    \
284                             );                                      \
285                         })
286
287 #define mttlbhi(v)      ({  __asm__ __volatile__ (      \
288                                 "mts\trtlbhi,%0\n\tnop\n" :: "d" (v)    \
289                             );                                      \
290                         })
291
292 #define mttlbsx(v)      ({  __asm__ __volatile__ (      \
293                                 "mts\trtlbsx,%0\n\tnop\n" :: "d" (v)    \
294                             );                                      \
295                         })
296
297 #define mtslr(v)        ({  __asm__ __volatile__ (      \
298                                 "mts\trslr,%0\n\tnop\n" :: "d" (v)  \
299                             );                                      \
300                         })
301
302 #define mtshr(v)        ({  __asm__ __volatile__ (      \
303                                 "mts\trshr,%0\n\tnop\n" :: "d" (v)  \
304                             );                                      \
305                         })
306
307 #define lwx(address)    ({  unsigned int _rval; \
308                               __asm__ __volatile__ ( \
309                              "lwx\t%0,%1,r0\n" : "=d"(_rval) : "d" (address) \
310                               ); \
311                               _rval; \
312                           })
313
314 #define lwr(address)    ({  unsigned int _rval; \
315                               __asm__ __volatile__ ( \
316                              "lwr\t%0,%1,r0\n" : "=d"(_rval) : "d" (address) \
317                               ); \
318                               _rval; \
319                           })
320
321 #define lhur(address)   ({  unsigned int _rval; \
322                               __asm__ __volatile__ ( \
323                              "lhur\t%0,%1,r0\n" : "=d"(_rval) : "d" (address) \
324                               ); \
325                               _rval; \
326                           })
327
328 #define lbur(address)   ({  unsigned int _rval; \
329                               __asm__ __volatile__ ( \
330                              "lbur\t%0,%1,r0\n" : "=d"(_rval) : "d" (address) \
331                               ); \
332                               _rval; \
333                           })
334
335 #define swx(address, data) ({  __asm__ __volatile__ ( \
336                                 "swx\t%0,%1,r0\n" :: "d" (data), "d" (address) \
337                                ); \
338                            })
339
340 #define swr(address, data) ({  __asm__ __volatile__ ( \
341                                 "swr\t%0,%1,r0\n" :: "d" (data), "d" (address) \
342                                ); \
343                            })
344
345 #define shr(address, data) ({  __asm__ __volatile__ ( \
346                                 "shr\t%0,%1,r0\n" :: "d" (data), "d" (address) \
347                                ); \
348                            })
349
350 #define sbr(address, data) ({  __asm__ __volatile__ ( \
351                                 "sbr\t%0,%1,r0\n" :: "d" (data), "d" (address) \
352                                ); \
353                            })
354
355 #define microblaze_getfpex_operand_a()     ({          \
356                                     extern unsigned int mb_fpex_op_a;   \
357                                     mb_fpex_op_a;                       \
358                                 })
359
360 #define microblaze_getfpex_operand_b()     ({          \
361                                     extern unsigned int mb_fpex_op_b;   \
362                                     mb_fpex_op_b;                       \
363                                 })
364
365 /* Deprecated MicroBlaze FSL macros */
366 #define microblaze_bread_datafsl(val, id)       getfsl(val,id)
367 #define microblaze_bwrite_datafsl(val, id)      putfsl(val,id)
368 #define microblaze_nbread_datafsl(val, id)      ngetfsl(val,id)
369 #define microblaze_nbwrite_datafsl(val, id)     nputfsl(val,id)
370 #define microblaze_bread_cntlfsl(val, id)       cgetfsl(val,id)
371 #define microblaze_bwrite_cntlfsl(val, id)      cputfsl(val,id)
372 #define microblaze_nbread_cntlfsl(val, id)      ncgetfsl(val,id)
373 #define microblaze_nbwrite_cntlfsl(val, id)     ncputfsl(val,id)
374
375 #ifdef __cplusplus
376 }
377 #endif
378 #endif // _MICROBLAZE_INTERFACE_H_