srt0.S revision 1.3
1/*	$NetBSD: srt0.S,v 1.3 2002/11/05 06:16:21 thorpej Exp $ */
2/*
3 * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *     This product includes software developed at Ludd, University of Lule}.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /* All bugs are subject to removal without further notice */
33
34#include "../include/asm.h"
35
36/*
37 * Auto-moving startup code for standalone programs. Can be loaded
38 * (almost) anywhere in memory but moves itself to the position
39 * it is linked for. Must be started at first position, recommended
40 * is phys addr 0 (boot loads programs at 0, but starts them at the
41 * position set in a.out header.
42 */
43
44	.globl	nisse		# pass -e nisse to ld gives OK start addr
45	.set	nisse,0
46
47ALTENTRY(start)
48	nop; nop
49
50	subl3	$_C_LABEL(start), $_C_LABEL(edata), %r0
51	movab	_C_LABEL(start), %r1 # get where we are
52	movl	$_C_LABEL(start), %r3 # get where we want to be
53	cmpl	%r1,%r3		# are we where we want to be?
54	beql	1f		# already relocated, skip copy
55	movc3	%r0,(%r1),(%r3)	# copy
561:
57	subl3	$_C_LABEL(edata), $_C_LABEL(end), %r2
58	movc5	$0,(%r3),$0,%r2,(%r3) # Zero bss
59
60	movl	$_C_LABEL(start), %sp	# set up boot stack
61	pushr	$0x1fff			# save for later usage
62
63	movpsl	-(%sp)
64	pushl	$relocated
65	rei
66relocated:	                # now relocation is done !!!
67	movl	%sp,_C_LABEL(bootregs)	# *bootregs
68	calls	$0, _C_LABEL(Xmain)	# Were here!
69	halt			# no return
70
71ENTRY(machdep_start, 0)
72	calls	$0,_C_LABEL(niclose)	# Evil hack to shutdown DEBNA.
73	mtpr	$0x1f,$0x12	# Block all interrupts
74	mtpr	$0,$0x18	# stop real time interrupt clock
75	movl	4(%ap), %r6
76	movl	20(%ap), %r9	# end of symbol table
77	pushl	8(%ap)		# number of symbols
78	pushl	16(%ap)		# start of symbols
79	movab	_C_LABEL(bootrpb),%r10	# get RPB address
80	pushl	%r10		# argument for new boot
81	ashl	$9,76(%r10),%r8	# memory size (COMPAT)
82	movl	$3,%r11		# ask boot (COMPAT)
83	clrl	%r10		# no boot dev (COMPAT)
84
85	calls	$3,(%r6)
86	halt
87