[90] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Int 19h BIOS functions (Boot Strap Loader).
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | B_READ_RETRY_TIMES EQU 3 ; Number of times to retry
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | ;--------------------------------------------------------------------
|
---|
| 11 | ; Boots if boot sector is successfully read from the drive.
|
---|
| 12 | ;
|
---|
| 13 | ; Int19h_TryToLoadBootSectorFromDL
|
---|
| 14 | ; Parameters:
|
---|
| 15 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 16 | ; DS: RAMVARS segment
|
---|
| 17 | ; Returns:
|
---|
| 18 | ; ES:BX: Ptr to boot sector (if successfull)
|
---|
| 19 | ; CF: Set if boot sector loaded succesfully
|
---|
| 20 | ; Cleared if failed to load boot sector
|
---|
| 21 | ; Corrupts registers:
|
---|
| 22 | ; AX, CX, DH, DI, (DL if failed to read boot sector)
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ALIGN JUMP_ALIGN
|
---|
| 25 | Int19h_TryToLoadBootSectorFromDL:
|
---|
| 26 | call BootPrint_TryToBootFromDL
|
---|
[95] | 27 | call LoadFirstSectorFromDriveDL
|
---|
[3] | 28 | jc SHORT .FailedToLoadFirstSector
|
---|
[61] | 29 |
|
---|
| 30 | test dl, 80h
|
---|
| 31 | jz SHORT .AlwaysBootFromFloppyDriveForBooterGames
|
---|
[3] | 32 | cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
|
---|
[61] | 33 | jne SHORT .FirstHardDiskSectorNotBootable
|
---|
| 34 | .AlwaysBootFromFloppyDriveForBooterGames:
|
---|
[95] | 35 | mov bx, g_szFound
|
---|
| 36 | call BootPrint_BootSectorResultStringFromBX
|
---|
[3] | 37 | stc
|
---|
| 38 | ret
|
---|
| 39 | .FailedToLoadFirstSector:
|
---|
| 40 | call BootPrint_FailedToLoadFirstSector
|
---|
| 41 | clc
|
---|
| 42 | ret
|
---|
[61] | 43 | .FirstHardDiskSectorNotBootable:
|
---|
[95] | 44 | mov bx, g_szNotFound
|
---|
| 45 | call BootPrint_BootSectorResultStringFromBX
|
---|
[3] | 46 | clc
|
---|
| 47 | ret
|
---|
| 48 |
|
---|
| 49 | ;--------------------------------------------------------------------
|
---|
[95] | 50 | ; LoadFirstSectorFromDriveDL
|
---|
[3] | 51 | ; Parameters:
|
---|
| 52 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 53 | ; Returns:
|
---|
| 54 | ; AH: INT 13h error code
|
---|
| 55 | ; ES:BX: Ptr to boot sector (if successfull)
|
---|
| 56 | ; CF: Cleared if read successfull
|
---|
| 57 | ; Set if any error
|
---|
| 58 | ; Corrupts registers:
|
---|
| 59 | ; AL, CX, DH, DI
|
---|
| 60 | ;--------------------------------------------------------------------
|
---|
| 61 | ALIGN JUMP_ALIGN
|
---|
[95] | 62 | LoadFirstSectorFromDriveDL:
|
---|
[3] | 63 | LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
|
---|
| 64 | mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
|
---|
[95] | 65 | mov di, B_READ_RETRY_TIMES ; Initialize retry counter
|
---|
[3] | 66 | ALIGN JUMP_ALIGN
|
---|
| 67 | .ReadRetryLoop:
|
---|
[28] | 68 | call .ResetBootDriveFromDL
|
---|
| 69 | call .LoadFirstSectorFromDLtoESBX
|
---|
[3] | 70 | jnc SHORT .Return
|
---|
| 71 | dec di ; Decrement retry counter
|
---|
| 72 | jnz SHORT .ReadRetryLoop ; Loop while retries left
|
---|
| 73 | ALIGN JUMP_ALIGN
|
---|
| 74 | .Return:
|
---|
| 75 | ret
|
---|
| 76 |
|
---|
| 77 | ;--------------------------------------------------------------------
|
---|
[28] | 78 | ; .ResetBootDriveFromDL
|
---|
[3] | 79 | ; Parameters:
|
---|
| 80 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 81 | ; Returns:
|
---|
| 82 | ; AH: INT 13h error code
|
---|
| 83 | ; CF: Cleared if read successfull
|
---|
| 84 | ; Set if any error
|
---|
| 85 | ; Corrupts registers:
|
---|
[28] | 86 | ; AL
|
---|
[3] | 87 | ;--------------------------------------------------------------------
|
---|
| 88 | ALIGN JUMP_ALIGN
|
---|
[28] | 89 | .ResetBootDriveFromDL:
|
---|
| 90 | xor ax, ax ; AH=0h, Disk Controller Reset
|
---|
| 91 | test dl, 80h ; Floppy drive?
|
---|
[95] | 92 | eCMOVNZ ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
|
---|
[3] | 93 | int INTV_DISK_FUNC
|
---|
| 94 | ret
|
---|
| 95 |
|
---|
| 96 | ;--------------------------------------------------------------------
|
---|
[28] | 97 | ; Reads first sector (boot sector) from drive DL to ES:BX.
|
---|
[3] | 98 | ;
|
---|
[28] | 99 | ; .LoadFirstSectorFromDLtoESBX
|
---|
[3] | 100 | ; Parameters:
|
---|
| 101 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
[28] | 102 | ; ES:BX: Destination buffer for boot sector
|
---|
[3] | 103 | ; Returns:
|
---|
[28] | 104 | ; AH: INT 13h error code
|
---|
| 105 | ; ES:BX: Ptr to boot sector
|
---|
| 106 | ; CF: Cleared if read successfull
|
---|
| 107 | ; Set if any error
|
---|
[3] | 108 | ; Corrupts registers:
|
---|
[28] | 109 | ; AL, CX, DH
|
---|
[3] | 110 | ;--------------------------------------------------------------------
|
---|
| 111 | ALIGN JUMP_ALIGN
|
---|
[28] | 112 | .LoadFirstSectorFromDLtoESBX:
|
---|
| 113 | mov ax, 0201h ; Read 1 sector
|
---|
| 114 | mov cx, 1 ; Cylinder 0, Sector 1
|
---|
| 115 | xor dh, dh ; Head 0
|
---|
[3] | 116 | int INTV_DISK_FUNC
|
---|
| 117 | ret
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | ;--------------------------------------------------------------------
|
---|
| 121 | ; Jumps to boot sector pointed by ES:BX.
|
---|
| 122 | ;
|
---|
| 123 | ; Int19h_JumpToBootSector
|
---|
| 124 | ; Parameters:
|
---|
| 125 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 126 | ; ES:BX: Ptr to boot sector
|
---|
| 127 | ; Returns:
|
---|
| 128 | ; Never returns
|
---|
| 129 | ;--------------------------------------------------------------------
|
---|
| 130 | ALIGN JUMP_ALIGN
|
---|
| 131 | Int19h_JumpToBootSector:
|
---|
| 132 | push es ; Push boot sector segment
|
---|
| 133 | push bx ; Push boot sector offset
|
---|
| 134 | call Int19h_ClearSegmentsForBoot
|
---|
| 135 | xor dh, dh ; Device supported by INT 13h
|
---|
| 136 | retf
|
---|
| 137 |
|
---|
| 138 | ;--------------------------------------------------------------------
|
---|
| 139 | ; Clears DS and ES registers to zero.
|
---|
| 140 | ;
|
---|
| 141 | ; Int19h_ClearSegmentsForBoot
|
---|
| 142 | ; Parameters:
|
---|
| 143 | ; Nothing
|
---|
| 144 | ; Returns:
|
---|
| 145 | ; DS=ES: Zero
|
---|
| 146 | ; Corrupts registers:
|
---|
| 147 | ; AX
|
---|
| 148 | ;--------------------------------------------------------------------
|
---|
| 149 | ALIGN JUMP_ALIGN
|
---|
| 150 | Int19h_ClearSegmentsForBoot:
|
---|
| 151 | xor ax, ax
|
---|
| 152 | mov ds, ax
|
---|
| 153 | mov es, ax
|
---|
| 154 | ret
|
---|