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