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

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

Changes to XTIDE Universal BIOS:

  • Moved some IRQ and LBA48 code to related modules.
File size: 6.1 KB
RevLine 
[99]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Functions for accessing DPT data.
3
[376]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
[3]20; Section containing code
21SECTION .text
22
[364]23%ifdef MODULE_ADVANCED_ATA
[3]24;--------------------------------------------------------------------
[364]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;--------------------------------------------------------------------
[150]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:
[411]70%ifdef MODULE_IRQ
[150]71    xor     al, al
[158]72    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ
[150]73    jnz     SHORT .EnableDeviceIrq
74    or      al, FLG_DEVCONTROL_nIEN ; Disable IRQ
75.EnableDeviceIrq:
[411]76%else
77    mov     al, FLG_DEVCONTROL_nIEN ; Disable IRQ
78%endif
[150]79    ret
80
[227]81
[150]82;--------------------------------------------------------------------
[227]83; AccessDPT_GetLCHStoAXBLBH
[3]84;   Parameters:
85;       DS:DI:  Ptr to Disk Parameter Table
86;   Returns:
[227]87;       AX:     Number of L-CHS cylinders
88;       BL:     Number of L-CHS heads
89;       BH:     Number of L-CHS sectors per track
[3]90;   Corrupts registers:
[227]91;       CX, DX
[3]92;--------------------------------------------------------------------
[227]93AccessDPT_GetLCHStoAXBLBH:
94    ; Return LBA-assisted CHS if LBA addressing used
[173]95    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
[227]96    jz      SHORT .ConvertPchsToLchs
[173]97
[227]98    call    AccessDPT_GetLbaSectorCountToBXDXAX
[358]99    call    LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
100    LIMIT_LBA_CYLINDERS_IN_DXAX_TO_LCHS_CYLINDERS
[227]101    ret
[173]102
[227]103.ConvertPchsToLchs:
104    mov     ax, [di+DPT.wPchsCylinders]
105    mov     bx, [di+DPT.wPchsHeadsAndSectors]
[230]106    ; Fall to AccessDPT_ShiftPCHinAXBLtoLCH
[227]107
108
109;--------------------------------------------------------------------
110; AccessDPT_ShiftPCHinAXBLtoLCH
[173]111;   Parameters:
[227]112;       AX:     P-CHS cylinders (1...16383)
113;       BL:     P-CHS heads (1...16)
[173]114;   Returns:
[227]115;       AX:     Number of L-CHS cylinders (1...1024)
116;       BL:     Number of L-CHS heads (1...255)
[230]117;       CX:     Number of bits shifted (4 at most)
[173]118;   Corrupts registers:
119;       Nothing
120;--------------------------------------------------------------------
[227]121AccessDPT_ShiftPCHinAXBLtoLCH:
[173]122    xor     cx, cx
123.ShiftLoop:
[227]124    cmp     ax, MAX_LCHS_CYLINDERS      ; Need to shift?
[231]125    jbe     SHORT .Return               ;  If not, return
[173]126    inc     cx                          ; Increment shift count
[227]127    shr     ax, 1                       ; Halve cylinders
128    shl     bl, 1                       ; Double heads
[231]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:
[173]133    ret
134
[227]135
[173]136;--------------------------------------------------------------------
[230]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;--------------------------------------------------------------------
[3]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:
[150]165    eMOVZX  bx, [di+DPT.bIdevarsOffset]         ; CS:BX points to IDEVARS
166    add     bx, BYTE IDEVARS.drvParamsMaster    ; CS:BX points to Master Drive DRVPARAMS
[158]167    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
[150]168    jz      SHORT .ReturnPointerToDRVPARAMS
169    add     bx, BYTE DRVPARAMS_size             ; CS:BX points to Slave Drive DRVPARAMS
170.ReturnPointerToDRVPARAMS:
[3]171    ret
[200]172
173;--------------------------------------------------------------------
174; AccessDPT_GetUnshiftedAddressModeToALZF
175;   Parameters:
176;       DS:DI:  Ptr to Disk Parameter Table
177;   Returns:
[230]178;       AL:     Addressing Mode (L-CHS, P-CHS, LBA28, LBA48)
[200]179;               unshifted (still shifted where it is in bFlagsLow)
180;       ZF:     Set based on value in AL
181;   Corrupts registers:
182;       AL
183;--------------------------------------------------------------------
[230]184;
185; Converted to a macro since only called in two places, and the call/ret overhead
[200]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.