]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/nios2/nios2.h
nios2.h (BITS_PER_UNIT): Don't define it.
[thirdparty/gcc.git] / gcc / config / nios2 / nios2.h
1 /* Definitions of target machine for Altera Nios II.
2 Copyright (C) 2012-2013 Free Software Foundation, Inc.
3 Contributed by Jonah Graham (jgraham@altera.com),
4 Will Reece (wreece@altera.com), and Jeff DaSilva (jdasilva@altera.com).
5 Contributed by Mentor Graphics, Inc.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 3, or (at your
12 option) any later version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 #ifndef GCC_NIOS2_H
24 #define GCC_NIOS2_H
25
26 /* FPU insn codes declared here. */
27 #include "config/nios2/nios2-opts.h"
28
29 /* Define built-in preprocessor macros. */
30 #define TARGET_CPU_CPP_BUILTINS() \
31 do \
32 { \
33 builtin_define_std ("NIOS2"); \
34 builtin_define_std ("nios2"); \
35 if (TARGET_BIG_ENDIAN) \
36 builtin_define_std ("nios2_big_endian"); \
37 else \
38 builtin_define_std ("nios2_little_endian"); \
39 } \
40 while (0)
41
42 /* We're little endian, unless otherwise specified by defining
43 BIG_ENDIAN_FLAG. */
44 #ifndef TARGET_ENDIAN_DEFAULT
45 # define TARGET_ENDIAN_DEFAULT 0
46 #endif
47
48 /* Default target_flags if no switches specified. */
49 #ifndef TARGET_DEFAULT
50 # define TARGET_DEFAULT (MASK_HAS_MUL | TARGET_ENDIAN_DEFAULT)
51 #endif
52
53 #define CC1_SPEC "%{G*}"
54
55 #if TARGET_ENDIAN_DEFAULT == 0
56 # define ASM_SPEC "%{!meb:-EL} %{meb:-EB}"
57 # define LINK_SPEC_ENDIAN "%{!meb:-EL} %{meb:-EB}"
58 # define MULTILIB_DEFAULTS { "EL" }
59 #else
60 # define ASM_SPEC "%{!mel:-EB} %{mel:-EL}"
61 # define LINK_SPEC_ENDIAN "%{!mel:-EB} %{mel:-EL}"
62 # define MULTILIB_DEFAULTS { "EB" }
63 #endif
64
65 #define LINK_SPEC LINK_SPEC_ENDIAN \
66 " %{shared:-shared} \
67 %{static:-Bstatic}"
68
69
70 /* Storage layout. */
71
72 #define DEFAULT_SIGNED_CHAR 1
73 #define BITS_BIG_ENDIAN 0
74 #define BYTES_BIG_ENDIAN (TARGET_BIG_ENDIAN != 0)
75 #define WORDS_BIG_ENDIAN (TARGET_BIG_ENDIAN != 0)
76 #define BITS_PER_WORD 32
77 #define UNITS_PER_WORD 4
78 #define POINTER_SIZE 32
79 #define BIGGEST_ALIGNMENT 32
80 #define STRICT_ALIGNMENT 1
81 #define FUNCTION_BOUNDARY 32
82 #define PARM_BOUNDARY 32
83 #define STACK_BOUNDARY 32
84 #define PREFERRED_STACK_BOUNDARY 32
85 #define MAX_FIXED_MODE_SIZE 64
86
87 #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
88 ((TREE_CODE (EXP) == STRING_CST) \
89 && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN))
90
91 /* Layout of source language data types. */
92
93 #define INT_TYPE_SIZE 32
94 #define SHORT_TYPE_SIZE 16
95 #define LONG_TYPE_SIZE 32
96 #define LONG_LONG_TYPE_SIZE 64
97 #define FLOAT_TYPE_SIZE 32
98 #define DOUBLE_TYPE_SIZE 64
99 #define LONG_DOUBLE_TYPE_SIZE DOUBLE_TYPE_SIZE
100
101 #undef SIZE_TYPE
102 #define SIZE_TYPE "unsigned int"
103
104 #undef PTRDIFF_TYPE
105 #define PTRDIFF_TYPE "int"
106
107
108 /* Basic characteristics of Nios II registers:
109
110 Regno Name
111 0 r0 zero always zero
112 1 r1 at Assembler Temporary
113 2-3 r2-r3 Return Location
114 4-7 r4-r7 Register Arguments
115 8-15 r8-r15 Caller Saved Registers
116 16-22 r16-r22 Callee Saved Registers
117 22 r22 Global Offset Table pointer (Linux ABI only)
118 23 r23 Thread pointer (Linux ABI only)
119 24 r24 et Exception Temporary
120 25 r25 bt Breakpoint Temporary
121 26 r26 gp Global Pointer
122 27 r27 sp Stack Pointer
123 28 r28 fp Frame Pointer
124 29 r29 ea Exception Return Address
125 30 r30 ba Breakpoint Return Address
126 31 r31 ra Return Address
127
128 32 ctl0 status
129 33 ctl1 estatus STATUS saved by exception
130 34 ctl2 bstatus STATUS saved by break
131 35 ctl3 ipri Interrupt Priority Mask
132 36 ctl4 ecause Exception Cause
133
134 37 pc Not an actual register
135
136 38 fake_fp Fake Frame Pointer (always eliminated)
137 39 fake_ap Fake Argument Pointer (always eliminated)
138 40 First Pseudo Register
139
140 In addition, r12 is used as the static chain register and r13, r14, and r15
141 are clobbered by PLT code sequences.
142
143 The definitions for all the hard register numbers are located in nios2.md.
144 */
145
146 #define FIXED_REGISTERS \
147 { \
148 /* +0 1 2 3 4 5 6 7 8 9 */ \
149 /* 0 */ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, \
150 /* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
151 /* 20 */ 0, 0, TARGET_LINUX_ABI, TARGET_LINUX_ABI, 1, 1, 1, 1, 0, 1, \
152 /* 30 */ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, \
153 }
154
155 /* Call used == caller saved + fixed regs + args + ret vals. */
156 #define CALL_USED_REGISTERS \
157 { \
158 /* +0 1 2 3 4 5 6 7 8 9 */ \
159 /* 0 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
160 /* 10 */ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, \
161 /* 20 */ 0, 0, TARGET_LINUX_ABI, TARGET_LINUX_ABI, 1, 1, 1, 1, 0, 1, \
162 /* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
163 }
164
165 #define MODES_TIEABLE_P(MODE1, MODE2) 1
166 #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
167 #define HARD_REGNO_NREGS(REGNO, MODE) \
168 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
169
170 /* Register Classes. */
171
172 enum reg_class
173 {
174 NO_REGS,
175 SIB_REGS,
176 GP_REGS,
177 ALL_REGS,
178 LIM_REG_CLASSES
179 };
180
181 #define N_REG_CLASSES (int) LIM_REG_CLASSES
182
183 #define REG_CLASS_NAMES \
184 { "NO_REGS", \
185 "SIB_REGS", \
186 "GP_REGS", \
187 "ALL_REGS" }
188
189 #define GENERAL_REGS ALL_REGS
190
191 #define REG_CLASS_CONTENTS \
192 { \
193 /* NO_REGS */ { 0, 0}, \
194 /* SIB_REGS */ { 0xfe0c, 0}, \
195 /* GP_REGS */ {~0, 0}, \
196 /* ALL_REGS */ {~0,~0} \
197 }
198
199
200 #define GP_REG_P(REGNO) ((unsigned)(REGNO) <= LAST_GP_REG)
201 #define REGNO_REG_CLASS(REGNO) (GP_REG_P (REGNO) ? GP_REGS : ALL_REGS)
202 #define CLASS_MAX_NREGS(CLASS, MODE) \
203 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
204
205 /* Tests for various kinds of constants used in the Nios II port. */
206
207 #define SMALL_INT(X) ((unsigned HOST_WIDE_INT)(X) + 0x8000 < 0x10000)
208 #define SMALL_INT_UNSIGNED(X) ((X) >= 0 && (X) < 0x10000)
209 #define UPPER16_INT(X) (((X) & 0xffff) == 0)
210 #define SHIFT_INT(X) ((X) >= 0 && (X) <= 31)
211 #define RDWRCTL_INT(X) ((X) >= 0 && (X) <= 31)
212 #define CUSTOM_INSN_OPCODE(X) ((X) >= 0 && (X) <= 255)
213
214 /* Say that the epilogue uses the return address register. Note that
215 in the case of sibcalls, the values "used by the epilogue" are
216 considered live at the start of the called function. */
217 #define EPILOGUE_USES(REGNO) (epilogue_completed && (REGNO) == RA_REGNO)
218
219 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
220 the stack pointer does not matter. The value is tested only in
221 functions that have frame pointers.
222 No definition is equivalent to always zero. */
223
224 #define EXIT_IGNORE_STACK 1
225
226 /* Trampolines use a 5-instruction sequence. */
227 #define TRAMPOLINE_SIZE 20
228
229 /* Stack layout. */
230 #define STACK_GROWS_DOWNWARD
231 #define STARTING_FRAME_OFFSET 0
232 #define FIRST_PARM_OFFSET(FUNDECL) 0
233
234 /* Before the prologue, RA lives in r31. */
235 #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (VOIDmode, RA_REGNO)
236 #define RETURN_ADDR_RTX(C,F) nios2_get_return_address (C)
237
238 #define DWARF_FRAME_RETURN_COLUMN RA_REGNO
239
240 /* The CFA includes the pretend args. */
241 #define ARG_POINTER_CFA_OFFSET(FNDECL) \
242 (gcc_assert ((FNDECL) == current_function_decl), \
243 FIRST_PARM_OFFSET (FNDECL) + crtl->args.pretend_args_size)
244
245 /* Frame/arg pointer elimination settings. */
246 #define ELIMINABLE_REGS \
247 {{ ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
248 { ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
249 { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
250 { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}}
251
252 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
253 (OFFSET) = nios2_initial_elimination_offset ((FROM), (TO))
254
255 /* Calling convention definitions. */
256 typedef struct nios2_args
257 {
258 int regs_used;
259 } CUMULATIVE_ARGS;
260
261 #define NUM_ARG_REGS (LAST_ARG_REGNO - FIRST_ARG_REGNO + 1)
262
263 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
264 do { (CUM).regs_used = 0; } while (0)
265
266 #define FUNCTION_ARG_PADDING(MODE, TYPE) \
267 (nios2_function_arg_padding ((MODE), (TYPE)))
268
269 #define PAD_VARARGS_DOWN \
270 (FUNCTION_ARG_PADDING (TYPE_MODE (type), type) == downward)
271
272 #define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
273 (nios2_block_reg_padding ((MODE), (TYPE), (FIRST)))
274
275 #define FUNCTION_ARG_REGNO_P(REGNO) \
276 ((REGNO) >= FIRST_ARG_REGNO && (REGNO) <= LAST_ARG_REGNO)
277
278 /* Passing function arguments on stack. */
279 #define PUSH_ARGS 0
280 #define ACCUMULATE_OUTGOING_ARGS 1
281
282 /* We define TARGET_RETURN_IN_MEMORY, so set to zero. */
283 #define DEFAULT_PCC_STRUCT_RETURN 0
284
285 /* Profiling. */
286 #define PROFILE_BEFORE_PROLOGUE
287 #define NO_PROFILE_COUNTERS 1
288 #define FUNCTION_PROFILER(FILE, LABELNO) \
289 nios2_function_profiler ((FILE), (LABELNO))
290
291 /* Addressing modes. */
292
293 #define CONSTANT_ADDRESS_P(X) \
294 (CONSTANT_P (X) && memory_address_p (SImode, X))
295
296 #define MAX_REGS_PER_ADDRESS 1
297 #define BASE_REG_CLASS ALL_REGS
298 #define INDEX_REG_CLASS NO_REGS
299
300 #define REGNO_OK_FOR_BASE_P(REGNO) nios2_regno_ok_for_base_p ((REGNO), true)
301 #define REGNO_OK_FOR_INDEX_P(REGNO) 0
302
303 /* Describing Relative Costs of Operations. */
304 #define MOVE_MAX 4
305 #define SLOW_BYTE_ACCESS 1
306
307 /* It is as good to call a constant function address as to call an address
308 kept in a register. */
309 #define NO_FUNCTION_CSE
310
311 /* Position independent code. */
312
313 #define PIC_OFFSET_TABLE_REGNUM 22
314 #define LEGITIMATE_PIC_OPERAND_P(X) nios2_legitimate_pic_operand_p (X)
315
316 /* Define output assembler language. */
317
318 #define ASM_APP_ON "#APP\n"
319 #define ASM_APP_OFF "#NO_APP\n"
320
321 #define ASM_COMMENT_START "# "
322
323 #define GLOBAL_ASM_OP "\t.global\t"
324
325 #define REGISTER_NAMES \
326 { \
327 "zero", \
328 "at", \
329 "r2", \
330 "r3", \
331 "r4", \
332 "r5", \
333 "r6", \
334 "r7", \
335 "r8", \
336 "r9", \
337 "r10", \
338 "r11", \
339 "r12", \
340 "r13", \
341 "r14", \
342 "r15", \
343 "r16", \
344 "r17", \
345 "r18", \
346 "r19", \
347 "r20", \
348 "r21", \
349 "r22", \
350 "r23", \
351 "et", \
352 "bt", \
353 "gp", \
354 "sp", \
355 "fp", \
356 "ta", \
357 "ba", \
358 "ra", \
359 "status", \
360 "estatus", \
361 "bstatus", \
362 "ipri", \
363 "ecause", \
364 "pc", \
365 "fake_fp", \
366 "fake_ap", \
367 }
368
369 #define ADDITIONAL_REGISTER_NAMES \
370 { \
371 {"r0", 0}, \
372 {"r1", 1}, \
373 {"r24", 24}, \
374 {"r25", 25}, \
375 {"r26", 26}, \
376 {"r27", 27}, \
377 {"r28", 28}, \
378 {"r29", 29}, \
379 {"r30", 30}, \
380 {"r31", 31} \
381 }
382
383 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
384 do \
385 { \
386 fputs (integer_asm_op (POINTER_SIZE / BITS_PER_UNIT, TRUE), FILE); \
387 fprintf (FILE, ".L%u\n", (unsigned) (VALUE)); \
388 } \
389 while (0)
390
391 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL)\
392 do \
393 { \
394 fputs (integer_asm_op (POINTER_SIZE / BITS_PER_UNIT, TRUE), STREAM); \
395 fprintf (STREAM, ".L%u-.L%u\n", (unsigned) (VALUE), (unsigned) (REL)); \
396 } \
397 while (0)
398
399 /* Section directives. */
400
401 /* Output before read-only data. */
402 #define TEXT_SECTION_ASM_OP "\t.section\t.text"
403
404 /* Output before writable data. */
405 #define DATA_SECTION_ASM_OP "\t.section\t.data"
406
407 /* Output before uninitialized data. */
408 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
409
410 /* Output before 'small' uninitialized data. */
411 #define SBSS_SECTION_ASM_OP "\t.section\t.sbss"
412
413 #ifndef IN_LIBGCC2
414 /* Default the definition of "small data" to 8 bytes. */
415 extern unsigned HOST_WIDE_INT nios2_section_threshold;
416 #endif
417
418 #define NIOS2_DEFAULT_GVALUE 8
419
420 /* This says how to output assembler code to declare an
421 uninitialized external linkage data object. Under SVR4,
422 the linker seems to want the alignment of data objects
423 to depend on their types. We do exactly that here. */
424 #undef COMMON_ASM_OP
425 #define COMMON_ASM_OP "\t.comm\t"
426
427 #define ASM_OUTPUT_ALIGN(FILE, LOG) \
428 do { \
429 fprintf ((FILE), "%s%d\n", ALIGN_ASM_OP, (LOG)); \
430 } while (0)
431
432 #undef ASM_OUTPUT_ALIGNED_COMMON
433 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
434 do \
435 { \
436 fprintf ((FILE), "%s", COMMON_ASM_OP); \
437 assemble_name ((FILE), (NAME)); \
438 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", (SIZE), \
439 (ALIGN) / BITS_PER_UNIT); \
440 } \
441 while (0)
442
443
444 /* This says how to output assembler code to declare an
445 uninitialized internal linkage data object. Under SVR4,
446 the linker seems to want the alignment of data objects
447 to depend on their types. We do exactly that here. */
448
449 #undef ASM_OUTPUT_ALIGNED_LOCAL
450 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
451 do { \
452 if ((SIZE) <= nios2_section_threshold) \
453 switch_to_section (sbss_section); \
454 else \
455 switch_to_section (bss_section); \
456 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
457 if (!flag_inhibit_size_directive) \
458 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
459 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
460 ASM_OUTPUT_LABEL(FILE, NAME); \
461 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
462 } while (0)
463
464 /* Put the jump tables in .text because when using position-independent code,
465 Nios II elf has no relocation that can represent arbitrary differences
466 between symbols in different sections. */
467 #define JUMP_TABLES_IN_TEXT_SECTION 1
468
469 /* Exception handling. */
470
471 /* Describe __builtin_eh_return. */
472 #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, LAST_RETVAL_REGNO)
473 #define EH_RETURN_DATA_REGNO(N) ((N) <= (LAST_ARG_REGNO - FIRST_ARG_REGNO) \
474 ? (N) + FIRST_ARG_REGNO : INVALID_REGNUM)
475
476 /* Nios II has no appropriate relocations for a 32-bit PC-relative or
477 section-relative pointer encoding. This therefore always chooses an
478 absolute representation for pointers. An unfortunate consequence of
479 this is that ld complains about the absolute fde encoding when linking
480 with -shared or -fpie, but the warning is harmless and there seems to
481 be no good way to suppress it. */
482 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
483 (flag_pic ? DW_EH_PE_aligned : DW_EH_PE_sdata4)
484
485 /* Misc. parameters. */
486
487 #define STORE_FLAG_VALUE 1
488 #define Pmode SImode
489 #define FUNCTION_MODE QImode
490
491 #define CASE_VECTOR_MODE Pmode
492
493 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
494
495 #define LOAD_EXTEND_OP(MODE) (ZERO_EXTEND)
496
497 #define WORD_REGISTER_OPERATIONS
498
499 #endif /* GCC_NIOS2_H */