[go: up one dir, main page]

File: crt0.S

package info (click to toggle)
silo 0.8.5-2.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,016 kB
  • ctags: 2,061
  • sloc: ansic: 10,060; asm: 2,319; makefile: 351; perl: 74; sh: 3
file content (201 lines) | stat: -rw-r--r-- 3,772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* Second stage boot loader bootstrap
   
   Copyright (C) 1996 Pete A. Zaitcev
		 1996 Miguel de Icaza
		 1996,1997,1998 Jakub Jelinek
   
   This program 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 of the License, or
   (at your option) any later version.
   
   This program 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; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

#define COPY	jmpl	%o7 + (copy - start), %l7

	.text
	.global _start, start, silo_conf, silo_conf_part, boot_part
_start:
start:
	call	1f
	 mov	%o7, %l0

	.byte	'L'	! This is for the primary loader to check if we are ok... :)
silo_conf_part:
	.byte 	0
boot_part:
	.byte 	0
	.align 4
silo_conf:
	.skip  256
1:
	/* Move ourselves up - there are three chunks to move. */
	clr	%i3
	tst	%o4
	bne,a	1f
	 sethi	%hi(0x100000), %i3
1:	set	main_text_start, %l3
	set	start, %l4
	add	%l4, %i3, %i0
	mov	%i0, %l1
	COPY
	 sub	%l3, %l4, %l2

	set	main_rodata_start, %l3
	set	main_text_end, %l4
	add	%l4, %i3, %l1
	COPY
	 sub	%l3, %l4, %l2

	set	main_data_start, %l3
	set	main_rodata_end, %l4
	add	%l4, %i3, %l1
	COPY
	 sub	%l3, %l4, %l2

	set	__bss_start + 16, %i1
	set	main_data_end, %l4
	add	%l4, %i3, %l1
	COPY
	 sub	%i1, %l4, %l2

	sub	%l0, 16, %l0
	sethi	%hi(gzminpi), %l1
	add	%l1, %i3, %l1
	st	%l0, [%l1 + %lo(gzminpi)]
#if 0
	add	%i0, (jumphere - start), %l0
	andn	%l0, 0xfff, %l0
	sethi	%hi(_etext), %l1
	or	%l1, %lo(_etext), %l1
	add	%l1, %i3, %l1
	sethi	%hi(0x1000), %l2
1:
	flush	%l0
	cmp	%l0, %l1
	blu	1b
	 add	%l0, %l2, %l0
#endif

	/* Jump to relocated code */
	sethi	%hi(_end), %l0
	jmpl	%i0 + (jumphere - start), %g0
	 or	%l0, %lo(_end), %l0

	.align	32
jumphere:
	/* Clear BSS */
	add	%l0, %i3, %l0
	add	%i1, %i3, %i1
	andcc	%i1, 4, %g0
	sub	%l0, %i1, %i2			! length
	be	1f
	 mov	%g0, %g1

	st	%g0, [%i1]
	add	%i1, 4, %i1
1:
	subcc	%i2, 32, %i2
	std	%g0, [%i1]
	std	%g0, [%i1 + 8]
	std	%g0, [%i1 + 16]
	std	%g0, [%i1 + 24]
	bgu	1b
	 add	%i1, 32, %i1

	tst	%o4
	be	1f
	 nop
#if 1
	rdpr	%pstate, %l1
	or	%l1, 8, %l1
	wrpr	%l1, 0, %pstate
#else
	nop; nop; nop
#endif
1:

	! Set up a stack
setup_stack:
	save	%i0,-120,%sp

	tst	%i4
	be	0f
	 sethi	%hi(gzminpi+0x100000), %l0
	ld	[%l0 + %lo(gzminpi)], %l1
	sethi	%hi(0x380000), %l2
1:	lduh	[%l1], %l3
	add	%l1, 2, %l1
	tst	%l3
	be	2f
	 add	%l2, %l3, %l2
	ldub	[%l2], %l3
	add	%l3, 4, %l3
	ba	1b
	 stb	%l3, [%l2]
2:	sethi	%hi(0x380000), %l2
3:	lduh	[%l1], %l3
	add	%l1, 2, %l1
	tst	%l3
	be	4f
	 add	%l2, %l3, %l2
	ldub	[%l2], %l3
	add	%l3, 16, %l3
	ba	3b
	 stb	%l3, [%l2]
4:	st	%l1, [%l0 + %lo(gzminpi)]

	! Call gunzipmain() to start the whole thingie up

0:	call	flush_icache
	 mov	%i6, %o2			! Cif sp on sun4u
	mov	%i4, %o1			! Cif handler on sun4u
	call	gunzipmain
	 mov	%i0, %o0			! Prom vector address
	call	flush_icache
	 nop
	jmpl	%o0 + %g0, %g0
	 restore

/* l0 from, l1 to, l2 len, l7 ret. Returns from + len in l0 */
copy:
	ld	[%l0], %l3
	ld	[%l0 + 4], %l4
	ld	[%l0 + 8], %l5
	ld	[%l0 + 12], %l6
	subcc	%l2, 16, %l2
	add	%l0, 16, %l0
	st	%l3, [%l1]
	st	%l4, [%l1 + 4]
	st	%l5, [%l1 + 8]
	st	%l6, [%l1 + 12]
	bgu	copy
	 add	%l1, 16, %l1

	jmpl	%l7 + 8, %g0
	 nop

flush_icache:
	tst	%i4
	be	0f
	 clr	%l0
	sethi	%hi(16384), %l1
	stxa	%g0, [%l0] 0x67
1:
	add	%l0, 32, %l0
	cmp	%l0, %l1
	blu,a,pt %xcc, 1b
	 stxa	%g0, [%l0] 0x67
0:
	retl
	 nop

	.section	".rodata"
	.word	_start