1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/*
* edd.c - real mode bios library for discovering EDD capabilities of
* BIOS drives
*
* Matt Wilson <msw@redhat.com>
*
* Copyright 2000 Red Hat, Inc.
*
* This software may be freely redistributed under the terms of the GNU
* library public license.
*
* You should have received a copy of the GNU Library Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <sys/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lrmi.h"
#include "edd.h"
static int edd_lrmi_initialized = 0;
static int
edd_lrmi_init (void) {
if (edd_lrmi_initialized)
return EDD_SUCCESS;
if (iopl(3)) {
fprintf (stderr, "ERROR: failed to set iopl permissions\n");
return EDD_ERROR;
}
if (ioperm(0, 0x400, 1)) {
fprintf (stderr, "ERROR: failed to set ioperm permissions\n");
return EDD_ERROR;
}
/* Initialize LRMI. */
if(LRMI_init() == 1) {
edd_lrmi_initialized = 1;
return EDD_SUCCESS;
}
fprintf (stderr, "ERROR: failed to initialize lrmi library\n");
return EDD_ERROR;
}
EDDParameters *
edd_get_parameters (EDDCapability *ec)
{
struct LRMI_regs regs;
EDDParameters *ep, *ret;
return NULL;
if (edd_lrmi_init() == EDD_ERROR) {
return NULL;
}
(unsigned char *) ep = LRMI_alloc_real(sizeof(EDDParameters));
if (ep == NULL) {
return NULL;
}
memset(ep, 0, sizeof(EDDParameters));
memset(®s, 0, sizeof(regs));
if (ec->version.major == 3)
ep->buffer_size = 0x42;
else if (ec->version.major == 2)
ep->buffer_size = 0x1e;
else
ep->buffer_size = 0x1a;
regs.eax = 0x4800;
regs.edx = ec->drive & 0x00ff;
regs.es = ((u_int32_t) ep) >> 4;
regs.edi = ((u_int32_t) ep) & 0x0f;
printf ("%p -> 0x%x 0x%x\n", ep, regs.es, regs.edi);
if(LRMI_int(0x13, ®s) == 0) {
LRMI_free_real((unsigned char *) ep);
return NULL;
}
/* XXX check return */
printf ("0x%x\n", regs.eax);
printf ("0x%x\n", regs.flags);
ret = malloc (sizeof (EDDParameters));
if (ret == NULL) {
fprintf (stderr, "out of memory\n");
abort();
}
memcpy (ret, ep, sizeof (EDDParameters));
LRMI_free_real((unsigned char *) ep);
return ret;
}
EDDCapability *
edd_supported(int drive)
{
struct LRMI_regs regs;
FILE *f = fopen("/proc/cmdline", "r");
if (f) {
char buf[100];
fgets(buf, sizeof(buf) - 1, f);
fclose(f);
if (strstr(buf, "lba32")) {
EDDCapability *ec = malloc (sizeof (EDDCapability));
ec->edd = 1;
return ec;
}
}
if (edd_lrmi_init() == EDD_ERROR) {
return NULL;
}
memset(®s, 0, sizeof(regs));
regs.eax = 0x4100;
regs.ebx = 0x55aa;
regs.edx = drive & 0xff;
/* Do it. */
if (LRMI_int (0x13, ®s) == 0) {
return NULL;
}
/* Check for successful return. */
if(regs.ebx == 0xaa55) {
/* Supported, report capabilities */
EDDCapability *ec = malloc (sizeof (EDDCapability));
memset (ec, 0, sizeof (EDDCapability));
if (ec == NULL) {
fprintf (stderr, "out of memory\n");
abort();
}
if ((regs.eax & 0xff00) == 0x0100) {
ec->version.major = 1;
ec->version.minor = 0;
} else if ((regs.eax & 0xff00) == 0x2000) {
ec->version.major = 2;
ec->version.minor = 0;
} else if ((regs.eax & 0xff00) == 0x2100) {
ec->version.major = 2;
ec->version.minor = 1;
} else if ((regs.eax & 0xff00) == 0x3000) {
ec->version.major = 3;
ec->version.minor = 0;
} else {
fprintf (stderr, "WARNING: Unknown EDD version 0x%x supported\n",
regs.eax & 0xff00);
}
if (regs.ecx & EDD_CAPABILITY_EDA)
ec->eda = 1;
if (regs.ecx & EDD_CAPABILITY_REMOVABLE)
ec->removable = 1;
if (regs.ecx & EDD_CAPABILITY_EDD)
ec->edd = 1;
ec->drive = drive;
return ec;
} else {
/* Not supported. */
return NULL;
}
}
#ifdef TESTING
int
main (void)
{
int i;
EDDCapability *ec;
EDDParameters *ep;
for (i = 0x80; i < 0x90; i++) {
if ((ec = edd_supported(i))) {
printf ("edd version %d.%d supported on 0x%x\n", ec->version.major,
ec->version.minor, i);
printf (" extended disk access %s\n",
ec->eda ? "supported" : "not supported");
printf (" removable media functions %s\n",
ec->removable ? "supported" : "not supported");
printf (" edd functions %s\n",
ec->edd ? "supported" : "not supported");
ep = edd_get_parameters (ec);
if (ep) {
printf ("heads: %d cyl: %d sec/track: %d\n",
ep->heads, ep->cyls, ep->sectors);
free (ep);
} else
printf ("get_parameters call failed\n");
free (ec);
} else
printf ("edd not supported on 0x%x\n", i);
}
return 0;
}
#endif
|