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.15 92/06/18$ 13 * 14 * @(#)srt0.c 7.6 (Berkeley) 06/18/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 _firstopen 27 .globl __rtt 28 .globl _bootdev,_howto,_lowram,_machineid 29 .globl _internalhpib 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 _howto: 47 .long 0 48 _lowram: 49 .long 0 50 _machineid: 51 .long 0 52 53 .text 54 begin: 55 movl #STACK,sp 56 moveq #47,d0 | # of vectors - 1 57 movl #VECTORS+2,a0 | addr part of first vector 58 vecloop: 59 movl #trap,a0@ | make it direct to trap 60 addql #6,a0 | move to next vector addr 61 dbf d0,vecloop | go til done 62 movl #NMIRESET,a0 | NMI keyboard reset addr 63 movl #nmi,a0@ | catch in reset routine 64 /* 65 * Determine our CPU type and look for internal HP-IB 66 * (really only care about detecting 320 (no DIO-II) right now). 67 */ 68 lea _machineid,a0 69 movl #0x808,d0 70 movc d0,cacr | clear and disable on-chip cache(s) 71 movl #0x200,d0 | data freeze bit 72 movc d0,cacr | only exists on 68030 73 movc cacr,d0 | read it back 74 tstl d0 | zero? 75 jeq not68030 | yes, we have 68020/68040 76 movl #0x808,d0 77 movc d0,cacr | clear data freeze bit again 78 79 movl #0x80,MMUCMD | set magic cookie 80 movl MMUCMD,d0 | read it back 81 btst #7,d0 | cookie still on? 82 jeq not370 | no, 360 or 375 83 movl #4,a0@ | consider a 370 for now 84 movl #0,MMUCMD | clear magic cookie 85 movl MMUCMD,d0 | read it back 86 btst #7,d0 | still on? 87 jeq ihpibcheck | no, a 370 88 movl #5,a0@ | yes, must be a 340 89 jra ihpibcheck 90 not370: 91 movl #3,a0@ | type is at least a 360 92 movl #0,MMUCMD | clear magic cookie2 93 movl MMUCMD,d0 | read it back 94 btst #16,d0 | still on? 95 jeq ihpibcheck | no, a 360 96 movl #6,a0@ | yes, must be a 345/375/400 97 jra ihpibcheck 98 not68030: 99 bset #31,d0 | data cache enable bit 100 movc d0,cacr | only exists on 68040 101 movc cacr,d0 | read it back 102 tstl d0 | zero? 103 beq is68020 | yes, we have 68020 104 moveq #0,d0 | now turn it back off 105 movec d0,cacr | before we access any data 106 .long 0x4e7b0004 | movc d0,itt0 107 .long 0x4e7b0005 | movc d0,itt1 108 .long 0x4e7b0006 | movc d0,dtt0 109 .long 0x4e7b0007 | movc d0,dtt1 110 movl #7,a0@ | we have a 380 111 jra ihpibcheck 112 is68020: 113 movl #1,a0@ | consider a 330 for now 114 movl #1,MMUCMD | a 68020, write HP MMU location 115 movl MMUCMD,d0 | read it back 116 btst #0,d0 | zero? 117 jeq ihpibcheck | yes, a 330 118 movl #0,a0@ | no, consider a 320 for now 119 movl #0x80,MMUCMD | set magic cookie 120 movl MMUCMD,d0 | read it back 121 btst #7,d0 | cookie still on? 122 jeq ihpibcheck | no, just a 320 123 movl #2,a0@ | yes, a 350 124 ihpibcheck: 125 movl #0,MMUCMD | make sure MMU is off 126 btst #5,SYSFLAG | do we have an internal HP-IB? 127 jeq boottype | yes, continue 128 clrl _internalhpib | no, clear the internal address 129 /* 130 * If this is a reboot, extract howto/bootdev stored by kernel 131 */ 132 boottype: 133 cmpw #12,BOOTTYPE | is this a reboot (REQ_REBOOT)? 134 jne notreboot | no, skip 135 lea MAXADDR,a0 | find last page 136 movl a0@+,d7 | and extract howto, bootdev 137 movl a0@+,d6 | from where doboot() left them 138 jra boot1 139 /* 140 * At this point we do not know which logical device the MSUS select 141 * code refers to so we cannot construct bootdev. So we just punt 142 * and let configure() construct it. 143 */ 144 notreboot: 145 moveq #0,d6 | make sure bootdev is invalid 146 cmpw #18,BOOTTYPE | does the user want to interact? 147 jeq askme | yes, go to it 148 moveq #0,d7 | default to RB_AUTOBOOT 149 jra boot1 150 askme: 151 moveq #3,d7 | default to RB_SINGLE|RB_ASKNAME 152 boot1: 153 movl d6,_bootdev | save bootdev and howto 154 movl d7,_howto | globally so all can access 155 movl LOWRAM,d0 | read lowram value from bootrom 156 addl #NBPG,d0 | must preserve this for bootrom to reboot 157 andl #0xfffff000,d0 | round to next page 158 movl d0,_lowram | stash that value 159 start: 160 movl #_edata,a2 | start of BSS 161 movl #_end,a3 | end 162 clr: 163 clrb a2@+ | clear BSS 164 cmpl a2,a3 | done? 165 bne clr | no, keep going 166 jsr _configure | configure critical devices 167 movl #1,_firstopen | mark this as the first open 168 jsr _main | lets go 169 __rtt: 170 movl #3,_howto | restarts get RB_SINGLE|RB_ASKNAME 171 jmp start 172 173 /* 174 * probe a location and see if it causes a bus error 175 */ 176 .globl _badaddr 177 _badaddr: 178 movl BUSERR,__bsave | save ROM bus error handler address 179 movl sp,__ssave | and current stack pointer 180 movl #catchbad,BUSERR| plug in our handler 181 movl sp@(4),a0 | address to probe 182 movw a0@,d1 | do it 183 movl __bsave,BUSERR | if we got here, it did not fault 184 clrl d0 | return that this was not a bad addr 185 rts 186 187 catchbad: 188 movl __bsave,BUSERR | got a bus error, so restore old handler 189 movl __ssave,sp | manually restore stack 190 moveq #1,d0 | indicate that we got a fault 191 rts | return to caller of badaddr() 192 193 __bsave: 194 .long 0 195 __ssave: 196 .long 0 197 198 .globl _trap 199 trap: 200 moveml #0xFFFF,sp@- | save registers 201 movl sp,sp@- | push pointer to frame 202 jsr _trap | call C routine to deal with it 203 tstl d0 204 jeq Lstop 205 addql #4,sp 206 moveml sp@+,#0x7FFF 207 addql #8,sp 208 rte 209 Lstop: 210 stop #0x2700 | stop cold 211 212 nmi: 213 movw #18,BOOTTYPE | mark as system switch 214 jsr _kbdnmi | clear the interrupt 215 jra begin | start over 216 217 #ifdef ROMPRF 218 .globl _romout 219 _romout: 220 movl sp@(4),d0 | line number 221 movl sp@(8),a0 | string 222 jsr 0x150 | do it 223 rts 224 #endif 225