xref: /netbsd-src/sys/arch/vax/boot/common/srt0.S (revision 1580a27b92f58fcdcb23fdfbc04a7c2b54a0b7c8)
1/*	$NetBSD: srt0.S,v 1.5 2017/05/22 17:00:19 ragge 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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /* All bugs are subject to removal without further notice */
28
29#include "../include/asm.h"
30
31/*
32 * Auto-moving startup code for standalone programs. Can be loaded
33 * (almost) anywhere in memory but moves itself to the position
34 * it is linked for. Must be started at first position, recommended
35 * is phys addr 0 (boot loads programs at 0, but starts them at the
36 * position set in a.out header.
37 */
38
39	.globl	nisse		# pass -e nisse to ld gives OK start addr
40	.set	nisse,0
41
42ALTENTRY(start)
43	nop;nop;
44	movl	$_C_LABEL(start), %sp	# Probably safe place for stack
45	pushr	$0x1fff		# save for later usage
46
47	subl3	$_C_LABEL(start), $_C_LABEL(edata), %r0
48	movab	_C_LABEL(start), %r1 # get where we are
49	movl	$_C_LABEL(start), %r3 # get where we want to be
50	cmpl	%r1,%r3		# are we where we want to be?
51	beql	relocated	# already relocated, skip copy
52	movc3	%r0,(%r1),(%r3)	# copy
53	subl3	$_C_LABEL(edata), $_C_LABEL(end), %r2
54	movc5	$0,(%r3),$0,%r2,(%r3) # Zero bss
55
56	movpsl	-(%sp)
57	pushl	$relocated
58	rei
59relocated:	                # now relocation is done !!!
60	movl	%sp,_C_LABEL(bootregs)	# *bootregs
61	calls	$0, _C_LABEL(Xmain)	# Were here!
62	halt			# no return
63
64ENTRY(machdep_start, 0)
65	calls	$0,_C_LABEL(niclose)	# Evil hack to shutdown DEBNA.
66	mtpr	$0x1f,$0x12	# Block all interrupts
67	mtpr	$0,$0x18	# stop real time interrupt clock
68	movl	4(%ap), %r6
69	movl	20(%ap), %r9	# end of symbol table
70	pushl	8(%ap)		# number of symbols
71	pushl	16(%ap)		# start of symbols
72	movab	_C_LABEL(bootrpb),%r10	# get RPB address
73	pushl	%r10		# argument for new boot
74	ashl	$9,76(%r10),%r8	# memory size (COMPAT)
75	movl	$3,%r11		# ask boot (COMPAT)
76	clrl	%r10		# no boot dev (COMPAT)
77
78	calls	$3,(%r6)
79	halt
80