bbstart.s revision 1.8 1 /* $NetBSD: bbstart.s,v 1.8 2001/03/02 16:43:26 mhitch Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <machine/asm.h>
40 #include "aout2bb.h"
41
42 #define LVOAllocMem -0x0c6
43 #define LVODoIO -0x1c8
44 #define LVOCacheClearU -0x27c
45
46 #define IOcmd 28
47 #define IOerr 31
48 #define IOlen 36
49 #define IObuf 40
50 #define IOoff 44
51
52 #define Cmd_Rd 2
53
54 .text
55 Lzero: .asciz "DOS" | "DOS type"
56 /*
57 * We put the relocator version here, for aout2bb, which replaces
58 * it with the bootblock checksum.
59 */
60 Chksum: .long RELVER_RELATIVE_BYTES_FORWARD
61 Filesz: .long 8192 | dummy
62
63 /*
64 * Entry point from Kickstart.
65 * A1 points to an IOrequest, A6 points to ExecBase, we have a stack.
66 * _must_ be at offset 12.
67 */
68 ENTRY_NOPROFILE(start)
69 #ifdef AUTOLOAD
70 jra Lautoload
71 #else
72 jra Lrelocate
73 #endif
74
75 Lreltab:
76 .word 0 | aout2bb puts the reloc table address here
77
78 #ifdef AUTOLOAD
79 /*
80 * autoload
81 */
82 Lautoload:
83 movl %a6,%sp@- |SysBase
84 movl %a1,%sp@- |IORequest
85
86 movl #AUTOLOAD,%d0 |Howmuch
87 movl %d0,%a1@(IOlen) | for the actual read...
88 movl #0x10001,%d1 |MEMF_CLEAR|MEMF_PUBLIC
89 jsr %a6@(LVOAllocMem)
90 movl %sp@+,%a1 |IORequest
91 movl %sp@+,%a6 |SysBase
92 orl %d0,%d0
93 jne Lgotmem
94 movql #1,%d0
95 rts
96
97 Lgotmem:
98 movl %d0,%sp@- |Address
99 movl %a1@(IOoff),%sp@- |Old offset
100 movl %a1,%sp@-
101 movl %a6,%sp@-
102
103 /* we've set IOlen above */
104 movl %d0,%a1@(IObuf)
105 movw #Cmd_Rd,%a1@(IOcmd)
106 jsr %a6@(LVODoIO)
107
108 movl %sp@+,%a6
109 movl %sp@+,%a1
110 movl %sp@+,%a1@(IOoff)
111
112 tstb %a1@(IOerr)
113 jne Lioerr
114 addl #Lrelocate-Lzero,%sp@
115
116 movl %a6,%sp@-
117 jsr %a6@(LVOCacheClearU)
118 movl %sp@+,%a6
119 rts
120 Lioerr:
121 movql #1,%d0
122 addql #4,%sp
123 rts
124 #endif
125
126 /*
127 * Relocate ourselves, at the same time clearing the relocation table
128 * (in case it overlaps with BSS).
129 *
130 * Register usage:
131 * A2: points into the reloc table, located at our end.
132 * A0: pointer to the longword to relocate.
133 * D0: word offset of longword to relocate
134 * D1: points to our start.
135 *
136 * Table has relative byte offsets, if a byte offset is zero, it is
137 * followed by an absolute word offset. If this is zero, too, table
138 * end is reached.
139 */
140
141 Lrelocate:
142 lea %pc@(Lzero),%a0
143 movl %a0,%d1
144 movw %pc@(Lreltab),%a2
145 addl %d1,%a2
146 jra Loopend
147
148 Loopw:
149 clrw %a2@+
150 movl %d1,%a0 | for a variant with relative words, erase this line
151 Loopb:
152 addl %d0,%a0
153 addl %d1,%a0@
154 Loopend:
155 movq #0,%d0
156 movb %a2@,%d0
157 clrb %a2@+ | bfclr %a2@+{0:8} is still two shorts
158 tstb %d0 | we could save one short by using casb %d0,d0,%a2@+
159 jne Loopb
160
161 movw %a2@,%d0
162 jne Loopw
163
164 Lendtab:
165 movl %a6,%sp@-
166 jsr %a6@(LVOCacheClearU)
167 movl %sp@+,%a6
168
169 /* We are relocated. Now it is safe to initialize _SysBase: */
170
171 movl %a6,_C_LABEL(SysBase)
172
173 movl %a1,%sp@-
174 bsr _C_LABEL(pain)
175
176 Lerr:
177 movq #1,%d0
178 rts
179
180 .comm _C_LABEL(SysBase),4
181