1285612Sdelphij/* Declarations for C-SKY targets running Linux.
2181834Sroberto   Copyright (C) 2018-2020 Free Software Foundation, Inc.
3285612Sdelphij   Contributed by C-SKY Microsystems and Mentor Graphics.
4285612Sdelphij
5181834Sroberto   This file is part of GCC.
6285612Sdelphij
7285612Sdelphij   GCC is free software; you can redistribute it and/or modify it
8285612Sdelphij   under the terms of the GNU General Public License as published
9285612Sdelphij   by the Free Software Foundation; either version 3, or (at your
10285612Sdelphij   option) any later version.
11285612Sdelphij
12285612Sdelphij   GCC is distributed in the hope that it will be useful, but WITHOUT
13285612Sdelphij   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14285612Sdelphij   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15285612Sdelphij   License for more details.
16285612Sdelphij
17285612Sdelphij   You should have received a copy of the GNU General Public License
18285612Sdelphij   along with GCC; see the file COPYING3.  If not see
19285612Sdelphij   <http://www.gnu.org/licenses/>.  */
20285612Sdelphij
21285612Sdelphij/******************************************************************
22285612Sdelphij *		 Run-time Target Specification			  *
23181834Sroberto ******************************************************************/
24285612Sdelphij
25285612Sdelphij#undef STARTFILE_SPEC
26285612Sdelphij#define STARTFILE_SPEC							      \
27285612Sdelphij  "%{!shared: %{pie:Scrt1.o%s;:crt1.o%s}}				      \
28285612Sdelphij  crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
29181834Sroberto
30181834Sroberto#undef ENDFILE_SPEC
31181834Sroberto#define ENDFILE_SPEC \
32181834Sroberto  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
33181834Sroberto
34181834Sroberto#undef CC1_SPEC
35181834Sroberto#define CC1_SPEC  \
36181834Sroberto  "%{EB:-EB}	  \
37181834Sroberto   %{EL:-EL}	  \
38181834Sroberto   %{profile:-p}  \
39181834Sroberto  "
40181834Sroberto
41181834Sroberto#undef ASM_SPEC
42181834Sroberto#define ASM_SPEC		\
43181834Sroberto  "%{mbig-endian:-mbig-endian}	\
44181834Sroberto  %{EB:-EB}			\
45285612Sdelphij  %{EL:-EL}			\
46285612Sdelphij  %{fpic|fPIC:-pic}		\
47285612Sdelphij  %{mcpu=*:-mcpu=%*}		\
48181834Sroberto  %{march=*:-march=%*}		\
49181834Sroberto  %{mhard-float:-mhard-float}	\
50181834Sroberto  %{melrw:-melrw}		\
51181834Sroberto  %{mno-elrw:-mno-elrw}		\
52181834Sroberto  %{mistack:-mistack}		\
53181834Sroberto  %{mno-istack:-mno-istack}	\
54181834Sroberto  %{mmp:-mmp}			\
55181834Sroberto  %{mcp:-mcp}			\
56181834Sroberto  %{mcache:-mcache}		\
57181834Sroberto  %{msecurity|mmac:-msecurity}	\
58181834Sroberto  %{mtrust:-mtrust}		\
59181834Sroberto  %{mdsp:-mdsp}			\
60181834Sroberto  %{medsp:-medsp}		\
61181834Sroberto  %{mvdsp:-mvdsp}		\
62181834Sroberto  "
63181834Sroberto
64181834Sroberto#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-cskyv2%{mhard-float:-hf}%{mbig-endian:-be}.so.1"
65181834Sroberto
66181834Sroberto#define LINUX_TARGET_LINK_SPEC	"%{h*} %{version:-v}		\
67285612Sdelphij   %{b}								\
68285612Sdelphij   %{static:-Bstatic}						\
69285612Sdelphij   %{shared:-shared}						\
70181834Sroberto   %{symbolic:-Bsymbolic}					\
71181834Sroberto   %{!static:							\
72181834Sroberto     %{rdynamic:-export-dynamic}				\
73181834Sroberto     %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}	\
74181834Sroberto   -X								\
75181834Sroberto   %{mbig-endian:-EB} %{mlittle-endian:-EL}			\
76181834Sroberto   %{EB:-EB} %{EL:-EL}"
77181834Sroberto
78181834Sroberto
79181834Sroberto#undef	LINK_SPEC
80181834Sroberto#define LINK_SPEC LINUX_TARGET_LINK_SPEC
81181834Sroberto
82181834Sroberto
83181834Sroberto#undef	LIB_SPEC
84181834Sroberto#define LIB_SPEC \
85181834Sroberto  "%{pthread:-lpthread} -lc %{mccrt:-lcc-rt}"
86181834Sroberto/* FIXME add this to LIB_SPEC when need */
87181834Sroberto/*   %{!shared:%{profile:-lc_p}%{!profile:-lc}}" */
88181834Sroberto
89181834Sroberto#define TARGET_OS_CPP_BUILTINS()	    \
90181834Sroberto  do					    \
91181834Sroberto    {					    \
92181834Sroberto      GNU_USER_TARGET_OS_CPP_BUILTINS ();   \
93181834Sroberto    }					    \
94181834Sroberto  while (0)
95181834Sroberto
96181834Sroberto/* In crtstuff.c to control section in where code resides.
97181834Sroberto   We have to write it as asm code.  */
98181834Sroberto#ifdef __PIC__
99181834Sroberto#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)  \
100181834Sroberto  asm (SECTION_OP "\n"				    \
101181834Sroberto       "\tgrs\tr3, .Lgetpc_"#FUNC"\n\t"		    \
102181834Sroberto       ".Lgetpc_"#FUNC":\n\t"			    \
103181834Sroberto       "\tlrw\tr2,\t.Lgetpc_"#FUNC"@GOTPC\n\t"	    \
104181834Sroberto       "\taddu\tr3, r2\n\t"			    \
105181834Sroberto       "\tlrw\tr2, "#FUNC"@GOTOFF\n\t"		    \
106181834Sroberto       "\taddu\tr2, r3\n\t"			    \
107181834Sroberto       "\tjsr\tr2\n\t");			    \
108181834Sroberto  FORCE_CODE_SECTION_ALIGN			    \
109181834Sroberto  asm (TEXT_SECTION_ASM_OP);
110181834Sroberto#endif
111181834Sroberto
112181834Sroberto#undef CPP_SPEC
113181834Sroberto#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
114181834Sroberto
115181834Sroberto#undef FUNCTION_PROFILER
116181834Sroberto#define SAVE_LR	    \
117181834Sroberto  "push\tlr"
118181834Sroberto#define FUNCTION_PROFILER(file, labelno)		\
119181834Sroberto  fprintf (file, "\t%s\n\tjbsr\t_mcount\n", SAVE_LR);
120181834Sroberto#define NO_PROFILE_COUNTERS 1
121181834Sroberto
122181834Sroberto/* Enable features only for Linux toolchains.  */
123181834Sroberto#define TARGET_CSKY_LINUX 1
124181834Sroberto
125181834Sroberto/* Clear the instruction cache from `BEG' to `END'.  */
126181834Sroberto#define CLEAR_INSN_CACHE(BEG, END)			\
127181834Sroberto  cacheflush (BEG, END-BEG, 3)
128181834Sroberto
129181834Sroberto/* For __clear_cache in libgcc2.c.  The declaration is copied from
130181834Sroberto   <sys/cachectl.h>.  */
131181834Sroberto#ifdef IN_LIBGCC2
132181834Srobertoextern int cacheflush (void *__addr, const int __nbytes, const int __op);
133181834Sroberto#endif
134181834Sroberto