comparison gcc/config/vms/vms-ucrt0.c @ 68:561a7518be6b

update gcc-4.6
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 21 Aug 2011 07:07:55 +0900
parents
children
comparison
equal deleted inserted replaced
67:f6334be47118 68:561a7518be6b
1 /* VMS crt0 returning Unix style condition codes.
2 Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc.
3 Contributed by Douglas B. Rupp (rupp@gnat.com).
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 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.
20
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/>. */
25
26 #include <stdlib.h>
27
28 /* Lots of cheat to handle 32bits/64bits pointer conversions.
29 We use 'long long' for 64 bits pointers and 'int' for 32 bits pointers. */
30
31 extern void decc$main (void *arg1, void *arg2, void *arg3,
32 void *image_file_desc, void *arg5, void *arg6,
33 int *, int *, int *);
34 extern int main (int, char **, char **);
35 extern int _malloc32 (int);
36
37 #ifdef __ia64__
38 #define MAIN_ASM_NAME asm ("ELF$TFRADR")
39 #else
40 #define MAIN_ASM_NAME
41 #endif
42
43 int __main (void *arg1, void *arg2, void *arg3,
44 void *image_file_desc, void *arg5, void *arg6) MAIN_ASM_NAME;
45
46 /* From errnodef.h, but we need to emulate the globalval. */
47 extern int C$_EXIT1;
48
49 /* From stsdef.h */
50 #define STS$V_MSG_NO 0x03
51 #define STS$M_INHIB_MSG 0x10000000
52
53 /* From ssdef.h */
54 #define SS$_NORMAL 1
55
56 int
57 __main (void *arg1, void *arg2, void *arg3,
58 void *image_file_desc, void *arg5, void *arg6)
59 {
60 int argc;
61 int argv;
62 int envp;
63 int status;
64 int i;
65 long long *long_argv;
66 long long *long_envp;
67
68 /* The argv and envp arrays are 32 bits pointers to 32 bits pointers. */
69 decc$main (arg1, arg2, arg3, image_file_desc,
70 arg5, arg6, &argc, &argv, &envp);
71
72 if (sizeof (void *) == 8)
73 {
74 /* Reallocate argv and envp with 64 bit pointers. */
75 long_argv = (long long *)
76 (long long) _malloc32 (sizeof (long long) * (argc + 1));
77
78 for (i = 0; i < argc; i++)
79 long_argv[i] = ((int *) (long long) argv)[i];
80
81 long_argv[argc] = 0;
82
83 for (i = 0; ((int *) (long long) envp)[i]; i++)
84 ;
85 long_envp = (long long *)
86 (long long) _malloc32 (sizeof (long long) * (i + 1));
87
88 for (i = 0; ((int *) (long long) envp)[i]; i++)
89 long_envp[i] = ((int *) (long long) envp)[i];
90
91 long_envp[i] = 0;
92 }
93 else
94 {
95 long_argv = (long long *) argv;
96 long_envp = (long long *) envp;
97 }
98 status = main (argc, (char **)long_argv, (char **)long_envp);
99
100 #ifdef CRT0_POSIX_EXIT
101 /* Map into a range of 0 - 255. */
102 status = status & 255;
103
104 if (status > 0)
105 {
106 int save_status = status;
107
108 status = (long) &C$_EXIT1 + ((status - 1) << STS$V_MSG_NO);
109
110 /* An exit failure status requires a "severe" error. All status values
111 are defined in errno with a successful (1) severity but can be
112 changed to an error (2) severity by adding 1. In addition for
113 compatibility with UNIX exit() routines we inhibit a run-time error
114 message from being generated on exit(1). */
115
116 if (save_status == 1)
117 {
118 status++;
119 status |= STS$M_INHIB_MSG;
120 }
121 }
122 else
123 status = SS$_NORMAL;
124 #endif /* CRT0_POSIX_EXIT */
125
126 return status;
127 }