1 /* Definitions for TI PRU assembler.
2    Copyright (C) 2014-2021 Free Software Foundation, Inc.
3    Contributed by Dimitar Dimitrov <dimitar@dinux.eu>
4 
5    This file is part of GAS, the GNU Assembler.
6 
7    GAS is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11 
12    GAS is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with GAS; see the file COPYING.  If not, write to the Free
19    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20    02110-1301, USA.  */
21 
22 #ifndef __TC_PRU__
23 #define __TC_PRU__
24 
25 #define TARGET_BYTES_BIG_ENDIAN 0
26 
27 /* Words are big enough to hold addresses.  */
28 #define WORKING_DOT_WORD	1
29 
30 extern const char *pru_target_format (void);
31 #define TARGET_FORMAT  pru_target_format ()
32 #define TARGET_ARCH    bfd_arch_pru
33 
34 /* A PRU instruction consists of tokens and separator characters
35    the tokens are things like the instruction name (add, or jmp etc),
36    the register indices ($5, $7 etc), and constant expressions.  The
37    separator characters are commas, brackets and space.
38    The instruction name is always separated from other tokens by a space
39    The maximum number of tokens in an instruction is 6 (the instruction name,
40    4 arguments, and a 4th string representing the expected instruction opcode
41    after assembly.  The latter is only used when the assemble is running in
42    self test mode, otherwise its presence will generate an error.  */
43 #define PRU_MAX_INSN_TOKENS	7
44 
45 /* There are no machine-specific operands so we #define this to nothing.  */
46 #define md_operand(x)
47 
48 /* Function prototypes exported to rest of GAS.  */
49 extern void md_assemble (char *op_str);
50 extern void md_end (void);
51 extern void md_begin (void);
52 
53 #define tc_fix_adjustable(fixp) pru_fix_adjustable (fixp)
54 extern int pru_fix_adjustable (struct fix *);
55 
56 #define tc_frob_label(lab) pru_frob_label (lab)
57 extern void pru_frob_label (symbolS *);
58 
59 extern void md_convert_frag (bfd * headers, segT sec, fragS * fragP);
60 
61 #define DIFF_EXPR_OK
62 
63 /* FIXME This seems appropriate, given that we intentionally prevent
64    PRU's .text from being used in a DIFF expression with symbols from
65    other sections.  Revisit once GDB is ported.  */
66 #define CFI_DIFF_EXPR_OK 0
67 
68 #define TC_PARSE_CONS_RETURN_TYPE int
69 #define TC_PARSE_CONS_RETURN_NONE 0
70 
71 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
72 	pru_parse_cons_expression (EXP, NBYTES)
73 extern int pru_parse_cons_expression (expressionS *exp, int size);
74 
75 #define TC_CONS_FIX_NEW pru_cons_fix_new
76 extern void pru_cons_fix_new (struct frag *frag, int where,
77 				unsigned int nbytes, struct expressionS *exp,
78 				const int is_pmem);
79 
80 /* If you define this macro, it means that `tc_gen_reloc' may return
81    multiple relocation entries for a single fixup.  In this case, the
82    return value of `tc_gen_reloc' is a pointer to a null terminated
83    array.  */
84 #undef RELOC_EXPANSION_POSSIBLE
85 
86 /* No shared lib support, so we don't need to ensure externally
87    visible symbols can be overridden.  */
88 #define EXTERN_FORCE_RELOC 0
89 
90 /* If defined, this macro allows control over whether fixups for a
91    given section will be processed when the linkrelax variable is
92    set.  Define it to zero and handle things in md_apply_fix instead.  */
93 #define TC_LINKRELAX_FIXUP(SEG) 0
94 
95 /* If this macro returns non-zero, it guarantees that a relocation will be
96    emitted even when the value can be resolved locally.  Do that if
97    linkrelax is turned on.  */
98 #define TC_FORCE_RELOCATION(fix)	pru_force_relocation (fix)
99 #define TC_FORCE_RELOCATION_SUB_SAME(fix, seg) \
100   (GENERIC_FORCE_RELOCATION_SUB_SAME (fix, seg) || pru_force_relocation (fix))
101 extern int pru_force_relocation (struct fix *);
102 
103 /* Do not use PC relative fixups and relocations for
104    anything but real PCREL relocations.  */
105 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \
106   (((FIX)->fx_r_type != BFD_RELOC_PRU_S10_PCREL) \
107    && ((FIX)->fx_r_type != BFD_RELOC_PRU_U8_PCREL))
108 
109 /* Values passed to md_apply_fix don't include the symbol value.  */
110 #define MD_APPLY_SYM_VALUE(FIX) 0
111 
112 /* We don't want gas to fixup the following memory related relocations.
113    We will need them in case that we want to do linker relaxation.
114    We could in principle keep these fixups in gas when not relaxing.
115    However, there is no serious performance penalty when making the linker
116    make the fixup work.  Check also that fx_addsy is not NULL, in order to
117    make sure that the fixup refers to some sort of label.  */
118 #define TC_VALIDATE_FIX(FIXP,SEG,SKIP)			      \
119   if ((FIXP->fx_r_type == BFD_RELOC_PRU_LDI32		      \
120        || FIXP->fx_r_type == BFD_RELOC_PRU_U16		      \
121        || FIXP->fx_r_type == BFD_RELOC_PRU_U16_PMEMIMM	      \
122        || FIXP->fx_r_type == BFD_RELOC_PRU_S10_PCREL	      \
123        || FIXP->fx_r_type == BFD_RELOC_PRU_U8_PCREL	      \
124        || FIXP->fx_r_type == BFD_RELOC_PRU_32_PMEM	      \
125        || FIXP->fx_r_type == BFD_RELOC_PRU_16_PMEM)	      \
126       && FIXP->fx_addsy != NULL				      \
127       && FIXP->fx_subsy == NULL)			      \
128     {							      \
129       symbol_mark_used_in_reloc (FIXP->fx_addsy);	      \
130       goto SKIP;					      \
131     }
132 
133 /* This macro is evaluated for any fixup with a fx_subsy that
134    fixup_segment cannot reduce to a number.  If the macro returns
135    false an error will be reported.  */
136 #define TC_VALIDATE_FIX_SUB(fix, seg)   pru_validate_fix_sub (fix)
137 extern int pru_validate_fix_sub (struct fix *);
138 
139 /* We want .cfi_* pseudo-ops for generating unwind info.  */
140 #define TARGET_USE_CFIPOP 1
141 
142 /* Program Counter register number is not defined by TI documents.
143    Pick the virtual number used by GCC.  */
144 #define DWARF2_DEFAULT_RETURN_COLUMN 132
145 
146 /* The stack grows down, and is only byte aligned.  */
147 #define DWARF2_CIE_DATA_ALIGNMENT -1
148 
149 #define tc_regname_to_dw2regnum pru_regname_to_dw2regnum
150 extern int pru_regname_to_dw2regnum (char *regname);
151 #define tc_cfi_frame_initial_instructions  pru_frame_initial_instructions
152 extern void pru_frame_initial_instructions (void);
153 
154 /* The difference between same-section symbols may be affected by linker
155    relaxation, so do not resolve such expressions in the assembler.  */
156 #define md_allow_local_subtract(l,r,s) pru_allow_local_subtract (l, r, s)
157 extern bool pru_allow_local_subtract (expressionS *, expressionS *, segT);
158 
159 #endif /* __TC_PRU__ */
160