source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm

Last change on this file was 618, checked in by krille_n_, 3 years ago

Changes:

  • Updated the BIOS makefile. Added the NO_ATAID_CORRECTION define back to the Tiny build as I've realized that the correction code should not be needed for builds without MODULE_EBIOS. Also added a new makefile target 'custom' to make it easier for people to make custom builds.
  • Fixed a bug where calling INT 13h/AH=15h for drives not handled by XUB (floppy drives for example) would return an error due to the fact that any non-zero return value in AH from the other BIOS would cause the CF to be set in Int13h_SetErrorCodeToIntpackInSSBPfromAH. The return path is now via Int13h_ReturnFromHandlerWithoutStoringErrorCode which means that no status/error code will be returned in the BDA but that should not be a problem as the other BIOS should do that anyway. This change also fixed another potential problem where return values in DL from the other BIOS were assumed to be drive numbers when MODULE_SERIAL_FLOPPY is included in the build.
  • Minor optimizations and fixes.
File size: 6.8 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Functions for address translations.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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;---------------------------------------------------------------------
24; Address_ExtractLCHSparametersFromOldInt13hAddress
25;   Parameters:
26;       CH:     Cylinder number, bits 7...0
27;       CL:     Bits 7...6: Cylinder number bits 9 and 8
28;               Bits 5...0: Sector number
29;       DH:     Head number
30;   Returns:
31;       BL:     Sector number (1...63)
32;       BH:     Head number (0...255)
33;       CX:     Cylinder number (0...1023)
34;   Corrupts registers:
35;       Nothing
36;--------------------------------------------------------------------
37ALIGN JUMP_ALIGN
38Address_ExtractLCHSparametersFromOldInt13hAddress:
39    mov     bl, 3Fh             ; Load sector number mask
40    and     bl, cl              ; Sector number now in BL
41%ifndef USE_186
42    sub     cl, bl              ; Remove from cylinder number high
43    rol     cl, 1               ; High bits to beginning
44    rol     cl, 1
45%else
46    shr     cl, 6
47%endif
48    mov     bh, dh              ; Copy Head number
49    xchg    cl, ch              ; Cylinder number now in CX
50    ret
51
52
53;---------------------------------------------------------------------
54; Converts LARGE addressing mode LCHS parameters to IDE P-CHS parameters.
55; PCylinder = (LCylinder << n) + (LHead / PHeadCount)
56; PHead     = LHead % PHeadCount
57; PSector   = LSector
58;
59; ConvertLargeModeLCHStoPCHS:
60;   Parameters:
61;       BL:     Sector number (1...63)
62;       BH:     Head number (0...239)
63;       CX:     Cylinder number (0...1023)
64;       DS:DI:  Ptr to Disk Parameter Table
65;   Returns:
66;       BL:     Sector number (1...63)
67;       BH:     Head number (0...15)
68;       CX:     Cylinder number (0...16382)
69;   Corrupts registers:
70;       AX, DX
71;--------------------------------------------------------------------
72ALIGN JUMP_ALIGN
73ConvertLargeModeLCHStoPCHS:
74    ; LHead / PHeadCount and LHead % PHeadCount
75    eMOVZX  ax, bh                  ; Copy L-CHS Head number to AX
76    div     BYTE [di+DPT.bPchsHeads]; AL = LHead / PHeadCount, AH = LHead % PHeadCount
77    mov     bh, ah                  ; Copy P-CHS Head number to BH
78    xor     ah, ah                  ; AX = LHead / PHeadCount
79
80    ; (LCylinder << n) + (LHead / PHeadCount)
81    mov     dx, cx                  ; Copy L-CHS Cylinder number to DX
82    mov     cl, MASKL_DPT_CHS_SHIFT_COUNT   ; Load shift count mask
83    and     cl, [di+DPT.bFlagsLow]  ; Shift count now in CL
84    shl     dx, cl                  ; DX = LCylinder << n
85    add     ax, dx                  ; AX = P-CHS Cylinder number
86    xchg    cx, ax                  ; Move P-CHS Cylinder number to CX
87DoNotConvertLCHS:
88    ret
89
90; *FIXME* The above function description doesn't match the code.
91; If CX has a maximum value of 1023 on entry then there is no way CX can be 16382 on return.
92; 1023 SHL 3 (MASKL_DPT_CHS_SHIFT_COUNT) is 8184. With the addition of AX (at most 255?)
93; the result is 8439.
94
95;--------------------------------------------------------------------
96; Address_OldInt13hAddressToIdeAddress
97;   Parameters:
98;       CH:     Cylinder number, bits 7...0
99;       CL:     Bits 7...6: Cylinder number bits 9 and 8
100;               Bits 5...0: Starting sector number (1...63)
101;       DH:     Starting head number (0...255)
102;       DS:DI:  Ptr to DPT
103;   Returns:
104;       BL:     LBA Low Register / Sector Number Register (LBA 7...0)
105;       CL:     LBA Mid Register / Low Cylinder Register (LBA 15...8)
106;       CH:     LBA High Register / High Cylinder Register (LBA 23...16)
107;       BH:     Drive and Head Register (LBA 27...24)
108;   Corrupts registers:
109;       AX, DX
110;--------------------------------------------------------------------
111ALIGN JUMP_ALIGN
112Address_OldInt13hAddressToIdeAddress:
113    call    Address_ExtractLCHSparametersFromOldInt13hAddress
114    mov     al, [di+DPT.bFlagsLow]
115    and     al, MASKL_DPT_TRANSLATEMODE
116
117;;; 0: TRANSLATEMODE_NORMAL
118    jz      SHORT DoNotConvertLCHS
119
120;;; 1: TRANSLATEMODE_LARGE
121    test    al, FLGL_DPT_ASSISTED_LBA
122    jz      SHORT ConvertLargeModeLCHStoPCHS
123
124;;; 2: TRANSLATEMODE_ASSISTED_LBA
125    ; Fall to ConvertAssistedLBAModeLCHStoLBARegisterValues
126
127
128;---------------------------------------------------------------------
129; Converts LCHS parameters to 28-bit LBA address.
130; Only 24-bits are used since LHCS to LBA28 conversion has 8.4GB limit.
131; LBA = ((cylToSeek*headsPerCyl+headToSeek)*sectPerTrack)+sectToSeek-1
132; headsPerCyl and sectPerTrack are the current translation values (L-CHS).
133;
134; Returned address is in same registers that
135; DoNotConvertLCHS and ConvertLargeModeLCHStoPCHS returns.
136;
137; ConvertAssistedLBAModeLCHStoLBARegisterValues:
138;   Parameters:
139;       BL:     Sector number (1...63)
140;       BH:     Head number (0...254)
141;       CX:     Cylinder number (0...1023)
142;       DS:DI:  Ptr to Disk Parameter Table
143;   Returns:
144;       BL:     LBA Low Register / Sector Number Register (LBA 7...0)
145;       CL:     LBA Mid Register / Low Cylinder Register (LBA 15...8)
146;       CH:     LBA High Register / High Cylinder Register (LBA 23...16)
147;       BH:     Drive and Head Register (LBA 27...24)
148;   Corrupts registers:
149;       AX, DX
150;--------------------------------------------------------------------
151ConvertAssistedLBAModeLCHStoLBARegisterValues:
152    ; cylToSeek*headsPerCyl (18-bit result)
153    ; Max = 1023 * 255 = 260,865 = 3FB01h
154    mov     ax, LBA_ASSIST_SPT      ; Load Sectors per Track
155    xchg    cx, ax                  ; Cylinder number to AX, Sectors per Track to CX
156%ifdef USE_386
157    movzx   dx, [di+DPT.bLchsHeads]
158%else
159    cwd
160    mov     dl, [di+DPT.bLchsHeads]
161%endif
162    mul     dx                      ; DX:AX = cylToSeek*headsPerCyl
163
164    ; +=headToSeek (18-bit result)
165    ; Max = 260,865 + 254 = 261,119 = 3FBFFh
166    add     al, bh                  ; Add Head number to DX:AX
167    adc     ah, dh                  ; DH = Zero after previous multiplication
168    adc     dl, dh
169
170    ; *=sectPerTrack (18-bit by 6-bit multiplication with 24-bit result)
171    ; Max = 261,119 * 63 = 16,450,497 = FB03C1h
172    xchg    ax, dx                  ; Hiword to AX, loword to DX
173    mul     cl                      ; AX = hiword * Sectors per Track
174    mov     bh, al                  ; Backup hiword * Sectors per Track
175    xchg    ax, dx                  ; Loword back to AX
176    mul     cx                      ; DX:AX = loword * Sectors per Track
177    add     dl, bh                  ; DX:AX = (cylToSeek*headsPerCyl+headToSeek)*sectPerTrack
178
179    ; +=sectToSeek-1 (24-bit result)
180    ; Max = 16,450,497 + 63 - 1 = 16,450,559 = FB03FFh
181    mov     bh, ch                  ; Sector number now in BX, CH=zero
182    dec     bx                      ; sectToSeek-=1
183    add     bx, ax                  ; Add loword to BX (BL = Sector Number Register (LBA 7...0))
184    adc     ch, dl                  ; Add possible carry to byte2 (CH = High Cylinder Register (LBA 23...16))
185    mov     cl, bh                  ; CL = Low Cylinder Register (LBA 15...8)
186    mov     bh, dh                  ; BH = Drive and Head Register (LBA 27...24)
187    ret
Note: See TracBrowser for help on using the repository browser.