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