1 /*
2  * Copyright (c) 2020 Synopsys.
3  * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_
9 #define ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_
10 
11 #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_
12 #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead
13 #endif
14 
15 #ifndef _LINKER
16 #if defined(_ASMLANGUAGE)
17 
18 #include <zephyr/toolchain/common.h>
19 
20 #define FUNC_CODE()
21 #define FUNC_INSTR(a)
22 
23 #ifdef __MW_ASM_RV_MACRO__
24 .macro section_var_mwdt, section, symbol
25 	.section \section().\symbol, "aw"
26 	\symbol :
27 .endm
28 
29 .macro section_func_mwdt, section, symbol
30 	.section \section().\symbol, "ax"
31 	FUNC_CODE()
32 	PERFOPT_ALIGN
33 	\symbol :
34 	FUNC_INSTR(symbol)
35 .endm
36 
37 .macro section_subsec_func_mwdt, section, subsection, symbol
38 	.section \section().\subsection, "ax"
39 	PERFOPT_ALIGN
40 	\symbol :
41 .endm
42 #else
43 .macro section_var_mwdt, section, symbol
44 	.section .\&section\&.\&symbol, "aw"
45 	symbol :
46 .endm
47 
48 .macro section_func_mwdt, section, symbol
49 	.section .\&section\&.\&symbol, "ax"
50 	FUNC_CODE()
51 	PERFOPT_ALIGN
52 	symbol :
53 	FUNC_INSTR(symbol)
54 .endm
55 
56 .macro section_subsec_func_mwdt, section, subsection, symbol
57 	.section .\&section\&.\&subsection, "ax"
58 	PERFOPT_ALIGN
59 	symbol :
60 .endm
61 #endif /* __MW_ASM_RV_MACRO__ */
62 
63 #define SECTION_VAR(sect, sym) section_var_mwdt sect, sym
64 #define SECTION_FUNC(sect, sym) section_func_mwdt sect, sym
65 #define SECTION_SUBSEC_FUNC(sect, subsec, sym) \
66 	section_subsec_func_mwdt sect, subsec, sym
67 
68 #ifdef __MW_ASM_RV_MACRO__
69 .macro glbl_text_mwdt, symbol
70 	.globl \symbol
71 	.type \symbol, @function
72 .endm
73 
74 .macro glbl_data_mwdt, symbol
75 	.globl \symbol
76 	.type \symbol, @object
77 .endm
78 
79 .macro weak_data_mwdt, symbol
80 	.weak \symbol
81 	.type \symbol, @object
82 .endm
83 
84 .macro weak_text_mwdt, symbol
85 	.weak \symbol
86 	.type \symbol, @function
87 .endm
88 #else
89 .macro glbl_text_mwdt, symbol
90 	.globl symbol
91 	.type symbol, @function
92 .endm
93 
94 .macro glbl_data_mwdt, symbol
95 	.globl symbol
96 	.type symbol, @object
97 .endm
98 
99 .macro weak_data_mwdt, symbol
100 	.weak symbol
101 	.type symbol, @object
102 .endm
103 
104 .macro weak_text_mwdt, symbol
105 	.weak symbol
106 	.type symbol, @function
107 .endm
108 #endif /* __MW_ASM_RV_MACRO__ */
109 
110 #define GTEXT(sym) glbl_text_mwdt sym
111 #define GDATA(sym) glbl_data_mwdt sym
112 #define WDATA(sym) weak_data_mwdt sym
113 #define WTEXT(sym) weak_text_mwdt sym
114 
115 #else /* defined(_ASMLANGUAGE) */
116 
117 #ifdef CONFIG_NEWLIB_LIBC
118   #error "ARC MWDT doesn't support building with CONFIG_NEWLIB_LIBC as it doesn't have newlib"
119 #endif /* CONFIG_NEWLIB_LIBC */
120 
121 #ifdef CONFIG_NATIVE_APPLICATION
122   #error "ARC MWDT doesn't support building Zephyr as an native application"
123 #endif /* CONFIG_NATIVE_APPLICATION */
124 
125 
126 #define __no_optimization __attribute__((optnone))
127 #define __fallthrough     __attribute__((fallthrough))
128 
129 #define TOOLCHAIN_HAS_C_GENERIC                 1
130 #define TOOLCHAIN_HAS_C_AUTO_TYPE               1
131 
132 #include <zephyr/toolchain/gcc.h>
133 
134 #undef BUILD_ASSERT
135 #if defined(__cplusplus) && (__cplusplus >= 201103L)
136 #define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG)
137 #elif defined(__cplusplus)
138 /* For cpp98 */
139 #define BUILD_ASSERT(EXPR, MSG...)
140 #else
141 #define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
142 #endif
143 
144 #define __builtin_arc_nop()	_nop()
145 
146 #endif /* _ASMLANGUAGE */
147 
148 #endif /* !_LINKER */
149 #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_ */
150