1/* $NetBSD: sdboot.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 cmpl #0x444d4172,%d3 | SCSI bootdev? 52 beqs 0f 53 movq #-1,%d4 | no, ACSI 54 bras 1f 55 560: tstb %d5 57 beqs 1f | no boot preference 58 cmpb #0x20,%d5 59 bnes exit | bootpref != NetBSD 60 611: btst #3,%d0 | Alternate? 62 bnes exit 63 subql #1,%d0 64 movl %d0,%a3 | autoboot flag 65 66 movl _membot:w,%d0 67 lea MAXBOT,%a4 68 cmpl %a4,%d0 69 bhis exit | membot > MAXBOT 70 71 movl _memtop:w,%d0 72 cmpl #MINTOP,%d0 73 blts exit | memtop < MINTOP 74 75 andw #-4,%d0 76 movl %d0,%a0 77 movl %sp,%a0@- 78 movl %a0,%sp | set new stack 79 80 movq #NSEC,%d5 | sector count 81 movq #1,%d6 | first sector 82 bsrs rds0 83 tstl %d0 84 bnes 0f 85/* 86 * loader (readsector, disklabel, autoboot) 87 */ 88 pea %a3@ | autoboot 89 pea %a4@(LBLST-MAXBOT) | disklabel 90 pea %pc@(rds1) | readsector 91 jsr %a4@(BXXST-MAXBOT) 92 lea %sp@(12),%sp | NetBSD not booted 93 940: movl %sp@,%sp | restore BIOS stack 95 tstl %d0 96 bmis exit 97 movl %d0,%sp@(8) | new boot preference 98 99exit: movml %sp@+,%d3-%d5/%d7 100 rts 101 102/* 103 * int readsec (void *buffer, u_int offset, u_int count); 104 */ 105rds1: movml %d2-%d7/%a2-%a6,%sp@- 106 movl %pc@(regsav),%a0 107 movml %a0@,%d3-%d5/%d7 108 movl %sp@(48),%a4 | buffer 109 movl %sp@(52),%d6 | offset 110 movl %sp@(56),%d3 | count 1110: movl #255,%d5 112 cmpl %d5,%d3 113 bccs 1f 114 movl %d3,%d5 1151: bsrs rds0 116 tstl %d0 117 bnes 2f 118 addl #(255*512),%a4 119 addl %d5,%d6 120 subl %d5,%d3 121 bnes 0b 1222: movml %sp@+,%d2-%d7/%a2-%a6 123 rts 124/* 125 * in: d4/d7 (target) d5 (count), d6 (offset), a4 (buffer) 126 * out: d0 (<= 0) 127 * mod: d0, d1, d2, a0, a5, a6 128 */ 129rds0: tstl %d4 130 bmis 0f 131 movw %d4,%sp@- | device 132 pea %a4@ | buffer 133 movw %d5,%sp@- | count 134 movl %d6,%sp@- | offset 135 movw #DMAread,%sp@- 136 trap #XBIOS 137 lea %sp@(14),%sp 138 rts 139 1400: st flock:w 141 movl _hz_200:w,%d0 142 addql #2,%d0 1431: cmpl _hz_200:w,%d0 144 bccs 1b 145 movml %d6/%a4,%sp@- 146 lea dmahi:w,%a6 147 movb %sp@(7),%a6@(4) 148 movb %sp@(6),%a6@(2) 149 movb %sp@(5),%a6@ 150 lea %pc@(r0com),%a6 151 movb %sp@(1),%a6@(1) 152 movb %sp@(2),%a6@(5) 153 movb %sp@(3),%a6@(9) 154 movb %d5,%a6@(13) 155 addql #8,%sp 156 lea dmodus:w,%a6 157 lea daccess:w,%a5 158 movw #0x198,%a6@ 159 movw #0x098,%a6@ 160 movw %d5,%a5@ 161 movw #0x88,%a6@ 162 movq #0,%d0 163 movb %d7,%d0 164 orb #0x08,%d0 165 swap %d0 166 movw #0x8a,%d0 167 bsrs shake 168 lea %pc@(r0com),%a0 169 movq #3,%d2 1702: movl %a0@+,%d0 171 bsrs shake 172 dbra %d2,2b 173 movq #0x0a,%d0 174 movl %d0,%a5@ 175 movl #0x190,%d1 176 bsrs wait 177 movw #0x8a,%a6@ 178 movw %a5@,%d0 179 andw #0xff,%d0 180 beqs 0f 181r0err: movq #-1,%d0 1820: movw #0x80,%a6@ 183 clrb flock:w 184r0ret: rts 185 186shake: movl %d0,%a5@ 187 movq #0x0a,%d1 188wait: addl _hz_200:w,%d1 1890: btst #5,gpip:w 190 beqs r0ret 191 cmpl _hz_200:w,%d1 192 bccs 0b 193 addql #4,%sp 194 bras r0err 195 196r0com: .long 0x0000008a 197 .long 0x0000008a 198 .long 0x0000008a 199 .long 0x0001008a 200 201regsav: .long 0 202 203fill: .space 24 204 205 .ascii "NetBSD" 206hd_siz: .long 0 207p0_dsc: .long 0, 0, 0 208p1_dsc: .long 0, 0, 0 209p2_dsc: .long 0, 0, 0 210p3_dsc: .long 0, 0, 0 211bsl_st: .long 0 212bsl_sz: .long 0 213 .word 0 214end: 215