1/* $NetBSD: fdboot.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/* 41 * Fake gemdos-fs bootsector, to keep TOS away. 42 */ 43 .ascii "NetBSD" | oem 44 .byte 0,0,0 | serial 45 .word 0 | bps 46 .byte 0 | spc 47 .word 0 | res 48 .byte 0 | fat 49 .word 0 | ndirs 50 .word 0 | sec 51 .byte 0 | media 52 .word 0 | spf 53 .word 0 | spt 54 .word 0 | side 55 .word 0 | hid 56 .even 57/* 58 * ROM loader does not save any register! 59 */ 60main: movml %d1-%d7/%a0-%a6,%sp@- 61 62 lea %pc@(m_bot),%a3 63 movl _membot:w,%d3 64 lea MAXBOT,%a6 65 cmpl %a6,%d3 66 bhis exit | membot > MAXBOT 67 68 lea %pc@(m_top),%a3 69 movl _memtop:w,%d3 70 cmpl #MINTOP,%d3 71 blts exit | memtop < MINTOP 72 73 andw #-4,%d3 74 movl %d3,%a0 75 movl %sp,%a0@- 76 movl %a0,%sp | set new stack 77/* 78 * Determine the number of sectors per cylinder. 79 */ 80 movq #0,%d3 810: movl %a6,%a3 | buffer 82 movq #1,%d0 | count 83 movq #0,%d1 | side 84 movl %d1,%d2 | track 85 addw %d0,%d3 | sector 86 bsr rds0 87 beqs 0b 88 subqw #1,%d3 89 addw %d3,%d3 90 lea %pc@(secpercyl),%a0 91 movw %d3,%a0@ 92/* 93 * Load secondary boot loader and disklabel. 94 */ 95 movq #NSEC,%d5 | # of sectors 96 movq #1,%d4 | first sector 97 movl %a6,%a3 | load address 98 bsr rds1 99 lea %pc@(m_rds),%a3 100 bnes 0f | I/O error 101/* 102 * int bootxx(readsector, disklabel, autoboot) 103 */ 104 clrl %sp@- | no autoboot 105 pea %a6@(LBLST-MAXBOT) | disklabel 106 pea %pc@(rds2) | readsector 107 jsr %a6@(BXXST-MAXBOT) 108 lea %pc@(m_sbl),%a3 | NetBSD not booted 109 lea %sp@(12),%sp 1100: movl %sp@,%sp | restore BIOS stack 111 movl %d0,%d3 112 113exit: bsrs puts | display error 114 lea %pc@(m_key),%a3 115 bsrs puts | wait for key 1160: movml %sp@+,%d1-%d7/%a0-%a6 117 movq #0,%d0 118 rts 119/* 120 * puts (in: a3, d3) 121 */ 1220: cmpw #35,%d0 | '#' 123 bnes 1f 124 bsrs puti 125 bras puts 1261: cmpw #64,%d0 | '@' 127 bnes 2f 128 movw #2,%sp@- 129 movw #Bconin,%sp@- 130 trap #BIOS 131 addql #4,%sp 132 bras puts 1332: bsrs putc 134puts: movq #0,%d0 135 movb %a3@+,%d0 136 bnes 0b 137 rts 138 139puti: swap %d3 140 bsrs 0f 141 swap %d3 1420: rorw #8,%d3 143 bsrs 1f 144 rorw #8,%d3 1451: rorb #4,%d3 146 bsrs 2f 147 rorb #4,%d3 1482: movw %d3,%d0 149 andw #15,%d0 150 addw #48,%d0 151 cmpw #58,%d0 152 bcss putc 153 addw #39,%d0 154putc: movw %d0,%sp@- 155 movw #2,%sp@- 156 movw #Bconout,%sp@- 157 trap #BIOS 158 addql #6,%sp 159 rts 160/* 161 * int readsec (void *buffer, u_int offset, u_int count); 162 */ 163rds2: movml %d2-%d5/%a2-%a3,%sp@- 164 movl %sp@(28),%a3 | buffer 165 movl %sp@(32),%d4 | offset 166 movl %sp@(36),%d5 | count 167 bsrs rds1 168 movml %sp@+,%d2-%d5/%a2-%a3 169 rts 170 171rds1: bsrs 1f 172 bnes 0f 173 tstl %d5 174 bnes rds1 1750: rts 176 1771: movq #0,%d0 178 movw %pc@(secpercyl),%d0 179 movl %d4,%d3 180 divuw %d0,%d3 181 movw %d3,%d2 | track 182 clrw %d3 183 swap %d3 184 lsrw #1,%d0 185 divuw %d0,%d3 186 movw %d3,%d1 | side 187 swap %d3 188 subw %d3,%d0 189 addqw #1,%d3 | sector 190 cmpl %d0,%d5 191 bccs rds0 192 movw %d5,%d0 193 194rds0: movw %d0,%sp@- | count 195 movw %d1,%sp@- | side 196 movw %d2,%sp@- | track 197 movw %d3,%sp@- | sector 198 movw _bootdev:w,%sp@- | device 199 clrl %sp@- | filler 200 movl %a3,%sp@- | buffer 201 addl %d0,%d4 202 subl %d0,%d5 203 lsll #8,%d0 204 addl %d0,%d0 205 addl %d0,%a3 206 movw #Floprd,%sp@- 207 trap #XBIOS 208 lea %sp@(20),%sp 209 tstl %d0 210 rts 211 212secpercyl: 213 .word 0 214 215m_bot: .asciz "fdboot: membot == 0x#\r\n" 216m_top: .asciz "fdboot: memtop == 0x#\r\n" 217m_sbl: .asciz "fdboot: bootxx => 0x#\r\n" 218m_rds: .asciz "fdboot: Floprd => 0x#\r\n" 219m_key: .asciz "\007\r\npress any key... @\r\n" 220 221fill: .space 22 | 510-(fill-start) 222 .word 0 | checksum 223end: 224