777d477db78caeb47c4569e77a55e5366c915782
[processor-sdk/open-amp.git] / libs / system / zynqmp_r5 / generic / xil_standalone_lib / xpseudo_asm_gcc.h
1 /******************************************************************************
2 *
3 * Copyright (C) 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 THE
22 * XILINX CONSORTIUM 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/29/14 First release
46 * </pre>
47 *
48 ******************************************************************************/
50 #ifndef XPSEUDO_ASM_GCC_H /* prevent circular inclusions */
51 #define XPSEUDO_ASM_GCC_H /* by using protection macros */
53 /***************************** Include Files ********************************/
55 #include "xil_types.h"
56 #ifdef __cplusplus
57 extern "C" {
58 #endif /* __cplusplus */
60 /************************** Constant Definitions ****************************/
62 /**************************** Type Definitions ******************************/
64 /***************** Macros (Inline Functions) Definitions ********************/
66 /* necessary for pre-processor */
67 #define stringify(s) tostring(s)
68 #define tostring(s) #s
70 /* pseudo assembler instructions */
71 #define mfcpsr() ({u32 rval; \
72 __asm__ __volatile__(\
73 "mrs %0, cpsr\n"\
74 : "=r" (rval)\
75 );\
76 rval;\
77 })
79 #define mtcpsr(v) __asm__ __volatile__(\
80 "msr cpsr,%0\n"\
81 : : "r" (v)\
82 )
84 #define cpsiei() __asm__ __volatile__("cpsie i\n")
85 #define cpsidi() __asm__ __volatile__("cpsid i\n")
87 #define cpsief() __asm__ __volatile__("cpsie f\n")
88 #define cpsidf() __asm__ __volatile__("cpsid f\n")
92 #define mtgpr(rn, v) __asm__ __volatile__(\
93 "mov r" stringify(rn) ", %0 \n"\
94 : : "r" (v)\
95 )
97 #define mfgpr(rn) ({u32 rval; \
98 __asm__ __volatile__(\
99 "mov %0,r" stringify(rn) "\n"\
100 : "=r" (rval)\
101 );\
102 rval;\
103 })
105 /* memory synchronization operations */
107 /* Instruction Synchronization Barrier */
108 #define isb() __asm__ __volatile__ ("isb" : : : "memory")
110 /* Data Synchronization Barrier */
111 #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
113 /* Data Memory Barrier */
114 #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
117 /* Memory Operations */
118 #define ldr(adr) ({u32 rval; \
119 __asm__ __volatile__(\
120 "ldr %0,[%1]"\
121 : "=r" (rval) : "r" (adr)\
122 );\
123 rval;\
124 })
126 #define ldrb(adr) ({u8 rval; \
127 __asm__ __volatile__(\
128 "ldrb %0,[%1]"\
129 : "=r" (rval) : "r" (adr)\
130 );\
131 rval;\
132 })
134 #define str(adr, val) __asm__ __volatile__(\
135 "str %0,[%1]\n"\
136 : : "r" (val), "r" (adr)\
137 )
139 #define strb(adr, val) __asm__ __volatile__(\
140 "strb %0,[%1]\n"\
141 : : "r" (val), "r" (adr)\
142 )
144 /* Count leading zeroes (clz) */
145 #define clz(arg) ({u8 rval; \
146 __asm__ __volatile__(\
147 "clz %0,%1"\
148 : "=r" (rval) : "r" (arg)\
149 );\
150 rval;\
151 })
153 /* CP15 operations */
154 #define mtcp(rn, v) __asm__ __volatile__(\
155 "mcr " rn "\n"\
156 : : "r" (v)\
157 );
159 #define mfcp(rn) ({u32 rval; \
160 __asm__ __volatile__(\
161 "mrc " rn "\n"\
162 : "=r" (rval)\
163 );\
164 rval;\
165 })
167 /************************** Variable Definitions ****************************/
169 /************************** Function Prototypes *****************************/
171 #ifdef __cplusplus
172 }
173 #endif /* __cplusplus */
175 #endif /* XPSEUDO_ASM_GCC_H */