1 /* Target Definitions for ft32.
2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
3 Contributed by FTDI <support@ftdi.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
25 #define STARTFILE_SPEC "crt0%O%s %{msim:crti.o%s} %{!msim:crti-hw.o%s} crtbegin.o%s"
27 /* Provide an ENDFILE_SPEC appropriate for svr4. Here we tack on our own
28 magical crtend.o file (see crtstuff.c) which provides part of the
29 support for getting C++ file-scope static object constructed before
30 entering `main', followed by the normal svr3/svr4 "finalizer" file,
31 which is either `gcrtn.o' or `crtn.o'. */
34 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
36 /* Provide a LIB_SPEC appropriate for svr4. Here we tack on the default
37 standard C library (unless we are building a shared library) and
38 the simulator BSP code. */
41 #define LIB_SPEC "%{!shared:%{!symbolic:-lc}} \
45 #define LINK_SPEC "%{h*} %{v:-V} \
46 %{static:-Bstatic} %{shared:-shared} %{symbolic:-Bsymbolic}"
48 /* Layout of Source Language Data Types */
50 #define INT_TYPE_SIZE 32
51 #define SHORT_TYPE_SIZE 16
52 #define LONG_TYPE_SIZE 32
53 #define LONG_LONG_TYPE_SIZE 64
55 #define FLOAT_TYPE_SIZE 32
56 #define DOUBLE_TYPE_SIZE 64
57 #define LONG_DOUBLE_TYPE_SIZE 64
59 #define DEFAULT_SIGNED_CHAR 1
62 #define SIZE_TYPE "unsigned int"
65 #define PTRDIFF_TYPE "int"
68 #define WCHAR_TYPE "long int"
70 #undef WCHAR_TYPE_SIZE
71 #define WCHAR_TYPE_SIZE BITS_PER_WORD
73 #define REGISTER_NAMES { \
74 "$fp", "$sp", "$r0", "$r1", \
75 "$r2", "$r3", "$r4", "$r5", \
76 "$r6", "$r7", "$r8", "$r9", \
77 "$r10", "$r11", "$r12", "$r13", \
78 "$r14", "$r15", "$r16", "$r17", "$r18", "$r19", "$r20", "$r21", "$r22", "$r23", "$r24", "$r25", "$r26", "$r27", "$r28", "$cc", \
79 "?fp", "?ap", "$pc", "?cc" }
113 #define FT32_QAP (32 + 1)
114 #define FT32_PC (32 + 2)
115 #define FT32_CC (32 + 3)
116 #define FIRST_PSEUDO_REGISTER (32 + 4)
128 #define REG_CLASS_CONTENTS \
129 { { 0x00000000, 0x00000000 }, /* Empty */ \
130 { 0xFFFFFFFF, 0x00000003 }, /* $fp, $sp, $r0 to $r13, ?fp */ \
131 { 0x00000000, 0x00000004 }, /* $pc */ \
132 { 0x00000000, 0x00000008 }, /* ?cc */ \
133 { 0xFFFFFFFF, 0x0000000F } /* All registers */ \
136 #define N_REG_CLASSES LIM_REG_CLASSES
138 #define REG_CLASS_NAMES {\
145 #define FIXED_REGISTERS /* fp sp r0 r1 */ { 1, 1, 0, 0, \
146 /* r2 r3 r4 r5 */ 0, 0, 0, 0, \
147 /* r6 r7 r8 r9 */ 0, 0, 0, 0, \
148 /* r10 r11 r12 r13 */ 0, 0, 0, 0, \
149 /* r14 r15 r16 r17 */ 0, 0, 0, 0, \
150 /* r18 r19 r20 r21 */ 0, 0, 0, 0, \
151 /* r22 r23 r24 r25 */ 0, 0, 0, 0, \
152 /* r26 r27 r28 r29 */ 0, 0, 1, 1, \
153 /* r30 r31 */ 1, 1, 1, 1 }
155 #define CALL_USED_REGISTERS \
156 /* fp sp r0 r1 */ { 1, 1, 1, 1, \
157 /* r2 r3 r4 r5 */ 1, 1, 1, 1, \
158 /* r6 r7 r8 r9 */ 1, 1, 1, 1, \
159 /* r10 r11 r12 r13 */ 1, 1, 1, 0, \
160 /* r14 r15 r16 r17 */ 0, 0, 0, 0, \
161 /* r18 r19 r20 r21 */ 0, 0, 0, 0, \
162 /* r22 r23 r24 r25 */ 0, 0, 0, 0, \
163 /* r26 r27 r28 r29 */ 0, 0, 1, 1, \
164 /* r30 r31 */ 1, 1, 1, 1 }
166 /* We can't copy to or from our CC register. */
167 #define AVOID_CCMODE_COPIES 1
169 /* A C expression whose value is a register class containing hard
171 #define REGNO_REG_CLASS(R) ((R < FT32_PC) ? GENERAL_REGS : \
172 (R == FT32_CC ? CC_REGS : SPECIAL_REGS))
174 /* A C expression for the number of consecutive hard registers,
175 starting at register number REGNO, required to hold a value of mode
177 #define HARD_REGNO_NREGS(REGNO, MODE) \
178 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
181 /* A C expression that is nonzero if a value of mode MODE1 is
182 accessible in mode MODE2 without copying. */
183 #define MODES_TIEABLE_P(MODE1, MODE2) 1
185 /* The Overall Framework of an Assembler File */
188 #define ASM_COMMENT_START "#"
189 #define ASM_APP_ON ""
190 #define ASM_APP_OFF ""
192 #define FILE_ASM_OP "\t.file\n"
194 /* Switch to the text or data segment. */
195 #define TEXT_SECTION_ASM_OP "\t.text"
196 #define DATA_SECTION_ASM_OP "\t.data"
198 /* Assembler Commands for Alignment */
200 #define ASM_OUTPUT_ALIGN(STREAM,POWER) \
201 fprintf (STREAM, "\t.p2align\t%d\n", POWER);
203 /* A C compound statement to output to stdio stream STREAM the
204 assembler syntax for an instruction operand X. */
205 #define PRINT_OPERAND(STREAM, X, CODE) ft32_print_operand (STREAM, X, CODE)
207 #define PRINT_OPERAND_ADDRESS(STREAM ,X) ft32_print_operand_address (STREAM, X)
209 /* Output and Generation of Labels */
211 #define GLOBAL_ASM_OP "\t.global\t"
213 #define JUMP_TABLES_IN_TEXT_SECTION 1
215 /* This is how to output an element of a case-vector that is absolute. */
217 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
218 fprintf (FILE, "\tjmp\t.L%d\n", VALUE); \
220 /* Passing Arguments in Registers */
222 /* A C type for declaring a variable that is used as the first
223 argument of `FUNCTION_ARG' and other related values. */
224 #define CUMULATIVE_ARGS unsigned int
226 /* If defined, the maximum amount of space required for outgoing arguments
227 will be computed and placed into the variable
228 `current_function_outgoing_args_size'. No space will be pushed
229 onto the stack for each call; instead, the function prologue should
230 increase the stack frame size by this amount. */
231 #define ACCUMULATE_OUTGOING_ARGS 1
233 /* A C statement (sans semicolon) for initializing the variable CUM
234 for the state at the beginning of the argument list.
235 For ft32, the first arg is passed in register 2 (aka $r0). */
236 #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,FNDECL,N_NAMED_ARGS) \
239 /* How Scalar Function Values Are Returned */
241 /* STACK AND CALLING */
243 /* Define this macro if pushing a word onto the stack moves the stack
244 pointer to a smaller address. */
245 #define STACK_GROWS_DOWNWARD 1
247 /* Offset from the frame pointer to the first local variable slot to
249 #define STARTING_FRAME_OFFSET 0
251 /* Offset from the argument pointer register to the first argument's
252 address. On some machines it may depend on the data type of the
254 #define FIRST_PARM_OFFSET(F) 0
256 /* Define this macro to nonzero value if the addresses of local variable slots
257 are at negative offsets from the frame pointer. */
258 #define FRAME_GROWS_DOWNWARD 1
260 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
261 the stack pointer does not matter. The value is tested only in
262 functions that have frame pointers.
263 No definition is equivalent to always zero. */
265 #define EXIT_IGNORE_STACK 0
267 /* Define this macro as a C expression that is nonzero for registers that are
268 used by the epilogue or the return pattern. The stack and frame
269 pointer registers are already assumed to be used as needed. */
270 #define EPILOGUE_USES(R) (R == FT32_R5)
272 /* A C expression whose value is RTL representing the location of the
273 incoming return address at the beginning of any function, before
275 #define INCOMING_RETURN_ADDR_RTX \
276 gen_frame_mem (Pmode, \
277 plus_constant (Pmode, stack_pointer_rtx, 333 * UNITS_PER_WORD))
279 #define RETURN_ADDR_RTX(COUNT, FRAMEADDR) \
281 ? gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, arg_pointer_rtx, GEN_INT (-4))) \
284 /* Describe how we implement __builtin_eh_return. */
285 #define EH_RETURN_DATA_REGNO(N) ((N) < 4 ? (N+2) : INVALID_REGNUM)
287 /* Store the return handler into the call frame. */
288 #define EH_RETURN_HANDLER_RTX \
289 gen_frame_mem (Pmode, \
290 plus_constant (Pmode, frame_pointer_rtx, UNITS_PER_WORD))
294 #define BITS_BIG_ENDIAN 0
295 #define BYTES_BIG_ENDIAN 0
296 #define WORDS_BIG_ENDIAN 0
298 /* Alignment required for a function entry point, in bits. */
299 #define FUNCTION_BOUNDARY 32
301 #define BRANCH_COST(speed_p, predictable_p) 2
303 /* Define this macro as a C expression which is nonzero if accessing
304 less than a word of memory (i.e. a `char' or a `short') is no
305 faster than accessing a word of memory. */
306 #define SLOW_BYTE_ACCESS 1
308 #define STORE_FLAG_VALUE 1
310 #define MOVE_RATIO(speed) ((speed) ? 6 : 2)
312 /* Number of storage units in a word; normally the size of a
313 general-purpose register, a power of two from 1 or 8. */
314 #define UNITS_PER_WORD 4
316 /* Define this macro to the minimum alignment enforced by hardware
317 for the stack pointer on this machine. The definition is a C
318 expression for the desired alignment (measured in bits). */
319 #define STACK_BOUNDARY 32
321 /* Normal alignment required for function parameters on the stack, in
322 bits. All stack parameters receive at least this much alignment
323 regardless of data type. */
324 #define PARM_BOUNDARY 32
326 /* Alignment of field after `int : 0' in a structure. */
327 #define EMPTY_FIELD_BOUNDARY 32
329 /* No data type wants to be aligned rounder than this. */
330 #define BIGGEST_ALIGNMENT 32
332 /* The best alignment to use in cases where we have a choice. */
333 #define FASTEST_ALIGNMENT 32
335 /* Align definitions of arrays, unions and structures so that
336 initializations and copies can be made more efficient. This is not
337 ABI-changing, so it only affects places where we can see the
338 definition. Increasing the alignment tends to introduce padding,
339 so don't do this when optimizing for size/conserving stack space. */
340 #define FT32_EXPAND_ALIGNMENT(COND, EXP, ALIGN) \
341 (((COND) && ((ALIGN) < BITS_PER_WORD) \
342 && (TREE_CODE (EXP) == ARRAY_TYPE \
343 || TREE_CODE (EXP) == UNION_TYPE \
344 || TREE_CODE (EXP) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
346 /* Make arrays of chars word-aligned for the same reasons. */
347 #define DATA_ALIGNMENT(TYPE, ALIGN) \
348 (TREE_CODE (TYPE) == ARRAY_TYPE \
349 && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
350 && (ALIGN) < FASTEST_ALIGNMENT ? FASTEST_ALIGNMENT : (ALIGN))
352 /* Similarly, make sure that objects on the stack are sensibly aligned. */
353 #define LOCAL_ALIGNMENT(EXP, ALIGN) \
354 FT32_EXPAND_ALIGNMENT(/*!flag_conserve_stack*/ 1, EXP, ALIGN)
356 /* Every structures size must be a multiple of 8 bits. */
357 #define STRUCTURE_SIZE_BOUNDARY 8
359 /* Look at the fundamental type that is used for a bit-field and use
360 that to impose alignment on the enclosing structure.
361 struct s {int a:8}; should have same alignment as "int", not "char". */
362 #define PCC_BITFIELD_TYPE_MATTERS 1
364 /* Largest integer machine mode for structures. If undefined, the default
365 is GET_MODE_SIZE(DImode). */
366 #define MAX_FIXED_MODE_SIZE 32
368 /* Make strings word-aligned so strcpy from constants will be faster. */
369 #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
370 ((TREE_CODE (EXP) == STRING_CST \
371 && (ALIGN) < FASTEST_ALIGNMENT) \
372 ? FASTEST_ALIGNMENT : (ALIGN))
374 /* Set this nonzero if move instructions will actually fail to work
375 when given unaligned data. */
376 #define STRICT_ALIGNMENT 1
378 /* Generating Code for Profiling */
379 #define FUNCTION_PROFILER(FILE,LABELNO) (abort (), 0)
381 /* Trampolines for Nested Functions. */
382 #define TRAMPOLINE_SIZE (2 + 6 + 6 + 2 + 2 + 6)
384 /* Alignment required for trampolines, in bits. */
385 #define TRAMPOLINE_ALIGNMENT 32
387 /* An alias for the machine mode for pointers. */
390 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
392 if (((MODE) == HImode) \
393 || ((MODE) == QImode)) \
397 /* An alias for the machine mode used for memory references to
398 functions being called, in `call' RTL expressions. */
399 #define FUNCTION_MODE QImode
401 #define STATIC_CHAIN_REGNUM FT32_R28
403 /* The register number of the stack pointer register, which must also
404 be a fixed register according to `FIXED_REGISTERS'. */
405 #define STACK_POINTER_REGNUM FT32_SP
407 /* The register number of the frame pointer register, which is used to
408 access automatic variables in the stack frame. */
409 #define FRAME_POINTER_REGNUM FT32_FP
411 /* The register number of the arg pointer register, which is used to
412 access the function's argument list. */
413 #define ARG_POINTER_REGNUM FT32_QAP
415 #define ELIMINABLE_REGS \
416 {{ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
417 {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
418 {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}}
421 /* This macro returns the initial difference between the specified pair
423 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
425 (OFFSET) = ft32_initial_elimination_offset ((FROM), (TO)); \
428 /* A C expression that is nonzero if REGNO is the number of a hard
429 register in which function arguments are sometimes passed. */
430 #define FUNCTION_ARG_REGNO_P(r) (r >= FT32_R0 && r <= FT32_R5)
432 /* A macro whose definition is the name of the class to which a valid
433 base register must belong. A base register is one used in an
434 address which is the register value plus a displacement. */
435 #define BASE_REG_CLASS GENERAL_REGS
437 #define INDEX_REG_CLASS NO_REGS
439 #define HARD_REGNO_OK_FOR_BASE_P(NUM) \
440 ((unsigned) (NUM) < FIRST_PSEUDO_REGISTER \
441 && (REGNO_REG_CLASS(NUM) == GENERAL_REGS \
442 || (NUM) == HARD_FRAME_POINTER_REGNUM))
444 /* A C expression which is nonzero if register number NUM is suitable
445 for use as a base register in operand addresses. */
447 #define REGNO_OK_FOR_BASE_P(NUM) \
448 (HARD_REGNO_OK_FOR_BASE_P(NUM) \
449 || HARD_REGNO_OK_FOR_BASE_P(reg_renumber[(NUM)]))
451 #define REGNO_OK_FOR_BASE_P(NUM) \
452 ((NUM) >= FIRST_PSEUDO_REGISTER || HARD_REGNO_OK_FOR_BASE_P(NUM))
455 /* A C expression which is nonzero if register number NUM is suitable
456 for use as an index register in operand addresses. */
457 #define REGNO_OK_FOR_INDEX_P(NUM) FT32_FP
459 /* The maximum number of bytes that a single instruction can move
460 quickly between memory and registers or between two memory
463 #define TRULY_NOOP_TRUNCATION(op,ip) 1
465 /* Define this to be nonzero if shift instructions ignore all but the low-order
467 #define SHIFT_COUNT_TRUNCATED 1
469 /* All load operations zero extend. */
470 #define LOAD_EXTEND_OP(MEM) ZERO_EXTEND
472 /* A number, the maximum number of registers that can appear in a
473 valid memory address. */
474 #define MAX_REGS_PER_ADDRESS 1
476 /* An alias for a machine mode name. This is the machine mode that
477 elements of a jump-table should have. */
478 #define CASE_VECTOR_MODE SImode
480 /* Run-time Target Specification */
482 #define TARGET_CPU_CPP_BUILTINS() \
484 builtin_define ("__FT32__"); \
487 #define HAS_LONG_UNCOND_BRANCH true
489 #define NO_FUNCTION_CSE 1
491 #define ADDR_SPACE_PM 1
493 #define REGISTER_TARGET_PRAGMAS() do { \
494 c_register_addr_space ("__flash__", ADDR_SPACE_PM); \
497 extern int ft32_is_mem_pm(rtx o
);
499 #define ASM_OUTPUT_SYMBOL_REF(stream, sym) \
501 assemble_name (stream, XSTR (sym, 0)); \
502 int section_debug = in_section && \
503 (SECTION_STYLE (in_section) == SECTION_NAMED) && \
504 (in_section->named.common.flags & SECTION_DEBUG); \
505 if (!section_debug && SYMBOL_REF_FLAGS (sym) & 0x1000) \
506 asm_fprintf (stream, "-0x800000"); \
509 #endif /* GCC_FT32_H */