nios2.h 15 KB

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