Home | History | Annotate | Line # | Download | only in nios2
crti.S revision 1.1
      1 /* Copyright (C) 2012-2015 Free Software Foundation, Inc.
      2    Contributed by Jonah Graham (jgraham (at) altera.com).
      3    Contributed by Mentor Graphics, Inc.
      4 
      5 This file is free software; you can redistribute it and/or modify it
      6 under the terms of the GNU General Public License as published by the
      7 Free Software Foundation; either version 3, or (at your option) any
      8 later version.
      9 
     10 This file is distributed in the hope that it will be useful, but
     11 WITHOUT ANY WARRANTY; without even the implied warranty of
     12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13 General Public License for more details.
     14 
     15 Under Section 7 of GPL version 3, you are granted additional
     16 permissions described in the GCC Runtime Library Exception, version
     17 3.1, as published by the Free Software Foundation.
     18 
     19 You should have received a copy of the GNU General Public License and
     20 a copy of the GCC Runtime Library Exception along with this program;
     21 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     22 <http://www.gnu.org/licenses/>.  */
     23 
     24 
     25 /* This file just make a stack frame for the contents of the .fini and
     26    .init sections.  Users may put any desired instructions in those
     27    sections.
     28 
     29    While technically any code can be put in the init and fini sections
     30    most stuff will not work other than stuff which obeys the call frame
     31    and ABI.  All the call-preserved registers are saved, the call clobbered
     32    registers should have been saved by the code calling init and fini.
     33 
     34    See crtstuff.c for an example of code that inserts itself in the init
     35    and fini sections.
     36 
     37    See crt0.s for the code that calls init and fini.  */
     38 
     39 	.section	".init"
     40 	.align 2
     41 	.global	_init
     42 _init:
     43 	addi	sp, sp, -48
     44 	stw	ra, 44(sp)
     45 	stw	r23, 40(sp)
     46 	stw	r22, 36(sp)
     47 	stw	r21, 32(sp)
     48 	stw	r20, 28(sp)
     49 	stw	r19, 24(sp)
     50 	stw	r18, 20(sp)
     51 	stw	r17, 16(sp)
     52 	stw	r16, 12(sp)
     53 	stw	fp, 8(sp)
     54 	addi	fp, sp, 8
     55 #ifdef linux
     56 	nextpc	r22
     57 1:	movhi	r2, %hiadj(_gp_got - 1b)
     58 	addi	r2, r2, %lo(_gp_got - 1b)
     59 	add	r22, r22, r2
     60 #endif
     61 
     62 
     63 	.section	".fini"
     64 	.align	2
     65 	.global	_fini
     66 _fini:
     67 	addi	sp, sp, -48
     68 	stw	ra, 44(sp)
     69 	stw	r23, 40(sp)
     70 	stw	r22, 36(sp)
     71 	stw	r21, 32(sp)
     72 	stw	r20, 28(sp)
     73 	stw	r19, 24(sp)
     74 	stw	r18, 20(sp)
     75 	stw	r17, 16(sp)
     76 	stw	r16, 12(sp)
     77 	stw	fp, 8(sp)
     78 	addi	fp, sp, 8
     79 #ifdef linux
     80 	nextpc	r22
     81 1:	movhi	r2, %hiadj(_gp_got - 1b)
     82 	addi	r2, r2, %lo(_gp_got - 1b)
     83 	add	r22, r22, r2
     84 #endif
     85 
     86