startit.s revision 1.2 1 /* $NetBSD: startit.s,v 1.2 1997/02/01 01:46:27 mhitch 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 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Michael L. Hitch.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 *
34 * From: $NetBSD: startit.s,v 1.2 1997/02/01 01:46:27 mhitch Exp $
35 */
36
37 .set ABSEXECBASE,4
38
39 .text
40
41 .globl _startit
42 .globl _startit_end
43
44 _startit:
45 #if TESTONAMIGA
46 movew #0x999,0xdff180 | gray
47 #endif
48 movel sp,a3
49 movel 4:w,a6
50 lea pc@(start_super:w),a5
51 jmp a6@(-0x1e) | supervisor-call
52
53 start_super:
54 #if TESTONAMIGA
55 movew #0x900,0xdff180 | dark red
56 #endif
57 movew #0x2700,sr
58
59 | the BSD kernel wants values into the following registers:
60 | a0: fastmem-start
61 | d0: fastmem-size
62 | d1: chipmem-size
63 | d3: Amiga specific flags
64 | d4: E clock frequency
65 | d5: AttnFlags (cpuid)
66 | d6: boot partition offset
67 | d7: boothowto
68 | a4: esym location
69 | a2: Inhibit sync flags
70 | All other registers zeroed for possible future requirements.
71
72 lea pc@(_startit:w),sp | make sure we have a good stack ***
73
74 movel a3@(4),a1 | loaded kernel
75 movel a3@(8),d2 | length of loaded kernel
76 | movel a3@(12),sp | entry point in stack pointer
77 movel a3@(12),a6 | entry point ***
78 movel a3@(16),a0 | fastmem-start
79 movel a3@(20),d0 | fastmem-size
80 movel a3@(24),d1 | chipmem-size
81 movel a3@(28),d7 | boothowto
82 movel a3@(32),a4 | esym
83 movel a3@(36),d5 | cpuid
84 movel a3@(40),d4 | E clock frequency
85 movel a3@(44),d3 | Amiga flags
86 movel a3@(48),a2 | Inhibit sync flags
87 movel a3@(52),d6 | boot partition offset
88
89 cmpb #0x7D,a3@(36) | is it DraCo?
90 movel a3@(56),a3 | Load to fastmem flag
91 jeq nott | yes, switch off MMU later
92
93 | no, it is an Amiga:
94
95 #if TESTONAMIGA
96 movew #0xf00,0xdff180 |red
97 #endif
98 | moveb #0,0x200003c8
99 | moveb #63,0x200003c9
100 | moveb #0,0x200003c9
101 | moveb #0,0x200003c9
102
103 movew #(1<<9),0xdff096 | disable DMA on Amigas.
104
105 | ------ mmu off start -----
106
107 btst #3,d5 | AFB_68040,SysBase->AttnFlags
108 jeq not040
109
110 | Turn off 68040/060 MMU
111
112 subl a5,a5
113 .word 0x4e7b,0xd003 | movec a5,tc
114 .word 0x4e7b,0xd806 | movec a5,urp
115 .word 0x4e7b,0xd807 | movec a5,srp
116 .word 0x4e7b,0xd004 | movec a5,itt0
117 .word 0x4e7b,0xd005 | movec a5,itt1
118 .word 0x4e7b,0xd006 | movec a5,dtt0
119 .word 0x4e7b,0xd007 | movec a5,dtt1
120 jra nott
121
122 not040:
123 lea pc@(zero:w),a5
124 pmove a5@,tc | Turn off MMU
125 lea pc@(nullrp:w),a5
126 pmove a5@,crp | Turn off MMU some more
127 pmove a5@,srp | Really, really, turn off MMU
128
129 | Turn off 68030 TT registers
130
131 btst #2,d5 | AFB_68030,SysBase->AttnFlags
132 jeq nott | Skip TT registers if not 68030
133 lea pc@(zero:w),a5
134 .word 0xf015,0x0800 | pmove a5@,tt0 (gas only knows about 68851 ops..)
135 .word 0xf015,0x0c00 | pmove a5@,tt1 (gas only knows about 68851 ops..)
136
137 nott:
138 | ---- mmu off end ----
139 #if TESTONAMIGA
140 movew #0xf60,0xdff180 | orange
141 #endif
142 | moveb #0,0x200003c8
143 | moveb #63,0x200003c9
144 | moveb #24,0x200003c9
145 | moveb #0,0x200003c9
146
147 | ---- copy kernel start ----
148
149 tstl a3 | Can we load to fastmem?
150 jeq L0 | No, leave destination at 0
151 movl a0,a3 | Move to start of fastmem chunk
152 addl a0,a6 | relocate kernel entry point
153 L0:
154 movl a1@+,a3@+
155 subl #4,d2
156 bcc L0
157
158 lea pc@(ckend:w),a1
159 movl a3,sp@-
160 pea pc@(_startit_end:w)
161 L1:
162 movl a1@+,a3@+
163 cmpl sp@,a1
164 bcs L1
165 addql #4,sp
166
167 btst #3,d5
168 jeq L2
169 .word 0xf4f8
170 L2: movql #0,d2 | switch off cache to ensure we use
171 movec d2,cacr | valid kernel data
172
173 #if TESTONAMIGA
174 movew #0xFF0,0xdff180 | yellow
175 #endif
176 | moveb #0,0x200003c8
177 | moveb #63,0x200003c9
178 | moveb #0,0x200003c9
179 | moveb #0,0x200003c9
180
181 rts
182
183 | ---- copy kernel end ----
184
185 ckend:
186 #if TESTONAMIGA
187 movew #0x0ff,0xdff180 | petrol
188 #endif
189 | moveb #0,0x200003c8
190 | moveb #0,0x200003c9
191 | moveb #63,0x200003c9
192 | moveb #63,0x200003c9
193
194 movl d5,d2
195 roll #8,d2
196 cmpb #0x7D,d2
197 jne noDraCo
198
199 | DraCo: switch off MMU now:
200
201 subl a5,a5
202 .word 0x4e7b,0xd003 | movec a5,tc
203 .word 0x4e7b,0xd806 | movec a5,urp
204 .word 0x4e7b,0xd807 | movec a5,srp
205 .word 0x4e7b,0xd004 | movec a5,itt0
206 .word 0x4e7b,0xd005 | movec a5,itt1
207 .word 0x4e7b,0xd006 | movec a5,dtt0
208 .word 0x4e7b,0xd007 | movec a5,dtt1
209
210 noDraCo:
211 moveq #0,d2 | zero out unused registers
212 movel d2,a1 | (might make future compatibility
213 movel d2,a3 | would have known contents)
214 movel d2,a5
215 movel a6,sp | entry point into stack pointer
216 movel d2,a6
217
218 #if TESTONAMIGA
219 movew #0x0F0,0xdff180 | green
220 #endif
221 | moveb #0,0x200003c8
222 | moveb #0,0x200003c9
223 | moveb #63,0x200003c9
224 | moveb #0,0x200003c9
225
226 jmp sp@ | jump to kernel entry point
227
228
229 | A do-nothing MMU root pointer (includes the following long as well)
230
231 nullrp: .long 0x7fff0001
232 zero: .long 0
233
234 _startit_end:
235