|
@@ -1,24 +1,17 @@
|
1
|
1
|
#include "realmode.h"
|
2
|
|
-#include "isa_ids.h"
|
|
2
|
+#include "console.h"
|
|
3
|
+#include "disk.h"
|
3
|
4
|
#include "bios_disks.h"
|
4
|
5
|
|
5
|
6
|
#define CF ( 1 << 0 )
|
6
|
7
|
#define BIOS_DISK_NONE 0
|
7
|
8
|
|
8
|
|
-/*
|
9
|
|
- * Ensure that there is sufficient space in the shared dev_bus
|
10
|
|
- * structure for a struct bios_disk_device.
|
11
|
|
- *
|
12
|
|
- */
|
13
|
|
-DEV_BUS( struct bios_disk_device, bios_disk_dev );
|
14
|
|
-static char bios_disk_magic[0]; /* guaranteed unique symbol */
|
15
|
|
-
|
16
|
9
|
/*
|
17
|
10
|
* Reset the disk system using INT 13,0. Forces both hard disks and
|
18
|
11
|
* floppy disks to seek back to track 0.
|
19
|
12
|
*
|
20
|
13
|
*/
|
21
|
|
-void bios_disk_init ( void ) {
|
|
14
|
+static void bios_disk_init ( void ) {
|
22
|
15
|
REAL_EXEC ( rm_bios_disk_init,
|
23
|
16
|
"sti\n\t"
|
24
|
17
|
"xorw %%ax,%%ax\n\t"
|
|
@@ -36,45 +29,82 @@ void bios_disk_init ( void ) {
|
36
|
29
|
* Read a single sector from a disk using INT 13,2.
|
37
|
30
|
*
|
38
|
31
|
* Returns the BIOS status code (%ah) - 0 indicates success.
|
|
32
|
+ * Automatically retries up to three times to allow time for floppy
|
|
33
|
+ * disks to spin up, calling bios_disk_init() after each failure.
|
39
|
34
|
*
|
40
|
35
|
*/
|
41
|
|
-unsigned int bios_disk_read_once ( struct bios_disk_device *bios_disk,
|
42
|
|
- unsigned int cylinder,
|
43
|
|
- unsigned int head,
|
44
|
|
- unsigned int sector,
|
45
|
|
- struct bios_disk_sector *buf ) {
|
46
|
|
- uint16_t basemem_buf, status, flags;
|
47
|
|
- int discard_c, discard_d;
|
|
36
|
+static unsigned int bios_disk_read ( struct bios_disk_device *bios_disk,
|
|
37
|
+ unsigned int cylinder,
|
|
38
|
+ unsigned int head,
|
|
39
|
+ unsigned int sector,
|
|
40
|
+ struct bios_disk_sector *buf ) {
|
|
41
|
+ uint16_t basemem_buf, ax, flags;
|
|
42
|
+ unsigned int status, discard_c, discard_d;
|
|
43
|
+ int retry = 3;
|
48
|
44
|
|
49
|
45
|
basemem_buf = BASEMEM_PARAMETER_INIT ( *buf );
|
50
|
|
- REAL_EXEC ( rm_bios_disk_read,
|
51
|
|
- "sti\n\t"
|
52
|
|
- "movw $0x0201, %%ax\n\t" /* Read a single sector */
|
53
|
|
- "int $0x13\n\t"
|
54
|
|
- "pushfw\n\t"
|
55
|
|
- "popw %%bx\n\t"
|
56
|
|
- "cli\n\t",
|
57
|
|
- 4,
|
58
|
|
- OUT_CONSTRAINTS ( "=a" ( status ), "=b" ( flags ),
|
59
|
|
- "=c" ( discard_c ),
|
60
|
|
- "=d" ( discard_d ) ),
|
61
|
|
- IN_CONSTRAINTS ( "c" ( ( ( cylinder & 0xff ) << 8 ) |
|
62
|
|
- ( ( cylinder >> 8 ) & 0x3 ) |
|
63
|
|
- sector ),
|
64
|
|
- "d" ( ( head << 8 ) | bios_disk->drive ),
|
65
|
|
- "b" ( basemem_buf ) ),
|
66
|
|
- CLOBBER ( "ebp", "esi", "edi" ) );
|
|
46
|
+ do {
|
|
47
|
+ REAL_EXEC ( rm_bios_disk_read,
|
|
48
|
+ "sti\n\t"
|
|
49
|
+ "movw $0x0201, %%ax\n\t" /* Read a single sector */
|
|
50
|
+ "int $0x13\n\t"
|
|
51
|
+ "pushfw\n\t"
|
|
52
|
+ "popw %%bx\n\t"
|
|
53
|
+ "cli\n\t",
|
|
54
|
+ 4,
|
|
55
|
+ OUT_CONSTRAINTS ( "=a" ( ax ), "=b" ( flags ),
|
|
56
|
+ "=c" ( discard_c ),
|
|
57
|
+ "=d" ( discard_d ) ),
|
|
58
|
+ IN_CONSTRAINTS ( "c" ( ( (cylinder & 0xff) << 8 ) |
|
|
59
|
+ ( (cylinder >> 8) & 0x3 ) |
|
|
60
|
+ sector ),
|
|
61
|
+ "d" ( ( head << 8 ) |
|
|
62
|
+ bios_disk->drive ),
|
|
63
|
+ "b" ( basemem_buf ) ),
|
|
64
|
+ CLOBBER ( "ebp", "esi", "edi" ) );
|
|
65
|
+ status = ( flags & CF ) ? ( ax >> 8 ) : 0;
|
|
66
|
+ } while ( ( status != 0 ) && ( bios_disk_init(), retry-- ) );
|
67
|
67
|
BASEMEM_PARAMETER_DONE ( *buf );
|
68
|
68
|
|
69
|
|
- return ( flags & CF ) ? ( status >> 8 ) : 0;
|
|
69
|
+ return status;
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+/*
|
|
73
|
+ * Increment a bus_loc structure to the next possible BIOS disk
|
|
74
|
+ * location. Leave the structure zeroed and return 0 if there are no
|
|
75
|
+ * more valid locations.
|
|
76
|
+ *
|
|
77
|
+ */
|
|
78
|
+static int bios_disk_next_location ( struct bus_loc *bus_loc ) {
|
|
79
|
+ struct bios_disk_loc *bios_disk_loc
|
|
80
|
+ = ( struct bios_disk_loc * ) bus_loc;
|
|
81
|
+
|
|
82
|
+ /*
|
|
83
|
+ * Ensure that there is sufficient space in the shared bus
|
|
84
|
+ * structures for a struct bios_disk_loc and a struct
|
|
85
|
+ * bios_disk_dev, as mandated by bus.h.
|
|
86
|
+ *
|
|
87
|
+ */
|
|
88
|
+ BUS_LOC_CHECK ( struct bios_disk_loc );
|
|
89
|
+ BUS_DEV_CHECK ( struct bios_disk_device );
|
|
90
|
+
|
|
91
|
+ return ( ++bios_disk_loc->drive );
|
70
|
92
|
}
|
71
|
93
|
|
72
|
94
|
/*
|
73
|
95
|
* Fill in parameters for a BIOS disk device based on drive number
|
74
|
96
|
*
|
75
|
97
|
*/
|
76
|
|
-static int fill_bios_disk_device ( struct bios_disk_device *bios_disk ) {
|
77
|
|
- uint16_t type, flags;
|
|
98
|
+static int bios_disk_fill_device ( struct bus_dev *bus_dev,
|
|
99
|
+ struct bus_loc *bus_loc ) {
|
|
100
|
+ struct bios_disk_loc *bios_disk_loc
|
|
101
|
+ = ( struct bios_disk_loc * ) bus_loc;
|
|
102
|
+ struct bios_disk_device *bios_disk
|
|
103
|
+ = ( struct bios_disk_device * ) bus_dev;
|
|
104
|
+ uint16_t flags;
|
|
105
|
+
|
|
106
|
+ /* Store drive in struct bios_disk_device */
|
|
107
|
+ bios_disk->drive = bios_disk_loc->drive;
|
78
|
108
|
|
79
|
109
|
REAL_EXEC ( rm_bios_disk_exists,
|
80
|
110
|
"sti\n\t"
|
|
@@ -82,14 +112,15 @@ static int fill_bios_disk_device ( struct bios_disk_device *bios_disk ) {
|
82
|
112
|
"int $0x13\n\t"
|
83
|
113
|
"pushfw\n\t"
|
84
|
114
|
"popw %%dx\n\t"
|
|
115
|
+ "movb %%ah, %%al\n\t"
|
85
|
116
|
"cli\n\t",
|
86
|
117
|
2,
|
87
|
|
- OUT_CONSTRAINTS ( "=a" ( type ), "=d" ( flags ) ),
|
|
118
|
+ OUT_CONSTRAINTS ( "=a" ( bios_disk->type ),
|
|
119
|
+ "=d" ( flags ) ),
|
88
|
120
|
IN_CONSTRAINTS ( "d" ( bios_disk->drive ) ),
|
89
|
121
|
CLOBBER ( "ebx", "ecx", "esi", "edi", "ebp" ) );
|
90
|
122
|
|
91
|
|
- if ( ( flags & CF ) ||
|
92
|
|
- ( ( type >> 8 ) == BIOS_DISK_NONE ) )
|
|
123
|
+ if ( ( flags & CF ) || ( bios_disk->type == BIOS_DISK_NONE ) )
|
93
|
124
|
return 0;
|
94
|
125
|
|
95
|
126
|
DBG ( "BIOS disk found valid drive %hhx\n", bios_disk->drive );
|
|
@@ -97,72 +128,72 @@ static int fill_bios_disk_device ( struct bios_disk_device *bios_disk ) {
|
97
|
128
|
}
|
98
|
129
|
|
99
|
130
|
/*
|
100
|
|
- * Find a BIOS disk device matching the specified driver
|
|
131
|
+ * Test whether or not a driver is capable of driving the device.
|
101
|
132
|
*
|
102
|
133
|
*/
|
103
|
|
-int find_bios_disk_device ( struct bios_disk_device *bios_disk,
|
104
|
|
- struct bios_disk_driver *driver ) {
|
105
|
|
-
|
106
|
|
- /* Initialise struct bios_disk if it's the first time it's been used.
|
107
|
|
- */
|
108
|
|
- if ( bios_disk->magic != bios_disk_magic ) {
|
109
|
|
- memset ( bios_disk, 0, sizeof ( *bios_disk ) );
|
110
|
|
- bios_disk->magic = bios_disk_magic;
|
|
134
|
+static int bios_disk_check_driver ( struct bus_dev *bus_dev,
|
|
135
|
+ struct device_driver *device_driver ) {
|
|
136
|
+ struct bios_disk_device *bios_disk
|
|
137
|
+ = ( struct bios_disk_device * ) bus_dev;
|
|
138
|
+ struct bios_disk_driver *driver
|
|
139
|
+ = ( struct bios_disk_driver * ) device_driver->bus_driver_info;
|
|
140
|
+
|
|
141
|
+ /* Compare against driver's valid ID range */
|
|
142
|
+ if ( ( bios_disk->drive >= driver->min_drive ) &&
|
|
143
|
+ ( bios_disk->drive <= driver->max_drive ) ) {
|
|
144
|
+ driver->fill_drive_name ( bios_disk->name, bios_disk->drive );
|
|
145
|
+ DBG ( "BIOS disk found drive %hhx (\"%s\") "
|
|
146
|
+ "matching driver %s\n",
|
|
147
|
+ bios_disk->drive, bios_disk->name,
|
|
148
|
+ driver->name );
|
|
149
|
+ return 1;
|
111
|
150
|
}
|
112
|
151
|
|
113
|
|
- /* Iterate through all possible BIOS drives, starting where we
|
114
|
|
- * left off
|
115
|
|
- */
|
116
|
|
- DBG ( "BIOS disk searching for device matching driver %s\n",
|
117
|
|
- driver->name );
|
118
|
|
- do {
|
119
|
|
- /* If we've already used this device, skip it */
|
120
|
|
- if ( bios_disk->already_tried ) {
|
121
|
|
- bios_disk->already_tried = 0;
|
122
|
|
- continue;
|
123
|
|
- }
|
124
|
|
-
|
125
|
|
- /* Fill in device parameters */
|
126
|
|
- if ( ! fill_bios_disk_device ( bios_disk ) ) {
|
127
|
|
- continue;
|
128
|
|
- }
|
129
|
|
-
|
130
|
|
- /* Compare against driver's valid ID range */
|
131
|
|
- if ( ( bios_disk->drive >= driver->min_drive ) &&
|
132
|
|
- ( bios_disk->drive <= driver->max_drive ) ) {
|
133
|
|
- driver->fill_drive_name ( bios_disk->drive,
|
134
|
|
- bios_disk->name );
|
135
|
|
- DBG ( "BIOS_DISK found drive %hhx (\"%s\") "
|
136
|
|
- "matching driver %s\n",
|
137
|
|
- bios_disk->drive, bios_disk->name,
|
138
|
|
- driver->name );
|
139
|
|
- bios_disk->already_tried = 1;
|
140
|
|
- return 1;
|
141
|
|
- }
|
142
|
|
- } while ( ++bios_disk->drive );
|
143
|
|
-
|
144
|
|
- /* No device found */
|
145
|
|
- DBG ( "BIOS disk found no device matching driver %s\n", driver->name );
|
146
|
152
|
return 0;
|
147
|
153
|
}
|
148
|
154
|
|
149
|
155
|
/*
|
150
|
|
- * Find the next MCA device that can be used to boot using the
|
151
|
|
- * specified driver.
|
|
156
|
+ * Describe a BIOS disk device
|
152
|
157
|
*
|
153
|
158
|
*/
|
154
|
|
-int find_bios_disk_boot_device ( struct dev *dev,
|
155
|
|
- struct bios_disk_driver *driver ) {
|
|
159
|
+static char * bios_disk_describe_device ( struct bus_dev *bus_dev ) {
|
156
|
160
|
struct bios_disk_device *bios_disk
|
157
|
|
- = ( struct bios_disk_device * ) dev->bus;
|
|
161
|
+ = ( struct bios_disk_device * ) bus_dev;
|
|
162
|
+ static char bios_disk_description[] = "BIOS disk 00";
|
158
|
163
|
|
159
|
|
- if ( ! find_bios_disk_device ( bios_disk, driver ) )
|
160
|
|
- return 0;
|
|
164
|
+ sprintf ( bios_disk_description + 10, "%hhx", bios_disk->drive );
|
|
165
|
+ return bios_disk_description;
|
|
166
|
+}
|
161
|
167
|
|
162
|
|
- dev->name = bios_disk->name;
|
163
|
|
- dev->devid.bus_type = ISA_BUS_TYPE;
|
164
|
|
- dev->devid.vendor_id = ISA_VENDOR ( 'D', 'S', 'K' );
|
165
|
|
- dev->devid.device_id = bios_disk->drive;
|
|
168
|
+/*
|
|
169
|
+ * Name a BIOS disk device
|
|
170
|
+ *
|
|
171
|
+ */
|
|
172
|
+static const char * bios_disk_name_device ( struct bus_dev *bus_dev ) {
|
|
173
|
+ struct bios_disk_device *bios_disk
|
|
174
|
+ = ( struct bios_disk_device * ) bus_dev;
|
|
175
|
+
|
|
176
|
+ return bios_disk->name;
|
|
177
|
+}
|
|
178
|
+
|
|
179
|
+/*
|
|
180
|
+ * BIOS disk bus operations table
|
|
181
|
+ *
|
|
182
|
+ */
|
|
183
|
+struct bus_driver bios_disk_driver __bus_driver = {
|
|
184
|
+ .name = "BIOS DISK",
|
|
185
|
+ .next_location = bios_disk_next_location,
|
|
186
|
+ .fill_device = bios_disk_fill_device,
|
|
187
|
+ .check_driver = bios_disk_check_driver,
|
|
188
|
+ .describe_device = bios_disk_describe_device,
|
|
189
|
+ .name_device = bios_disk_name_device,
|
|
190
|
+};
|
|
191
|
+
|
|
192
|
+/*
|
|
193
|
+ * Fill in a disk structure
|
|
194
|
+ *
|
|
195
|
+ */
|
|
196
|
+void bios_disk_fill_disk ( struct disk *disk __unused,
|
|
197
|
+ struct bios_disk_device *bios_disk __unused ) {
|
166
|
198
|
|
167
|
|
- return 1;
|
168
|
199
|
}
|