| 1 |
/* Target Definitions for OpenRISC. |
| 2 |
Copyright (C) 2018-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Stafford Horne. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 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 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but WITHOUT |
| 13 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 15 |
License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#ifndef GCC_OR1K_H |
| 22 |
#define GCC_OR1K_H |
| 23 |
|
| 24 |
#include "config/or1k/or1k-opts.h" |
| 25 |
|
| 26 |
/* Names to predefine in the preprocessor for this target machine. */ |
| 27 |
#define TARGET_CPU_CPP_BUILTINS() \ |
| 28 |
do \ |
| 29 |
{ \ |
| 30 |
builtin_define ("__OR1K__"); \ |
| 31 |
builtin_define ("__OR1K_DELAY__"); \ |
| 32 |
builtin_define ("__or1k__"); \ |
| 33 |
if (TARGET_CMOV) \ |
| 34 |
builtin_define ("__or1k_cmov__"); \ |
| 35 |
if (TARGET_HARD_FLOAT) \ |
| 36 |
builtin_define ("__or1k_hard_float__"); \ |
| 37 |
builtin_assert ("cpu=or1k"); \ |
| 38 |
builtin_assert ("machine=or1k"); \ |
| 39 |
} \ |
| 40 |
while (0) |
| 41 |
|
| 42 |
#define TARGET_CMODEL_SMALL \ |
| 43 |
(or1k_code_model == CMODEL_SMALL) |
| 44 |
#define TARGET_CMODEL_LARGE \ |
| 45 |
(or1k_code_model == CMODEL_LARGE) |
| 46 |
|
| 47 |
/* Storage layout. */ |
| 48 |
|
| 49 |
#define DEFAULT_SIGNED_CHAR 1 |
| 50 |
#define BITS_BIG_ENDIAN 0 |
| 51 |
#define BYTES_BIG_ENDIAN 1 |
| 52 |
#define WORDS_BIG_ENDIAN 1 |
| 53 |
#define BITS_PER_WORD 32 |
| 54 |
#define UNITS_PER_WORD 4 |
| 55 |
#define POINTER_SIZE 32 |
| 56 |
#define BIGGEST_ALIGNMENT 32 |
| 57 |
#define STRICT_ALIGNMENT 1 |
| 58 |
#define FUNCTION_BOUNDARY 32 |
| 59 |
#define PARM_BOUNDARY 32 |
| 60 |
#define STACK_BOUNDARY 32 |
| 61 |
#define PREFERRED_STACK_BOUNDARY 32 |
| 62 |
#define MAX_FIXED_MODE_SIZE 64 |
| 63 |
|
| 64 |
/* Layout of source language data types. */ |
| 65 |
|
| 66 |
#define INT_TYPE_SIZE 32 |
| 67 |
#define SHORT_TYPE_SIZE 16 |
| 68 |
#define LONG_TYPE_SIZE 32 |
| 69 |
#define LONG_LONG_TYPE_SIZE 64 |
| 70 |
#define WCHAR_TYPE_SIZE 32 |
| 71 |
|
| 72 |
#undef SIZE_TYPE |
| 73 |
#define SIZE_TYPE "unsigned int" |
| 74 |
|
| 75 |
#undef PTRDIFF_TYPE |
| 76 |
#define PTRDIFF_TYPE "int" |
| 77 |
|
| 78 |
#undef WCHAR_TYPE |
| 79 |
#define WCHAR_TYPE "unsigned int" |
| 80 |
|
| 81 |
/* Describing Relative Costs of Operations. */ |
| 82 |
#define MOVE_MAX 4 |
| 83 |
#define SLOW_BYTE_ACCESS 1 |
| 84 |
|
| 85 |
/* Register usage, class and contents. */ |
| 86 |
|
| 87 |
/* In OpenRISC there are 32 general purpose registers with the following |
| 88 |
designations: |
| 89 |
|
| 90 |
r0 always 0 |
| 91 |
r1 stack pointer |
| 92 |
r2 frame pointer (optional) |
| 93 |
r3 arg 0 |
| 94 |
r4 arg 1 |
| 95 |
r5 arg 2 |
| 96 |
r6 arg 3 |
| 97 |
r7 arg 4 |
| 98 |
r8 arg 5 |
| 99 |
r9 function call return link address |
| 100 |
r10 thread local storage |
| 101 |
r11 function return value & static chain |
| 102 |
r12 function return value high (upper 64-bit) |
| 103 |
r13 temporary (used in prologue and epilogue) |
| 104 |
r14 callee saved |
| 105 |
r15 temporary |
| 106 |
r16 callee saved & pic base register |
| 107 |
r17 temporary |
| 108 |
r18 callee saved |
| 109 |
r19 temporary |
| 110 |
r20 callee saved |
| 111 |
r21 temporary |
| 112 |
r22 callee saved |
| 113 |
r23 temporary |
| 114 |
r24 callee saved |
| 115 |
r25 temporary |
| 116 |
r26 callee saved |
| 117 |
r27 temporary |
| 118 |
r28 callee saved |
| 119 |
r29 temporary |
| 120 |
r30 callee saved |
| 121 |
r31 temporary |
| 122 |
|
| 123 |
r32 soft argument pointer |
| 124 |
r33 soft frame pointer |
| 125 |
r34 SR[F] (bit) register |
| 126 |
|
| 127 |
This ABI has no adjacent call-saved register, which means that |
| 128 |
DImode/DFmode pseudos cannot be call-saved and will always be |
| 129 |
spilled across calls. To solve this without changing the ABI, |
| 130 |
remap the compiler internal register numbers to place the even |
| 131 |
call-saved registers r16-r30 in 24-31, and the odd call-clobbered |
| 132 |
registers r17-r31 in 16-23. */ |
| 133 |
|
| 134 |
#define FIRST_PSEUDO_REGISTER 35 |
| 135 |
|
| 136 |
#define HW_TO_GCC_REGNO(X) \ |
| 137 |
((X) < 16 || (X) > 31 ? (X) \ |
| 138 |
: (X) & 1 ? ((X) - 16) / 2 + 16 \ |
| 139 |
: ((X) - 16) / 2 + 24) |
| 140 |
|
| 141 |
#define GCC_TO_HW_REGNO(X) \ |
| 142 |
((X) < 16 || (X) > 31 ? (X) \ |
| 143 |
: (X) < 24 ? ((X) - 16) * 2 + 17 \ |
| 144 |
: ((X) - 24) * 2 + 16) |
| 145 |
|
| 146 |
#define DEBUGGER_REGNO(X) GCC_TO_HW_REGNO(X) |
| 147 |
|
| 148 |
#define REGISTER_NAMES { \ |
| 149 |
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \ |
| 150 |
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \ |
| 151 |
"r17", "r19", "r21", "r23", "r25", "r27", "r29", "r31", \ |
| 152 |
"r16", "r18", "r20", "r22", "r24", "r26", "r28", "r30", \ |
| 153 |
"?ap", "?fp", "?sr_f" } |
| 154 |
|
| 155 |
#define FIXED_REGISTERS \ |
| 156 |
{ 1, 1, 0, 0, 0, 0, 0, 0, \ |
| 157 |
0, 0, 1, 0, 0, 0, 0, 0, \ |
| 158 |
0, 0, 0, 0, 0, 0, 0, 0, \ |
| 159 |
0, 0, 0, 0, 0, 0, 0, 0, \ |
| 160 |
1, 1, 1 } |
| 161 |
|
| 162 |
/* Caller saved/temporary registers + args + fixed */ |
| 163 |
#define CALL_USED_REGISTERS \ |
| 164 |
{ 1, 1, 0, 1, 1, 1, 1, 1, \ |
| 165 |
1, 1, 1, 1, 1, 1, 0, 1, \ |
| 166 |
1, 1, 1, 1, 1, 1, 1, 1, \ |
| 167 |
0, 0, 0, 0, 0, 0, 0, 0, \ |
| 168 |
1, 1, 1 } |
| 169 |
|
| 170 |
/* List the order in which to allocate registers. Each register must |
| 171 |
be listed once, even those in FIXED_REGISTERS. |
| 172 |
|
| 173 |
??? Note that placing REAL_PIC_OFFSET_TABLE_REGNUM (r16 = 24) first |
| 174 |
happens to make it most likely selected *as* the pic register when |
| 175 |
compiling without optimization, simply because the pic pseudo happens |
| 176 |
to be allocated with the lowest pseudo regno. */ |
| 177 |
|
| 178 |
#define REG_ALLOC_ORDER { \ |
| 179 |
16, 17, 18, 19, 20, 21, 22, 23, /* r17-r31 (odd), non-saved */ \ |
| 180 |
13, 15, /* non-saved */ \ |
| 181 |
12, 11, /* non-saved return values */ \ |
| 182 |
8, 7, 6, 5, 4, 3, /* non-saved argument regs */ \ |
| 183 |
24, /* r16, saved, pic reg */ \ |
| 184 |
25, 26, 27, 28, 29, 30, 31, /* r18-r31 (even), saved */ \ |
| 185 |
14, /* r14, saved */ \ |
| 186 |
2, /* saved hard frame pointer */ \ |
| 187 |
9, /* saved return address */ \ |
| 188 |
0, /* fixed zero reg */ \ |
| 189 |
1, /* fixed stack pointer */ \ |
| 190 |
10, /* fixed thread pointer */ \ |
| 191 |
32, 33, 34, /* fixed ap, fp, sr[f], */ \ |
| 192 |
} |
| 193 |
|
| 194 |
enum reg_class |
| 195 |
{ |
| 196 |
NO_REGS, |
| 197 |
SIBCALL_REGS, |
| 198 |
DOUBLE_REGS, |
| 199 |
GOT_REGS, |
| 200 |
GENERAL_REGS, |
| 201 |
FLAG_REGS, |
| 202 |
ALL_REGS, |
| 203 |
LIM_REG_CLASSES |
| 204 |
}; |
| 205 |
|
| 206 |
#define N_REG_CLASSES (int) LIM_REG_CLASSES |
| 207 |
|
| 208 |
#define REG_CLASS_NAMES { \ |
| 209 |
"NO_REGS", \ |
| 210 |
"SIBCALL_REGS", \ |
| 211 |
"DOUBLE_REGS", \ |
| 212 |
"GOT_REGS", \ |
| 213 |
"GENERAL_REGS", \ |
| 214 |
"FLAG_REGS", \ |
| 215 |
"ALL_REGS" } |
| 216 |
|
| 217 |
/* The SIBCALL_REGS must be call-clobbered, and not used as a temporary |
| 218 |
in the epilogue. This excludes R9 (LR), R11 (STATIC_CHAIN), and |
| 219 |
R13 (PE_TMP_REGNUM). */ |
| 220 |
#define SIBCALL_REGS_MASK 0x00ff95f8u |
| 221 |
|
| 222 |
#define REG_CLASS_CONTENTS \ |
| 223 |
{ { 0x00000000, 0x00000000 }, \ |
| 224 |
{ SIBCALL_REGS_MASK, 0 }, \ |
| 225 |
{ 0x7f7ffffe, 0x00000000 }, \ |
| 226 |
{ 0xfffffdff, 0x00000000 }, \ |
| 227 |
{ 0xffffffff, 0x00000003 }, \ |
| 228 |
{ 0x00000000, 0x00000004 }, \ |
| 229 |
{ 0xffffffff, 0x00000007 } \ |
| 230 |
} |
| 231 |
|
| 232 |
/* A C expression whose value is a register class containing hard |
| 233 |
register REGNO. In general there is more that one such class; |
| 234 |
choose a class which is "minimal", meaning that no smaller class |
| 235 |
also contains the register. */ |
| 236 |
#define REGNO_REG_CLASS(REGNO) \ |
| 237 |
((REGNO) >= SR_F_REGNUM ? FLAG_REGS \ |
| 238 |
: (REGNO) < 32 && ((SIBCALL_REGS_MASK >> (REGNO)) & 1) ? SIBCALL_REGS \ |
| 239 |
: GENERAL_REGS) |
| 240 |
|
| 241 |
#define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE) \ |
| 242 |
do { \ |
| 243 |
if (GET_MODE_CLASS (MODE) == MODE_INT \ |
| 244 |
&& GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \ |
| 245 |
(MODE) = word_mode; \ |
| 246 |
} while (0) |
| 247 |
|
| 248 |
/* A macro whose definition is the name of the class to which a valid |
| 249 |
base register must belong. A base register is one used in an |
| 250 |
address which is the register value plus a displacement. */ |
| 251 |
#define BASE_REG_CLASS GENERAL_REGS |
| 252 |
|
| 253 |
#define INDEX_REG_CLASS NO_REGS |
| 254 |
|
| 255 |
/* Assembly definitions. */ |
| 256 |
|
| 257 |
#define ASM_APP_ON "" |
| 258 |
#define ASM_APP_OFF "" |
| 259 |
|
| 260 |
#define ASM_COMMENT_START "# " |
| 261 |
|
| 262 |
#define GLOBAL_ASM_OP "\t.global\t" |
| 263 |
#define TEXT_SECTION_ASM_OP "\t.section\t.text" |
| 264 |
#define DATA_SECTION_ASM_OP "\t.section\t.data" |
| 265 |
#define BSS_SECTION_ASM_OP "\t.section\t.bss" |
| 266 |
#define SBSS_SECTION_ASM_OP "\t.section\t.sbss" |
| 267 |
|
| 268 |
/* This is how to output an assembler line |
| 269 |
that says to advance the location counter |
| 270 |
to a multiple of 2**LOG bytes. */ |
| 271 |
#define ASM_OUTPUT_ALIGN(FILE,LOG) \ |
| 272 |
do \ |
| 273 |
{ \ |
| 274 |
if ((LOG) != 0) \ |
| 275 |
fprintf (FILE, "\t.align %d\n", 1 << (LOG)); \ |
| 276 |
} \ |
| 277 |
while (0) |
| 278 |
|
| 279 |
/* This is used in crtstuff to create call stubs in the |
| 280 |
_init() and _fini() functions. Defining this here saves |
| 281 |
a few bytes created by the dummy call_xxx() functions. */ |
| 282 |
#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \ |
| 283 |
asm (SECTION_OP "\n" \ |
| 284 |
" l.jal " #FUNC "\n" \ |
| 285 |
" l.nop\n" \ |
| 286 |
" .previous"); |
| 287 |
|
| 288 |
|
| 289 |
#define PRINT_OPERAND_PUNCT_VALID_P(CODE) (code == '#') |
| 290 |
|
| 291 |
/* Calling convention definitions. */ |
| 292 |
#define CUMULATIVE_ARGS int |
| 293 |
#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \ |
| 294 |
do { (CUM) = 0; } while (0) |
| 295 |
|
| 296 |
|
| 297 |
/* Trampolines, for nested functions */ |
| 298 |
#define TRAMPOLINE_SIZE 20 |
| 299 |
#define TRAMPOLINE_ALIGNMENT 32 |
| 300 |
|
| 301 |
/* Pointer mode */ |
| 302 |
#define Pmode SImode |
| 303 |
#define FUNCTION_MODE SImode |
| 304 |
#define STACK_POINTER_REGNUM SP_REGNUM |
| 305 |
#define FRAME_POINTER_REGNUM SFP_REGNUM |
| 306 |
#define HARD_FRAME_POINTER_REGNUM HFP_REGNUM |
| 307 |
#define STATIC_CHAIN_REGNUM RV_REGNUM |
| 308 |
|
| 309 |
/* The register number of the arg pointer register, which is used to |
| 310 |
access the function's argument list. */ |
| 311 |
#define ARG_POINTER_REGNUM AP_REGNUM |
| 312 |
|
| 313 |
/* Position Independent Code. See or1k_init_pic_reg. */ |
| 314 |
#define REAL_PIC_OFFSET_TABLE_REGNUM HW_TO_GCC_REGNO (16) |
| 315 |
|
| 316 |
/* ??? Follow i386 in working around gimple costing estimation, which |
| 317 |
happens without properly initializing the pic_offset_table pseudo. */ |
| 318 |
#define PIC_OFFSET_TABLE_REGNUM \ |
| 319 |
(pic_offset_table_rtx ? INVALID_REGNUM : REAL_PIC_OFFSET_TABLE_REGNUM) |
| 320 |
|
| 321 |
/* A C expression that is nonzero if REGNO is the number of a hard |
| 322 |
register in which function arguments are sometimes passed. */ |
| 323 |
#define FUNCTION_ARG_REGNO_P(r) (r >= 3 && r <= 8) |
| 324 |
|
| 325 |
#define MAX_REGS_PER_ADDRESS 1 |
| 326 |
|
| 327 |
/* The ELIMINABLE_REGS macro specifies a table of register pairs used to |
| 328 |
eliminate unneeded registers that point into the stack frame. Note, |
| 329 |
the only elimination attempted by the compiler is to replace references |
| 330 |
to the frame pointer with references to the stack pointer. */ |
| 331 |
|
| 332 |
#define ELIMINABLE_REGS \ |
| 333 |
{{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \ |
| 334 |
{ FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM }, \ |
| 335 |
{ ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \ |
| 336 |
{ ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM }} |
| 337 |
|
| 338 |
#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \ |
| 339 |
do { \ |
| 340 |
(OFFSET) = or1k_initial_elimination_offset ((FROM), (TO)); \ |
| 341 |
} while (0) |
| 342 |
|
| 343 |
#define REGNO_OK_FOR_INDEX_P(REGNO) 0 |
| 344 |
#define REGNO_OK_FOR_BASE_P(REGNO) ((REGNO) <= SFP_REGNUM) |
| 345 |
|
| 346 |
/* If defined, the maximum amount of space required for outgoing |
| 347 |
arguments will be computed and placed into the variable |
| 348 |
'crtl->outgoing_args_size'. No space will be pushed |
| 349 |
onto the stack for each call; instead, the function prologue |
| 350 |
should increase the stack frame size by this amount. */ |
| 351 |
#define ACCUMULATE_OUTGOING_ARGS 1 |
| 352 |
|
| 353 |
/* Stack layout and stack pointer usage. */ |
| 354 |
|
| 355 |
/* This plus ARG_POINTER_REGNUM points to the first word of incoming args. */ |
| 356 |
#define FIRST_PARM_OFFSET(FNDECL) (0) |
| 357 |
|
| 358 |
/* This plus STACK_POINTER_REGNUM points to the first work of outgoing args. */ |
| 359 |
#define STACK_POINTER_OFFSET (0) |
| 360 |
|
| 361 |
/* Define this macro if pushing a word onto the stack moves the stack |
| 362 |
pointer to a smaller address. */ |
| 363 |
#define STACK_GROWS_DOWNWARD 1 |
| 364 |
|
| 365 |
#define FRAME_GROWS_DOWNWARD 1 |
| 366 |
|
| 367 |
/* An alias for a machine mode name. This is the machine mode that |
| 368 |
elements of a jump-table should have. */ |
| 369 |
#define CASE_VECTOR_MODE SImode |
| 370 |
|
| 371 |
#define STORE_FLAG_VALUE 1 |
| 372 |
|
| 373 |
/* Indicates how loads of narrow mode values are loaded into words. */ |
| 374 |
#define LOAD_EXTEND_OP(MODE) (ZERO_EXTEND) |
| 375 |
|
| 376 |
/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function, |
| 377 |
the stack pointer does not matter. */ |
| 378 |
#define EXIT_IGNORE_STACK 1 |
| 379 |
|
| 380 |
/* Macros related to the access of the stack frame chain. */ |
| 381 |
#define INITIAL_FRAME_ADDRESS_RTX or1k_initial_frame_addr () |
| 382 |
#define DYNAMIC_CHAIN_ADDRESS or1k_dynamic_chain_addr |
| 383 |
#define RETURN_ADDR_RTX or1k_return_addr |
| 384 |
|
| 385 |
/* Always pass the SYMBOL_REF for direct calls to the expanders. */ |
| 386 |
#define NO_FUNCTION_CSE 1 |
| 387 |
|
| 388 |
#define NO_PROFILE_COUNTERS 1 |
| 389 |
|
| 390 |
/* Emit rtl for profiling. Output assembler code to call "_mcount" for |
| 391 |
profiling a function entry. */ |
| 392 |
#define PROFILE_HOOK(LABEL) or1k_profile_hook() |
| 393 |
|
| 394 |
/* All the work is done in PROFILE_HOOK, but this is still required. */ |
| 395 |
#define FUNCTION_PROFILER(STREAM, LABELNO) do { } while (0) |
| 396 |
|
| 397 |
/* Dwarf 2 Support */ |
| 398 |
#define DWARF2_DEBUGGING_INFO 1 |
| 399 |
#define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, LR_REGNUM) |
| 400 |
#define DWARF_FRAME_RETURN_COLUMN LR_REGNUM |
| 401 |
|
| 402 |
/* Describe how we implement __builtin_eh_return. */ |
| 403 |
#define EH_RETURN_REGNUM HW_TO_GCC_REGNO (23) |
| 404 |
/* Use r25, r27, r29 and r31 (clobber regs) for exception data. |
| 405 |
Recall that these are remapped consecutively. */ |
| 406 |
#define EH_RETURN_DATA_REGNO(N) \ |
| 407 |
((N) < 4 ? HW_TO_GCC_REGNO (25) + (N) : INVALID_REGNUM) |
| 408 |
#define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, EH_RETURN_REGNUM) |
| 409 |
|
| 410 |
/* Select a format to encode pointers in exception handling data. */ |
| 411 |
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ |
| 412 |
(((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) |
| 413 |
|
| 414 |
#endif /* GCC_OR1K_H */ |