srt0.S revision 1.2
11.2Smatt/*	$NetBSD: srt0.S,v 1.2 2002/03/31 00:11:14 matt 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.1Smatt	nop;nop;
491.1Smatt	movl	$_C_LABEL(start), %sp	# Probably safe place for stack
501.1Smatt	pushr	$0x1fff		# save for later usage
511.1Smatt
521.1Smatt	subl3	$_C_LABEL(start), $_C_LABEL(edata), %r0
531.1Smatt	movab	_C_LABEL(start), %r1 # get where we are
541.1Smatt	movl	$_C_LABEL(start), %r3 # get where we want to be
551.1Smatt	cmpl	%r1,%r3		# are we where we want to be?
561.1Smatt	beql	relocated	# already relocated, skip copy
571.1Smatt	movc3	%r0,(%r1),(%r3)	# copy
581.1Smatt	subl3	$_C_LABEL(edata), $_C_LABEL(end), %r2
591.1Smatt	movc5	$0,(%r3),$0,%r2,(%r3) # Zero bss
601.1Smatt
611.1Smatt	movpsl	-(%sp)
621.1Smatt	pushl	$relocated
631.1Smatt	rei
641.1Smattrelocated:	                # now relocation is done !!!
651.1Smatt	movl	%sp,_C_LABEL(bootregs)	# *bootregs
661.1Smatt	calls	$0, _C_LABEL(Xmain)	# Were here!
671.1Smatt	halt			# no return
681.1Smatt
691.1SmattENTRY(machdep_start, 0)
701.1Smatt	calls	$0,_C_LABEL(niclose)	# Evil hack to shutdown DEBNA.
711.1Smatt	mtpr	$0x1f,$0x12	# Block all interrupts
721.1Smatt	mtpr	$0,$0x18	# stop real time interrupt clock
731.1Smatt	movl	4(%ap), %r6
741.1Smatt	movl	20(%ap), %r9	# end of symbol table
751.1Smatt	pushl	8(%ap)		# number of symbols
761.2Smatt	pushl	16(%ap)		# start of symbols
771.1Smatt	movab	_C_LABEL(bootrpb),%r10	# get RPB address
781.1Smatt	pushl	%r10		# argument for new boot
791.1Smatt	ashl	$9,76(%r10),%r8	# memory size (COMPAT)
801.1Smatt	movl	$3,%r11		# ask boot (COMPAT)
811.1Smatt	clrl	%r10		# no boot dev (COMPAT)
821.1Smatt
831.1Smatt	calls	$3,(%r6)
841.1Smatt	halt
85