1/* $NetBSD: wdb00t.ahdi.S,v 1.1.4.3 2004/09/21 13:14:11 skrll 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#ifdef __ELF__ 36 .globl _start, main, fill 37 38 .text 39 40_start: bras main 41#else 42 .globl start, main, fill 43 44 .text 45 46start: bras main 47#endif 48 bra rds0 49 50main: bclr #2,(_drvbits+3):w 51 clrl pun_ptr:w 52 movml %d3/%d5,%sp@- 53 movw #-1,%sp@- 54 movw #Kbshift,%sp@- 55 trap #BIOS 56 addql #4,%sp 57 btst #3,%d0 | Alternate? 58 bnes exit 59 movq #3,%d0 60 lea %pc@(p0_dsc),%a0 61 movb %d5,%d1 | NVRAM bootpref 62 bnes 0f 63 64 | The Hades bios does not provide a bootprev. In case 65 | of doubt, we fetch it ourselves. 66 movb #BOOTPREF,rtcrnr:w 67 movb rtcdat:w,%d1 68 bnes 0f 69 movq #-8,%d1 | bootpref = any 70 710: movb %a0@,%d2 | bootflags 72 btst #0,%d2 73 beqs 1f 74 andb %d1,%d2 75 bnes boot 761: lea %a0@(12),%a0 77 dbra %d0,0b 78 79exit: movml %sp@+,%d3/%d5 80tostst: clrw _bootdev:w 81 movl _sysbase:w,%a0 82 movl %a0@(24),%d0 83 swap %d0 84 cmpl #0x19870422,%d0 | old TOS? 85 bccs 0f | no 86 movw #0xe0,%d7 870: rts 88 89boot: movl %a0@(4),%d6 90 movq #1,%d5 91 lea %pc@(end),%a4 92 bsrs rds0 93 tstw %d0 94 bnes exit 95 movl %a4,%a0 96 movw #0xff,%d0 97 movq #0,%d1 980: addw %a0@+,%d1 99 dbra %d0,0b 100 cmpw #0x1234,%d1 101 bnes exit 102 lea %pc@(rds0),%a3 103 lea %pc@(tostst),%a5 104 movml %sp@+,%d3/%d5 105 jmp %a4@ | start bootsector code 106/* 107 * in: d4 (target) d5 (count), d6 (offset), a4 (buffer) 108 * out: d0 (<= 0) 109 * mod: d0, d1, d2, a0, a1, a5, a6 110 */ 111rds0: lea %pc@(dpar),%a6 112 tstb %a6@ 113 bnes 0f 114 movb %d4,%d0 115 andb #1,%d0 116 aslb #4,%d0 117 orb #0xa0,%d0 118 movb %d0,idesdh:l 119 movl %a4,%a0 120 movq #0,%d1 121 movb #0,idedor:l 122 movb #0xec,idecr:l | IDENTIFY DRIVE 123 bsrs wait 124 bnes err 125 movb %a4@(7),%a6@ | tracks/cylinder 126 movb %a4@(13),%a6@(1) | sectors/track 1270: movl %d6,%d1 128 movq #0,%d0 129 movb %a6@(1),%d0 130 movq #0,%d2 131 movb %a6@,%d2 132 mulu %d0,%d2 133 divu %d2,%d1 134 movb %d1,idecl:l 135 lsrl #8,%d1 136 movb %d1,idech:l 137 lsrl #8,%d1 138 divu %d0,%d1 139 movb %d4,%d0 140 andb #1,%d0 141 aslb #4,%d0 142 orb %d0,%d1 143 orb #0xa0,%d1 144 movb %d1,idesdh:l 145 swap %d1 146 addqw #1,%d1 147 movb %d1,idesn:l 148 movl %a4,%a0 149 movb %d5,idesc:l 150 movw %d5,%d1 151 subqw #1,%d1 152 movb #0,idedor:l 153 movb #0x20,idecr:l 154wait: movl #0x7d0,%d0 155 addl _hz_200:w,%d0 1562: btst #5,gpip:w 157 beqs 3f 158 cmpl _hz_200:w,%d0 159 bhis 2b 160err: movq #-1,%d0 161 rts 1623: movb idesr:l,%d0 163 btst #0,%d0 164 bnes err 165 btst #3,%d0 166 beqs err 167 movq #63,%d0 168 lea idedr:l,%a1 1694: movw %a1@,%a0@+ 170 movw %a1@,%a0@+ 171 movw %a1@,%a0@+ 172 movw %a1@,%a0@+ 173 dbra %d0,4b 174 dbra %d1,wait 175 movq #0,%d0 176 rts 177 178fill: .space 52 179 180dpar: .byte 0 | tracks/cylinder 181 .byte 0 | sectors/track 182 .ascii "NetBSD" 183hd_siz: .long 0 184p0_dsc: .long 0, 0, 0 185p1_dsc: .long 0, 0, 0 186p2_dsc: .long 0, 0, 0 187p3_dsc: .long 0, 0, 0 188bsl_st: .long 0 189bsl_sz: .long 0 190 .word 0 191end: 192