along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-/* Note to future editors: VxWorks is mostly an EABI target.  We do
-   not use rs6000/eabi.h because we would have to override most of
-   it anyway.  However, if you change that file, consider making
-   analogous changes here too.  */
+/* The port comes in two very different flavors at this stage:
+
+   - For 653 (AE) and regular versions prior to VxWorks 7, the port
+     comes with its own set of definitions, matching a system compiler
+     configured this way as well as the corresponding run-time
+     environment.  This is essentially an eabi system, so changes to
+     eabi.h should usually be reflected here.
+
+   - Starting with VxWorks 7 (post SR600), the system environment
+     was made extremely similar to GNU/Linux and this toolchain is
+     built on top of the corresponding header files.  */
+
+/*-------------------------------------------------------------*/
+/* Common definitions first.                                   */
+/*-------------------------------------------------------------*/
 
 /* CPP predefined macros.  */
 
     }          \
   while (0)
 
-/* vx6 library path.  */
-#if !TARGET_VXWORKS7
-#undef  STARTFILE_PREFIX_SPEC
-#define STARTFILE_PREFIX_SPEC                                          \
- "%{mrtp:%{!shared:%:getenv(WIND_BASE /target/lib/usr/lib/ppc/PPC32/common)}}"
+/* Specific CPU macro definitions expected by the system headers,
+   inferred from -mcpu requests by the user.  Different versions of
+   VxWorks expect different forms of macros, such as
+
+   -D_VX_CPU=_VX_PPC403 on Vx7 and some variants of Vx6,
+   -DCPU=PPC403 on all Vx6 and earlier.  */
+
+#if TARGET_VXWORKS7
+#define VX_CPU_PREFIX "_VX_"
+#else
+#define VX_CPU_PREFIX ""
 #endif
 
-/* Only big endian PPC is supported by VxWorks.  */
-#undef BYTES_BIG_ENDIAN
-#define BYTES_BIG_ENDIAN 1
-#undef WORDS_BIG_ENDIAN
-#define WORDS_BIG_ENDIAN 1
+#define VX_CPUDEF(CPUID) \
+  ":-D" VX_CPU_PREFIX "CPU=" VX_CPU_PREFIX #CPUID
 
-/* We have to kill off the entire specs set created by rs6000/sysv4.h
-   and substitute our own set.  The top level vxworks.h has done some
-   of this for us.  */
+#define VX_MCPU(CPU,CPUID) \
+  "mcpu=" #CPU VX_CPUDEF(CPUID)
 
-#undef SUBTARGET_EXTRA_SPECS
 #undef CPP_SPEC
-#undef CC1_SPEC
-#undef ASM_SPEC
-
-#define SUBTARGET_EXTRA_SPECS /* none needed */
+#define CPP_SPEC                       \
+  "%{!D" VX_CPU_PREFIX "CPU=*:%{"      \
+  VX_MCPU(403, PPC403)   ";"           \
+  VX_MCPU(405, PPC405)   ";"           \
+  VX_MCPU(440, PPC440)   ";"           \
+  VX_MCPU(464, PPC464)   ";"           \
+  VX_MCPU(476, PPC476)   ";"           \
+  VX_MCPU(603, PPC603)   ";"           \
+  VX_MCPU(604, PPC604)   ";"           \
+  VX_MCPU(860, PPC860)   ";"           \
+  VX_MCPU(e6500, E6500)  ";"           \
+  VX_MCPU(8540, PPC85XX) ";"           \
+  VX_MCPU(8548, PPC85XX) ";"           \
+  VX_CPUDEF(PPC604)                    \
+  "}}"                                 \
+  VXWORKS_ADDITIONAL_CPP_SPEC
 
 /* FIXME: The only reason we allow no -mcpu switch at all is because
-   config-ml.in insists on a "." multilib. */
-#define CPP_SPEC \
-"%{!DCPU=*:              \
-   %{mcpu=403 : -DCPU=PPC403  ; \
-     mcpu=405 : -DCPU=PPC405  ; \
-     mcpu=440 : -DCPU=PPC440  ; \
-     mcpu=464 : -DCPU=PPC464  ; \
-     mcpu=476 : -DCPU=PPC476  ; \
-     mcpu=603 : -DCPU=PPC603  ; \
-     mcpu=604 : -DCPU=PPC604  ; \
-     mcpu=860 : -DCPU=PPC860  ; \
-     mcpu=8540: -DCPU=PPC85XX ; \
-     mcpu=8548: -DCPU=PPC85XX ; \
-              : -DCPU=PPC604  }}" \
-VXWORKS_ADDITIONAL_CPP_SPEC
-
-#define CC1_SPEC                                               \
-"%{G*} %{mno-sdata:-msdata=none} %{msdata:-msdata=default}     \
- %{mlittle|mlittle-endian:-mstrict-align}"
-
-#define ASM_SPEC \
-"%(asm_cpu) \
- %{,assembler|,assembler-with-cpp: %{mregnames} %{mno-regnames}} \
- %{mrelocatable} %{mrelocatable-lib} %{" FPIC_SPEC ":-K PIC} -mbig"
+   config-ml.in insists on a "." multilib.  */
 
 #undef  LIB_SPEC
 #define LIB_SPEC VXWORKS_LIB_SPEC
 
-/* For RTPs, leverage linker relaxation.  This helps programs referring
-   to, typically, kernel services too far away for short calls.  This is more
-   precise than -mlongcall and can be overriden with -Wl,--no-relax.  */
-#define VXWORKS_RELAX_LINK_SPEC "%{mrtp:--relax}"
-
-#undef  LINK_SPEC
-#define LINK_SPEC VXWORKS_LINK_SPEC " " VXWORKS_RELAX_LINK_SPEC
-
 #undef  STARTFILE_SPEC
 #define STARTFILE_SPEC VXWORKS_STARTFILE_SPEC
+
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC VXWORKS_ENDFILE_SPEC
 
 /* There is no default multilib.  */
 #undef MULTILIB_DEFAULTS
 
-#undef TARGET_DEFAULT
-#define TARGET_DEFAULT (MASK_EABI | MASK_STRICT_ALIGN)
+/* No _mcount profiling on VxWorks.  */
+#undef FUNCTION_PROFILER
+#define FUNCTION_PROFILER(FILE,LABELNO) VXWORKS_FUNCTION_PROFILER(FILE,LABELNO)
 
-#undef PROCESSOR_DEFAULT
-#define PROCESSOR_DEFAULT PROCESSOR_PPC604
+/* Initialize library function table.  */
+#undef TARGET_INIT_LIBFUNCS
+#define TARGET_INIT_LIBFUNCS rs6000_vxworks_init_libfuncs
 
 /* Nor sdata, for kernel mode.  We use this in
    SUBSUBTARGET_INITIALIZE_OPTIONS, after rs6000_rtp has been initialized.  */
 #undef SDATA_DEFAULT_SIZE
 #define SDATA_DEFAULT_SIZE (TARGET_VXWORKS_RTP ? 8 : 0)
 
-/* Enforce 16-byte alignment for the stack pointer, to permit general
-   compliance with e.g. Altivec instructions requirements.  Make sure
-   this isn't overruled by the EABI constraints.  */
+#undef SUB3TARGET_OVERRIDE_OPTIONS
+#define SUB3TARGET_OVERRIDE_OPTIONS           \
+  do {                                          \
+  if (!global_options_set.x_g_switch_value)     \
+    g_switch_value = SDATA_DEFAULT_SIZE;        \
+  VXWORKS_OVERRIDE_OPTIONS;                     \
+  } while (0)
 
-#undef  STACK_BOUNDARY
-#define STACK_BOUNDARY (16*BITS_PER_UNIT)
+/* The stack pointer need not be moved while checking the stack.  */
+#undef STACK_CHECK_MOVING_SP
 
-#undef  PREFERRED_STACK_BOUNDARY
-#define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
+/* Define this to be nonzero if static stack checking is supported.  */
+#define STACK_CHECK_STATIC_BUILTIN 1
 
-#undef  ABI_STACK_BOUNDARY
+/* Room needed to allow exception propagation, from what experiments
+   and low level observations taught us ...  */
+#define STACK_CHECK_PROTECT (TARGET_64BIT ? 16 * 1024 : 12 * 1024)
+
+/* Leverage linker relaxation for RTPs.  This helps 32bit programs
+   referring to kernel services too far away for short calls, is more
+   precise than -mlongcall and can be overriden with -Wl,--no-relax.  */
+#define VXWORKS_RELAX_LINK_SPEC "%{mrtp:--relax}"
+
+/*-------------------------------------------------------------*/
+/* Pre-VxWorks7 configuration.                                 */
+/*-------------------------------------------------------------*/
+
+#if !TARGET_VXWORKS7
 
 #undef RS6000_STARTING_FRAME_OFFSET
 #define RS6000_STARTING_FRAME_OFFSET                                   \
    RS6000_ALIGN (crtl->outgoing_args_size.to_constant ()               \
                 + STACK_POINTER_OFFSET, 16)
 
-#undef SUBSUBTARGET_OVERRIDE_OPTIONS
-#define SUBSUBTARGET_OVERRIDE_OPTIONS          \
-  do {                                         \
-  if (!global_options_set.x_g_switch_value)    \
-    g_switch_value = SDATA_DEFAULT_SIZE;       \
-  VXWORKS_OVERRIDE_OPTIONS;                    \
-  } while (0)
+/* Enforce 16-byte alignment for the stack pointer, to permit general
+   compliance with e.g. Altivec instructions requirements.  Make sure
+   this isn't overruled by the EABI constraints.  */
 
-/* No _mcount profiling on VxWorks.  */
-#undef FUNCTION_PROFILER
-#define FUNCTION_PROFILER(FILE,LABELNO) VXWORKS_FUNCTION_PROFILER(FILE,LABELNO)
+#undef  STACK_BOUNDARY
+#define STACK_BOUNDARY (16*BITS_PER_UNIT)
 
-/* Define this to be nonzero if static stack checking is supported.  */
-#define STACK_CHECK_STATIC_BUILTIN 1
+#undef  PREFERRED_STACK_BOUNDARY
+#define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
+
+#undef  ABI_STACK_BOUNDARY
+
+#undef  STARTFILE_PREFIX_SPEC
+#define STARTFILE_PREFIX_SPEC                                          \
+ "%{mrtp:%{!shared:%:getenv(WIND_BASE /target/lib/usr/lib/ppc/PPC32/common)}}"
+
+/* For aggregates passing, use the same, consistent ABI as Linux.  */
+#define AGGREGATE_PADDING_FIXED 0
+#define AGGREGATES_PAD_UPWARD_ALWAYS 0
+
+#undef ASM_SPEC
+#define ASM_SPEC \
+"%(asm_cpu) \
+ %{,assembler|,assembler-with-cpp: %{mregnames} %{mno-regnames}} \
+ %{mrelocatable} %{mrelocatable-lib} %{" FPIC_SPEC ":-K PIC} -mbig"
+
+#undef CC1_SPEC
+#define CC1_SPEC VXWORKS_CC1_SPEC " \
+  %{G*} %{mno-sdata:-msdata=none} %{msdata:-msdata=default}      \
+ %{mlittle|mlittle-endian:-mstrict-align}"
+
+#undef  LINK_SPEC
+#define LINK_SPEC VXWORKS_LINK_SPEC " " VXWORKS_RELAX_LINK_SPEC
+
+#undef TARGET_DEFAULT
+#define TARGET_DEFAULT (MASK_EABI | MASK_STRICT_ALIGN)
+
+#undef PROCESSOR_DEFAULT
+#define PROCESSOR_DEFAULT PROCESSOR_PPC604
+
+/* Only big endian PPC is supported by VxWorks.  */
+#undef BYTES_BIG_ENDIAN
+#define BYTES_BIG_ENDIAN 1
+
+#undef WORDS_BIG_ENDIAN
+#define WORDS_BIG_ENDIAN 1
+
+#undef SUBTARGET_EXTRA_SPECS
+#define SUBTARGET_EXTRA_SPECS /* none needed */
+
+#else /* TARGET_VXWORKS7 */
+
+/*-------------------------------------------------------------*/
+/* Post-VxWorks7 (SR600) configuration.                        */
+/*-------------------------------------------------------------*/
+
+/* VxWorks does not use local symbols for the function entry point.  */
+#undef DOT_SYMBOLS
+#define DOT_SYMBOLS 0
+
+#undef LINK_OS_VXWORKS_SPEC
+#define LINK_OS_VXWORKS_SPEC \
+  " %{!mrtp:-r} %{mrtp:-q -static} %{!Xbind-lazy:-z now}"
+
+#undef LINK_OS_EXTRA_SPEC32
+#define LINK_OS_EXTRA_SPEC32 LINK_OS_VXWORKS_SPEC " " VXWORKS_RELAX_LINK_SPEC
+
+#undef LINK_OS_EXTRA_SPEC64
+#define LINK_OS_EXTRA_SPEC64 LINK_OS_VXWORKS_SPEC
+
+/* linux64.h enables this, not supported in vxWorks.  */
+#undef TARGET_FLOAT128_ENABLE_TYPE
+#define TARGET_FLOAT128_ENABLE_TYPE 0
+
+#endif /* TARGET_VXWORKS7 */
 
-/* This platform supports the probing method of stack checking (RTP mode).
-   8K is reserved in the stack to propagate exceptions in case of overflow.  */
-#define STACK_CHECK_PROTECT 8192