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