]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/standalone_v6_1/src/xpseudo_asm_gcc.h
Update Zynq MPSoC hardware definition and BSP files to be those shipped with the...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / standalone_v6_1 / src / xpseudo_asm_gcc.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2014 - 2016 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 /**
34 *
35 * @file xpseudo_asm_gcc.h
36 *
37 * This header file contains macros for using inline assembler code. It is
38 * written specifically for the GNU compiler.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who      Date     Changes
44 * ----- -------- -------- -----------------------------------------------
45 * 5.00  pkp              05/21/14 First release
46 * 6.0   mus      07/27/16 Consolidated file for a53,a9 and r5 processors
47 * </pre>
48 *
49 ******************************************************************************/
50
51 #ifndef XPSEUDO_ASM_GCC_H  /* prevent circular inclusions */
52 #define XPSEUDO_ASM_GCC_H  /* by using protection macros */
53
54 /***************************** Include Files ********************************/
55
56 #include "xil_types.h"
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif /* __cplusplus */
61
62 /************************** Constant Definitions ****************************/
63
64 /**************************** Type Definitions ******************************/
65
66 /***************** Macros (Inline Functions) Definitions ********************/
67
68 /* necessary for pre-processor */
69 #define stringify(s)    tostring(s)
70 #define tostring(s)     #s
71
72 #if defined (__aarch64__)
73 /* pseudo assembler instructions */
74 #define mfcpsr()        ({u32 rval; \
75                            asm volatile("mrs %0,  DAIF" : "=r" (rval));\
76                           rval;\
77                          })
78
79 #define mtcpsr(v) __asm__ __volatile__ ("msr DAIF, %0" : : "r" (v))
80
81 #define cpsiei()        //__asm__ __volatile__("cpsie   i\n")
82 #define cpsidi()        //__asm__ __volatile__("cpsid   i\n")
83
84 #define cpsief()        //__asm__ __volatile__("cpsie   f\n")
85 #define cpsidf()        //__asm__ __volatile__("cpsid   f\n")
86
87
88
89 #define mtgpr(rn, v)    /*__asm__ __volatile__(\
90                           "mov r" stringify(rn) ", %0 \n"\
91                           : : "r" (v)\
92                         )*/
93
94 #define mfgpr(rn)       /*({u32 rval; \
95                           __asm__ __volatile__(\
96                             "mov %0,r" stringify(rn) "\n"\
97                             : "=r" (rval)\
98                           );\
99                           rval;\
100                          })*/
101
102 /* memory synchronization operations */
103
104 /* Instruction Synchronization Barrier */
105 #define isb() __asm__ __volatile__ ("isb sy")
106
107 /* Data Synchronization Barrier */
108 #define dsb() __asm__ __volatile__("dsb sy")
109
110 /* Data Memory Barrier */
111 #define dmb() __asm__ __volatile__("dmb sy")
112
113
114 /* Memory Operations */
115 #define ldr(adr)        ({u64 rval; \
116                           __asm__ __volatile__(\
117                             "ldr        %0,[%1]"\
118                             : "=r" (rval) : "r" (adr)\
119                           );\
120                           rval;\
121                          })
122
123 #else
124
125 /* pseudo assembler instructions */
126 #define mfcpsr()        ({u32 rval; \
127                           __asm__ __volatile__(\
128                             "mrs        %0, cpsr\n"\
129                             : "=r" (rval)\
130                           );\
131                           rval;\
132                          })
133
134 #define mtcpsr(v)       __asm__ __volatile__(\
135                           "msr  cpsr,%0\n"\
136                           : : "r" (v)\
137                         )
138
139 #define cpsiei()        __asm__ __volatile__("cpsie     i\n")
140 #define cpsidi()        __asm__ __volatile__("cpsid     i\n")
141
142 #define cpsief()        __asm__ __volatile__("cpsie     f\n")
143 #define cpsidf()        __asm__ __volatile__("cpsid     f\n")
144
145
146
147 #define mtgpr(rn, v)    __asm__ __volatile__(\
148                           "mov r" stringify(rn) ", %0 \n"\
149                           : : "r" (v)\
150                         )
151
152 #define mfgpr(rn)       ({u32 rval; \
153                           __asm__ __volatile__(\
154                             "mov %0,r" stringify(rn) "\n"\
155                             : "=r" (rval)\
156                           );\
157                           rval;\
158                          })
159
160 /* memory synchronization operations */
161
162 /* Instruction Synchronization Barrier */
163 #define isb() __asm__ __volatile__ ("isb" : : : "memory")
164
165 /* Data Synchronization Barrier */
166 #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
167
168 /* Data Memory Barrier */
169 #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
170
171
172 /* Memory Operations */
173 #define ldr(adr)        ({u32 rval; \
174                           __asm__ __volatile__(\
175                             "ldr        %0,[%1]"\
176                             : "=r" (rval) : "r" (adr)\
177                           );\
178                           rval;\
179                          })
180
181 #endif
182
183 #define ldrb(adr)       ({u8 rval; \
184                           __asm__ __volatile__(\
185                             "ldrb       %0,[%1]"\
186                             : "=r" (rval) : "r" (adr)\
187                           );\
188                           rval;\
189                          })
190
191 #define str(adr, val)   __asm__ __volatile__(\
192                           "str  %0,[%1]\n"\
193                           : : "r" (val), "r" (adr)\
194                         )
195
196 #define strb(adr, val)  __asm__ __volatile__(\
197                           "strb %0,[%1]\n"\
198                           : : "r" (val), "r" (adr)\
199                         )
200
201 /* Count leading zeroes (clz) */
202 #define clz(arg)        ({u8 rval; \
203                           __asm__ __volatile__(\
204                             "clz        %0,%1"\
205                             : "=r" (rval) : "r" (arg)\
206                           );\
207                           rval;\
208                          })
209
210 #if defined (__aarch64__)
211 #define mtcpdc(reg,val) __asm__ __volatile__("dc " #reg ",%0"  : : "r" (val))
212 #define mtcpic(reg,val) __asm__ __volatile__("ic " #reg ",%0"  : : "r" (val))
213
214 #define mtcpicall(reg)  __asm__ __volatile__("ic " #reg)
215 #define mtcptlbi(reg)   __asm__ __volatile__("tlbi " #reg)
216 #define mtcpat(reg,val) __asm__ __volatile__("at " #reg ",%0"  : : "r" (val))
217 /* CP15 operations */
218 #define mfcp(reg)       ({u64 rval;\
219                         __asm__ __volatile__("mrs       %0, " #reg : "=r" (rval));\
220                         rval;\
221                         })
222
223 #define mtcp(reg,val)   __asm__ __volatile__("msr " #reg ",%0"  : : "r" (val))
224
225 #else
226 /* CP15 operations */
227 #define mtcp(rn, v)     __asm__ __volatile__(\
228                          "mcr " rn "\n"\
229                          : : "r" (v)\
230                         );
231
232 #define mfcp(rn)        ({u32 rval; \
233                          __asm__ __volatile__(\
234                            "mrc " rn "\n"\
235                            : "=r" (rval)\
236                          );\
237                          rval;\
238                          })
239 #endif
240
241 /************************** Variable Definitions ****************************/
242
243 /************************** Function Prototypes *****************************/
244
245 #ifdef __cplusplus
246 }
247 #endif /* __cplusplus */
248
249 #endif /* XPSEUDO_ASM_GCC_H */