[3] | 1 | ; File name : DetectDrives.asm
|
---|
| 2 | ; Project name : IDE BIOS
|
---|
| 3 | ; Created date : 17.3.2010
|
---|
| 4 | ; Last update : 2.5.2010
|
---|
| 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Functions for detecting drive for the BIOS.
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | ; Section containing code
|
---|
| 10 | SECTION .text
|
---|
| 11 |
|
---|
| 12 | ;--------------------------------------------------------------------
|
---|
| 13 | ; Detects all IDE hard disks to be controlled by this BIOS.
|
---|
| 14 | ;
|
---|
| 15 | ; DetectDrives_FromAllIDEControllers
|
---|
| 16 | ; Parameters:
|
---|
| 17 | ; DS: RAMVARS segment
|
---|
| 18 | ; ES: BDA segment (zero)
|
---|
| 19 | ; Returns:
|
---|
| 20 | ; Nothing
|
---|
| 21 | ; Corrupts registers:
|
---|
| 22 | ; All (not segments)
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ALIGN JUMP_ALIGN
|
---|
| 25 | DetectDrives_FromAllIDEControllers:
|
---|
| 26 | call Initialize_GetIdeControllerCountToCX
|
---|
| 27 | mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS
|
---|
| 28 | ALIGN JUMP_ALIGN
|
---|
| 29 | .DriveDetectLoop:
|
---|
| 30 | call DetectDrives_WithIDEVARS ; Detect Master and Slave
|
---|
| 31 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
| 32 | loop .DriveDetectLoop
|
---|
| 33 | ret
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | ;--------------------------------------------------------------------
|
---|
| 37 | ; Detects IDE hard disks by using information from IDEVARS.
|
---|
| 38 | ;
|
---|
| 39 | ; DetectDrives_WithIDEVARS
|
---|
| 40 | ; Parameters:
|
---|
| 41 | ; CS:BP: Ptr to IDEVARS
|
---|
| 42 | ; DS: RAMVARS segment
|
---|
| 43 | ; ES: Zero (BDA segment)
|
---|
| 44 | ; Returns:
|
---|
| 45 | ; Nothing
|
---|
| 46 | ; Corrupts registers:
|
---|
| 47 | ; AX, BX, DX, SI, DI
|
---|
| 48 | ;--------------------------------------------------------------------
|
---|
| 49 | ALIGN JUMP_ALIGN
|
---|
| 50 | DetectDrives_WithIDEVARS:
|
---|
| 51 | push cx
|
---|
| 52 | call DetectPrint_StartingMasterDetect ; Print detection string
|
---|
| 53 | call DetectDrives_DetectMasterDrive ; Detect and create DPT + BOOTNFO
|
---|
| 54 | call DetectPrint_DriveNameOrNotFound ; Print found or not found string
|
---|
| 55 |
|
---|
| 56 | call DetectPrint_StartingSlaveDetect
|
---|
| 57 | call DetectDrives_DetectSlaveDrive
|
---|
| 58 | call DetectPrint_DriveNameOrNotFound
|
---|
| 59 | pop cx
|
---|
| 60 | ret
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | ;--------------------------------------------------------------------
|
---|
| 64 | ; Detects IDE Master or Slave drive.
|
---|
| 65 | ;
|
---|
| 66 | ; DetectDrives_DetectMasterDrive
|
---|
| 67 | ; DetectDrives_DetectSlaveDrive
|
---|
| 68 | ; Parameters:
|
---|
| 69 | ; CS:BP: Ptr to IDEVARS
|
---|
| 70 | ; DS: RAMVARS segment
|
---|
| 71 | ; ES: Zero (BDA segment)
|
---|
| 72 | ; Returns:
|
---|
| 73 | ; ES:BX: Ptr to BOOTNFO (if successful)
|
---|
| 74 | ; CF: Cleared if drive detected successfully
|
---|
| 75 | ; Set if any drive not found or other error
|
---|
| 76 | ; Corrupts registers:
|
---|
| 77 | ; AX, CX, DX, SI, DI
|
---|
| 78 | ;--------------------------------------------------------------------
|
---|
| 79 | ALIGN JUMP_ALIGN
|
---|
| 80 | DetectDrives_DetectMasterDrive:
|
---|
| 81 | mov bh, MASK_IDE_DRVHD_SET ; Select Master drive
|
---|
| 82 | jmp SHORT DetectDrives_StartDetection
|
---|
| 83 | ALIGN JUMP_ALIGN
|
---|
| 84 | DetectDrives_DetectSlaveDrive:
|
---|
| 85 | mov bh, MASK_IDE_DRVHD_SET | FLG_IDE_DRVHD_DRV
|
---|
| 86 | ; Fall to DetectDrives_StartDetection
|
---|
| 87 |
|
---|
| 88 | ;--------------------------------------------------------------------
|
---|
| 89 | ; Detects IDE Master or Slave drive.
|
---|
| 90 | ;
|
---|
| 91 | ; DetectDrives_StartDetection
|
---|
| 92 | ; Parameters:
|
---|
| 93 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 94 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 95 | ; DS: RAMVARS segment
|
---|
| 96 | ; ES: Zero (BDA segment)
|
---|
| 97 | ; Returns:
|
---|
| 98 | ; ES:BX: Ptr to BOOTNFO (if successful)
|
---|
| 99 | ; CF: Cleared if drive detected successfully
|
---|
| 100 | ; Set if any drive not found or other error
|
---|
| 101 | ; Corrupts registers:
|
---|
| 102 | ; AX, CX, DX, SI, DI
|
---|
| 103 | ;--------------------------------------------------------------------
|
---|
| 104 | ALIGN JUMP_ALIGN
|
---|
| 105 | DetectDrives_StartDetection:
|
---|
| 106 | call DetectDrives_ReadAtaInfoFromDrive ; Assume hard disk
|
---|
| 107 | jnc SHORT DetectDrives_CreateBiosTablesForHardDisk
|
---|
| 108 | call DetectDrives_ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
| 109 | jnc SHORT DetectDrives_CreateBiosTablesForCDROM
|
---|
| 110 | ret
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | ;--------------------------------------------------------------------
|
---|
| 114 | ; Reads ATA information from the drive (for hard disks).
|
---|
| 115 | ;
|
---|
| 116 | ; DetectDrives_ReadAtaInfoFromDrive
|
---|
| 117 | ; Parameters:
|
---|
| 118 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 119 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 120 | ; DS: RAMVARS segment
|
---|
| 121 | ; ES: Zero (BDA segment)
|
---|
| 122 | ; Returns:
|
---|
| 123 | ; ES:SI Ptr to ATA information (read with IDENTIFY DEVICE command)
|
---|
| 124 | ; CF: Cleared if ATA-information read successfully
|
---|
| 125 | ; Set if any error
|
---|
| 126 | ; Corrupts registers:
|
---|
| 127 | ; AX, BL, CX, DX, DI
|
---|
| 128 | ;--------------------------------------------------------------------
|
---|
| 129 | ALIGN JUMP_ALIGN
|
---|
| 130 | DetectDrives_ReadAtaInfoFromDrive:
|
---|
| 131 | mov bl, [cs:bp+IDEVARS.bBusType]; Load BUS type
|
---|
| 132 | mov dx, [cs:bp+IDEVARS.wPort] ; Load IDE Base Port address
|
---|
| 133 | mov di, BOOTVARS.rgbAtaInfo ; ES:DI now points to ATA info location
|
---|
| 134 | call AH25h_GetDriveInfo
|
---|
| 135 | mov si, di ; ES:SI now points to ATA information
|
---|
| 136 | ret
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | ;--------------------------------------------------------------------
|
---|
| 140 | ; Reads ATAPI information from the drive (for CD/DVD-ROMs).
|
---|
| 141 | ;
|
---|
| 142 | ; DetectDrives_ReadAtapiInfoFromDrive
|
---|
| 143 | ; Parameters:
|
---|
| 144 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 145 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 146 | ; DS: RAMVARS segment
|
---|
| 147 | ; ES: Zero (BDA segment)
|
---|
| 148 | ; Returns:
|
---|
| 149 | ; ES:SI Ptr to ATAPI information (read with IDENTIFY PACKET DEVICE command)
|
---|
| 150 | ; CF: Cleared if ATAPI-information read successfully
|
---|
| 151 | ; Set if any error
|
---|
| 152 | ; Corrupts registers:
|
---|
| 153 | ; AX, BL, CX, DX, DI
|
---|
| 154 | ;--------------------------------------------------------------------
|
---|
| 155 | ALIGN JUMP_ALIGN
|
---|
| 156 | DetectDrives_ReadAtapiInfoFromDrive:
|
---|
| 157 | stc
|
---|
| 158 | ret
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | ;--------------------------------------------------------------------
|
---|
| 162 | ; Creates all BIOS tables for detected hard disk.
|
---|
| 163 | ;
|
---|
| 164 | ; DetectDrives_CreateBiosTablesForHardDisk
|
---|
| 165 | ; Parameters:
|
---|
| 166 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 167 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 168 | ; ES:SI Ptr to ATA information for the drive
|
---|
| 169 | ; DS: RAMVARS segment
|
---|
| 170 | ; Returns:
|
---|
| 171 | ; ES:BX: Ptr to BOOTNFO (if successful)
|
---|
| 172 | ; CF: Cleared if BIOS tables created succesfully
|
---|
| 173 | ; Set if any error
|
---|
| 174 | ; Corrupts registers:
|
---|
| 175 | ; AX, CX, DX, SI, DI
|
---|
| 176 | ;--------------------------------------------------------------------
|
---|
| 177 | ALIGN JUMP_ALIGN
|
---|
| 178 | DetectDrives_CreateBiosTablesForHardDisk:
|
---|
| 179 | call CreateDPT_FromAtaInformation
|
---|
| 180 | jc SHORT .InvalidAtaInfo
|
---|
| 181 | call BootInfo_CreateForHardDisk
|
---|
| 182 | ;jc SHORT .InvalidAtaInfo
|
---|
| 183 | ; Call to search for BIOS partitions goes here
|
---|
| 184 | ;clc
|
---|
| 185 | .InvalidAtaInfo:
|
---|
| 186 | ret
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | ;--------------------------------------------------------------------
|
---|
| 190 | ; Creates all BIOS tables for detected CD/DVD-ROM.
|
---|
| 191 | ;
|
---|
| 192 | ; DetectDrives_CreateBiosTablesForCDROM
|
---|
| 193 | ; Parameters:
|
---|
| 194 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 195 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 196 | ; ES:SI Ptr to ATAPI information for the drive
|
---|
| 197 | ; DS: RAMVARS segment
|
---|
| 198 | ; Returns:
|
---|
| 199 | ; ES:BX: Ptr to BOOTNFO (if successful)
|
---|
| 200 | ; CF: Cleared if BIOS tables created succesfully
|
---|
| 201 | ; Set if any error
|
---|
| 202 | ; Corrupts registers:
|
---|
| 203 | ; AX, CX, DX, SI, DI
|
---|
| 204 | ;--------------------------------------------------------------------
|
---|
| 205 | ALIGN JUMP_ALIGN
|
---|
| 206 | DetectDrives_CreateBiosTablesForCDROM:
|
---|
| 207 | stc
|
---|
| 208 | ret
|
---|