OSDN Git Service

* config/pa/som.h (MAKE_DECL_ONE_ONLY): Define.
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / som.h
1 /* Definitions for SOM assembler support.
2    Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* So we can conditionalize small amounts of code in pa.c or pa.md.  */
22 #define OBJ_SOM
23
24 /* We do not use BINCL stabs in SOM.
25    ??? If it does not hurt, we probably should to avoid useless divergence
26    from other embedded stabs implementations.  */
27 #undef DBX_USE_BINCL
28
29 /* We make the first line stab special to avoid adding several
30    gross hacks to GAS.  */
31 #undef  ASM_OUTPUT_SOURCE_LINE
32 #define ASM_OUTPUT_SOURCE_LINE(file, line)              \
33   { static int sym_lineno = 1;                          \
34     static tree last_function_decl = NULL;              \
35     if (current_function_decl == last_function_decl)    \
36       fprintf (file, "\t.stabn 68,0,%d,L$M%d-%s\nL$M%d:\n",     \
37                line, sym_lineno,                        \
38                XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0) + 1, \
39                sym_lineno);                             \
40     else                                                \
41       fprintf (file, "\t.stabn 68,0,%d,0\n", line);     \
42     last_function_decl = current_function_decl;         \
43     sym_lineno += 1; }
44
45 /* gdb needs a null N_SO at the end of each file for scattered loading. */
46
47 #undef  DBX_OUTPUT_MAIN_SOURCE_FILE_END
48 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
49   text_section (); \
50   fputs ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE); \
51   fprintf (FILE,                                                        \
52            "\t.stabs \"\",%d,0,0,L$text_end0000\nL$text_end0000:\n", N_SO)
53
54 /* HPUX has a program 'chatr' to list the dependencies of dynamically
55    linked executables and shared libraries.  */
56 #define LDD_SUFFIX "chatr"
57 /* Look for lines like "dynamic   /usr/lib/X11R5/libX11.sl"
58    or "static    /usr/lib/X11R5/libX11.sl". 
59
60    HPUX 10.20 also has lines like "static branch prediction ..."
61    so we filter that out explicitly.
62
63    We also try to bound our search for libraries with marker
64    lines.  What a pain.  */
65 #define PARSE_LDD_OUTPUT(PTR)                                   \
66 do {                                                            \
67   static int in_shlib_list = 0;                                 \
68   while (*PTR == ' ') PTR++;                                    \
69   if (strncmp (PTR, "shared library list:",                     \
70                sizeof ("shared library list:") - 1) == 0)       \
71     {                                                           \
72       PTR = 0;                                                  \
73       in_shlib_list = 1;                                        \
74     }                                                           \
75   else if (strncmp (PTR, "shared library binding:",             \
76                     sizeof ("shared library binding:") - 1) == 0)\
77     {                                                           \
78       PTR = 0;                                                  \
79       in_shlib_list = 0;                                        \
80     }                                                           \
81   else if (strncmp (PTR, "static branch prediction disabled",   \
82                     sizeof ("static branch prediction disabled") - 1) == 0)\
83     {                                                           \
84       PTR = 0;                                                  \
85       in_shlib_list = 0;                                        \
86     }                                                           \
87   else if (in_shlib_list                                        \
88            &&  strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \
89     {                                                           \
90       PTR += sizeof ("dynamic") - 1;                            \
91       while (*p == ' ') PTR++;                                  \
92     }                                                           \
93   else if (in_shlib_list                                        \
94            && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \
95     {                                                           \
96       PTR += sizeof ("static") - 1;                             \
97       while (*p == ' ') PTR++;                                  \
98     }                                                           \
99   else                                                          \
100     PTR = 0;                                                    \
101 } while (0)
102
103 /* Output the label for a function definition.  */
104 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
105 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1)    \
106   do { fprintf (FILE, ",ARGW%d=FR", (ARG0));            \
107        fprintf (FILE, ",ARGW%d=FU", (ARG1));} while (0)
108 #define DFMODE_RETURN_STRING ",RTNVAL=FU"
109 #define SFMODE_RETURN_STRING ",RTNVAL=FR"
110 #else
111 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1)    \
112   do { fprintf (FILE, ",ARGW%d=FU", (ARG0));            \
113        fprintf (FILE, ",ARGW%d=FR", (ARG1));} while (0)
114 #define DFMODE_RETURN_STRING ",RTNVAL=FR"
115 #define SFMODE_RETURN_STRING ",RTNVAL=FU"
116 #endif
117
118 \f
119 /* NAME refers to the function's name.  If we are placing each function into
120    its own section, we need to switch to the section for this function.  Note
121    that the section name will have a "." prefix.  */
122 #define ASM_OUTPUT_FUNCTION_PREFIX(FILE, NAME) \
123   {                                                                     \
124     const char *name;                                                   \
125     STRIP_NAME_ENCODING (name, NAME);                                   \
126     if (TARGET_GAS && in_section == in_text)                            \
127       fputs ("\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE); \
128     else if (TARGET_GAS)                                                \
129       fprintf (FILE,                                                    \
130                "\t.SUBSPA .%s\n", name);                                \
131   }
132     
133 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
134     do { tree fntype = TREE_TYPE (TREE_TYPE (DECL));                    \
135          tree tree_type = TREE_TYPE (DECL);                             \
136          tree parm;                                                     \
137          int i;                                                         \
138          if (TREE_PUBLIC (DECL) || TARGET_GAS)                          \
139            {                                                            \
140              if (TREE_PUBLIC (DECL))                                    \
141                {                                                        \
142                  fputs ("\t.EXPORT ", FILE);                            \
143                  assemble_name (FILE, NAME);                            \
144                  fputs (",ENTRY,PRIV_LEV=3", FILE);                     \
145                }                                                        \
146              else                                                       \
147                {                                                        \
148                  fputs ("\t.PARAM ", FILE);                             \
149                  assemble_name (FILE, NAME);                            \
150                  fputs (",PRIV_LEV=3", FILE);                           \
151                }                                                        \
152              for (parm = DECL_ARGUMENTS (DECL), i = 0; parm && i < 4;   \
153                   parm = TREE_CHAIN (parm))                             \
154                {                                                        \
155                  if (TYPE_MODE (DECL_ARG_TYPE (parm)) == SFmode         \
156                      && ! TARGET_SOFT_FLOAT)                            \
157                    fprintf (FILE, ",ARGW%d=FR", i++);                   \
158                  else if (TYPE_MODE (DECL_ARG_TYPE (parm)) == DFmode    \
159                           && ! TARGET_SOFT_FLOAT)                       \
160                    {                                                    \
161                      if (i <= 2)                                        \
162                        {                                                \
163                          if (i == 1) i++;                               \
164                          ASM_DOUBLE_ARG_DESCRIPTORS (FILE, i++, i++);   \
165                        }                                                \
166                      else                                               \
167                        break;                                           \
168                    }                                                    \
169                  else                                                   \
170                    {                                                    \
171                      int arg_size =                                     \
172                        FUNCTION_ARG_SIZE (TYPE_MODE (DECL_ARG_TYPE (parm)),\
173                                           DECL_ARG_TYPE (parm));        \
174                      /* Passing structs by invisible reference uses     \
175                         one general register.  */                       \
176                      if (arg_size > 2                                   \
177                          || TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))    \
178                        arg_size = 1;                                    \
179                      if (arg_size == 2 && i <= 2)                       \
180                        {                                                \
181                          if (i == 1) i++;                               \
182                          fprintf (FILE, ",ARGW%d=GR", i++);             \
183                          fprintf (FILE, ",ARGW%d=GR", i++);             \
184                        }                                                \
185                      else if (arg_size == 1)                            \
186                        fprintf (FILE, ",ARGW%d=GR", i++);               \
187                      else                                               \
188                        i += arg_size;                                   \
189                    }                                                    \
190                }                                                        \
191              /* anonymous args */                                       \
192              if ((TYPE_ARG_TYPES (tree_type) != 0                       \
193                   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
194                       != void_type_node))                               \
195                  || current_function_varargs)                           \
196                {                                                        \
197                  for (; i < 4; i++)                                     \
198                    fprintf (FILE, ",ARGW%d=GR", i);                     \
199                }                                                        \
200              if (TYPE_MODE (fntype) == DFmode && ! TARGET_SOFT_FLOAT)   \
201                fputs (DFMODE_RETURN_STRING, FILE);                      \
202              else if (TYPE_MODE (fntype) == SFmode && ! TARGET_SOFT_FLOAT) \
203                fputs (SFMODE_RETURN_STRING, FILE);                      \
204              else if (fntype != void_type_node)                         \
205                fputs (",RTNVAL=GR", FILE);                              \
206              fputs ("\n", FILE);                                        \
207            }} while (0)
208
209 /* Output at beginning of assembler file.  */
210
211 #define ASM_FILE_START(FILE) \
212 do {  \
213      if (TARGET_PA_20) \
214        fputs("\t.LEVEL 2.0\n", FILE); \
215      else if (TARGET_PA_11) \
216        fputs("\t.LEVEL 1.1\n", FILE); \
217      else \
218        fputs("\t.LEVEL 1.0\n", FILE); \
219      fputs ("\t.SPACE $PRIVATE$\n\
220 \t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31\n\
221 \t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82\n\
222 \t.SPACE $TEXT$\n\
223 \t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44\n\
224 \t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n\
225 \t.IMPORT $global$,DATA\n\
226 \t.IMPORT $$dyncall,MILLICODE\n", FILE);\
227      if (profile_flag)\
228        fprintf (FILE, "\t.IMPORT _mcount, CODE\n");\
229      if (write_symbols != NO_DEBUG) \
230        output_file_directive ((FILE), main_input_filename); \
231    } while (0)
232
233 /* Output before code.  */
234
235 /* Supposedly the assembler rejects the command if there is no tab!  */
236 #define TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$\n"
237
238 /* Output before read-only data.  */
239
240 /* Supposedly the assembler rejects the command if there is no tab!  */
241 #define READONLY_DATA_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$\n"
242
243 #define READONLY_DATA_SECTION readonly_data
244
245 /* Output before writable data.  */
246
247 /* Supposedly the assembler rejects the command if there is no tab!  */
248 #define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
249
250 /* Output before uninitialized data.  */
251
252 #define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
253
254 /* Define the .bss section for ASM_OUTPUT_LOCAL to use. */
255
256 #ifndef CTORS_SECTION_FUNCTION
257 #define EXTRA_SECTIONS in_readonly_data
258 #define CTORS_SECTION_FUNCTION
259 #define DTORS_SECTION_FUNCTION
260 #else
261 #define EXTRA_SECTIONS in_readonly_data, in_ctors, in_dtors
262 #endif
263
264 /* Switch into a generic section.
265    This is currently only used to support section attributes.
266
267    We make the section read-only and executable for a function decl,
268    read-only for a const data decl, and writable for a non-const data decl.  */
269 #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME, RELOC) \
270   if (DECL && TREE_CODE (DECL) == FUNCTION_DECL)                \
271     {                                                           \
272       fputs ("\t.SPACE $TEXT$\n", FILE);                        \
273       fprintf (FILE,                                            \
274                "\t.SUBSPA %s%s%s,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY,SORT=24\n",\
275                TARGET_GAS ? "" : "$", NAME, TARGET_GAS ? "" : "$"); \
276     }                                                           \
277   else if (DECL && DECL_READONLY_SECTION (DECL, RELOC))         \
278     {                                                           \
279       fputs ("\t.SPACE $TEXT$\n", FILE);                        \
280       fprintf (FILE,                                            \
281                "\t.SUBSPA %s%s%s,QUAD=0,ALIGN=8,ACCESS=44,SORT=16\n", \
282                TARGET_GAS ? "" : "$", NAME, TARGET_GAS ? "" : "$"); \
283     }                                                           \
284   else                                                          \
285     {                                                           \
286       fputs ("\t.SPACE $PRIVATE$\n", FILE);                     \
287       fprintf (FILE,                                            \
288                "\t.SUBSPA %s%s%s,QUAD=1,ALIGN=8,ACCESS=31,SORT=16\n", \
289                TARGET_GAS ? "" : "$", NAME, TARGET_GAS ? "" : "$"); \
290     }
291
292 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
293    which reference data within the $TEXT$ space (for example constant
294    strings in the $LIT$ subspace).
295
296    The assemblers (GAS and HP as) both have problems with handling
297    the difference of two symbols which is the other correct way to
298    reference constant data during PIC code generation.
299
300    So, there's no way to reference constant data which is in the
301    $TEXT$ space during PIC generation.  Instead place all constant
302    data into the $PRIVATE$ subspace (this reduces sharing, but it
303    works correctly).  */
304
305 #define EXTRA_SECTION_FUNCTIONS                                         \
306 void                                                                    \
307 readonly_data ()                                                        \
308 {                                                                       \
309   if (in_section != in_readonly_data)                                   \
310     {                                                                   \
311       if (flag_pic)                                                     \
312         fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);            \
313       else                                                              \
314         fprintf (asm_out_file, "%s\n", READONLY_DATA_ASM_OP);           \
315       in_section = in_readonly_data;                                    \
316     }                                                                   \
317 }                                                                       \
318 CTORS_SECTION_FUNCTION                                                  \
319 DTORS_SECTION_FUNCTION
320
321 /* This is how to output a command to make the user-level label named NAME
322    defined for reference from other files.
323
324    We call assemble_name, which in turn sets TREE_SYMBOL_REFERENCED.  This
325    macro will restore the original value of TREE_SYMBOL_REFERENCED to avoid
326    placing useless function definitions in the output file.
327
328    Also note that the SOM based tools need the symbol imported as a CODE
329    symbol, while the ELF based tools require the symbol to be imported as
330    an ENTRY symbol.  What a crock.  */
331
332 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)   \
333   do { int save_referenced;                                     \
334        save_referenced = TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)); \
335        fputs ("\t.IMPORT ", FILE);                                      \
336          assemble_name (FILE, NAME);                            \
337        if (FUNCTION_NAME_P (NAME))                              \
338          fputs (",CODE\n", FILE);                               \
339        else                                                     \
340          fputs (",DATA\n", FILE);                               \
341        TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)) = save_referenced; \
342      } while (0)
343
344 /* The bogus HP assembler requires ALL external references to be
345    "imported", even library calls. They look a bit different, so
346    here's this macro.
347
348    Also note not all libcall names are passed to ENCODE_SECTION_INFO
349    (__main for example).  To make sure all libcall names have section
350    info recorded in them, we do it here.  */
351
352 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
353   do { fputs ("\t.IMPORT ", FILE);                                      \
354        if (!function_label_operand (RTL, VOIDmode))                     \
355          hppa_encode_label (RTL, 1);                                    \
356        assemble_name (FILE, XSTR ((RTL), 0));                           \
357        fputs (",CODE\n", FILE);                                         \
358      } while (0)
359
360 #define ASM_FILE_END(FILE) output_deferred_plabels (FILE)
361
362 /* We want __gcc_plt_call to appear in every program built by
363    gcc, so we make a reference to it out of __main.
364    We use the asm statement to fool the optimizer into not
365    removing the dead (but important) initialization of
366    REFERENCE.  */
367
368 #define DO_GLOBAL_DTORS_BODY                    \
369 do {                                            \
370   extern void __gcc_plt_call ();                \
371   void (*reference)() = &__gcc_plt_call;        \
372   func_ptr *p;                                  \
373   __asm__ ("" : : "r" (reference));             \
374   for (p = __DTOR_LIST__ + 1; *p; )             \
375     (*p++) ();                                  \
376 } while (0)
377
378 /* The .align directive in the HP assembler allows up to a 32 alignment.  */
379 #define MAX_OFILE_ALIGNMENT 32768
380
381 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
382
383 /* This is how we tell the assembler that a symbol is weak.  */
384
385 #define ASM_WEAKEN_LABEL(FILE,NAME) \
386   do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
387        fputc ('\n', FILE); } while (0)