wdb00t.ahdi.S revision 1.3 1 /* $NetBSD: wdb00t.ahdi.S,v 1.3 2022/06/26 14:14:46 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1995 Waldi Ravens
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Waldi Ravens.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "xxboot.h"
34
35 .globl _start, main, fill
36
37 .text
38
39 _start: bras main
40 bra rds0
41
42 main: bclr #2,(_drvbits+3):w
43 clrl pun_ptr:w
44 movml %d3/%d5,%sp@-
45 movw #-1,%sp@-
46 movw #Kbshift,%sp@-
47 trap #BIOS
48 addql #4,%sp
49 btst #3,%d0 | Alternate?
50 bnes exit
51 movq #3,%d0
52 lea %pc@(p0_dsc),%a0
53 movb %d5,%d1 | NVRAM bootpref
54 bnes 0f
55
56 | The Hades bios does not provide a bootprev. In case
57 | of doubt, we fetch it ourselves.
58 movb #BOOTPREF,rtcrnr:w
59 movb rtcdat:w,%d1
60 bnes 0f
61 movq #-8,%d1 | bootpref = any
62
63 0: movb %a0@,%d2 | bootflags
64 btst #0,%d2
65 beqs 1f
66 andb %d1,%d2
67 bnes boot
68 1: lea %a0@(12),%a0
69 dbra %d0,0b
70
71 exit: movml %sp@+,%d3/%d5
72 tostst: clrw _bootdev:w
73 movl _sysbase:w,%a0
74 movl %a0@(24),%d0
75 swap %d0
76 cmpl #0x19870422,%d0 | old TOS?
77 bccs 0f | no
78 movw #0xe0,%d7
79 0: rts
80
81 boot: movl %a0@(4),%d6
82 movq #1,%d5
83 lea %pc@(end),%a4
84 bsrs rds0
85 tstw %d0
86 bnes exit
87 movl %a4,%a0
88 movw #0xff,%d0
89 movq #0,%d1
90 0: addw %a0@+,%d1
91 dbra %d0,0b
92 cmpw #0x1234,%d1
93 bnes exit
94 lea %pc@(rds0),%a3
95 lea %pc@(tostst),%a5
96 movml %sp@+,%d3/%d5
97 jmp %a4@ | start bootsector code
98 /*
99 * in: d4 (target) d5 (count), d6 (offset), a4 (buffer)
100 * out: d0 (<= 0)
101 * mod: d0, d1, d2, a0, a1, a5, a6
102 */
103 rds0: lea %pc@(dpar),%a6
104 tstb %a6@
105 bnes 0f
106 movb %d4,%d0
107 andb #1,%d0
108 aslb #4,%d0
109 orb #0xa0,%d0
110 movb %d0,idesdh:l
111 movl %a4,%a0
112 movq #0,%d1
113 movb #0,idedor:l
114 movb #0xec,idecr:l | IDENTIFY DRIVE
115 bsrs wait
116 bnes err
117 movb %a4@(7),%a6@ | tracks/cylinder
118 movb %a4@(13),%a6@(1) | sectors/track
119 0: movl %d6,%d1
120 movq #0,%d0
121 movb %a6@(1),%d0
122 movq #0,%d2
123 movb %a6@,%d2
124 mulu %d0,%d2
125 divu %d2,%d1
126 movb %d1,idecl:l
127 lsrl #8,%d1
128 movb %d1,idech:l
129 lsrl #8,%d1
130 divu %d0,%d1
131 movb %d4,%d0
132 andb #1,%d0
133 aslb #4,%d0
134 orb %d0,%d1
135 orb #0xa0,%d1
136 movb %d1,idesdh:l
137 swap %d1
138 addqw #1,%d1
139 movb %d1,idesn:l
140 movl %a4,%a0
141 movb %d5,idesc:l
142 movw %d5,%d1
143 subqw #1,%d1
144 movb #0,idedor:l
145 movb #0x20,idecr:l
146 wait: movl #0x7d0,%d0
147 addl _hz_200:w,%d0
148 2: btst #5,gpip:w
149 beqs 3f
150 cmpl _hz_200:w,%d0
151 bhis 2b
152 err: movq #-1,%d0
153 rts
154 3: movb idesr:l,%d0
155 btst #0,%d0
156 bnes err
157 btst #3,%d0
158 beqs err
159 movq #63,%d0
160 lea idedr:l,%a1
161 4: movw %a1@,%a0@+
162 movw %a1@,%a0@+
163 movw %a1@,%a0@+
164 movw %a1@,%a0@+
165 dbra %d0,4b
166 dbra %d1,wait
167 movq #0,%d0
168 rts
169
170 fill: .space 52
171
172 dpar: .byte 0 | tracks/cylinder
173 .byte 0 | sectors/track
174 .ascii "NetBSD"
175 hd_siz: .long 0
176 p0_dsc: .long 0, 0, 0
177 p1_dsc: .long 0, 0, 0
178 p2_dsc: .long 0, 0, 0
179 p3_dsc: .long 0, 0, 0
180 bsl_st: .long 0
181 bsl_sz: .long 0
182 .word 0
183 end:
184