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