Changeset 29 for trunk/BOOTCODE/REGULAR/DRIVEIO.ASM
- Timestamp:
- May 5, 2011, 2:00:00 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BOOTCODE/REGULAR/DRIVEIO.ASM
r26 r29 1 2 ; Disclaimer:3 ; =============4 ; The sourcecode is released via www.netlabs.org CVS *ONLY*.5 ; You MUST NOT upload it to other servers nor republish it in any way.6 ; The sourcecode is still COPYRIGHTED and NOT RELEASED UNDER GPL.7 ; It's (c) Copyright 1998-2003 by Martin Kiewitz.8 ; You may recompile the source and do *PRIVATE* modifications, but please keep9 ; in mind that modifying this code needs at least *some* assembly skill. If10 ; you mess up your system, because you needed to hack your way through, don't11 ; blame me. Releasing a customized version of AiR-BOOT, selling it in any form12 ; or reusing parts of this source is *PROHIBITED*. Ask me, if you have some13 ; idea about new functionality *before* developing the code, otherwise I will14 ; definitely reject it. Also please accept, that I have some basic design15 ; rules on AiR-BOOT and I will maintain them at all costs, so this won't get16 ; another GRUB.17 1 ; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz 2 ; 3 ; This file is part of AiR-BOOT 4 ; 5 ; AiR-BOOT is free software: you can redistribute it and/or modify it under 6 ; the terms of the GNU General Public License as published by the Free 7 ; Software Foundation, either version 3 of the License, or (at your option) 8 ; any later version. 9 ; 10 ; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY 11 ; WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS 12 ; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 ; details. 14 ; 15 ; You should have received a copy of the GNU General Public License along with 16 ; AiR-BOOT. If not, see <http://www.gnu.org/licenses/>. 17 ; 18 18 ;--------------------------------------------------------------------------- 19 19 ; AiR-BOOT / DRIVE I/O 20 20 ;--------------------------------------------------------------------------- 21 21 22 ; Note: Some routines set DS/ES to CS, even if its not needed. 23 ; This was done for SECURITY. So DO NOT remove it. Its there to make 24 ; sure the correct data is loaded/written to/from harddrive. 25 ; 26 ; IF YOU MODIFY ANYTHING IN HERE, YOU CAN EASILY BREAK YOUR HARDDRIVE! 22 ; Note: Some routines set DS/ES to CS or even address via CS, even if its not 23 ; needed. This was done for SECURITY. So DO NOT remove it. 24 ; Its there to make sure the correct data is loaded/written to/from 25 ; harddrive. 26 ; 27 ; IF YOU MODIFY ANYTHING IN HERE, YOU MAY EASILY BREAK YOUR HARDDRIVE! 27 28 28 29 ; Will only load base-configuration, will NOT load IPT nor Hide-Config … … 124 125 ; Internal access (to AiR-BOOT) is always done via INT 13h/CHS. 125 126 127 DriveIO_GetHardDriveCount Proc Near Uses ds si 128 push ds si 129 push 0040h 130 pop ds 131 mov si, 0075h 132 mov dh, ds:[si] ; 40:75 -> POST: Total Harddiscs == DL 133 pop si ds 134 mov TotalHarddiscs, dh 135 ret 136 DriveIO_GetHardDriveCount EndP 137 138 139 ; Fills our LBA-Usage table. It holds the LBA-address, where BIOS/CHS access is 140 ; stopped and BIOS/LBA access is started. 141 ; This is calculated by Sector*Heads. Comparing will get done with Bit 25-10 142 ; on LBA sectors, so we actually divide sector number by 1024. 143 DriveIO_InitLBASwitchTable Proc Near Uses es di 144 mov di, offset LBASwitchTable 145 mov dh, TotalHarddiscs 146 mov dl, 80h 147 DIOILUT_DriveLoop: 148 push dx di 149 mov ah, 08h 150 int 13h ; DISK - GET DRIVE PARAMETERS 151 mov ah, 0FBh ; Assume 255 heads/63 sectors, if error 152 jc DIOILUT_Error 153 and cl, 111111b ; Isolate lower 6 bits of CL -> sector count 154 movzx ax, cl 155 mov bl, dh ; DH -> head count 156 mul bl ; AX = Sectors*Heads 157 shl ah, 1 158 shl ah, 1 ; Shift 2 bits, so we are able to compare to 159 ; bit 16-23 of the LBA address 160 DIOILUT_Error: 161 pop di dx 162 mov bptr ds:[di], ah ; Save that value 163 inc di ; Go to next BYTE 164 inc dl 165 dec dh 166 jnz DIOILUT_DriveLoop 167 ret 168 DriveIO_InitLBASwitchTable EndP 169 170 ; Adjusts BX:AX / CX:DX to meet LVM sector location 171 ; Destroys SI 172 DriveIO_LVMAdjustToInfoSector Proc Near Uses 173 push cx 174 xor ch, ch 175 and cl, 63 ; Isolate lower bits, because upper 176 mov si, 63 ; ones may be used for cylinder 177 sub si, cx 178 pop cx 179 add ax, si 180 adc bx, 0 ; Adjust LBA Sector (BX:AX) 181 or cl, 63 ; Set Sector to 63 182 ret 183 DriveIO_LVMAdjustToInfoSector EndP 184 126 185 Comment *ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 127 186 Routine: Loads partition to ExecBase and checks for validity … … 132 191 Preserve: all registers 133 192 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ* 134 DriveIO_LoadPartition Proc Near Uses ds si 135 int 3 193 DriveIO_LoadPartition Proc Near Uses si 136 194 mov wptr cs:[CurPartition_Location+0], ax 137 195 mov wptr cs:[CurPartition_Location+2], bx 138 196 mov wptr cs:[CurPartition_Location+4], dx 139 197 mov wptr cs:[CurPartition_Location+6], cx ; Saves the location 140 push ExecBaseSeg 141 pop ds 142 mov si, ExecBasePtr ; DS:SI - ExecBase 198 mov si, offset PartitionSector ; DS:SI - ExecBase 143 199 call DriveIO_LoadSector 144 200 clc 145 cmp w ord ptr ds:[si+LocBR_Magic], 0AA55h201 cmp wptr [si+LocBR_Magic], 0AA55h 146 202 je DIOLP_Success 147 203 ; We check, if we are scanning partitions. In that case, if CHS is not 0/0/1 … … 165 221 Preserve: all registers 166 222 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ* 167 DriveIO_SavePartition Proc Near Uses ax bx cx dx dssi223 DriveIO_SavePartition Proc Near Uses ax bx cx dx si 168 224 mov ax, wptr cs:[CurPartition_Location+0] 169 225 mov bx, wptr cs:[CurPartition_Location+2] 170 226 mov dx, wptr cs:[CurPartition_Location+4] 171 227 mov cx, wptr cs:[CurPartition_Location+6] ; Gets prev. saved location 172 push ExecBaseSeg173 pop ds174 mov si, ExecBasePtr ; DS:SI - ExecBase228 mov si, offset PartitionSector ; DS:SI - ExecBase 229 cmp wptr [si+LocBR_Magic], 0AA55h ; Checks for signature, if not found 230 jne DIOSP_SevereError ; we assume a really bad error 175 231 call DriveIO_SaveSector 232 DIOSP_SevereError: 176 233 ret 177 234 DriveIO_SavePartition EndP 178 235 179 ; Lsst DS:SI fr Aufrufer236 ; Keeps DS:SI for caller 180 237 DriveIO_LoadTmpSector Proc Near Uses 181 push cs182 pop ds183 238 mov si, offset TmpSector 184 239 call DriveIO_LoadSector … … 186 241 DriveIO_LoadTmpSector EndP 187 242 188 ; Lsst DS:SI fr Aufrufer243 ; Keeps DS:SI for caller 189 244 DriveIO_SaveTmpSector Proc Near Uses 190 push cs191 pop ds192 245 mov si, offset TmpSector 193 246 call DriveIO_SaveSector 194 247 ret 195 248 DriveIO_SaveTmpSector EndP 249 250 ; Keeps DS:SI for caller, sets carry if valid LVM sector encountered 251 DriveIO_LoadLVMSector Proc Near Uses ax bx cx dx 252 test [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so 253 jnz DIOLLVMS_NoLVMSector ; don't load but declare as bad! 254 mov ax, wptr cs:[CurPartition_Location+0] 255 mov bx, wptr cs:[CurPartition_Location+2] 256 mov dx, wptr cs:[CurPartition_Location+4] 257 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location 258 call DriveIO_LVMAdjustToInfoSector 259 mov si, offset LVMSector 260 call DriveIO_LoadSector 261 call LVM_CheckSectorSignature 262 jnc DIOLLVMS_NoLVMSector 263 call LVM_CheckSectorCRC 264 jnc DIOLLVMS_NoLVMSector 265 ret 266 ; This here is called, if an invalid (or no) LVM information sector is found 267 ; It will truncate the first byte of the sector, so all other routines 268 ; will notice it easily by just comparing the first byte. 269 DIOLLVMS_NoLVMSector: 270 mov bptr [si+LocLVM_SignatureStart], 0 271 ret 272 DriveIO_LoadLVMSector EndP 273 274 ; Keeps DS:SI for caller, saves at anytime w/o checks (!) 275 DriveIO_SaveLVMSector Proc Near Uses ax bx cx dx 276 test [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so 277 jnz DIOSLVMS_SevereError ; don't save at anytime (security!) 278 mov ax, wptr cs:[CurPartition_Location+0] 279 mov bx, wptr cs:[CurPartition_Location+2] 280 mov dx, wptr cs:[CurPartition_Location+4] 281 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location 282 call LVM_CheckSectorSignature 283 jnc DIOSLVMS_SevereError ; LVM Signature must be there 284 call DriveIO_LVMAdjustToInfoSector 285 mov si, offset LVMSector 286 call DriveIO_SaveSector 287 DIOSLVMS_SevereError: 288 ret 289 DriveIO_SaveLVMSector EndP 196 290 197 291 ; Memory-Block that holds information for LBA-access via INT 13h … … 206 300 ; so users will notice that something is bad with their partition table(s) 207 301 DriveIO_GotLoadError Proc Near 208 test cs:CurIO_Scanning, 1 ; Must be CS:, cause DS!=CS here302 test cs:CurIO_Scanning, 1 ; Must be CS:, cause DS!=CS maybe here 209 303 jnz InScanMode 210 304 jmp MBR_LoadError … … 213 307 push cs 214 308 pop ds 309 call MBR_Teletype 310 mov si, offset BrokenHDD 311 sub dl, 50h ; 80h -> '0' 312 cmp dl, 39h 313 jbe DIOGLE_BelowA 314 add dl, 7 ; 3Ah -> 'A' 315 DIOGLE_BelowA: 316 mov bptr [si+5], dl 215 317 call MBR_Teletype 216 318 jmp MBRLE_Halt … … 227 329 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ* 228 330 DriveIO_LoadSector Proc Near Uses ax bx ds si es di 229 test cs:[CurIO_UseExtension], 1 230 jz DIOLS_UseNormal 231 ; LBA-boundary >16450560 (FB0400h) 232 cmp bx, 00FBh 233 jae DIOLS_UseExtension 234 ; or are we forced do use LBA? 235 test cs:[CFG_ForceLBAUsage], 1 236 jnz DIOLS_UseExtension 331 test cs:[CurIO_UseExtension], 1 332 jz DIOLS_UseNormal 333 ; Are we forced do use LBA via Setting? 334 test cs:[CFG_ForceLBAUsage], 1 335 jnz DIOLS_UseExtension 336 ; Is the drive not a harddrive? 337 cmp dl, 80h 338 jb DIOLS_UseNormal 339 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h) 340 or bh, bh 341 jnz DIOLS_UseExtension 342 ; Compare Switch-Table value to bit 16-23 of LBA-address 343 mov di, dx 344 and di, 007Fh 345 cmp bptr cs:[LBASwitchTable+di], bl 346 jbe DIOLS_UseExtension 237 347 DIOLS_UseNormal: 238 mov di, 3348 mov di, 3 239 349 DIOLS_ErrorLoop: 240 push ds241 pop es242 mov bx, si; ES:BX - Destination243 mov ax, 0201h; Function 2 - Load Sector244 int 13h245 jnc DIOLS_Success246 dec di247 jnz DIOLS_ErrorLoop350 push ds 351 pop es 352 mov bx, si ; ES:BX - Destination 353 mov ax, 0201h ; Function 2 - Load Sector 354 int 13h 355 jnc DIOLS_Success 356 dec di 357 jnz DIOLS_ErrorLoop 248 358 ; Sector load failed... 249 jmp DriveIO_GotLoadError359 jmp DriveIO_GotLoadError 250 360 251 361 DIOLS_UseExtension: … … 260 370 pop ds 261 371 mov si, offset DriveIO_DAP 262 mov ah, 42h 372 mov ah, 42h ; Extended Read 263 373 int 13h 264 374 pop cx … … 281 391 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ* 282 392 DriveIO_SaveSector Proc Near Uses ax bx cx ds si es di 283 test cs:[CurIO_UseExtension], 1 284 jz DIOSS_UseNormal 285 ; LBA-boundary >16450560 (FB0400h) 286 cmp bx, 00FBh 287 jae DIOSS_UseExtension 288 ; or are we forced do use LBA? 289 test cs:[CFG_ForceLBAUsage], 1 290 jnz DIOSS_UseExtension 393 test cs:[CurIO_UseExtension], 1 394 jz DIOSS_UseNormal 395 ; Are we forced do use LBA via Setting? 396 test cs:[CFG_ForceLBAUsage], 1 397 jnz DIOSS_UseExtension 398 ; Is the drive not a harddrive? 399 cmp dl, 80h 400 jb DIOSS_UseNormal 401 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h) 402 or bh, bh 403 jnz DIOSS_UseExtension 404 ; Compare Switch-Table value to bit 16-23 of LBA-address 405 mov di, dx 406 and di, 007Fh 407 cmp bptr cs:[LBASwitchTable+di], bl 408 jbe DIOSS_UseExtension 291 409 DIOSS_UseNormal: 292 mov di, 3410 mov di, 3 293 411 DIOSS_ErrorLoop: 294 push ds295 pop es296 mov bx, si; ES:BX - Destination297 mov ax, 0301h; Function 3 - Write Sector298 int 13h299 jnc DIOSS_Success300 dec di301 jnz DIOSS_ErrorLoop302 call MBR_SaveError412 push ds 413 pop es 414 mov bx, si ; ES:BX - Destination 415 mov ax, 0301h ; Function 3 - Write Sector 416 int 13h 417 jnc DIOSS_Success 418 dec di 419 jnz DIOSS_ErrorLoop 420 call MBR_SaveError 303 421 304 422 DIOSS_UseExtension:
Note:
See TracChangeset
for help on using the changeset viewer.