1/* Definitions for PowerPC running FreeBSD using the ELF format 2 Copyright (C) 2001, 2003 Free Software Foundation, Inc. 3 Contributed by David E. O'Brien <obrien@FreeBSD.org> and BSDi. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published 9 by the Free Software Foundation; either version 2, or (at your 10 option) any later version. 11 12 GCC is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15 License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GCC; see the file COPYING. If not, write to the 19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 20 MA 02110-1301, USA. */ 21 22/* Override the defaults, which exist to force the proper definition. */ 23 24#ifdef IN_LIBGCC2 25#undef TARGET_64BIT 26#ifdef __powerpc64__ 27#define TARGET_64BIT 1 28#else 29#define TARGET_64BIT 0 30#endif 31#endif 32 33/* On 64-bit systems, use the AIX ABI like Linux and NetBSD */ 34 35#undef DEFAULT_ABI 36#define DEFAULT_ABI (TARGET_64BIT ? ABI_AIX : ABI_V4) 37#undef TARGET_AIX 38#define TARGET_AIX TARGET_64BIT 39 40#ifdef HAVE_LD_NO_DOT_SYMS 41/* New ABI uses a local sym for the function entry point. */ 42extern int dot_symbols; 43#undef DOT_SYMBOLS 44#define DOT_SYMBOLS dot_symbols 45#endif 46 47#undef FBSD_TARGET_CPU_CPP_BUILTINS 48#define FBSD_TARGET_CPU_CPP_BUILTINS() \ 49 do \ 50 { \ 51 builtin_define ("__PPC__"); \ 52 builtin_define ("__ppc__"); \ 53 builtin_define ("__PowerPC__"); \ 54 builtin_define ("__powerpc__"); \ 55 if (TARGET_64BIT) \ 56 { \ 57 builtin_define ("__LP64__"); \ 58 builtin_define ("__ppc64__"); \ 59 builtin_define ("__powerpc64__"); \ 60 builtin_define ("__arch64__"); \ 61 builtin_assert ("cpu=powerpc64"); \ 62 builtin_assert ("machine=powerpc64"); \ 63 } else { \ 64 builtin_assert ("cpu=powerpc"); \ 65 builtin_assert ("machine=powerpc"); \ 66 } \ 67 } \ 68 while (0) 69 70#define INVALID_64BIT "-m%s not supported in this configuration" 71#define INVALID_32BIT INVALID_64BIT 72 73#undef SUBSUBTARGET_OVERRIDE_OPTIONS 74#define SUBSUBTARGET_OVERRIDE_OPTIONS \ 75 do \ 76 { \ 77 if (!rs6000_explicit_options.alignment) \ 78 rs6000_alignment_flags = MASK_ALIGN_NATURAL; \ 79 if (TARGET_64BIT) \ 80 { \ 81 if (DEFAULT_ABI != ABI_AIX) \ 82 { \ 83 rs6000_current_abi = ABI_AIX; \ 84 error (INVALID_64BIT, "call"); \ 85 } \ 86 dot_symbols = !strcmp (rs6000_abi_name, "aixdesc"); \ 87 if (target_flags & MASK_RELOCATABLE) \ 88 { \ 89 target_flags &= ~MASK_RELOCATABLE; \ 90 error (INVALID_64BIT, "relocatable"); \ 91 } \ 92 if (target_flags & MASK_EABI) \ 93 { \ 94 target_flags &= ~MASK_EABI; \ 95 error (INVALID_64BIT, "eabi"); \ 96 } \ 97 if (target_flags & MASK_PROTOTYPE) \ 98 { \ 99 target_flags &= ~MASK_PROTOTYPE; \ 100 error (INVALID_64BIT, "prototype"); \ 101 } \ 102 if ((target_flags & MASK_POWERPC64) == 0) \ 103 { \ 104 target_flags |= MASK_POWERPC64; \ 105 error ("64 bit CPU required"); \ 106 } \ 107 } \ 108 } \ 109 while (0) 110 111 112#undef STARTFILE_DEFAULT_SPEC 113#define STARTFILE_DEFAULT_SPEC "%(startfile_freebsd)" 114 115#undef ENDFILE_DEFAULT_SPEC 116#define ENDFILE_DEFAULT_SPEC "%(endfile_freebsd)" 117 118#undef LIB_DEFAULT_SPEC 119#define LIB_DEFAULT_SPEC "%(lib_freebsd)" 120 121#undef LINK_START_DEFAULT_SPEC 122#define LINK_START_DEFAULT_SPEC "%(link_start_freebsd)" 123 124#undef LINK_OS_DEFAULT_SPEC 125#define LINK_OS_DEFAULT_SPEC "%(link_os_freebsd)" 126 127/* XXX: This is wrong for many platforms in sysv4.h. 128 We should work on getting that definition fixed. */ 129#undef LINK_SHLIB_SPEC 130#define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}}" 131 132 133/************************[ Target stuff ]***********************************/ 134 135/* Define the actual types of some ANSI-mandated types. 136 Needs to agree with <machine/ansi.h>. GCC defaults come from c-decl.c, 137 c-common.c, and config/<arch>/<arch>.h. */ 138 139#undef SIZE_TYPE 140#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int") 141 142#undef PTRDIFF_TYPE 143#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") 144 145/* rs6000.h gets this wrong for FreeBSD. We use the GCC defaults instead. */ 146#undef WCHAR_TYPE 147 148#undef WCHAR_TYPE_SIZE 149#define WCHAR_TYPE_SIZE 32 150 151#undef TARGET_VERSION 152#define TARGET_VERSION fprintf (stderr, " (FreeBSD/PowerPC ELF)"); 153 154/* Override rs6000.h definition. */ 155#undef ASM_APP_ON 156#define ASM_APP_ON "#APP\n" 157 158/* Override rs6000.h definition. */ 159#undef ASM_APP_OFF 160#define ASM_APP_OFF "#NO_APP\n" 161 162/* Tell the assembler we want 32/64-bit binaries if -m32 or -m64 is passed */ 163#if (TARGET_DEFAULT & MASK_64BIT) 164#define SVR4_ASM_SPEC "%(asm_cpu) \ 165%{.s: %{mregnames} %{mno-regnames}} %{.S: %{mregnames} %{mno-regnames}} \ 166%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*} \ 167%{mrelocatable} %{mrelocatable-lib} %{fpic|fpie|fPIC|fPIE:-K PIC} \ 168%{memb|msdata|msdata=eabi: -memb} \ 169%{mlittle|mlittle-endian:-mlittle; \ 170 mbig|mbig-endian :-mbig; \ 171 mcall-aixdesc | \ 172 mcall-freebsd | \ 173 mcall-netbsd | \ 174 mcall-openbsd | \ 175 mcall-linux | \ 176 mcall-gnu :-mbig; \ 177 mcall-i960-old :-mlittle}" 178#define LINK_OS_FREEBSD_SPEC_DEF "\ 179 %{p:%nconsider using `-pg' instead of `-p' with gprof(1)} \ 180 %{v:-V} \ 181 %{assert*} %{R*} %{rpath*} %{defsym*} \ 182 %{shared:-Bshareable %{h*} %{soname*}} \ 183 %{!static:--enable-new-dtags} \ 184 %{!shared: \ 185 %{!static: \ 186 %{rdynamic: -export-dynamic} \ 187 %{!dynamic-linker:-dynamic-linker %(fbsd_dynamic_linker) }} \ 188 %{static:-Bstatic}} \ 189 %{symbolic:-Bsymbolic}" 190 191 192#undef ASM_DEFAULT_SPEC 193#undef ASM_SPEC 194#undef LINK_OS_FREEBSD_SPEC 195#define ASM_DEFAULT_SPEC "-mppc%{!m32:64}" 196#define ASM_SPEC "%{m32:-a32}%{!m32:-a64} " SVR4_ASM_SPEC 197#define LINK_OS_FREEBSD_SPEC "%{m32:-melf32ppc_fbsd}%{!m32:-melf64ppc_fbsd} " LINK_OS_FREEBSD_SPEC_DEF 198#endif 199 200/* _init and _fini functions are built from bits spread across many 201 object files, each potentially with a different TOC pointer. For 202 that reason, place a nop after the call so that the linker can 203 restore the TOC pointer if a TOC adjusting call stub is needed. */ 204#ifdef __powerpc64__ 205#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \ 206 asm (SECTION_OP "\n" \ 207" bl " #FUNC "\n" \ 208" nop\n" \ 209" .previous"); 210#endif 211 212/* __throw will restore its own return address to be the same as the 213 return address of the function that the throw is being made to. 214 This is unfortunate, because we want to check the original 215 return address to see if we need to restore the TOC. 216 So we have to squirrel it away with this. */ 217#define SETUP_FRAME_ADDRESSES() \ 218 do { if (TARGET_64BIT) rs6000_aix_emit_builtin_unwind_init (); } while (0) 219 220/* Select a format to encode pointers in exception handling data. CODE 221 is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is 222 true if the symbol may be affected by dynamic relocations. */ 223#undef ASM_PREFERRED_EH_DATA_FORMAT 224#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ 225 ((TARGET_64BIT || flag_pic || TARGET_RELOCATABLE) \ 226 ? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel \ 227 | (TARGET_64BIT ? DW_EH_PE_udata8 : DW_EH_PE_sdata4)) \ 228 : DW_EH_PE_absptr) 229 230#ifdef __powerpc64__ 231#define MD_FROB_UPDATE_CONTEXT(CTX, FS) \ 232 if ((FS)->regs.reg[2].how == REG_UNSAVED) \ 233 { \ 234 unsigned int *insn = (unsigned int *) \ 235 _Unwind_GetGR ((CTX), LINK_REGISTER_REGNUM); \ 236 if (insn != NULL && *insn == 0xE8410028) \ 237 _Unwind_SetGRPtr ((CTX), 2, (CTX)->cfa + 40); \ 238 } 239#endif 240 241#define TARGET_ASM_FILE_END rs6000_elf_end_indicate_exec_stack 242 243/* FreeBSD doesn't support saving and restoring 64-bit regs with a 32-bit 244 kernel. This is supported when running on a 64-bit kernel with 245 COMPAT_FREEBSD32, but tell GCC it isn't so that our 32-bit binaries 246 are compatible. */ 247#define OS_MISSING_POWERPC64 !TARGET_64BIT 248 249/* Function profiling bits */ 250#undef RS6000_MCOUNT 251#define RS6000_MCOUNT ((TARGET_64BIT) ? "._mcount" : "_mcount") 252#define PROFILE_HOOK(LABEL) \ 253 do { if (TARGET_64BIT) output_profile_hook (LABEL); } while (0) 254 255#undef NEED_INDICATE_EXEC_STACK 256#define NEED_INDICATE_EXEC_STACK 1 257 258/* This is how to declare the size of a function. */ 259#undef ASM_DECLARE_FUNCTION_SIZE 260#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ 261 do \ 262 { \ 263 if (!flag_inhibit_size_directive) \ 264 { \ 265 fputs ("\t.size\t", (FILE)); \ 266 if (TARGET_64BIT && DOT_SYMBOLS) \ 267 putc ('.', (FILE)); \ 268 assemble_name ((FILE), (FNAME)); \ 269 fputs (",.-", (FILE)); \ 270 rs6000_output_function_entry (FILE, FNAME); \ 271 putc ('\n', (FILE)); \ 272 } \ 273 } \ 274 while (0) 275 276