1/* $NetBSD: wdboot.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_start: 39/* 40 * in: d3 ('DMAr' flag), d4 (SCSI target), d5 (boot pref), d7 (ACSI target) 41 */ 42main: lea %pc@(regsav),%a0 43 movml %d3-%d5/%d7,%sp@- 44 movl %sp,%a0@ 45 46 movw #-1,%sp@- 47 movw #Kbshift,%sp@- 48 trap #BIOS 49 addql #4,%sp 50 51 tstb %d5 52 beqs 0f | no boot preference 53 cmpb #0x20,%d5 54 bnes exit | bootpref != NetBSD 55 560: btst #3,%d0 | Alternate? 57 bnes exit 58 subql #1,%d0 59 movl %d0,%a3 | autoboot flag 60 61 movl _membot:w,%d3 62 lea MAXBOT,%a4 63 cmpl %a4,%d3 64 bhis exit | membot > MAXBOT 65 66 movl _memtop:w,%d3 67 cmpl #MINTOP,%d3 68 blts exit | memtop < MINTOP 69 70 andw #-4,%d3 71 movl %d3,%a0 72 movl %sp,%a0@- 73 movl %a0,%sp | set new stack 74 75 movq #NSEC,%d5 | sector count 76 movq #1,%d6 | first sector 77 bsrs rds0 78 tstl %d0 79 bnes 0f 80/* 81 * loader (readsector, disklabel, autoboot) 82 */ 83 pea %a3@ | autoboot 84 pea %a4@(LBLST-MAXBOT) | disklabel 85 pea %pc@(rds1) | readsector 86 jsr %a4@(BXXST-MAXBOT) 87 lea %sp@(12),%sp | NetBSD not booted 88 890: movl %sp@,%sp | restore BIOS stack 90 tstl %d0 91 bmis exit 92 movl %d0,%sp@(8) | new boot preference 93 94exit: movml %sp@+,%d3-%d5/%d7 95 rts 96 97/* 98 * int readsec (void *buffer, u_int offset, u_int count); 99 */ 100rds1: movml %d2-%d7/%a2-%a6,%sp@- 101 movl %pc@(regsav),%a0 102 movml %a0@,%d3-%d5/%d7 103 movl %sp@(48),%a4 | buffer 104 movl %sp@(52),%d6 | offset 105 movl %sp@(56),%d3 | count 1060: movl #255,%d5 107 cmpl %d5,%d3 108 bccs 1f 109 movl %d3,%d5 1101: bsrs rds0 111 tstl %d0 112 bnes 2f 113 addl #(255*512),%a4 114 addl %d5,%d6 115 subl %d5,%d3 116 bnes 0b 1172: movml %sp@+,%d2-%d7/%a2-%a6 118 rts 119/* 120 * in: d4 (target) d5 (count), d6 (offset), a4 (buffer) 121 * out: d0 (<= 0) 122 * mod: d0, d1, d2, a0, a1, a5, a6 123 */ 124rds0: lea %pc@(dpar),%a6 125 tstb %a6@ 126 bnes 0f 127 movb %d4,%d0 128 andb #1,%d0 129 aslb #4,%d0 130 orb #0xa0,%d0 131 movb %d0,idesdh:l 132 movl %a4,%a0 133 movq #0,%d1 134 movb #0,idedor:l 135 movb #0xec,idecr:l | IDENTIFY DRIVE 136 bsrs wait 137 bnes err 138 movb %a4@(7),%a6@ | tracks/cylinder 139 movb %a4@(13),%a6@(1) | sectors/track 1400: movl %d6,%d1 141 movq #0,%d0 142 movb %a6@(1),%d0 143 movq #0,%d2 144 movb %a6@,%d2 145 mulu %d0,%d2 146 divu %d2,%d1 147 movb %d1,idecl:l 148 lsrl #8,%d1 149 movb %d1,idech:l 150 lsrl #8,%d1 151 divu %d0,%d1 152 movb %d4,%d0 153 andb #1,%d0 154 aslb #4,%d0 155 orb %d0,%d1 156 orb #0xa0,%d1 157 movb %d1,idesdh:l 158 swap %d1 159 addqw #1,%d1 160 movb %d1,idesn:l 161 movl %a4,%a0 162 movb %d5,idesc:l 163 movw %d5,%d1 164 subqw #1,%d1 165 movb #0,idedor:l 166 movb #0x20,idecr:l 167wait: movl #0x7d0,%d0 168 addl _hz_200:w,%d0 1692: btst #5,gpip:w 170 beqs 3f 171 cmpl _hz_200:w,%d0 172 bhis 2b 173err: movq #-1,%d0 174 rts 1753: movb idesr:l,%d0 176 btst #0,%d0 177 bnes err 178 btst #3,%d0 179 beqs err 180 movq #63,%d0 181 lea idedr:l,%a1 1824: movw %a1@,%a0@+ 183 movw %a1@,%a0@+ 184 movw %a1@,%a0@+ 185 movw %a1@,%a0@+ 186 dbra %d0,4b 187 dbra %d1,wait 188 movq #0,%d0 189 rts 190 191regsav: .long 0 192 193fill: .space 30 194 195dpar: .byte 0 | tracks/cylinder 196 .byte 0 | sectors/track 197 198 .ascii "NetBSD" 199hd_siz: .long 0 200p0_dsc: .long 0, 0, 0 201p1_dsc: .long 0, 0, 0 202p2_dsc: .long 0, 0, 0 203p3_dsc: .long 0, 0, 0 204bsl_st: .long 0 205bsl_sz: .long 0 206 .word 0 207end: 208