4bf1d313c52b7d294da9481727d58fdd2f412571
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /////////////////////////////////////////////////////////////////////////////////////////////
27 /////////////////////////////////////////////////////////////////////////////////////////////
29 BOOLEAN
DiskResetController(ULONG DriveNumber
)
34 DPRINTM(DPRINT_DISK
, "DiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber
);
36 // BIOS Int 13h, function 0 - Reset disk system
38 // DL = drive (if bit 7 is set both hard disks and floppy disks reset)
41 // CF clear if successful
44 RegsIn
.b
.dl
= DriveNumber
;
46 // Reset the disk controller
47 Int386(0x13, &RegsIn
, &RegsOut
);
49 return INT386_SUCCESS(RegsOut
);
52 BOOLEAN
DiskInt13ExtensionsSupported(ULONG DriveNumber
)
57 DPRINTM(DPRINT_DISK
, "DiskInt13ExtensionsSupported()\n");
59 // IBM/MS INT 13 Extensions - INSTALLATION CHECK
62 // DL = drive (80h-FFh)
64 // CF set on error (extensions not supported)
65 // AH = 01h (invalid function)
66 // CF clear if successful
67 // BX = AA55h if installed
68 // AH = major version of extensions
70 // 20h = 2.0 / EDD-1.0
71 // 21h = 2.1 / EDD-1.1
74 // CX = API subset support bitmap
75 // DH = extension version (v2.0+ ??? -- not present in 1.x)
77 // Bitfields for IBM/MS INT 13 Extensions API support bitmap
78 // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
79 // Bit 1, removable drive controller functions (AH=45h,46h,48h,49h,INT 15/AH=52h) supported
80 // Bit 2, enhanced disk drive (EDD) functions (AH=48h,AH=4Eh) supported
81 // extended drive parameter table is valid
85 RegsIn
.b
.dl
= DriveNumber
;
87 // Reset the disk controller
88 Int386(0x13, &RegsIn
, &RegsOut
);
90 if (!INT386_SUCCESS(RegsOut
))
92 // CF set on error (extensions not supported)
96 if (RegsOut
.w
.bx
!= 0xAA55)
98 // BX = AA55h if installed
103 // The original check is too strict because some BIOSes report that
104 // extended disk access functions are not suported when booting
105 // from a CD (e.g. Phoenix BIOS v6.00PG). Argh!
107 if (!(RegsOut
.w
.cx
& 0x0001))
109 // CX = API subset support bitmap
110 // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
115 // Use this relaxed check instead
116 if (RegsOut
.w
.cx
== 0x0000)
118 // CX = API subset support bitmap
125 VOID
DiskStopFloppyMotor(VOID
)
127 WRITE_PORT_UCHAR((PUCHAR
)0x3F2, 0);
130 BOOLEAN
DiskGetExtendedDriveParameters(ULONG DriveNumber
, PVOID Buffer
, USHORT BufferSize
)
134 PUSHORT Ptr
= (PUSHORT
)(BIOSCALLBUFFER
);
136 DPRINTM(DPRINT_DISK
, "DiskGetExtendedDriveParameters()\n");
138 // Initialize transfer buffer
141 // BIOS Int 13h, function 48h - Get drive parameters
143 // DL = drive (bit 7 set for hard disk)
144 // DS:SI = result buffer
148 // CF clear if successful
150 // DS:SI -> result buffer
152 RegsIn
.b
.dl
= DriveNumber
;
153 RegsIn
.x
.ds
= BIOSCALLBUFSEGMENT
; // DS:SI -> result buffer
154 RegsIn
.w
.si
= BIOSCALLBUFOFFSET
;
156 // Get drive parameters
157 Int386(0x13, &RegsIn
, &RegsOut
);
159 if (!INT386_SUCCESS(RegsOut
))
164 memcpy(Buffer
, Ptr
, BufferSize
);
167 DPRINTM(DPRINT_DISK
, "size of buffer: %x\n", Ptr
[0]);
168 DPRINTM(DPRINT_DISK
, "information flags: %x\n", Ptr
[1]);
169 DPRINTM(DPRINT_DISK
, "number of physical cylinders on drive: %u\n", *(PULONG
)&Ptr
[2]);
170 DPRINTM(DPRINT_DISK
, "number of physical heads on drive: %u\n", *(PULONG
)&Ptr
[4]);
171 DPRINTM(DPRINT_DISK
, "number of physical sectors per track: %u\n", *(PULONG
)&Ptr
[6]);
172 DPRINTM(DPRINT_DISK
, "total number of sectors on drive: %I64u\n", *(unsigned long long*)&Ptr
[8]);
173 DPRINTM(DPRINT_DISK
, "bytes per sector: %u\n", Ptr
[12]);
176 DPRINTM(DPRINT_DISK
, "EED configuration parameters: %x:%x\n", Ptr
[13], Ptr
[14]);
177 if (Ptr
[13] != 0xffff && Ptr
[14] != 0xffff)
179 PUCHAR SpecPtr
= (PUCHAR
)(ULONG_PTR
)((Ptr
[13] << 4) + Ptr
[14]);
180 DPRINTM(DPRINT_DISK
, "SpecPtr: %x\n", SpecPtr
);
181 DPRINTM(DPRINT_DISK
, "physical I/O port base address: %x\n", *(PUSHORT
)&SpecPtr
[0]);
182 DPRINTM(DPRINT_DISK
, "disk-drive control port address: %x\n", *(PUSHORT
)&SpecPtr
[2]);
183 DPRINTM(DPRINT_DISK
, "drive flags: %x\n", SpecPtr
[4]);
184 DPRINTM(DPRINT_DISK
, "proprietary information: %x\n", SpecPtr
[5]);
185 DPRINTM(DPRINT_DISK
, "IRQ for drive: %u\n", SpecPtr
[6]);
186 DPRINTM(DPRINT_DISK
, "sector count for multi-sector transfers: %u\n", SpecPtr
[7]);
187 DPRINTM(DPRINT_DISK
, "DMA control: %x\n", SpecPtr
[8]);
188 DPRINTM(DPRINT_DISK
, "programmed I/O control: %x\n", SpecPtr
[9]);
189 DPRINTM(DPRINT_DISK
, "drive options: %x\n", *(PUSHORT
)&SpecPtr
[10]);
194 DPRINTM(DPRINT_DISK
, "signature: %x\n", Ptr
[15]);