12a6b7db3Sskrll /* This file is tc-avr.h
2*f22f0ef4Schristos    Copyright (C) 1999-2022 Free Software Foundation, Inc.
32a6b7db3Sskrll 
42a6b7db3Sskrll    Contributed by Denis Chertykov <denisc@overta.ru>
52a6b7db3Sskrll 
62a6b7db3Sskrll    This file is part of GAS, the GNU Assembler.
72a6b7db3Sskrll 
82a6b7db3Sskrll    GAS is free software; you can redistribute it and/or modify
92a6b7db3Sskrll    it under the terms of the GNU General Public License as published by
102a6b7db3Sskrll    the Free Software Foundation; either version 3, or (at your option)
112a6b7db3Sskrll    any later version.
122a6b7db3Sskrll 
132a6b7db3Sskrll    GAS is distributed in the hope that it will be useful,
142a6b7db3Sskrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
152a6b7db3Sskrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162a6b7db3Sskrll    GNU General Public License for more details.
172a6b7db3Sskrll 
182a6b7db3Sskrll    You should have received a copy of the GNU General Public License
192a6b7db3Sskrll    along with GAS; see the file COPYING.  If not, write to the Free
202a6b7db3Sskrll    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
212a6b7db3Sskrll    02110-1301, USA.  */
222a6b7db3Sskrll 
232a6b7db3Sskrll /* By convention, you should define this macro in the `.h' file.  For
242a6b7db3Sskrll    example, `tc-m68k.h' defines `TC_M68K'.  You might have to use this
252a6b7db3Sskrll    if it is necessary to add CPU specific code to the object format
262a6b7db3Sskrll    file.  */
272a6b7db3Sskrll #define TC_AVR
282a6b7db3Sskrll 
292a6b7db3Sskrll /* This macro is the BFD target name to use when creating the output
302a6b7db3Sskrll    file.  This will normally depend upon the `OBJ_FMT' macro.  */
312a6b7db3Sskrll #define TARGET_FORMAT "elf32-avr"
322a6b7db3Sskrll 
332a6b7db3Sskrll /* This macro is the BFD architecture to pass to `bfd_set_arch_mach'.  */
342a6b7db3Sskrll #define TARGET_ARCH bfd_arch_avr
352a6b7db3Sskrll 
362a6b7db3Sskrll /* This macro is the BFD machine number to pass to
372a6b7db3Sskrll    `bfd_set_arch_mach'.  If it is not defined, GAS will use 0.  */
382a6b7db3Sskrll #define TARGET_MACH 0
392a6b7db3Sskrll 
402a6b7db3Sskrll /* You should define this macro to be non-zero if the target is big
412a6b7db3Sskrll    endian, and zero if the target is little endian.  */
422a6b7db3Sskrll #define TARGET_BYTES_BIG_ENDIAN 0
432a6b7db3Sskrll 
442a6b7db3Sskrll /* If you define this macro, GAS will warn about the use of
452a6b7db3Sskrll    nonstandard escape sequences in a string.  */
462a6b7db3Sskrll #define ONLY_STANDARD_ESCAPES
472a6b7db3Sskrll 
485ba6b03cSchristos #define DIFF_EXPR_OK    /* .-foo gets turned into PC relative relocs */
495ba6b03cSchristos 
502a6b7db3Sskrll /* GAS will call this function for any expression that can not be
512a6b7db3Sskrll    recognized.  When the function is called, `input_line_pointer'
522a6b7db3Sskrll    will point to the start of the expression.  */
532a6b7db3Sskrll #define md_operand(x)
542a6b7db3Sskrll 
555ba6b03cSchristos typedef struct
565ba6b03cSchristos {
575ba6b03cSchristos   /* Name of the expression modifier allowed with .byte, .word, etc.  */
585ba6b03cSchristos   const char *name;
595ba6b03cSchristos 
605ba6b03cSchristos   /* Only allowed with n bytes of data.  */
615ba6b03cSchristos   int nbytes;
625ba6b03cSchristos 
635ba6b03cSchristos   /* Associated RELOC.  */
645ba6b03cSchristos   bfd_reloc_code_real_type reloc;
655ba6b03cSchristos 
665ba6b03cSchristos   /* Part of the error message.  */
675ba6b03cSchristos   const char *error;
685ba6b03cSchristos } exp_mod_data_t;
695ba6b03cSchristos 
705ba6b03cSchristos extern const exp_mod_data_t exp_mod_data[];
715ba6b03cSchristos #define TC_PARSE_CONS_RETURN_TYPE const exp_mod_data_t *
725ba6b03cSchristos #define TC_PARSE_CONS_RETURN_NONE exp_mod_data
735ba6b03cSchristos 
742a6b7db3Sskrll /* You may define this macro to parse an expression used in a data
752a6b7db3Sskrll    allocation pseudo-op such as `.word'.  You can use this to
762a6b7db3Sskrll    recognize relocation directives that may appear in such directives.  */
772a6b7db3Sskrll #define TC_PARSE_CONS_EXPRESSION(EXPR,N) avr_parse_cons_expression (EXPR, N)
785ba6b03cSchristos extern const exp_mod_data_t *avr_parse_cons_expression (expressionS *, int);
792a6b7db3Sskrll 
802a6b7db3Sskrll /* You may define this macro to generate a fixup for a data
812a6b7db3Sskrll    allocation pseudo-op.  */
825ba6b03cSchristos #define TC_CONS_FIX_NEW avr_cons_fix_new
835ba6b03cSchristos extern void avr_cons_fix_new (fragS *,int, int, expressionS *,
845ba6b03cSchristos 			      const exp_mod_data_t *);
852a6b7db3Sskrll 
862a6b7db3Sskrll /* This should just call either `number_to_chars_bigendian' or
872a6b7db3Sskrll    `number_to_chars_littleendian', whichever is appropriate.  On
882a6b7db3Sskrll    targets like the MIPS which support options to change the
892a6b7db3Sskrll    endianness, which function to call is a runtime decision.  On
902a6b7db3Sskrll    other targets, `md_number_to_chars' can be a simple macro.  */
912a6b7db3Sskrll #define md_number_to_chars number_to_chars_littleendian
922a6b7db3Sskrll 
932a6b7db3Sskrll /* `md_short_jump_size'
942a6b7db3Sskrll    `md_long_jump_size'
952a6b7db3Sskrll    `md_create_short_jump'
962a6b7db3Sskrll    `md_create_long_jump'
972a6b7db3Sskrll    If `WORKING_DOT_WORD' is defined, GAS will not do broken word
982a6b7db3Sskrll    processing (*note Broken words::.).  Otherwise, you should set
992a6b7db3Sskrll    `md_short_jump_size' to the size of a short jump (a jump that is
1002a6b7db3Sskrll    just long enough to jump around a long jmp) and
1012a6b7db3Sskrll    `md_long_jump_size' to the size of a long jump (a jump that can go
1022a6b7db3Sskrll    anywhere in the function), You should define
1032a6b7db3Sskrll    `md_create_short_jump' to create a short jump around a long jump,
1042a6b7db3Sskrll    and define `md_create_long_jump' to create a long jump.  */
1052a6b7db3Sskrll #define WORKING_DOT_WORD
1062a6b7db3Sskrll 
1072a6b7db3Sskrll /* If you define this macro, it means that `tc_gen_reloc' may return
1082a6b7db3Sskrll    multiple relocation entries for a single fixup.  In this case, the
1092a6b7db3Sskrll    return value of `tc_gen_reloc' is a pointer to a null terminated
1102a6b7db3Sskrll    array.  */
1112a6b7db3Sskrll #undef RELOC_EXPANSION_POSSIBLE
1122a6b7db3Sskrll 
1132a6b7db3Sskrll /* No shared lib support, so we don't need to ensure externally
1142a6b7db3Sskrll    visible symbols can be overridden.  */
1152a6b7db3Sskrll #define EXTERN_FORCE_RELOC 0
1162a6b7db3Sskrll 
1175ba6b03cSchristos /* If defined, this macro allows control over whether fixups for a
1185ba6b03cSchristos    given section will be processed when the linkrelax variable is
1195ba6b03cSchristos    set. Define it to zero and handle things in md_apply_fix instead.*/
1205ba6b03cSchristos #define TC_LINKRELAX_FIXUP(SEG) 0
1215ba6b03cSchristos 
1225ba6b03cSchristos /* If this macro returns non-zero, it guarantees that a relocation will be emitted
1235ba6b03cSchristos    even when the value can be resolved locally. Do that if linkrelax is turned on */
1245ba6b03cSchristos #define TC_FORCE_RELOCATION(fix)	avr_force_relocation (fix)
1255ba6b03cSchristos #define TC_FORCE_RELOCATION_SUB_SAME(fix, seg) \
12698f124a6Schristos   (GENERIC_FORCE_RELOCATION_SUB_SAME (fix, seg)	\
12798f124a6Schristos    || avr_force_relocation (fix))
1285ba6b03cSchristos extern int avr_force_relocation (struct fix *);
1295ba6b03cSchristos 
1302a6b7db3Sskrll /* Values passed to md_apply_fix don't include the symbol value.  */
1312a6b7db3Sskrll #define MD_APPLY_SYM_VALUE(FIX) 0
1322a6b7db3Sskrll 
1332a6b7db3Sskrll /* If you define this macro, it should return the offset between the
1342a6b7db3Sskrll    address of a PC relative fixup and the position from which the PC
1352a6b7db3Sskrll    relative adjustment should be made.  On many processors, the base
1362a6b7db3Sskrll    of a PC relative instruction is the next instruction, so this
1372a6b7db3Sskrll    macro would return the length of an instruction.  */
1382a6b7db3Sskrll #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from_section (FIX, SEC)
1392a6b7db3Sskrll 
1402a6b7db3Sskrll /* The number of bytes to put into a word in a listing.  This affects
1412a6b7db3Sskrll    the way the bytes are clumped together in the listing.  For
1422a6b7db3Sskrll    example, a value of 2 might print `1234 5678' where a value of 1
1432a6b7db3Sskrll    would print `12 34 56 78'.  The default value is 4.  */
1442a6b7db3Sskrll #define LISTING_WORD_SIZE 2
1452a6b7db3Sskrll 
146*f22f0ef4Schristos /* AVR port uses `$' as a logical line separator by default. */
1472a6b7db3Sskrll #define LEX_DOLLAR 0
1482a6b7db3Sskrll 
1492a6b7db3Sskrll /* An `.lcomm' directive with no explicit alignment parameter will
1502a6b7db3Sskrll    use this macro to set P2VAR to the alignment that a request for
1512a6b7db3Sskrll    SIZE bytes will have.  The alignment is expressed as a power of
1522a6b7db3Sskrll    two.  If no alignment should take place, the macro definition
1532a6b7db3Sskrll    should do nothing.  Some targets define a `.bss' directive that is
1542a6b7db3Sskrll    also affected by this macro.  The default definition will set
1552a6b7db3Sskrll    P2VAR to the truncated power of two of sizes up to eight bytes.  */
1562a6b7db3Sskrll #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) (P2VAR) = 0
1572a6b7db3Sskrll 
1582a6b7db3Sskrll /* We don't want gas to fixup the following program memory related relocations.
1592a6b7db3Sskrll    We will need them in case that we want to do linker relaxation.
1602a6b7db3Sskrll    We could in principle keep these fixups in gas when not relaxing.
1615ba6b03cSchristos    However, there is no serious performance penalty when making the linker
1622a6b7db3Sskrll    make the fixup work.  Check also that fx_addsy is not NULL, in order to make
1635ba6b03cSchristos    sure that the fixup refers to some sort of label.  */
1642a6b7db3Sskrll #define TC_VALIDATE_FIX(FIXP,SEG,SKIP)                       \
1652a6b7db3Sskrll   if (   (FIXP->fx_r_type == BFD_RELOC_AVR_7_PCREL           \
1662a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_13_PCREL          \
1672a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM        \
1682a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_GS        \
1692a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM        \
1702a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_GS        \
1712a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM        \
1722a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM_NEG    \
1732a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM_NEG    \
1742a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM_NEG    \
1755ba6b03cSchristos        || FIXP->fx_r_type == BFD_RELOC_AVR_8_LO              \
1765ba6b03cSchristos        || FIXP->fx_r_type == BFD_RELOC_AVR_8_HI              \
1775ba6b03cSchristos        || FIXP->fx_r_type == BFD_RELOC_AVR_8_HLO             \
1782a6b7db3Sskrll        || FIXP->fx_r_type == BFD_RELOC_AVR_16_PM)            \
1795ba6b03cSchristos       && FIXP->fx_addsy != NULL				     \
1805ba6b03cSchristos       && FIXP->fx_subsy == NULL)			     \
1812a6b7db3Sskrll     {							     \
1825ba6b03cSchristos       symbol_mark_used_in_reloc (FIXP->fx_addsy);	     \
1832a6b7db3Sskrll       goto SKIP;					     \
1842a6b7db3Sskrll     }
1852a6b7db3Sskrll 
1865ba6b03cSchristos /* This macro is evaluated for any fixup with a fx_subsy that
1875ba6b03cSchristos    fixup_segment cannot reduce to a number.  If the macro returns
1885ba6b03cSchristos    false an error will be reported. */
1895ba6b03cSchristos #define TC_VALIDATE_FIX_SUB(fix, seg)   avr_validate_fix_sub (fix)
1905ba6b03cSchristos extern int avr_validate_fix_sub (struct fix *);
1915ba6b03cSchristos 
1922a6b7db3Sskrll /* This target is buggy, and sets fix size too large.  */
1932a6b7db3Sskrll #define TC_FX_SIZE_SLACK(FIX) 2
194b578a859Schristos 
195b578a859Schristos /* AVR instructions are 2 or 4 bytes long.  */
196b578a859Schristos #define DWARF2_LINE_MIN_INSN_LENGTH 	2
197b578a859Schristos 
198b578a859Schristos /* 32 bits pseudo-addresses are used on AVR.  */
199b578a859Schristos #define DWARF2_ADDR_SIZE(bfd) 4
20005caefcfSchristos 
20105caefcfSchristos /* Enable cfi directives.  */
20205caefcfSchristos #define TARGET_USE_CFIPOP 1
20305caefcfSchristos 
20405caefcfSchristos /* The stack grows down, and is only byte aligned.  */
20505caefcfSchristos #define DWARF2_CIE_DATA_ALIGNMENT -1
20605caefcfSchristos 
20705caefcfSchristos /* Define the column that represents the PC.  */
20805caefcfSchristos #define DWARF2_DEFAULT_RETURN_COLUMN  36
20905caefcfSchristos 
21005caefcfSchristos /* Define a hook to setup initial CFI state.  */
21105caefcfSchristos extern void tc_cfi_frame_initial_instructions (void);
21205caefcfSchristos #define tc_cfi_frame_initial_instructions tc_cfi_frame_initial_instructions
2135ba6b03cSchristos 
2145ba6b03cSchristos /* The difference between same-section symbols may be affected by linker
2155ba6b03cSchristos    relaxation, so do not resolve such expressions in the assembler.  */
2165ba6b03cSchristos #define md_allow_local_subtract(l,r,s) avr_allow_local_subtract (l, r, s)
217*f22f0ef4Schristos extern bool avr_allow_local_subtract (expressionS *, expressionS *, segT);
2185ba6b03cSchristos 
2195ba6b03cSchristos #define elf_tc_final_processing 	avr_elf_final_processing
2205ba6b03cSchristos extern void avr_elf_final_processing (void);
2215ba6b03cSchristos 
22298f124a6Schristos #define md_pre_output_hook avr_pre_output_hook ()
22398f124a6Schristos extern void avr_pre_output_hook (void);
22498f124a6Schristos 
22598f124a6Schristos #define md_undefined_symbol avr_undefined_symbol
22698f124a6Schristos extern symbolS* avr_undefined_symbol (char*);
22798f124a6Schristos 
2285ba6b03cSchristos #define md_post_relax_hook avr_post_relax_hook ()
2295ba6b03cSchristos extern void avr_post_relax_hook (void);
2305ba6b03cSchristos 
2315ba6b03cSchristos #define HANDLE_ALIGN(fragP) avr_handle_align (fragP)
23298f124a6Schristos extern void avr_handle_align (fragS *);
2335ba6b03cSchristos 
2345ba6b03cSchristos struct avr_frag_data
2355ba6b03cSchristos {
2365ba6b03cSchristos   unsigned is_org : 1;
2375ba6b03cSchristos   unsigned is_align : 1;
2385ba6b03cSchristos   unsigned has_fill : 1;
2395ba6b03cSchristos 
2405ba6b03cSchristos   char fill;
2415ba6b03cSchristos   offsetT alignment;
24298f124a6Schristos   unsigned int prev_opcode;
2435ba6b03cSchristos };
2445ba6b03cSchristos #define TC_FRAG_TYPE			struct avr_frag_data
245f7172901Schristos #define TC_FRAG_INIT(frag, max_bytes)	avr_frag_init (frag)
24698f124a6Schristos extern void avr_frag_init (fragS *);
247*f22f0ef4Schristos 
248*f22f0ef4Schristos #define tc_line_separator_chars avr_line_separator_chars
249*f22f0ef4Schristos extern const char *avr_line_separator_chars;
250*f22f0ef4Schristos 
251*f22f0ef4Schristos #define tc_fix_adjustable(FIX) avr_fix_adjustable (FIX)
252*f22f0ef4Schristos extern bool avr_fix_adjustable (struct fix *);
253