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 _LINKER
12 #if defined(_ASMLANGUAGE)
13 
14 #include <zephyr/toolchain/common.h>
15 
16 #define FUNC_CODE()
17 #define FUNC_INSTR(a)
18 
19 .macro section_var_mwdt, section, symbol
20 	.section .\&section\&.\&symbol, "aw"
21 	symbol :
22 .endm
23 
24 .macro section_func_mwdt, section, symbol
25 	.section .\&section\&.\&symbol, "ax"
26 	FUNC_CODE()
27 	PERFOPT_ALIGN
28 	symbol :
29 	FUNC_INSTR(symbol)
30 .endm
31 
32 .macro section_subsec_func_mwdt, section, subsection, symbol
33 	.section .\&section\&.\&subsection, "ax"
34 	PERFOPT_ALIGN
35 	symbol :
36 .endm
37 
38 #define SECTION_VAR(sect, sym) section_var_mwdt sect, sym
39 #define SECTION_FUNC(sect, sym) section_func_mwdt sect, sym
40 #define SECTION_SUBSEC_FUNC(sect, subsec, sym) \
41 	section_subsec_func_mwdt sect, subsec, sym
42 
43 .macro glbl_text_mwdt, symbol
44 	.globl symbol
45 	.type symbol, @function
46 .endm
47 
48 .macro glbl_data_mwdt, symbol
49 	.globl symbol
50 	.type symbol, @object
51 .endm
52 
53 .macro weak_data_mwdt, symbol
54 	.weak symbol
55 	.type symbol, @object
56 .endm
57 
58 #define GTEXT(sym) glbl_text_mwdt sym
59 #define GDATA(sym) glbl_data_mwdt sym
60 #define WDATA(sym) weak_data_mwdt sym
61 
62 #else /* defined(_ASMLANGUAGE) */
63 
64 /* MWDT toolchain misses ssize_t definition which is used by Zephyr */
65 #ifndef _SSIZE_T_DEFINED
66 #define _SSIZE_T_DEFINED
67 #ifdef CONFIG_64BIT
68 	typedef long ssize_t;
69 #else
70 	typedef int ssize_t;
71 #endif
72 #endif /* _SSIZE_T_DEFINED */
73 
74 #ifdef CONFIG_NEWLIB_LIBC
75   #error "ARC MWDT doesn't support building with CONFIG_NEWLIB_LIBC as it doesn't have newlib"
76 #endif /* CONFIG_NEWLIB_LIBC */
77 
78 #ifdef CONFIG_NATIVE_APPLICATION
79   #error "ARC MWDT doesn't support building Zephyr as an native application"
80 #endif /* CONFIG_NATIVE_APPLICATION */
81 
82 
83 #define __no_optimization __attribute__((optnone))
84 #define __fallthrough     __attribute__((fallthrough))
85 
86 #define TOOLCHAIN_HAS_C_GENERIC                 1
87 #define TOOLCHAIN_HAS_C_AUTO_TYPE               1
88 
89 #include <zephyr/toolchain/gcc.h>
90 
91 #undef BUILD_ASSERT
92 #if defined(__cplusplus) && (__cplusplus >= 201103L)
93 #define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG)
94 #elif defined(__cplusplus)
95 /* For cpp98 */
96 #define BUILD_ASSERT(EXPR, MSG...)
97 #else
98 #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
99 #endif
100 
101 #define __builtin_arc_nop()	_nop()
102 
103 #endif /* _ASMLANGUAGE */
104 
105 #endif /* !_LINKER */
106 #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_ */
107