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