Home | History | Annotate | Line # | Download | only in xxboot
start.S revision 1.3
      1 /*	$NetBSD: start.S,v 1.3 2005/10/21 21:10:45 he Exp $ */
      2 /*
      3  * Copyright (c) 1995 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to Ludd by
      7  * Bertram Barth.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed at Ludd, University of
     20  *	Lule}, Sweden and its contributors.
     21  * 4. The name of the author may not be used to endorse or promote products
     22  *    derived from this software without specific prior written permission
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36  /* All bugs are subject to removal without further notice */
     37 
     38 
     39 #define _LOCORE
     40 
     41 #define OMIT_DKTYPENUMS
     42 #define OMIT_FSTYPENUMS
     43 #include "sys/disklabel.h"
     44 
     45 #include "../include/mtpr.h"
     46 #include "../include/asm.h"
     47 
     48 _C_LABEL(_start):
     49 _C_LABEL(start):
     50 	.globl _C_LABEL(start)	# this is the symbolic name for the start
     51 	.globl _C_LABEL(_start) # of code to be relocated. We can use this
     52 				# to get the actual/real address (pc-rel)
     53 				# or to get the relocated address (abs).
     54 
     55 .org	0x00			# uVAX booted from TK50 starts here
     56 	brb	from_0x00	# continue behind dispatch-block
     57 
     58 .org	0x02			# information used by uVAX-ROM
     59 	.byte	0xcf		# offset in words to identification area
     60 	.byte	1		# this byte must be 1
     61 	.word	0		# logical block number (word swapped)
     62 	.word	0		# of the secondary image
     63 
     64 .org	0x08			#
     65 	brb	from_0x08	# skip ...
     66 
     67 .org	0x0C			# 11/750  & 8200 starts here
     68 	movzbl	$1,_C_LABEL(from)# We booted from "old" rom.
     69 	brw	cont_750
     70 
     71 
     72 from_0x00:			# uVAX from TK50
     73 	brw	start_uvax	# all uVAXen continue there
     74 
     75 from_0x08:			# Any machine from VMB
     76 	movzbl	$4,_C_LABEL(from)		# Booted from full VMB
     77 	brw	start_vmb
     78 
     79 # the complete area reserved for label
     80 # must be empty (i.e. filled with zeroes).
     81 # disklabel(8) checks that before installing
     82 # the bootblocks over existing label.
     83 
     84 .org	LABELOFFSET
     85 	.globl	_C_LABEL(romlabel)
     86 _C_LABEL(romlabel):
     87 	.long	0
     88 
     89 .org	LABELOFFSET + d_end_
     90 start_vmb:
     91 	/*
     92 	 * Read in block 1-15.
     93 	 */
     94 	movl	52(%r11), %r7	# load iovec/bqo into %r7
     95 	addl3	(%r7), %r7, %r6	# load qio into %r6
     96 	pushl	%r11		# base of rpb
     97 	pushl	$0		# virtual-flag
     98 	pushl	$33		# read-logical-block
     99 	pushl	$1		# lbn to start reading
    100 	pushl	$7680		# number of bytes to read
    101 	pushab	start_uvax	# buffer-address
    102 	calls	$6, (%r6)	# call the qio-routine
    103 	brw	start_uvax
    104 
    105 /*
    106  * Parameter block for uVAX boot.
    107  */
    108 #define VOLINFO		0	/* 1=single-sided  81=double-sided volumes */
    109 #define SISIZE		16	/* size in blocks of secondary image */
    110 #define SILOAD		0	/* load offset (usually 0) from the default */
    111 #define SIOFF		0x200	/* byte offset into secondary image */
    112 
    113 .org	0x19e
    114 	.byte	0x18		# must be 0x18
    115 	.byte	0x00		# must be 0x00 (MBZ)
    116 	.byte	0x00		# any value
    117 	.byte	0xFF - (0x18 + 0x00 + 0x00)
    118 		/* 4th byte holds 1s' complement of sum of previous 3 bytes */
    119 
    120 	.byte	0x00		# must be 0x00 (MBZ)
    121 	.byte	VOLINFO
    122 	.byte	0x00		# any value
    123 	.byte	0x00		# any value
    124 
    125 	.long	SISIZE		# size in blocks of secondary image
    126 	.long	SILOAD		# load offset (usually 0)
    127 	.long	SIOFF		# byte offset into secondary image
    128 	.long	(SISIZE + SILOAD + SIOFF)	# sum of previous 3
    129 
    130 
    131 	.align	2
    132 	.globl	_C_LABEL(from)
    133 _C_LABEL(from):
    134 	.long	0
    135 
    136 /*
    137  * After bootblock (LBN0) has been loaded into the first page
    138  * of good memory by 11/750's ROM-code (transfer address
    139  * of bootblock-code is: base of good memory + 0x0C) registers
    140  * are initialized as:
    141  *	R0:	type of boot-device
    142  *			0:	Massbus device
    143  *			1:	RK06/RK07
    144  *			2:	RL02
    145  *			17:	UDA50
    146  *			35:	TK50
    147  *			64:	TU58
    148  *	R1:	(UBA) address of UNIBUS I/O-page
    149  *		(MBA) address of boot device's adapter
    150  *	R2:	(UBA) address of the boot device's CSR
    151  *		(MBA) controller number of boot device
    152  *	R6:	address of driver subroutine in ROM
    153  *
    154  * cont_750 reads in LBN1-15 for further execution.
    155  */
    156 cont_750:
    157 	movl	$_C_LABEL(start), %sp	# move stack to avoid clobbering the code
    158 	pushr	$0x131		# save clobbered registers
    159 	clrl	%r4		# %r4 == # of blocks transferred
    160 	movab	_C_LABEL(start),%r5	# %r5 have base address for next transfer
    161 	pushl	%r5		# ...on stack also (Why?)
    162 1:	incl	%r4		# increment block count
    163 	movl	%r4,%r8		# LBN is in %r8 for rom routine
    164 	addl2	$0x200,%r5	# Increase address for next read
    165 	cmpl	$16,%r4		# read 15 blocks?
    166 	beql	2f		# Yep
    167 	movl	%r5,(%sp)		# move address to stack also
    168 	jsb	(%r6)		# read 512 bytes
    169 	blbs	%r0,1b		# jump if read succeeded
    170 	halt			# otherwise die...
    171 2:	tstl	(%sp)+		# remove boring arg from stack
    172 	popr	$0x131		# restore clobbered registers
    173 	brw	start_all	# Ok, continue...
    174 
    175 /* uVAX main entry is at the start of the second disk block.  This is
    176  * needed for multi-arch CD booting where multiple architecture need
    177  * to shove stuff in boot block 0.
    178  */
    179 	.org	0x200		# uVAX booted from disk starts here
    180 
    181 start_uvax:
    182 	movzbl	$2,_C_LABEL(from)	# Booted from subset-VMB
    183 	brb	start_all
    184 
    185 /*
    186  * start_all: stack already at RELOC, we save registers, move ourself
    187  * to RELOC and loads boot.
    188  */
    189 start_all:
    190 	movl	$_C_LABEL(start), %sp	# move stack to a better
    191 	pushr	$0x1fff			# save all regs, used later.
    192 
    193 	subl3	$_C_LABEL(start), $_C_LABEL(edata), %r0
    194 					# get size of text+data (w/o bss)
    195 	moval	_C_LABEL(start), %r1	# get actual base-address of code
    196 	subl3	$_C_LABEL(start), $_C_LABEL(end), %r2
    197 					# get complete size (incl. bss)
    198 	movl	$_C_LABEL(start), %r3	# get relocated base-address of code
    199 	movc5	%r0, (%r1), $0, %r2, (%r3)	# copy code to new location
    200 
    201 	movpsl	-(%sp)
    202 	movl	$relocated, -(%sp)	# return-address on top of stack
    203 	rei				# can be replaced with new address
    204 relocated:				# now relocation is done !!!
    205 	movl	%sp, _C_LABEL(bootregs)
    206 	calls	$0, _C_LABEL(Xmain)	# call Xmain (gcc workaround)which is
    207 	halt				# not intended to return ...
    208 
    209 /*
    210  * hoppabort() is called when jumping to the newly loaded program.
    211  */
    212 ENTRY(hoppabort, 0)
    213 	movl    4(%ap),%r6
    214 	movl	_C_LABEL(rpb),%r11
    215 	mnegl	$1,%ap		# Hack to figure out boot device.
    216 	movpsl	-(%sp)
    217 	pushab	2(%r6)
    218 	mnegl	$1,_C_LABEL(vax_load_failure)
    219 	rei
    220 #	calls	$0,(%r6)
    221 	halt
    222 
    223 ENTRY(unit_init, R6|R7|R8|R9|R10|R11)
    224 	mfpr	$17,%r7			# Wanted bu KDB
    225 	movl	4(%ap),%r0		# init routine address
    226 	movl	8(%ap),%r9		# RPB in %r9
    227 	movl	12(%ap),%r1		# VMB argument list
    228 	callg	(%r1),(%r0)
    229 	ret
    230 
    231 # A bunch of functions unwanted in boot blocks.
    232 ENTRY(getchar, 0)
    233 	halt
    234 
    235 #ifndef USE_PRINTF
    236 ENTRY(putchar, 0)
    237 	ret
    238 
    239 ENTRY(printf, 0)
    240 	ret
    241 #endif
    242 
    243 ENTRY(panic, 0)
    244 	halt
    245