srt0.S revision 1.11 1 /* $NetBSD: srt0.S,v 1.11 1999/12/14 20:57:44 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1982, 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: Utah $Hdr: srt0.c 1.18 92/12/21$
41 *
42 * @(#)srt0.c 8.1 (Berkeley) 6/10/93
43 */
44
45 /*
46 * Startup code for standalone system
47 */
48
49 /* For machineid and mmuid constants */
50 #include <machine/hp300spu.h>
51
52 /* For _C_LABEL() and friends. */
53 #include <machine/asm.h>
54
55 STACK = 0xfffff000 /* below the ROM page */
56 BOOTTYPE = 0xfffffdc0
57 LOWRAM = 0xfffffdce
58 SYSFLAG = 0xfffffed2 /* system flags */
59 MSUS = 0xfffffedc /* MSUS (?) structure */
60 VECTORS = 0xfffffee0 /* beginning of jump vectors */
61 NMIRESET = 0xffffff9c /* reset vector */
62 BUSERR = 0xfffffffc
63 MAXADDR = 0xfffff000
64 NBPG = 4096
65 MMUCMD = 0x005f400c /* MMU command/status register */
66
67 .data
68 GLOBAL(bootdev)
69 .long 0
70
71 GLOBAL(howto)
72 .long 0
73
74 GLOBAL(lowram)
75 .long 0
76
77 GLOBAL(machineid)
78 .long 0
79
80 GLOBAL(mmuid)
81 .long 0
82
83 .text
84 ASENTRY_NOPROFILE(begin)
85 movl #STACK,%sp
86 moveq #47,%d0 /* # of vectors - 1 */
87 movl #VECTORS+2,%a0 /* addr part of first vector */
88 1:
89 movl #_ASM_LABEL(__trap),%a0@ /* make it direct to __trap */
90 addql #6,%a0 /* move to next vector addr */
91 dbf %d0,1b /* go til done */
92 #ifdef ITECONSOLE
93 movl #NMIRESET,%a0 /* NMI keyboard reset addr */
94 movl #nmi,%a0@ /* catch in reset routine */
95 #else
96 /*
97 * Built without ITE console support; leave the ROM's NMI
98 * vector in place, so the system will still reset if a
99 * keyboard NMI is issued.
100 */
101 #endif
102
103 /*
104 * Determine our SPU type and look for internal HP-IB
105 */
106 lea _C_LABEL(machineid),%a0
107 movl #0x808,%d0
108 movc %d0,%cacr /* clear and disable on-chip cache(s) */
109 movl #0x200,%d0 /* data freeze bit */
110 movc %d0,%cacr /* only exists on 68030 */
111 movc %cacr,%d0 /* read it back */
112 tstl %d0 /* zero? */
113 jeq not68030 /* yes, we have 68020/68040 */
114
115 movl #0x808,%d0
116 movc %d0,%cacr /* clear data freeze bit again */
117
118 /*
119 * 68030 models
120 */
121
122 movl #0x80,MMUCMD /* set magic cookie */
123 movl MMUCMD,%d0 /* read it back */
124 btst #7,%d0 /* cookie still on? */
125 jeq not370 /* no, 360 or 375 */
126 movl #HP_370,%a0@ /* consider a 370 for now */
127 movl #0,MMUCMD /* clear magic cookie */
128 movl MMUCMD,%d0 /* read it back */
129 btst #7,%d0 /* still on? */
130 jeq ihpibcheck /* no, a 370 */
131 movl #HP_340,%a0@ /* yes, must be a 340 */
132 jra ihpibcheck
133
134 not370:
135 movl #HP_360,%a0@ /* type is at least a 360 */
136 movl #0,MMUCMD /* clear magic cookie2 */
137 movl MMUCMD,%d0 /* read it back */
138 btst #16,%d0 /* still on? */
139 jeq ihpibcheck /* no, a 360 */
140 lea _C_LABEL(mmuid),%a0
141 lsrl #MMUID_SHIFT,%d0 /* save MMU ID */
142 andl #MMUID_MASK,%d0
143 movl %d0,%a0@
144 lea _C_LABEL(machineid),%a0
145 cmpb #MMUID_345,%d0 /* are we a 345? */
146 jeq isa345
147 cmpb #MMUID_375,%d0 /* how about a 375? */
148 jeq isa375
149 movl #HP_400,%a0@ /* must be a 400 */
150 jra ihpibcheck
151 isa345:
152 movl #HP_345,%a0@
153 jra ihpibcheck
154 isa375:
155 movl #HP_375,%a0@
156 jra ihpibcheck
157
158 /*
159 * End of 68030 section
160 */
161
162 not68030:
163 bset #31,%d0 /* data cache enable bit */
164 movc %d0,%cacr /* only exists on 68040 */
165 movc %cacr,%d0 /* read it back */
166 tstl %d0 /* zero? */
167 beq is68020 /* yes, we have 68020 */
168 moveq #0,%d0 /* now turn it back off */
169 movec %d0,%cacr /* before we access any data */
170
171 .long 0x4e7b0004 /* movc %d0,%itt0 */
172 .long 0x4e7b0005 /* movc %d0,%itt1 */
173 .long 0x4e7b0006 /* movc %d0,%dtt0 */
174 .long 0x4e7b0007 /* movc %d0,%dtt1 */
175 .word 0xf4d8 /* cinva bc */
176
177 /*
178 * 68040 models
179 */
180
181 lea _C_LABEL(mmuid),%a0
182 movl MMUCMD,%d0 /* get MMU ID */
183 lsrl #MMUID_SHIFT,%d0
184 andl #MMUID_MASK,%d0
185 movl %d0,%a0@ /* save it */
186 lea _C_LABEL(machineid),%a0
187 cmpb #MMUID_425_T,%d0 /* are we a 425t? */
188 jeq isa425
189 cmpb #MMUID_425_S,%d0 /* how about 425s? */
190 jeq isa425
191 cmpb #MMUID_425_E,%d0 /* or maybe a 425e? */
192 jeq isa425
193 cmpb #MMUID_433_T,%d0 /* or a 433t? */
194 jeq isa433
195 cmpb #MMUID_433_S,%d0 /* or a 433s? */
196 jeq isa433
197 cmpb #MMUID_385,%d0 /* or a 385? */
198 jeq isa385
199 movl #HP_380,%a0@ /* guess we are a 380 */
200 jra ihpibcheck
201 isa425:
202 movl #HP_425,%a0@
203 jra ihpibcheck
204 isa433:
205 movl #HP_433,%a0@
206 jra ihpibcheck
207 isa385:
208 movl #HP_385,%a0@
209 jra ihpibcheck
210
211 /*
212 * End 68040 section
213 */
214
215 /*
216 * 68020 models
217 */
218
219 is68020:
220 movl #HP_330,%a0@ /* consider a 330 for now */
221 movl #1,MMUCMD /* a 68020, write HP MMU location */
222 movl MMUCMD,%d0 /* read it back */
223 btst #0,%d0 /* zero? */
224 jeq ihpibcheck /* yes, a 330 */
225 movl #HP_320,%a0@ /* no, consider a 320 for now */
226 movl #0x80,MMUCMD /* set magic cookie */
227 movl MMUCMD,%d0 /* read it back */
228 btst #7,%d0 /* cookie still on? */
229 jeq ihpibcheck /* no, just a 320 */
230 movl #HP_350,%a0@ /* yes, a 350 */
231
232 /*
233 * End 68020 section
234 */
235
236 ihpibcheck:
237 movl #0,MMUCMD /* make sure MMU is off */
238 btst #5,SYSFLAG /* do we have an internal HP-IB? */
239 jeq boottype /* yes, continue */
240 clrl _C_LABEL(internalhpib) /* no, clear the internal address */
241 /*
242 * If this is a reboot, extract howto/bootdev stored by kernel
243 */
244 boottype:
245 cmpw #12,BOOTTYPE /* is this a reboot (REQ_REBOOT)? */
246 jne notreboot /* no, skip */
247 lea MAXADDR,%a0 /* find last page */
248 movl %a0@+,%d7 /* and extract howto, bootdev */
249 movl %a0@+,%d6 /* from where doboot() left them */
250 jra boot1
251 /*
252 * At this point we do not know which logical device the MSUS select
253 * code refers to so we cannot construct bootdev. So we just punt
254 * and let configure() construct it.
255 */
256 notreboot:
257 moveq #0,%d6 /* make sure bootdev is invalid */
258 cmpw #18,BOOTTYPE /* does the user want to interact? */
259 jeq askme /* yes, go to it */
260 moveq #0,%d7 /* default to RB_AUTOBOOT */
261 jra boot1
262 askme:
263 moveq #3,%d7 /* default to RB_SINGLE|RB_ASKNAME */
264 boot1:
265 movl %d6,_C_LABEL(bootdev) /* save bootdev and howto */
266 movl %d7,_C_LABEL(howto) /* globally so all can access */
267 movl LOWRAM,%d0 /* read lowram value from bootrom */
268 /*
269 * Must preserve the scratch area for the BOOT ROM.
270 * Round up to the next 8k boundary.
271 */
272 addl #((2*NBPG)-1),%d0
273 andl #-(2*NBPG),%d0
274 movl %d0,_C_LABEL(lowram) /* stash that value */
275 start:
276 movl #_C_LABEL(edata),%a2 /* start of BSS */
277 movl #_C_LABEL(end),%a3 /* end */
278 1:
279 clrb %a2@+ /* clear BSS */
280 cmpl %a2,%a3 /* done? */
281 bne 1b /* no, keep going */
282 jsr _C_LABEL(configure) /* configure critical devices */
283 jsr _C_LABEL(main) /* lets go */
284 GLOBAL(_rtt)
285 movl #3,_C_LABEL(howto) /* restarts get RB_SINGLE|RB_ASKNAME */
286 jmp start
287
288 /*
289 * probe a location and see if it causes a bus error
290 */
291 ENTRY_NOPROFILE(badaddr)
292 movl BUSERR,_C_LABEL(_bsave) /* save ROM bus error handler address */
293 movl %sp,_C_LABEL(_ssave) /* and current stack pointer */
294 movl #catchbad,BUSERR /* plug in our handler */
295 movl %sp@(4),%a0 /* address to probe */
296 movw %a0@,%d1 /* do it */
297 movl _C_LABEL(_bsave),BUSERR /* if we got here, it did not fault */
298 clrl %d0 /* return that this was not a bad */
299 /* addr */
300 rts
301
302 catchbad:
303 movl _C_LABEL(_bsave),BUSERR /* got a bus error, so restore */
304 /* old handler */
305 movl _C_LABEL(_ssave),%sp /* manually restore stack */
306 moveq #1,%d0 /* indicate that we got a fault */
307 rts /* return to caller of badaddr() */
308
309 .data
310 GLOBAL(_bsave)
311 .long 0
312
313 GLOBAL(_ssave)
314 .long 0
315
316 ASENTRY_NOPROFILE(__trap)
317 moveml #0xFFFF,%sp@- /* save registers */
318 movl %sp,%sp@- /* push pointer to frame */
319 jsr _C_LABEL(trap) /* call C routine to deal with it */
320 tstl %d0
321 jeq Lstop
322 addql #4,%sp
323 moveml %sp@+,#0x7FFF
324 addql #8,%sp
325 rte
326 Lstop:
327 stop #0x2700 /* stop cold */
328
329 #ifdef ITECONSOLE
330 ASENTRY_NOPROFILE(nmi)
331 movw #18,BOOTTYPE /* mark as system switch */
332 jsr _C_LABEL(kbdnmi) /* clear the interrupt, and */
333 /* reset the system */
334 stop #0 /* SCREEEECH! */
335 #endif
336
337 ENTRY_NOPROFILE(call_req_reboot)
338 jmp 0x1A4 /* call ROM reboot function */
339 rts /* XXX: just in case? */
340
341 ENTRY_NOPROFILE(romout)
342 movl %sp@(4),%d0 /* line number */
343 movl %sp@(8),%a0 /* string */
344 jsr 0x150 /* do it */
345 rts
346
347 /*
348 * _transfer(entry, howto, opendev, conscode, lowram, esym)
349 *
350 * Transfer control to the kernel. We also set up registers
351 * as older kernels expect.
352 */
353 ENTRY_NOPROFILE(_transfer)
354 movl %sp@(8),%d7 /* howto */
355 movl %sp@(12),%d6 /* opendev (compat) */
356 movl %sp@(16),%d5 /* conscode (compat) */
357 movl %sp@(20),%a5 /* lowram */
358 movl %sp@(24),%a4 /* esym (compat) */
359
360 movl %sp@(4),%a0 /* load entry point */
361 jbsr %a0@ /* GO! */
362