[392] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Reading and jumping to boot sector.
|
---|
| 3 |
|
---|
| 4 | ;
|
---|
[505] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[392] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[505] | 12 | ;
|
---|
[392] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
[505] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
[392] | 19 |
|
---|
| 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[505] | 24 | ; BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[392] | 25 | ; Parameters:
|
---|
| 26 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 27 | ; DS: RAMVARS segment
|
---|
| 28 | ; Returns:
|
---|
| 29 | ; ES:BX: Ptr to boot sector (if successful)
|
---|
| 30 | ; CF: Set if boot sector loaded successfully
|
---|
| 31 | ; Cleared if failed to load boot sector
|
---|
| 32 | ; Corrupts registers:
|
---|
| 33 | ; AX, CX, DH, SI, DI, (DL if failed to read boot sector)
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
[492] | 35 | BootSector_TryToLoadFromDriveDL_AndBoot:
|
---|
[392] | 36 | call DetectPrint_TryToBootFromDL
|
---|
| 37 | call LoadFirstSectorFromDriveDL
|
---|
[505] | 38 | %ifndef USE_386
|
---|
[392] | 39 | jc SHORT .FailedToLoadFirstSector
|
---|
[505] | 40 | %else
|
---|
| 41 | jc DetectPrint_FailedToLoadFirstSector
|
---|
| 42 | %endif
|
---|
[392] | 43 |
|
---|
| 44 | test dl, dl
|
---|
| 45 | jns SHORT .AlwaysBootFromFloppyDriveForBooterGames
|
---|
| 46 | cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
|
---|
| 47 | jne SHORT .FirstHardDiskSectorNotBootable
|
---|
| 48 | .AlwaysBootFromFloppyDriveForBooterGames:
|
---|
| 49 | stc
|
---|
[505] | 50 | jmp SHORT JumpToBootSector_or_RomBoot
|
---|
| 51 |
|
---|
| 52 | %ifndef USE_386
|
---|
[392] | 53 | .FailedToLoadFirstSector:
|
---|
[505] | 54 | jmp DetectPrint_FailedToLoadFirstSector
|
---|
| 55 | %endif
|
---|
| 56 |
|
---|
[392] | 57 | .FirstHardDiskSectorNotBootable:
|
---|
| 58 | mov si, g_szBootSectorNotFound
|
---|
[505] | 59 | jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
[392] | 60 |
|
---|
[505] | 61 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[492] | 62 | %ifdef MODULE_DRIVEXLATE
|
---|
| 63 | %if TryToBoot_FallThroughTo_BootSector_TryToLoadFromDriveDL_AndBoot <> BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
| 64 | %error "TryToBoot_FallThroughTo_BootSector_TryToLoadFromDriveDL_AndBoot <> BootSector_TryToLoadFromDriveDL_AndBoot, BootSector must come immediately after int19h.asm"
|
---|
| 65 | %endif
|
---|
| 66 | %endif
|
---|
| 67 | %endif
|
---|
| 68 |
|
---|
[392] | 69 | ;--------------------------------------------------------------------
|
---|
| 70 | ; LoadFirstSectorFromDriveDL
|
---|
| 71 | ; Parameters:
|
---|
| 72 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 73 | ; Returns:
|
---|
| 74 | ; AH: INT 13h error code
|
---|
| 75 | ; ES:BX: Ptr to boot sector (if successful)
|
---|
| 76 | ; CF: Cleared if read successful
|
---|
| 77 | ; Set if any error
|
---|
| 78 | ; Corrupts registers:
|
---|
| 79 | ; AL, CX, DH, DI
|
---|
| 80 | ;--------------------------------------------------------------------
|
---|
| 81 | LoadFirstSectorFromDriveDL:
|
---|
| 82 | LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
|
---|
| 83 | mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
|
---|
| 84 | mov di, BOOT_READ_RETRY_TIMES ; Initialize retry counter
|
---|
| 85 |
|
---|
| 86 | .ReadRetryLoop:
|
---|
[505] | 87 | mov ax, 0201h ; Read 1 sector
|
---|
| 88 | mov cx, 1 ; Cylinder 0, Sector 1
|
---|
| 89 | xor dh, dh ; Head 0
|
---|
| 90 | int BIOS_DISK_INTERRUPT_13h
|
---|
| 91 | jc SHORT .FailedToLoadFirstSector
|
---|
| 92 | .Return:
|
---|
| 93 | ret
|
---|
| 94 |
|
---|
| 95 | .FailedToLoadFirstSector:
|
---|
[428] | 96 | dec di ; Decrement retry counter (preserve CF)
|
---|
| 97 | jz SHORT .Return ; Loop while retries left
|
---|
[392] | 98 |
|
---|
[428] | 99 | ; Reset drive and retry
|
---|
[505] | 100 | xor ax, ax ; AH=00h, Disk Controller Reset
|
---|
[392] | 101 | test dl, dl ; Floppy drive?
|
---|
[505] | 102 | eCMOVS ah, RESET_HARD_DISK ; AH=0Dh, Reset Hard Disk (Alternate reset)
|
---|
[392] | 103 | int BIOS_DISK_INTERRUPT_13h
|
---|
[428] | 104 | jmp SHORT .ReadRetryLoop
|
---|
[392] | 105 |
|
---|