11553Srgrimes/* Definitions for Altera Nios II assembler.
21553Srgrimes   Copyright (C) 2012-2020 Free Software Foundation, Inc.
31553Srgrimes   Contributed by Nigel Gray (ngray@altera.com).
41553Srgrimes   Contributed by Mentor Graphics, Inc.
51553Srgrimes
61553Srgrimes   This file is part of GAS, the GNU Assembler.
71553Srgrimes
81553Srgrimes   GAS is free software; you can redistribute it and/or modify
91553Srgrimes   it under the terms of the GNU General Public License as published by
101553Srgrimes   the Free Software Foundation; either version 3, or (at your option)
111553Srgrimes   any later version.
121553Srgrimes
131553Srgrimes   GAS is distributed in the hope that it will be useful,
141553Srgrimes   but WITHOUT ANY WARRANTY; without even the implied warranty of
151553Srgrimes   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161553Srgrimes   GNU General Public License for more details.
171553Srgrimes
181553Srgrimes   You should have received a copy of the GNU General Public License
191553Srgrimes   along with GAS; see the file COPYING.  If not, write to the Free
201553Srgrimes   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
211553Srgrimes   02110-1301, USA.  */
221553Srgrimes
231553Srgrimes#ifndef TC_NIOS2
241553Srgrimes#define TC_NIOS2
251553Srgrimes
261553Srgrimes/* If unspecified, default to little endian.  We can explicitly specify
271553Srgrimes * a big-endian default by configuring with --target=nios2eb-elf.  We
281553Srgrimes * can override the default with the -EB and -EL options.  */
291553Srgrimes#ifndef TARGET_BYTES_BIG_ENDIAN
301553Srgrimes#define TARGET_BYTES_BIG_ENDIAN 0
311553Srgrimes#endif
321553Srgrimes
331553Srgrimes/* Words are big enough to hold addresses.  */
341553Srgrimes#define WORKING_DOT_WORD	1
3529602Scharnier
361553Srgrimes#ifdef OBJ_ELF
371553Srgrimesextern const char *nios2_target_format (void);
381553Srgrimes#define TARGET_FORMAT  nios2_target_format ()
391553Srgrimes#define TARGET_ARCH    bfd_arch_nios2
401553Srgrimes#endif
4129602Scharnier
4229602Scharnier/* A NIOS2 instruction consists of tokens and separator characters
4329602Scharnier   the tokens are things like the instruction name (add, or jmp etc),
4429602Scharnier   the register indices ($5, $7 etc), and constant expressions. The
4548988Ssheldonh   separator characters are commas, brackets and space.
461553Srgrimes   The instruction name is always separated from other tokens by a space
471553Srgrimes   The maximum number of tokens in an instruction is 5 (the instruction name,
481553Srgrimes   3 arguments, and a 4th string representing the expected instruct in opcode
491553Srgrimes   after assembly. The latter is only used when the assemble is running in
501553Srgrimes   self test mode, otherwise its presence will generate an error.  */
511553Srgrimes#define NIOS2_MAX_INSN_TOKENS	6
521553Srgrimes
531553Srgrimes/* There are no machine-specific operands so we #define this to nothing.  */
541553Srgrimes#define md_operand(x)
551553Srgrimes
561553Srgrimes/* Function prototypes exported to rest of GAS.  */
571553Srgrimesextern void md_assemble (char *op_str);
581553Srgrimesextern void md_end (void);
591553Srgrimesextern void md_begin (void);
601553Srgrimes
611553Srgrimes#define TC_FORCE_RELOCATION(fixp) nios2_force_relocation (fixp)
621553Srgrimesextern int nios2_force_relocation (struct fix *);
638857Srgrimes
641553Srgrimes#define tc_fix_adjustable(fixp) nios2_fix_adjustable (fixp)
651553Srgrimesextern int nios2_fix_adjustable (struct fix *);
661553Srgrimes
671553Srgrimes#define tc_frob_label(lab)	     nios2_frob_label (lab)
681553Srgrimesextern void nios2_frob_label (symbolS *);
691553Srgrimes
701553Srgrimes#define tc_frob_symbol(symp, punt)  punt = nios2_frob_symbol (symp) ? 1 : punt
711553Srgrimesextern int nios2_frob_symbol (symbolS * symp);
721553Srgrimes
731553Srgrimes#define md_cons_align(nbytes) nios2_cons_align (nbytes)
741553Srgrimesextern void nios2_cons_align (int);
751553Srgrimes
761553Srgrimesextern void md_convert_frag (bfd * headers, segT sec, fragS * fragP);
771553Srgrimes
781553Srgrimes/* When relaxing, we need to generate relocations for alignment
791553Srgrimes   directives.  */
801553Srgrimes#define HANDLE_ALIGN(frag) nios2_handle_align (frag)
811553Srgrimesextern void nios2_handle_align (fragS *);
821553Srgrimes
831553Srgrimes#define md_relax_frag nios2_relax_frag
841553Srgrimesextern long nios2_relax_frag (segT segment, fragS * fragP, long stretch);
851553Srgrimes
861553Srgrimes#ifdef OBJ_ELF
871553Srgrimes#define ELF_TC_SPECIAL_SECTIONS \
881553Srgrimes  { ".sdata",   SHT_PROGBITS,   SHF_ALLOC + SHF_WRITE + SHF_NIOS2_GPREL  }, \
891553Srgrimes  { ".sbss",    SHT_NOBITS,     SHF_ALLOC + SHF_WRITE + SHF_NIOS2_GPREL  }, \
901553Srgrimes  { ".lit4",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_NIOS2_GPREL  }, \
911553Srgrimes  { ".lit8",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_NIOS2_GPREL  },
921553Srgrimes
931553Srgrimes/* Processor-specific section directives.  */
941553Srgrimes#define md_elf_section_letter		nios2_elf_section_letter
952657Scsgrextern int nios2_elf_section_letter (int, const char **);
962657Scsgr#define md_elf_section_flags		nios2_elf_section_flags
972657Scsgrextern flagword nios2_elf_section_flags (flagword, int, int);
982657Scsgr#endif
992657Scsgr
1002657Scsgr#define GLOBAL_OFFSET_TABLE_NAME       "_GLOBAL_OFFSET_TABLE_"
1012657Scsgr
1022657Scsgr#define DIFF_EXPR_OK
1032657Scsgr
1041553Srgrimes/* Don't allow the generic code to convert fixups involving the
1051553Srgrimes   subtraction of a label in the current section to pc-relative if we
1061553Srgrimes   don't have the necessary pc-relative relocation.  */
1071553Srgrimes#define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG)		\
1081553Srgrimes  (!((FIX)->fx_r_type == BFD_RELOC_16			\
1091553Srgrimes     || (FIX)->fx_r_type == BFD_RELOC_NIOS2_LO16	\
1101553Srgrimes     || (FIX)->fx_r_type == BFD_RELOC_NIOS2_HIADJ16))
1111553Srgrimes
1121553Srgrimes/* Nios2 ABI doesn't have 32-bit PCREL relocation, and, as relocations for
11336042Sguido   CFI information will be in section other than .text, we can't use PC-biased
1141553Srgrimes   relocs.  */
1152657Scsgr#define CFI_DIFF_EXPR_OK 0
11619617Sjulian
1171553Srgrimes#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) nios2_cons (EXP, NBYTES)
1181553Srgrimesextern bfd_reloc_code_real_type nios2_cons (expressionS *exp, int size);
11929602Scharnier
1201553Srgrimes/* We want .cfi_* pseudo-ops for generating unwind info.  */
12130807Sache#define TARGET_USE_CFIPOP 1
1221553Srgrimes#define DWARF2_DEFAULT_RETURN_COLUMN 31
1231553Srgrimes#define DWARF2_CIE_DATA_ALIGNMENT (-4)
1241553Srgrimes#define tc_regname_to_dw2regnum nios2_regname_to_dw2regnum
1251553Srgrimesextern int nios2_regname_to_dw2regnum (char *regname);
1261553Srgrimes#define tc_cfi_frame_initial_instructions  nios2_frame_initial_instructions
1271553Srgrimesextern void nios2_frame_initial_instructions (void);
1281553Srgrimes
12948279Ssheldonh#define elf_tc_final_processing nios2_elf_final_processing
1301553Srgrimesextern void nios2_elf_final_processing (void);
13113142Speter
13219617Sjulian#endif /* TC_NIOS2 */
1331553Srgrimes