1 /* Static condition handler for Alpha/VMS.
2 Copyright (C) 2005-2009
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 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/>. */
26 /* This file implements __gcc_shell_handler, the static VMS condition handler
27 used as the indirection wrapper around user level handlers installed with
28 establish_vms_condition_handler GCC builtin.
30 [ABI] in comments refers to the "HP OpenVMS calling standard" document
31 dated January 2005. */
33 #include <vms/chfdef.h>
34 #include <vms/pdscdef.h>
35 #include <vms/ssdef.h>
38 typedef unsigned long long REG
;
40 #define REG_AT(addr) (*(REG *)(addr))
42 /* Compute pointer to procedure descriptor (Procedure Value) from Frame
43 Pointer FP, according to the rules in [ABI-3.5.1 Current Procedure]. */
46 ? (((REG_AT (FP) & 0x7) == 0) ? *(PDSCDEF **)(FP) : (PDSCDEF *)(FP)) : 0)
49 __gcc_shell_handler (struct chf$signal_array
*sig_arr
,
50 struct chf$mech_array
*mech_arr
);
52 /* Helper for __gcc_shell_handler. Fetch the pointer to procedure currently
53 registered as the VMS condition handler for the live function with a frame
57 get_dyn_handler_pointer (REG fp
)
59 /* From the frame pointer we find the procedure descriptor, and fetch
60 the handler_data field from there. This field contains the offset
61 from FP at which the address of the currently installed handler is
64 PDSCDEF
* pd
= PV_FOR (fp
);
65 /* Procedure descriptor pointer for the live subprogram with FP as the frame
66 pointer, and to which _gcc_shell_handler is attached as a condition
69 REG handler_slot_offset
;
70 /* Offset from FP at which the address of the currently established real
71 condition handler is to be found. This offset is available from the
72 handler_data field of the procedure descriptor. */
74 REG handler_data_offset
;
75 /* The handler_data field position in the procedure descriptor, which
76 depends on the kind of procedure at hand. */
78 switch (pd
->pdsc$w_flags
& 0xf)
80 case PDSC$K_KIND_FP_STACK
: /* [3.4.2 PD for stack frame procedures] */
81 handler_data_offset
= 40;
84 case PDSC$K_KIND_FP_REGISTER
: /* [3.4.5 PD for reg frame procedures] */
85 handler_data_offset
= 32;
89 handler_data_offset
= 0;
93 /* If we couldn't determine the handler_data field position, give up. */
94 if (handler_data_offset
== 0)
97 /* Otherwise, fetch the fp offset at which the real handler address is to be
98 found, then fetch and return the latter in turn. */
100 handler_slot_offset
= REG_AT ((REG
)pd
+ handler_data_offset
);
102 return (ADDR
) REG_AT (fp
+ handler_slot_offset
);
105 /* The static VMS condition handler for GCC code. Fetch the address of the
106 currently established condition handler, then resignal if there is none or
107 call the handler with the VMS condition arguments. */
110 __gcc_shell_handler (struct chf$signal_array
*sig_arr
,
111 struct chf$mech_array
*mech_arr
)
114 long (*user_handler
) (struct chf$signal_array
*, struct chf$mech_array
*);
116 user_handler
= get_dyn_handler_pointer (mech_arr
->chf$q_mch_frame
);
120 ret
= user_handler (sig_arr
, mech_arr
);