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