1 /* Definitions of target machine for GNU compiler, Lattice Mico32 architecture.
2 Contributed by Jon Beniston <jon@beniston.com>
4 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 3, or (at your
11 option) any later version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /*-------------------------------*/
23 /* Run-time Target Specification */
24 /*-------------------------------*/
26 /* Print subsidiary information on the compiler version in use. */
27 #ifndef TARGET_VERSION
28 #define TARGET_VERSION fprintf (stderr, " (LatticeMico32)")
31 /* Target CPU builtins. */
32 #define TARGET_CPU_CPP_BUILTINS() \
35 builtin_define ("__lm32__"); \
36 builtin_assert ("cpu=lm32"); \
37 builtin_assert ("machine=lm32"); \
38 if (TARGET_MULTIPLY_ENABLED) \
39 builtin_define ("__multiply_enabled__"); \
40 if (TARGET_DIVIDE_ENABLED) \
41 builtin_define ("__divide_enabled__"); \
42 if (TARGET_BARREL_SHIFT_ENABLED) \
43 builtin_define ("__barrel_shift_enabled__"); \
44 if (TARGET_SIGN_EXTEND_ENABLED) \
45 builtin_define ("__sign_extend_enabled__"); \
46 if (TARGET_USER_ENABLED) \
47 builtin_define ("__user_enabled__"); \
53 %{mmultiply-enabled} \
55 %{mbarrel-shift-enabled} \
56 %{msign-extend-enabled} \
57 %{muser-extend-enabled} \
61 /* Let link script define all link options.
62 Default to using simulator link script. */
65 #define STARTFILE_SPEC ""
67 #define ENDFILE_SPEC ""
69 #define LIB_SPEC "%{!T*:-T sim.ld}"
71 extern int target_flags;
73 /* Add -G xx support. */
75 #undef SWITCH_TAKES_ARG
76 #define SWITCH_TAKES_ARG(CHAR) \
77 (DEFAULT_SWITCH_TAKES_ARG (CHAR) || (CHAR) == 'G')
80 #define CC1_SPEC "%{G*}"
82 /*---------------------------------*/
83 /* Target machine storage layout. */
84 /*---------------------------------*/
86 #define BITS_BIG_ENDIAN 0
87 #define BYTES_BIG_ENDIAN 1
88 #define WORDS_BIG_ENDIAN 1
89 #define LIBGCC2_WORDS_BIG_ENDIAN 1
91 #define BITS_PER_UNIT 8
92 #define BITS_PER_WORD 32
93 #define UNITS_PER_WORD 4
95 #define POINTER_SIZE 32
97 #define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE) \
99 if (GET_MODE_CLASS (MODE) == MODE_INT \
100 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
101 (MODE) = word_mode; \
104 #define PARM_BOUNDARY 32
106 #define STACK_BOUNDARY 32
108 #define BIGGEST_ALIGNMENT 64
110 #define FUNCTION_BOUNDARY 32
112 #define EMPTY_FIELD_BOUNDARY 32
114 #define STRICT_ALIGNMENT 1
116 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
118 /* Make strings word-aligned so strcpy from constants will be faster. */
119 #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
120 (TREE_CODE (EXP) == STRING_CST \
121 && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN))
123 /* Make arrays and structures word-aligned to allow faster copying etc. */
124 #define DATA_ALIGNMENT(TYPE, ALIGN) \
125 ((((ALIGN) < BITS_PER_WORD) \
126 && (TREE_CODE (TYPE) == ARRAY_TYPE \
127 || TREE_CODE (TYPE) == UNION_TYPE \
128 || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
130 /* We need this for the same reason as DATA_ALIGNMENT, namely to cause
131 character arrays to be word-aligned so that `strcpy' calls that copy
132 constants to character arrays can be done inline, and 'strcmp' can be
133 optimised to use word loads. */
134 #define LOCAL_ALIGNMENT(TYPE, ALIGN) \
135 DATA_ALIGNMENT (TYPE, ALIGN)
137 /*----------------------------------------*/
138 /* Layout of source language data types. */
139 /*----------------------------------------*/
141 #define INT_TYPE_SIZE 32
142 #define SHORT_TYPE_SIZE 16
143 #define LONG_TYPE_SIZE 32
144 #define LONG_LONG_TYPE_SIZE 64
146 #define FLOAT_TYPE_SIZE 32
147 #define DOUBLE_TYPE_SIZE 64
148 #define LONG_DOUBLE_TYPE_SIZE 64
150 #define DEFAULT_SIGNED_CHAR 0
152 #define SIZE_TYPE "unsigned int"
154 #define PTRDIFF_TYPE "int"
156 /*---------------------------*/
157 /* Standard register usage. */
158 /*---------------------------*/
160 #define FIRST_PSEUDO_REGISTER 32
168 #define G_REG_P(X) ((X)<32)
170 #define FIXED_REGISTERS \
171 { 1, 0, 0, 0, 0, 0, 0, 0, \
172 0, 0, 0, 0, 0, 0, 0, 0, \
173 0, 0, 0, 0, 0, 0, 0, 0, \
174 0, 0, 1, 0, 1, 0, 1, 1}
176 #define CALL_USED_REGISTERS \
177 { 1, 1, 1, 1, 1, 1, 1, 1, \
178 1, 1, 1, 0, 0, 0, 0, 0, \
179 0, 0, 0, 0, 0, 0, 0, 0, \
180 0, 0, 1, 0, 1, 0, 1, 1}
182 #define HARD_REGNO_NREGS(REGNO, MODE) \
183 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
185 #define HARD_REGNO_MODE_OK(REGNO, MODE) G_REG_P(REGNO)
187 #define MODES_TIEABLE_P(MODE1, MODE2) \
188 ( GET_MODE_CLASS (MODE1) == MODE_INT \
189 && GET_MODE_CLASS (MODE2) == MODE_INT \
190 && GET_MODE_SIZE (MODE1) <= UNITS_PER_WORD \
191 && GET_MODE_SIZE (MODE2) <= UNITS_PER_WORD)
193 #define AVOID_CCMODE_COPIES
195 /*----------------------------------*/
196 /* Register classes and constants. */
197 /*----------------------------------*/
207 #define N_REG_CLASSES (int) LIM_REG_CLASSES
209 #define REG_CLASS_NAMES { "NO_REGS", "GENERAL_REGS", "ALL_REGS" }
211 #define REG_CLASS_CONTENTS \
217 #define REGNO_REG_CLASS(REGNO) \
218 (G_REG_P(REGNO) ? GENERAL_REGS : NO_REGS)
220 #define CLASS_MAX_NREGS(CLASS, MODE) \
221 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
223 #define INDEX_REG_CLASS NO_REGS
225 #define BASE_REG_CLASS GENERAL_REGS
227 #define REGNO_OK_FOR_BASE_P(REGNO) \
228 (G_REG_P (REGNO) || G_REG_P ((unsigned) reg_renumber[REGNO]))
230 #define REGNO_OK_FOR_INDEX_P(REGNO) 0
232 #define PREFERRED_RELOAD_CLASS(X,CLASS) (CLASS)
234 /*----------------------------------------*/
235 /* Stack Layout and Calling Conventions. */
236 /*----------------------------------------*/
238 #define STACK_GROWS_DOWNWARD 1
240 #define FRAME_GROWS_DOWNWARD 1
242 #define STACK_POINTER_OFFSET (UNITS_PER_WORD)
244 #define STARTING_FRAME_OFFSET (UNITS_PER_WORD)
246 #define FIRST_PARM_OFFSET(FNDECL) (UNITS_PER_WORD)
248 #define STACK_POINTER_REGNUM SP_REGNUM
250 #define FRAME_POINTER_REGNUM FP_REGNUM
252 #define ARG_POINTER_REGNUM FRAME_POINTER_REGNUM
254 #define RETURN_ADDR_RTX(count, frame) \
255 lm32_return_addr_rtx (count, frame)
257 /* FIXME - This is not yet supported. */
258 #define STATIC_CHAIN_REGNUM 9
260 #define ELIMINABLE_REGS \
261 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
262 { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
265 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
266 (OFFSET) = lm32_compute_initial_elimination_offset (FROM, TO)
268 /*-----------------------------*/
269 /* Function argument passing. */
270 /*-----------------------------*/
272 #define ACCUMULATE_OUTGOING_ARGS 1
274 /*--------------------------------*/
275 /* Passing Arguments in Registers */
276 /*--------------------------------*/
278 /* The first argument register. */
279 #define LM32_FIRST_ARG_REG 1
281 /* The number of (integer) argument register available. */
282 #define LM32_NUM_ARG_REGS 8
284 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
285 lm32_function_arg ((CUM), (MODE), (TYPE), (NAMED))
287 #define CUMULATIVE_ARGS int
289 #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,INDIRECT,N_NAMED_ARGS) \
292 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \
293 (CUM) += LM32_NUM_REGS2 (MODE, TYPE)
295 #define FUNCTION_ARG_REGNO_P(r) \
296 (((r) >= LM32_FIRST_ARG_REG) && ((r) <= LM32_NUM_ARG_REGS))
298 /*--------------------*/
299 /* Function results. */
300 /*--------------------*/
302 #define FUNCTION_VALUE(VALTYPE, FUNC) \
303 gen_rtx_REG ((INTEGRAL_TYPE_P (VALTYPE) \
304 && TYPE_PRECISION (VALTYPE) < BITS_PER_WORD) \
306 : TYPE_MODE (VALTYPE), \
309 #define LIBCALL_VALUE(MODE) gen_rtx_REG (MODE, RV_REGNUM)
311 #define FUNCTION_VALUE_REGNO_P(N) ((N) == RV_REGNUM)
313 #define RETURN_IN_MEMORY(TYPE) lm32_return_in_memory (TYPE)
315 #define DEFAULT_PCC_STRUCT_RETURN 0
317 /* Convert from bytes to ints. */
318 #define LM32_NUM_INTS(X) (((X) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
320 /* The number of (integer) registers required to hold a quantity of
322 #define LM32_NUM_REGS(MODE) LM32_NUM_INTS (GET_MODE_SIZE (MODE))
324 /* The number of (integer) registers required to hold a quantity of
326 #define LM32_NUM_REGS2(MODE, TYPE) \
327 LM32_NUM_INTS ((MODE) == BLKmode ? \
328 int_size_in_bytes (TYPE) : GET_MODE_SIZE (MODE))
330 #define STRUCT_VALUE 0
332 /*---------------------------*/
333 /* Function entry and exit. */
334 /*---------------------------*/
340 #define FUNCTION_PROFILER(FILE, LABELNO)
346 #define TRAMPOLINE_SIZE 0
348 /*---------------------*/
349 /* Addressing Modes. */
350 /*---------------------*/
352 #define CONSTANT_ADDRESS_P(X) \
353 ((GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \
354 || GET_CODE (X) == CONST_INT || GET_CODE (X) == HIGH \
355 || (GET_CODE (X) == CONST)))
357 #define MAX_REGS_PER_ADDRESS 1
359 #define STRICT_REG_OK_FOR_BASE_P(X) \
360 (REGNO_OK_FOR_BASE_P (REGNO (X)))
361 #define NONSTRICT_REG_OK_FOR_BASE_P(X) \
362 (G_REG_P (REGNO (X)) || !HARD_REGISTER_NUM_P (REGNO (X)))
365 #define REG_OK_FOR_BASE_P(X) STRICT_REG_OK_FOR_BASE_P(X)
367 #define REG_OK_FOR_BASE_P(X) NONSTRICT_REG_OK_FOR_BASE_P(X)
370 #define LEGITIMATE_CONSTANT_P(X) lm32_legitimate_constant_p
372 /*-------------------------*/
373 /* Condition Code Status. */
374 /*-------------------------*/
376 #define REVERSIBLE_CC_MODE(MODE) 1
382 #define SLOW_BYTE_ACCESS 1
384 #define NO_FUNCTION_CSE
386 #define BRANCH_COST(speed_p, predictable_p) 4
388 #define MOVE_RATIO(speed) (speed ? 24 : 3)
394 #define TEXT_SECTION_ASM_OP "\t.section\t.text"
395 #define DATA_SECTION_ASM_OP "\t.section\t.data"
396 #define SDATA_SECTION_ASM_OP "\t.section\t.sdata,\"aw\""
397 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
398 #define SBSS_SECTION_ASM_OP "\t.section\t.sbss,\"aw\""
404 #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? GP_REGNUM : INVALID_REGNUM)
406 #define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
408 #define LEGITIMATE_PIC_OPERAND_P(X) \
409 (!(nonpic_symbol_mentioned_p (X)))
415 #define ASM_COMMENT_START "#"
417 #define ASM_APP_ON "#APP\n"
419 #define ASM_APP_OFF "#NO_APP\n"
421 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
423 fputc ( '\t', FILE); \
424 assemble_name (FILE, LABEL1); \
425 fputs ( " = ", FILE); \
426 assemble_name (FILE, LABEL2); \
427 fputc ( '\n', FILE); \
430 /* Override default implementation in elfos.h to support -G. */
431 #undef ASM_OUTPUT_ALIGNED_LOCAL
432 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
434 if ((SIZE) <= g_switch_value) \
435 switch_to_section (sbss_section); \
437 switch_to_section (bss_section); \
438 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
439 if (!flag_inhibit_size_directive) \
440 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
441 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
442 ASM_OUTPUT_LABEL(FILE, NAME); \
443 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
446 /* Override default implementation in elfos.h to support -G. */
447 #undef ASM_OUTPUT_ALIGNED_COMMON
448 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
451 if ((SIZE) <= g_switch_value) \
453 switch_to_section (sbss_section); \
454 (*targetm.asm_out.globalize_label) (FILE, NAME); \
455 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
456 if (!flag_inhibit_size_directive) \
457 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
458 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
459 ASM_OUTPUT_LABEL(FILE, NAME); \
460 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
464 switch_to_section (bss_section); \
465 fprintf ((FILE), "%s", COMMON_ASM_OP); \
466 assemble_name ((FILE), (NAME)); \
467 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
468 (SIZE), (ALIGN) / BITS_PER_UNIT); \
473 #define ASM_OUTPUT_LABEL(FILE, NAME) \
474 do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0)
476 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
478 const char *xname = (NAME); \
479 if (xname[0] == '@') \
481 if (xname[0] == '*') \
483 fputs (xname, FILE); \
486 #define ASM_OUTPUT_SYMBOL_REF(STREAM, SYMBOL) \
488 assemble_name (STREAM, XSTR (SYMBOL, 0)); \
491 #define GLOBAL_ASM_OP "\t.global\t"
493 #define REGISTER_NAMES \
495 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
496 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \
497 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", \
498 "r24", "r25", "gp", "fp", "sp", "ra", "ea", "ba"}
500 #define PRINT_OPERAND_PUNCT_VALID_P(CHAR) \
501 (((CHAR) == '&') || ((CHAR) == '@') || ((CHAR) == '*'))
503 #define PRINT_OPERAND(FILE, X, CODE) \
504 lm32_print_operand (FILE, X, CODE)
506 #define PRINT_OPERAND_ADDRESS(FILE, ADDR) \
507 lm32_print_operand_address (FILE, ADDR)
509 #ifndef LOCAL_LABEL_PREFIX
510 #define LOCAL_LABEL_PREFIX "."
513 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
514 do { if ((LOG) != 0) fprintf (FILE, "\t.align %d\n", (1 << (LOG))); } while (0)
516 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
519 ASM_GENERATE_INTERNAL_LABEL (label, "L", VALUE); \
520 fprintf (FILE, "\n\t.word\t"); \
521 assemble_name (FILE, label); \
522 fprintf (FILE, "\n"); \
525 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
528 fprintf (FILE, "\t.word\t("); \
529 ASM_GENERATE_INTERNAL_LABEL (label, "L", VALUE); \
530 assemble_name (FILE, label); \
531 fprintf (FILE, "-"); \
532 ASM_GENERATE_INTERNAL_LABEL (label, "L", REL); \
533 assemble_name (FILE, label); \
534 fprintf (FILE, ")\n"); \
541 #define DBX_REGISTER_NUMBER(REGNO) (REGNO)
543 #define CAN_DEBUG_WITHOUT_FP
545 #define DEFAULT_GDB_EXTENSIONS 1
551 #define CASE_VECTOR_MODE Pmode
553 #define WORD_REGISTER_OPERATIONS
555 #define LOAD_EXTEND_OP(MODE) ZERO_EXTEND
557 #define SHORT_IMMEDIATES_SIGN_EXTEND
559 #define MOVE_MAX UNITS_PER_WORD
560 #define MAX_MOVE_MAX 4
562 #define SHIFT_COUNT_TRUNCATED 1
564 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
568 #define FUNCTION_MODE SImode
570 #ifndef NO_IMPLICIT_EXTERN_C
571 #define NO_IMPLICIT_EXTERN_C
574 #define STORE_FLAG_VALUE 1