srt0.S revision 1.6
11.6Sragge/*	$NetBSD: srt0.S,v 1.6 2018/03/19 15:37:56 ragge 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 *
151.1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161.1Smatt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171.1Smatt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181.1Smatt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191.1Smatt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201.1Smatt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211.1Smatt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221.1Smatt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231.1Smatt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241.1Smatt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251.1Smatt */
261.1Smatt
271.1Smatt /* All bugs are subject to removal without further notice */
281.1Smatt
291.1Smatt#include "../include/asm.h"
301.1Smatt
311.1Smatt/*
321.1Smatt * Auto-moving startup code for standalone programs. Can be loaded
331.1Smatt * (almost) anywhere in memory but moves itself to the position
341.1Smatt * it is linked for. Must be started at first position, recommended
351.1Smatt * is phys addr 0 (boot loads programs at 0, but starts them at the
361.1Smatt * position set in a.out header.
371.1Smatt */
381.1Smatt
391.1Smatt	.globl	nisse		# pass -e nisse to ld gives OK start addr
401.1Smatt	.set	nisse,0
411.1Smatt
421.1SmattALTENTRY(start)
431.4Sragge	nop;nop;
441.4Sragge	movl	$_C_LABEL(start), %sp	# Probably safe place for stack
451.4Sragge	pushr	$0x1fff		# save for later usage
461.1Smatt
471.1Smatt	subl3	$_C_LABEL(start), $_C_LABEL(edata), %r0
481.1Smatt	movab	_C_LABEL(start), %r1 # get where we are
491.1Smatt	movl	$_C_LABEL(start), %r3 # get where we want to be
501.1Smatt	cmpl	%r1,%r3		# are we where we want to be?
511.4Sragge	beql	relocated	# already relocated, skip copy
521.6Sragge1:	movb	(%r1)+,(%r3)+	# copy
531.6Sragge	sobgtr	%r0,1b
541.6Sragge
551.1Smatt	subl3	$_C_LABEL(edata), $_C_LABEL(end), %r2
561.1Smatt	movc5	$0,(%r3),$0,%r2,(%r3) # Zero bss
571.1Smatt
581.1Smatt	movpsl	-(%sp)
591.1Smatt	pushl	$relocated
601.1Smatt	rei
611.1Smattrelocated:	                # now relocation is done !!!
621.1Smatt	movl	%sp,_C_LABEL(bootregs)	# *bootregs
631.1Smatt	calls	$0, _C_LABEL(Xmain)	# Were here!
641.1Smatt	halt			# no return
651.1Smatt
661.1SmattENTRY(machdep_start, 0)
671.1Smatt	calls	$0,_C_LABEL(niclose)	# Evil hack to shutdown DEBNA.
681.1Smatt	mtpr	$0x1f,$0x12	# Block all interrupts
691.1Smatt	mtpr	$0,$0x18	# stop real time interrupt clock
701.1Smatt	movl	4(%ap), %r6
711.1Smatt	movl	20(%ap), %r9	# end of symbol table
721.1Smatt	pushl	8(%ap)		# number of symbols
731.2Smatt	pushl	16(%ap)		# start of symbols
741.1Smatt	movab	_C_LABEL(bootrpb),%r10	# get RPB address
751.1Smatt	pushl	%r10		# argument for new boot
761.1Smatt	ashl	$9,76(%r10),%r8	# memory size (COMPAT)
771.1Smatt	movl	$3,%r11		# ask boot (COMPAT)
781.1Smatt	clrl	%r10		# no boot dev (COMPAT)
791.1Smatt
801.1Smatt	calls	$3,(%r6)
811.1Smatt	halt
82