1# crti.S for Sunplus S+CORE
2#
3#   Copyright (C) 2005-2018 Free Software Foundation, 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# This file makes a stack frame for the contents of the .init and
25# .fini sections.
26.extern _stack
27
28#ifndef __pic__
29.section .init, "ax", @progbits
30        .weak   _start
31        .ent    _start
32        .frame  r0, 0, r3, 0
33        .mask   0x00000000, 0
34_start:
35        la      r28, _gp
36        la      r8, __bss_start
37        la      r9, __bss_end__
38        sub!    r9, r8
39        srli!   r9, 2
40        addi    r9, -1
41        mtsr    r9, sr0
42        li      r9, 0
431:
44        sw      r9, [r8]+, 4
45        bcnz    1b
46        la      r0, _stack
47        jl      _init
48        la      r4, _end
49        jl      _init_argv
50        jl      exit
51        .end    _start
52
53        .weak   _init_argv
54        .ent
55        .frame  r0, 0, r3, 0
56        .mask   0x00000000, 0
57_init_argv:
58        ldiu!   r4, 0
59        ldiu!   r5, 0
60        j       main
61        .end    _init_argv
62
63        .globl  _init
64        .type   _init, %function
65_init:
66        addi    r0, -32
67        sw      r3, [r0, 20]
68
69        .section .fini, "ax", @progbits
70        .globl  _fini
71        .type   _fini, %function
72_fini:
73        addi    r0, -32
74        sw      r3, [r0, 20]
75#else
76.section .init, "ax", @progbits
77        .set    pic
78        .weak   _start
79        .ent    _start
80        .frame  r0, 0, r3, 0
81        .mask   0x00000000, 0
82_start:
83        mv      r29, r3
84        bl      0f
850:
86        .cpload r3
87        mv      r3, r29
88        la      r8, __bss_start
89        la      r9, __bss_end__
90        sub!    r9, r8
91        srli!   r9, 2
92        addi    r9, -1
93        mtsr    r9, sr0
94        li      r9, 0
951:
96        sw      r9, [r8]+, 4
97        bcnz    1b
98        la      r0, _stack
99        bl      _init
100        la      r4, _end
101        la      r29, _init_argv
102        brl     r29
103        la      r29, exit
104        brl     r29
105        .end    _start
106
107        .weak   _init_argv
108        .ent _init_argv
109        .frame  r0, 0, r3, 0
110        .mask   0x00000000, 0
111_init_argv:
112        ldiu!   r4, 0
113        ldiu!   r5, 0
114        la      r29, main
115        brl     r29
116        .end    _init_argv
117
118        .globl  _init
119        .type   _init, %function
120_init:
121        addi    r0, -32
122        sw      r3, [r0, 20]
123
124        .section .fini, "ax", @progbits
125        .globl  _fini
126        .type   _fini, %function
127_fini:
128        addi    r0, -32
129        sw      r3, [r0, 20]
130
131#endif
132