~ubuntu-branches/ubuntu/lucid/silo/lucid

« back to all changes in this revision

Viewing changes to tilo/crt0.S

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20071025092808-pnva6x2ggmlkd65e
Tags: upstream-1.4.13a+git20070930
ImportĀ upstreamĀ versionĀ 1.4.13a+git20070930

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
#ifndef LARGETILO
 
27
#define STACK_BASE 0x400000
 
28
#else
 
29
#define STACK_BASE 0x500000
 
30
#endif
 
31
 
 
32
        .text
 
33
        .global _start
 
34
        .global image_table
 
35
        .align  16
 
36
_start:
 
37
        call    1f
 
38
         mov    %o7, %l0
 
39
 
 
40
image_table:
 
41
        .skip   64              /* struct ImageInfo image_table[4] */
 
42
 
 
43
1:
 
44
        /* Move ourselves up */                 ! %l0 = original start
 
45
        set     __bss_start + 16, %i1           ! %i1 = original end
 
46
        set     _start, %l1                     ! %i0 = %l1 = relocated start
 
47
        mov     %l1, %i0                        ! %l2 = code length
 
48
        COPY
 
49
         sub    %i1, %l1, %l2
 
50
 
 
51
        /* Jump to relocated code */
 
52
        sethi   %hi(_end), %l0
 
53
        jmpl    %i0 + (jumphere - _start), %g0
 
54
         or     %l0, %lo(_end), %l0             ! %l0 = _end
 
55
 
 
56
        .align  32
 
57
jumphere:
 
58
        /* Clear BSS */
 
59
5:      add     %l0, %i3, %l0
 
60
        add     %i1, %i3, %i1
 
61
        andcc   %i1, 4, %g0
 
62
        sub     %l0, %i1, %i2                   ! %i2 = BSS length
 
63
        be      1f
 
64
         mov    %g0, %g1
 
65
 
 
66
        st      %g0, [%i1]
 
67
        add     %i1, 4, %i1
 
68
1:
 
69
        subcc   %i2, 32, %i2
 
70
        std     %g0, [%i1]
 
71
        std     %g0, [%i1 + 8]
 
72
        std     %g0, [%i1 + 16]
 
73
        std     %g0, [%i1 + 24]
 
74
        bgu     1b
 
75
         add    %i1, 32, %i1
 
76
 
 
77
        tst     %o4                             ! if not Ultra,
 
78
        be      1f                              ! skip %pstate modification
 
79
         nop
 
80
 
 
81
        rdpr    %pstate, %l1
 
82
        or      %l1, 8, %l1
 
83
        wrpr    %l1, 0, %pstate
 
84
1:
 
85
 
 
86
        ! Set up a stack
 
87
setup_stack:
 
88
        set     STACK_BASE, %l1
 
89
        save    %l1, -64, %sp
 
90
 
 
91
        ! Call my_main() to start the whole thingie up
 
92
 
 
93
0:      call    flush_icache
 
94
         mov    %i6, %o2                        ! Cif sp on sun4u
 
95
        mov     %i4, %o1                        ! Cif handler on sun4u
 
96
        call    my_main
 
97
         mov    %i0, %o0                        ! Prom vector or cifh on sun4m
 
98
        call    flush_icache
 
99
         nop
 
100
        jmpl    %o0 + %g0, %g0                  ! Jump to return address from my_main()
 
101
         restore
 
102
 
 
103
/* l0 from, l1 to, l2 len, l7 ret. Returns from + len in l0 */
 
104
copy:
 
105
        ld      [%l0], %l3
 
106
        ld      [%l0 + 4], %l4
 
107
        ld      [%l0 + 8], %l5
 
108
        ld      [%l0 + 12], %l6
 
109
        subcc   %l2, 16, %l2
 
110
        add     %l0, 16, %l0
 
111
        st      %l3, [%l1]
 
112
        st      %l4, [%l1 + 4]
 
113
        st      %l5, [%l1 + 8]
 
114
        st      %l6, [%l1 + 12]
 
115
        bgu     copy
 
116
         add    %l1, 16, %l1
 
117
 
 
118
        jmpl    %l7 + 8, %g0
 
119
         nop
 
120
 
 
121
flush_icache:
 
122
        tst     %i4                     /* quit unless it's Sun4u */
 
123
        be      0f
 
124
         nop
 
125
        rdpr    %ver, %l0
 
126
        srlx    %l0, (32 + 16), %l1
 
127
        cmp     %l1, 0x3e
 
128
        bne,pt  %xcc, 99f
 
129
         sllx   %l0, 16, %l0
 
130
        srlx    %l0, (32 + 16), %l1
 
131
        cmp     %l1, 0x14
 
132
        bgeu,pt %xcc, 0f                /* quit if Ultra-III or derivative */
 
133
         nop
 
134
99:
 
135
        rdpr    %ver, %l0
 
136
        srlx    %l0, 32, %l0
 
137
        sethi   %hi(0x40003), %l1
 
138
        or      %l1, %lo(0x40003), %l1
 
139
        cmp     %l0, %l1
 
140
        be      0f                      /* quit if HAL SPARC64-III */
 
141
         nop
 
142
        sethi   %hi(0x40004), %l1
 
143
        or      %l1, %lo(0x40004), %l1
 
144
        cmp     %l0, %l1
 
145
        be      0f                      /* quit if HAL SPARC64-IV */
 
146
         nop
 
147
        clr     %l0
 
148
        sethi   %hi(16384), %l1
 
149
        stxa    %g0, [%l0] 0x67         /* ASI_IC_TAG */
 
150
1:
 
151
        add     %l0, 32, %l0
 
152
        cmp     %l0, %l1
 
153
        blu,a,pt %xcc, 1b
 
154
         stxa   %g0, [%l0] 0x67         /* ASI_IC_TAG */
 
155
0:
 
156
        retl
 
157
         nop
 
158
 
 
159
        .section        ".rodata"
 
160
        .word   _start