1 /* $NetBSD: devopen.c,v 1.2 2004/03/24 16:54:18 drochner Exp $ */ 2 3 /* 4 * Copyright (c) 1996, 1997 5 * Matthias Drochner. 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 29 #include <sys/types.h> 30 31 #include <lib/libsa/stand.h> 32 #include <lib/libkern/libkern.h> 33 34 #include <libi386.h> 35 #include <biosdisk.h> 36 #include "devopen.h" 37 #ifdef _STANDALONE 38 #include <bootinfo.h> 39 #endif 40 #ifdef SUPPORT_PS2 41 #include <biosmca.h> 42 #endif 43 44 static __inline int dev2bios __P((char *, unsigned int, int *)); 45 46 static __inline int 47 dev2bios(devname, unit, biosdev) 48 char *devname; 49 unsigned int unit; 50 int *biosdev; 51 { 52 if (strcmp(devname, "hd") == 0) 53 *biosdev = 0x80 + unit; 54 else if (strcmp(devname, "fd") == 0) 55 *biosdev = 0x00 + unit; 56 else 57 return (ENXIO); 58 59 return (0); 60 } 61 62 int 63 bios2dev(int biosdev, char **devname, u_int *unit, u_int sector, u_int *ptnp) 64 { 65 if (biosdev & 0x80) 66 *devname = "hd"; 67 else 68 *devname = "fd"; 69 70 *unit = biosdev & 0x7f; 71 *ptnp = biosdiskfindptn(biosdev, sector); 72 73 return 0; 74 } 75 76 #ifdef _STANDALONE 77 struct btinfo_bootpath bibp; 78 #endif 79 80 /* 81 * Open the BIOS disk device 82 */ 83 int 84 devopen(f, fname, file) 85 struct open_file *f; 86 const char *fname; 87 char **file; 88 { 89 char *fsname, *devname; 90 unsigned int unit, partition; 91 int biosdev; 92 int error; 93 struct devsw *dp; 94 95 if ((error = parsebootfile(fname, &fsname, &devname, 96 &unit, &partition, (const char **) file)) 97 || (error = dev2bios(devname, unit, &biosdev))) 98 return (error); 99 100 dp = &devsw[0]; /* must be biosdisk */ 101 f->f_dev = dp; 102 103 #ifdef _STANDALONE 104 strncpy(bibp.bootpath, *file, sizeof(bibp.bootpath)); 105 BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp)); 106 #endif 107 108 return (biosdiskopen(f, biosdev, partition)); 109 } 110