source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm @ 258

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

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

File size: 9.1 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Functions for creating Disk Parameter Table.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Creates new Disk Parameter Table for detected hard disk.
9; Drive is then fully accessible using any BIOS function.
10;
11; CreateDPT_FromAtaInformation
12;   Parameters:
13;       BH:     Drive Select byte for Drive and Head Register
14;       ES:SI:  Ptr to 512-byte ATA information read from the drive
15;       CS:BP:  Ptr to IDEVARS for the controller
16;       DS:     RAMVARS segment
17;       ES:     BDA Segment
18;   Returns:
19;       DL:     Drive number for new drive
20;       DS:DI:  Ptr to Disk Parameter Table (if succesfull)
21;       CF:     Cleared if DPT created successfully
22;               Set if any error
23;   Corrupts registers:
24;       AX, BX, CX, DH
25;--------------------------------------------------------------------
26CreateDPT_FromAtaInformation:
27    call    FindDPT_ForNewDriveToDSDI
28    ; Fall to .InitializeDPT
29
30;--------------------------------------------------------------------
31; .InitializeDPT
32;   Parameters:
33;       BH:     Drive Select byte for Drive and Head Register
34;       DS:DI:  Ptr to Disk Parameter Table
35;       CS:BP:  Ptr to IDEVARS for the controller
36;   Returns:
37;       Nothing
38;   Corrupts registers:
39;       AX
40;--------------------------------------------------------------------
41.InitializeDPT:
42    mov     [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
43    ; Fall to .StoreDriveSelectAndDriveControlByte
44
45;--------------------------------------------------------------------
46; .StoreDriveSelectAndDriveControlByte
47;   Parameters:
48;       BH:     Drive Select byte for Drive and Head Register
49;       DS:DI:  Ptr to Disk Parameter Table
50;       ES:SI:  Ptr to 512-byte ATA information read from the drive
51;       CS:BP:  Ptr to IDEVARS for the controller
52;   Returns:
53;       Nothing
54;   Corrupts registers:
55;       AX
56;--------------------------------------------------------------------
57.StoreDriveSelectAndDriveControlByte:
58    mov     al, bh
59    and     ax, BYTE FLG_DRVNHEAD_DRV       ; AL now has Master/Slave bit
60    cmp     [cs:bp+IDEVARS.bIRQ], ah        ; Interrupts enabled?
61    jz      SHORT .StoreFlags               ;  If not, do not set interrupt flag
62    or      al, FLGL_DPT_ENABLE_IRQ
63.StoreFlags:
64    mov     [di+DPT.wFlags], ax
65    ; Fall to .StoreAddressing
66
67;--------------------------------------------------------------------
68; .StoreAddressing
69;   Parameters:
70;       DS:DI:  Ptr to Disk Parameter Table
71;       ES:SI:  Ptr to 512-byte ATA information read from the drive
72;       CS:BP:  Ptr to IDEVARS for the controller
73;   Returns:
74;       Nothing
75;   Corrupts registers:
76;       AX, BX, CX, DX
77;--------------------------------------------------------------------
78.StoreAddressing:
79    ; Check if CHS defined in ROMVARS
80    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
81    test    byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS    ; User specified CHS?
82    jnz     SHORT .StoreUserDefinedPCHS
83
84    ; Check if LBA supported
85    call    AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
86    test    BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
87    jz      SHORT .StoreCHSfromAXBHBL       ; Small old drive with CHS addressing only
88
89    ; Check if 48-bit LBA supported
90    test    BYTE [es:si+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
91    jz      SHORT .StoreLBA28addressing
92    or      BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
93.StoreLBA28addressing:
94    or      BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
95    call    AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
96    mov     [di+DPT.twLbaSectors], ax
97    mov     [di+DPT.twLbaSectors+2], dx
98    mov     [di+DPT.twLbaSectors+4], bx
99    call    AtaID_GetLbaAssistedCHStoDXAXBLBH
100    mov     [di+DPT.bLbaHeads], bl
101    jmp     SHORT .StoreBlockMode
102
103;--------------------------------------------------------------------
104; .StoreUserDefinedPCHS
105;   Parameters:
106;       DS:DI:  Ptr to Disk Parameter Table
107;       ES:SI:  Ptr to 512-byte ATA information read from the drive
108;       CS:BP:  Ptr to IDEVARS for the controller
109;   Returns:
110;       AX:     Number of P-CHS cylinders
111;       BH:     Number of P-CHS sectors per track
112;       BL:     Number of P-CHS heads
113;   Corrupts registers:
114;       Nothing
115;--------------------------------------------------------------------
116.StoreUserDefinedPCHS:
117    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
118    mov     ax, [cs:bx+DRVPARAMS.wCylinders]
119    mov     bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
120    ; Fall to .StoreCHSfromAXBHBL
121
122;--------------------------------------------------------------------
123; .StoreCHSfromAXBHBL
124;   Parameters:
125;       AX:     Number of P-CHS cylinders
126;       BH:     Number of P-CHS sectors per track
127;       BL:     Number of P-CHS heads
128;       DS:DI:  Ptr to Disk Parameter Table
129;       ES:SI:  Ptr to 512-byte ATA information read from the drive
130;       CS:BP:  Ptr to IDEVARS for the controller
131;   Returns:
132;       AX:     Number of P-CHS cylinders
133;       BH:     Number of P-CHS sectors per track
134;       BL:     Number of P-CHS heads
135;   Corrupts registers:
136;       CX
137;--------------------------------------------------------------------
138.StoreCHSfromAXBHBL:
139    push    ax
140    push    bx
141    call    AccessDPT_ShiftPCHinAXBLtoLCH   ; Get number of bits to shift
142    pop     bx
143    pop     ax
144    jcxz    .StorePCHSfromAXDX              ; Small drive so use L-CHS addressing
145
146    ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
147    or      cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
148    or      [di+DPT.bFlagsLow], cl
149    ; Fall to .StoreChsFromAXBLBH
150
151;--------------------------------------------------------------------
152; .StoreChsFromAXBLBH
153;   Parameters:
154;       AX:     Number of P-CHS cylinders
155;       BH:     Number of P-CHS sectors per track
156;       BL:     Number of P-CHS heads
157;       DS:DI:  Ptr to Disk Parameter Table
158;       ES:SI:  Ptr to 512-byte ATA information read from the drive
159;       CS:BP:  Ptr to IDEVARS for the controller
160;   Returns:
161;       Nothing
162;   Corrupts registers:
163;       Nothing
164;--------------------------------------------------------------------
165.StorePCHSfromAXDX:
166    mov     [di+DPT.wPchsCylinders], ax
167    mov     [di+DPT.wPchsHeadsAndSectors], bx
168    ; Fall to .StoreBlockMode
169
170;--------------------------------------------------------------------
171; .StoreBlockMode
172;   Parameters:
173;       DS:DI:  Ptr to Disk Parameter Table
174;       ES:SI:  Ptr to 512-byte ATA information read from the drive
175;       CS:BP:  Ptr to IDEVARS for the controller
176;   Returns:
177;       Nothing
178;   Corrupts registers:
179;       Nothing
180;--------------------------------------------------------------------
181.StoreBlockMode:
182    cmp     BYTE [es:si+ATA1.bBlckSize], 1  ; Max block size in sectors
183    jbe     SHORT .BlockModeTransfersNotSupported
184    or      BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
185.BlockModeTransfersNotSupported:
186    ; Fall to .StoreDeviceSpecificParameters
187
188;--------------------------------------------------------------------
189; .StoreDeviceSpecificParameters
190;   Parameters:
191;       DS:DI:  Ptr to Disk Parameter Table
192;       ES:SI:  Ptr to 512-byte ATA information read from the drive
193;       CS:BP:  Ptr to IDEVARS for the controller
194;   Returns:
195;       Nothing
196;   Corrupts registers:
197;       AX, BX, CX, DX
198;--------------------------------------------------------------------
199.StoreDeviceSpecificParameters:
200    call    Device_FinalizeDPT
201
202%ifdef MODULE_SERIAL_FLOPPY
203;
204; These two instructions serve two purposes:
205; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
206; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is 
207;    effectively discarded.  This is more of a safety check then code that should ever normally be hit (see below).
208;    Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT, 
209;    this was necessary.  Now, this situation shouldn't happen in normal operation, for a couple of reasons:
210;       A. xtidecfg always puts configured serial ports at the end fo the IDEVARS list
211;       B. the auto serial code is always executed last
212;       C. the serial server always returns floppy drives last
213;
214    adc     byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
215    jnz     .AllDone   
216%else
217;
218; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
219; could lead to unpredictable results since no MBR will be present, etc.  The server doesn't know that 
220; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
221;
222    jc      .AllDone
223%endif
224
225    ; Fall to .StoreDriveNumberAndUpdateDriveCount
226
227;--------------------------------------------------------------------
228; .StoreDriveNumberAndUpdateDriveCount
229;   Parameters:
230;       DS:DI:  Ptr to Disk Parameter Table
231;       ES:SI:  Ptr to 512-byte ATA information read from the drive
232;       CS:BP:  Ptr to IDEVARS for the controller
233;       ES:     BDA Segment
234;   Returns:
235;       DL:     Drive number for new drive
236;       CF:     Always cleared
237;   Corrupts registers:
238;       Nothing
239;--------------------------------------------------------------------
240.StoreDriveNumberAndUpdateDriveCount:
241    mov     dl, [es:BDA.bHDCount]
242    or      dl, 80h                     ; Set bit 7 since hard disk
243
244    inc     BYTE [RAMVARS.bDrvCnt]      ; Increment drive count to RAMVARS
245    inc     BYTE [es:BDA.bHDCount]      ; Increment drive count to BDA
246
247    cmp     BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
248    ja      SHORT .AllDone              ;  If so, return
249    mov     [RAMVARS.bFirstDrv], dl     ; Store first drive number
250
251.AllDone:
252    clc
253    ret
254
Note: See TracBrowser for help on using the repository browser.