This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH] linux support for SH


On Aug 29, 2000, kaz Kojima <kkojima@rr.iij4u.or.jp> wrote:

> Here's a patch to support a new sh-unknown-linux-gnu target for Hitachi
> SH processors. This is a patch for (current cvs tree + our PIC patch).

And here's the patch for GNU/Linux/SH that we currently have at Red
Hat.  Ok to install?

> 	Changes for "fpscr_values" (place it at .data)

What's the point of doing this?

In fact, now that you mention it, I recall Joern gave an interesting
idea: we could have fpscr_values be in a fixed (low) position in
virtual memory, set up by the kernel, so that we could avoid all the
hassle of PIC addressing when referring to it.


Index: gcc/ChangeLog
from  Niibe Yutaka  <gniibe@m17n.org>, Kaz Kojima  <kkojima@rr.iij4u.or.jp>, Alexandre Oliva  <aoliva@redhat.com>

	* configure.in (sh-*-linux*): Added.
	* configure: Rebuilt.
	* config/sh/t-linux: New file.
	* config/sh/sh.h (USERMODE_BIT): Define.
	(TARGET_USERMODE): Likewise.
	(TARGET_SWITCHES): New switches for the bits above.
	(INITIALIZE_TRAMPOLINE): Call __ic_invalidate in USERMODE.
	* config/sh/linux.h: New file.
	* config/sh/lib1funcs.asm (GLOBAL): Don't prefix symbols with
	underscore on linux.
	(L_sdivsi3, L_udivsi3): Define for linux.
	(L_ic_invalidate): Define.
	* invoke.texi (SH Options): Document -musermode.

Index: gcc/configure.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/configure.in,v
retrieving revision 1.413
diff -u -p -r1.413 configure.in
--- gcc/configure.in	2000/09/02 03:28:46	1.413
+++ gcc/configure.in	2000/09/02 06:00:36
@@ -3358,6 +3358,16 @@ changequote([,])dnl
 		tm_file="sh/sh.h sh/rtems.h"
 		float_format=sh
 		;;
+	sh-*-linux*)
+		tm_file="sh/sh.h sh/elf.h sh/linux.h"
+		tmake_file="sh/t-sh sh/t-elf sh/t-linux"
+		xmake_file=x-linux
+		gas=yes gnu_ld=yes
+ 		if test x$enable_threads = xyes; then
+ 			thread_file='posix'
+ 		fi
+		float_format=sh
+		;;
 	sh-*-*)
 		float_format=sh
 		;;
Index: gcc/invoke.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/invoke.texi,v
retrieving revision 1.213
diff -u -p -r1.213 invoke.texi
--- gcc/invoke.texi	2000/09/02 03:28:47	1.213
+++ gcc/invoke.texi	2000/09/02 06:00:40
@@ -419,6 +419,7 @@ in the following sections.
 -mbigtable  -mfmovd  -mhitachi  -mnomacsave
 -misize  -mpadstruct  -mspace
 -mprefergot
+-musermode
 
 @emph{System V Options}
 -Qy  -Qn  -YP,@var{paths}  -Ym,@var{dir}
@@ -6718,6 +6719,12 @@ Optimize for space instead of speed.  Im
 @item -mprefergot
 When generating position-independent code, emit function calls using
 the Global Offset Table instead of the Procedure Linkage Table.
+
+@item -musermode
+Generate a library function call to invalidate instruction cache
+entries, after fixing up a trampoline.  This library function call
+doesn't assume it can write to the whole memory address space.  This
+is the default when the target is @code{sh-*-linux*}.
 @end table
 
 @node System V Options
Index: gcc/config/sh/t-linux
===================================================================
RCS file: t-linux
diff -N t-linux
--- gcc/config/sh/t-linux	Tue May  5 13:32:27 1998
+++ gcc/config/sh/t-linux	Fri Sep  1 23:00:40 2000
@@ -0,0 +1,11 @@
+TARGET_LIBGCC2_CFLAGS = -fpic
+LIBGCC1 = libgcc1-asm.a
+LIB1ASMFUNCS = _ashiftrt _ashiftrt_n _ashiftlt _lshiftrt _movstr \
+  _movstr_i4 _mulsi3 _sdivsi3 _sdivsi3_i4 _udivsi3 _udivsi3_i4 _set_fpscr \
+  _ic_invalidate
+
+MULTILIB_OPTIONS= mb m3e/m4
+MULTILIB_DIRNAMES= 
+MULTILIB_MATCHES = 
+
+EXTRA_MULTILIB_PARTS= crtbegin.o crtend.o crtbeginS.o crtendS.o
Index: gcc/config/sh/sh.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/sh/sh.h,v
retrieving revision 1.68
diff -u -p -r1.68 sh.h
--- gcc/config/sh/sh.h	2000/09/02 03:28:47	1.68
+++ gcc/config/sh/sh.h	2000/09/02 06:00:40
@@ -109,6 +109,7 @@ extern int target_flags;
 #define SPACE_BIT 	(1<<13)
 #define BIGTABLE_BIT  	(1<<14)
 #define RELAX_BIT	(1<<15)
+#define USERMODE_BIT	(1<<16)
 #define HITACHI_BIT     (1<<22)
 #define NOMACSAVE_BIT   (1<<23)
 #define PREFERGOT_BIT	(1<<24)
@@ -184,6 +185,9 @@ extern int target_flags;
 /* Nonzero if generating code for a little endian SH.  */
 #define TARGET_LITTLE_ENDIAN     (target_flags & LITTLE_ENDIAN_BIT)
 
+/* Nonzero if we should do everything in userland.  */
+#define TARGET_USERMODE		(target_flags & USERMODE_BIT)
+
 /* Nonzero if we should prefer @GOT calls when generating PIC.  */
 #define TARGET_PREFERGOT	(target_flags & PREFERGOT_BIT)
 
@@ -210,6 +214,7 @@ extern int target_flags;
   {"prefergot",	PREFERGOT_BIT},			\
   {"relax",	RELAX_BIT},			\
   {"space", 	SPACE_BIT},			\
+  {"usermode",	USERMODE_BIT},			\
   SUBTARGET_SWITCHES                            \
   {"",   	TARGET_DEFAULT} 		\
 }
@@ -1201,6 +1206,13 @@ extern int current_function_anonymous_ar
   emit_move_insn (gen_rtx_MEM (SImode, plus_constant ((TRAMP), 12)),	\
 		  (FNADDR));						\
   if (TARGET_HARVARD)							\
+    {									\
+      if (TARGET_USERMODE)						\
+	emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__ic_invalidate"),\
+			   0, VOIDmode, 1, (TRAMP), SImode);		\
+      else								\
+	emit_insn (gen_ic_invalidate_line (TRAMP));			\
+    }									\
     emit_insn (gen_ic_invalidate_line (TRAMP));				\
 }
 
Index: gcc/config/sh/linux.h
===================================================================
RCS file: linux.h
diff -N linux.h
--- gcc/config/sh/linux.h	Tue May  5 13:32:27 1998
+++ gcc/config/sh/linux.h	Fri Sep  1 23:00:41 2000
@@ -0,0 +1,90 @@
+/* Definitions for SH running Linux-based GNU systems using ELF
+   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+   Contributed by Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* Run-time Target Specification.  */
+#undef TARGET_VERSION
+#define TARGET_VERSION  fputs (" (SH GNU/Linux with ELF)", stderr);
+
+/* Return to the original ELF way.  */
+#undef USER_LABEL_PREFIX
+#define USER_LABEL_PREFIX ""
+
+#undef SIZE_TYPE
+#define SIZE_TYPE "unsigned int"
+ 
+#undef PTRDIFF_TYPE
+#define PTRDIFF_TYPE "int"
+  
+#undef WCHAR_TYPE
+#define WCHAR_TYPE "long int"
+   
+#undef WCHAR_TYPE_SIZE
+#define WCHAR_TYPE_SIZE BITS_PER_WORD
+
+#undef CPP_SPEC
+#define CPP_SPEC \
+  "%{mb:-D__BIG_ENDIAN__} \
+   %{!mb:-D__LITTLE_ENDIAN__} \
+   %{m3e:-D__SH3E__} \
+   %{m4:-D__SH4__} \
+   %{!m3e:%{!m4:-D__SH3__ -D__sh3__}} \
+   %{fPIC:-D__PIC__ -D__pic__} \
+   %{fpic:-D__PIC__ -D__pic__} \
+   %{posix:-D_POSIX_SOURCE} \
+   %{pthread:-D_REENTRANT -D_PTHREADS}"
+
+#undef CPP_PREDEFINES
+#define CPP_PREDEFINES "-D__ELF__ -Dunix -D__sh__ -Dlinux -Asystem(posix)"
+
+#undef ASM_SPEC
+#define ASM_SPEC  "%{!mb:-little} %{mrelax:-relax}"
+
+#undef CC1_SPEC
+#define CC1_SPEC \
+  "-musermode %{!mb:-ml} %{!m3e:%{!m4:-m3}}"
+
+#undef CC1PLUS_SPEC
+#define CC1PLUS_SPEC \
+  "-musermode %{!mb:-ml} %{!m3e:%{!m4:-m3}}"
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+  "%{!mb:-m shlelf_linux} %{mrelax:-relax} \
+   %{shared:-shared} \
+   %{!static: \
+     %{rdynamic:-export-dynamic} \
+     %{!dynamic-linker:-dynamic-linker /lib/ld.so.1} \
+     %{!rpath:-rpath /lib}} \
+   %{static:-static}"
+
+#undef LIB_SPEC
+#define LIB_SPEC \
+  "%{shared: -lc} \
+   %{!shared: %{pthread:-lthread} \
+     %{profile:-lc_p} %{!profile: -lc}}"
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC \
+  "%{!shared: \
+     %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \
+		       %{!p:%{profile:gcrt1.o%s} \
+			 %{!profile:crt1.o%s}}}} \
+   crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}"
Index: gcc/config/sh/lib1funcs.asm
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/sh/lib1funcs.asm,v
retrieving revision 1.12
diff -u -p -r1.12 lib1funcs.asm
--- gcc/config/sh/lib1funcs.asm	2000/08/16 21:17:40	1.12
+++ gcc/config/sh/lib1funcs.asm	2000/09/02 06:00:41
@@ -42,6 +42,10 @@ Boston, MA 02111-1307, USA.  */
 #define LOCAL(X) L_##X
 #endif
 
+#ifdef __linux__
+#define GLOBAL(X) __##X
+#endif
+
 #ifndef GLOBAL
 #define GLOBAL(X) ___##X
 #endif
@@ -903,7 +907,7 @@ GLOBAL(sdivsi3_i4):
 #ifdef L_sdivsi3
 /* __SH4_SINGLE_ONLY__ keeps this part for link compatibility with
    sh3e code.  */
-#if ! defined(__SH4__) && ! defined (__SH4_SINGLE__)
+#if (! defined(__SH4__) && ! defined (__SH4_SINGLE__)) || defined (__linux__)
 !!
 !! Steve Chamberlain
 !! sac@cygnus.com
@@ -1105,7 +1109,7 @@ L1:
 #ifdef L_udivsi3
 /* __SH4_SINGLE_ONLY__ keeps this part for link compatibility with
    sh3e code.  */
-#if ! defined(__SH4__) && ! defined (__SH4_SINGLE__)
+#if (! defined(__SH4__) && ! defined (__SH4_SINGLE__)) || defined (__linux__)
 !!
 !! Steve Chamberlain
 !! sac@cygnus.com
@@ -1207,3 +1211,25 @@ LOCAL(set_fpscr_L1):
 #endif /* ELF */
 #endif /* SH3E / SH4 */
 #endif /* L_set_fpscr */
+#ifdef L_ic_invalidate
+#if defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
+	.global GLOBAL(ic_invalidate)
+GLOBAL(ic_invalidate):
+	ocbwb	@r4
+	mova	0f,r0
+	mov.w	1f,r1
+	sub	r0,r4
+	and	r1,r4
+	add	#4,r4
+	braf	r4
+	nop
+1:
+	.short	0x1fe0
+	nop
+0:
+	.rept	2048
+	rts
+	nop
+	.endr
+#endif /* SH4 */
+#endif /* L_ic_invalidate */

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]