1/*        $NetBSD: srt0.S,v 1.6 2018/03/19 15:37:56 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
521:        movb      (%r1)+,(%r3)+       # copy
53          sobgtr    %r0,1b
54
55          subl3     $_C_LABEL(edata), $_C_LABEL(end), %r2
56          movc5     $0,(%r3),$0,%r2,(%r3) # Zero bss
57
58          movpsl    -(%sp)
59          pushl     $relocated
60          rei
61relocated:                          # now relocation is done !!!
62          movl      %sp,_C_LABEL(bootregs)        # *bootregs
63          calls     $0, _C_LABEL(Xmain) # Were here!
64          halt                          # no return
65
66ENTRY(machdep_start, 0)
67          calls     $0,_C_LABEL(niclose)          # Evil hack to shutdown DEBNA.
68          mtpr      $0x1f,$0x12         # Block all interrupts
69          mtpr      $0,$0x18  # stop real time interrupt clock
70          movl      4(%ap), %r6
71          movl      20(%ap), %r9        # end of symbol table
72          pushl     8(%ap)              # number of symbols
73          pushl     16(%ap)             # start of symbols
74          movab     _C_LABEL(bootrpb),%r10        # get RPB address
75          pushl     %r10                # argument for new boot
76          ashl      $9,76(%r10),%r8     # memory size (COMPAT)
77          movl      $3,%r11             # ask boot (COMPAT)
78          clrl      %r10                # no boot dev (COMPAT)
79
80          calls     $3,(%r6)
81          halt
82