srt0.S revision 1.3
11.3Sthorpej/*	$NetBSD: srt0.S,v 1.3 2002/11/05 06:16:21 thorpej Exp $ */
21.1Smatt/*
31.1Smatt * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
41.1Smatt * All rights reserved.
51.1Smatt *
61.1Smatt * Redistribution and use in source and binary forms, with or without
71.1Smatt * modification, are permitted provided that the following conditions
81.1Smatt * are met:
91.1Smatt * 1. Redistributions of source code must retain the above copyright
101.1Smatt *    notice, this list of conditions and the following disclaimer.
111.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
121.1Smatt *    notice, this list of conditions and the following disclaimer in the
131.1Smatt *    documentation and/or other materials provided with the distribution.
141.1Smatt * 3. All advertising materials mentioning features or use of this software
151.1Smatt *    must display the following acknowledgement:
161.1Smatt *     This product includes software developed at Ludd, University of Lule}.
171.1Smatt * 4. The name of the author may not be used to endorse or promote products
181.1Smatt *    derived from this software without specific prior written permission
191.1Smatt *
201.1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
211.1Smatt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221.1Smatt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
231.1Smatt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
241.1Smatt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
251.1Smatt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
261.1Smatt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
271.1Smatt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
281.1Smatt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
291.1Smatt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
301.1Smatt */
311.1Smatt
321.1Smatt /* All bugs are subject to removal without further notice */
331.1Smatt
341.1Smatt#include "../include/asm.h"
351.1Smatt
361.1Smatt/*
371.1Smatt * Auto-moving startup code for standalone programs. Can be loaded
381.1Smatt * (almost) anywhere in memory but moves itself to the position
391.1Smatt * it is linked for. Must be started at first position, recommended
401.1Smatt * is phys addr 0 (boot loads programs at 0, but starts them at the
411.1Smatt * position set in a.out header.
421.1Smatt */
431.1Smatt
441.1Smatt	.globl	nisse		# pass -e nisse to ld gives OK start addr
451.1Smatt	.set	nisse,0
461.1Smatt
471.1SmattALTENTRY(start)
481.3Sthorpej	nop; nop
491.1Smatt
501.1Smatt	subl3	$_C_LABEL(start), $_C_LABEL(edata), %r0
511.1Smatt	movab	_C_LABEL(start), %r1 # get where we are
521.1Smatt	movl	$_C_LABEL(start), %r3 # get where we want to be
531.1Smatt	cmpl	%r1,%r3		# are we where we want to be?
541.3Sthorpej	beql	1f		# already relocated, skip copy
551.1Smatt	movc3	%r0,(%r1),(%r3)	# copy
561.3Sthorpej1:
571.1Smatt	subl3	$_C_LABEL(edata), $_C_LABEL(end), %r2
581.1Smatt	movc5	$0,(%r3),$0,%r2,(%r3) # Zero bss
591.3Sthorpej
601.3Sthorpej	movl	$_C_LABEL(start), %sp	# set up boot stack
611.3Sthorpej	pushr	$0x1fff			# save for later usage
621.1Smatt
631.1Smatt	movpsl	-(%sp)
641.1Smatt	pushl	$relocated
651.1Smatt	rei
661.1Smattrelocated:	                # now relocation is done !!!
671.1Smatt	movl	%sp,_C_LABEL(bootregs)	# *bootregs
681.1Smatt	calls	$0, _C_LABEL(Xmain)	# Were here!
691.1Smatt	halt			# no return
701.1Smatt
711.1SmattENTRY(machdep_start, 0)
721.1Smatt	calls	$0,_C_LABEL(niclose)	# Evil hack to shutdown DEBNA.
731.1Smatt	mtpr	$0x1f,$0x12	# Block all interrupts
741.1Smatt	mtpr	$0,$0x18	# stop real time interrupt clock
751.1Smatt	movl	4(%ap), %r6
761.1Smatt	movl	20(%ap), %r9	# end of symbol table
771.1Smatt	pushl	8(%ap)		# number of symbols
781.2Smatt	pushl	16(%ap)		# start of symbols
791.1Smatt	movab	_C_LABEL(bootrpb),%r10	# get RPB address
801.1Smatt	pushl	%r10		# argument for new boot
811.1Smatt	ashl	$9,76(%r10),%r8	# memory size (COMPAT)
821.1Smatt	movl	$3,%r11		# ask boot (COMPAT)
831.1Smatt	clrl	%r10		# no boot dev (COMPAT)
841.1Smatt
851.1Smatt	calls	$3,(%r6)
861.1Smatt	halt
87