[165] | 1 | ; Project name : XTIDE Universal BIOS |
---|
| 2 | ; Description : Int 13h function AH=48h, Get Extended Drive Parameters. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team. |
---|
[376] | 7 | ; |
---|
| 8 | ; This program is free software; you can redistribute it and/or modify |
---|
| 9 | ; it under the terms of the GNU General Public License as published by |
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ; (at your option) any later version. |
---|
[526] | 12 | ; |
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful, |
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ; GNU General Public License for more details. |
---|
[526] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
[376] | 19 | |
---|
[165] | 20 | ; Section containing code |
---|
| 21 | SECTION .text |
---|
| 22 | |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ; Int 13h function AH=48h, Get Extended Drive Parameters. |
---|
| 25 | ; |
---|
[533] | 26 | ; It is not completely clear what this function should return as total sector count in some cases. |
---|
| 27 | ; What is certain is that: |
---|
| 28 | ; A) Phoenix Enhanced Disk Drive Specification v3.0 says that P-CHS values |
---|
| 29 | ; are never returned for drives with more than 15,482,880 sectors (16384*15*63). |
---|
| 30 | ; For those drives we can simply return total sector count from |
---|
| 31 | ; ATA ID WORDs 60 and 61 (LBA28) or WORDs 100-103 (LBA48). |
---|
| 32 | ; B) IBM PC DOS 7.1 fdisk32 displays warning message if P-CHS values multiplied |
---|
| 33 | ; together are different than total sector count. Therefore for drives with less |
---|
| 34 | ; than or equal 15,482,880 sectors we MUST NOT return total sector count from |
---|
| 35 | ; ATA ID WORDs 60 and 61. |
---|
| 36 | ; |
---|
| 37 | ; Lets take an example. 6 GB Hitachi microdrive reports following values in ATA ID: |
---|
| 38 | ; Sector count from WORDs 60 and 61 : 12,000,556 |
---|
| 39 | ; Cylinders : 11905 |
---|
| 40 | ; Heads : 16 |
---|
| 41 | ; Sectors per track : 63 |
---|
| 42 | ; |
---|
| 43 | ; When multiplying C*H*S we get : 12,000,240 |
---|
| 44 | ; So the CHS size is a little bit less than LBA size. But we must use |
---|
| 45 | ; the smaller value since C*H*S must equal total sector count! |
---|
| 46 | ; |
---|
| 47 | ; Now we get to the uncertain area where I could not find any information. |
---|
| 48 | ; Award BIOS from 1997 Pentium motherboard returns following values: |
---|
| 49 | ; AH=08h L-CHS: 745, 255, 63 (exactly the same as what we return) |
---|
| 50 | ; => Total Sector Count: 745*255*63 = 11,968,425 |
---|
| 51 | ; AH=48h P-CHS: 11873, 16, 63 |
---|
| 52 | ; AH=48h Total Sector Count: 11873* 16*63 = 11,967,984 |
---|
| 53 | ; |
---|
[542] | 54 | ; Notice how AH=48h returns lesser total sector count than AH=08h! The only |
---|
[533] | 55 | ; way I could think of to get 11873 cylinders is to divide AH=08h sector |
---|
| 56 | ; count with P-CHS heads and sectors: (745*255*63) / (16*63) = 11873 |
---|
| 57 | ; |
---|
[542] | 58 | ; The only reason I can think of is that the Award BIOS has a bug and |
---|
| 59 | ; uses L-CHS when it should use P-CHS values in the calculation. |
---|
[533] | 60 | ; |
---|
| 61 | ; |
---|
[165] | 62 | ; AH48h_GetExtendedDriveParameters |
---|
| 63 | ; Parameters: |
---|
| 64 | ; SI: Same as in INTPACK |
---|
| 65 | ; DL: Translated Drive number |
---|
| 66 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
| 67 | ; SS:BP: Ptr to IDEPACK |
---|
| 68 | ; Parameters on INTPACK: |
---|
| 69 | ; DS:SI: Ptr to Extended Drive Information Table to fill |
---|
| 70 | ; Returns with INTPACK: |
---|
| 71 | ; AH: Int 13h return status |
---|
| 72 | ; DS:SI: Ptr to Extended Drive Information Table |
---|
[294] | 73 | ; CF: 0 if successful, 1 if error |
---|
[165] | 74 | ;-------------------------------------------------------------------- |
---|
| 75 | AH48h_HandlerForGetExtendedDriveParameters: |
---|
[535] | 76 | mov si, di |
---|
| 77 | push ds |
---|
| 78 | pop es ; ES = RAMVARS segment |
---|
| 79 | xor bx, bx |
---|
| 80 | dec bx ; Set to FFFFh to assume we do not return DPTE |
---|
[167] | 81 | |
---|
[535] | 82 | ; Create DPTE (hardware information for device drivers) |
---|
[550] | 83 | %ifdef MODULE_COMPATIBLE_TABLES |
---|
[535] | 84 | call AH41h_GetSupportBitsToCX |
---|
| 85 | test cl, ENHANCED_DISK_DRIVE_SUPPORT |
---|
| 86 | jz SHORT .DoNotCreateDPTE |
---|
[541] | 87 | call CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI |
---|
[535] | 88 | .DoNotCreateDPTE: |
---|
[550] | 89 | %endif ; MODULE_COMPATIBLE_TABLES |
---|
[535] | 90 | |
---|
| 91 | ; Point DS:DI to Extended Drive Information Table to fill |
---|
| 92 | mov di, [bp+IDEPACK.intpack+INTPACK.si] |
---|
[169] | 93 | mov ds, [bp+IDEPACK.intpack+INTPACK.ds] |
---|
[535] | 94 | |
---|
| 95 | ; Check and adjust Extended Drive Information Table size |
---|
| 96 | ; to MINIMUM_EDRIVEINFO_SIZE or EDRIVEINFO_SIZE_WITH_DPTE |
---|
| 97 | mov ax, MINIMUM_EDRIVEINFO_SIZE |
---|
| 98 | mov cx, [di+EDRIVE_INFO.wSize] |
---|
| 99 | cmp cx, ax |
---|
[332] | 100 | jb Prepare_ReturnFromInt13hWithInvalidFunctionError |
---|
[535] | 101 | mov [di+EDRIVE_INFO.wSize], ax |
---|
| 102 | add al, EDRIVEINFO_SIZE_WITH_DPTE - MINIMUM_EDRIVEINFO_SIZE |
---|
| 103 | cmp cx, ax |
---|
| 104 | jb SHORT .SkipEddConfigurationParameters |
---|
| 105 | mov [di+EDRIVE_INFO.wSize], ax |
---|
[165] | 106 | |
---|
[535] | 107 | ; Store DPTE for standard controllers only, |
---|
| 108 | ; FFFF:FFFF for non standard controllers |
---|
[550] | 109 | %ifdef MODULE_COMPATIBLE_TABLES |
---|
[535] | 110 | mov [di+EDRIVE_INFO.fpDPTE], bx |
---|
| 111 | mov [di+EDRIVE_INFO.fpDPTE+2], es |
---|
| 112 | inc bx |
---|
| 113 | jnz SHORT .SkipEddConfigurationParameters ; Already stored |
---|
| 114 | dec bx |
---|
| 115 | mov [di+EDRIVE_INFO.fpDPTE+2], bx ; Segment = FFFFh |
---|
| 116 | %else |
---|
| 117 | mov [di+EDRIVE_INFO.fpDPTE], bx |
---|
| 118 | mov [di+EDRIVE_INFO.fpDPTE+2], bx |
---|
[550] | 119 | %endif ; MODULE_COMPATIBLE_TABLES |
---|
[167] | 120 | |
---|
[535] | 121 | ; Fill Extended Drive Information Table in DS:DI from DPT in ES:SI |
---|
[167] | 122 | .SkipEddConfigurationParameters: |
---|
[535] | 123 | mov WORD [di+EDRIVE_INFO.wFlags], FLG_DMA_BOUNDARY_ERRORS_HANDLED_BY_BIOS |
---|
[165] | 124 | |
---|
[324] | 125 | ; Store total sector count |
---|
[535] | 126 | call Registers_ExchangeDSSIwithESDI |
---|
| 127 | call AccessDPT_GetLbaSectorCountToBXDXAX |
---|
| 128 | call Registers_ExchangeDSSIwithESDI |
---|
| 129 | mov [di+EDRIVE_INFO.qwTotalSectors], ax |
---|
| 130 | mov [di+EDRIVE_INFO.qwTotalSectors+2], dx |
---|
| 131 | mov [di+EDRIVE_INFO.qwTotalSectors+4], bx |
---|
[530] | 132 | xor cx, cx |
---|
[535] | 133 | mov [di+EDRIVE_INFO.qwTotalSectors+6], cx ; Always zero |
---|
| 134 | mov WORD [di+EDRIVE_INFO.wSectorSize], 512 |
---|
[169] | 135 | |
---|
[530] | 136 | ; Store P-CHS. Based on phoenix specification this is returned only if |
---|
| 137 | ; total sector count is 15,482,880 or less. |
---|
[544] | 138 | sub ax, (MAX_SECTOR_COUNT_TO_RETURN_PCHS+1) & 0FFFFh |
---|
| 139 | sbb dx, (MAX_SECTOR_COUNT_TO_RETURN_PCHS+1) >> 16 |
---|
[530] | 140 | sbb bx, cx ; Zero |
---|
[545] | 141 | jnc SHORT .DoNotSetChsFlag |
---|
[542] | 142 | or BYTE [di+EDRIVE_INFO.wFlags], FLG_CHS_INFORMATION_IS_VALID |
---|
[530] | 143 | |
---|
[545] | 144 | ; We store something to P-CHS anyway since some HW detection programs |
---|
| 145 | ; ignore the CHS flag. And we should at least clear the variables anyway |
---|
| 146 | ; since the same buffer is used for all drives so it contains parameters |
---|
| 147 | ; from previously scanned drive. |
---|
| 148 | .DoNotSetChsFlag: |
---|
[568] | 149 | eMOVZX dx, [es:si+DPT.bPchsHeads] |
---|
[535] | 150 | mov [di+EDRIVE_INFO.dwHeads], dx |
---|
| 151 | mov [di+EDRIVE_INFO.dwHeads+2], cx |
---|
[421] | 152 | |
---|
[535] | 153 | mov dl, [es:si+DPT.bPchsSectorsPerTrack] |
---|
| 154 | mov [di+EDRIVE_INFO.dwSectorsPerTrack], dx |
---|
| 155 | mov [di+EDRIVE_INFO.dwSectorsPerTrack+2], cx |
---|
[421] | 156 | |
---|
[535] | 157 | mov dx, [es:si+DPT.wPchsCylinders] |
---|
| 158 | mov [di+EDRIVE_INFO.dwCylinders], dx |
---|
| 159 | mov [di+EDRIVE_INFO.dwCylinders+2], cx |
---|
[421] | 160 | |
---|
[568] | 161 | xor ax, ax ; Success |
---|
[165] | 162 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|