OSDN Git Service

Fix -msdata init code; Make sure correct endian flag is defined
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / eabi.asm
index b5cf5c5..62c483c 100644 (file)
@@ -1,3 +1,39 @@
+/*
+ * special support for eabi
+ *
+ *   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ *   Written By Michael Meissner
+ * 
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ * 
+ * In addition to the permissions in the GNU General Public License, the
+ * Free Software Foundation gives you unlimited permission to link the
+ * compiled version of this file with other programs, and to distribute
+ * those programs without any restriction coming from the use of this
+ * file.  (The General Public License restrictions do apply in other
+ * respects; for example, they cover modification of the file, and
+ * distribution when not linked into another program.)
+ * 
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ * 
+ *    As a special exception, if you link this library with files
+ *    compiled with GCC to produce an executable, this does not cause
+ *    the resulting executable to be covered by the GNU General Public License.
+ *    This exception does not however invalidate any other reasons why
+ *    the executable file might be covered by the GNU General Public License.
+ */ 
+
 /* Do any initializations needed for the eabi environment */
 
        .file   "eabi.asm"
        #include "ppc-asm.h"
 
         .section ".got2","aw"
+       .align  2
 .LCTOC1 = . /* +32768 */
 
 /* Table of addresses */
 .Ltable = .-.LCTOC1
        .long   .LCTOC1                         /* address we are really at */
 
-.Lgot = .-.LCTOC1
-       .long   _GLOBAL_OFFSET_TABLE_           /* normal GOT address */
+.Lsda = .-.LCTOC1
+       .long   _SDA_BASE_                      /* address of the first small data area */
+
+.Lsdas = .-.LCTOC1
+       .long   __SDATA_START__                 /* start of .sdata/.sbss section */
+
+.Lsdae = .-.LCTOC1
+       .long   __SBSS_END__                    /* end of .sdata/.sbss section */
+
+.Lsda2 = .-.LCTOC1
+       .long   _SDA2_BASE_                     /* address of the second small data area */
 
-.Lgots = .-.LCTOC1
-       .long   _GOT_START_                     /* start of .got section */
+.Lsda2s = .-.LCTOC1
+       .long   __SDATA2_START__                /* start of .sdata2/.sbss2 section */
 
-.Lgote = .-.LCTOC1
-       .long   _GOT_END_                       /* end of .got section */
+.Lsda2e = .-.LCTOC1
+       .long   __SBSS2_END__                   /* end of .sdata2/.sbss2 section */
 
 .Lgot2s = .-.LCTOC1
-       .long   _GOT2_START_                    /* -mrelocatable GOT pointers start */
+       .long   __GOT2_START__                  /* -mrelocatable GOT pointers start */
 
 .Lgot2e = .-.LCTOC1
-       .long   _GOT2_END_                      /* -mrelocatable GOT pointers end */
+       .long   __GOT2_END__                    /* -mrelocatable GOT pointers end */
 
 .Lfixups = .-.LCTOC1
-       .long   _FIXUP_START_                   /* start of .fixup section */
+       .long   __FIXUP_START__                 /* start of .fixup section */
 
 .Lfixupe = .-.LCTOC1
-       .long   _FIXUP_END_                     /* end of .fixup section */
+       .long   __FIXUP_END__                   /* end of .fixup section */
+
+.Lctors = .-.LCTOC1
+       .long   __CTOR_LIST__                   /* start of .ctor section */
+
+.Lctore = .-.LCTOC1
+       .long   __CTOR_END__                    /* end of .ctor section */
+
+.Ldtors = .-.LCTOC1
+       .long   __DTOR_LIST__                   /* start of .dtor section */
+
+.Ldtore = .-.LCTOC1
+       .long   __DTOR_END__                    /* end of .dtor section */
+
+.Lexcepts = .-.LCTOC1
+       .long   __EXCEPT_START__                /* start of .gcc_except_table section */
+
+.Lexcepte = .-.LCTOC1
+       .long   __EXCEPT_END__                  /* end of .gcc_except_table section */
+
+.Linit = .-.LCTOC1
+       .long   .Linit_p                        /* address of variable to say we've been called */
+
+       .data
+       .align  2
+.Linit_p:
+       .long   0
 
        .text
+#ifdef _RELOCATABLE
 .Lptr:
        .long   .LCTOC1-.Laddr                  /* PC relative pointer to .got2 */
+#endif
 
 FUNC_START(__eabi)
+
+/* Eliminate -mrelocatable code if not -mrelocatable, so that this file can
+   be assembled with other assemblers than GAS, such as the Solaris PowerPC
+   assembler.  */
+
+#ifdef _RELOCATABLE
        mflr    0
        bl      .Laddr                          /* get current address */
 .Laddr:
@@ -44,33 +124,58 @@ FUNC_START(__eabi)
        lwz     11,(.Lptr-.Laddr)(12)           /* linker generated address of .LCTOC1 */
        add     11,11,12                        /* correct to real pointer */
        lwz     12,.Ltable(11)                  /* get linker's idea of where .Laddr is */
+       lwz     10,.Linit(11)                   /* address of init flag */
        subf.   12,12,11                        /* calculate difference */
+       lwzx    9,10,12                         /* done flag */
        mtlr    0                               /* restore link register */
-       bc      4,2,.Lreloc                     /* skip if we need to relocate */
+       cmplwi  2,9,0                           /* init flag != 0? */
+       bnelr   2                               /* return now, if we've been called already */
+       stwx    1,10,12                         /* store a non-zero value in the done flag */
+       bne-    0,.Lreloc                       /* skip if we need to relocate */
 
-/* Only load up register 2 if there is a .got section */
+#else /* !-mrelocatable */
+       addis   10,0,.Linit_p@ha                /* init flag */
+       addis   11,0,.LCTOC1@ha                 /* load address of .LCTOC1 */
+       lwz     9,.Linit_p@l(10)                /* init flag */
+       addi    11,11,.LCTOC1@l
+       cmplwi  2,9,0                           /* init flag != 0? */
+       bnelr   2                               /* return now, if we've been called already */
+       stw     1,.Linit_p@l(10)                /* store a non-zero value in the done flag */
 
-       lwz     3,.Lgots(11)                    /* start of .got section */
-       lwz     4,.Lgote(11)                    /* end of .got section */
-       cmpw    1,3,4                           /* .got section non-empty? */
-       bc      12,6,.Ldone
+#endif /* !-mrelocatable */
+
+/* Only load up register 13 if there is a .sdata and/or .sbss section */
+
+       lwz     3,.Lsdas(11)                    /* start of .sdata/.sbss section */
+       lwz     4,.Lsdae(11)                    /* end of .sdata/.sbss section */
+       cmpw    1,3,4                           /* .sdata/.sbss section non-empty? */
+       beq-    1,.Lsda2l                       /* skip loading r13 */
 
-/* Normal program, load up register 2 */
+       lwz     13,.Lsda(11)                    /* load r13 with _SDA_BASE address */
 
-       lwz     2,.Lgot(11)                     /* normal GOT address (obsolete in register 2) */
-       mr      13,2                            /* also same as _SDA_BASE_ (V.4 small data ptr) */
+/* Only load up register 2 if there is a .sdata2 and/or .sbss2 section */
+
+.Lsda2l:       
+       lwz     3,.Lsda2s(11)                   /* start of .sdata/.sbss section */
+       lwz     4,.Lsda2e(11)                   /* end of .sdata/.sbss section */
+       cmpw    1,3,4                           /* .sdata/.sbss section non-empty? */
+       beq+    1,.Ldone                        /* skip loading r2 */
+
+       lwz     2,.Lsda2(11)                    /* load r2 with _SDA2_BASE address */
        b       FUNC_NAME(__do_global_ctors)    /* do any C++ global constructors (which returns to caller) */
 
-/* We need to relocate the .got2 pointers.  Don't load register 2 */
 
+#ifdef _RELOCATABLE
 .Lreloc:
+/* We need to relocate the .got2 pointers.  Don't load registers 2 or 13 */
+
        lwz     3,.Lgot2s(11)                   /* GOT pointers start */
        lwz     4,.Lgot2e(11)                   /* GOT pointers end */
        add     3,12,3                          /* adjust pointers */
        add     4,12,4
 
        cmpw    1,3,4                           /* any pointers to adjust */
-       bc      12,6,.Lfix
+       bc      12,6,.Lctor
 
 .Lloop:
        lwz     5,0(3)                          /* next pointer */
@@ -80,9 +185,61 @@ FUNC_START(__eabi)
        cmpw    1,3,4                           /* more pointers to adjust? */
        bc      4,6,.Lloop
 
+/* Fixup the .ctor section for static constructors */
+
+.Lctor:
+       lwz     3,.Lctors(11)                   /* constructors pointers start */
+       lwz     4,.Lctore(11)                   /* constructors pointers end */
+
+       cmpw    1,3,4                           /* any pointers to adjust */
+       bc      12,6,.Ldtor
+
+.Lcloop:
+       lwz     5,0(3)                          /* next pointer */
+       add     5,5,12                          /* adjust */
+       stw     5,0(3)
+       addi    3,3,4                           /* bump to next word */
+       cmpw    1,3,4                           /* more pointers to adjust? */
+       bc      4,6,.Lcloop
+
+/* Fixup the .dtor section for static destructors */
+
+.Ldtor:
+       lwz     3,.Ldtors(11)                   /* destructors pointers start */
+       lwz     4,.Ldtore(11)                   /* destructors pointers end */
+
+       cmpw    1,3,4                           /* any pointers to adjust */
+       bc      12,6,.Lexcept
+
+.Ldloop:
+       lwz     5,0(3)                          /* next pointer */
+       add     5,5,12                          /* adjust */
+       stw     5,0(3)
+       addi    3,3,4                           /* bump to next word */
+       cmpw    1,3,4                           /* more pointers to adjust? */
+       bc      4,6,.Ldloop
+
+/* Fixup the .gcc_except_table section for G++ exceptions */
+
+.Lexcept:
+       lwz     3,.Lexcepts(11)                 /* exception table pointers start */
+       lwz     4,.Lexcepte(11)                 /* exception table pointers end */
+
+       cmpw    1,3,4                           /* any pointers to adjust */
+       bc      12,6,.Lfix
+
+.Leloop:
+       lwz     5,0(3)                          /* next pointer */
+       addi    3,3,4                           /* bump to next word */
+       cmpi    1,5,0
+       beq     1,.Leloop                       /* if NULL pointer, don't adjust */
+       add     5,5,12                          /* adjust */
+       stw     5,-4(3)
+       cmpw    1,3,4                           /* more pointers to adjust? */
+       bc      4,6,.Leloop
+
 /* Fixup any user initialized pointers now (the compiler drops pointers to */
-/* each of the relocs that it does in the .fixup section).  Note, the pointers */
-/* themselves have already been fixed up by the previous loop. */
+/* each of the relocs that it does in the .fixup section).  */
 
 .Lfix:
        lwz     3,.Lfixups(11)                  /* fixup pointers start */
@@ -93,12 +250,15 @@ FUNC_START(__eabi)
 
 .Lfloop:
        lwz     5,0(3)                          /* next pointer */
+       add     5,5,12                          /* adjust pointer */
        lwz     6,0(5)                          /* get the pointer it points to */
+       stw     5,0(3)                          /* store adjusted pointer */
        add     6,6,12                          /* adjust */
        stw     6,0(5)
        addi    3,3,4                           /* bump to next word */
        cmpw    1,3,4                           /* more pointers to adjust? */
        bc      4,6,.Lfloop
+#endif /* _RELOCATABLE */
 
 /* Done adjusting pointers, return */