1/* $NetBSD: start.S,v 1.5 2013/04/04 12:48:07 martin Exp $ */ 2/* 3 * Copyright (c) 1995 Ludd, University of Lule}, Sweden. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Ludd by 7 * Bertram Barth. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed at Ludd, University of 20 * Lule}, Sweden and its contributors. 21 * 4. The name of the author may not be used to endorse or promote products 22 * derived from this software without specific prior written permission 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /* All bugs are subject to removal without further notice */ 37 38 39#define _LOCORE 40 41#define __HAVE_OLD_DISKLABEL /* not automatically added due to _LOCORE */ 42#define OMIT_DKTYPENUMS 43#define OMIT_FSTYPENUMS 44#include "sys/disklabel.h" 45 46#include "../include/mtpr.h" 47#include "../include/asm.h" 48 49_C_LABEL(_start): 50_C_LABEL(start): 51 .globl _C_LABEL(start) # this is the symbolic name for the start 52 .globl _C_LABEL(_start) # of code to be relocated. We can use this 53 # to get the actual/real address (pc-rel) 54 # or to get the relocated address (abs). 55 56.org 0x00 # uVAX booted from TK50 starts here 57 brb from_0x00 # continue behind dispatch-block 58 59# At offset 0x02 we have a dual used area: VMB.EXE starts execution here, 60# and uVAX-ROM looks for a pointer to a parameter block. We arrange for 61# the parameter block offset to disassmble as a CASEL instructions which 62# falls through to 0x08. 63.org 0x02 # information used by uVAX-ROM 64 .byte 0xcf # offset in words to identification area 65 .byte 1 # this byte must be 1 66 .word 0 # logical block number (word swapped) 67 .word 0 # of the secondary image 68 69.org 0x08 # 70 brb from_0x08 # skip ... 71 72.org 0x0C # 11/750 & 8200 starts here 73 movzbl $1,_C_LABEL(from)# We booted from "old" rom. 74 brw cont_750 75 76 77from_0x00: # uVAX from TK50 78 brw start_uvax # all uVAXen continue there 79 80from_0x08: # Any machine from VMB 81 movzbl $4,_C_LABEL(from) # Booted from full VMB 82 /* 83 * Read in block 1-15. 84 */ 85 movl 52(%r11), %r7 # load iovec/bqo into %r7 86 addl3 (%r7), %r7, %r6 # load qio into %r6 87 pushl %r11 # base of rpb 88 pushl $0 # virtual-flag 89 pushl $33 # read-logical-block 90 pushl $1 # lbn to start reading 91 pushl $7680 # number of bytes to read 92 pushab start_uvax # buffer-address 93 calls $6, (%r6) # call the qio-routine 94 brw start_uvax 95 96# the complete area reserved for label 97# must be empty (i.e. filled with zeroes). 98# disklabel(8) checks that before installing 99# the bootblocks over existing label. 100 101.org LABELOFFSET 102 .globl _C_LABEL(romlabel) 103_C_LABEL(romlabel): 104 .long 0 105 106.org LABELOFFSET + d_end_ 107# Make sure the parameter block is past the disklabel. 108# If not, the next .org would try to move backwards. 109 110/* 111 * Parameter block for uVAX boot. 112 */ 113#define VOLINFO 0 /* 1=single-sided 81=double-sided volumes */ 114#define SISIZE 16 /* size in blocks of secondary image */ 115#define SILOAD 0 /* load offset (usually 0) from the default */ 116#define SIOFF 0x200 /* byte offset into secondary image */ 117 118.org 0x19e # do not move, see comment earlier about CASEL 119 .byte 0x18 # must be 0x18 120 .byte 0x00 # must be 0x00 (MBZ) 121 .byte 0x00 # any value 122 .byte 0xFF - (0x18 + 0x00 + 0x00) 123 /* 4th byte holds 1s' complement of sum of previous 3 bytes */ 124 125 .byte 0x00 # must be 0x00 (MBZ) 126 .byte VOLINFO 127 .byte 0x00 # any value 128 .byte 0x00 # any value 129 130 .long SISIZE # size in blocks of secondary image 131 .long SILOAD # load offset (usually 0) 132 .long SIOFF # byte offset into secondary image 133 .long (SISIZE + SILOAD + SIOFF) # sum of previous 3 134 135 136 .align 2 137 .globl _C_LABEL(from) 138_C_LABEL(from): 139 .long 0 140 141/* 142 * After bootblock (LBN0) has been loaded into the first page 143 * of good memory by 11/750's ROM-code (transfer address 144 * of bootblock-code is: base of good memory + 0x0C) registers 145 * are initialized as: 146 * R0: type of boot-device 147 * 0: Massbus device 148 * 1: RK06/RK07 149 * 2: RL02 150 * 17: UDA50 151 * 35: TK50 152 * 64: TU58 153 * R1: (UBA) address of UNIBUS I/O-page 154 * (MBA) address of boot device's adapter 155 * R2: (UBA) address of the boot device's CSR 156 * (MBA) controller number of boot device 157 * R6: address of driver subroutine in ROM 158 * 159 * cont_750 reads in LBN1-15 for further execution. 160 */ 161cont_750: 162 movl $_C_LABEL(start), %sp # move stack to avoid clobbering the code 163 pushr $0x131 # save clobbered registers 164 clrl %r4 # %r4 == # of blocks transferred 165 movab _C_LABEL(start),%r5 # %r5 have base address for next transfer 166 pushl %r5 # ...on stack also (Why?) 1671: incl %r4 # increment block count 168 movl %r4,%r8 # LBN is in %r8 for rom routine 169 addl2 $0x200,%r5 # Increase address for next read 170 cmpl $16,%r4 # read 15 blocks? 171 beql 2f # Yep 172 movl %r5,(%sp) # move address to stack also 173 jsb (%r6) # read 512 bytes 174 blbs %r0,1b # jump if read succeeded 175 halt # otherwise die... 1762: tstl (%sp)+ # remove boring arg from stack 177 popr $0x131 # restore clobbered registers 178 brw start_all # Ok, continue... 179 180/* uVAX main entry is at the start of the second disk block. This is 181 * needed for multi-arch CD booting where multiple architecture need 182 * to shove stuff in boot block 0. 183 */ 184 .org 0x200 # uVAX booted from disk starts here 185 186start_uvax: 187 movzbl $2,_C_LABEL(from) # Booted from subset-VMB 188 brb start_all 189 190/* 191 * start_all: stack already at RELOC, we save registers, move ourself 192 * to RELOC and loads boot. 193 */ 194start_all: 195 movl $_C_LABEL(start), %sp # move stack to a better 196 pushr $0x1fff # save all regs, used later. 197 198 subl3 $_C_LABEL(start), $_C_LABEL(edata), %r0 199 # get size of text+data (w/o bss) 200 moval _C_LABEL(start), %r1 # get actual base-address of code 201 subl3 $_C_LABEL(start), $_C_LABEL(end), %r2 202 # get complete size (incl. bss) 203 movl $_C_LABEL(start), %r3 # get relocated base-address of code 204 movc5 %r0, (%r1), $0, %r2, (%r3) # copy code to new location 205 206 movpsl -(%sp) 207 movl $relocated, -(%sp) # return-address on top of stack 208 rei # can be replaced with new address 209relocated: # now relocation is done !!! 210 movl %sp, _C_LABEL(bootregs) 211 calls $0, _C_LABEL(Xmain) # call Xmain (gcc workaround)which is 212 halt # not intended to return ... 213 214/* 215 * hoppabort() is called when jumping to the newly loaded program. 216 */ 217ENTRY(hoppabort, 0) 218 movl 4(%ap),%r6 219 movl _C_LABEL(rpb),%r11 220 mnegl $1,%ap # Hack to figure out boot device. 221 movpsl -(%sp) 222 pushab 2(%r6) 223 mnegl $1,_C_LABEL(vax_load_failure) 224 rei 225# calls $0,(%r6) 226 halt 227 228ENTRY(unit_init, R6|R7|R8|R9|R10|R11) 229 mfpr $17,%r7 # Wanted bu KDB 230 movl 4(%ap),%r0 # init routine address 231 movl 8(%ap),%r9 # RPB in %r9 232 movl 12(%ap),%r1 # VMB argument list 233 callg (%r1),(%r0) 234 ret 235 236# A bunch of functions unwanted in boot blocks. 237ENTRY(getchar, 0) 238 halt 239 240#ifndef USE_PRINTF 241ENTRY(putchar, 0) 242 ret 243 244ENTRY(printf, 0) 245 ret 246#endif 247 248ENTRY(panic, 0) 249 halt 250