xref: /netbsd-src/sys/arch/amiga/stand/bootblock/boot/startit.s (revision ac9f09c8c7a1b8912762219d974f9926e0fd9fb8)
1/*	$NetBSD: startit.s,v 1.9 2009/11/15 20:38:36 snj Exp $	*/
2
3/*
4 * Copyright (c) 1996 Ignatios Souvatzis
5 * Copyright (c) 1994 Michael L. Hitch
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 *
29 * From: $NetBSD: startit.s,v 1.9 2009/11/15 20:38:36 snj Exp $
30 */
31#include <machine/asm.h>
32
33	.set	ABSEXECBASE,4
34
35	.text
36
37ENTRY_NOPROFILE(startit)
38#if TESTONAMIGA
39	movew	#0x999,0xdff180		| gray
40#endif
41#if TESTONDRACO
42	moveb	#0,0x200003c8
43	moveb	#31,0x200003c9
44	moveb	#31,0x200003c9
45	moveb	#31,0x200003c9
46#endif
47	movel	%sp,%a3
48	movel	4:w,%a6
49	lea	%pc@(start_super:w),%a5
50	jmp	%a6@(-0x1e)		| supervisor-call
51
52start_super:
53#if TESTONAMIGA
54	movew	#0x900,0xdff180		| dark red
55#endif
56	movew	#0x2700,%sr
57
58	| the BSD kernel wants values into the following registers:
59	| %a0:  fastmem-start
60	| %d0:  fastmem-size
61	| %d1:  chipmem-size
62	| %d3:  Amiga specific flags
63	| %d4:  E clock frequency
64	| %d5:  AttnFlags (cpuid)
65	| %d6:  boot partition offset
66	| %d7:  boothowto
67	| %a4:  esym location
68	| %a2:  Inhibit sync flags
69	| All other registers zeroed for possible future requirements.
70
71	lea	%pc@(_C_LABEL(startit):w),%sp	| make sure we have a good stack ***
72
73	movel	%a3@(4),%a1		| loaded kernel
74	movel	%a3@(8),%d2		| length of loaded kernel
75|	movel	%a3@(12),%sp		| entry point in stack pointer
76	movel	%a3@(12),%a6		| entry point		***
77	movel	%a3@(16),%a0		| fastmem-start
78	movel	%a3@(20),%d0		| fastmem-size
79	movel	%a3@(24),%d1		| chipmem-size
80	movel	%a3@(28),%d7		| boothowto
81	movel	%a3@(32),%a4		| esym
82	movel	%a3@(36),%d5		| cpuid
83	movel	%a3@(40),%d4		| E clock frequency
84	movel	%a3@(44),%d3		| Amiga flags
85	movel	%a3@(48),%a2		| Inhibit sync flags
86	movel	%a3@(52),%d6		| boot partition offset
87
88	cmpb	#0x7D,%a3@(36)		| is it DraCo?
89	movel	%a3@(56),%a3		| Load to fastmem flag
90	jeq	nott			| yes, switch off MMU later
91
92					| no, it is an Amiga:
93
94#if TESTONAMIGA
95	movew	#0xf00,0xdff180		|red
96#endif
97#if TESTONDRACO
98	moveb	#0,0x200003c8
99	moveb	#63,0x200003c9
100	moveb	#0,0x200003c9
101	moveb	#0,0x200003c9
102#endif
103
104	movew	#(1<<9),0xdff096	| disable DMA on Amigas.
105
106| ------ mmu off start -----
107
108	btst	#3,%d5			| AFB_68040,SysBase->AttnFlags
109	jeq	not040
110
111| Turn off 68040/060 MMU
112
113	subl	%a5,%a5
114	.word 0x4e7b,0xd003		| movec %a5,tc
115	.word 0x4e7b,0xd806		| movec %a5,urp
116	.word 0x4e7b,0xd807		| movec %a5,srp
117	.word 0x4e7b,0xd004		| movec %a5,itt0
118	.word 0x4e7b,0xd005		| movec %a5,itt1
119	.word 0x4e7b,0xd006		| movec %a5,dtt0
120	.word 0x4e7b,0xd007		| movec %a5,dtt1
121	jra	nott
122
123not040:
124	lea	%pc@(zero:w),%a5
125	pmove	%a5@,%tc		| Turn off MMU
126	lea	%pc@(nullrp:w),%a5
127	pmove	%a5@,%crp		| Turn off MMU some more
128	pmove	%a5@,%srp		| Really, really, turn off MMU
129
130| Turn off 68030 TT registers
131
132	btst	#2,%d5			| AFB_68030,SysBase->AttnFlags
133	jeq	nott			| Skip TT registers if not 68030
134	lea	%pc@(zero:w),%a5
135	.word 0xf015,0x0800		| pmove %a5@,tt0 (gas only knows about 68851 ops..)
136	.word 0xf015,0x0c00		| pmove %a5@,tt1 (gas only knows about 68851 ops..)
137
138nott:
139| ---- mmu off end ----
140#if TESTONAMIGA
141	movew	#0xf60,0xdff180		| orange
142#endif
143#if TESTONDRACO
144	moveb	#0,0x200003c8
145	moveb	#63,0x200003c9
146	moveb	#24,0x200003c9
147	moveb	#0,0x200003c9
148#endif
149
150
151| ---- copy kernel start ----
152
153| removed Z flag
154|	tstl	%a3			| Can we load to fastmem?
155|	jeq	L0			| No, leave destination at 0
156	movl	%a0,%a3			| Move to start of fastmem chunk
157	addl	%a0,%a6			| relocate kernel entry point
158
159	addl	#3,%d2
160	andl	#0xfffffffc,%d2		| round up.
161
162	| determine if the kernel need be copied upwards or downwards
163
164	cmpl	%a1,%a3			| %a3-a1
165	bcs	above			| source is above
166
167	movl	%a0,%sp
168	addl	%d0,%sp			| move the stack to the end of segment
169
170	| copy from below upwards requires copying from end to start.
171
172	addl	%d2,%a3			| one long word past
173	addl	%d2,%a1			| one long word past
174
175	subl	#4,%sp			| alloc space
176	movl	%a1,%sp@-			| save source
177	movl	%a3,%sp@-			| save destination
178
179	| copy copier to end of segment
180
181	movl	%sp,%a3
182	subl	#256,%a3			| end of segment save our stack
183
184	lea	%pc@(_C_LABEL(startit_end):w),%a1
185	movl	%a0,%sp@-			| save segment start
186	lea	%pc@(below:w),%a0
187
188L0:	movw	%a1@-,%a3@-
189	cmpl	%a0,%a1
190	bne	L0
191	movl	%sp@,%a0			| restore segment start
192	movl	%a3,%sp@			| address of relocated below
193	addl	#(ckend - below),%a3
194	movl	%a3,%sp@(12)		| address of ckend for later
195| ---- switch off cache ----
196	bra	Lchoff			| and to relocated below
197
198
199below:	movl	%sp@+,%a3			| recover destination
200	movl	%sp@+,%a1			| recover source
201
202L1:	movl	%a1@-,%a3@-		| copy kernel
203	subl	#4,%d2
204	bne	L1
205
206| ---- switch off cache ----
207	bra	Lchoff			| and to relocated ckend
208
209above:	movl	%a1@+,%a3@+
210	subl	#4,%d2
211	bne	above
212
213	lea	%pc@(ckend:w),%a1
214	movl	%a3,%sp@-
215	pea	%pc@(_C_LABEL(startit_end):w)
216L2:
217	movl	%a1@+,%a3@+
218	cmpl	%sp@,%a1
219	bcs	L2
220	addql	#4,%sp
221
222#if TESTONAMIGA
223	movew	#0xFF0,0xdff180		| yellow
224#endif
225#if TESTONDRACO
226	moveb	#0,0x200003c8
227	moveb	#63,0x200003c9
228	moveb	#63,0x200003c9
229	moveb	#0,0x200003c9
230#endif
231
232| ---- switch off cache ----
233Lchoff:	btst	#3,%d5
234	jeq	L3c
235	.word	0xf4f8
236L3c:	movl	%d2,%sp@-			| save %d2
237	movql	#0,%d2			| switch off cache to ensure we use
238	movec	%d2,%cacr			| valid kernel data
239	movl	%sp@+,%d2			| restore %d2
240	rts
241
242| ---- copy kernel end ----
243
244ckend:
245#if TESTONAMIGA
246	movew	#0x0ff,0xdff180		| petrol
247#endif
248#if TESTONDRACO
249	moveb	#0,0x200003c8
250	moveb	#0,0x200003c9
251	moveb	#63,0x200003c9
252	moveb	#63,0x200003c9
253#endif
254
255	movl	%d5,%d2
256	roll	#8,%d2
257	cmpb	#0x7D,%d2
258	jne	noDraCo
259
260| DraCo: switch off MMU now:
261
262	subl	%a5,%a5
263	.word 0x4e7b,0xd003		| movec %a5,tc
264	.word 0x4e7b,0xd806		| movec %a5,urp
265	.word 0x4e7b,0xd807		| movec %a5,srp
266	.word 0x4e7b,0xd004		| movec %a5,itt0
267	.word 0x4e7b,0xd005		| movec %a5,itt1
268	.word 0x4e7b,0xd006		| movec %a5,dtt0
269	.word 0x4e7b,0xd007		| movec %a5,dtt1
270
271noDraCo:
272	moveq	#0,%d2			| zero out unused registers
273	movel	%d2,%a1			| (might make future compatibility
274	movel	%d2,%a3			|  would have known contents)
275	movel	%d2,%a5
276	movel	%a6,%sp			| entry point into stack pointer
277	movel	%d2,%a6
278
279#if TESTONAMIGA
280	movew	#0x0F0,0xdff180		| green
281#endif
282#if TESTONDRACO
283	moveb	#0,0x200003c8
284	moveb	#0,0x200003c9
285	moveb	#63,0x200003c9
286	moveb	#0,0x200003c9
287#endif
288
289	jmp	%sp@			| jump to kernel entry point
290
291
292| A do-nothing MMU root pointer (includes the following long as well)
293
294nullrp:	.long	0x7fff0001
295zero:	.long	0
296
297ENTRY_NOPROFILE(startit_end)
298