1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for accessing DPT data.
|
---|
3 |
|
---|
4 | ;
|
---|
5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
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.
|
---|
12 | ;
|
---|
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.
|
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
18 | ;
|
---|
19 |
|
---|
20 | ; Section containing code
|
---|
21 | SECTION .text
|
---|
22 |
|
---|
23 | %ifdef MODULE_ADVANCED_ATA
|
---|
24 | ;--------------------------------------------------------------------
|
---|
25 | ; AccessDPT_GetIdeBasePortToBX
|
---|
26 | ; Parameters:
|
---|
27 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
28 | ; Returns:
|
---|
29 | ; BX: IDE Base Port Address
|
---|
30 | ; Corrupts registers:
|
---|
31 | ; Nothing
|
---|
32 | ;--------------------------------------------------------------------
|
---|
33 | ALIGN JUMP_ALIGN
|
---|
34 | AccessDPT_GetIdeBasePortToBX:
|
---|
35 | eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
|
---|
36 | mov bx, [cs:bx+IDEVARS.wPort]
|
---|
37 | ret
|
---|
38 |
|
---|
39 | %endif
|
---|
40 |
|
---|
41 |
|
---|
42 | ;--------------------------------------------------------------------
|
---|
43 | ; AccessDPT_GetDriveSelectByteToAL
|
---|
44 | ; Parameters:
|
---|
45 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
46 | ; Returns:
|
---|
47 | ; AL: Drive Select Byte
|
---|
48 | ; Corrupts registers:
|
---|
49 | ; Nothing
|
---|
50 | ;--------------------------------------------------------------------
|
---|
51 | ALIGN JUMP_ALIGN
|
---|
52 | AccessDPT_GetDriveSelectByteToAL:
|
---|
53 | mov al, [di+DPT.wFlags]
|
---|
54 | and al, FLG_DRVNHEAD_LBA | FLG_DRVNHEAD_DRV
|
---|
55 | or al, MASK_DRVNHEAD_SET ; Bits set to 1 for old drives
|
---|
56 | ret
|
---|
57 |
|
---|
58 |
|
---|
59 | ;--------------------------------------------------------------------
|
---|
60 | ; AccessDPT_GetDeviceControlByteToAL
|
---|
61 | ; Parameters:
|
---|
62 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
63 | ; Returns:
|
---|
64 | ; AL: Device Control Byte
|
---|
65 | ; Corrupts registers:
|
---|
66 | ; Nothing
|
---|
67 | ;--------------------------------------------------------------------
|
---|
68 | ALIGN JUMP_ALIGN
|
---|
69 | AccessDPT_GetDeviceControlByteToAL:
|
---|
70 | xor al, al
|
---|
71 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ
|
---|
72 | jnz SHORT .EnableDeviceIrq
|
---|
73 | or al, FLG_DEVCONTROL_nIEN ; Disable IRQ
|
---|
74 | .EnableDeviceIrq:
|
---|
75 | ret
|
---|
76 |
|
---|
77 |
|
---|
78 | ;--------------------------------------------------------------------
|
---|
79 | ; AccessDPT_GetLCHStoAXBLBH
|
---|
80 | ; Parameters:
|
---|
81 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
82 | ; Returns:
|
---|
83 | ; AX: Number of L-CHS cylinders
|
---|
84 | ; BL: Number of L-CHS heads
|
---|
85 | ; BH: Number of L-CHS sectors per track
|
---|
86 | ; Corrupts registers:
|
---|
87 | ; CX, DX
|
---|
88 | ;--------------------------------------------------------------------
|
---|
89 | AccessDPT_GetLCHStoAXBLBH:
|
---|
90 | ; Return LBA-assisted CHS if LBA addressing used
|
---|
91 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
|
---|
92 | jz SHORT .ConvertPchsToLchs
|
---|
93 |
|
---|
94 | call AccessDPT_GetLbaSectorCountToBXDXAX
|
---|
95 | call LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
|
---|
96 | LIMIT_LBA_CYLINDERS_IN_DXAX_TO_LCHS_CYLINDERS
|
---|
97 | ret
|
---|
98 |
|
---|
99 | .ConvertPchsToLchs:
|
---|
100 | mov ax, [di+DPT.wPchsCylinders]
|
---|
101 | mov bx, [di+DPT.wPchsHeadsAndSectors]
|
---|
102 | ; Fall to AccessDPT_ShiftPCHinAXBLtoLCH
|
---|
103 |
|
---|
104 |
|
---|
105 | ;--------------------------------------------------------------------
|
---|
106 | ; AccessDPT_ShiftPCHinAXBLtoLCH
|
---|
107 | ; Parameters:
|
---|
108 | ; AX: P-CHS cylinders (1...16383)
|
---|
109 | ; BL: P-CHS heads (1...16)
|
---|
110 | ; Returns:
|
---|
111 | ; AX: Number of L-CHS cylinders (1...1024)
|
---|
112 | ; BL: Number of L-CHS heads (1...255)
|
---|
113 | ; CX: Number of bits shifted (4 at most)
|
---|
114 | ; Corrupts registers:
|
---|
115 | ; Nothing
|
---|
116 | ;--------------------------------------------------------------------
|
---|
117 | AccessDPT_ShiftPCHinAXBLtoLCH:
|
---|
118 | xor cx, cx
|
---|
119 | .ShiftLoop:
|
---|
120 | cmp ax, MAX_LCHS_CYLINDERS ; Need to shift?
|
---|
121 | jbe SHORT .Return ; If not, return
|
---|
122 | inc cx ; Increment shift count
|
---|
123 | shr ax, 1 ; Halve cylinders
|
---|
124 | shl bl, 1 ; Double heads
|
---|
125 | jnz SHORT .ShiftLoop ; Falls through only on the last (4th) iteration and only if BL was 16 on entry
|
---|
126 | dec bl ; DOS doesn't support drives with 256 heads so we limit heads to 255
|
---|
127 | ; We can save a byte here by using DEC BX if we don't care about BH
|
---|
128 | .Return:
|
---|
129 | ret
|
---|
130 |
|
---|
131 |
|
---|
132 | ;--------------------------------------------------------------------
|
---|
133 | ; AccessDPT_GetLbaSectorCountToBXDXAX
|
---|
134 | ; Parameters:
|
---|
135 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
136 | ; Returns:
|
---|
137 | ; BX:DX:AX: 48-bit sector count
|
---|
138 | ; Corrupts registers:
|
---|
139 | ; Nothing
|
---|
140 | ;--------------------------------------------------------------------
|
---|
141 | AccessDPT_GetLbaSectorCountToBXDXAX:
|
---|
142 | mov ax, [di+DPT.twLbaSectors]
|
---|
143 | mov dx, [di+DPT.twLbaSectors+2]
|
---|
144 | mov bx, [di+DPT.twLbaSectors+4]
|
---|
145 | ret
|
---|
146 |
|
---|
147 |
|
---|
148 | ;--------------------------------------------------------------------
|
---|
149 | ; Returns pointer to DRVPARAMS for master or slave drive.
|
---|
150 | ;
|
---|
151 | ; AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
152 | ; Parameters:
|
---|
153 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
154 | ; Returns:
|
---|
155 | ; CS:BX: Ptr to DRVPARAMS
|
---|
156 | ; Corrupts registers:
|
---|
157 | ; Nothing
|
---|
158 | ;--------------------------------------------------------------------
|
---|
159 | ALIGN JUMP_ALIGN
|
---|
160 | AccessDPT_GetPointerToDRVPARAMStoCSBX:
|
---|
161 | eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
|
---|
162 | add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS
|
---|
163 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
|
---|
164 | jz SHORT .ReturnPointerToDRVPARAMS
|
---|
165 | add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS
|
---|
166 | .ReturnPointerToDRVPARAMS:
|
---|
167 | ret
|
---|
168 |
|
---|
169 | ;--------------------------------------------------------------------
|
---|
170 | ; AccessDPT_GetUnshiftedAddressModeToALZF
|
---|
171 | ; Parameters:
|
---|
172 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
173 | ; Returns:
|
---|
174 | ; AL: Addressing Mode (L-CHS, P-CHS, LBA28, LBA48)
|
---|
175 | ; unshifted (still shifted where it is in bFlagsLow)
|
---|
176 | ; ZF: Set based on value in AL
|
---|
177 | ; Corrupts registers:
|
---|
178 | ; AL
|
---|
179 | ;--------------------------------------------------------------------
|
---|
180 | ;
|
---|
181 | ; Converted to a macro since only called in two places, and the call/ret overhead
|
---|
182 | ; is not worth it for these two instructions (4 bytes total)
|
---|
183 | ;
|
---|
184 | %macro AccessDPT_GetUnshiftedAddressModeToALZF 0
|
---|
185 | mov al, [di+DPT.bFlagsLow]
|
---|
186 | and al, MASKL_DPT_ADDRESSING_MODE
|
---|
187 | %endmacro
|
---|