136ac495dSmrg /* Definitions of target machine GNU compiler. 32bit VMS version.
2*8feb0f0bSmrg Copyright (C) 2009-2020 Free Software Foundation, Inc.
336ac495dSmrg Contributed by Douglas B Rupp (rupp@gnat.com).
436ac495dSmrg
536ac495dSmrg This file is part of GCC.
636ac495dSmrg
736ac495dSmrg GCC is free software; you can redistribute it and/or modify
836ac495dSmrg it under the terms of the GNU General Public License as published by
936ac495dSmrg the Free Software Foundation; either version 3, or (at your option)
1036ac495dSmrg any later version.
1136ac495dSmrg
1236ac495dSmrg GCC is distributed in the hope that it will be useful,
1336ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of
1436ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1536ac495dSmrg GNU General Public License for more details.
1636ac495dSmrg
1736ac495dSmrg You should have received a copy of the GNU General Public License
1836ac495dSmrg along with GCC; see the file COPYING3. If not see
1936ac495dSmrg <http://www.gnu.org/licenses/>. */
2036ac495dSmrg
21a2dc1f3fSmrg #define IN_TARGET_CODE 1
22a2dc1f3fSmrg
2336ac495dSmrg #include "config.h"
2436ac495dSmrg #include "system.h"
2536ac495dSmrg #include "coretypes.h"
2636ac495dSmrg #include "target.h"
2736ac495dSmrg #include "tree.h"
2836ac495dSmrg #include "stringpool.h"
2936ac495dSmrg #include "alias.h"
3036ac495dSmrg #include "vms-protos.h"
3136ac495dSmrg #include "output.h"
3236ac495dSmrg #include "dwarf2out.h"
3336ac495dSmrg
3436ac495dSmrg /* Correlation of standard CRTL names with DECCRTL function names. */
3536ac495dSmrg
3636ac495dSmrg /* Name is for a function that allocate memory. Use the 64bit version
3736ac495dSmrg if -mmalloc64. */
3836ac495dSmrg #define VMS_CRTL_MALLOC (1 << 0)
3936ac495dSmrg
4036ac495dSmrg /* If long pointer are enabled, use _NAME64 instead. */
4136ac495dSmrg #define VMS_CRTL_64 (1 << 1)
4236ac495dSmrg
4336ac495dSmrg /* Prepend s/f before the name. To be applied after the previous rule.
4436ac495dSmrg use 's' for S float, 'f' for IEEE 32. */
4536ac495dSmrg #define VMS_CRTL_FLOAT32 (1 << 2)
4636ac495dSmrg
4736ac495dSmrg /* Prepend t/g/d before the name. To be applied after the previous rule.
4836ac495dSmrg use 'g' for VAX G float, 'd' for VAX D float, 't' for IEEE 64. */
4936ac495dSmrg #define VMS_CRTL_FLOAT64 (1 << 3)
5036ac495dSmrg
5136ac495dSmrg /* Prepend d before the name, only if using VAX fp. */
5236ac495dSmrg #define VMS_CRTL_FLOAT64_VAXD (1 << 4)
5336ac495dSmrg
5436ac495dSmrg /* Prepend x before the name for if 128 bit long doubles are enabled. This
5536ac495dSmrg concern mostly 'printf'-like functions. */
5636ac495dSmrg #define VMS_CRTL_FLOAT128 (1 << 5)
5736ac495dSmrg
5836ac495dSmrg /* From xxx, create xxx, xxxf, xxxl using MATH$XXX_T, MATH$XXX_S
5936ac495dSmrg and MATH$XXX{_X} if DPML is used. */
6036ac495dSmrg #define VMS_CRTL_DPML (1 << 6)
6136ac495dSmrg
6236ac495dSmrg /* Together with DPML, it means that all variant (ie xxx, xxxf and xxxl) are
6336ac495dSmrg overridden by decc. Without DPML, it means this is a variant (ie xxxf
6436ac495dSmrg or xxxl) of a function. */
6536ac495dSmrg #define VMS_CRTL_NODPML (1 << 7)
6636ac495dSmrg
6736ac495dSmrg /* Prepend __bsd44_ before the name. To be applied after the P64
6836ac495dSmrg rule. */
6936ac495dSmrg #define VMS_CRTL_BSD44 (1 << 8)
7036ac495dSmrg
7136ac495dSmrg /* Define only in 32 bits mode, as this has no 64 bit variants.
7236ac495dSmrg Concerns getopt/getarg. */
7336ac495dSmrg #define VMS_CRTL_32ONLY (1 << 9)
7436ac495dSmrg
7536ac495dSmrg /* GLobal data prefix (ga_, gl_...) */
7636ac495dSmrg #define VMS_CRTL_G_MASK (7 << 10)
7736ac495dSmrg #define VMS_CRTL_G_NONE (0 << 10)
7836ac495dSmrg #define VMS_CRTL_GA (1 << 10)
7936ac495dSmrg #define VMS_CRTL_GL (2 << 10)
8036ac495dSmrg
8136ac495dSmrg /* Append '_2'. Not compatible with 64. */
8236ac495dSmrg #define VMS_CRTL_FLOATV2 (1 << 13)
8336ac495dSmrg
8436ac495dSmrg struct vms_crtl_name
8536ac495dSmrg {
8636ac495dSmrg /* The standard C name. */
8736ac495dSmrg const char *const name;
8836ac495dSmrg
8936ac495dSmrg /* Flags to drive the translation. */
9036ac495dSmrg unsigned int flags;
9136ac495dSmrg };
9236ac495dSmrg
9336ac495dSmrg /* Map for the translation. */
9436ac495dSmrg
9536ac495dSmrg static const struct vms_crtl_name vms_crtl_names[] =
9636ac495dSmrg {
9736ac495dSmrg #include "vms-crtlmap.h"
9836ac495dSmrg };
9936ac495dSmrg
10036ac495dSmrg /* Number of entires in the above array. */
10136ac495dSmrg
10236ac495dSmrg #define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
10336ac495dSmrg
10436ac495dSmrg /* List of aliased identifiers. They must be persistent across gc. */
10536ac495dSmrg
10636ac495dSmrg static GTY(()) vec<tree, va_gc> *aliases_id;
10736ac495dSmrg
10836ac495dSmrg /* Add a CRTL translation. This simply use the transparent alias
10936ac495dSmrg mechanism, which is platform independent and works with the
11036ac495dSmrg #pragma extern_prefix (which set the assembler name). */
11136ac495dSmrg
11236ac495dSmrg static void
vms_add_crtl_xlat(const char * name,size_t nlen,const char * id_str,size_t id_len)11336ac495dSmrg vms_add_crtl_xlat (const char *name, size_t nlen,
11436ac495dSmrg const char *id_str, size_t id_len)
11536ac495dSmrg {
11636ac495dSmrg tree targ;
11736ac495dSmrg
11836ac495dSmrg /* printf ("vms crtl: %.*s -> %.*s\n", nlen, name, id_len, id_str); */
11936ac495dSmrg
12036ac495dSmrg targ = get_identifier_with_length (name, nlen);
12136ac495dSmrg gcc_assert (!IDENTIFIER_TRANSPARENT_ALIAS (targ));
12236ac495dSmrg IDENTIFIER_TRANSPARENT_ALIAS (targ) = 1;
12336ac495dSmrg TREE_CHAIN (targ) = get_identifier_with_length (id_str, id_len);
12436ac495dSmrg
12536ac495dSmrg vec_safe_push (aliases_id, targ);
12636ac495dSmrg }
12736ac495dSmrg
12836ac495dSmrg /* Do VMS specific stuff on builtins: disable the ones that are not
12936ac495dSmrg standard, mangle names. */
13036ac495dSmrg
13136ac495dSmrg void
vms_patch_builtins(void)13236ac495dSmrg vms_patch_builtins (void)
13336ac495dSmrg {
13436ac495dSmrg /* enum built_in_function bi; */
13536ac495dSmrg unsigned int i;
13636ac495dSmrg
13736ac495dSmrg /* Fwrite on VMS is non-standard. */
13836ac495dSmrg if (builtin_decl_implicit_p (BUILT_IN_FWRITE))
13936ac495dSmrg set_builtin_decl_implicit_p (BUILT_IN_FWRITE, false);
14036ac495dSmrg
14136ac495dSmrg if (builtin_decl_implicit_p (BUILT_IN_FWRITE_UNLOCKED))
14236ac495dSmrg set_builtin_decl_implicit_p (BUILT_IN_FWRITE_UNLOCKED, false);
14336ac495dSmrg
14436ac495dSmrg /* Define aliases for names. */
14536ac495dSmrg for (i = 0; i < NBR_CRTL_NAMES; i++)
14636ac495dSmrg {
14736ac495dSmrg const struct vms_crtl_name *n = &vms_crtl_names[i];
14836ac495dSmrg char res[VMS_CRTL_MAXLEN + 3 + 9 + 1 + 1];
14936ac495dSmrg int rlen;
15036ac495dSmrg int nlen = strlen (n->name);
15136ac495dSmrg
15236ac495dSmrg /* Discard 32ONLY if using 64 bit pointers. */
15336ac495dSmrg if ((n->flags & VMS_CRTL_32ONLY)
15436ac495dSmrg && flag_vms_pointer_size == VMS_POINTER_SIZE_64)
15536ac495dSmrg continue;
15636ac495dSmrg
15736ac495dSmrg /* Handle DPML unless overridden by decc. */
15836ac495dSmrg if ((n->flags & VMS_CRTL_DPML)
15936ac495dSmrg && !(n->flags & VMS_CRTL_NODPML))
16036ac495dSmrg {
16136ac495dSmrg const char *p;
16236ac495dSmrg char alt[VMS_CRTL_MAXLEN + 3];
16336ac495dSmrg
16436ac495dSmrg memcpy (res, "MATH$", 5);
16536ac495dSmrg rlen = 5;
16636ac495dSmrg for (p = n->name; *p; p++)
16736ac495dSmrg res[rlen++] = TOUPPER (*p);
16836ac495dSmrg res[rlen++] = '_';
16936ac495dSmrg res[rlen++] = 'T';
17036ac495dSmrg
17136ac495dSmrg /* Double version. */
17236ac495dSmrg if (!(n->flags & VMS_CRTL_FLOAT64))
17336ac495dSmrg vms_add_crtl_xlat (n->name, nlen, res, rlen);
17436ac495dSmrg
17536ac495dSmrg /* Float version. */
17636ac495dSmrg res[rlen - 1] = 'S';
17736ac495dSmrg memcpy (alt, n->name, nlen);
17836ac495dSmrg alt[nlen] = 'f';
17936ac495dSmrg vms_add_crtl_xlat (alt, nlen + 1, res, rlen);
18036ac495dSmrg
18136ac495dSmrg /* Long double version. */
18236ac495dSmrg res[rlen - 1] = (LONG_DOUBLE_TYPE_SIZE == 128 ? 'X' : 'T');
18336ac495dSmrg alt[nlen] = 'l';
18436ac495dSmrg vms_add_crtl_xlat (alt, nlen + 1, res, rlen);
18536ac495dSmrg
18636ac495dSmrg if (!(n->flags & (VMS_CRTL_FLOAT32 | VMS_CRTL_FLOAT64)))
18736ac495dSmrg continue;
18836ac495dSmrg }
18936ac495dSmrg
19036ac495dSmrg if (n->flags & VMS_CRTL_FLOAT64_VAXD)
19136ac495dSmrg continue;
19236ac495dSmrg
19336ac495dSmrg /* Add the dec-c prefix. */
19436ac495dSmrg memcpy (res, "decc$", 5);
19536ac495dSmrg rlen = 5;
19636ac495dSmrg
19736ac495dSmrg if (n->flags & VMS_CRTL_BSD44)
19836ac495dSmrg {
19936ac495dSmrg memcpy (res + rlen, "__bsd44_", 8);
20036ac495dSmrg rlen += 8;
20136ac495dSmrg }
20236ac495dSmrg
20336ac495dSmrg if ((n->flags & VMS_CRTL_G_MASK) != VMS_CRTL_G_NONE)
20436ac495dSmrg {
20536ac495dSmrg res[rlen++] = 'g';
20636ac495dSmrg switch (n->flags & VMS_CRTL_G_MASK)
20736ac495dSmrg {
20836ac495dSmrg case VMS_CRTL_GA:
20936ac495dSmrg res[rlen++] = 'a';
21036ac495dSmrg break;
21136ac495dSmrg case VMS_CRTL_GL:
21236ac495dSmrg res[rlen++] = 'l';
21336ac495dSmrg break;
21436ac495dSmrg default:
21536ac495dSmrg gcc_unreachable ();
21636ac495dSmrg }
21736ac495dSmrg res[rlen++] = '_';
21836ac495dSmrg }
21936ac495dSmrg
22036ac495dSmrg if (n->flags & VMS_CRTL_FLOAT32)
22136ac495dSmrg res[rlen++] = 'f';
22236ac495dSmrg
22336ac495dSmrg if (n->flags & VMS_CRTL_FLOAT64)
22436ac495dSmrg res[rlen++] = 't';
22536ac495dSmrg
22636ac495dSmrg if ((n->flags & VMS_CRTL_FLOAT128) && LONG_DOUBLE_TYPE_SIZE == 128)
22736ac495dSmrg res[rlen++] = 'x';
22836ac495dSmrg
22936ac495dSmrg memcpy (res + rlen, n->name, nlen);
23036ac495dSmrg
23136ac495dSmrg if ((n->flags & VMS_CRTL_64) == 0)
23236ac495dSmrg {
23336ac495dSmrg rlen += nlen;
23436ac495dSmrg
23536ac495dSmrg if (n->flags & VMS_CRTL_FLOATV2)
23636ac495dSmrg {
23736ac495dSmrg res[rlen++] = '_';
23836ac495dSmrg res[rlen++] = '2';
23936ac495dSmrg }
24036ac495dSmrg vms_add_crtl_xlat (n->name, nlen, res, rlen);
24136ac495dSmrg }
24236ac495dSmrg else
24336ac495dSmrg {
24436ac495dSmrg char alt[VMS_CRTL_MAXLEN + 3];
24536ac495dSmrg bool use_64;
24636ac495dSmrg
24736ac495dSmrg /* Add three translations:
24836ac495dSmrg _X32 -> X
24936ac495dSmrg _X64 -> _X64
25036ac495dSmrg X -> X if short, _X64 if long. */
25136ac495dSmrg alt[0] = '_';
25236ac495dSmrg memcpy (alt + 1, n->name, nlen);
25336ac495dSmrg alt[1 + nlen + 0] = '3';
25436ac495dSmrg alt[1 + nlen + 1] = '2';
25536ac495dSmrg alt[1 + nlen + 2] = 0;
25636ac495dSmrg vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen);
25736ac495dSmrg
25836ac495dSmrg use_64 = (((n->flags & VMS_CRTL_64)
25936ac495dSmrg && flag_vms_pointer_size == VMS_POINTER_SIZE_64)
26036ac495dSmrg || ((n->flags & VMS_CRTL_MALLOC)
26136ac495dSmrg && flag_vms_malloc64
26236ac495dSmrg && flag_vms_pointer_size != VMS_POINTER_SIZE_NONE));
26336ac495dSmrg if (!use_64)
26436ac495dSmrg vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen);
26536ac495dSmrg
26636ac495dSmrg res[rlen++] = '_';
26736ac495dSmrg memcpy (res + rlen, n->name, nlen);
26836ac495dSmrg res[rlen + nlen + 0] = '6';
26936ac495dSmrg res[rlen + nlen + 1] = '4';
27036ac495dSmrg
27136ac495dSmrg if (use_64)
27236ac495dSmrg vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen + 2);
27336ac495dSmrg
27436ac495dSmrg alt[1 + nlen + 0] = '6';
27536ac495dSmrg alt[1 + nlen + 1] = '4';
27636ac495dSmrg vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen + 2);
27736ac495dSmrg }
27836ac495dSmrg }
27936ac495dSmrg }
28036ac495dSmrg
28136ac495dSmrg /* Always default to .text section. */
28236ac495dSmrg
28336ac495dSmrg section *
vms_function_section(tree decl ATTRIBUTE_UNUSED,enum node_frequency freq ATTRIBUTE_UNUSED,bool startup ATTRIBUTE_UNUSED,bool exit ATTRIBUTE_UNUSED)28436ac495dSmrg vms_function_section (tree decl ATTRIBUTE_UNUSED,
28536ac495dSmrg enum node_frequency freq ATTRIBUTE_UNUSED,
28636ac495dSmrg bool startup ATTRIBUTE_UNUSED,
28736ac495dSmrg bool exit ATTRIBUTE_UNUSED)
28836ac495dSmrg {
28936ac495dSmrg return NULL;
29036ac495dSmrg }
29136ac495dSmrg
29236ac495dSmrg /* Additionnal VMS specific code for start_function. */
29336ac495dSmrg
29436ac495dSmrg /* Must be kept in sync with libgcc/config/vms/vms-ucrt0.c */
29536ac495dSmrg #define VMS_MAIN_FLAGS_SYMBOL "__gcc_main_flags"
29636ac495dSmrg #define MAIN_FLAG_64BIT (1 << 0)
29736ac495dSmrg #define MAIN_FLAG_POSIX (1 << 1)
29836ac495dSmrg
29936ac495dSmrg void
vms_start_function(const char * fnname)30036ac495dSmrg vms_start_function (const char *fnname)
30136ac495dSmrg {
30236ac495dSmrg #if VMS_DEBUGGING_INFO
30336ac495dSmrg if (vms_debug_main
30436ac495dSmrg && debug_info_level > DINFO_LEVEL_NONE
30536ac495dSmrg && strncmp (vms_debug_main, fnname, strlen (vms_debug_main)) == 0)
30636ac495dSmrg {
30736ac495dSmrg targetm.asm_out.globalize_label (asm_out_file, VMS_DEBUG_MAIN_POINTER);
30836ac495dSmrg ASM_OUTPUT_DEF (asm_out_file, VMS_DEBUG_MAIN_POINTER, fnname);
30936ac495dSmrg dwarf2out_vms_debug_main_pointer ();
31036ac495dSmrg vms_debug_main = 0;
31136ac495dSmrg }
31236ac495dSmrg #endif
31336ac495dSmrg
31436ac495dSmrg /* Registers flags used for function main. This is necessary for
31536ac495dSmrg crt0 code. */
31636ac495dSmrg if (strcmp (fnname, "main") == 0)
31736ac495dSmrg {
31836ac495dSmrg unsigned int flags = 0;
31936ac495dSmrg
32036ac495dSmrg if (flag_vms_pointer_size == VMS_POINTER_SIZE_64)
32136ac495dSmrg flags |= MAIN_FLAG_64BIT;
32236ac495dSmrg if (!flag_vms_return_codes)
32336ac495dSmrg flags |= MAIN_FLAG_POSIX;
32436ac495dSmrg
32536ac495dSmrg targetm.asm_out.globalize_label (asm_out_file, VMS_MAIN_FLAGS_SYMBOL);
32636ac495dSmrg assemble_name (asm_out_file, VMS_MAIN_FLAGS_SYMBOL);
32736ac495dSmrg fprintf (asm_out_file, " = %u\n", flags);
32836ac495dSmrg }
32936ac495dSmrg }
33036ac495dSmrg
33136ac495dSmrg #include "gt-vms.h"
332