Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
548 | serge | 1 | /**************************************************************************** |
2 | * |
||
3 | * Open Watcom Project |
||
4 | * |
||
5 | * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
||
6 | * |
||
7 | * ======================================================================== |
||
8 | * |
||
9 | * This file contains Original Code and/or Modifications of Original |
||
10 | * Code as defined in and that are subject to the Sybase Open Watcom |
||
11 | * Public License version 1.0 (the 'License'). You may not use this file |
||
12 | * except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
||
13 | * ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
||
14 | * provided with the Original Code and Modifications, and is also |
||
15 | * available at www.sybase.com/developer/opensource. |
||
16 | * |
||
17 | * The Original Code and all software distributed under the License are |
||
18 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||
19 | * EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
||
20 | * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
||
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
||
22 | * NON-INFRINGEMENT. Please see the License for the specific language |
||
23 | * governing rights and limitations under the License. |
||
24 | * |
||
25 | * ======================================================================== |
||
26 | * |
||
27 | * Description: Structures for run-time initialization/finalization. |
||
28 | * |
||
29 | ****************************************************************************/ |
||
30 | |||
31 | |||
32 | #ifndef __RTINIT_H__ |
||
33 | #define __RTINIT_H__ |
||
34 | |||
35 | #include "langenvd.h" |
||
36 | #if defined( __PPC__ ) |
||
37 | #define __TGT_SYS __TGT_SYS_AXP_PPC |
||
38 | typedef unsigned __type_rtp; |
||
39 | typedef unsigned __type_pad; |
||
40 | typedef void( *__type_rtn ) ( void ); |
||
41 | #elif defined( __AXP__ ) |
||
42 | #define __TGT_SYS __TGT_SYS_AXP_NT |
||
43 | typedef unsigned __type_rtp; |
||
44 | typedef unsigned __type_pad; |
||
45 | typedef void( *__type_rtn ) ( void ); |
||
46 | #elif defined( __MIPS__ ) |
||
47 | #define __TGT_SYS __TGT_SYS_MIPS |
||
48 | typedef unsigned __type_rtp; |
||
49 | typedef unsigned __type_pad; |
||
50 | typedef void( *__type_rtn ) ( void ); |
||
51 | #else |
||
52 | #define __TGT_SYS __TGT_SYS_X86 |
||
53 | typedef unsigned char __type_rtp; |
||
54 | typedef unsigned short __type_pad; |
||
55 | #if defined( __386__ ) |
||
56 | typedef void __near( *__type_rtn ) ( void ); |
||
57 | #else |
||
58 | typedef void( *__type_rtn ) ( void ); |
||
59 | #endif |
||
60 | #endif |
||
61 | #include "langenv.h" |
||
62 | |||
63 | #if defined( __MEDIUM__ ) || defined( __LARGE__ ) || defined( __HUGE__ ) |
||
64 | #define __LARGE_CODE__ |
||
65 | #endif |
||
66 | |||
67 | // initialization progresses from highest priority to lowest |
||
68 | // finalization progresses from lowest to highest |
||
69 | #pragma pack( 1 ) |
||
70 | struct rt_init // structure placed in XI/YI segment |
||
71 | { |
||
72 | __type_rtp rtn_type; // - near=0/far=1 routine indication |
||
73 | // also used when walking table to flag |
||
74 | // completed entries |
||
75 | __type_rtp priority; // - priority (0-highest 255-lowest) |
||
76 | __type_rtn rtn; // - routine |
||
77 | #if !( defined( __LARGE_CODE__ ) || defined( __386__ ) ) || defined( COMP_CFG_COFF ) |
||
78 | __type_pad padding; // - padding, when small code ptr |
||
79 | // or when risc cpu |
||
80 | #endif |
||
81 | }; |
||
82 | #pragma pack() |
||
83 | |||
84 | #if defined( M_I86 ) |
||
85 | #if defined( __LARGE_CODE__ ) /* segmented large code models */ |
||
86 | #define YIXI( seg, label, routine, priority ) \ |
||
87 | struct rt_init __based( __segname( seg ) ) label = \ |
||
88 | { 1, priority, routine }; |
||
89 | #else /* other segmented models */ |
||
90 | #define YIXI( seg, label, routine, priority ) \ |
||
91 | struct rt_init __based( __segname( seg ) ) label = \ |
||
92 | { 0, priority, routine, 0 }; |
||
93 | #endif |
||
94 | #else /* non-segmented architectures */ |
||
95 | #define YIXI( seg, label, routine, priority ) \ |
||
96 | struct rt_init __based( __segname( seg ) ) label = \ |
||
97 | { 0, priority, routine }; |
||
98 | #endif |
||
99 | |||
100 | /* |
||
101 | Use these when you want a global label for the XI/YI structure |
||
102 | */ |
||
103 | #define XI( label, routine, priority ) YIXI( TS_SEG_XI, label, routine, priority ) |
||
104 | #define YI( label, routine, priority ) YIXI( TS_SEG_YI, label, routine, priority ) |
||
105 | |||
106 | /* |
||
107 | Use these when you don't care about the label on the XI/YI structure |
||
108 | */ |
||
109 | #define __ANON( x ) __anon ## x |
||
110 | #define ANON( x ) __ANON( x ) |
||
111 | #define AXI( routine, priority ) static XI( ANON( __LINE__ ), routine, priority ) |
||
112 | #define AYI( routine, priority ) static YI( ANON( __LINE__ ), routine, priority ) |
||
113 | |||
114 | enum { |
||
115 | INIT_PRIORITY_THREAD = 1, // priority for thread data init |
||
116 | INIT_PRIORITY_FPU = 2, // priority for FPU/EMU init |
||
117 | INIT_PRIORITY_RUNTIME = 10, // priority for run/time initialization |
||
118 | INIT_PRIORITY_IOSTREAM = 20, // priority for IOSTREAM |
||
119 | INIT_PRIORITY_LIBRARY = 32, // default library-initialization priority |
||
120 | INIT_PRIORITY_PROGRAM = 64, // default program-initialization priority |
||
121 | FINI_PRIORITY_DTOR = 40, // priority for module DTOR |
||
122 | DTOR_PRIORITY = 40, // priority for module DTOR |
||
123 | FINI_PRIORITY_EXIT = 16 // when exit() is called, functions between |
||
124 | // 255 and this are called, the rest of the |
||
125 | // fini routines are called from __exit(). |
||
126 | }; |
||
127 | |||
128 | /* have to turn off, or we get unref'd warnings for AXI & AYI stuff */ |
||
129 | #pragma off( unreferenced ) |
||
130 | |||
131 | #endif |