[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
|
---|
[294] | 28 | call StartDetectionWithDriveSelectByteInBHandStringInCX ; Detect and create DPT + BOOTNFO
|
---|
[233] | 29 |
|
---|
| 30 | mov cx, g_szDetectSlave
|
---|
[242] | 31 | mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
|
---|
[294] | 32 | call StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
[242] | 33 |
|
---|
[233] | 34 | pop cx
|
---|
| 35 |
|
---|
| 36 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
| 37 |
|
---|
[242] | 38 | %ifdef MODULE_SERIAL
|
---|
[262] | 39 | jcxz .AddHardDisks ; 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
|
---|
[262] | 50 | jnc .AddHardDisks
|
---|
[233] | 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 |
|
---|
[262] | 60 | .AddHardDisks:
|
---|
[258] | 61 | ;----------------------------------------------------------------------
|
---|
| 62 | ;
|
---|
[262] | 63 | ; Add in hard disks to BDA, finalize our Count and First variables
|
---|
[258] | 64 | ;
|
---|
[269] | 65 | ; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
|
---|
| 66 | ; This is done because we use the value of .bFirstDrv to know how many drives were in the system
|
---|
| 67 | ; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
|
---|
| 68 | ; FindDPT_ForDriveNumber will not find any drives that are ours.
|
---|
| 69 | ;
|
---|
[262] | 70 | mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
|
---|
[258] | 71 |
|
---|
[262] | 72 | mov al, [es:BDA.bHDCount]
|
---|
| 73 | add cl, al ; Add our drives to the system count
|
---|
[294] | 74 | mov [es:BDA.bHDCount], cl
|
---|
| 75 | or al, 80h ; Or in hard disk flag
|
---|
| 76 | mov [RAMVARS.bFirstDrv], al ; Store first drive number
|
---|
[262] | 77 |
|
---|
[294] | 78 | .AddFloppies:
|
---|
| 79 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
[262] | 80 | ;----------------------------------------------------------------------
|
---|
| 81 | ;
|
---|
| 82 | ; Add in any emulated serial floppy drives, finalize our packed Count and First variables
|
---|
| 83 | ;
|
---|
| 84 | dec ch
|
---|
| 85 | mov al, ch
|
---|
[294] | 86 | js .NoFloppies ; if no drives are present, we store 0ffh
|
---|
[262] | 87 |
|
---|
[258] | 88 | call FloppyDrive_GetCountFromBIOS_or_BDA
|
---|
| 89 |
|
---|
| 90 | push ax
|
---|
| 91 |
|
---|
[262] | 92 | add al, ch ; Add our drives to existing drive count
|
---|
[258] | 93 | cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
|
---|
[294] | 94 | jb .MaxBDAFloppiesExceeded
|
---|
| 95 | mov al, 3
|
---|
[258] | 96 | .MaxBDAFloppiesExceeded:
|
---|
| 97 | eROR_IM al, 2 ; move to bits 6-7
|
---|
| 98 | inc ax ; low order bit, indicating floppy drive exists
|
---|
| 99 |
|
---|
[294] | 100 | mov ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte
|
---|
[258] | 101 | and ah, 03eh ; Mask off drive number and drives present bit
|
---|
| 102 | or al, ah ; Or in new values
|
---|
| 103 | mov [es:BDA.wEquipment], al ; and store
|
---|
| 104 |
|
---|
| 105 | mov al, 1eh ; BDA pointer to Floppy DPT
|
---|
| 106 | mov si, AH8h_FloppyDPT
|
---|
| 107 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
| 108 |
|
---|
| 109 | pop ax
|
---|
| 110 |
|
---|
[262] | 111 | shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
|
---|
[258] | 112 | rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
|
---|
[294] | 113 | .NoFloppies:
|
---|
[258] | 114 | mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
|
---|
[263] | 115 | %endif
|
---|
[294] | 116 |
|
---|
[3] | 117 | ret
|
---|
| 118 |
|
---|
[294] | 119 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[261] | 120 | %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
|
---|
| 121 | %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."
|
---|
| 122 | %endif
|
---|
[199] | 123 | %endif
|
---|
| 124 |
|
---|
[242] | 125 |
|
---|
[3] | 126 | ;--------------------------------------------------------------------
|
---|
[294] | 127 | ; StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
[3] | 128 | ; Parameters:
|
---|
| 129 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[233] | 130 | ; CX: Offset to "Master" or "Slave" string
|
---|
[3] | 131 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 132 | ; DS: RAMVARS segment
|
---|
| 133 | ; ES: Zero (BDA segment)
|
---|
| 134 | ; Returns:
|
---|
[203] | 135 | ; None
|
---|
[3] | 136 | ; Corrupts registers:
|
---|
[98] | 137 | ; AX, BX, CX, DX, SI, DI
|
---|
[3] | 138 | ;--------------------------------------------------------------------
|
---|
[294] | 139 | StartDetectionWithDriveSelectByteInBHandStringInCX:
|
---|
| 140 | call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
|
---|
[120] | 141 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
[3] | 142 |
|
---|
| 143 | ;--------------------------------------------------------------------
|
---|
[120] | 144 | ; .ReadAtaInfoFromHardDisk
|
---|
[3] | 145 | ; Parameters:
|
---|
| 146 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 147 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 148 | ; DS: RAMVARS segment
|
---|
| 149 | ; ES: Zero (BDA segment)
|
---|
| 150 | ; Returns:
|
---|
| 151 | ; CF: Cleared if ATA-information read successfully
|
---|
| 152 | ; Set if any error
|
---|
| 153 | ; Corrupts registers:
|
---|
[150] | 154 | ; AX, BL, CX, DX, SI, DI
|
---|
[3] | 155 | ;--------------------------------------------------------------------
|
---|
[120] | 156 | .ReadAtaInfoFromHardDisk:
|
---|
[150] | 157 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
| 158 | push es
|
---|
| 159 | push si
|
---|
| 160 | push bx
|
---|
| 161 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
| 162 | pop bx
|
---|
| 163 | pop si
|
---|
| 164 | pop es
|
---|
[120] | 165 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
| 166 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
[3] | 167 |
|
---|
[120] | 168 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
| 169 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
| 170 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
[242] | 171 |
|
---|
[203] | 172 | ;jmp short DetectDrives_DriveNotFound
|
---|
| 173 | ;;; fall-through instead of previous jmp instruction
|
---|
| 174 | ;--------------------------------------------------------------------
|
---|
| 175 | ; DetectDrives_DriveNotFound
|
---|
| 176 | ; Parameters:
|
---|
| 177 | ; Nothing
|
---|
| 178 | ; Returns:
|
---|
| 179 | ; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
|
---|
| 180 | ; Corrupts registers:
|
---|
| 181 | ; AX, SI
|
---|
| 182 | ;--------------------------------------------------------------------
|
---|
[242] | 183 | DetectDrives_DriveNotFound:
|
---|
[203] | 184 | mov si, g_szNotFound
|
---|
[242] | 185 | jmp BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
[3] | 186 |
|
---|
[120] | 187 |
|
---|
[3] | 188 | ;--------------------------------------------------------------------
|
---|
[98] | 189 | ; CreateBiosTablesForHardDisk
|
---|
[3] | 190 | ; Parameters:
|
---|
| 191 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 192 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
[150] | 193 | ; ES:SI Ptr to ATA information for the drive
|
---|
[3] | 194 | ; DS: RAMVARS segment
|
---|
[98] | 195 | ; ES: BDA/Bootnfo segment
|
---|
[3] | 196 | ; Returns:
|
---|
[98] | 197 | ; Nothing
|
---|
[3] | 198 | ; Corrupts registers:
|
---|
[98] | 199 | ; AX, BX, CX, DX, SI, DI
|
---|
[3] | 200 | ;--------------------------------------------------------------------
|
---|
[98] | 201 | CreateBiosTablesForHardDisk:
|
---|
[3] | 202 | call CreateDPT_FromAtaInformation
|
---|
[196] | 203 | jc SHORT DetectDrives_DriveNotFound
|
---|
[254] | 204 | call BootMenuInfo_CreateForHardDisk
|
---|
[196] | 205 | jmp short DetectPrint_DriveNameFromBootnfoInESBX
|
---|