1/* $NetBSD: xxboot.ahdi.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 * AHDI rootsector code passes: 59 * d3: SCSI/IDE <-> ACSI flag d4: SCSI/IDE target (or -1) 60 * d5: boot preference d6: offset of boot block 61 * d7: ACSI target a3: pointer to readsector() 62 * a4: pointer to `start' a5: pointer to back-to-ROM 63 */ 64main: movml %d3-%d7/%a3-%a5,%sp@- 65 lea %pc@(regsav),%a0 66 movl %sp,%a0@ 67 68 movw #-1,%sp@- 69 movw #Kbshift,%sp@- 70 trap #BIOS 71 addql #4,%sp 72 subql #1,%d0 73 movl %d0,%a5 | autoboot flag 74 75 lea %pc@(m_bot),%a6 76 movl _membot:w,%d3 77 lea MAXBOT,%a4 78 cmpl %a4,%d3 79 bhis exit | membot > MAXBOT 80 81 lea %pc@(m_top),%a6 82 movl _memtop:w,%d3 83 cmpl #MINTOP,%d3 84 blts exit | memtop < MINTOP 85 86 andw #-4,%d3 87 movl %d3,%a0 88 movl %sp,%a0@- 89 movl %a0,%sp | set new stack 90/* 91 * Load secondary boot loader and disklabel. 92 */ 93 movml %a4/%a5,%sp@- 94 movq #NSEC,%d3 | # of sectors 95 addql #1,%d6 | first sector 96 bsr rds1 97 lea %pc@(m_rds),%a6 98 movml %sp@+,%a4/%a5 99 bnes 0f | I/O error 100/* 101 * int bootxx(readsector, disklabel, autoboot) 102 */ 103 pea %a5@ | autoboot 104 pea %a4@(LBLST-MAXBOT) | disklabel 105 pea %pc@(rds2) | readsector 106 jsr %a4@(BXXST-MAXBOT) 107 lea %pc@(m_sbl),%a6 | NetBSD not booted 108 lea %sp@(12),%sp 109 1100: movl %sp@,%sp | restore BIOS stack 111 movl %d0,%d3 112 bmis exit 113 movml %sp@+,%d3-%d7/%a3-%a5 114 movl %d0,%d5 | new boot preference 115 jmp %a4@(-0x200) 116 117exit: bsrs puts | display error 118 lea %pc@(m_key),%a6 119 bsrs puts | wait for key 120 movml %sp@+,%d3-%d7/%a3-%a5 121 jmp %a5@ 122 123/* 124 * puts (in: a6, d3) 125 */ 1260: cmpw #35,%d0 | '#' 127 bnes 1f 128 bsrs puti 129 bras puts 1301: cmpw #64,%d0 | '@' 131 bnes 2f 132 movw #2,%sp@- 133 movw #Bconin,%sp@- 134 trap #BIOS 135 addql #4,%sp 136 bras puts 1372: bsrs putc 138puts: movq #0,%d0 139 movb %a6@+,%d0 140 bnes 0b 141 rts 142 143puti: swap %d3 144 bsrs 0f 145 swap %d3 1460: rorw #8,%d3 147 bsrs 1f 148 rorw #8,%d3 1491: rorb #4,%d3 150 bsrs 2f 151 rorb #4,%d3 1522: movw %d3,%d0 153 andw #15,%d0 154 addw #48,%d0 155 cmpw #58,%d0 156 bcss putc 157 addw #39,%d0 158putc: movw %d0,%sp@- 159 movw #2,%sp@- 160 movw #Bconout,%sp@- 161 trap #BIOS 162 addql #6,%sp 163 rts 164/* 165 * int readsec (void *buffer, u_int offset, u_int count); 166 */ 167rds2: movml %d2-%d7/%a2-%a6,%sp@- 168 movl %pc@(regsav),%a0 169 movml %a0@,%d3-%d7/%a3-%a5 170 movl %sp@(48),%a4 | buffer 171 movl %sp@(52),%d6 | offset 172 movl %sp@(56),%d3 | count 173 bsrs rds1 174 movml %sp@+,%d2-%d7/%a2-%a6 175 rts 176 177rds1: movl #255,%d5 178 cmpl %d5,%d3 179 bccs 0f 180 movl %d3,%d5 1810: jsr %a3@ 182 tstl %d0 183 bnes 1f 184 addl #(255*512),%a4 185 addl %d5,%d6 186 subl %d5,%d3 187 bnes rds1 1881: rts 189 190m_bot: .asciz "xxboot: membot == 0x#\r\n" 191m_top: .asciz "xxboot: memtop == 0x#\r\n" 192m_sbl: .asciz "xxboot: bootxx => 0x#\r\n" 193m_rds: .asciz "xxboot: Floprd => 0x#\r\n" 194m_key: .asciz "\007\r\npress any key... @\r\n" 195 196regsav: .long 0 197 198fill: .space 54 | 510-(fill-start) 199 .word 0 | checksum 200end: 201