source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm@ 416

Last change on this file since 416 was 411, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Moved some IRQ and LBA48 code to related modules.
File size: 6.1 KB
Line 
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
21SECTION .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;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34AccessDPT_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;--------------------------------------------------------------------
51ALIGN JUMP_ALIGN
52AccessDPT_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;--------------------------------------------------------------------
68ALIGN JUMP_ALIGN
69AccessDPT_GetDeviceControlByteToAL:
70%ifdef MODULE_IRQ
71 xor al, al
72 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ
73 jnz SHORT .EnableDeviceIrq
74 or al, FLG_DEVCONTROL_nIEN ; Disable IRQ
75.EnableDeviceIrq:
76%else
77 mov al, FLG_DEVCONTROL_nIEN ; Disable IRQ
78%endif
79 ret
80
81
82;--------------------------------------------------------------------
83; AccessDPT_GetLCHStoAXBLBH
84; Parameters:
85; DS:DI: Ptr to Disk Parameter Table
86; Returns:
87; AX: Number of L-CHS cylinders
88; BL: Number of L-CHS heads
89; BH: Number of L-CHS sectors per track
90; Corrupts registers:
91; CX, DX
92;--------------------------------------------------------------------
93AccessDPT_GetLCHStoAXBLBH:
94 ; Return LBA-assisted CHS if LBA addressing used
95 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
96 jz SHORT .ConvertPchsToLchs
97
98 call AccessDPT_GetLbaSectorCountToBXDXAX
99 call LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
100 LIMIT_LBA_CYLINDERS_IN_DXAX_TO_LCHS_CYLINDERS
101 ret
102
103.ConvertPchsToLchs:
104 mov ax, [di+DPT.wPchsCylinders]
105 mov bx, [di+DPT.wPchsHeadsAndSectors]
106 ; Fall to AccessDPT_ShiftPCHinAXBLtoLCH
107
108
109;--------------------------------------------------------------------
110; AccessDPT_ShiftPCHinAXBLtoLCH
111; Parameters:
112; AX: P-CHS cylinders (1...16383)
113; BL: P-CHS heads (1...16)
114; Returns:
115; AX: Number of L-CHS cylinders (1...1024)
116; BL: Number of L-CHS heads (1...255)
117; CX: Number of bits shifted (4 at most)
118; Corrupts registers:
119; Nothing
120;--------------------------------------------------------------------
121AccessDPT_ShiftPCHinAXBLtoLCH:
122 xor cx, cx
123.ShiftLoop:
124 cmp ax, MAX_LCHS_CYLINDERS ; Need to shift?
125 jbe SHORT .Return ; If not, return
126 inc cx ; Increment shift count
127 shr ax, 1 ; Halve cylinders
128 shl bl, 1 ; Double heads
129 jnz SHORT .ShiftLoop ; Falls through only on the last (4th) iteration and only if BL was 16 on entry
130 dec bl ; DOS doesn't support drives with 256 heads so we limit heads to 255
131 ; We can save a byte here by using DEC BX if we don't care about BH
132.Return:
133 ret
134
135
136;--------------------------------------------------------------------
137; AccessDPT_GetLbaSectorCountToBXDXAX
138; Parameters:
139; DS:DI: Ptr to Disk Parameter Table
140; Returns:
141; BX:DX:AX: 48-bit sector count
142; Corrupts registers:
143; Nothing
144;--------------------------------------------------------------------
145AccessDPT_GetLbaSectorCountToBXDXAX:
146 mov ax, [di+DPT.twLbaSectors]
147 mov dx, [di+DPT.twLbaSectors+2]
148 mov bx, [di+DPT.twLbaSectors+4]
149 ret
150
151
152;--------------------------------------------------------------------
153; Returns pointer to DRVPARAMS for master or slave drive.
154;
155; AccessDPT_GetPointerToDRVPARAMStoCSBX
156; Parameters:
157; DS:DI: Ptr to Disk Parameter Table
158; Returns:
159; CS:BX: Ptr to DRVPARAMS
160; Corrupts registers:
161; Nothing
162;--------------------------------------------------------------------
163ALIGN JUMP_ALIGN
164AccessDPT_GetPointerToDRVPARAMStoCSBX:
165 eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
166 add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS
167 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
168 jz SHORT .ReturnPointerToDRVPARAMS
169 add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS
170.ReturnPointerToDRVPARAMS:
171 ret
172
173;--------------------------------------------------------------------
174; AccessDPT_GetUnshiftedAddressModeToALZF
175; Parameters:
176; DS:DI: Ptr to Disk Parameter Table
177; Returns:
178; AL: Addressing Mode (L-CHS, P-CHS, LBA28, LBA48)
179; unshifted (still shifted where it is in bFlagsLow)
180; ZF: Set based on value in AL
181; Corrupts registers:
182; AL
183;--------------------------------------------------------------------
184;
185; Converted to a macro since only called in two places, and the call/ret overhead
186; is not worth it for these two instructions (4 bytes total)
187;
188%macro AccessDPT_GetUnshiftedAddressModeToALZF 0
189 mov al, [di+DPT.bFlagsLow]
190 and al, MASKL_DPT_ADDRESSING_MODE
191%endmacro
Note: See TracBrowser for help on using the repository browser.