Home | History | Annotate | Line # | Download | only in stand
      1 /*
      2  * Copyright (c) 1988 University of Utah.
      3  * Copyright (c) 1982, 1990, 1993
      4  *	The Regents of the University of California.  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.18 92/12/21$
     13  *
     14  *	@(#)srt0.c	8.1 (Berkeley) 06/10/93
     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 	.word	0xf4d8		| cinva bc
    111 	movl	MMUCMD,d0	| get MMU register
    112 	lsrl	#8,d0		| get apparent ID
    113 	cmpb	#6,d0		| id == 6?
    114 	jeq	is33mhz		| yes, we have a 433s
    115 	movl	#7,a0@		| no, we have a 380/425t
    116 	jra	ihpibcheck
    117 is33mhz:
    118 	movl	#8,a0@		| 433s (XXX 425s returns same ID, ugh!)
    119 	jra	ihpibcheck
    120 is68020:
    121 	movl	#1,a0@		| consider a 330 for now
    122 	movl	#1,MMUCMD	| a 68020, write HP MMU location
    123 	movl	MMUCMD,d0	| read it back
    124 	btst	#0,d0		| zero?
    125 	jeq	ihpibcheck	| yes, a 330
    126 	movl	#0,a0@		| no, consider a 320 for now
    127 	movl	#0x80,MMUCMD	| set magic cookie
    128 	movl	MMUCMD,d0	| read it back
    129 	btst	#7,d0		| cookie still on?
    130 	jeq	ihpibcheck	| no, just a 320
    131 	movl	#2,a0@		| yes, a 350
    132 ihpibcheck:
    133 	movl	#0,MMUCMD	| make sure MMU is off
    134 	btst	#5,SYSFLAG	| do we have an internal HP-IB?
    135 	jeq	boottype	| yes, continue
    136 	clrl	_internalhpib	| no, clear the internal address
    137 /*
    138  * If this is a reboot, extract howto/bootdev stored by kernel
    139  */
    140 boottype:
    141 	cmpw	#12,BOOTTYPE	| is this a reboot (REQ_REBOOT)?
    142 	jne	notreboot	| no, skip
    143 	lea	MAXADDR,a0	| find last page
    144 	movl	a0@+,d7		| and extract howto, bootdev
    145 	movl	a0@+,d6		|   from where doboot() left them
    146 	jra	boot1
    147 /*
    148  * At this point we do not know which logical device the MSUS select
    149  * code refers to so we cannot construct bootdev.  So we just punt
    150  * and let configure() construct it.
    151  */
    152 notreboot:
    153 	moveq	#0,d6		| make sure bootdev is invalid
    154 	cmpw	#18,BOOTTYPE	| does the user want to interact?
    155 	jeq	askme		| yes, go to it
    156 	moveq	#0,d7		| default to RB_AUTOBOOT
    157 	jra	boot1
    158 askme:
    159 	moveq	#3,d7		| default to RB_SINGLE|RB_ASKNAME
    160 boot1:
    161 	movl	d6,_bootdev	| save bootdev and howto
    162 	movl	d7,_howto	|   globally so all can access
    163 	movl	LOWRAM,d0	| read lowram value from bootrom
    164 	addl	#NBPG,d0	| must preserve this for bootrom to reboot
    165 	andl	#0xfffff000,d0	| round to next page
    166 	movl	d0,_lowram	| stash that value
    167 start:
    168 	movl	#_edata,a2	| start of BSS
    169 	movl	#_end,a3	| end
    170 clr:
    171 	clrb	a2@+		| clear BSS
    172 	cmpl	a2,a3		| done?
    173 	bne	clr		| no, keep going
    174 	jsr	_configure	| configure critical devices
    175 	movl	#1,_firstopen	| mark this as the first open
    176 	jsr	_main		| lets go
    177 __rtt:
    178 	movl	#3,_howto	| restarts get RB_SINGLE|RB_ASKNAME
    179 	jmp	start
    180 
    181 /*
    182  * probe a location and see if it causes a bus error
    183  */
    184 	.globl	_badaddr
    185 _badaddr:
    186 	movl	BUSERR,__bsave	| save ROM bus error handler address
    187 	movl	sp,__ssave	| and current stack pointer
    188 	movl	#catchbad,BUSERR| plug in our handler
    189 	movl	sp@(4),a0	| address to probe
    190 	movw	a0@,d1		| do it
    191 	movl	__bsave,BUSERR	| if we got here, it did not fault
    192 	clrl	d0		| return that this was not a bad addr
    193 	rts
    194 
    195 catchbad:
    196 	movl	__bsave,BUSERR	| got a bus error, so restore old handler
    197 	movl	__ssave,sp	| manually restore stack
    198 	moveq	#1,d0		| indicate that we got a fault
    199 	rts			| return to caller of badaddr()
    200 
    201 __bsave:
    202 	.long	0
    203 __ssave:
    204 	.long	0
    205 
    206 	.globl	_trap
    207 trap:
    208 	moveml	#0xFFFF,sp@-	| save registers
    209 	movl	sp,sp@-		| push pointer to frame
    210 	jsr	_trap		| call C routine to deal with it
    211 	tstl	d0
    212 	jeq	Lstop
    213 	addql	#4,sp
    214 	moveml	sp@+,#0x7FFF
    215 	addql	#8,sp
    216 	rte
    217 Lstop:
    218 	stop	#0x2700		| stop cold
    219 
    220 nmi:
    221 	movw	#18,BOOTTYPE	| mark as system switch
    222 	jsr	_kbdnmi		| clear the interrupt
    223 	jra	begin		| start over
    224 
    225 #ifdef ROMPRF
    226 	.globl	_romout
    227 _romout:
    228 	movl	sp@(4),d0	| line number
    229 	movl	sp@(8),a0	| string
    230 	jsr	0x150		| do it
    231 	rts
    232 #endif
    233