[150] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Functions for detecting drive for the BIOS. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .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 | ;-------------------------------------------------------------------- |
---|
| 19 | DetectDrives_FromAllIDEControllers: |
---|
[33] | 20 | call RamVars_GetIdeControllerCountToCX |
---|
[3] | 21 | mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS |
---|
[200] | 22 | |
---|
| 23 | .DriveDetectLoop: ; Loop through IDEVARS |
---|
[233] | 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 |
---|
[242] | 31 | mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV |
---|
[233] | 32 | call StartDetectionWithDriveSelectByteInBHandStringInAX |
---|
[242] | 33 | |
---|
[233] | 34 | pop cx |
---|
| 35 | |
---|
| 36 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS |
---|
| 37 | |
---|
[242] | 38 | %ifdef MODULE_SERIAL |
---|
[233] | 39 | jcxz .done ; Set to zero on .ideVarsSerialAuto iteration (if any) |
---|
[196] | 40 | %endif |
---|
[242] | 41 | |
---|
[3] | 42 | loop .DriveDetectLoop |
---|
[203] | 43 | |
---|
[242] | 44 | %ifdef MODULE_SERIAL |
---|
[258] | 45 | ;---------------------------------------------------------------------- |
---|
[203] | 46 | ; |
---|
[233] | 47 | ; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection) |
---|
[203] | 48 | ; |
---|
[233] | 49 | call FindDPT_ToDSDIforSerialDevice |
---|
| 50 | jc .done |
---|
| 51 | |
---|
[242] | 52 | mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans |
---|
| 53 | |
---|
[200] | 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 |
---|
[242] | 57 | jnz .DriveDetectLoop |
---|
[233] | 58 | %endif |
---|
[203] | 59 | |
---|
[258] | 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 | |
---|
[3] | 100 | ret |
---|
| 101 | |
---|
[261] | 102 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS |
---|
| 103 | %if FLG_ROMVARS_SERIAL_SCANDETECT != 8 |
---|
| 104 | %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." |
---|
| 105 | %endif |
---|
[199] | 106 | %endif |
---|
| 107 | |
---|
[242] | 108 | |
---|
[3] | 109 | ;-------------------------------------------------------------------- |
---|
[98] | 110 | ; StartDetectionWithDriveSelectByteInBHandStringInAX |
---|
[3] | 111 | ; Parameters: |
---|
| 112 | ; BH: Drive Select byte for Drive and Head Register |
---|
[233] | 113 | ; CX: Offset to "Master" or "Slave" string |
---|
[3] | 114 | ; CS:BP: Ptr to IDEVARS for the drive |
---|
| 115 | ; DS: RAMVARS segment |
---|
| 116 | ; ES: Zero (BDA segment) |
---|
| 117 | ; Returns: |
---|
[203] | 118 | ; None |
---|
[3] | 119 | ; Corrupts registers: |
---|
[98] | 120 | ; AX, BX, CX, DX, SI, DI |
---|
[3] | 121 | ;-------------------------------------------------------------------- |
---|
[98] | 122 | StartDetectionWithDriveSelectByteInBHandStringInAX: |
---|
| 123 | call DetectPrint_StartDetectWithMasterOrSlaveStringInAXandIdeVarsInCSBP |
---|
[120] | 124 | ; Fall to .ReadAtaInfoFromHardDisk |
---|
[3] | 125 | |
---|
| 126 | ;-------------------------------------------------------------------- |
---|
[120] | 127 | ; .ReadAtaInfoFromHardDisk |
---|
[3] | 128 | ; Parameters: |
---|
| 129 | ; BH: Drive Select byte for Drive and Head Register |
---|
| 130 | ; CS:BP: Ptr to IDEVARS for the drive |
---|
| 131 | ; DS: RAMVARS segment |
---|
| 132 | ; ES: Zero (BDA segment) |
---|
| 133 | ; Returns: |
---|
| 134 | ; CF: Cleared if ATA-information read successfully |
---|
| 135 | ; Set if any error |
---|
| 136 | ; Corrupts registers: |
---|
[150] | 137 | ; AX, BL, CX, DX, SI, DI |
---|
[3] | 138 | ;-------------------------------------------------------------------- |
---|
[120] | 139 | .ReadAtaInfoFromHardDisk: |
---|
[150] | 140 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location |
---|
| 141 | push es |
---|
| 142 | push si |
---|
| 143 | push bx |
---|
| 144 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH |
---|
| 145 | pop bx |
---|
| 146 | pop si |
---|
| 147 | pop es |
---|
[120] | 148 | jnc SHORT CreateBiosTablesForHardDisk |
---|
| 149 | ; Fall to .ReadAtapiInfoFromDrive |
---|
[3] | 150 | |
---|
[120] | 151 | .ReadAtapiInfoFromDrive: ; Not yet implemented |
---|
| 152 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM |
---|
| 153 | ;jnc SHORT _CreateBiosTablesForCDROM |
---|
[242] | 154 | |
---|
[203] | 155 | ;jmp short DetectDrives_DriveNotFound |
---|
| 156 | ;;; fall-through instead of previous jmp instruction |
---|
| 157 | ;-------------------------------------------------------------------- |
---|
| 158 | ; DetectDrives_DriveNotFound |
---|
| 159 | ; Parameters: |
---|
| 160 | ; Nothing |
---|
| 161 | ; Returns: |
---|
| 162 | ; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF) |
---|
| 163 | ; Corrupts registers: |
---|
| 164 | ; AX, SI |
---|
| 165 | ;-------------------------------------------------------------------- |
---|
[242] | 166 | DetectDrives_DriveNotFound: |
---|
[203] | 167 | mov si, g_szNotFound |
---|
[242] | 168 | jmp BootMenuPrint_NullTerminatedStringFromCSSIandSetCF |
---|
[3] | 169 | |
---|
[120] | 170 | |
---|
[3] | 171 | ;-------------------------------------------------------------------- |
---|
[98] | 172 | ; CreateBiosTablesForHardDisk |
---|
[3] | 173 | ; Parameters: |
---|
| 174 | ; BH: Drive Select byte for Drive and Head Register |
---|
| 175 | ; CS:BP: Ptr to IDEVARS for the drive |
---|
[150] | 176 | ; ES:SI Ptr to ATA information for the drive |
---|
[3] | 177 | ; DS: RAMVARS segment |
---|
[98] | 178 | ; ES: BDA/Bootnfo segment |
---|
[3] | 179 | ; Returns: |
---|
[98] | 180 | ; Nothing |
---|
[3] | 181 | ; Corrupts registers: |
---|
[98] | 182 | ; AX, BX, CX, DX, SI, DI |
---|
[3] | 183 | ;-------------------------------------------------------------------- |
---|
[98] | 184 | CreateBiosTablesForHardDisk: |
---|
[3] | 185 | call CreateDPT_FromAtaInformation |
---|
[196] | 186 | jc SHORT DetectDrives_DriveNotFound |
---|
[254] | 187 | call BootMenuInfo_CreateForHardDisk |
---|
[196] | 188 | jmp short DetectPrint_DriveNameFromBootnfoInESBX |
---|
| 189 | |
---|
| 190 | |
---|