OSDN Git Service

Replace valid memory checks with new myfault class "exception handling", almost
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / crt0.c
1 /* crt0.c.
2
3    Copyright 2001 Red Hat, Inc.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 #ifdef __PPC__
10 /* For the PowerPC, we want to make this function have its structured
11    exception table exception function point to something we control.  */
12
13 extern void __cygwin_exception_handler();
14 extern void mainCRTStartup(void) __attribute__((__exception__(__cygwin_exception_handler)));
15 #endif
16
17 /* In the following ifdef'd i386 code, the FPU precision is set to 80 bits
18    and all FPU exceptions are masked.  The former is needed to make long
19    doubles work correctly.  The latter causes the FPU to generate NaNs and
20    Infinities instead of signals for certain operations.
21 */
22
23 #ifdef __i386__
24 #define FPU_RESERVED 0xF0C0
25 #define FPU_DEFAULT  0x033f
26
27 /* For debugging on *#!$@ windbg.  bp for breakpoint.  */
28 int __cygwin_crt0_bp = 0;
29 #endif
30
31 extern int main (int argc, char **argv);
32
33 void cygwin_crt0 (int (*main) (int, char **));
34
35 void
36 mainCRTStartup ()
37 {
38 #ifdef __i386__
39   (void)__builtin_return_address(1);
40   asm volatile ("andl $-16,%%esp" ::: "%esp");
41   if (__cygwin_crt0_bp)
42     asm volatile ("int3");
43
44   {
45     volatile unsigned short cw;
46
47     /* Get Control Word */
48     __asm__ volatile ("fnstcw %0" : "=m" (cw) : );
49
50     /* mask in */
51     cw &= FPU_RESERVED;
52     cw |= FPU_DEFAULT;
53
54     /* set cw */
55     __asm__ volatile ("fldcw %0" :: "m" (cw));
56   }
57 #endif
58
59   cygwin_crt0 (main);
60 }