1 /* $NetBSD: sdb00t.ahdi.S,v 1.4 2025/11/19 09:43:28 nia 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. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "xxboot.h" 31 32 .globl _start, main, fill 33 34 .text 35 36 _start: bras main 37 bra rds0 38 39 main: bclr #2,(_drvbits+3):w 40 clrl pun_ptr:w 41 movml %d3/%d5,%sp@- 42 movw #-1,%sp@- 43 movw #Kbshift,%sp@- 44 trap #BIOS 45 addql #4,%sp 46 btst #3,%d0 | Alternate? 47 bnes exit 48 movq #3,%d0 49 lea %pc@(p0_dsc),%a0 50 cmpl #0x444d4172,%d3 | SCSI bootdev? 51 beqs 0f 52 movq #-1,%d4 | no, ACSI 53 movq #0,%d5 54 0: movb %d5,%d1 | NVRAM bootpref 55 bnes 1f 56 57 | The Hades bios does not provide a bootprev. In case 58 | of doubt, we fetch it ourselves. 59 moveml %d0-%d2/%a0-%a2,%sp@- 60 pea bpref 61 movw #1, %sp@- 62 movw #1, %sp@- 63 movw #0, %sp@- 64 movw #NVMaccess, %sp@- 65 trap #XBIOS 66 lea %sp@(12),%sp 67 moveml %sp@+,%d0-%d2/%a0-%a2 68 movb bpref:w,%d1 69 bnes 1f 70 movq #-8,%d1 | bootpref = any 71 72 1: movb %a0@,%d2 | bootflags 73 btst #0,%d2 74 beqs 2f 75 andb %d1,%d2 76 bnes boot 77 2: lea %a0@(12),%a0 78 dbra %d0,1b 79 80 exit: movml %sp@+,%d3/%d5 81 tostst: clrw _bootdev:w 82 movl _sysbase:w,%a0 83 movl %a0@(24),%d0 84 swap %d0 85 cmpl #0x19870422,%d0 | old TOS? 86 bccs 0f | no 87 movw #0xe0,%d7 88 0: rts 89 90 boot: movl %a0@(4),%d6 91 movq #1,%d5 92 lea %pc@(end),%a4 93 bsrs rds0 94 tstw %d0 95 bnes exit 96 movl %a4,%a0 97 movw #0xff,%d0 98 movq #0,%d1 99 0: addw %a0@+,%d1 100 dbra %d0,0b 101 cmpw #0x1234,%d1 102 bnes exit 103 lea %pc@(rds0),%a3 104 lea %pc@(tostst),%a5 105 movml %sp@+,%d3/%d5 106 jmp %a4@ | start bootsector code 107 /* 108 * in: d4/d7 (target) d5 (count), d6 (offset), a4 (buffer) 109 * out: d0 (<= 0) 110 * mod: d0, d1, d2, a0, a1, a5, a6 111 */ 112 rds0: tstl %d4 113 bmis 0f 114 movw %d4,%sp@- | device 115 pea %a4@ | buffer 116 movw %d5,%sp@- | count 117 movl %d6,%sp@- | offset 118 movw #DMAread,%sp@- 119 trap #XBIOS 120 lea %sp@(14),%sp 121 rts 122 123 0: st flock:w 124 movl _hz_200:w,%d0 125 addql #2,%d0 126 1: cmpl _hz_200:w,%d0 127 bccs 1b 128 movml %d6/%a4,%sp@- 129 lea dmahi:w,%a6 130 movb %sp@(7),%a6@(4) 131 movb %sp@(6),%a6@(2) 132 movb %sp@(5),%a6@ 133 lea %pc@(r0com),%a6 134 movb %sp@(1),%a6@(1) 135 movb %sp@(2),%a6@(5) 136 movb %sp@(3),%a6@(9) 137 movb %d5,%a6@(13) 138 addql #8,%sp 139 lea dmodus:w,%a6 140 lea daccess:w,%a5 141 movw #0x198,%a6@ 142 movw #0x098,%a6@ 143 movw %d5,%a5@ 144 movw #0x88,%a6@ 145 movq #0,%d0 146 movb %d7,%d0 147 orb #0x08,%d0 148 swap %d0 149 movw #0x8a,%d0 150 bsrs shake 151 lea %pc@(r0com),%a0 152 movq #3,%d2 153 2: movl %a0@+,%d0 154 bsrs shake 155 dbra %d2,2b 156 movq #0x0a,%d0 157 movl %d0,%a5@ 158 movl #0x190,%d1 159 bsrs wait 160 movw #0x8a,%a6@ 161 movw %a5@,%d0 162 andw #0xff,%d0 163 beqs 0f 164 r0err: movq #-1,%d0 165 0: movw #0x80,%a6@ 166 clrb flock:w 167 r0ret: rts 168 169 shake: movl %d0,%a5@ 170 movq #0x0a,%d1 171 wait: addl _hz_200:w,%d1 172 0: btst #5,gpip:w 173 beqs r0ret 174 cmpl _hz_200:w,%d1 175 bccs 0b 176 addql #4,%sp 177 bras r0err 178 179 r0com: .long 0x0000008a 180 .long 0x0000008a 181 .long 0x0000008a 182 .long 0x0001008a 183 bpref: .word 0 184 185 fill: .space 16 186 187 .ascii "NetBSD" 188 hd_siz: .long 0 189 p0_dsc: .long 0, 0, 0 190 p1_dsc: .long 0, 0, 0 191 p2_dsc: .long 0, 0, 0 192 p3_dsc: .long 0, 0, 0 193 bsl_st: .long 0 194 bsl_sz: .long 0 195 .word 0 196 end: 197