| 1 |
/* Definitions of target machine GNU compiler. 32bit VMS version. |
| 2 |
Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Douglas B Rupp ([email protected]). |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public 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 |
#define IN_TARGET_CODE 1 |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include "system.h" |
| 25 |
#include "coretypes.h" |
| 26 |
#include "target.h" |
| 27 |
#include "tree.h" |
| 28 |
#include "stringpool.h" |
| 29 |
#include "alias.h" |
| 30 |
#include "vms-protos.h" |
| 31 |
#include "output.h" |
| 32 |
#include "dwarf2out.h" |
| 33 |
|
| 34 |
/* Correlation of standard CRTL names with DECCRTL function names. */ |
| 35 |
|
| 36 |
/* Name is for a function that allocate memory. Use the 64bit version |
| 37 |
if -mmalloc64. */ |
| 38 |
#define VMS_CRTL_MALLOC (1 << 0) |
| 39 |
|
| 40 |
/* If long pointer are enabled, use _NAME64 instead. */ |
| 41 |
#define VMS_CRTL_64 (1 << 1) |
| 42 |
|
| 43 |
/* Prepend s/f before the name. To be applied after the previous rule. |
| 44 |
use 's' for S float, 'f' for IEEE 32. */ |
| 45 |
#define VMS_CRTL_FLOAT32 (1 << 2) |
| 46 |
|
| 47 |
/* Prepend t/g/d before the name. To be applied after the previous rule. |
| 48 |
use 'g' for VAX G float, 'd' for VAX D float, 't' for IEEE 64. */ |
| 49 |
#define VMS_CRTL_FLOAT64 (1 << 3) |
| 50 |
|
| 51 |
/* Prepend d before the name, only if using VAX fp. */ |
| 52 |
#define VMS_CRTL_FLOAT64_VAXD (1 << 4) |
| 53 |
|
| 54 |
/* Prepend x before the name for if 128 bit long doubles are enabled. This |
| 55 |
concern mostly 'printf'-like functions. */ |
| 56 |
#define VMS_CRTL_FLOAT128 (1 << 5) |
| 57 |
|
| 58 |
/* From xxx, create xxx, xxxf, xxxl using MATH$XXX_T, MATH$XXX_S |
| 59 |
and MATH$XXX{_X} if DPML is used. */ |
| 60 |
#define VMS_CRTL_DPML (1 << 6) |
| 61 |
|
| 62 |
/* Together with DPML, it means that all variant (ie xxx, xxxf and xxxl) are |
| 63 |
overridden by decc. Without DPML, it means this is a variant (ie xxxf |
| 64 |
or xxxl) of a function. */ |
| 65 |
#define VMS_CRTL_NODPML (1 << 7) |
| 66 |
|
| 67 |
/* Prepend __bsd44_ before the name. To be applied after the P64 |
| 68 |
rule. */ |
| 69 |
#define VMS_CRTL_BSD44 (1 << 8) |
| 70 |
|
| 71 |
/* Define only in 32 bits mode, as this has no 64 bit variants. |
| 72 |
Concerns getopt/getarg. */ |
| 73 |
#define VMS_CRTL_32ONLY (1 << 9) |
| 74 |
|
| 75 |
/* GLobal data prefix (ga_, gl_...) */ |
| 76 |
#define VMS_CRTL_G_MASK (7 << 10) |
| 77 |
#define VMS_CRTL_G_NONE (0 << 10) |
| 78 |
#define VMS_CRTL_GA (1 << 10) |
| 79 |
#define VMS_CRTL_GL (2 << 10) |
| 80 |
|
| 81 |
/* Append '_2'. Not compatible with 64. */ |
| 82 |
#define VMS_CRTL_FLOATV2 (1 << 13) |
| 83 |
|
| 84 |
struct vms_crtl_name |
| 85 |
{ |
| 86 |
/* The standard C name. */ |
| 87 |
const char *const name; |
| 88 |
|
| 89 |
/* Flags to drive the translation. */ |
| 90 |
unsigned int flags; |
| 91 |
}; |
| 92 |
|
| 93 |
/* Map for the translation. */ |
| 94 |
|
| 95 |
static const struct vms_crtl_name vms_crtl_names[] = |
| 96 |
{ |
| 97 |
#include "vms-crtlmap.h" |
| 98 |
}; |
| 99 |
|
| 100 |
/* Number of entires in the above array. */ |
| 101 |
|
| 102 |
#define NBR_CRTL_NAMES (ARRAY_SIZE (vms_crtl_names)) |
| 103 |
|
| 104 |
/* List of aliased identifiers. They must be persistent across gc. */ |
| 105 |
|
| 106 |
static GTY(()) vec<tree, va_gc> *aliases_id; |
| 107 |
|
| 108 |
/* Add a CRTL translation. This simply use the transparent alias |
| 109 |
mechanism, which is platform independent and works with the |
| 110 |
#pragma extern_prefix (which set the assembler name). */ |
| 111 |
|
| 112 |
static void |
| 113 |
vms_add_crtl_xlat (const char *name, size_t nlen, |
| 114 |
const char *id_str, size_t id_len) |
| 115 |
{ |
| 116 |
tree targ; |
| 117 |
|
| 118 |
/* printf ("vms crtl: %.*s -> %.*s\n", nlen, name, id_len, id_str); */ |
| 119 |
|
| 120 |
targ = get_identifier_with_length (name, nlen); |
| 121 |
gcc_assert (!IDENTIFIER_TRANSPARENT_ALIAS (targ)); |
| 122 |
IDENTIFIER_TRANSPARENT_ALIAS (targ) = 1; |
| 123 |
TREE_CHAIN (targ) = get_identifier_with_length (id_str, id_len); |
| 124 |
|
| 125 |
vec_safe_push (aliases_id, targ); |
| 126 |
} |
| 127 |
|
| 128 |
/* Do VMS specific stuff on builtins: disable the ones that are not |
| 129 |
standard, mangle names. */ |
| 130 |
|
| 131 |
void |
| 132 |
vms_patch_builtins (void) |
| 133 |
{ |
| 134 |
/* enum built_in_function bi; */ |
| 135 |
unsigned int i; |
| 136 |
|
| 137 |
/* Fwrite on VMS is non-standard. */ |
| 138 |
if (builtin_decl_implicit_p (BUILT_IN_FWRITE)) |
| 139 |
set_builtin_decl_implicit_p (BUILT_IN_FWRITE, false); |
| 140 |
|
| 141 |
if (builtin_decl_implicit_p (BUILT_IN_FWRITE_UNLOCKED)) |
| 142 |
set_builtin_decl_implicit_p (BUILT_IN_FWRITE_UNLOCKED, false); |
| 143 |
|
| 144 |
unsigned long_double_type_size = TYPE_PRECISION (long_double_type_node); |
| 145 |
/* Define aliases for names. */ |
| 146 |
for (i = 0; i < NBR_CRTL_NAMES; i++) |
| 147 |
{ |
| 148 |
const struct vms_crtl_name *n = &vms_crtl_names[i]; |
| 149 |
char res[VMS_CRTL_MAXLEN + 3 + 9 + 1 + 1]; |
| 150 |
int rlen; |
| 151 |
int nlen = strlen (n->name); |
| 152 |
|
| 153 |
/* Discard 32ONLY if using 64 bit pointers. */ |
| 154 |
if ((n->flags & VMS_CRTL_32ONLY) |
| 155 |
&& flag_vms_pointer_size == VMS_POINTER_SIZE_64) |
| 156 |
continue; |
| 157 |
|
| 158 |
/* Handle DPML unless overridden by decc. */ |
| 159 |
if ((n->flags & VMS_CRTL_DPML) |
| 160 |
&& !(n->flags & VMS_CRTL_NODPML)) |
| 161 |
{ |
| 162 |
const char *p; |
| 163 |
char alt[VMS_CRTL_MAXLEN + 3]; |
| 164 |
|
| 165 |
memcpy (res, "MATH$", 5); |
| 166 |
rlen = 5; |
| 167 |
for (p = n->name; *p; p++) |
| 168 |
res[rlen++] = TOUPPER (*p); |
| 169 |
res[rlen++] = '_'; |
| 170 |
res[rlen++] = 'T'; |
| 171 |
|
| 172 |
/* Double version. */ |
| 173 |
if (!(n->flags & VMS_CRTL_FLOAT64)) |
| 174 |
vms_add_crtl_xlat (n->name, nlen, res, rlen); |
| 175 |
|
| 176 |
/* Float version. */ |
| 177 |
res[rlen - 1] = 'S'; |
| 178 |
memcpy (alt, n->name, nlen); |
| 179 |
alt[nlen] = 'f'; |
| 180 |
vms_add_crtl_xlat (alt, nlen + 1, res, rlen); |
| 181 |
|
| 182 |
/* Long double version. */ |
| 183 |
res[rlen - 1] = (long_double_type_size == 128 ? 'X' : 'T'); |
| 184 |
alt[nlen] = 'l'; |
| 185 |
vms_add_crtl_xlat (alt, nlen + 1, res, rlen); |
| 186 |
|
| 187 |
if (!(n->flags & (VMS_CRTL_FLOAT32 | VMS_CRTL_FLOAT64))) |
| 188 |
continue; |
| 189 |
} |
| 190 |
|
| 191 |
if (n->flags & VMS_CRTL_FLOAT64_VAXD) |
| 192 |
continue; |
| 193 |
|
| 194 |
/* Add the dec-c prefix. */ |
| 195 |
memcpy (res, "decc$", 5); |
| 196 |
rlen = 5; |
| 197 |
|
| 198 |
if (n->flags & VMS_CRTL_BSD44) |
| 199 |
{ |
| 200 |
memcpy (res + rlen, "__bsd44_", 8); |
| 201 |
rlen += 8; |
| 202 |
} |
| 203 |
|
| 204 |
if ((n->flags & VMS_CRTL_G_MASK) != VMS_CRTL_G_NONE) |
| 205 |
{ |
| 206 |
res[rlen++] = 'g'; |
| 207 |
switch (n->flags & VMS_CRTL_G_MASK) |
| 208 |
{ |
| 209 |
case VMS_CRTL_GA: |
| 210 |
res[rlen++] = 'a'; |
| 211 |
break; |
| 212 |
case VMS_CRTL_GL: |
| 213 |
res[rlen++] = 'l'; |
| 214 |
break; |
| 215 |
default: |
| 216 |
gcc_unreachable (); |
| 217 |
} |
| 218 |
res[rlen++] = '_'; |
| 219 |
} |
| 220 |
|
| 221 |
if (n->flags & VMS_CRTL_FLOAT32) |
| 222 |
res[rlen++] = 'f'; |
| 223 |
|
| 224 |
if (n->flags & VMS_CRTL_FLOAT64) |
| 225 |
res[rlen++] = 't'; |
| 226 |
|
| 227 |
if ((n->flags & VMS_CRTL_FLOAT128) && long_double_type_size == 128) |
| 228 |
res[rlen++] = 'x'; |
| 229 |
|
| 230 |
memcpy (res + rlen, n->name, nlen); |
| 231 |
|
| 232 |
if ((n->flags & VMS_CRTL_64) == 0) |
| 233 |
{ |
| 234 |
rlen += nlen; |
| 235 |
|
| 236 |
if (n->flags & VMS_CRTL_FLOATV2) |
| 237 |
{ |
| 238 |
res[rlen++] = '_'; |
| 239 |
res[rlen++] = '2'; |
| 240 |
} |
| 241 |
vms_add_crtl_xlat (n->name, nlen, res, rlen); |
| 242 |
} |
| 243 |
else |
| 244 |
{ |
| 245 |
char alt[VMS_CRTL_MAXLEN + 3]; |
| 246 |
bool use_64; |
| 247 |
|
| 248 |
/* Add three translations: |
| 249 |
_X32 -> X |
| 250 |
_X64 -> _X64 |
| 251 |
X -> X if short, _X64 if long. */ |
| 252 |
alt[0] = '_'; |
| 253 |
memcpy (alt + 1, n->name, nlen); |
| 254 |
alt[1 + nlen + 0] = '3'; |
| 255 |
alt[1 + nlen + 1] = '2'; |
| 256 |
alt[1 + nlen + 2] = 0; |
| 257 |
vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen); |
| 258 |
|
| 259 |
use_64 = (((n->flags & VMS_CRTL_64) |
| 260 |
&& flag_vms_pointer_size == VMS_POINTER_SIZE_64) |
| 261 |
|| ((n->flags & VMS_CRTL_MALLOC) |
| 262 |
&& flag_vms_malloc64 |
| 263 |
&& flag_vms_pointer_size != VMS_POINTER_SIZE_NONE)); |
| 264 |
if (!use_64) |
| 265 |
vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen); |
| 266 |
|
| 267 |
res[rlen++] = '_'; |
| 268 |
memcpy (res + rlen, n->name, nlen); |
| 269 |
res[rlen + nlen + 0] = '6'; |
| 270 |
res[rlen + nlen + 1] = '4'; |
| 271 |
|
| 272 |
if (use_64) |
| 273 |
vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen + 2); |
| 274 |
|
| 275 |
alt[1 + nlen + 0] = '6'; |
| 276 |
alt[1 + nlen + 1] = '4'; |
| 277 |
vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen + 2); |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
/* Always default to .text section. */ |
| 283 |
|
| 284 |
section * |
| 285 |
vms_function_section (tree decl ATTRIBUTE_UNUSED, |
| 286 |
enum node_frequency freq ATTRIBUTE_UNUSED, |
| 287 |
bool startup ATTRIBUTE_UNUSED, |
| 288 |
bool exit ATTRIBUTE_UNUSED) |
| 289 |
{ |
| 290 |
return NULL; |
| 291 |
} |
| 292 |
|
| 293 |
/* Additionnal VMS specific code for start_function. */ |
| 294 |
|
| 295 |
/* Must be kept in sync with libgcc/config/vms/vms-ucrt0.c */ |
| 296 |
#define VMS_MAIN_FLAGS_SYMBOL "__gcc_main_flags" |
| 297 |
#define MAIN_FLAG_64BIT (1 << 0) |
| 298 |
#define MAIN_FLAG_POSIX (1 << 1) |
| 299 |
|
| 300 |
void |
| 301 |
vms_start_function (const char *fnname) |
| 302 |
{ |
| 303 |
#if VMS_DEBUGGING_INFO |
| 304 |
if (vms_debug_main |
| 305 |
&& debug_info_level > DINFO_LEVEL_NONE |
| 306 |
&& startswith (vms_debug_main, fnname)) |
| 307 |
{ |
| 308 |
targetm.asm_out.globalize_label (asm_out_file, VMS_DEBUG_MAIN_POINTER); |
| 309 |
ASM_OUTPUT_DEF (asm_out_file, VMS_DEBUG_MAIN_POINTER, fnname); |
| 310 |
dwarf2out_vms_debug_main_pointer (); |
| 311 |
vms_debug_main = 0; |
| 312 |
} |
| 313 |
#endif |
| 314 |
|
| 315 |
/* Registers flags used for function main. This is necessary for |
| 316 |
crt0 code. */ |
| 317 |
if (strcmp (fnname, "main") == 0) |
| 318 |
{ |
| 319 |
unsigned int flags = 0; |
| 320 |
|
| 321 |
if (flag_vms_pointer_size == VMS_POINTER_SIZE_64) |
| 322 |
flags |= MAIN_FLAG_64BIT; |
| 323 |
if (!flag_vms_return_codes) |
| 324 |
flags |= MAIN_FLAG_POSIX; |
| 325 |
|
| 326 |
targetm.asm_out.globalize_label (asm_out_file, VMS_MAIN_FLAGS_SYMBOL); |
| 327 |
assemble_name (asm_out_file, VMS_MAIN_FLAGS_SYMBOL); |
| 328 |
fprintf (asm_out_file, " = %u\n", flags); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
#include "gt-vms.h" |