1 /* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1982, 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. 9 * 10 * %sccs.include.redist.c% 11 * 12 * from: Utah $Hdr: srt0.c 1.12 91/04/25$ 13 * 14 * @(#)srt0.c 7.5 (Berkeley) 02/14/92 15 */ 16 17 /* 18 * Startup code for standalone system 19 */ 20 21 .globl begin 22 .globl _end 23 .globl _edata 24 .globl _main 25 .globl _configure 26 .globl _bootdev 27 .globl _firstopen 28 .globl __rtt 29 .globl _lowram,_howto,_devtype,_internalhpib,_machineid 30 31 STACK = 0xfffff000 | below the ROM page 32 BOOTTYPE = 0xfffffdc0 33 LOWRAM = 0xfffffdce 34 SYSFLAG = 0xfffffed2 | system flags 35 MSUS = 0xfffffedc | MSUS (?) structure 36 VECTORS = 0xfffffee0 | beginning of jump vectors 37 NMIRESET = 0xffffff9c | reset vector 38 BUSERR = 0xfffffffc 39 MAXADDR = 0xfffff000 40 NBPG = 4096 41 MMUCMD = 0x005f400c | MMU command/status register 42 43 .data 44 _bootdev: 45 .long 0 46 _devtype: 47 .long 0 48 _howto: 49 .long 0 50 _lowram: 51 .long 0 52 _machineid: 53 .long 0 54 55 .text 56 begin: 57 movl #STACK,sp 58 moveq #47,d0 | # of vectors - 1 59 movl #VECTORS+2,a0 | addr part of first vector 60 vecloop: 61 movl #trap,a0@ | make it direct to trap 62 addql #6,a0 | move to next vector addr 63 dbf d0,vecloop | go til done 64 movl #NMIRESET,a0 | NMI keyboard reset addr 65 movl #nmi,a0@ | catch in reset routine 66 /* 67 * Determine our CPU type and look for internal HP-IB 68 * (really only care about detecting 320 (no DIO-II) right now). 69 */ 70 lea _machineid,a0 71 movl #0x808,d0 72 movc d0,cacr | clear and disable on-chip cache(s) 73 movl #0x200,d0 | data freeze bit 74 movc d0,cacr | only exists on 68030 75 movc cacr,d0 | read it back 76 tstl d0 | zero? 77 jeq is68020 | yes, we have 68020 78 movl #0x808,d0 79 movc d0,cacr | clear data freeze bit again 80 movl #0x80,MMUCMD | set magic cookie 81 movl MMUCMD,d0 | read it back 82 btst #7,d0 | cookie still on? 83 jeq not370 | no, 360 or 375 84 movl #4,a0@ | consider a 370 for now 85 movl #0,MMUCMD | clear magic cookie 86 movl MMUCMD,d0 | read it back 87 btst #7,d0 | still on? 88 jeq ihpibcheck | no, a 370 89 movl #5,a0@ | yes, must be a 340 90 jra ihpibcheck 91 not370: 92 movl #3,a0@ | type is at least a 360 93 movl #0,MMUCMD | clear magic cookie2 94 movl MMUCMD,d0 | read it back 95 btst #16,d0 | still on? 96 jeq ihpibcheck | no, a 360 97 movl #6,a0@ | yes, must be a 345/375/400 98 jra ihpibcheck 99 is68020: 100 movl #1,a0@ | consider a 330 for now 101 movl #1,MMUCMD | a 68020, write HP MMU location 102 movl MMUCMD,d0 | read it back 103 btst #0,d0 | zero? 104 jeq ihpibcheck | yes, a 330 105 movl #0,a0@ | no, consider a 320 for now 106 movl #0x80,MMUCMD | set magic cookie 107 movl MMUCMD,d0 | read it back 108 btst #7,d0 | cookie still on? 109 jeq ihpibcheck | no, just a 320 110 movl #2,a0@ | yes, a 350 111 ihpibcheck: 112 movl #0,MMUCMD | make sure MMU is off 113 btst #5,SYSFLAG | do we have an internal HP-IB? 114 jeq boottype | yes, continue 115 clrl _internalhpib | no, clear the internal address 116 /* 117 * If this is a reboot, extract howto/devtype stored by kernel 118 */ 119 boottype: 120 cmpw #12,BOOTTYPE | is this a reboot (REQ_REBOOT)? 121 jne notreboot | no, skip 122 movl #MAXADDR,a0 | find last page 123 movl a0@+,d7 | and extract howto, devtype 124 movl a0@+,d6 | from where doboot() left them 125 jra boot1 126 /* 127 * At this point we do not know which logical hpib the given select 128 * code refers to. So we just put the select code in the adaptor field 129 * where hpibinit() can replace it with the logical hpib number. 130 * Note that this may clobber the B_DEVMAGIC field but that isn't set 131 * til later anyway. 132 */ 133 notreboot: 134 cmpw #18,BOOTTYPE | does the user want to interact? 135 jeq askme | yes, go to it 136 movl MSUS,d1 | no, get rom info 137 movw d1,d6 | MSUS comes with SC in upper, unit in lower 138 swap d6 | put in place 139 movw #2,d6 | assume 'a' partition of rd disk 140 moveq #0,d7 | default to RB_AUTOBOOT 141 jra boot1 142 askme: 143 moveq #7,d6 | default to HP-IB at sc7 144 lslw #8,d6 | position as adaptor number 145 swap d6 | put in place (note implied unit 0) 146 movw #2,d6 | assume 'a' partition of rd disk 147 moveq #3,d7 | default to RB_SINGLE|RB_ASKNAME 148 boot1: 149 movl d6,_devtype | save devtype and howto 150 movl d7,_howto | globally so all can access 151 movl LOWRAM,d0 | read lowram value from bootrom 152 addl #NBPG,d0 | must preserve this for bootrom to reboot 153 andl #0xfffff000,d0 | round to next page 154 movl d0,_lowram | stash that value 155 start: 156 movl #_edata,a2 | start of BSS 157 movl #_end,a3 | end 158 clr: 159 clrb a2@+ | clear BSS 160 cmpl a2,a3 | done? 161 bne clr | no, keep going 162 jsr _configure | configure critical devices 163 movl #1,_firstopen | mark this as the first open 164 jsr _main | lets go 165 __rtt: 166 movl #3,_howto | restarts get RB_SINGLE|RB_ASKNAME 167 jmp start 168 169 /* 170 * probe a location and see if it causes a bus error 171 */ 172 .globl _badaddr 173 _badaddr: 174 movl BUSERR,__bsave | save ROM bus error handler address 175 movl sp,__ssave | and current stack pointer 176 movl #catchbad,BUSERR| plug in our handler 177 movl sp@(4),a0 | address to probe 178 movw a0@,d1 | do it 179 movl __bsave,BUSERR | if we got here, it didn''t fault /* XXX cpp */ 180 clrl d0 | return that this was not a bad addr 181 rts 182 183 catchbad: 184 movl __bsave,BUSERR | got a bus error, so restore old handler 185 movl __ssave,sp | manually restore stack 186 moveq #1,d0 | indicate that we got a fault 187 rts | return to caller of badaddr() 188 189 __bsave: 190 .long 0 191 __ssave: 192 .long 0 193 194 .globl _trap 195 trap: 196 moveml #0xFFFF,sp@- | save registers 197 movl sp,sp@- | push pointer to frame 198 jsr _trap | call C routine to deal with it 199 stop #0x2700 | stop cold 200 201 nmi: 202 movw #18,BOOTTYPE | mark as system switch 203 jsr _kbdnmi | clear the interrupt 204 jra begin | start over 205 206 #ifdef ROMPRF 207 .globl _romout 208 _romout: 209 movl sp@(4),d0 | line number 210 movl sp@(8),a0 | string 211 jsr 0x150 | do it 212 rts 213 #endif 214