~ubuntu-branches/ubuntu/hardy/silo/hardy-updates

« back to all changes in this revision

Viewing changes to second/crt0.S

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Linux SPARC/UltraSPARC Loader Bootstrap
 
2
 
 
3
   Copyright (C) 1996,1997,1998,2000 Jakub Jelinek
 
4
                 1998 Jan Vondrak
 
5
                 1996 Pete A. Zaitcev
 
6
                 1996 Miguel de Icaza
 
7
                 2001 Ben Collins
 
8
 
 
9
   This program is free software; you can redistribute it and/or modify
 
10
   it under the terms of the GNU General Public License as published by
 
11
   the Free Software Foundation; either version 2 of the License, or
 
12
   (at your option) any later version.
 
13
   
 
14
   This program is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
   GNU General Public License for more details.
 
18
 
 
19
   You should have received a copy of the GNU General Public License
 
20
   along with this program; if not, write to the Free Software
 
21
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
22
   USA.  */
 
23
 
 
24
#define COPY    jmpl    %o7 + (copy - _start), %l7
 
25
 
 
26
        .text
 
27
        .global _start
 
28
        .global silo_conf, silo_conf_part, boot_part
 
29
        .global raid_dsk_number, silo_conf_parts, boot_parts
 
30
_start:
 
31
        call    1f
 
32
         mov    %o7, %l0
 
33
 
 
34
        .byte   'L'     ! This is for the primary loader to check if we are ok... :)
 
35
silo_conf_part:
 
36
        .byte   0
 
37
boot_part:
 
38
        .byte   0
 
39
raid_dsk_number:
 
40
        .byte   0
 
41
        .align 4
 
42
silo_conf:
 
43
        .skip  256
 
44
        .ascii  IMGVERSION
 
45
imglen: .word   0
 
46
silo_conf_parts:
 
47
        .skip   32
 
48
boot_parts:
 
49
        .skip   32
 
50
1:      /* First store %l3 to raid_dsk_number */
 
51
        stb     %l3, [%l0 + (raid_dsk_number - _start)]
 
52
        /* Move ourselves up - there are three chunks to move. */
 
53
        clr     %i3
 
54
        tst     %o4
 
55
        bne,a   1f
 
56
         sethi  %hi(0x100000), %i3
 
57
1:      set     main_text_start, %l3
 
58
        set     _start, %l4
 
59
        add     %l4, %i3, %i0
 
60
        mov     %i0, %l1
 
61
        COPY
 
62
         sub    %l3, %l4, %l2
 
63
 
 
64
        set     main_rodata_start, %l3
 
65
        set     main_text_end, %l4
 
66
        add     %l4, %i3, %l1
 
67
        COPY
 
68
         sub    %l3, %l4, %l2
 
69
 
 
70
        set     main_data_start, %l3
 
71
        set     main_rodata_end, %l4
 
72
        add     %l4, %i3, %l1
 
73
        COPY
 
74
         sub    %l3, %l4, %l2
 
75
 
 
76
        set     __bss_start + 16, %i1
 
77
        set     main_data_end, %l4
 
78
        add     %l4, %i3, %l1
 
79
        COPY
 
80
         sub    %i1, %l4, %l2
 
81
 
 
82
        sub     %l0, 16, %l0
 
83
        sethi   %hi(gzminpi), %l1
 
84
        add     %l1, %i3, %l1
 
85
        st      %l0, [%l1 + %lo(gzminpi)]
 
86
 
 
87
        /* Jump to relocated code */
 
88
        sethi   %hi(_end), %l0
 
89
        jmpl    %i0 + (jumphere - _start), %g0
 
90
         or     %l0, %lo(_end), %l0             ! %l0 = _end
 
91
 
 
92
        .align  32
 
93
jumphere:
 
94
        /* Clear BSS */
 
95
5:      add     %l0, %i3, %l0
 
96
        add     %i1, %i3, %i1
 
97
        andcc   %i1, 4, %g0
 
98
        sub     %l0, %i1, %i2                   ! %i2 = BSS length
 
99
        be      1f
 
100
         mov    %g0, %g1
 
101
 
 
102
        st      %g0, [%i1]
 
103
        add     %i1, 4, %i1
 
104
1:
 
105
        subcc   %i2, 32, %i2
 
106
        std     %g0, [%i1]
 
107
        std     %g0, [%i1 + 8]
 
108
        std     %g0, [%i1 + 16]
 
109
        std     %g0, [%i1 + 24]
 
110
        bgu     1b
 
111
         add    %i1, 32, %i1
 
112
 
 
113
        tst     %o4                             ! if not Ultra,
 
114
        be      1f                              ! skip %pstate modification
 
115
         nop
 
116
 
 
117
        rdpr    %pstate, %l1
 
118
        or      %l1, 8, %l1
 
119
        wrpr    %l1, 0, %pstate
 
120
1:
 
121
 
 
122
        ! Set up a stack
 
123
setup_stack:
 
124
        save    %i0,-120,%sp
 
125
 
 
126
        tst     %i4
 
127
        be      0f
 
128
         sethi  %hi(gzminpi+0x100000), %l0
 
129
        ld      [%l0 + %lo(gzminpi)], %l1
 
130
        sethi   %hi(LARGE_RELOC), %l2
 
131
1:      lduh    [%l1], %l3
 
132
        add     %l1, 2, %l1
 
133
        tst     %l3
 
134
        be      2f
 
135
         add    %l2, %l3, %l2
 
136
        ldub    [%l2], %l3
 
137
        add     %l3, 4, %l3
 
138
        ba      1b
 
139
         stb    %l3, [%l2]
 
140
2:      sethi   %hi(LARGE_RELOC), %l2
 
141
3:      lduh    [%l1], %l3
 
142
        add     %l1, 2, %l1
 
143
        tst     %l3
 
144
        be      4f
 
145
         add    %l2, %l3, %l2
 
146
        ldub    [%l2], %l3
 
147
        add     %l3, 16, %l3
 
148
        ba      3b
 
149
         stb    %l3, [%l2]
 
150
4:      st      %l1, [%l0 + %lo(gzminpi)]
 
151
 
 
152
        ! Call my_main() to start the whole thingie up
 
153
 
 
154
0:      call    flush_icache
 
155
         mov    %i6, %o2                        ! Cif sp on sun4u
 
156
        mov     %i4, %o1                        ! Cif handler on sun4u
 
157
        call    my_main
 
158
         mov    %i0, %o0                        ! Prom vector or cifh on sun4m
 
159
        call    flush_icache
 
160
         nop
 
161
        jmpl    %o0 + %g0, %g0                  ! Jump to return address from my_main()
 
162
         restore
 
163
 
 
164
/* l0 from, l1 to, l2 len, l7 ret. Returns from + len in l0 */
 
165
copy:
 
166
        ld      [%l0], %l3
 
167
        ld      [%l0 + 4], %l4
 
168
        ld      [%l0 + 8], %l5
 
169
        ld      [%l0 + 12], %l6
 
170
        subcc   %l2, 16, %l2
 
171
        add     %l0, 16, %l0
 
172
        st      %l3, [%l1]
 
173
        st      %l4, [%l1 + 4]
 
174
        st      %l5, [%l1 + 8]
 
175
        st      %l6, [%l1 + 12]
 
176
        bgu     copy
 
177
         add    %l1, 16, %l1
 
178
 
 
179
        jmpl    %l7 + 8, %g0
 
180
         nop
 
181
 
 
182
flush_icache:
 
183
        tst     %i4                     /* quit unless it's Sun4u */
 
184
        be      0f
 
185
         nop
 
186
 
 
187
        /* Careful, we cannot read the %ver register on sun4v because
 
188
         * there that register is hyperprivileged and we are executing
 
189
         * in privileged mode.
 
190
         *
 
191
         * This early on it's difficult to portably detect sun4v as
 
192
         * that requires OBP calls.  So do this super-ugly trick of
 
193
         * trying to set the PSTATE_AG bit in %pstate which will read
 
194
         * back as zero on sun4u.
 
195
         */
 
196
        rdpr    %pstate, %l0
 
197
        or      %l0, 0x1, %l1
 
198
        wrpr    %l1, %pstate
 
199
        rdpr    %pstate, %l1
 
200
        wrpr    %l0, %pstate
 
201
        andcc   %l1, 0x1, %g0
 
202
        be,pn   %xcc, 0f
 
203
         nop
 
204
 
 
205
        rdpr    %ver, %l0
 
206
        srlx    %l0, (32 + 16), %l1
 
207
        cmp     %l1, 0x3e
 
208
        bne,pt  %xcc, 99f
 
209
         sllx   %l0, 16, %l0
 
210
        srlx    %l0, (32 + 16), %l1
 
211
        cmp     %l1, 0x14
 
212
        bgeu,pt %xcc, 0f                /* quit if Ultra-III or derivative */
 
213
         nop
 
214
99:
 
215
        rdpr    %ver, %l0
 
216
        srlx    %l0, 32, %l0
 
217
        sethi   %hi(0x40003), %l1
 
218
        or      %l1, %lo(0x40003), %l1
 
219
        cmp     %l0, %l1
 
220
        be      0f                      /* quit if HAL SPARC64-III */
 
221
         nop
 
222
        sethi   %hi(0x40004), %l1
 
223
        or      %l1, %lo(0x40004), %l1
 
224
        cmp     %l0, %l1
 
225
        be      0f                      /* quit if HAL SPARC64-IV */
 
226
         nop
 
227
        clr     %l0
 
228
        sethi   %hi(16384), %l1
 
229
        stxa    %g0, [%l0] 0x67         /* ASI_IC_TAG */
 
230
1:
 
231
        add     %l0, 32, %l0
 
232
        cmp     %l0, %l1
 
233
        blu,a,pt %xcc, 1b
 
234
         stxa   %g0, [%l0] 0x67         /* ASI_IC_TAG */
 
235
0:
 
236
        retl
 
237
         nop
 
238
 
 
239
        .section        ".rodata"
 
240
        .word   _start