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

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

Changes to XTIDE Universal BIOS:

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