RTEMS 6.1-rc2
Loading...
Searching...
No Matches
xpseudo_asm_gcc.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) 2014 - 2021 Xilinx, Inc. All rights reserved.
3* SPDX-License-Identifier: MIT
4******************************************************************************/
5
6/*****************************************************************************/
31#ifndef XPSEUDO_ASM_GCC_H /* prevent circular inclusions */
32#define XPSEUDO_ASM_GCC_H /* by using protection macros */
33
34/***************************** Include Files ********************************/
35
36#include "xil_types.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif /* __cplusplus */
41
42/************************** Constant Definitions ****************************/
43
44/**************************** Type Definitions ******************************/
45
46/***************** Macros (Inline Functions) Definitions ********************/
47
48/* necessary for pre-processor */
49#define stringify(s) tostring(s)
50#define tostring(s) #s
51
52#if defined (__aarch64__)
53/* pseudo assembler instructions */
54#define mfcpsr() ({u32 rval = 0U; \
55 asm volatile("mrs %0, DAIF" : "=r" (rval));\
56 rval;\
57 })
58
59#define mtcpsr(v) __asm__ __volatile__ ("msr DAIF, %0" : : "r" (v))
60
61#define cpsiei() //__asm__ __volatile__("cpsie i\n")
62#define cpsidi() //__asm__ __volatile__("cpsid i\n")
63
64#define cpsief() //__asm__ __volatile__("cpsie f\n")
65#define cpsidf() //__asm__ __volatile__("cpsid f\n")
66
67
68
69#define mtgpr(rn, v) /*__asm__ __volatile__(\
70 "mov r" stringify(rn) ", %0 \n"\
71 : : "r" (v)\
72 )*/
73
74#define mfgpr(rn) /*({u32 rval; \
75 __asm__ __volatile__(\
76 "mov %0,r" stringify(rn) "\n"\
77 : "=r" (rval)\
78 );\
79 rval;\
80 })*/
81
82/* memory synchronization operations */
83
84/* Instruction Synchronization Barrier */
85#define isb() __asm__ __volatile__ ("isb sy")
86
87/* Data Synchronization Barrier */
88#define dsb() __asm__ __volatile__("dsb sy")
89
90/* Data Memory Barrier */
91#define dmb() __asm__ __volatile__("dmb sy")
92
93
94/* Memory Operations */
95#define ldr(adr) ({u64 rval; \
96 __asm__ __volatile__(\
97 "ldr %0,[%1]"\
98 : "=r" (rval) : "r" (adr)\
99 );\
100 rval;\
101 })
102
103#define mfelrel3() ({u64 rval = 0U; \
104 asm volatile("mrs %0, ELR_EL3" : "=r" (rval));\
105 rval;\
106 })
107
108#define mtelrel3(v) __asm__ __volatile__ ("msr ELR_EL3, %0" : : "r" (v))
109
110#else
111
112/* pseudo assembler instructions */
113#define mfcpsr() ({u32 rval = 0U; \
114 __asm__ __volatile__(\
115 "mrs %0, cpsr\n"\
116 : "=r" (rval)\
117 );\
118 rval;\
119 })
120
121#define mtcpsr(v) __asm__ __volatile__(\
122 "msr cpsr,%0\n"\
123 : : "r" (v) : "cc" \
124 )
125
126#define cpsiei() __asm__ __volatile__("cpsie i\n")
127#define cpsidi() __asm__ __volatile__("cpsid i\n")
128
129#define cpsief() __asm__ __volatile__("cpsie f\n")
130#define cpsidf() __asm__ __volatile__("cpsid f\n")
131
132
133
134#define mtgpr(rn, v) __asm__ __volatile__(\
135 "mov r" stringify(rn) ", %0 \n"\
136 : : "r" (v)\
137 )
138
139#define mfgpr(rn) ({u32 rval; \
140 __asm__ __volatile__(\
141 "mov %0,r" stringify(rn) "\n"\
142 : "=r" (rval)\
143 );\
144 rval;\
145 })
146
147/* memory synchronization operations */
148
149/* Instruction Synchronization Barrier */
150#define isb() __asm__ __volatile__ ("isb" : : : "memory")
151
152/* Data Synchronization Barrier */
153#define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
154
155/* Data Memory Barrier */
156#define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
157
158
159/* Memory Operations */
160#define ldr(adr) ({u32 rval; \
161 __asm__ __volatile__(\
162 "ldr %0,[%1]"\
163 : "=r" (rval) : "r" (adr)\
164 );\
165 rval;\
166 })
167
168#endif
169
170#define ldrb(adr) ({u8 rval; \
171 __asm__ __volatile__(\
172 "ldrb %0,[%1]"\
173 : "=r" (rval) : "r" (adr)\
174 );\
175 rval;\
176 })
177
178#define strw(adr, val) __asm__ __volatile__(\
179 "str %0,[%1]\n"\
180 : : "r" (val), "r" (adr)\
181 )
182
183#define strb(adr, val) __asm__ __volatile__(\
184 "strb %0,[%1]\n"\
185 : : "r" (val), "r" (adr)\
186 )
187
188/* Count leading zeroes (clz) */
189#define clz(arg) ({u8 rval; \
190 __asm__ __volatile__(\
191 "clz %0,%1"\
192 : "=r" (rval) : "r" (arg)\
193 );\
194 rval;\
195 })
196
197#if defined (__aarch64__)
198#define mtcpdc(reg,val) __asm__ __volatile__("dc " #reg ",%0" : : "r" (val))
199#define mtcpic(reg,val) __asm__ __volatile__("ic " #reg ",%0" : : "r" (val))
200
201#define mtcpicall(reg) __asm__ __volatile__("ic " #reg)
202#define mtcptlbi(reg) __asm__ __volatile__("tlbi " #reg)
203#define mtcpat(reg,val) __asm__ __volatile__("at " #reg ",%0" : : "r" (val))
204/* CP15 operations */
205#define mfcp(reg) ({u64 rval = 0U;\
206 __asm__ __volatile__("mrs %0, " #reg : "=r" (rval));\
207 rval;\
208 })
209
210#define mtcp(reg,val) __asm__ __volatile__("msr " #reg ",%0" : : "r" (val))
211
212#else
213/* CP15 operations */
214#define mtcp(rn, v) __asm__ __volatile__(\
215 "mcr " rn "\n"\
216 : : "r" (v)\
217 );
218
219#define mfcp(rn) ({u32 rval = 0U; \
220 __asm__ __volatile__(\
221 "mrc " rn "\n"\
222 : "=r" (rval)\
223 );\
224 rval;\
225 })
226#endif
227
228/************************** Variable Definitions ****************************/
229
230/************************** Function Prototypes *****************************/
231
232#ifdef __cplusplus
233}
234#endif /* __cplusplus */
235
240#endif /* XPSEUDO_ASM_GCC_H */