OSDN Git Service

* common.opt (R, T, Tbss, Tdata, Ttext, h, z): New.
[pf3gnuchains/gcc-fork.git] / gcc / config / microblaze / microblaze.h
1 /* Definitions of target machine for GNU compiler for Xilinx MicroBlaze.
2    Copyright 2009, 2010 Free Software Foundation, Inc.
3
4    Contributed by Michael Eager <eager@eagercon.com>.
5
6    This file is part of GCC.
7
8    GCC is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published
10    by the Free Software Foundation; either version 3, or (at your
11    option) any later version.
12
13    GCC is distributed in the hope that it will be useful, but WITHOUT
14    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16    License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GCC; see the file COPYING3.  If not see
20    <http://www.gnu.org/licenses/>.  */
21
22 /* Standard GCC variables that we reference.  */
23
24 /* MicroBlaze external variables defined in microblaze.c.  */
25
26 /* Which pipeline to schedule for.  */
27 enum pipeline_type
28 {
29   MICROBLAZE_PIPE_3 = 0,
30   MICROBLAZE_PIPE_5 = 1
31 };
32
33 #define MICROBLAZE_MASK_NO_UNSAFE_DELAY         0x00000001
34
35 /* print_operand punctuation chars */
36 extern char microblaze_print_operand_punct[];
37
38 /* # bytes of data/sdata cutoff */
39 extern int microblaze_section_threshold;
40
41 /* Map register # to debug register # */
42 extern int microblaze_dbx_regno[];
43
44 extern int microblaze_no_unsafe_delay;
45 extern enum pipeline_type microblaze_pipe;
46
47 #define OBJECT_FORMAT_ELF
48
49 /* Default target_flags if no switches are specified  */
50 #define TARGET_DEFAULT      (MASK_SOFT_MUL | MASK_SOFT_DIV | MASK_SOFT_FLOAT)
51
52 /* What is the default setting for -mcpu= . We set it to v4.00.a even though 
53    we are actually ahead. This is safest version that has generate code 
54    compatible for the original ISA */
55 #define MICROBLAZE_DEFAULT_CPU      "v4.00.a"
56
57 /* Macros to decide whether certain features are available or not,
58    depending on the instruction set architecture level.  */
59
60 #define DRIVER_SELF_SPECS                               \
61         "%{mxl-soft-mul:%<mno-xl-soft-mul}",            \
62         "%{mno-xl-barrel-shift:%<mxl-barrel-shift}",    \
63         "%{mno-xl-pattern-compare:%<mxl-pattern-compare}", \
64         "%{mxl-soft-div:%<mno-xl-soft-div}",            \
65         "%{msoft-float:%<mhard-float}"
66
67 /* Tell collect what flags to pass to nm.  */
68 #ifndef NM_FLAGS
69 #define NM_FLAGS "-Bn"
70 #endif
71
72 /* Names to predefine in the preprocessor for this target machine.  */
73 #define TARGET_CPU_CPP_BUILTINS() microblaze_cpp_define (pfile)
74
75 /* Assembler specs.  */
76
77 #define TARGET_ASM_SPEC "%{v}"
78
79 #define ASM_SPEC "\
80 %{microblaze1} \
81 %(target_asm_spec)"
82
83 /* Extra switches sometimes passed to the linker.  */
84 /* -xl-mode-xmdstub translated to -Zxl-mode-xmdstub -- deprecated.  */
85
86 #define LINK_SPEC "%{shared:-shared} -N -relax \
87   %{Zxl-mode-xmdstub:-defsym _TEXT_START_ADDR=0x800} \
88   %{mxl-mode-xmdstub:-defsym _TEXT_START_ADDR=0x800} \
89   %{mxl-gp-opt:%{G*}} %{!mxl-gp-opt: -G 0} \
90   %{!Wl,-T*: %{!T*: -dT xilinx.ld%s}}"
91
92 /* Specs for the compiler proper  */
93
94 #ifndef CC1_SPEC
95 #define CC1_SPEC " \
96 %{G*} %{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \
97 %{save-temps: } \
98 %(subtarget_cc1_spec) \
99 %{mxl-multiply-high:-mcpu=v6.00.a} \
100 "
101 #endif
102
103 #define EXTRA_SPECS                                                     \
104   { "target_asm_spec", TARGET_ASM_SPEC },                               \
105   SUBTARGET_EXTRA_SPECS
106
107 /* Print subsidiary information on the compiler version in use.  */
108 #define MICROBLAZE_VERSION MICROBLAZE_DEFAULT_CPU
109
110 #ifndef MACHINE_TYPE
111 #define MACHINE_TYPE "MicroBlaze/ELF"
112 #endif
113
114 #ifndef TARGET_VERSION_INTERNAL
115 #define TARGET_VERSION_INTERNAL(STREAM)                                 \
116   fprintf (STREAM, " %s %s", MACHINE_TYPE, MICROBLAZE_VERSION)
117 #endif
118
119 #ifndef TARGET_VERSION
120 #define TARGET_VERSION TARGET_VERSION_INTERNAL (stderr)
121 #endif
122
123 /* Local compiler-generated symbols must have a prefix that the assembler
124    understands.   */
125
126 #ifndef LOCAL_LABEL_PREFIX
127 #define LOCAL_LABEL_PREFIX      "$"
128 #endif
129
130 /* fixed registers.  */
131 #define MB_ABI_BASE_REGNUM                   0
132 #define MB_ABI_STACK_POINTER_REGNUM          1
133 #define MB_ABI_GPRO_REGNUM                   2
134 #define MB_ABI_GPRW_REGNUM                  13
135 #define MB_ABI_INTR_RETURN_ADDR_REGNUM      14
136 #define MB_ABI_SUB_RETURN_ADDR_REGNUM       15
137 #define MB_ABI_DEBUG_RETURN_ADDR_REGNUM     16
138 #define MB_ABI_EXCEPTION_RETURN_ADDR_REGNUM 17
139 #define MB_ABI_ASM_TEMP_REGNUM              18  
140 /* This is our temp register.  */
141 #define MB_ABI_FRAME_POINTER_REGNUM         19
142 #define MB_ABI_PIC_ADDR_REGNUM              20
143 #define MB_ABI_PIC_FUNC_REGNUM              21
144 /* Volatile registers.  */
145 #define MB_ABI_INT_RETURN_VAL_REGNUM         3
146 #define MB_ABI_INT_RETURN_VAL2_REGNUM        4
147 #define MB_ABI_FIRST_ARG_REGNUM              5
148 #define MB_ABI_LAST_ARG_REGNUM              10
149 #define MB_ABI_MAX_ARG_REGS                 (MB_ABI_LAST_ARG_REGNUM     \
150                                              - MB_ABI_FIRST_ARG_REGNUM + 1)
151 #define MB_ABI_STATIC_CHAIN_REGNUM           3
152 #define MB_ABI_TEMP1_REGNUM                 11
153 #define MB_ABI_TEMP2_REGNUM                 12
154 #define MB_ABI_MSR_SAVE_REG                 11  
155 /* Volatile register used to save MSR in interrupt handlers.  */
156
157
158 /* Debug stuff.  */
159
160 /* How to renumber registers for dbx and gdb.  */
161 #define DBX_REGISTER_NUMBER(REGNO) microblaze_dbx_regno[(REGNO)]
162
163 /* Generate DWARF exception handling info.  */
164 #define DWARF2_UNWIND_INFO 1
165
166 /* Don't generate .loc operations.  */
167 #define DWARF2_ASM_LINE_DEBUG_INFO 0
168
169 /* The DWARF 2 CFA column which tracks the return address.  */
170 #define DWARF_FRAME_RETURN_COLUMN \
171         (GP_REG_FIRST + MB_ABI_SUB_RETURN_ADDR_REGNUM)
172
173 /* Initial state of return address on entry to func = R15.
174    Actually, the RA is at R15+8, but gcc doesn't know how 
175    to generate this. 
176    NOTE:  GDB has a workaround and expects this incorrect value.
177    If this is fixed, a corresponding fix to GDB is needed.  */
178 #define INCOMING_RETURN_ADDR_RTX                        \
179   gen_rtx_REG (VOIDmode, GP_REG_FIRST + MB_ABI_SUB_RETURN_ADDR_REGNUM)
180
181 /* Use DWARF 2 debugging information by default.  */
182 #define DWARF2_DEBUGGING_INFO
183 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
184
185 /* Target machine storage layout */
186
187 #define BITS_BIG_ENDIAN 0
188 #define BYTES_BIG_ENDIAN 1
189 #define WORDS_BIG_ENDIAN 1
190 #define BITS_PER_UNIT           8
191 #define BITS_PER_WORD           32
192 #define UNITS_PER_WORD          4
193 #define MIN_UNITS_PER_WORD      4
194 #define INT_TYPE_SIZE           32
195 #define SHORT_TYPE_SIZE         16
196 #define LONG_TYPE_SIZE          32
197 #define LONG_LONG_TYPE_SIZE     64
198 #define FLOAT_TYPE_SIZE         32
199 #define DOUBLE_TYPE_SIZE        64
200 #define LONG_DOUBLE_TYPE_SIZE   64
201 #define POINTER_SIZE            32
202 #define PARM_BOUNDARY           32
203 #define FUNCTION_BOUNDARY       32
204 #define EMPTY_FIELD_BOUNDARY    32
205 #define STRUCTURE_SIZE_BOUNDARY 8
206 #define BIGGEST_ALIGNMENT       32
207 #define STRICT_ALIGNMENT        1
208 #define PCC_BITFIELD_TYPE_MATTERS 1
209
210 #define CONSTANT_ALIGNMENT(EXP, ALIGN)                                  \
211   ((TREE_CODE (EXP) == STRING_CST  || TREE_CODE (EXP) == CONSTRUCTOR)   \
212    && (ALIGN) < BITS_PER_WORD                                           \
213         ? BITS_PER_WORD                                                 \
214         : (ALIGN))
215
216 #define DATA_ALIGNMENT(TYPE, ALIGN)                                     \
217   ((((ALIGN) < BITS_PER_WORD)                                           \
218     && (TREE_CODE (TYPE) == ARRAY_TYPE                                  \
219         || TREE_CODE (TYPE) == UNION_TYPE                               \
220         || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
221
222 #define LOCAL_ALIGNMENT(TYPE, ALIGN)                                    \
223     (((TREE_CODE (TYPE) == ARRAY_TYPE                                   \
224        && TYPE_MODE (TREE_TYPE (TYPE)) == QImode)                       \
225      && (ALIGN) < BITS_PER_WORD) ? BITS_PER_WORD : (ALIGN))
226
227 #define WORD_REGISTER_OPERATIONS
228
229 #define LOAD_EXTEND_OP(MODE)  ZERO_EXTEND
230
231 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE)     \
232   if (GET_MODE_CLASS (MODE) == MODE_INT         \
233       && GET_MODE_SIZE (MODE) < 4)              \
234     (MODE) = SImode;
235
236 /* Standard register usage.  */
237
238 /* On the MicroBlaze, we have 32 integer registers */
239
240 #define FIRST_PSEUDO_REGISTER 36
241
242 #define FIXED_REGISTERS                                                 \
243 {                                                                       \
244   1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,                       \
245   1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                       \
246   1, 1, 1, 1                                                            \
247 }
248
249 #define CALL_USED_REGISTERS                                             \
250 {                                                                       \
251   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,                       \
252   1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                       \
253   1, 1, 1, 1                                                            \
254 }
255
256 #define GP_REG_FIRST    0
257 #define GP_REG_LAST     31
258 #define GP_REG_NUM      (GP_REG_LAST - GP_REG_FIRST + 1)
259 #define GP_DBX_FIRST    0
260
261 #define ST_REG          32
262 #define AP_REG_NUM      33
263 #define RAP_REG_NUM     34
264 #define FRP_REG_NUM     35
265
266 #define GP_REG_P(REGNO) ((unsigned) ((REGNO) - GP_REG_FIRST) < GP_REG_NUM)
267 #define ST_REG_P(REGNO) ((REGNO) == ST_REG)
268
269 #define HARD_REGNO_NREGS(REGNO, MODE)                                   \
270         ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
271
272 /* Value is 1 if hard register REGNO can hold a value of machine-mode
273    MODE.  In 32 bit mode, require that DImode and DFmode be in even
274    registers.  For DImode, this makes some of the insns easier to
275    write, since you don't have to worry about a DImode value in
276    registers 3 & 4, producing a result in 4 & 5.
277
278    To make the code simpler HARD_REGNO_MODE_OK now just references an
279    array built in override_options.  Because machmodes.h is not yet
280    included before this file is processed, the MODE bound can't be
281    expressed here.  */
282 extern char microblaze_hard_regno_mode_ok[][FIRST_PSEUDO_REGISTER];
283 #define HARD_REGNO_MODE_OK(REGNO, MODE)                                 \
284             microblaze_hard_regno_mode_ok[ (int)(MODE) ][ (REGNO)]
285
286 #define MODES_TIEABLE_P(MODE1, MODE2)                                   \
287   ((GET_MODE_CLASS (MODE1) == MODE_FLOAT ||                             \
288     GET_MODE_CLASS (MODE1) == MODE_COMPLEX_FLOAT)                       \
289    == (GET_MODE_CLASS (MODE2) == MODE_FLOAT ||                          \
290        GET_MODE_CLASS (MODE2) == MODE_COMPLEX_FLOAT))
291
292 #define STACK_POINTER_REGNUM   (GP_REG_FIRST + MB_ABI_STACK_POINTER_REGNUM)
293
294 #define STACK_POINTER_OFFSET   FIRST_PARM_OFFSET(FNDECL)
295
296 /* Base register for access to local variables of the function.  We
297    pretend that the frame pointer is
298    MB_ABI_INTR_RETURN_ADDR_REGNUM, and then eliminate it
299    to HARD_FRAME_POINTER_REGNUM.  We can get away with this because
300    rMB_ABI_INTR_RETUREN_ADDR_REGNUM is a fixed
301    register(return address for interrupt), and will not be used for
302    anything else.  */
303    
304 #define FRAME_POINTER_REGNUM            FRP_REG_NUM
305 #define HARD_FRAME_POINTER_REGNUM       \
306         (GP_REG_FIRST + MB_ABI_FRAME_POINTER_REGNUM)
307 #define ARG_POINTER_REGNUM              AP_REG_NUM
308 #define RETURN_ADDRESS_POINTER_REGNUM   RAP_REG_NUM
309 #define STATIC_CHAIN_REGNUM             \
310         (GP_REG_FIRST + MB_ABI_STATIC_CHAIN_REGNUM)
311
312 /* registers used in prologue/epilogue code when the stack frame
313    is larger than 32K bytes.  These registers must come from the
314    scratch register set, and not used for passing and returning
315    arguments and any other information used in the calling sequence
316    (such as pic).  */
317
318 #define MICROBLAZE_TEMP1_REGNUM         \
319         (GP_REG_FIRST + MB_ABI_TEMP1_REGNUM)
320
321 #define MICROBLAZE_TEMP2_REGNUM         \
322         (GP_REG_FIRST + MB_ABI_TEMP2_REGNUM)
323
324 #define NO_FUNCTION_CSE                 1
325
326 #define PIC_OFFSET_TABLE_REGNUM         \
327         (flag_pic ? (GP_REG_FIRST + MB_ABI_PIC_ADDR_REGNUM) : \
328         INVALID_REGNUM)
329
330 enum reg_class
331 {
332   NO_REGS,                      /* no registers in set.  */
333   GR_REGS,                      /* integer registers.  */
334   ST_REGS,                      /* status register.  */
335   ALL_REGS,                     /* all registers.  */
336   LIM_REG_CLASSES               /* max value + 1.  */
337 };
338
339 #define N_REG_CLASSES           (int) LIM_REG_CLASSES
340
341 #define GENERAL_REGS            GR_REGS
342
343 #define REG_CLASS_NAMES                                                 \
344 {                                                                       \
345   "NO_REGS",                                                            \
346   "GR_REGS",                                                            \
347   "ST_REGS",                                                            \
348   "ALL_REGS"                                                            \
349 }
350
351 #define REG_CLASS_CONTENTS                                              \
352 {                                                                       \
353   { 0x00000000, 0x00000000 },           /* no registers.  */            \
354   { 0xffffffff, 0x00000000 },           /* integer registers.  */       \
355   { 0x00000000, 0x00000001 },           /* status registers.  */        \
356   { 0xffffffff, 0x0000000f }            /* all registers.  */           \
357 }
358
359 extern enum reg_class microblaze_regno_to_class[];
360
361 #define REGNO_REG_CLASS(REGNO)          microblaze_regno_to_class[ (REGNO) ]
362
363 #define BASE_REG_CLASS                  GR_REGS
364
365 #define INDEX_REG_CLASS                 GR_REGS
366
367 #define GR_REG_CLASS_P(CLASS)           ((CLASS) == GR_REGS)
368
369 /* REGISTER AND CONSTANT CLASSES */
370
371 #define SMALL_INT(X) ((unsigned HOST_WIDE_INT) (INTVAL (X) + 0x8000) < 0x10000)
372 #define LARGE_INT(X) (INTVAL (X) >= 0x80000000 && INTVAL (X) <= 0xffffffff)
373 #define PLT_ADDR_P(X) (GET_CODE (X) == UNSPEC && XINT (X,1) == UNSPEC_PLT)
374 /* Test for a valid operand for a call instruction.
375    Don't allow the arg pointer register or virtual regs
376    since they may change into reg + const, which the patterns
377    can't handle yet.  */
378 #define CALL_INSN_OP(X) (CONSTANT_ADDRESS_P (X) \
379                          || (GET_CODE (X) == REG && X != arg_pointer_rtx\
380                              && ! (REGNO (X) >= FIRST_PSEUDO_REGISTER   \
381                              && REGNO (X) <= LAST_VIRTUAL_REGISTER)))
382
383 /* True if VALUE is a signed 16-bit number.  */
384 #define SMALL_OPERAND(VALUE)                                            \
385   ((unsigned HOST_WIDE_INT) (VALUE) + 0x8000 < 0x10000)
386
387 /* Constant which cannot be loaded in one instruction.  */
388 #define LARGE_OPERAND(VALUE)                                            \
389   ((((VALUE) & ~0x0000ffff) != 0)                                       \
390    && (((VALUE) & ~0x0000ffff) != ~0x0000ffff)                          \
391    && (((VALUE) & 0x0000ffff) != 0                                      \
392        || (((VALUE) & ~2147483647) != 0                                 \
393            && ((VALUE) & ~2147483647) != ~2147483647)))
394         
395 #define PREFERRED_RELOAD_CLASS(X,CLASS)                                 \
396   ((CLASS) != ALL_REGS                                                  \
397    ? (CLASS)                                                    \
398    : ((GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT                      \
399        || GET_MODE_CLASS (GET_MODE (X)) == MODE_COMPLEX_FLOAT)          \
400       ? (GR_REGS)                       \
401       : ((GET_MODE_CLASS (GET_MODE (X)) == MODE_INT                     \
402           || GET_MODE (X) == VOIDmode)                                  \
403          ? (GR_REGS) : (CLASS))))
404
405 #define SECONDARY_MEMORY_NEEDED(CLASS1, CLASS2, MODE)                   \
406   (GET_MODE_CLASS (MODE) == MODE_INT)
407
408 #define CLASS_MAX_NREGS(CLASS, MODE)                                    \
409   ((GET_MODE_SIZE (MODE) + (UNITS_PER_WORD) - 1) / (UNITS_PER_WORD))
410
411 /* Stack layout; function entry, exit and calling.  */
412
413 #define STACK_GROWS_DOWNWARD
414
415 /* Changed the starting frame offset to including the new link stuff */
416 #define STARTING_FRAME_OFFSET                                           \
417    (crtl->outgoing_args_size + FIRST_PARM_OFFSET(FNDECL))
418
419 /* The return address for the current frame is in r31 if this is a leaf
420    function.  Otherwise, it is on the stack.  It is at a variable offset
421    from sp/fp/ap, so we define a fake hard register rap which is a
422    poiner to the return address on the stack.  This always gets eliminated
423    during reload to be either the frame pointer or the stack pointer plus
424    an offset.  */
425
426 #define RETURN_ADDR_RTX(count, frame)                   \
427   microblaze_return_addr(count,frame)
428
429 extern struct microblaze_frame_info current_frame_info;
430
431 #define ELIMINABLE_REGS                                                 \
432 {{ ARG_POINTER_REGNUM,   STACK_POINTER_REGNUM},                         \
433  { ARG_POINTER_REGNUM,   GP_REG_FIRST + MB_ABI_FRAME_POINTER_REGNUM},   \
434  { RETURN_ADDRESS_POINTER_REGNUM, STACK_POINTER_REGNUM},                \
435  { RETURN_ADDRESS_POINTER_REGNUM,                                       \
436    GP_REG_FIRST + MB_ABI_FRAME_POINTER_REGNUM},                         \
437  { RETURN_ADDRESS_POINTER_REGNUM,                                       \
438    GP_REG_FIRST + MB_ABI_SUB_RETURN_ADDR_REGNUM},                       \
439  { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM},                         \
440  { FRAME_POINTER_REGNUM, GP_REG_FIRST + MB_ABI_FRAME_POINTER_REGNUM}}
441
442 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)                     \
443         (OFFSET) = microblaze_initial_elimination_offset ((FROM), (TO))
444
445 #define ACCUMULATE_OUTGOING_ARGS        1
446
447 #define FIRST_PARM_OFFSET(FNDECL)               (UNITS_PER_WORD)
448
449 #define ARG_POINTER_CFA_OFFSET(FNDECL)          0
450
451 #define REG_PARM_STACK_SPACE(FNDECL)            (MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD)
452
453 #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE)   1
454
455 #define STACK_BOUNDARY                          32
456
457 #define NUM_OF_ARGS                             6
458
459 #define GP_RETURN                               (GP_REG_FIRST + MB_ABI_INT_RETURN_VAL_REGNUM)
460
461 #define GP_ARG_FIRST                            (GP_REG_FIRST + MB_ABI_FIRST_ARG_REGNUM)
462 #define GP_ARG_LAST                             (GP_REG_FIRST + MB_ABI_LAST_ARG_REGNUM)
463
464 #define MAX_ARGS_IN_REGISTERS                   MB_ABI_MAX_ARG_REGS
465
466 #define LIBCALL_VALUE(MODE)                                             \
467   gen_rtx_REG (                                                         \
468            ((GET_MODE_CLASS (MODE) != MODE_INT                          \
469              || GET_MODE_SIZE (MODE) >= 4)                              \
470             ? (MODE)                                                    \
471             : SImode), GP_RETURN)
472
473 /* 1 if N is a possible register number for a function value.
474    On the MicroBlaze, R2 R3 are the only register thus used.
475    Currently, R2 are only implemented  here (C has no complex type)  */
476
477 #define FUNCTION_VALUE_REGNO_P(N)               ((N) == GP_RETURN)
478
479 #define FUNCTION_ARG_REGNO_P(N)                 (((N) >= GP_ARG_FIRST && (N) <= GP_ARG_LAST))
480
481 typedef struct microblaze_args
482 {
483   int gp_reg_found;             /* whether a gp register was found yet */
484   int arg_number;               /* argument number */
485   int arg_words;                /* # total words the arguments take */
486   int fp_arg_words;             /* # words for FP args */
487   int last_arg_fp;              /* nonzero if last arg was FP (EABI only) */
488   int fp_code;                  /* Mode of FP arguments */
489   int num_adjusts;              /* number of adjustments made */
490   /* Adjustments made to args pass in regs.  */
491   /* ??? The size is doubled to work around a bug in the code that sets the 
492      adjustments in function_arg.  */
493   struct rtx_def *adjust[MAX_ARGS_IN_REGISTERS * 2];
494 } CUMULATIVE_ARGS;
495
496 #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,FNDECL,N_NAMED_ARGS)    \
497   init_cumulative_args (&CUM, FNTYPE, LIBNAME)
498
499 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)                    \
500   function_arg_advance (&CUM, MODE, TYPE, NAMED)
501
502 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
503   function_arg( &CUM, MODE, TYPE, NAMED)
504
505 #define NO_PROFILE_COUNTERS                     1
506
507 #define FUNCTION_PROFILER(FILE, LABELNO) { \
508   {                                        \
509     fprintf (FILE, "\tbrki\tr16,_mcount\n");           \
510   }                                                    \
511  }
512
513 #define EXIT_IGNORE_STACK                       1
514
515 #define TRAMPOLINE_SIZE                         (32 + 8)
516
517 #define TRAMPOLINE_ALIGNMENT                    32
518
519 #define REGNO_OK_FOR_BASE_P(regno)              microblaze_regno_ok_for_base_p ((regno), 1)
520
521 #define REGNO_OK_FOR_INDEX_P(regno)             microblaze_regno_ok_for_base_p ((regno), 1)
522
523 #ifndef REG_OK_STRICT
524 #define REG_STRICT_FLAG                         0
525 #else
526 #define REG_STRICT_FLAG                         1
527 #endif
528
529 #define REG_OK_FOR_BASE_P(X)    \
530   microblaze_regno_ok_for_base_p (REGNO (X), REG_STRICT_FLAG)
531
532 #define REG_OK_FOR_INDEX_P(X)   \
533   microblaze_regno_ok_for_base_p (REGNO (X), REG_STRICT_FLAG)
534
535 #define MAX_REGS_PER_ADDRESS 2
536
537
538 /* Identify valid constant addresses.  Exclude if PIC addr which 
539    needs scratch register.  */
540 #define CONSTANT_ADDRESS_P(X)                                           \
541   (GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF              \
542     || GET_CODE (X) == CONST_INT                                        \
543     || (GET_CODE (X) == CONST                                           \
544         && ! (flag_pic && pic_address_needs_scratch (X))))
545
546 /* Define this, so that when PIC, reload won't try to reload invalid
547    addresses which require two reload registers.  */
548 #define LEGITIMATE_PIC_OPERAND_P(X)  (!pic_address_needs_scratch (X))
549
550 /* At present, GAS doesn't understand li.[sd], so don't allow it
551    to be generated at present.  */
552 #define LEGITIMATE_CONSTANT_P(X)                                \
553   (GET_CODE (X) != CONST_DOUBLE                                 \
554     || microblaze_const_double_ok (X, GET_MODE (X)))
555
556 #define CASE_VECTOR_MODE                        (SImode)
557
558 #ifndef DEFAULT_SIGNED_CHAR
559 #define DEFAULT_SIGNED_CHAR                     1
560 #endif
561
562 #define MOVE_MAX                                4
563 #define MAX_MOVE_MAX                            8
564
565 #define SLOW_BYTE_ACCESS                        1
566
567 /* sCOND operations return 1.  */
568 #define STORE_FLAG_VALUE                        1
569
570 #define SHIFT_COUNT_TRUNCATED                   1
571
572 /* This results in inefficient code for 64 bit to 32 conversions.
573    Something needs to be done about this.  Perhaps not use any 32 bit
574    instructions?  Perhaps use PROMOTE_MODE?  */
575 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC)  1
576
577 #define Pmode SImode
578
579 #define FUNCTION_MODE   SImode
580
581 /* Mode should alwasy be SImode */
582 #define REGISTER_MOVE_COST(MODE, FROM, TO)                      \
583   ( GR_REG_CLASS_P (FROM) && GR_REG_CLASS_P (TO) ? 2            \
584    : (FROM) == ST_REGS && GR_REG_CLASS_P (TO) ? 4               \
585    : 12)
586
587 #define MEMORY_MOVE_COST(MODE,CLASS,TO_P) \
588   (4 + memory_move_secondary_cost ((MODE), (CLASS), (TO_P)))
589
590 #define BRANCH_COST(speed_p, predictable_p)     2
591
592 /* Control the assembler format that we output.  */
593 #define ASM_APP_ON " #APP\n"
594 #define ASM_APP_OFF " #NO_APP\n"
595
596 #define REGISTER_NAMES {                                                \
597   "r0",   "r1",   "r2",   "r3",   "r4",   "r5",   "r6",   "r7",         \
598   "r8",   "r9",   "r10",  "r11",  "r12",  "r13",  "r14",  "r15",        \
599   "r16",  "r17",  "r18",  "r19",  "r20",  "r21",  "r22",  "r23",        \
600   "r24",  "r25",  "r26",  "r27",  "r28",  "r29",  "r30",  "r31",        \
601   "rmsr", "$ap",  "$rap", "$frp" }
602
603 #define ADDITIONAL_REGISTER_NAMES                                       \
604 {                                                                       \
605   { "r0",        0 + GP_REG_FIRST },                                    \
606   { "r1",        1 + GP_REG_FIRST },                                    \
607   { "r2",        2 + GP_REG_FIRST },                                    \
608   { "r3",        3 + GP_REG_FIRST },                                    \
609   { "r4",        4 + GP_REG_FIRST },                                    \
610   { "r5",        5 + GP_REG_FIRST },                                    \
611   { "r6",        6 + GP_REG_FIRST },                                    \
612   { "r7",        7 + GP_REG_FIRST },                                    \
613   { "r8",        8 + GP_REG_FIRST },                                    \
614   { "r9",        9 + GP_REG_FIRST },                                    \
615   { "r10",      10 + GP_REG_FIRST },                                    \
616   { "r11",      11 + GP_REG_FIRST },                                    \
617   { "r12",      12 + GP_REG_FIRST },                                    \
618   { "r13",      13 + GP_REG_FIRST },                                    \
619   { "r14",      14 + GP_REG_FIRST },                                    \
620   { "r15",      15 + GP_REG_FIRST },                                    \
621   { "r16",      16 + GP_REG_FIRST },                                    \
622   { "r17",      17 + GP_REG_FIRST },                                    \
623   { "r18",      18 + GP_REG_FIRST },                                    \
624   { "r19",      19 + GP_REG_FIRST },                                    \
625   { "r20",      20 + GP_REG_FIRST },                                    \
626   { "r21",      21 + GP_REG_FIRST },                                    \
627   { "r22",      22 + GP_REG_FIRST },                                    \
628   { "r23",      23 + GP_REG_FIRST },                                    \
629   { "r24",      24 + GP_REG_FIRST },                                    \
630   { "r25",      25 + GP_REG_FIRST },                                    \
631   { "r26",      26 + GP_REG_FIRST },                                    \
632   { "r27",      27 + GP_REG_FIRST },                                    \
633   { "r28",      28 + GP_REG_FIRST },                                    \
634   { "r29",      29 + GP_REG_FIRST },                                    \
635   { "r30",      30 + GP_REG_FIRST },                                    \
636   { "r31",      31 + GP_REG_FIRST },                                    \
637   { "rmsr",     ST_REG}                                                 \
638 }
639
640 #define PRINT_OPERAND(FILE, X, CODE) print_operand (FILE, X, CODE)
641
642 #define PRINT_OPERAND_PUNCT_VALID_P(CODE) microblaze_print_operand_punct[CODE]
643
644 #define PRINT_OPERAND_ADDRESS(FILE, ADDR) print_operand_address (FILE, ADDR)
645
646 /* ASM_OUTPUT_ALIGNED_COMMON and ASM_OUTPUT_ALIGNED_LOCAL
647
648    Unfortunately, we still need to set the section explicitly. Somehow,
649    our binutils assign .comm and .lcomm variables to the "current" section 
650    in the assembly file, rather than where they implicitly belong. We need to
651    remove this explicit setting in GCC when binutils can understand sections
652    better.  */
653 #undef  ASM_OUTPUT_ALIGNED_COMMON
654 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)              \
655 do {                                                                    \
656   if (SIZE > 0 && SIZE <= microblaze_section_threshold                  \
657       && TARGET_XLGPOPT)                                               \
658     {                                                                   \
659       switch_to_section (sbss_section);                                 \
660     }                                                                   \
661   else                                                                  \
662     {                                                                   \
663       switch_to_section (bss_section);                                  \
664     }                                                                   \
665   fprintf (FILE, "%s", COMMON_ASM_OP);                                  \
666   assemble_name ((FILE), (NAME));                                       \
667   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",              \
668            (SIZE), (ALIGN) / BITS_PER_UNIT);                            \
669   ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");                     \
670 } while (0)
671
672 #undef ASM_OUTPUT_ALIGNED_LOCAL
673 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)               \
674 do {                                                                    \
675   if (SIZE > 0 && SIZE <= microblaze_section_threshold                  \
676       && TARGET_XLGPOPT)                                               \
677     {                                                                   \
678       switch_to_section (sbss_section);                                 \
679     }                                                                   \
680   else                                                                  \
681     {                                                                   \
682       switch_to_section (bss_section);                                  \
683     }                                                                   \
684   fprintf (FILE, "%s", LCOMMON_ASM_OP);                                 \
685   assemble_name ((FILE), (NAME));                                       \
686   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",              \
687            (SIZE), (ALIGN) / BITS_PER_UNIT);                            \
688   ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");                     \
689 } while (0)
690
691 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN)           \
692 do {                                                                    \
693   ASM_OUTPUT_ALIGNED_LOCAL (FILE, NAME, SIZE, ALIGN);                   \
694 } while (0)
695
696 #define ASM_DECLARE_FUNCTION_NAME(STREAM,NAME,DECL)                     \
697 {                                                                       \
698 }
699
700 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)                   \
701   sprintf ((LABEL), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX), (long)(NUM))
702
703 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE)                          \
704   fprintf (STREAM, "\t%s\t%sL%d\n",                                     \
705            ".gpword",                                                   \
706            LOCAL_LABEL_PREFIX, VALUE)
707
708 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL)              \
709 do {                                                                    \
710   if (flag_pic == 2)                                               \
711     fprintf (STREAM, "\t%s\t%sL%d@GOTOFF\n",                            \
712              ".gpword",                                                 \
713              LOCAL_LABEL_PREFIX, VALUE);                                \
714   else                                                                  \
715     fprintf (STREAM, "\t%s\t%sL%d\n",                                   \
716              ".gpword",                                                 \
717              LOCAL_LABEL_PREFIX, VALUE);                                \
718 } while (0)
719
720 #define ASM_OUTPUT_ALIGN(STREAM,LOG)                                    \
721   fprintf (STREAM, "\t.align\t%d\n", (LOG))
722
723 #define ASM_OUTPUT_SKIP(STREAM,SIZE)                                    \
724   fprintf (STREAM, "\t.space\t%lu\n", (SIZE))
725
726 #define ASCII_DATA_ASM_OP               "\t.ascii\t"
727 #define STRING_ASM_OP                   "\t.asciz\t"
728
729 #define ASM_OUTPUT_IDENT(FILE, STRING)                                  \
730   microblaze_asm_output_ident (FILE, STRING)
731
732 /* Default to -G 8 */
733 #ifndef MICROBLAZE_DEFAULT_GVALUE
734 #define MICROBLAZE_DEFAULT_GVALUE 8
735 #endif
736
737 /* Given a decl node or constant node, choose the section to output it in
738    and select that section.  */
739
740 /* Store in OUTPUT a string (made with alloca) containing
741    an assembler-name for a local static variable named NAME.
742    LABELNO is an integer which is different for each call.  */
743 #define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO)                  \
744 ( (OUTPUT) = (char *) alloca (strlen ((NAME)) + 10),                    \
745   sprintf ((OUTPUT), "%s.%d", (NAME), (LABELNO)))
746
747 /* How to start an assembler comment.
748    The leading space is important (the microblaze assembler requires it).  */
749 #ifndef ASM_COMMENT_START
750 #define ASM_COMMENT_START               " #"
751 #endif
752
753 #define BSS_VAR         1
754 #define SBSS_VAR        2
755 #define DATA_VAR        4
756 #define SDATA_VAR       5
757 #define RODATA_VAR      6
758 #define SDATA2_VAR      7
759
760 /* These definitions are used in with the shift_type flag in the rtl.  */
761 #define SHIFT_CONST     1
762 #define SHIFT_REG       2
763 #define USE_ADDK        3
764
765 /* Handle interrupt attribute.  */
766 extern int interrupt_handler;
767 extern int save_volatiles;
768
769 #define INTERRUPT_HANDLER_NAME "_interrupt_handler"
770
771 /* These #define added for C++.  */
772 #define UNALIGNED_SHORT_ASM_OP          ".data16"
773 #define UNALIGNED_INT_ASM_OP            ".data32"
774 #define UNALIGNED_DOUBLE_INT_ASM_OP     ".data8"
775
776 #define ASM_BYTE_OP                     ".data8"
777
778 /* The following #defines are used in the headers files. Always retain these.  */
779
780 /* Added for declaring size at the end of the function.  */
781 #undef ASM_DECLARE_FUNCTION_SIZE
782 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)                    \
783   do {                                                                  \
784     if (!flag_inhibit_size_directive)                                   \
785       {                                                                 \
786         char label[256];                                                \
787         static int labelno;                                             \
788         labelno++;                                                      \
789         ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);            \
790         (*targetm.asm_out.internal_label) (FILE, "Lfe", labelno);       \
791         fprintf (FILE, "%s", SIZE_ASM_OP);                              \
792         assemble_name (FILE, (FNAME));                                  \
793         fprintf (FILE, ",");                                            \
794         assemble_name (FILE, label);                                    \
795         fprintf (FILE, "-");                                            \
796         assemble_name (FILE, (FNAME));                                  \
797         putc ('\n', FILE);                                              \
798       }                                                                 \
799   } while (0)
800
801 #define GLOBAL_ASM_OP                   "\t.globl\t"
802 #define TYPE_ASM_OP                     "\t.type\t"
803 #define SIZE_ASM_OP                     "\t.size\t"
804 #define COMMON_ASM_OP                   "\t.comm\t"
805 #define LCOMMON_ASM_OP                  "\t.lcomm\t"
806
807 #define MAX_OFILE_ALIGNMENT             (32768*8)
808
809 #define TYPE_OPERAND_FMT                "@%s"
810
811 /* Write the extra assembler code needed to declare an object properly.  */
812 #undef ASM_DECLARE_OBJECT_NAME
813 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                       \
814   do {                                                                  \
815     fprintf (FILE, "%s", TYPE_ASM_OP);                                  \
816     assemble_name (FILE, NAME);                                         \
817     putc (',', FILE);                                                   \
818     fprintf (FILE, TYPE_OPERAND_FMT, "object");                         \
819     putc ('\n', FILE);                                                  \
820     size_directive_output = 0;                                          \
821     if (!flag_inhibit_size_directive && DECL_SIZE (DECL))               \
822       {                                                                 \
823         size_directive_output = 1;                                      \
824         fprintf (FILE, "%s", SIZE_ASM_OP);                              \
825         assemble_name (FILE, NAME);                                     \
826         fprintf (FILE, ",%d\n",  int_size_in_bytes (TREE_TYPE (DECL))); \
827       }                                                                 \
828     microblaze_declare_object (FILE, NAME, "", ":\n", 0);                       \
829   } while (0)
830
831 #undef ASM_FINISH_DECLARE_OBJECT
832 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)         \
833 do {                                                                     \
834      char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);                   \
835      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)                \
836          && ! AT_END && TOP_LEVEL                                        \
837          && DECL_INITIAL (DECL) == error_mark_node                       \
838          && !size_directive_output)                                      \
839        {                                                                 \
840          size_directive_output = 1;                                      \
841          fprintf (FILE, "%s", SIZE_ASM_OP);                              \
842          assemble_name (FILE, name);                                     \
843          fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL)));  \
844        }                                                                 \
845    } while (0)
846
847 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                            \
848  do { fputc ( '\t', FILE);                                            \
849       assemble_name (FILE, LABEL1);                                   \
850       fputs ( " = ", FILE);                                           \
851       assemble_name (FILE, LABEL2);                                   \
852       fputc ( '\n', FILE);                                            \
853  } while (0)
854
855 #define ASM_WEAKEN_LABEL(FILE,NAME)                                     \
856  do { fputs ("\t.weakext\t", FILE);                                     \
857       assemble_name (FILE, NAME);                                       \
858       fputc ('\n', FILE);                                               \
859     } while (0)
860
861 #define MAKE_DECL_ONE_ONLY(DECL)        (DECL_WEAK (DECL) = 1)
862 #undef UNIQUE_SECTION_P
863 #define UNIQUE_SECTION_P(DECL)          (DECL_ONE_ONLY (DECL))
864
865 #undef TARGET_ASM_NAMED_SECTION
866 #define TARGET_ASM_NAMED_SECTION        default_elf_asm_named_section
867
868 /* Define the strings to put out for each section in the object file.  
869    
870    Note: For ctors/dtors, we want to give these sections the SHF_WRITE 
871    attribute to allow shared libraries to patch/resolve addresses into 
872    these locations.  On Microblaze, there is no concept of shared libraries 
873    yet, so this is for future use.  */
874 #define TEXT_SECTION_ASM_OP     "\t.text"
875 #define DATA_SECTION_ASM_OP     "\t.data"
876 #define READONLY_DATA_SECTION_ASM_OP    \
877                                 "\t.rodata"
878 #define BSS_SECTION_ASM_OP      "\t.bss"
879 #define CTORS_SECTION_ASM_OP    "\t.section\t.ctors,\"aw\""
880 #define DTORS_SECTION_ASM_OP    "\t.section\t.dtors,\"aw\""
881 #define INIT_SECTION_ASM_OP     "\t.section\t.init,\"ax\""
882 #define FINI_SECTION_ASM_OP     "\t.section\t.fini,\"ax\""
883
884 #define SDATA_SECTION_ASM_OP    "\t.sdata"      /* Small RW initialized data   */
885 #define SDATA2_SECTION_ASM_OP   "\t.sdata2"     /* Small RO initialized data   */
886 #define SBSS_SECTION_ASM_OP     "\t.sbss"       /* Small RW uninitialized data */
887 #define SBSS2_SECTION_ASM_OP    "\t.sbss2"      /* Small RO uninitialized data */
888
889 #define HOT_TEXT_SECTION_NAME   ".text.hot"
890 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
891                                 ".text.unlikely"
892
893 /* We do this to save a few 10s of code space that would be taken up
894    by the call_FUNC () wrappers, used by the generic CRT_CALL_STATIC_FUNCTION
895    definition in crtstuff.c.  */
896 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)      \
897     asm ( SECTION_OP "\n"                               \
898           "\tbrlid   r15, " #FUNC "\n\t nop\n"         \
899           TEXT_SECTION_ASM_OP);
900
901 /* We need to group -lm as well, since some Newlib math functions 
902    reference __errno!  */
903 #undef LIB_SPEC
904 #define LIB_SPEC \
905 "%{!nostdlib: \
906 %{pg:-start-group -lxilprofile -lgloss -lxil -lc -lm -end-group } \
907 %{!pg:-start-group -lgloss -lxil -lc -lm -end-group }} "
908
909 #undef  ENDFILE_SPEC
910 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
911
912 #define STARTFILE_EXECUTABLE_SPEC   "crt0.o%s crti.o%s crtbegin.o%s"
913 #define STARTFILE_XMDSTUB_SPEC      "crt1.o%s crti.o%s crtbegin.o%s"
914 #define STARTFILE_BOOTSTRAP_SPEC    "crt2.o%s crti.o%s crtbegin.o%s"
915 #define STARTFILE_NOVECTORS_SPEC    "crt3.o%s crti.o%s crtbegin.o%s"
916 #define STARTFILE_CRTINIT_SPEC      "%{!pg: %{!mno-clearbss: crtinit.o%s} \
917 %{mno-clearbss: sim-crtinit.o%s}} \
918 %{pg: %{!mno-clearbss: pgcrtinit.o%s} %{mno-clearbss: sim-pgcrtinit.o%s}}"
919
920 #define STARTFILE_DEFAULT_SPEC      STARTFILE_EXECUTABLE_SPEC
921
922 #undef SUBTARGET_EXTRA_SPECS
923 #define SUBTARGET_EXTRA_SPECS                                           \
924   { "startfile_executable",     STARTFILE_EXECUTABLE_SPEC },            \
925   { "startfile_xmdstub",        STARTFILE_XMDSTUB_SPEC },               \
926   { "startfile_bootstrap",      STARTFILE_BOOTSTRAP_SPEC },             \
927   { "startfile_novectors",      STARTFILE_NOVECTORS_SPEC },             \
928   { "startfile_crtinit",        STARTFILE_CRTINIT_SPEC },               \
929   { "startfile_default",        STARTFILE_DEFAULT_SPEC },
930
931 #undef  STARTFILE_SPEC
932 #define STARTFILE_SPEC  "\
933 %{Zxl-mode-executable   : %(startfile_executable)  ; \
934   mxl-mode-executable   : %(startfile_executable)  ; \
935   Zxl-mode-xmdstub      : %(startfile_xmdstub)     ; \
936   mxl-mode-xmdstub      : %(startfile_xmdstub)     ; \
937   Zxl-mode-bootstrap    : %(startfile_bootstrap)   ; \
938   mxl-mode-bootstrap    : %(startfile_bootstrap)   ; \
939   Zxl-mode-novectors    : %(startfile_novectors)   ; \
940   mxl-mode-novectors    : %(startfile_novectors)   ; \
941   Zxl-mode-xilkernel    : %(startfile_xilkernel)   ; \
942   mxl-mode-xilkernel    : %(startfile_xilkernel)   ; \
943                         : %(startfile_default)       \
944 } \
945 %(startfile_crtinit)"