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