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