xref: /csrg-svn/sys/hp300/stand/srt0.c (revision 63165)
141488Smckusick /*
241488Smckusick  * Copyright (c) 1988 University of Utah.
3*63165Sbostic  * Copyright (c) 1982, 1990, 1993
4*63165Sbostic  *	The Regents of the University of California.  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  *
1257299Shibler  * from: Utah $Hdr: srt0.c 1.18 92/12/21$
1341488Smckusick  *
14*63165Sbostic  *	@(#)srt0.c	8.1 (Berkeley) 06/10/93
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	_firstopen
2741488Smckusick 	.globl	__rtt
2854073Shibler 	.globl	_bootdev,_howto,_lowram,_machineid
2954073Shibler 	.globl	_internalhpib
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
4149333Shibler 	MMUCMD =   0x005f400c	| MMU command/status register
4241488Smckusick 
4341488Smckusick 	.data
4449157Sbostic _bootdev:
4541488Smckusick 	.long	0
4641488Smckusick _howto:
4741488Smckusick 	.long	0
4849157Sbostic _lowram:
4941488Smckusick 	.long	0
5049333Shibler _machineid:
5149333Shibler 	.long	0
5241488Smckusick 
5341488Smckusick 	.text
5441488Smckusick begin:
5541488Smckusick 	movl	#STACK,sp
5641488Smckusick 	moveq	#47,d0		| # of vectors - 1
5741488Smckusick 	movl	#VECTORS+2,a0	| addr part of first vector
5841488Smckusick vecloop:
5941488Smckusick 	movl	#trap,a0@	| make it direct to trap
6041488Smckusick 	addql	#6,a0		| move to next vector addr
6141488Smckusick 	dbf	d0,vecloop	| go til done
6241488Smckusick 	movl	#NMIRESET,a0	| NMI keyboard reset addr
6341488Smckusick 	movl	#nmi,a0@	| catch in reset routine
6449333Shibler /*
6549333Shibler  * Determine our CPU type and look for internal HP-IB
6649333Shibler  * (really only care about detecting 320 (no DIO-II) right now).
6749333Shibler  */
6849333Shibler 	lea	_machineid,a0
6949333Shibler 	movl	#0x808,d0
7049333Shibler 	movc	d0,cacr		| clear and disable on-chip cache(s)
7149333Shibler 	movl	#0x200,d0	| data freeze bit
7249333Shibler 	movc	d0,cacr		|   only exists on 68030
7349333Shibler 	movc	cacr,d0		| read it back
7449333Shibler 	tstl	d0		| zero?
7554073Shibler 	jeq	not68030	| yes, we have 68020/68040
7649333Shibler 	movl	#0x808,d0
7749333Shibler 	movc	d0,cacr		| clear data freeze bit again
7854073Shibler 
7949333Shibler 	movl	#0x80,MMUCMD	| set magic cookie
8049333Shibler 	movl	MMUCMD,d0	| read it back
8149333Shibler 	btst	#7,d0		| cookie still on?
8249333Shibler 	jeq	not370		| no, 360 or 375
8349333Shibler 	movl	#4,a0@		| consider a 370 for now
8449333Shibler 	movl	#0,MMUCMD	| clear magic cookie
8549333Shibler 	movl	MMUCMD,d0	| read it back
8649333Shibler 	btst	#7,d0		| still on?
8749333Shibler 	jeq	ihpibcheck	| no, a 370
8849333Shibler 	movl	#5,a0@		| yes, must be a 340
8949333Shibler 	jra	ihpibcheck
9049333Shibler not370:
9149333Shibler 	movl	#3,a0@		| type is at least a 360
9249333Shibler 	movl	#0,MMUCMD	| clear magic cookie2
9349333Shibler 	movl	MMUCMD,d0	| read it back
9449333Shibler 	btst	#16,d0		| still on?
9549333Shibler 	jeq	ihpibcheck	| no, a 360
9649333Shibler 	movl	#6,a0@		| yes, must be a 345/375/400
9749333Shibler 	jra	ihpibcheck
9854073Shibler not68030:
9954073Shibler 	bset	#31,d0		| data cache enable bit
10054073Shibler 	movc	d0,cacr		|   only exists on 68040
10154073Shibler 	movc	cacr,d0		| read it back
10254073Shibler 	tstl	d0		| zero?
10354073Shibler 	beq	is68020		| yes, we have 68020
10454073Shibler 	moveq	#0,d0		| now turn it back off
10554073Shibler 	movec	d0,cacr		|   before we access any data
10654073Shibler 	.long	0x4e7b0004	| movc d0,itt0
10754073Shibler 	.long	0x4e7b0005	| movc d0,itt1
10854073Shibler 	.long	0x4e7b0006	| movc d0,dtt0
10954073Shibler 	.long	0x4e7b0007	| movc d0,dtt1
11057299Shibler 	.word	0xf4d8		| cinva bc
11157299Shibler 	movl	MMUCMD,d0	| get MMU register
11257299Shibler 	lsrl	#8,d0		| get apparent ID
11357299Shibler 	cmpb	#6,d0		| id == 6?
11457299Shibler 	jeq	is33mhz		| yes, we have a 433s
11557299Shibler 	movl	#7,a0@		| no, we have a 380/425t
11654073Shibler 	jra	ihpibcheck
11757299Shibler is33mhz:
11857299Shibler 	movl	#8,a0@		| 433s (XXX 425s returns same ID, ugh!)
11957299Shibler 	jra	ihpibcheck
12049333Shibler is68020:
12149333Shibler 	movl	#1,a0@		| consider a 330 for now
12249333Shibler 	movl	#1,MMUCMD	| a 68020, write HP MMU location
12349333Shibler 	movl	MMUCMD,d0	| read it back
12449333Shibler 	btst	#0,d0		| zero?
12549333Shibler 	jeq	ihpibcheck	| yes, a 330
12649333Shibler 	movl	#0,a0@		| no, consider a 320 for now
12749333Shibler 	movl	#0x80,MMUCMD	| set magic cookie
12849333Shibler 	movl	MMUCMD,d0	| read it back
12949333Shibler 	btst	#7,d0		| cookie still on?
13049333Shibler 	jeq	ihpibcheck	| no, just a 320
13149333Shibler 	movl	#2,a0@		| yes, a 350
13249333Shibler ihpibcheck:
13349333Shibler 	movl	#0,MMUCMD	| make sure MMU is off
13442378Smckusick 	btst	#5,SYSFLAG	| do we have an internal HP-IB?
13542378Smckusick 	jeq	boottype	| yes, continue
13642378Smckusick 	clrl	_internalhpib	| no, clear the internal address
13749333Shibler /*
13854073Shibler  * If this is a reboot, extract howto/bootdev stored by kernel
13949333Shibler  */
14042378Smckusick boottype:
14141488Smckusick 	cmpw	#12,BOOTTYPE	| is this a reboot (REQ_REBOOT)?
14241488Smckusick 	jne	notreboot	| no, skip
14354073Shibler 	lea	MAXADDR,a0	| find last page
14454073Shibler 	movl	a0@+,d7		| and extract howto, bootdev
14541488Smckusick 	movl	a0@+,d6		|   from where doboot() left them
14641488Smckusick 	jra	boot1
14741488Smckusick /*
14854073Shibler  * At this point we do not know which logical device the MSUS select
14954073Shibler  * code refers to so we cannot construct bootdev.  So we just punt
15054073Shibler  * and let configure() construct it.
15141488Smckusick  */
15241488Smckusick notreboot:
15354073Shibler 	moveq	#0,d6		| make sure bootdev is invalid
15441488Smckusick 	cmpw	#18,BOOTTYPE	| does the user want to interact?
15541488Smckusick 	jeq	askme		| yes, go to it
15641488Smckusick 	moveq	#0,d7		| default to RB_AUTOBOOT
15741488Smckusick 	jra	boot1
15841488Smckusick askme:
15941488Smckusick 	moveq	#3,d7		| default to RB_SINGLE|RB_ASKNAME
16041488Smckusick boot1:
16154073Shibler 	movl	d6,_bootdev	| save bootdev and howto
16241488Smckusick 	movl	d7,_howto	|   globally so all can access
16341488Smckusick 	movl	LOWRAM,d0	| read lowram value from bootrom
16441488Smckusick 	addl	#NBPG,d0	| must preserve this for bootrom to reboot
16541488Smckusick 	andl	#0xfffff000,d0	| round to next page
16641488Smckusick 	movl	d0,_lowram	| stash that value
16741488Smckusick start:
16841488Smckusick 	movl	#_edata,a2	| start of BSS
16941488Smckusick 	movl	#_end,a3	| end
17041488Smckusick clr:
17141488Smckusick 	clrb	a2@+		| clear BSS
17241488Smckusick 	cmpl	a2,a3		| done?
17341488Smckusick 	bne	clr		| no, keep going
17441488Smckusick 	jsr	_configure	| configure critical devices
17549157Sbostic 	movl	#1,_firstopen	| mark this as the first open
17641488Smckusick 	jsr	_main		| lets go
17741488Smckusick __rtt:
17841488Smckusick 	movl	#3,_howto	| restarts get RB_SINGLE|RB_ASKNAME
17941488Smckusick 	jmp	start
18041488Smckusick 
18141488Smckusick /*
18241488Smckusick  * probe a location and see if it causes a bus error
18341488Smckusick  */
18441488Smckusick 	.globl	_badaddr
18541488Smckusick _badaddr:
18641488Smckusick 	movl	BUSERR,__bsave	| save ROM bus error handler address
18741488Smckusick 	movl	sp,__ssave	| and current stack pointer
18841488Smckusick 	movl	#catchbad,BUSERR| plug in our handler
18941488Smckusick 	movl	sp@(4),a0	| address to probe
19041488Smckusick 	movw	a0@,d1		| do it
19154073Shibler 	movl	__bsave,BUSERR	| if we got here, it did not fault
19241488Smckusick 	clrl	d0		| return that this was not a bad addr
19341488Smckusick 	rts
19441488Smckusick 
19541488Smckusick catchbad:
19641488Smckusick 	movl	__bsave,BUSERR	| got a bus error, so restore old handler
19741488Smckusick 	movl	__ssave,sp	| manually restore stack
19841488Smckusick 	moveq	#1,d0		| indicate that we got a fault
19941488Smckusick 	rts			| return to caller of badaddr()
20041488Smckusick 
20141488Smckusick __bsave:
20241488Smckusick 	.long	0
20341488Smckusick __ssave:
20441488Smckusick 	.long	0
20541488Smckusick 
20641488Smckusick 	.globl	_trap
20741488Smckusick trap:
20841488Smckusick 	moveml	#0xFFFF,sp@-	| save registers
20941488Smckusick 	movl	sp,sp@-		| push pointer to frame
21041488Smckusick 	jsr	_trap		| call C routine to deal with it
21154073Shibler 	tstl	d0
21254073Shibler 	jeq	Lstop
21354073Shibler 	addql	#4,sp
21454073Shibler 	moveml	sp@+,#0x7FFF
21554073Shibler 	addql	#8,sp
21654073Shibler 	rte
21754073Shibler Lstop:
21841488Smckusick 	stop	#0x2700		| stop cold
21941488Smckusick 
22041488Smckusick nmi:
22141488Smckusick 	movw	#18,BOOTTYPE	| mark as system switch
22241488Smckusick 	jsr	_kbdnmi		| clear the interrupt
22341488Smckusick 	jra	begin		| start over
22441488Smckusick 
22541488Smckusick #ifdef ROMPRF
22641488Smckusick 	.globl	_romout
22741488Smckusick _romout:
22841488Smckusick 	movl	sp@(4),d0	| line number
22941488Smckusick 	movl	sp@(8),a0	| string
23041488Smckusick 	jsr	0x150		| do it
23141488Smckusick 	rts
23241488Smckusick #endif
233