1 /* $NetBSD: rom.c,v 1.3 2000/07/19 00:58:25 matt Exp $ */ 2 /* 3 * Copyright (c) 1996 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 #include "sys/param.h" 37 #include "sys/reboot.h" 38 #include "sys/disklabel.h" 39 40 #include "lib/libsa/stand.h" 41 #include "lib/libsa/ufs.h" 42 43 #include "lib/libkern/libkern.h" 44 45 #include "../include/pte.h" 46 #include "../include/sid.h" 47 #include "../include/mtpr.h" 48 #include "../include/reg.h" 49 #include "../include/rpb.h" 50 51 #include "data.h" 52 #include "vaxstand.h" 53 54 static struct disklabel romlabel; 55 static char io_buf[DEV_BSIZE]; 56 static struct bqo *bqo; 57 static int dpart, dunit; 58 59 int 60 romopen(struct open_file *f, int adapt, int ctlr, int unit, int part) 61 { 62 char *msg; 63 struct disklabel *lp = &romlabel; 64 size_t i; 65 int err; 66 67 bqo = (void *)bootrpb.iovec; 68 69 if (bootrpb.unit > 0 && (bootrpb.unit % 100) == 0) { 70 printf ("changing bootrpb.unit from %d ", bootrpb.unit); 71 bootrpb.unit /= 100; 72 printf ("to %d\n", bootrpb.unit); 73 } 74 75 bzero(lp, sizeof(struct disklabel)); 76 dunit = unit; 77 dpart = part; 78 79 err = romstrategy(0, F_READ, LABELSECTOR, DEV_BSIZE, io_buf, &i); 80 if (err) { 81 printf("reading disklabel: %s\n",strerror(err)); 82 return 0; 83 } 84 msg = getdisklabel(io_buf+LABELOFFSET, lp); 85 if (msg) 86 printf("getdisklabel: %s\n",msg); 87 return(0); 88 } 89 90 int romwrite_uvax(int, int, void *, struct rpb *); 91 int romread_uvax(int, int, void *, struct rpb *); 92 93 int 94 romstrategy (f, func, dblk, size, buf, rsize) 95 void *f; 96 int func; 97 daddr_t dblk; 98 size_t size; 99 void *buf; 100 size_t *rsize; 101 { 102 struct disklabel *lp; 103 int block; 104 105 lp = &romlabel; 106 block = dblk + lp->d_partitions[dpart].p_offset; 107 if (dunit >= 0 && dunit < 10) 108 bootrpb.unit = dunit; 109 110 if (func == F_WRITE) 111 romwrite_uvax(block, size, buf, &bootrpb); 112 else 113 romread_uvax(block, size, buf, &bootrpb); 114 115 *rsize = size; 116 return 0; 117 } 118 119