1 // bootstrap.cxx -- bootstrap routines: main()
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 - 2002 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #if defined(__linux__) && defined(__i386__)
29 # include <fpu_control.h>
35 #include <simgear/compiler.h>
36 #include <simgear/structure/exception.hxx>
37 #include <simgear/debug/logstream.hxx>
54 # include <console.h> // -dw- for command line dialog
58 #if defined(__linux__) && defined(__i386__)
60 static void handleFPE (int);
65 fpu_control_t fpe_flags = 0;
66 _FPU_GETCW(fpe_flags);
67 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
68 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
69 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
70 // fpe_flags &= ~_FPU_MASK_OM; // overflow
71 // fpe_flags &= ~_FPU_MASK_UM; // underflow
72 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
73 _FPU_SETCW(fpe_flags);
74 signal(SIGFPE, handleFPE);
81 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
94 short CPSGetCurrentProcess(PSN *psn);
95 short CPSSetProcessName (PSN *psn, char *processname);
96 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
97 short CPSSetFrontProcess(PSN *psn);
100 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
104 // Main entry point; catch any exceptions that have made it this far.
105 int main ( int argc, char **argv ) {
107 // Enable floating-point exceptions for Linux/x86
108 #if defined(__linux__) && defined(__i386__)
112 // Enable floating-point exceptions for Windows
113 #if defined( _MSC_VER ) && defined( DEBUG )
114 // Christian, we should document what this does
115 _control87( _EM_INEXACT, _MCW_EM );
118 #if defined( HAVE_BC5PLUS )
119 _control87(MCW_EM, MCW_EM); /* defined in float.h */
122 // Keyboard focus hack
123 #if defined(__APPLE__) && !defined(OSX_BUNDLE)
127 glutInit (&argc, argv);
129 CPSGetCurrentProcess(&psn);
130 CPSSetProcessName(&psn, "FlightGear");
132 CPSSetFrontProcess(&psn);
136 // FIXME: add other, more specific
139 fgMainInit(argc, argv);
140 } catch (sg_throwable &t) {
141 // We must use cerr rather than
142 // logging, since logging may be
144 cerr << "Fatal error: " << t.getFormattedMessage()
145 << "\n (received from " << t.getOrigin() << ')' << endl;