bbstart.s revision 1.4 1 /* $NetBSD: bbstart.s,v 1.4 1999/02/16 22:46:56 is Exp $ */
2
3 /*-
4 * Copyright (c) 1999 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 "aout2bb.h"
40
41 #define LVOAllocMem -0x0c6
42 #define LVODoIO -0x1c8
43 #define LVOCacheClearU -0x27c
44
45 #define IOcmd 28
46 #define IOerr 31
47 #define IOlen 36
48 #define IObuf 40
49 #define IOoff 44
50
51 #define Cmd_Rd 2
52
53 .globl _pain
54
55 .text
56 Lzero: .asciz "DOS" | "DOS type"
57 /*
58 * We put the relocator version here, for aout2bb, which replaces
59 * it with the bootblock checksum.
60 */
61 Chksum: .long RELVER_RELATIVE_BYTES_FORWARD
62 Filesz: .long 8192 | dummy
63
64 /*
65 * Entry point from Kickstart.
66 * A1 points to an IOrequest, A6 points to ExecBase, we have a stack.
67 * _must_ be at offset 12.
68 */
69 .globl _start
70 _start:
71 #ifdef AUTOLOAD
72 jra Lautoload
73 #else
74 jra Lrelocate
75 #endif
76
77 Lreltab:
78 .word 0 | aout2bb puts the reloc table address here
79
80 #ifdef AUTOLOAD
81 /*
82 * autoload
83 */
84 Lautoload:
85 movl a6,sp@- |SysBase
86 movl a1,sp@- |IORequest
87
88 movl #AUTOLOAD,d0 |Howmuch
89 movl d0,a1@(IOlen) | for the actual read...
90 movl #0x10001,d1 |MEMF_CLEAR|MEMF_PUBLIC
91 jsr a6@(LVOAllocMem)
92 movl sp@+,a1 |IORequest
93 movl sp@+,a6 |SysBase
94 orl d0,d0
95 jne Lgotmem
96 movql #1,d0
97 rts
98
99 Lgotmem:
100 movl d0,sp@- |Address
101 movl a1@(IOoff),sp@- |Old offset
102 movl a1,sp@-
103 movl a6,sp@-
104
105 /* we've set IOlen above */
106 movl d0,a1@(IObuf)
107 movw #Cmd_Rd,a1@(IOcmd)
108 jsr a6@(LVODoIO)
109
110 movl sp@+,a6
111 movl sp@+,a1
112 movl sp@+,a1@(IOoff)
113
114 tstb a1@(IOerr)
115 jne Lioerr
116 addl #Lrelocate-Lzero,sp@
117
118 movl a6,sp@-
119 jsr a6@(LVOCacheClearU)
120 movl sp@+,a6
121 rts
122 Lioerr:
123 movql #1,d0
124 addql #4,sp
125 rts
126 #endif
127
128 /*
129 * Relocate ourselves, at the same time clearing the relocation table
130 * (in case it overlaps with BSS).
131 *
132 * Register usage:
133 * A2: points into the reloc table, located at our end.
134 * A0: pointer to the longword to relocate.
135 * D0: word offset of longword to relocate
136 * D1: points to our start.
137 *
138 * Table has relative byte offsets, if a byte offset is zero, it is
139 * followed by an absolute word offset. If this is zero, too, table
140 * end is reached.
141 */
142
143 Lrelocate:
144 lea pc@(Lzero),a0
145 movl a0,d1
146 movw pc@(Lreltab),a2
147 addl d1,a2
148 jra Loopend
149
150 Loopw:
151 clrw a2@+
152 movl d1,a0 | for a variant with relative words, erase this line
153 Loopb:
154 addl d0,a0
155 addl d1,a0@
156 Loopend:
157 movq #0,d0
158 movb a2@,d0
159 clrb a2@+ | bfclr a2@+{0:8} is still two shorts
160 tstb d0 | we could save one short by using casb d0,d0,a2@+
161 jne Loopb
162
163 movw a2@,d0
164 jne Loopw
165
166 Lendtab:
167 movl a6,sp@-
168 jsr a6@(LVOCacheClearU)
169 movl sp@+,a6
170
171 /* We are relocated. Now it is safe to initialize _SysBase: */
172
173 movl a6,_SysBase
174
175 movl a1,sp@-
176 bsr _pain
177
178 Lerr:
179 movq #1,d0
180 rts
181
182 .comm _SysBase,4
183