[3] | 1 | ; File name : Int19h.asm
|
---|
| 2 | ; Project name : IDE BIOS
|
---|
| 3 | ; Created date : 3.8.2007
|
---|
[28] | 4 | ; Last update : 1.8.2010
|
---|
[3] | 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Int 19h BIOS functions (Boot Strap Loader).
|
---|
| 7 |
|
---|
| 8 | ; Section containing code
|
---|
| 9 | SECTION .text
|
---|
| 10 |
|
---|
| 11 | B_READ_RETRY_TIMES EQU 3 ; Number of times to retry
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | ;--------------------------------------------------------------------
|
---|
| 15 | ; Int 19h software interrupt handler for late initialization.
|
---|
| 16 | ; Calls actual Int 19h after initialization is complete.
|
---|
| 17 | ;
|
---|
| 18 | ; Int19h_LateInitialization
|
---|
| 19 | ; Parameters:
|
---|
| 20 | ; Nothing
|
---|
| 21 | ; Returns:
|
---|
| 22 | ; Never returns
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ALIGN JUMP_ALIGN
|
---|
| 25 | Int19h_LateInitialization:
|
---|
| 26 | call Initialize_ShouldSkip ; Skip initialization?
|
---|
| 27 | jc SHORT .SkipInitialization
|
---|
| 28 | call Initialize_AndDetectDrives
|
---|
| 29 | int INTV_BOOTSTRAP ; Call actual boot loader
|
---|
| 30 | .SkipInitialization:
|
---|
| 31 | call RamVars_Initialize ; RAMVARS must be initialized even for simple boot loader
|
---|
| 32 | ; Fall to Int19h_SimpleBootLoader
|
---|
| 33 |
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
| 35 | ; Simple boot loader.
|
---|
| 36 | ; Boot sequence is fixed to 00h, 80h and INT 18h.
|
---|
| 37 | ;
|
---|
| 38 | ; Int19h_SimpleBootLoader
|
---|
| 39 | ; Parameters:
|
---|
| 40 | ; Nothing
|
---|
| 41 | ; Returns:
|
---|
| 42 | ; Never returns
|
---|
| 43 | ;--------------------------------------------------------------------
|
---|
| 44 | ALIGN JUMP_ALIGN
|
---|
| 45 | Int19h_SimpleBootLoader:
|
---|
| 46 | sti ; Enable interrupts
|
---|
| 47 | call RamVars_GetSegmentToDS
|
---|
| 48 | xor dx, dx
|
---|
| 49 | call Int19h_TryToLoadBootSectorFromDL
|
---|
| 50 | jc SHORT Int19h_JumpToBootSector
|
---|
| 51 | mov dl, 80h
|
---|
| 52 | call Int19h_TryToLoadBootSectorFromDL
|
---|
| 53 | jc SHORT Int19h_JumpToBootSector
|
---|
| 54 | call Int19h_BootFailure ; Should never return
|
---|
| 55 | jmp SHORT Int19h_SimpleBootLoader
|
---|
| 56 |
|
---|
| 57 | ;--------------------------------------------------------------------
|
---|
| 58 | ; Boots if boot sector is successfully read from the drive.
|
---|
| 59 | ;
|
---|
| 60 | ; Int19h_TryToLoadBootSectorFromDL
|
---|
| 61 | ; Parameters:
|
---|
| 62 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 63 | ; DS: RAMVARS segment
|
---|
| 64 | ; Returns:
|
---|
| 65 | ; ES:BX: Ptr to boot sector (if successfull)
|
---|
| 66 | ; CF: Set if boot sector loaded succesfully
|
---|
| 67 | ; Cleared if failed to load boot sector
|
---|
| 68 | ; Corrupts registers:
|
---|
| 69 | ; AX, CX, DH, DI, (DL if failed to read boot sector)
|
---|
| 70 | ;--------------------------------------------------------------------
|
---|
| 71 | ALIGN JUMP_ALIGN
|
---|
| 72 | Int19h_TryToLoadBootSectorFromDL:
|
---|
| 73 | call BootPrint_TryToBootFromDL
|
---|
| 74 | call Int19h_LoadFirstSectorFromDL
|
---|
| 75 | jc SHORT .FailedToLoadFirstSector
|
---|
| 76 | cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
|
---|
| 77 | jne SHORT .FirstSectorNotBootable
|
---|
| 78 | call BootPrint_BootSectorLoaded
|
---|
| 79 | stc
|
---|
| 80 | ret
|
---|
| 81 | .FailedToLoadFirstSector:
|
---|
| 82 | call BootPrint_FailedToLoadFirstSector
|
---|
| 83 | clc
|
---|
| 84 | ret
|
---|
| 85 | .FirstSectorNotBootable:
|
---|
| 86 | call BootPrint_FirstSectorNotBootable
|
---|
| 87 | clc
|
---|
| 88 | ret
|
---|
| 89 |
|
---|
| 90 | ;--------------------------------------------------------------------
|
---|
| 91 | ; Reads first sector (boot sector) from drive DL.
|
---|
| 92 | ;
|
---|
| 93 | ; Int19h_LoadFirstSectorFromDL
|
---|
| 94 | ; Parameters:
|
---|
| 95 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 96 | ; Returns:
|
---|
| 97 | ; AH: INT 13h error code
|
---|
| 98 | ; ES:BX: Ptr to boot sector (if successfull)
|
---|
| 99 | ; CF: Cleared if read successfull
|
---|
| 100 | ; Set if any error
|
---|
| 101 | ; Corrupts registers:
|
---|
| 102 | ; AL, CX, DH, DI
|
---|
| 103 | ;--------------------------------------------------------------------
|
---|
| 104 | ALIGN JUMP_ALIGN
|
---|
| 105 | Int19h_LoadFirstSectorFromDL:
|
---|
| 106 | LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
|
---|
| 107 | mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
|
---|
| 108 | mov di, B_READ_RETRY_TIMES ; Retry counter
|
---|
| 109 | ALIGN JUMP_ALIGN
|
---|
| 110 | .ReadRetryLoop:
|
---|
[28] | 111 | call .ResetBootDriveFromDL
|
---|
| 112 | call .LoadFirstSectorFromDLtoESBX
|
---|
[3] | 113 | jnc SHORT .Return
|
---|
| 114 | dec di ; Decrement retry counter
|
---|
| 115 | jnz SHORT .ReadRetryLoop ; Loop while retries left
|
---|
| 116 | stc
|
---|
| 117 | ALIGN JUMP_ALIGN
|
---|
| 118 | .Return:
|
---|
| 119 | ret
|
---|
| 120 |
|
---|
| 121 | ;--------------------------------------------------------------------
|
---|
[28] | 122 | ; .ResetBootDriveFromDL
|
---|
[3] | 123 | ; Parameters:
|
---|
| 124 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 125 | ; Returns:
|
---|
| 126 | ; AH: INT 13h error code
|
---|
| 127 | ; CF: Cleared if read successfull
|
---|
| 128 | ; Set if any error
|
---|
| 129 | ; Corrupts registers:
|
---|
[28] | 130 | ; AL
|
---|
[3] | 131 | ;--------------------------------------------------------------------
|
---|
| 132 | ALIGN JUMP_ALIGN
|
---|
[28] | 133 | .ResetBootDriveFromDL:
|
---|
| 134 | xor ax, ax ; AH=0h, Disk Controller Reset
|
---|
| 135 | test dl, 80h ; Floppy drive?
|
---|
| 136 | jz SHORT .ResetDriveFromDL ; If so, jump to reset
|
---|
| 137 | mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
|
---|
| 138 | .ResetDriveFromDL:
|
---|
[3] | 139 | int INTV_DISK_FUNC
|
---|
| 140 | ret
|
---|
| 141 |
|
---|
| 142 | ;--------------------------------------------------------------------
|
---|
[28] | 143 | ; Reads first sector (boot sector) from drive DL to ES:BX.
|
---|
[3] | 144 | ;
|
---|
[28] | 145 | ; .LoadFirstSectorFromDLtoESBX
|
---|
[3] | 146 | ; Parameters:
|
---|
| 147 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
[28] | 148 | ; ES:BX: Destination buffer for boot sector
|
---|
[3] | 149 | ; Returns:
|
---|
[28] | 150 | ; AH: INT 13h error code
|
---|
| 151 | ; ES:BX: Ptr to boot sector
|
---|
| 152 | ; CF: Cleared if read successfull
|
---|
| 153 | ; Set if any error
|
---|
[3] | 154 | ; Corrupts registers:
|
---|
[28] | 155 | ; AL, CX, DH
|
---|
[3] | 156 | ;--------------------------------------------------------------------
|
---|
| 157 | ALIGN JUMP_ALIGN
|
---|
[28] | 158 | .LoadFirstSectorFromDLtoESBX:
|
---|
| 159 | mov ax, 0201h ; Read 1 sector
|
---|
| 160 | mov cx, 1 ; Cylinder 0, Sector 1
|
---|
| 161 | xor dh, dh ; Head 0
|
---|
[3] | 162 | int INTV_DISK_FUNC
|
---|
| 163 | ret
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 | ;--------------------------------------------------------------------
|
---|
| 167 | ; Jumps to boot sector pointed by ES:BX.
|
---|
| 168 | ;
|
---|
| 169 | ; Int19h_JumpToBootSector
|
---|
| 170 | ; Parameters:
|
---|
| 171 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 172 | ; ES:BX: Ptr to boot sector
|
---|
| 173 | ; Returns:
|
---|
| 174 | ; Never returns
|
---|
| 175 | ;--------------------------------------------------------------------
|
---|
| 176 | ALIGN JUMP_ALIGN
|
---|
| 177 | Int19h_JumpToBootSector:
|
---|
| 178 | push es ; Push boot sector segment
|
---|
| 179 | push bx ; Push boot sector offset
|
---|
| 180 | call Int19h_ClearSegmentsForBoot
|
---|
| 181 | xor dh, dh ; Device supported by INT 13h
|
---|
| 182 | retf
|
---|
| 183 |
|
---|
| 184 | ;--------------------------------------------------------------------
|
---|
| 185 | ; Clears DS and ES registers to zero.
|
---|
| 186 | ;
|
---|
| 187 | ; Int19h_ClearSegmentsForBoot
|
---|
| 188 | ; Parameters:
|
---|
| 189 | ; Nothing
|
---|
| 190 | ; Returns:
|
---|
| 191 | ; DS=ES: Zero
|
---|
| 192 | ; Corrupts registers:
|
---|
| 193 | ; AX
|
---|
| 194 | ;--------------------------------------------------------------------
|
---|
| 195 | ALIGN JUMP_ALIGN
|
---|
| 196 | Int19h_ClearSegmentsForBoot:
|
---|
| 197 | xor ax, ax
|
---|
| 198 | mov ds, ax
|
---|
| 199 | mov es, ax
|
---|
| 200 | ret
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | ;--------------------------------------------------------------------
|
---|
| 204 | ; Calls INT 18h (ROM Basic or Boot Failure). Called after booting from
|
---|
| 205 | ; floppy drive or hard disk fails.
|
---|
| 206 | ;
|
---|
| 207 | ; Int19h_BootFailure
|
---|
| 208 | ; Parameters:
|
---|
| 209 | ; Nothing
|
---|
| 210 | ; Returns:
|
---|
| 211 | ; Should never return (but might)
|
---|
| 212 | ;--------------------------------------------------------------------
|
---|
| 213 | ALIGN JUMP_ALIGN
|
---|
| 214 | Int19h_BootFailure:
|
---|
| 215 | call Int19h_ClearSegmentsForBoot
|
---|
| 216 | int INTV_BOOT_FAILURE
|
---|
| 217 | ret
|
---|