1440a403fSchristos /* tc-riscv.h -- header file for tc-riscv.c.
2*b88e3e88Schristos    Copyright (C) 2011-2020 Free Software Foundation, Inc.
3440a403fSchristos 
406324dcfSchristos    Contributed by Andrew Waterman (andrew@sifive.com).
5440a403fSchristos    Based on MIPS target.
6440a403fSchristos 
7440a403fSchristos    This file is part of GAS.
8440a403fSchristos 
9440a403fSchristos    GAS is free software; you can redistribute it and/or modify
10440a403fSchristos    it under the terms of the GNU General Public License as published by
11440a403fSchristos    the Free Software Foundation; either version 3, or (at your option)
12440a403fSchristos    any later version.
13440a403fSchristos 
14440a403fSchristos    GAS is distributed in the hope that it will be useful,
15440a403fSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
16440a403fSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17440a403fSchristos    GNU General Public License for more details.
18440a403fSchristos 
19440a403fSchristos    You should have received a copy of the GNU General Public License
2006324dcfSchristos    along with this program; see the file COPYING3. If not,
2106324dcfSchristos    see <http://www.gnu.org/licenses/>.  */
22440a403fSchristos 
23440a403fSchristos #ifndef TC_RISCV
24440a403fSchristos #define TC_RISCV
25440a403fSchristos 
26440a403fSchristos #include "opcode/riscv.h"
27440a403fSchristos 
28440a403fSchristos struct frag;
29440a403fSchristos struct expressionS;
30440a403fSchristos 
31440a403fSchristos #define TARGET_BYTES_BIG_ENDIAN 0
32440a403fSchristos 
33440a403fSchristos #define TARGET_ARCH bfd_arch_riscv
34440a403fSchristos 
35440a403fSchristos #define WORKING_DOT_WORD	1
36440a403fSchristos #define LOCAL_LABELS_FB 	1
3706324dcfSchristos 
3806324dcfSchristos /* Symbols named FAKE_LABEL_NAME are emitted when generating DWARF, so make
3906324dcfSchristos    sure FAKE_LABEL_NAME is printable.  It still must be distinct from any
4006324dcfSchristos    real label name.  So, append a space, which other labels can't contain.  */
41*b88e3e88Schristos #define FAKE_LABEL_NAME RISCV_FAKE_LABEL_NAME
4206324dcfSchristos /* Changing the special character in FAKE_LABEL_NAME requires changing
4306324dcfSchristos    FAKE_LABEL_CHAR too.  */
44*b88e3e88Schristos #define FAKE_LABEL_CHAR RISCV_FAKE_LABEL_CHAR
45440a403fSchristos 
46440a403fSchristos #define md_relax_frag(segment, fragp, stretch) \
47440a403fSchristos   riscv_relax_frag (segment, fragp, stretch)
48440a403fSchristos extern int riscv_relax_frag (asection *, struct frag *, long);
49440a403fSchristos 
50440a403fSchristos #define md_section_align(seg,size)	(size)
51440a403fSchristos #define md_undefined_symbol(name)	(0)
52440a403fSchristos #define md_operand(x)
53440a403fSchristos 
5406324dcfSchristos extern bfd_boolean riscv_frag_align_code (int);
5506324dcfSchristos #define md_do_align(N, FILL, LEN, MAX, LABEL)				\
5606324dcfSchristos   if ((N) != 0 && !(FILL) && !need_pass_2 && subseg_text_p (now_seg))	\
5706324dcfSchristos     {									\
5806324dcfSchristos       if (riscv_frag_align_code (N))					\
5906324dcfSchristos 	goto LABEL;							\
6006324dcfSchristos     }
61440a403fSchristos 
6206324dcfSchristos extern void riscv_handle_align (fragS *);
6306324dcfSchristos #define HANDLE_ALIGN riscv_handle_align
6406324dcfSchristos 
6506324dcfSchristos #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4)
66440a403fSchristos 
67440a403fSchristos /* The ISA of the target may change based on command-line arguments.  */
68440a403fSchristos #define TARGET_FORMAT riscv_target_format()
69440a403fSchristos extern const char * riscv_target_format (void);
70440a403fSchristos 
71440a403fSchristos #define md_after_parse_args() riscv_after_parse_args()
72440a403fSchristos extern void riscv_after_parse_args (void);
73440a403fSchristos 
74440a403fSchristos #define md_parse_long_option(arg) riscv_parse_long_option (arg)
75440a403fSchristos extern int riscv_parse_long_option (const char *);
76440a403fSchristos 
7706324dcfSchristos #define md_pre_output_hook riscv_pre_output_hook()
7806324dcfSchristos extern void riscv_pre_output_hook (void);
7906324dcfSchristos 
80440a403fSchristos /* Let the linker resolve all the relocs due to relaxation.  */
81440a403fSchristos #define tc_fix_adjustable(fixp) 0
82440a403fSchristos #define md_allow_local_subtract(l,r,s) 0
83440a403fSchristos 
84440a403fSchristos /* Values passed to md_apply_fix don't include symbol values.  */
85440a403fSchristos #define MD_APPLY_SYM_VALUE(FIX) 0
86440a403fSchristos 
87440a403fSchristos /* Global syms must not be resolved, to support ELF shared libraries.  */
88440a403fSchristos #define EXTERN_FORCE_RELOC			\
89440a403fSchristos   (OUTPUT_FLAVOR == bfd_target_elf_flavour)
90440a403fSchristos 
9106324dcfSchristos /* Postpone text-section label subtraction calculation until linking, since
9206324dcfSchristos    linker relaxations might change the deltas.  */
9306324dcfSchristos #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG)	\
9406324dcfSchristos   (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEG)	\
9506324dcfSchristos    || ((SEG)->flags & SEC_CODE) != 0)
96440a403fSchristos #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) 1
97440a403fSchristos #define TC_VALIDATE_FIX_SUB(FIX, SEG) 1
98440a403fSchristos #define TC_FORCE_RELOCATION_LOCAL(FIX) 1
99440a403fSchristos #define DIFF_EXPR_OK 1
100440a403fSchristos 
101440a403fSchristos extern void riscv_pop_insert (void);
102440a403fSchristos #define md_pop_insert()		riscv_pop_insert ()
103440a403fSchristos 
104440a403fSchristos #define TARGET_USE_CFIPOP 1
105440a403fSchristos 
106440a403fSchristos #define tc_cfi_frame_initial_instructions riscv_cfi_frame_initial_instructions
107440a403fSchristos extern void riscv_cfi_frame_initial_instructions (void);
108440a403fSchristos 
109440a403fSchristos #define tc_regname_to_dw2regnum tc_riscv_regname_to_dw2regnum
11006324dcfSchristos extern int tc_riscv_regname_to_dw2regnum (char *);
111440a403fSchristos 
112440a403fSchristos #define DWARF2_DEFAULT_RETURN_COLUMN X_RA
11306324dcfSchristos 
11406324dcfSchristos /* Even on RV64, use 4-byte alignment, as F registers may be only 32 bits.  */
11506324dcfSchristos #define DWARF2_CIE_DATA_ALIGNMENT -4
116440a403fSchristos 
117440a403fSchristos #define elf_tc_final_processing riscv_elf_final_processing
118440a403fSchristos extern void riscv_elf_final_processing (void);
119440a403fSchristos 
12006324dcfSchristos /* Adjust debug_line after relaxation.  */
12106324dcfSchristos #define DWARF2_USE_FIXED_ADVANCE_PC 1
12206324dcfSchristos 
123*b88e3e88Schristos #define md_end riscv_md_end
124*b88e3e88Schristos #define CONVERT_SYMBOLIC_ATTRIBUTE riscv_convert_symbolic_attribute
125*b88e3e88Schristos 
126*b88e3e88Schristos extern void riscv_md_end (void);
127*b88e3e88Schristos extern int riscv_convert_symbolic_attribute (const char *);
128*b88e3e88Schristos 
129440a403fSchristos #endif /* TC_RISCV */
130