1 /* VMS crt0 returning Unix style condition codes.
2 Copyright (C) 2001-2016 Free Software Foundation, Inc.
3 Contributed by Douglas B. Rupp (rupp@gnat.com).
5 This file is part of GCC.
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)
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.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
29 #if __INITIAL_POINTER_SIZE != 64
30 #error "vms-ucrt0.c must be compiled with -mpointer-size=64"
33 /* Lots of cheat to handle 32bits/64bits pointer conversions.
34 We use 'long long' for 64 bits pointers and 'int' for 32 bits pointers. */
36 extern void decc$
main (void *, void *, void *, void *, unsigned int,
37 unsigned int, int *, int *, int *);
38 extern int main (int, char **, char **);
39 extern int _malloc32 (int);
42 #define MAIN_ASM_NAME asm ("ELF$TFRADR")
47 int __main (void *, void *, void *, void *,
48 unsigned int, unsigned int) MAIN_ASM_NAME
;
50 /* From errnodef.h, but we need to emulate the globalval. */
54 #define STS$V_MSG_NO 0x03
55 #define STS$M_INHIB_MSG 0x10000000
56 /* Symbol defined while main() is compiled to record the flags used.
57 (Note that the symbol defines the value, ie extract the bits from the
59 bit 0 set for 64 bit pointers
60 bit 1 set for posix return value. */
61 extern char __gcc_main_flags
;
65 #define MAIN_FLAG_64BIT (1 << 0)
66 #define MAIN_FLAG_POSIX (1 << 1)
69 __main (void *progxfer
, void *cli_util
, void *imghdr
, void *image_file_desc
,
70 unsigned int linkflag
, unsigned int cliflag
)
78 unsigned int flags
= (unsigned __int64
)&__gcc_main_flags
;
80 /* The argv and envp arrays are 32 bits pointers to 32 bits pointers. */
81 decc$
main (progxfer
, cli_util
, imghdr
, image_file_desc
,
82 linkflag
, cliflag
, &argc
, &argv
, &envp
);
84 if (flags
& MAIN_FLAG_64BIT
)
88 /* Reallocate argv and envp with 64 bit pointers. */
89 argv64
= (char **) _malloc32 (sizeof (char *) * (argc
+ 1));
91 for (i
= 0; i
< argc
; i
++)
92 argv64
[i
] = (char *) (__int64
)(((int *) (__int64
) argv
)[i
]);
96 for (i
= 0; ((int *) (__int64
) envp
)[i
]; i
++)
98 envp64
= (char **) _malloc32 (sizeof (char *) * (i
+ 1));
100 for (i
= 0; ((int *) (__int64
) envp
)[i
]; i
++)
101 envp64
[i
] = (char *)(__int64
)(((int *) (__int64
) envp
)[i
]);
107 argv64
= (char **)(__int64
)argv
;
108 envp64
= (char **)(__int64
)envp
;
111 status
= main (argc
, argv64
, envp64
);
113 if (flags
& MAIN_FLAG_POSIX
)
115 /* Map into a range of 0 - 255. */
120 int save_status
= status
;
122 status
= (__int64
) &C$_EXIT1
+ ((status
- 1) << STS$V_MSG_NO
);
124 /* An exit failure status requires a "severe" error. All
125 status values are defined in errno with a successful (1)
126 severity but can be changed to an error (2) severity by
127 adding 1. In addition for compatibility with UNIX exit()
128 routines we inhibit a run-time error message from being
129 generated on exit(1). */
131 if (save_status
== 1)
134 status
|= STS$M_INHIB_MSG
;