00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "config.h"
00018
00019 extern void init_misc(void);
00020 extern EmbeddedTcl et_ns_lib;
00021 extern EmbeddedTcl et_ns_ptypes;
00022
00023
00024 #ifdef MEMDEBUG_SIMULATIONS
00025 #include "mem-trace.h"
00026 MemTrace *globalMemTrace;
00027 #endif
00028
00029 #define NS_BEGIN_EXTERN_C extern "C" {
00030 #define NS_END_EXTERN_C }
00031
00032 NS_BEGIN_EXTERN_C
00033
00034 #ifdef HAVE_FENV_H
00035 #include <fenv.h>
00036 #endif
00037
00038
00039
00040
00041
00042
00043 #ifdef TCL_TEST
00044 EXTERN int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00045 #endif
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int
00065 main(int argc, char **argv)
00066 {
00067 Tcl_Main(argc, argv, Tcl_AppInit);
00068 return 0;
00069 }
00070
00071 #if defined(__i386__) && defined(__GNUC__)
00072
00073 #define HAVE_NS_SETUP_FPU
00074
00075
00076
00077
00078
00079 static void ns_setup_fpu() {
00080
00081 static const int NS_FPU_CW_IC = 0x1000;
00082 static const int NS_FPU_CW_RC = 0x0000;
00083 static const int NS_FPU_CW_PC = 0x0200;
00084 static const int NS_FPU_CW_IEM = 0x0000;
00085 static const int NS_FPU_CW_B6 = 0x0040;
00086 static const int NS_FPU_CW_PM = 0x0020;
00087 static const int NS_FPU_CW_UM = 0x0010;
00088 static const int NS_FPU_CW_OM = 0x0000;
00089 static const int NS_FPU_CW_ZM = 0x0000;
00090 static const int NS_FPU_CW_DM = 0x0002;
00091 static const int NS_FPU_CW_IM = 0x0000;
00092
00093 static const int NS_FPU_CW = NS_FPU_CW_IC
00094 | NS_FPU_CW_RC
00095 | NS_FPU_CW_PC
00096 | NS_FPU_CW_IEM
00097 | NS_FPU_CW_B6
00098 | NS_FPU_CW_PM
00099 | NS_FPU_CW_UM
00100 | NS_FPU_CW_OM
00101 | NS_FPU_CW_ZM
00102 | NS_FPU_CW_DM
00103 | NS_FPU_CW_IM;
00104
00105 unsigned short _cw = NS_FPU_CW;
00106 asm ("fldcw %0" : : "m" (*&_cw));
00107 }
00108 #endif
00109
00110 #if !defined(HAVE_FESETPRECISION) && defined(__i386__) && defined(__GNUC__)
00111
00112 #define HAVE_FESETPRECISION
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 #define FE_FLTPREC 0x000
00123 #define FE_INVALIDPREC 0x100
00124 #define FE_DBLPREC 0x200
00125 #define FE_LDBLPREC 0x300
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 static inline int fesetprecision(int prec)
00140 {
00141 if ( !(prec & ~FE_LDBLPREC) && (prec != FE_INVALIDPREC) )
00142 {
00143 unsigned short cw;
00144 asm ("fnstcw %0":"=m" (*&cw));
00145 asm ("fwait");
00146
00147 cw = (cw & ~FE_LDBLPREC) | (prec & FE_LDBLPREC);
00148
00149 asm volatile ("fldcw %0" : : "m" (*&cw));
00150 return 1;
00151 }
00152 else
00153 return 0;
00154 }
00155 #endif
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 static inline void
00175 setup_floating_point_environment()
00176 {
00177 #ifdef HAVE_NS_SETUP_FPU
00178
00179 ns_setup_fpu();
00180
00181 #else
00182
00183
00184
00185 #ifdef HAVE_FESETPRECISION
00186 fesetprecision(FE_DBLPREC);
00187 #endif
00188
00189 #ifdef HAVE_FEENABLEEXCEPT
00190
00191
00192
00193
00194
00195
00196
00197 int trap_exceptions = 0;
00198 #ifdef FE_DIVBYZERO
00199 trap_exceptions |= FE_DIVBYZERO;
00200 #endif
00201 #ifdef FE_INVALID
00202 trap_exceptions |= FE_INVALID;
00203 #endif
00204 #ifdef FE_OVERFLOW
00205 trap_exceptions |= FE_OVERFLOW;
00206 #endif
00207
00208
00209
00210
00211 feenableexcept(trap_exceptions);
00212 #endif
00213 #endif
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 int
00237 Tcl_AppInit(Tcl_Interp *interp)
00238 {
00239 #ifdef MEMDEBUG_SIMULATIONS
00240 extern MemTrace *globalMemTrace;
00241 globalMemTrace = new MemTrace;
00242 #endif
00243
00244 setup_floating_point_environment();
00245
00246 if (Tcl_Init(interp) == TCL_ERROR ||
00247 Otcl_Init(interp) == TCL_ERROR)
00248 return TCL_ERROR;
00249
00250 #ifdef HAVE_LIBTCLDBG
00251 extern int Tcldbg_Init(Tcl_Interp *);
00252 if (Tcldbg_Init(interp) == TCL_ERROR) {
00253 return TCL_ERROR;
00254 }
00255 #endif
00256
00257 Tcl_SetVar(interp, "tcl_rcFileName", "~/.ns.tcl", TCL_GLOBAL_ONLY);
00258 Tcl::init(interp, "ns");
00259 init_misc();
00260 et_ns_ptypes.load();
00261 et_ns_lib.load();
00262
00263
00264 #ifdef TCL_TEST
00265 if (Tcltest_Init(interp) == TCL_ERROR) {
00266 return TCL_ERROR;
00267 }
00268 Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
00269 (Tcl_PackageInitProc *) NULL);
00270 #endif
00271
00272 return TCL_OK;
00273 }
00274
00275 #ifndef WIN32
00276 void
00277 abort()
00278 {
00279 Tcl& tcl = Tcl::instance();
00280 tcl.evalc("[Simulator instance] flush-trace");
00281 #ifdef abort
00282 #undef abort
00283 abort();
00284 #else
00285 exit(1);
00286 #endif
00287
00288 }
00289 #endif
00290
00291 NS_END_EXTERN_C
00292
00293