xref: /csrg-svn/sys/hp300/stand/srt0.c (revision 49333)
141488Smckusick /*
241488Smckusick  * Copyright (c) 1988 University of Utah.
341488Smckusick  * Copyright (c) 1982, 1990 The Regents of the University of California.
441488Smckusick  * All rights reserved.
541488Smckusick  *
641488Smckusick  * This code is derived from software contributed to Berkeley by
741488Smckusick  * the Systems Programming Group of the University of Utah Computer
841488Smckusick  * Science Department.
941488Smckusick  *
1041488Smckusick  * %sccs.include.redist.c%
1141488Smckusick  *
12*49333Shibler  * from: Utah $Hdr: srt0.c 1.12 91/04/25$
1341488Smckusick  *
14*49333Shibler  *	@(#)srt0.c	7.4 (Berkeley) 05/07/91
1541488Smckusick  */
1641488Smckusick 
1741488Smckusick /*
1841488Smckusick  * Startup code for standalone system
1941488Smckusick  */
2041488Smckusick 
2141488Smckusick 	.globl	begin
2241488Smckusick 	.globl	_end
2341488Smckusick 	.globl	_edata
2441488Smckusick 	.globl	_main
2541488Smckusick 	.globl	_configure
2649157Sbostic 	.globl	_bootdev
2749157Sbostic 	.globl	_firstopen
2841488Smckusick 	.globl	__rtt
29*49333Shibler 	.globl	_lowram,_howto,_devtype,_internalhpib,_machineid
3041488Smckusick 
3141488Smckusick 	STACK =    0xfffff000	| below the ROM page
3241488Smckusick 	BOOTTYPE = 0xfffffdc0
3341488Smckusick 	LOWRAM =   0xfffffdce
3442378Smckusick 	SYSFLAG =  0xfffffed2	| system flags
3541488Smckusick 	MSUS =	   0xfffffedc	| MSUS (?) structure
3641488Smckusick 	VECTORS =  0xfffffee0	| beginning of jump vectors
3741488Smckusick 	NMIRESET = 0xffffff9c	| reset vector
3841488Smckusick 	BUSERR =   0xfffffffc
3941488Smckusick 	MAXADDR =  0xfffff000
4041488Smckusick 	NBPG =     4096
41*49333Shibler 	MMUCMD =   0x005f400c	| MMU command/status register
4241488Smckusick 
4341488Smckusick 	.data
4449157Sbostic _bootdev:
4541488Smckusick 	.long	0
4649157Sbostic _devtype:
4749157Sbostic 	.long	0
4841488Smckusick _howto:
4941488Smckusick 	.long	0
5049157Sbostic _lowram:
5141488Smckusick 	.long	0
52*49333Shibler _machineid:
53*49333Shibler 	.long	0
5441488Smckusick 
5541488Smckusick 	.text
5641488Smckusick begin:
5741488Smckusick 	movl	#STACK,sp
5841488Smckusick 	moveq	#47,d0		| # of vectors - 1
5941488Smckusick 	movl	#VECTORS+2,a0	| addr part of first vector
6041488Smckusick vecloop:
6141488Smckusick 	movl	#trap,a0@	| make it direct to trap
6241488Smckusick 	addql	#6,a0		| move to next vector addr
6341488Smckusick 	dbf	d0,vecloop	| go til done
6441488Smckusick 	movl	#NMIRESET,a0	| NMI keyboard reset addr
6541488Smckusick 	movl	#nmi,a0@	| catch in reset routine
66*49333Shibler /*
67*49333Shibler  * Determine our CPU type and look for internal HP-IB
68*49333Shibler  * (really only care about detecting 320 (no DIO-II) right now).
69*49333Shibler  */
70*49333Shibler 	lea	_machineid,a0
71*49333Shibler 	movl	#0x808,d0
72*49333Shibler 	movc	d0,cacr		| clear and disable on-chip cache(s)
73*49333Shibler 	movl	#0x200,d0	| data freeze bit
74*49333Shibler 	movc	d0,cacr		|   only exists on 68030
75*49333Shibler 	movc	cacr,d0		| read it back
76*49333Shibler 	tstl	d0		| zero?
77*49333Shibler 	jeq	is68020		| yes, we have 68020
78*49333Shibler 	movl	#0x808,d0
79*49333Shibler 	movc	d0,cacr		| clear data freeze bit again
80*49333Shibler 	movl	#0x80,MMUCMD	| set magic cookie
81*49333Shibler 	movl	MMUCMD,d0	| read it back
82*49333Shibler 	btst	#7,d0		| cookie still on?
83*49333Shibler 	jeq	not370		| no, 360 or 375
84*49333Shibler 	movl	#4,a0@		| consider a 370 for now
85*49333Shibler 	movl	#0,MMUCMD	| clear magic cookie
86*49333Shibler 	movl	MMUCMD,d0	| read it back
87*49333Shibler 	btst	#7,d0		| still on?
88*49333Shibler 	jeq	ihpibcheck	| no, a 370
89*49333Shibler 	movl	#5,a0@		| yes, must be a 340
90*49333Shibler 	jra	ihpibcheck
91*49333Shibler not370:
92*49333Shibler 	movl	#3,a0@		| type is at least a 360
93*49333Shibler 	movl	#0,MMUCMD	| clear magic cookie2
94*49333Shibler 	movl	MMUCMD,d0	| read it back
95*49333Shibler 	btst	#16,d0		| still on?
96*49333Shibler 	jeq	ihpibcheck	| no, a 360
97*49333Shibler 	movl	#6,a0@		| yes, must be a 345/375/400
98*49333Shibler 	jra	ihpibcheck
99*49333Shibler is68020:
100*49333Shibler 	movl	#1,a0@		| consider a 330 for now
101*49333Shibler 	movl	#1,MMUCMD	| a 68020, write HP MMU location
102*49333Shibler 	movl	MMUCMD,d0	| read it back
103*49333Shibler 	btst	#0,d0		| zero?
104*49333Shibler 	jeq	ihpibcheck	| yes, a 330
105*49333Shibler 	movl	#0,a0@		| no, consider a 320 for now
106*49333Shibler 	movl	#0x80,MMUCMD	| set magic cookie
107*49333Shibler 	movl	MMUCMD,d0	| read it back
108*49333Shibler 	btst	#7,d0		| cookie still on?
109*49333Shibler 	jeq	ihpibcheck	| no, just a 320
110*49333Shibler 	movl	#2,a0@		| yes, a 350
111*49333Shibler ihpibcheck:
112*49333Shibler 	movl	#0,MMUCMD	| make sure MMU is off
11342378Smckusick 	btst	#5,SYSFLAG	| do we have an internal HP-IB?
11442378Smckusick 	jeq	boottype	| yes, continue
11542378Smckusick 	clrl	_internalhpib	| no, clear the internal address
116*49333Shibler /*
117*49333Shibler  * If this is a reboot, extract howto/devtype stored by kernel
118*49333Shibler  */
11942378Smckusick boottype:
12041488Smckusick 	cmpw	#12,BOOTTYPE	| is this a reboot (REQ_REBOOT)?
12141488Smckusick 	jne	notreboot	| no, skip
12241488Smckusick 	movl	#MAXADDR,a0	| find last page
12341488Smckusick 	movl	a0@+,d7		| and extract howto, devtype
12441488Smckusick 	movl	a0@+,d6		|   from where doboot() left them
12541488Smckusick 	jra	boot1
12641488Smckusick /*
12741488Smckusick  * At this point we do not know which logical hpib the given select
12841488Smckusick  * code refers to.  So we just put the select code in the adaptor field
12941488Smckusick  * where hpibinit() can replace it with the logical hpib number.
13041488Smckusick  * Note that this may clobber the B_DEVMAGIC field but that isn't set
13141488Smckusick  * til later anyway.
13241488Smckusick  */
13341488Smckusick notreboot:
13441488Smckusick 	cmpw	#18,BOOTTYPE	| does the user want to interact?
13541488Smckusick 	jeq	askme		| yes, go to it
13641488Smckusick 	movl	MSUS,d1		| no, get rom info
13741488Smckusick 	movw	d1,d6		| MSUS comes with SC in upper, unit in lower
13841488Smckusick 	swap	d6		| put in place
13941488Smckusick 	movw	#2,d6		| assume 'a' partition of rd disk
14041488Smckusick 	moveq	#0,d7		| default to RB_AUTOBOOT
14141488Smckusick 	jra	boot1
14241488Smckusick askme:
14341488Smckusick 	moveq	#7,d6		| default to HP-IB at sc7
14441488Smckusick 	lslw	#8,d6		| position as adaptor number
14541488Smckusick 	swap	d6		| put in place (note implied unit 0)
14641488Smckusick 	movw	#2,d6		| assume 'a' partition of rd disk
14741488Smckusick 	moveq	#3,d7		| default to RB_SINGLE|RB_ASKNAME
14841488Smckusick boot1:
14941488Smckusick 	movl	d6,_devtype	| save devtype and howto
15041488Smckusick 	movl	d7,_howto	|   globally so all can access
15141488Smckusick 	movl	LOWRAM,d0	| read lowram value from bootrom
15241488Smckusick 	addl	#NBPG,d0	| must preserve this for bootrom to reboot
15341488Smckusick 	andl	#0xfffff000,d0	| round to next page
15441488Smckusick 	movl	d0,_lowram	| stash that value
15541488Smckusick start:
15641488Smckusick 	movl	#_edata,a2	| start of BSS
15741488Smckusick 	movl	#_end,a3	| end
15841488Smckusick clr:
15941488Smckusick 	clrb	a2@+		| clear BSS
16041488Smckusick 	cmpl	a2,a3		| done?
16141488Smckusick 	bne	clr		| no, keep going
16241488Smckusick 	jsr	_configure	| configure critical devices
16349157Sbostic 	movl	#1,_firstopen	| mark this as the first open
16441488Smckusick 	jsr	_main		| lets go
16541488Smckusick __rtt:
16641488Smckusick 	movl	#3,_howto	| restarts get RB_SINGLE|RB_ASKNAME
16741488Smckusick 	jmp	start
16841488Smckusick 
16941488Smckusick /*
17041488Smckusick  * probe a location and see if it causes a bus error
17141488Smckusick  */
17241488Smckusick 	.globl	_badaddr
17341488Smckusick _badaddr:
17441488Smckusick 	movl	BUSERR,__bsave	| save ROM bus error handler address
17541488Smckusick 	movl	sp,__ssave	| and current stack pointer
17641488Smckusick 	movl	#catchbad,BUSERR| plug in our handler
17741488Smckusick 	movl	sp@(4),a0	| address to probe
17841488Smckusick 	movw	a0@,d1		| do it
17941488Smckusick 	movl	__bsave,BUSERR	| if we got here, it didn't fault
18041488Smckusick 	clrl	d0		| return that this was not a bad addr
18141488Smckusick 	rts
18241488Smckusick 
18341488Smckusick catchbad:
18441488Smckusick 	movl	__bsave,BUSERR	| got a bus error, so restore old handler
18541488Smckusick 	movl	__ssave,sp	| manually restore stack
18641488Smckusick 	moveq	#1,d0		| indicate that we got a fault
18741488Smckusick 	rts			| return to caller of badaddr()
18841488Smckusick 
18941488Smckusick __bsave:
19041488Smckusick 	.long	0
19141488Smckusick __ssave:
19241488Smckusick 	.long	0
19341488Smckusick 
19441488Smckusick 	.globl	_trap
19541488Smckusick trap:
19641488Smckusick 	moveml	#0xFFFF,sp@-	| save registers
19741488Smckusick 	movl	sp,sp@-		| push pointer to frame
19841488Smckusick 	jsr	_trap		| call C routine to deal with it
19941488Smckusick 	stop	#0x2700		| stop cold
20041488Smckusick 
20141488Smckusick nmi:
20241488Smckusick 	movw	#18,BOOTTYPE	| mark as system switch
20341488Smckusick 	jsr	_kbdnmi		| clear the interrupt
20441488Smckusick 	jra	begin		| start over
20541488Smckusick 
20641488Smckusick #ifdef ROMPRF
20741488Smckusick 	.globl	_romout
20841488Smckusick _romout:
20941488Smckusick 	movl	sp@(4),d0	| line number
21041488Smckusick 	movl	sp@(8),a0	| string
21141488Smckusick 	jsr	0x150		| do it
21241488Smckusick 	rts
21341488Smckusick #endif
214