160484Sobrien/* This file is tc-arm.h
2218822Sdim   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3218822Sdim   2004, 2005, 2006, 2007 Free Software Foundation, Inc.
460484Sobrien   Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
560484Sobrien	Modified by David Taylor (dtaylor@armltd.co.uk)
660484Sobrien
760484Sobrien   This file is part of GAS, the GNU Assembler.
860484Sobrien
960484Sobrien   GAS is free software; you can redistribute it and/or modify
1060484Sobrien   it under the terms of the GNU General Public License as published by
1160484Sobrien   the Free Software Foundation; either version 2, or (at your option)
1260484Sobrien   any later version.
1360484Sobrien
1460484Sobrien   GAS is distributed in the hope that it will be useful,
1560484Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1660484Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1760484Sobrien   GNU General Public License for more details.
1860484Sobrien
1960484Sobrien   You should have received a copy of the GNU General Public License
2060484Sobrien   along with GAS; see the file COPYING.  If not, write to the Free
21218822Sdim   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22218822Sdim   02110-1301, USA.  */
2360484Sobrien
2460484Sobrien#define TC_ARM 1
2560484Sobrien
2660484Sobrien#ifndef TARGET_BYTES_BIG_ENDIAN
2760484Sobrien#define TARGET_BYTES_BIG_ENDIAN 0
2860484Sobrien#endif
2960484Sobrien
3060484Sobrien#define WORKING_DOT_WORD
3160484Sobrien
3260484Sobrien#define COFF_MAGIC 	ARMMAGIC
3360484Sobrien#define TARGET_ARCH 	bfd_arch_arm
3460484Sobrien
3560484Sobrien#define DIFF_EXPR_OK
3660484Sobrien
3760484Sobrien#ifdef  LITTLE_ENDIAN
3860484Sobrien#undef  LITTLE_ENDIAN
3960484Sobrien#endif
4060484Sobrien
4160484Sobrien#ifdef  BIG_ENDIAN
4260484Sobrien#undef  BIG_ENDIAN
4360484Sobrien#endif
4460484Sobrien
4560484Sobrien#define LITTLE_ENDIAN 	1234
4660484Sobrien#define BIG_ENDIAN 	4321
4760484Sobrien
48130561Sobrienstruct fix;
49130561Sobrien
5060484Sobrien#if defined OBJ_AOUT
51130561Sobrien# if defined TE_RISCIX
52130561Sobrien#  define TARGET_FORMAT "a.out-riscix"
53130561Sobrien# elif defined TE_LINUX
54130561Sobrien#  define ARM_BI_ENDIAN
55130561Sobrien#  define TARGET_FORMAT "a.out-arm-linux"
56130561Sobrien# elif defined TE_NetBSD
57130561Sobrien#  define TARGET_FORMAT "a.out-arm-netbsd"
58130561Sobrien# else
59130561Sobrien#  define ARM_BI_ENDIAN
60130561Sobrien#  define TARGET_FORMAT (target_big_endian ? "a.out-arm-big" : "a.out-arm-little")
61130561Sobrien# endif
62130561Sobrien#elif defined OBJ_AIF
63130561Sobrien# define TARGET_FORMAT "aif"
64130561Sobrien#elif defined OBJ_COFF
6560484Sobrien# define ARM_BI_ENDIAN
6660484Sobrien# if defined TE_PE
67130561Sobrien#  if defined TE_EPOC
68130561Sobrien#   define TARGET_FORMAT (target_big_endian ? "epoc-pe-arm-big" : "epoc-pe-arm-little")
69218822Sdim#  elif defined TE_WINCE
70218822Sdim#   define TARGET_FORMAT (target_big_endian ? "pe-arm-wince-big" : "pe-arm-wince-little")
71130561Sobrien#  else
72130561Sobrien#   define TARGET_FORMAT (target_big_endian ? "pe-arm-big" : "pe-arm-little")
73130561Sobrien#  endif
7460484Sobrien# else
7560484Sobrien#  define TARGET_FORMAT (target_big_endian ? "coff-arm-big" : "coff-arm-little")
7660484Sobrien# endif
77130561Sobrien#elif defined OBJ_ELF
78130561Sobrien# define ARM_BI_ENDIAN
79130561Sobrien# define TARGET_FORMAT	elf32_arm_target_format ()
8060484Sobrien#endif
8160484Sobrien
82130561Sobrien#define TC_FORCE_RELOCATION(FIX) arm_force_relocation (FIX)
8377298Sobrien
84218822Sdim#define md_relax_frag(segment, fragp, stretch) \
85218822Sdim  arm_relax_frag(segment, fragp, stretch)
86218822Sdimextern int arm_relax_frag (asection *, struct frag *, long);
8760484Sobrien
88218822Sdim#define md_optimize_expr(l,o,r)		arm_optimize_expr (l, o, r)
89218822Sdimextern int arm_optimize_expr (expressionS *, operatorT, expressionS *);
90218822Sdim
9160484Sobrien#define md_cleanup() arm_cleanup ()
9260484Sobrien
9360484Sobrien#define md_start_line_hook() arm_start_line_hook ()
9460484Sobrien
9560484Sobrien#define tc_frob_label(S) arm_frob_label (S)
9660484Sobrien
9760484Sobrien/* We also need to mark assembler created symbols:  */
9860484Sobrien#define tc_frob_fake_label(S) arm_frob_label (S)
9960484Sobrien
100218822Sdim#ifdef OBJ_ELF
101218822Sdim#define md_end arm_md_end
102218822Sdimextern void arm_md_end (void);
103218822Sdimbfd_boolean arm_is_eabi (void);
104218822Sdim#endif
105218822Sdim
10660484Sobrien/* NOTE: The fake label creation in stabs.c:s_stab_generic() has
10760484Sobrien   deliberately not been updated to mark assembler created stabs
10860484Sobrien   symbols as Thumb.  */
10960484Sobrien
110218822Sdim#define TC_FIX_TYPE int
111218822Sdim#define TC_INIT_FIX_DATA(FIX) ((FIX)->tc_fix_data = 0)
11260484Sobrien
11360484Sobrien/* We need to keep some local information on symbols.  */
11460484Sobrien
115130561Sobrien#define TC_SYMFIELD_TYPE 	unsigned int
11660484Sobrien#define ARM_GET_FLAG(s)   	(*symbol_get_tc (s))
11760484Sobrien#define ARM_SET_FLAG(s,v) 	(*symbol_get_tc (s) |= (v))
11860484Sobrien#define ARM_RESET_FLAG(s,v) 	(*symbol_get_tc (s) &= ~(v))
11960484Sobrien
12060484Sobrien#define ARM_FLAG_THUMB 		(1 << 0)	/* The symbol is a Thumb symbol rather than an Arm symbol.  */
121130561Sobrien#define ARM_FLAG_INTERWORK 	(1 << 1)	/* The symbol is attached to code that supports interworking.  */
12260484Sobrien#define THUMB_FLAG_FUNC		(1 << 2)	/* The symbol is attached to the start of a Thumb function.  */
12360484Sobrien
12460484Sobrien#define ARM_IS_THUMB(s)		(ARM_GET_FLAG (s) & ARM_FLAG_THUMB)
12560484Sobrien#define ARM_IS_INTERWORK(s)	(ARM_GET_FLAG (s) & ARM_FLAG_INTERWORK)
126218822Sdim#ifdef OBJ_ELF
127218822Sdim
128218822Sdim/* For ELF objects THUMB_IS_FUNC is inferred from
129218822Sdim   ARM_IS_TUMB and the function type.  */
130218822Sdim#define THUMB_IS_FUNC(s) \
131218822Sdim  ((arm_is_eabi () \
132218822Sdim    && (ARM_IS_THUMB (s)) \
133218822Sdim    && (symbol_get_bfdsym (s)->flags & BSF_FUNCTION)) \
134218822Sdim   || (ARM_GET_FLAG (s) & THUMB_FLAG_FUNC))
135218822Sdim
136218822Sdim#else
13760484Sobrien#define THUMB_IS_FUNC(s)	(ARM_GET_FLAG (s) & THUMB_FLAG_FUNC)
138218822Sdim#endif
13960484Sobrien
14060484Sobrien#define ARM_SET_THUMB(s,t)      ((t) ? ARM_SET_FLAG (s, ARM_FLAG_THUMB)     : ARM_RESET_FLAG (s, ARM_FLAG_THUMB))
14160484Sobrien#define ARM_SET_INTERWORK(s,t)  ((t) ? ARM_SET_FLAG (s, ARM_FLAG_INTERWORK) : ARM_RESET_FLAG (s, ARM_FLAG_INTERWORK))
14260484Sobrien#define THUMB_SET_FUNC(s,t)     ((t) ? ARM_SET_FLAG (s, THUMB_FLAG_FUNC)    : ARM_RESET_FLAG (s, THUMB_FLAG_FUNC))
14360484Sobrien
144218822Sdimvoid arm_copy_symbol_attributes (symbolS *, symbolS *);
145218822Sdim#ifndef TC_COPY_SYMBOL_ATTRIBUTES
146218822Sdim#define TC_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
147218822Sdim  (arm_copy_symbol_attributes (DEST, SRC))
148218822Sdim#endif
149218822Sdim
150130561Sobrien#define TC_START_LABEL(C,STR)            (c == ':' || (c == '/' && arm_data_in_code ()))
151130561Sobrien#define tc_canonicalize_symbol_name(str) arm_canonicalize_symbol_name (str);
152130561Sobrien#define obj_adjust_symtab() 		 arm_adjust_symtab ()
15360484Sobrien
15460484Sobrien#define LISTING_HEADER "ARM GAS "
15560484Sobrien
15660484Sobrien#define OPTIONAL_REGISTER_PREFIX '%'
15760484Sobrien
158218822Sdim#define LOCAL_LABEL(name)  (name[0] == '.' && name[1] == 'L')
159218822Sdim#define LOCAL_LABELS_FB    1
16060484Sobrien
161130561Sobrien/* This expression evaluates to true if the relocation is for a local
162130561Sobrien   object for which we still want to do the relocation at runtime.
163130561Sobrien   False if we are willing to perform this relocation while building
164130561Sobrien   the .o file.  GOTOFF does not need to be checked here because it is
165130561Sobrien   not pcrel.  I am not sure if some of the others are ever used with
16660484Sobrien   pcrel, but it is easier to be safe than sorry.  */
16760484Sobrien
168130561Sobrien#define TC_FORCE_RELOCATION_LOCAL(FIX)			\
169130561Sobrien  (!(FIX)->fx_pcrel					\
170130561Sobrien   || (FIX)->fx_r_type == BFD_RELOC_ARM_GOT32		\
171130561Sobrien   || (FIX)->fx_r_type == BFD_RELOC_32			\
172130561Sobrien   || TC_FORCE_RELOCATION (FIX))
17360484Sobrien
174218822Sdim/* Force output of R_ARM_REL32 relocations against thumb function symbols.
175218822Sdim   This is needed to ensure the low bit is handled correctly.  */
176218822Sdim#define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG)	\
177218822Sdim  (THUMB_IS_FUNC ((FIX)->fx_addsy)		\
178218822Sdim   || !SEG_NORMAL (SEG))
179218822Sdim
18060484Sobrien#define TC_CONS_FIX_NEW cons_fix_new_arm
18160484Sobrien
18278828Sobrien#define MAX_MEM_FOR_RS_ALIGN_CODE 31
18378828Sobrien
18478828Sobrien/* For frags in code sections we need to record whether they contain
18578828Sobrien   ARM code or THUMB code.  This is that if they have to be aligned,
18678828Sobrien   they can contain the correct type of no-op instruction.  */
187130561Sobrien#define TC_FRAG_TYPE		int
18878828Sobrien#define TC_FRAG_INIT(fragp)	arm_init_frag (fragp)
189130561Sobrien#define HANDLE_ALIGN(fragp)	arm_handle_align (fragp)
19078828Sobrien
19178828Sobrien#define md_do_align(N, FILL, LEN, MAX, LABEL)					\
19278828Sobrien  if (FILL == NULL && (N) != 0 && ! need_pass_2 && subseg_text_p (now_seg))	\
19378828Sobrien    {										\
19478828Sobrien      arm_frag_align_code (N, MAX);						\
19578828Sobrien      goto LABEL;								\
19678828Sobrien    }
197130561Sobrien
198218822Sdim#define DWARF2_LINE_MIN_INSN_LENGTH 	2
199218822Sdim
200218822Sdim/* The lr register is r14.  */
201218822Sdim#define DWARF2_DEFAULT_RETURN_COLUMN  14
202218822Sdim
203218822Sdim/* Registers are generally saved at negative offsets to the CFA.  */
204218822Sdim#define DWARF2_CIE_DATA_ALIGNMENT     (-4)
205218822Sdim
206130561Sobrien#ifdef OBJ_ELF
207130561Sobrien# define obj_frob_symbol(sym, punt)	armelf_frob_symbol ((sym), & (punt))
208130561Sobrien# define md_elf_section_change_hook()	arm_elf_change_section ()
209218822Sdim# define md_elf_section_type(str, len)	arm_elf_section_type (str, len)
210130561Sobrien# define GLOBAL_OFFSET_TABLE_NAME	"_GLOBAL_OFFSET_TABLE_"
211218822Sdim# define TC_SEGMENT_INFO_TYPE 		struct arm_segment_info_type
212130561Sobrien
213218822Sdim/* This is not really an alignment operation, but it's something we
214218822Sdim   need to do at the same time: whenever we are figuring out the
215218822Sdim   alignment for data, we should check whether a $d symbol is
216218822Sdim   necessary.  */
217218822Sdim# define md_cons_align(nbytes)		mapping_state (MAP_DATA)
218218822Sdim
219130561Sobrienenum mstate
220130561Sobrien{
221130561Sobrien  MAP_UNDEFINED = 0, /* Must be zero, for seginfo in new sections.  */
222130561Sobrien  MAP_DATA,
223130561Sobrien  MAP_ARM,
224130561Sobrien  MAP_THUMB
225130561Sobrien};
226130561Sobrien
227218822Sdimvoid mapping_state (enum mstate);
228218822Sdim
229218822Sdimstruct arm_segment_info_type
230218822Sdim{
231218822Sdim  enum mstate mapstate;
232218822Sdim  unsigned int marked_pr_dependency;
233218822Sdim};
234218822Sdim
235218822Sdim/* We want .cfi_* pseudo-ops for generating unwind info.  */
236218822Sdim#define TARGET_USE_CFIPOP              1
237218822Sdim
238218822Sdim/* CFI hooks.  */
239218822Sdim#define tc_regname_to_dw2regnum            tc_arm_regname_to_dw2regnum
240218822Sdim#define tc_cfi_frame_initial_instructions  tc_arm_frame_initial_instructions
241218822Sdim
242130561Sobrien#else /* Not OBJ_ELF.  */
243130561Sobrien#define GLOBAL_OFFSET_TABLE_NAME "__GLOBAL_OFFSET_TABLE_"
244130561Sobrien#endif
245130561Sobrien
246130561Sobrien#if defined OBJ_ELF || defined OBJ_COFF
247130561Sobrien
248130561Sobrien# define EXTERN_FORCE_RELOC 			1
249130561Sobrien# define tc_fix_adjustable(FIX) 		arm_fix_adjustable (FIX)
250218822Sdim/* Values passed to md_apply_fix don't include the symbol value.  */
251130561Sobrien# define MD_APPLY_SYM_VALUE(FIX) 		0
252130561Sobrien# define TC_VALIDATE_FIX(FIX, SEGTYPE, LABEL)	arm_validate_fix (FIX)
253130561Sobrien
254130561Sobrien#endif
255130561Sobrien
256218822Sdim#define MD_PCREL_FROM_SECTION(F,S) md_pcrel_from_section(F,S)
257218822Sdim
258218822Sdimextern long md_pcrel_from_section (struct fix *, segT);
259130561Sobrienextern void arm_frag_align_code (int, int);
260130561Sobrienextern void arm_validate_fix (struct fix *);
261130561Sobrienextern const char * elf32_arm_target_format (void);
262130561Sobrienextern void arm_elf_change_section (void);
263130561Sobrienextern int arm_force_relocation (struct fix *);
264130561Sobrienextern void arm_cleanup (void);
265130561Sobrienextern void arm_start_line_hook (void);
266130561Sobrienextern void arm_frob_label (symbolS *);
267130561Sobrienextern int arm_data_in_code (void);
268130561Sobrienextern char * arm_canonicalize_symbol_name (char *);
269130561Sobrienextern void arm_adjust_symtab (void);
270130561Sobrienextern void armelf_frob_symbol (symbolS *, int *);
271130561Sobrienextern void cons_fix_new_arm (fragS *, int, int, expressionS *);
272130561Sobrienextern void arm_init_frag (struct frag *);
273130561Sobrienextern void arm_handle_align (struct frag *);
274130561Sobrienextern bfd_boolean arm_fix_adjustable (struct fix *);
275218822Sdimextern int arm_elf_section_type (const char *, size_t);
276218822Sdimextern int tc_arm_regname_to_dw2regnum (char *regname);
277218822Sdimextern void tc_arm_frame_initial_instructions (void);
278218822Sdim
279218822Sdim#ifdef TE_PE
280218822Sdim
281218822Sdim#define O_secrel O_md1
282218822Sdim
283218822Sdim#define TC_DWARF2_EMIT_OFFSET  tc_pe_dwarf2_emit_offset
284218822Sdimvoid tc_pe_dwarf2_emit_offset (symbolS *, unsigned int);
285218822Sdim
286218822Sdim#endif /* TE_PE */
287