rl78.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /* GCC backend definitions for the Renesas RL78 processor.
  2. Copyright (C) 2011-2015 Free Software Foundation, Inc.
  3. Contributed by Red Hat.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published
  7. by the Free Software Foundation; either version 3, or (at your
  8. option) any later version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #define RL78_MUL_NONE (rl78_mul_type == MUL_NONE)
  17. #define RL78_MUL_RL78 (rl78_mul_type == MUL_RL78)
  18. #define RL78_MUL_G13 (rl78_mul_type == MUL_G13)
  19. #define TARGET_CPU_CPP_BUILTINS() \
  20. do \
  21. { \
  22. builtin_define ("__RL78__"); \
  23. builtin_assert ("cpu=RL78"); \
  24. if (RL78_MUL_RL78) \
  25. builtin_define ("__RL78_MUL_RL78__"); \
  26. if (RL78_MUL_G13) \
  27. builtin_define ("__RL78_MUL_G13__"); \
  28. if (TARGET_G10) \
  29. builtin_define ("__RL78_G10__"); \
  30. } \
  31. while (0)
  32. #undef STARTFILE_SPEC
  33. #define STARTFILE_SPEC "%{pg:gcrt0.o%s}%{!pg:crt0.o%s} crtbegin.o%s"
  34. #undef ENDFILE_SPEC
  35. #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
  36. #undef ASM_SPEC
  37. #define ASM_SPEC "\
  38. %{mrelax:-relax} \
  39. %{mg10} \
  40. "
  41. #undef LINK_SPEC
  42. #define LINK_SPEC "\
  43. %{mrelax:-relax} \
  44. %{!r:--gc-sections} \
  45. "
  46. #undef LIB_SPEC
  47. #define LIB_SPEC " \
  48. --start-group \
  49. -lc \
  50. -lsim \
  51. %{fprofile-arcs|fprofile-generate|coverage:-lgcov} \
  52. --end-group \
  53. %{!T*: %{msim:%Trl78-sim.ld}%{!msim:%Trl78.ld}} \
  54. "
  55. #define BITS_BIG_ENDIAN 0
  56. #define BYTES_BIG_ENDIAN 0
  57. #define WORDS_BIG_ENDIAN 0
  58. #ifdef IN_LIBGCC2
  59. /* This is to get correct SI and DI modes in libgcc2.c (32 and 64 bits). */
  60. #define UNITS_PER_WORD 4
  61. /* We have a problem with libgcc2. It only defines two versions of
  62. each function, one for "int" and one for "long long". Ie it assumes
  63. that "sizeof (int) == sizeof (long)". For the RL78 this is not true
  64. and we need a third set of functions. We explicitly define
  65. LIBGCC2_UNITS_PER_WORD here so that it is clear that we are expecting
  66. to get the SI and DI versions from the libgcc2.c sources, and we
  67. provide our own set of HI functions, which is why this
  68. definition is surrounded by #ifndef..#endif. */
  69. #ifndef LIBGCC2_UNITS_PER_WORD
  70. #define LIBGCC2_UNITS_PER_WORD 4
  71. #endif
  72. #else
  73. /* Actual width of a word, in units (bytes). */
  74. #define UNITS_PER_WORD 1
  75. #endif
  76. #define SHORT_TYPE_SIZE 16
  77. #define INT_TYPE_SIZE 16
  78. #define LONG_TYPE_SIZE 32
  79. #define LONG_LONG_TYPE_SIZE 64
  80. #define FLOAT_TYPE_SIZE 32
  81. #define DOUBLE_TYPE_SIZE 32 /*64*/
  82. #define LONG_DOUBLE_TYPE_SIZE 64 /*DOUBLE_TYPE_SIZE*/
  83. #define DEFAULT_SIGNED_CHAR 0
  84. #define STRICT_ALIGNMENT 1
  85. #define FUNCTION_BOUNDARY 8
  86. #define BIGGEST_ALIGNMENT 16
  87. #define STACK_BOUNDARY 16
  88. #define PARM_BOUNDARY 16
  89. #define STACK_GROWS_DOWNWARD 1
  90. #define FRAME_GROWS_DOWNWARD 1
  91. #define FIRST_PARM_OFFSET(FNDECL) 0
  92. #define MAX_REGS_PER_ADDRESS 1
  93. #define Pmode HImode
  94. #define POINTER_SIZE 16
  95. #undef SIZE_TYPE
  96. #define SIZE_TYPE "unsigned int"
  97. #undef PTRDIFF_TYPE
  98. #define PTRDIFF_TYPE "int"
  99. #undef WCHAR_TYPE
  100. #define WCHAR_TYPE "long int"
  101. #undef WCHAR_TYPE_SIZE
  102. #define WCHAR_TYPE_SIZE BITS_PER_WORD
  103. #define POINTERS_EXTEND_UNSIGNED 1
  104. #define FUNCTION_MODE HImode
  105. #define CASE_VECTOR_MODE Pmode
  106. #define WORD_REGISTER_OPERATIONS 0
  107. #define HAS_LONG_COND_BRANCH 0
  108. #define HAS_LONG_UNCOND_BRANCH 0
  109. #define MOVE_MAX 2
  110. #define STARTING_FRAME_OFFSET 0
  111. #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
  112. #define ADDR_SPACE_NEAR 1
  113. #define ADDR_SPACE_FAR 2
  114. #define HAVE_PRE_DECCREMENT 0
  115. #define HAVE_POST_INCREMENT 0
  116. #define MOVE_RATIO(SPEED) ((SPEED) ? 24 : 16)
  117. #define SLOW_BYTE_ACCESS 0
  118. #define STORE_FLAG_VALUE 1
  119. #define LOAD_EXTEND_OP(MODE) ZERO_EXTEND
  120. /* The RL78 has four register banks. Normal operation uses RB0 as
  121. real registers, RB1 and RB2 as "virtual" registers (because we know
  122. they'll be there, and not used as variables), and RB3 is reserved
  123. for interrupt handlers. The virtual registers are accessed as
  124. SADDRs:
  125. FFEE0-FFEE7 RB0
  126. FFEE8-FFEEF RB1
  127. FFEF0-FFEF7 RB2
  128. FFEF8-FFEFF RB3
  129. */
  130. #define REGISTER_NAMES \
  131. { \
  132. "x", "a", "c", "b", "e", "d", "l", "h", \
  133. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \
  134. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", \
  135. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", \
  136. "sp", "ap", "psw", "es", "cs" \
  137. }
  138. #define ADDITIONAL_REGISTER_NAMES \
  139. { \
  140. { "ax", 0 }, \
  141. { "bc", 2 }, \
  142. { "de", 4 }, \
  143. { "hl", 6 }, \
  144. { "rp0", 0 }, \
  145. { "rp1", 2 }, \
  146. { "rp2", 4 }, \
  147. { "rp3", 6 }, \
  148. { "r0", 0 }, \
  149. { "r1", 1 }, \
  150. { "r2", 2 }, \
  151. { "r3", 3 }, \
  152. { "r4", 4 }, \
  153. { "r5", 5 }, \
  154. { "r6", 6 }, \
  155. { "r7", 7 }, \
  156. }
  157. enum reg_class
  158. {
  159. NO_REGS, /* No registers in set. */
  160. XREG,
  161. AREG,
  162. AXREG,
  163. CREG,
  164. BREG,
  165. BCREG,
  166. EREG,
  167. DREG,
  168. DEREG,
  169. LREG,
  170. HREG,
  171. HLREG,
  172. IDX_REGS,
  173. QI_REGS,
  174. SPREG,
  175. R8W_REGS,
  176. R10W_REGS,
  177. INT_REGS,
  178. V_REGS, /* Virtual registers. */
  179. GR_REGS, /* Integer registers. */
  180. PSWREG,
  181. ALL_REGS, /* All registers. */
  182. LIM_REG_CLASSES /* Max value + 1. */
  183. };
  184. #define REG_CLASS_NAMES \
  185. { \
  186. "NO_REGS", \
  187. "XREG", \
  188. "AREG", \
  189. "AXREG", \
  190. "CREG", \
  191. "BREG", \
  192. "BCREG", \
  193. "EREG", \
  194. "DREG", \
  195. "DEREG", \
  196. "LREG", \
  197. "HREG", \
  198. "HLREG", \
  199. "IDX_REGS", \
  200. "QI_REGS", \
  201. "SPREG", \
  202. "R8W_REGS", \
  203. "R10W_REGS", \
  204. "INT_REGS", \
  205. "V_REGS", \
  206. "GR_REGS", \
  207. "PSWREG", \
  208. "ALL_REGS" \
  209. }
  210. /* Note that no class may include the second register in $fp, because
  211. we treat $fp as a single HImode register. */
  212. #define REG_CLASS_CONTENTS \
  213. { \
  214. { 0x00000000, 0x00000000 }, /* No registers, */ \
  215. { 0x00000001, 0x00000000 }, \
  216. { 0x00000002, 0x00000000 }, \
  217. { 0x00000003, 0x00000000 }, \
  218. { 0x00000004, 0x00000000 }, \
  219. { 0x00000008, 0x00000000 }, \
  220. { 0x0000000c, 0x00000000 }, \
  221. { 0x00000010, 0x00000000 }, \
  222. { 0x00000020, 0x00000000 }, \
  223. { 0x00000030, 0x00000000 }, \
  224. { 0x00000040, 0x00000000 }, \
  225. { 0x00000080, 0x00000000 }, \
  226. { 0x000000c0, 0x00000000 }, \
  227. { 0x0000000c, 0x00000000 }, /* B and C - index regs. */ \
  228. { 0x000000ff, 0x00000000 }, /* all real registers. */ \
  229. { 0x00000000, 0x00000001 }, /* SP */ \
  230. { 0x00000300, 0x00000000 }, /* R8 - HImode */ \
  231. { 0x00000c00, 0x00000000 }, /* R10 - HImode */ \
  232. { 0xff000000, 0x00000000 }, /* INT - HImode */ \
  233. { 0xff7fff00, 0x00000000 }, /* Virtual registers. */ \
  234. { 0xff7fff00, 0x00000002 }, /* General registers. */ \
  235. { 0x04000000, 0x00000004 }, /* PSW. */ \
  236. { 0xff7fffff, 0x0000001f } /* All registers. */ \
  237. }
  238. #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true
  239. #define N_REG_CLASSES (int) LIM_REG_CLASSES
  240. #define CLASS_MAX_NREGS(CLASS, MODE) ((GET_MODE_SIZE (MODE) \
  241. + UNITS_PER_WORD - 1) \
  242. / UNITS_PER_WORD)
  243. #define GENERAL_REGS GR_REGS
  244. #define BASE_REG_CLASS V_REGS
  245. #define INDEX_REG_CLASS V_REGS
  246. #define FIRST_PSEUDO_REGISTER 37
  247. #define REGNO_REG_CLASS(REGNO) ((REGNO) < FIRST_PSEUDO_REGISTER \
  248. ? GR_REGS : NO_REGS)
  249. #define FRAME_POINTER_REGNUM 22
  250. #define STACK_POINTER_REGNUM 32
  251. #define ARG_POINTER_REGNUM 33
  252. #define CC_REGNUM 34
  253. #define FUNC_RETURN_REGNUM 8
  254. #define STATIC_CHAIN_REGNUM 14
  255. /* Trampolines are implemented with a separate data stack. The memory
  256. on stack only holds the function pointer for the chosen stub.
  257. */
  258. #define TRAMPOLINE_SIZE 4
  259. #define TRAMPOLINE_ALIGNMENT 16
  260. #define ELIMINABLE_REGS \
  261. {{ ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
  262. { ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM }, \
  263. { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }}
  264. #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
  265. (OFFSET) = rl78_initial_elimination_offset ((FROM), (TO))
  266. #define FUNCTION_ARG_REGNO_P(N) 0
  267. #define FUNCTION_VALUE_REGNO_P(N) ((N) == 8)
  268. #define DEFAULT_PCC_STRUCT_RETURN 0
  269. #define FIXED_REGISTERS \
  270. { \
  271. 1,1,1,1, 1,1,1,1, \
  272. 0,0,0,0, 0,0,0,0, \
  273. 0,0,0,0, 0,0,1,1, \
  274. 1,1,1,1, 1,1,1,1, \
  275. 0, 1, 0, 1, 1 \
  276. }
  277. #define CALL_USED_REGISTERS \
  278. { \
  279. 1,1,1,1, 1,1,1,1, \
  280. 1,1,1,1, 1,1,1,1, \
  281. 0,0,0,0, 0,0,1,1, \
  282. 1,1,1,1, 1,1,1,1, \
  283. 0, 1, 1, 1, 1 \
  284. }
  285. #define LIBCALL_VALUE(MODE) \
  286. gen_rtx_REG ((MODE), \
  287. FUNC_RETURN_REGNUM)
  288. /* Order of allocation of registers. */
  289. #define REG_ALLOC_ORDER \
  290. { 8, 9, 10, 11, 12, 13, 14, 15, \
  291. 16, 17, 18, 19, 20, 21, 22, 23, \
  292. 0, 1, 6, 7, 2, 3, 4, 5, \
  293. 24, 25, 26, 27, 28, 29, 30, 31, \
  294. 32, 33, 34 \
  295. }
  296. #define REGNO_IN_RANGE(REGNO, MIN, MAX) \
  297. (IN_RANGE ((REGNO), (MIN), (MAX)) \
  298. || (reg_renumber != NULL \
  299. && reg_renumber[(REGNO)] >= (MIN) \
  300. && reg_renumber[(REGNO)] <= (MAX)))
  301. #ifdef REG_OK_STRICT
  302. #define REGNO_OK_FOR_BASE_P(regno) REGNO_IN_RANGE (regno, 16, 31)
  303. #else
  304. #define REGNO_OK_FOR_BASE_P(regno) 1
  305. #endif
  306. #define REGNO_OK_FOR_INDEX_P(regno) REGNO_OK_FOR_BASE_P (regno)
  307. #define REGNO_MODE_CODE_OK_FOR_BASE_P(regno, mode, address_space, outer_code, index_code) \
  308. rl78_regno_mode_code_ok_for_base_p (regno, mode, address_space, outer_code, index_code)
  309. #define MODE_CODE_BASE_REG_CLASS(mode, address_space, outer_code, index_code) \
  310. rl78_mode_code_base_reg_class (mode, address_space, outer_code, index_code)
  311. #define RETURN_ADDR_RTX(COUNT, FRAMEADDR) \
  312. ((COUNT) == 0 \
  313. ? gen_rtx_MEM (Pmode, gen_rtx_PLUS (HImode, arg_pointer_rtx, GEN_INT (-4))) \
  314. : NULL_RTX)
  315. #define INCOMING_RETURN_ADDR_RTX gen_rtx_MEM (Pmode, stack_pointer_rtx)
  316. #define ACCUMULATE_OUTGOING_ARGS 1
  317. typedef unsigned int CUMULATIVE_ARGS;
  318. #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
  319. (CUM) = 0
  320. /* FIXME */
  321. #define NO_PROFILE_COUNTERS 1
  322. #define PROFILE_BEFORE_PROLOGUE 1
  323. #define FUNCTION_PROFILER(FILE, LABELNO) \
  324. fprintf (FILE, "\tbsr\t__mcount\n");
  325. #define HARD_REGNO_NREGS(REGNO, MODE) \
  326. rl78_hard_regno_nregs (REGNO, MODE)
  327. #define HARD_REGNO_MODE_OK(REGNO, MODE) \
  328. rl78_hard_regno_mode_ok (REGNO, MODE)
  329. #define MODES_TIEABLE_P(MODE1, MODE2) \
  330. ( ( GET_MODE_CLASS (MODE1) == MODE_FLOAT \
  331. || GET_MODE_CLASS (MODE1) == MODE_COMPLEX_FLOAT) \
  332. == ( GET_MODE_CLASS (MODE2) == MODE_FLOAT \
  333. || GET_MODE_CLASS (MODE2) == MODE_COMPLEX_FLOAT))
  334. #define TEXT_SECTION_ASM_OP ".text"
  335. #define DATA_SECTION_ASM_OP ".data"
  336. #define BSS_SECTION_ASM_OP ".bss"
  337. #define CTORS_SECTION_ASM_OP ".section \".ctors\",\"a\""
  338. #define DTORS_SECTION_ASM_OP ".section \".dtors\",\"a\""
  339. #define ASM_COMMENT_START " ;"
  340. #define ASM_APP_ON ""
  341. #define ASM_APP_OFF ""
  342. #define LOCAL_LABEL_PREFIX ".L"
  343. #undef USER_LABEL_PREFIX
  344. #define USER_LABEL_PREFIX "_"
  345. #define GLOBAL_ASM_OP "\t.global\t"
  346. #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
  347. fprintf (FILE, "\t.long .L%d\n", VALUE)
  348. /* This is how to output an element of a case-vector that is relative.
  349. Note: The local label referenced by the "3b" below is emitted by
  350. the tablejump insn. */
  351. #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
  352. fprintf (FILE, "\t.long .L%d - 1b\n", VALUE)
  353. #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) rl78_output_symbol_ref ((FILE), (SYM))
  354. #define ASM_OUTPUT_LABELREF(FILE, SYM) rl78_output_labelref ((FILE), (SYM))
  355. #define ASM_OUTPUT_ALIGNED_DECL_COMMON(STREAM, DECL, NAME, SIZE, ALIGNMENT) \
  356. rl78_output_aligned_common (STREAM, DECL, NAME, SIZE, ALIGNMENT, 1)
  357. #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(STREAM, DECL, NAME, SIZE, ALIGNMENT) \
  358. rl78_output_aligned_common (STREAM, DECL, NAME, SIZE, ALIGNMENT, 0)
  359. #define ASM_OUTPUT_ALIGN(STREAM, LOG) \
  360. do \
  361. { \
  362. if ((LOG) == 0) \
  363. break; \
  364. fprintf (STREAM, "\t.balign %d\n", 1 << (LOG)); \
  365. } \
  366. while (0)
  367. /* For PIC put jump tables into the text section so that the offsets that
  368. they contain are always computed between two same-section symbols. */
  369. #define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
  370. /* This is a version of REG_P that also returns TRUE for SUBREGs. */
  371. #define RL78_REG_P(rtl) (REG_P (rtl) || GET_CODE (rtl) == SUBREG)
  372. /* Like REG_P except that this macro is true for SET expressions. */
  373. #define SET_P(rtl) (GET_CODE (rtl) == SET)
  374. #undef PREFERRED_DEBUGGING_TYPE
  375. #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
  376. #undef DWARF2_ADDR_SIZE
  377. #define DWARF2_ADDR_SIZE 4
  378. #define DWARF2_ASM_LINE_DEBUG_INFO 1
  379. #define EXIT_IGNORE_STACK 0
  380. #define INCOMING_FRAME_SP_OFFSET 4
  381. #define BRANCH_COST(SPEED,PREDICT) 1
  382. #define REGISTER_MOVE_COST(MODE,FROM,TO) 2
  383. #define EH_RETURN_DATA_REGNO(N) (N < 2 ? (8+(N)*2) : INVALID_REGNUM)
  384. #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (HImode, 20)
  385. #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) DW_EH_PE_udata4
  386. /* NOTE: defined but zero means dwarf2 debugging, but sjlj EH. */
  387. #define DWARF2_UNWIND_INFO 0
  388. #define REGISTER_TARGET_PRAGMAS() rl78_register_pragmas()