tc-ppc.h revision 77298
160484Sobrien/* tc-ppc.h -- Header file for tc-ppc.c.
260484Sobrien   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000
360484Sobrien   Free Software Foundation, Inc.
460484Sobrien   Written by Ian Lance Taylor, Cygnus Support.
560484Sobrien
660484Sobrien   This file is part of GAS, the GNU Assembler.
760484Sobrien
860484Sobrien   GAS is free software; you can redistribute it and/or modify
960484Sobrien   it under the terms of the GNU General Public License as published by
1060484Sobrien   the Free Software Foundation; either version 2, or (at your option)
1160484Sobrien   any later version.
1260484Sobrien
1360484Sobrien   GAS is distributed in the hope that it will be useful,
1460484Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1560484Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1660484Sobrien   GNU General Public License for more details.
1760484Sobrien
1860484Sobrien   You should have received a copy of the GNU General Public License
1960484Sobrien   along with GAS; see the file COPYING.  If not, write to the Free
2060484Sobrien   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2177298Sobrien   02111-1307, USA.  */
2260484Sobrien
2360484Sobrien#define TC_PPC
2460484Sobrien
2560484Sobrien#ifdef ANSI_PROTOTYPES
2660484Sobrienstruct fix;
2760484Sobrien#endif
2860484Sobrien
2960484Sobrien/* Set the endianness we are using.  Default to big endian.  */
3060484Sobrien#ifndef TARGET_BYTES_BIG_ENDIAN
3160484Sobrien#define TARGET_BYTES_BIG_ENDIAN 1
3260484Sobrien#endif
3360484Sobrien
3460484Sobrien#ifndef BFD_ASSEMBLER
3560484Sobrien #error PowerPC support requires BFD_ASSEMBLER
3660484Sobrien#endif
3760484Sobrien
3860484Sobrien/* If OBJ_COFF is defined, and TE_PE is not defined, we are assembling
3960484Sobrien   XCOFF for AIX or PowerMac.  If TE_PE is defined, we are assembling
4060484Sobrien   COFF for Windows NT.  */
4160484Sobrien
4260484Sobrien#ifdef OBJ_COFF
4360484Sobrien#ifndef TE_PE
4460484Sobrien#define OBJ_XCOFF
4560484Sobrien#endif
4660484Sobrien#endif
4760484Sobrien
4860484Sobrien/* The target BFD architecture.  */
4960484Sobrien#define TARGET_ARCH (ppc_arch ())
5077298Sobrien#define TARGET_MACH (ppc_mach ())
5160484Sobrienextern enum bfd_architecture ppc_arch PARAMS ((void));
5277298Sobrienextern unsigned long ppc_mach PARAMS ((void));
5360484Sobrien
5460484Sobrien/* Whether or not the target is big endian */
5560484Sobrienextern int target_big_endian;
5660484Sobrien
5760484Sobrien/* The target BFD format.  */
5877298Sobrien#define TARGET_FORMAT (ppc_target_format ())
5977298Sobrienextern char* ppc_target_format ();
6060484Sobrien
6160484Sobrien/* Permit temporary numeric labels.  */
6260484Sobrien#define LOCAL_LABELS_FB 1
6360484Sobrien
6460484Sobrien/* $ is used to refer to the current location.  */
6560484Sobrien#define DOLLAR_DOT
6660484Sobrien
6760484Sobrien/* Strings do not use backslash escapes under COFF.  */
6860484Sobrien#ifdef OBJ_COFF
6960484Sobrien#define NO_STRING_ESCAPES
7060484Sobrien#endif
7160484Sobrien
7260484Sobrien#ifdef OBJ_ELF
7360484Sobrien#define DIFF_EXPR_OK		/* foo-. gets turned into PC relative relocs */
7460484Sobrien#endif
7560484Sobrien
7660484Sobrien#if TARGET_BYTES_BIG_ENDIAN
7760484Sobrien#define PPC_BIG_ENDIAN 1
7860484Sobrien#else
7960484Sobrien#define PPC_BIG_ENDIAN 0
8060484Sobrien#endif
8160484Sobrien
8260484Sobrien/* We don't need to handle .word strangely.  */
8360484Sobrien#define WORKING_DOT_WORD
8460484Sobrien
8560484Sobrien/* We set the fx_done field appropriately in md_apply_fix.  */
8660484Sobrien#define TC_HANDLES_FX_DONE
8760484Sobrien
8860484Sobrien#ifdef TE_PE
8960484Sobrien
9060484Sobrien/* Question marks are permitted in symbol names.  */
9160484Sobrien#define LEX_QM 1
9260484Sobrien
9360484Sobrien/* Don't adjust TOC relocs.  */
9460484Sobrien#define tc_fix_adjustable(fixp) ppc_pe_fix_adjustable (fixp)
9560484Sobrienextern int ppc_pe_fix_adjustable PARAMS ((struct fix *));
9660484Sobrien
9760484Sobrien#endif
9860484Sobrien
9960484Sobrien#ifdef OBJ_XCOFF
10060484Sobrien
10160484Sobrien/* Declarations needed when generating XCOFF code.  XCOFF is an
10260484Sobrien   extension of COFF, used only on the RS/6000.  Rather than create an
10360484Sobrien   obj-xcoff, we just use obj-coff, and handle the extensions here in
10460484Sobrien   tc-ppc.  */
10560484Sobrien
10660484Sobrien/* We need to keep some information for symbols.  */
10760484Sobrienstruct ppc_tc_sy
10860484Sobrien{
10960484Sobrien  /* We keep a few linked lists of symbols.  */
11060484Sobrien  symbolS *next;
11160484Sobrien  /* Non-zero if the symbol should be output.  The RS/6000 assembler
11260484Sobrien     only outputs symbols that are external or are mentioned in a
11360484Sobrien     .globl or .lglobl statement.  */
11460484Sobrien  int output;
11560484Sobrien  /* The symbol class.  */
11660484Sobrien  int class;
11760484Sobrien  /* The real name, if the symbol was renamed.  */
11860484Sobrien  char *real_name;
11960484Sobrien  /* For a csect symbol, the subsegment we are using.  This is zero
12060484Sobrien     for symbols that are not csects.  */
12160484Sobrien  subsegT subseg;
12260484Sobrien  /* For a csect or common symbol, the alignment to use.  */
12360484Sobrien  int align;
12460484Sobrien  /* For a function symbol, a symbol whose value is the size.  The
12560484Sobrien     field is NULL if there is no size.  */
12660484Sobrien  symbolS *size;
12760484Sobrien  /* For a csect symbol, the last symbol which has been defined in
12860484Sobrien     this csect, or NULL if none have been defined so far.  For a .bs
12960484Sobrien     symbol, the referenced csect symbol.  */
13060484Sobrien  symbolS *within;
13160484Sobrien};
13260484Sobrien
13360484Sobrien#define TC_SYMFIELD_TYPE struct ppc_tc_sy
13460484Sobrien
13560484Sobrien/* We need an additional auxent for function symbols.  */
13660484Sobrien#define OBJ_COFF_MAX_AUXENTRIES 2
13760484Sobrien
13860484Sobrien/* Square and curly brackets are permitted in symbol names.  */
13960484Sobrien#define LEX_BR 3
14060484Sobrien
14160484Sobrien/* Canonicalize the symbol name.  */
14260484Sobrien#define tc_canonicalize_symbol_name(name) ppc_canonicalize_symbol_name (name)
14360484Sobrienextern char *ppc_canonicalize_symbol_name PARAMS ((char *));
14460484Sobrien
14560484Sobrien/* Get the symbol class from the name.  */
14660484Sobrien#define tc_symbol_new_hook(sym) ppc_symbol_new_hook (sym)
14760484Sobrienextern void ppc_symbol_new_hook PARAMS ((symbolS *));
14860484Sobrien
14960484Sobrien/* Set the symbol class of a label based on the csect.  */
15060484Sobrien#define tc_frob_label(sym) ppc_frob_label (sym)
15160484Sobrienextern void ppc_frob_label PARAMS ((symbolS *));
15260484Sobrien
15360484Sobrien/* TOC relocs requires special handling.  */
15460484Sobrien#define tc_fix_adjustable(fixp) ppc_fix_adjustable (fixp)
15560484Sobrienextern int ppc_fix_adjustable PARAMS ((struct fix *));
15660484Sobrien
15760484Sobrien/* A relocation from one csect to another must be kept.  */
15860484Sobrien#define TC_FORCE_RELOCATION(FIXP) ppc_force_relocation (FIXP)
15960484Sobrienextern int ppc_force_relocation PARAMS ((struct fix *));
16060484Sobrien
16160484Sobrien/* We need to set the section VMA.  */
16260484Sobrien#define tc_frob_section(sec) ppc_frob_section (sec)
16360484Sobrienextern void ppc_frob_section PARAMS ((asection *));
16460484Sobrien
16560484Sobrien/* Finish up the symbol.  */
16660484Sobrien#define tc_frob_symbol(sym, punt) punt = ppc_frob_symbol (sym)
16760484Sobrienextern int ppc_frob_symbol PARAMS ((symbolS *));
16860484Sobrien
16960484Sobrien/* Finish up the entire symtab.  */
17060484Sobrien#define tc_adjust_symtab() ppc_adjust_symtab ()
17160484Sobrienextern void ppc_adjust_symtab PARAMS ((void));
17260484Sobrien
17360484Sobrien/* Niclas Andersson <nican@ida.liu.se> says this is needed.  */
17477298Sobrienextern int ppc_subseg_align PARAMS ((void));
17577298Sobrien#define SUB_SEGMENT_ALIGN(SEG) ppc_subseg_align()
17660484Sobrien
17760484Sobrien/* We also need to copy, in particular, the class of the symbol,
17860484Sobrien   over what obj-coff would otherwise have copied.  */
17960484Sobrien#define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src)			\
18060484Sobriendo {								\
18160484Sobrien  if (SF_GET_GET_SEGMENT (dest))				\
18260484Sobrien    S_SET_SEGMENT (dest, S_GET_SEGMENT (src));			\
18360484Sobrien  symbol_get_tc (dest)->size = symbol_get_tc (src)->size;	\
18460484Sobrien  symbol_get_tc (dest)->align = symbol_get_tc (src)->align;	\
18560484Sobrien  symbol_get_tc (dest)->class = symbol_get_tc (src)->class;	\
18660484Sobrien  symbol_get_tc (dest)->within = symbol_get_tc (src)->within;	\
18760484Sobrien} while (0)
18860484Sobrien
18960484Sobrien#endif /* OBJ_XCOFF */
19060484Sobrien
19160484Sobrien#ifdef OBJ_ELF
19260484Sobrien
19360484Sobrien/* Branch prediction relocations must force relocation, as must
19460484Sobrien   the vtable description relocs.  */
19560484Sobrien#define TC_FORCE_RELOCATION(FIXP)					\
19660484Sobrien((FIXP)->fx_r_type == BFD_RELOC_PPC_B16_BRTAKEN				\
19760484Sobrien || (FIXP)->fx_r_type == BFD_RELOC_PPC_B16_BRNTAKEN			\
19860484Sobrien || (FIXP)->fx_r_type == BFD_RELOC_PPC_BA16_BRTAKEN			\
19960484Sobrien || (FIXP)->fx_r_type == BFD_RELOC_PPC_BA16_BRNTAKEN			\
20060484Sobrien || (FIXP)->fx_r_type == BFD_RELOC_VTABLE_INHERIT			\
20160484Sobrien || (FIXP)->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20260484Sobrien
20360484Sobrien#define TC_FORCE_RELOCATION_SECTION(FIXP,SEC)				\
20460484Sobrien(TC_FORCE_RELOCATION (FIXP)						\
20560484Sobrien || ((FIXP)->fx_addsy && !(FIXP)->fx_subsy				\
20660484Sobrien     && S_GET_SEGMENT ((FIXP)->fx_addsy) != SEC))
20760484Sobrien
20860484Sobrien/* Support for SHF_EXCLUDE and SHT_ORDERED */
20960484Sobrienextern int ppc_section_letter PARAMS ((int, char **));
21060484Sobrienextern int ppc_section_type PARAMS ((char *, size_t));
21160484Sobrienextern int ppc_section_word PARAMS ((char *, size_t));
21260484Sobrienextern int ppc_section_flags PARAMS ((int, int, int));
21360484Sobrien
21460484Sobrien#define md_elf_section_letter(LETTER, PTR_MSG)	ppc_section_letter (LETTER, PTR_MSG)
21560484Sobrien#define md_elf_section_type(STR, LEN)		ppc_section_type (STR, LEN)
21660484Sobrien#define md_elf_section_word(STR, LEN)		ppc_section_word (STR, LEN)
21760484Sobrien#define md_elf_section_flags(FLAGS, ATTR, TYPE)	ppc_section_flags (FLAGS, ATTR, TYPE)
21860484Sobrien
21960484Sobrien/* Add extra PPC sections -- Note, for now, make .sbss2 and .PPC.EMB.sbss0 a
22060484Sobrien   normal section, and not a bss section so that the linker doesn't crater
22160484Sobrien   when trying to make more than 2 sections.  */
22260484Sobrien#define ELF_TC_SPECIAL_SECTIONS \
22360484Sobrien  { ".tags",		SHT_ORDERED,	SHF_ALLOC }, \
22460484Sobrien  { ".sdata",		SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE }, \
22560484Sobrien  { ".sbss",		SHT_NOBITS,	SHF_ALLOC + SHF_WRITE }, \
22660484Sobrien  { ".sdata2",		SHT_PROGBITS,	SHF_ALLOC }, \
22760484Sobrien  { ".sbss2",		SHT_PROGBITS,	SHF_ALLOC }, \
22860484Sobrien  { ".PPC.EMB.sdata0",	SHT_PROGBITS,	SHF_ALLOC }, \
22960484Sobrien  { ".PPC.EMB.sbss0",	SHT_PROGBITS,	SHF_ALLOC },
23060484Sobrien
23160484Sobrien#define tc_comment_chars ppc_comment_chars
23260484Sobrienextern const char *ppc_comment_chars;
23360484Sobrien
23477298Sobrien/* Keep relocations relative to the GOT, or non-PC relative.  */
23560484Sobrien#define tc_fix_adjustable(FIX)                          		\
23660484Sobrien  ((FIX)->fx_r_type != BFD_RELOC_16_GOTOFF              		\
23760484Sobrien   && (FIX)->fx_r_type != BFD_RELOC_LO16_GOTOFF         		\
23860484Sobrien   && (FIX)->fx_r_type != BFD_RELOC_HI16_GOTOFF         		\
23960484Sobrien   && (FIX)->fx_r_type != BFD_RELOC_HI16_S_GOTOFF       		\
24060484Sobrien   && (FIX)->fx_r_type != BFD_RELOC_GPREL16             		\
24160484Sobrien   && (FIX)->fx_r_type != BFD_RELOC_VTABLE_INHERIT			\
24260484Sobrien   && (FIX)->fx_r_type != BFD_RELOC_VTABLE_ENTRY			\
24360484Sobrien   && ! S_IS_EXTERNAL ((FIX)->fx_addsy)					\
24460484Sobrien   && ! S_IS_WEAK ((FIX)->fx_addsy)					\
24560484Sobrien   && ((FIX)->fx_pcrel				        		\
24660484Sobrien       || ((FIX)->fx_subsy != NULL					\
24760484Sobrien	   && (S_GET_SEGMENT ((FIX)->fx_subsy)				\
24860484Sobrien	       == S_GET_SEGMENT ((FIX)->fx_addsy)))			\
24960484Sobrien       || S_IS_LOCAL ((FIX)->fx_addsy)))
25060484Sobrien
25160484Sobrien/* We must never ever try to resolve references to externally visible
25260484Sobrien   symbols in the assembler, because the .o file might go into a shared
25360484Sobrien   library, and some other shared library might override that symbol.  */
25460484Sobrien#define TC_RELOC_RTSYM_LOC_FIXUP(FIX)  \
25560484Sobrien  ((FIX)->fx_addsy == NULL \
25660484Sobrien   || (! S_IS_EXTERNAL ((FIX)->fx_addsy) \
25760484Sobrien       && ! S_IS_WEAK ((FIX)->fx_addsy) \
25860484Sobrien       && S_IS_DEFINED ((FIX)->fx_addsy) \
25960484Sobrien       && ! S_IS_COMMON ((FIX)->fx_addsy)))
26060484Sobrien
26177298Sobrien#define DWARF2_LINE_MIN_INSN_LENGTH 4
26260484Sobrien#endif /* OBJ_ELF */
26360484Sobrien
26460484Sobrien/* call md_apply_fix3 with segment instead of md_apply_fix */
26560484Sobrien#define MD_APPLY_FIX3
26660484Sobrien
26760484Sobrien/* call md_pcrel_from_section, not md_pcrel_from */
26860484Sobrien#define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from_section(FIXP, SEC)
26960484Sobrienextern long md_pcrel_from_section PARAMS ((struct fix *, segT));
27060484Sobrien
27160484Sobrien#define md_parse_name(name, exp) ppc_parse_name (name, exp)
27260484Sobrienextern int ppc_parse_name PARAMS ((const char *, struct expressionS *));
27360484Sobrien
27460484Sobrien#define md_operand(x)
275