source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.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: 6.0 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Functions for detecting drive for the BIOS.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Detects all IDE hard disks to be controlled by this BIOS.
9;
10; DetectDrives_FromAllIDEControllers
11;   Parameters:
12;       DS:     RAMVARS segment
13;       ES:     BDA segment (zero)
14;   Returns:
15;       Nothing
16;   Corrupts registers:
17;       All (not segments)
18;--------------------------------------------------------------------
19DetectDrives_FromAllIDEControllers:
20    call    RamVars_GetIdeControllerCountToCX
21    mov     bp, ROMVARS.ideVars0            ; CS:BP now points to first IDEVARS
22
23.DriveDetectLoop:                           ; Loop through IDEVARS
24    push    cx
25
26    mov     cx, g_szDetectMaster
27    mov     bh, MASK_DRVNHEAD_SET                               ; Select Master drive
28    call    StartDetectionWithDriveSelectByteInBHandStringInAX  ; Detect and create DPT + BOOTNFO
29
30    mov     cx, g_szDetectSlave
31    mov     bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
32    call    StartDetectionWithDriveSelectByteInBHandStringInAX
33
34    pop     cx
35
36    add     bp, BYTE IDEVARS_size           ; Point to next IDEVARS
37
38%ifdef MODULE_SERIAL
39    jcxz    .done                           ; Set to zero on .ideVarsSerialAuto iteration (if any)
40%endif
41
42    loop    .DriveDetectLoop
43
44%ifdef MODULE_SERIAL
45;----------------------------------------------------------------------
46;
47; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
48;
49    call    FindDPT_ToDSDIforSerialDevice
50    jc      .done
51
52    mov     bp, ROMVARS.ideVarsSerialAuto   ; Point to our special IDEVARS structure, just for serial scans
53
54    mov     al,[cs:ROMVARS.wFlags]          ; Configurator set to always scan?
55    or      al,[es:BDA.bKBFlgs1]            ; Or, did the user hold down the ALT key?
56    and     al,8                            ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
57    jnz     .DriveDetectLoop
58%endif
59
60.done: 
61%ifdef MODULE_SERIAL_FLOPPY
62;----------------------------------------------------------------------
63;
64; Add in any emulated serial floppy drives.
65;
66    mov     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
67    dec     al
68    mov     cl, al
69    js      .NoFloppies                     ; if no drives are present, we store 0ffh
70
71    call    FloppyDrive_GetCountFromBIOS_or_BDA
72
73    push    ax
74
75    add     al, cl                          ; Add our drives to existing drive count
76    cmp     al, 3                           ; For BDA, max out at 4 drives (ours is zero based)
77    jl      .MaxBDAFloppiesExceeded
78    mov     al, 3                           
79.MaxBDAFloppiesExceeded:
80    eROR_IM al, 2                           ; move to bits 6-7
81    inc     ax                              ; low order bit, indicating floppy drive exists
82
83    mov     ah, [es:BDA.wEquipment]         ; Load Equipment WORD low byte 
84    and     ah, 03eh                        ; Mask off drive number and drives present bit
85    or      al, ah                          ; Or in new values
86    mov     [es:BDA.wEquipment], al         ; and store
87
88    mov     al, 1eh                         ; BDA pointer to Floppy DPT
89    mov     si, AH8h_FloppyDPT
90    call    Interrupts_InstallHandlerToVectorInALFromCSSI
91
92    pop     ax
93
94    shr     cl, 1                           ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
95    rcl     al, 1                           ; starting drive number in upper 7 bits, number of drives in low bit
96.NoFloppies:   
97    mov     [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
98%endif
99       
100    ret
101
102%if FLG_ROMVARS_SERIAL_SCANDETECT != 8
103    %error "DetectDrives is currently coded to assume that FLG_ROMVARS_SERIAL_SCANDETECT is the same bit as the ALT key code in the BDA.  Changes in the code will be needed if these values are no longer the same."
104%endif
105
106
107;--------------------------------------------------------------------
108; StartDetectionWithDriveSelectByteInBHandStringInAX
109;   Parameters:
110;       BH:     Drive Select byte for Drive and Head Register
111;       CX:     Offset to "Master" or "Slave" string
112;       CS:BP:  Ptr to IDEVARS for the drive
113;       DS:     RAMVARS segment
114;       ES:     Zero (BDA segment)
115;   Returns:
116;       None
117;   Corrupts registers:
118;       AX, BX, CX, DX, SI, DI
119;--------------------------------------------------------------------
120StartDetectionWithDriveSelectByteInBHandStringInAX:
121    call    DetectPrint_StartDetectWithMasterOrSlaveStringInAXandIdeVarsInCSBP
122    ; Fall to .ReadAtaInfoFromHardDisk
123
124;--------------------------------------------------------------------
125; .ReadAtaInfoFromHardDisk
126;   Parameters:
127;       BH:     Drive Select byte for Drive and Head Register
128;       CS:BP:  Ptr to IDEVARS for the drive
129;       DS:     RAMVARS segment
130;       ES:     Zero (BDA segment)
131;   Returns:
132;       CF:     Cleared if ATA-information read successfully
133;               Set if any error
134;   Corrupts registers:
135;       AX, BL, CX, DX, SI, DI
136;--------------------------------------------------------------------
137.ReadAtaInfoFromHardDisk:
138    mov     si, BOOTVARS.rgbAtaInfo     ; ES:SI now points to ATA info location
139    push    es
140    push    si
141    push    bx
142    call    Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
143    pop     bx
144    pop     si
145    pop     es
146    jnc     SHORT CreateBiosTablesForHardDisk
147    ; Fall to .ReadAtapiInfoFromDrive
148
149.ReadAtapiInfoFromDrive:                ; Not yet implemented
150    ;call   ReadAtapiInfoFromDrive      ; Assume CD-ROM
151    ;jnc    SHORT _CreateBiosTablesForCDROM
152
153    ;jmp    short DetectDrives_DriveNotFound
154;;; fall-through instead of previous jmp instruction
155;--------------------------------------------------------------------
156; DetectDrives_DriveNotFound
157;   Parameters:
158;       Nothing
159;   Returns:
160;       CF:     Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
161;   Corrupts registers:
162;       AX, SI
163;--------------------------------------------------------------------
164DetectDrives_DriveNotFound:
165    mov     si, g_szNotFound
166    jmp     BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
167
168
169;--------------------------------------------------------------------
170; CreateBiosTablesForHardDisk
171;   Parameters:
172;       BH:     Drive Select byte for Drive and Head Register
173;       CS:BP:  Ptr to IDEVARS for the drive
174;       ES:SI   Ptr to ATA information for the drive
175;       DS:     RAMVARS segment
176;       ES:     BDA/Bootnfo segment
177;   Returns:
178;       Nothing
179;   Corrupts registers:
180;       AX, BX, CX, DX, SI, DI
181;--------------------------------------------------------------------
182CreateBiosTablesForHardDisk:
183    call    CreateDPT_FromAtaInformation
184    jc      SHORT DetectDrives_DriveNotFound
185    call    BootMenuInfo_CreateForHardDisk
186    jmp     short DetectPrint_DriveNameFromBootnfoInESBX
187
188
Note: See TracBrowser for help on using the repository browser.