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