[243] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Int 19h Handler (Boot Loader).
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[505] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 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 | ;
|
---|
[376] | 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
|
---|
[505] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[505] | 18 | ;
|
---|
[376] | 19 |
|
---|
[243] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; Int19h_BootLoaderHandler
|
---|
| 25 | ; Parameters:
|
---|
| 26 | ; Nothing
|
---|
| 27 | ; Returns:
|
---|
| 28 | ; Never returns (loads operating system)
|
---|
| 29 | ;--------------------------------------------------------------------
|
---|
| 30 | Int19h_BootLoaderHandler:
|
---|
[553] | 31 | sti ; Enable interrupts
|
---|
[592] | 32 | %ifdef CLD_NEEDED
|
---|
[553] | 33 | cld ; String instructions to increment pointers
|
---|
[592] | 34 | %endif
|
---|
[567] | 35 | %ifdef MODULE_VERY_LATE_INIT
|
---|
[561] | 36 | LOAD_BDA_SEGMENT_TO ds, ax ; Load BDA segment (zero) to DS
|
---|
| 37 | les ax, [TEMPORARY_VECTOR_FOR_SYSTEM_INT13h*4]
|
---|
| 38 | mov [BIOS_DISK_INTERRUPT_13h*4], ax
|
---|
| 39 | mov [BIOS_DISK_INTERRUPT_13h*4+2], es
|
---|
| 40 | push ds ; BDA segment (zero)...
|
---|
| 41 | pop es ; ...to ES
|
---|
| 42 | %else
|
---|
[560] | 43 | LOAD_BDA_SEGMENT_TO es, ax ; Load BDA segment (zero) to ES
|
---|
[556] | 44 | %endif
|
---|
[392] | 45 | ; Fall to .PrepareBootLoaderStack
|
---|
[243] | 46 |
|
---|
[392] | 47 |
|
---|
[243] | 48 | ;--------------------------------------------------------------------
|
---|
[392] | 49 | ; Drive detection and boot menu use lots of stack so it is
|
---|
| 50 | ; wise to relocate stack. Otherwise something important from
|
---|
| 51 | ; interrupt vectors are likely corrupted, likely our own DPTs if
|
---|
| 52 | ; they are located to 30:0h.
|
---|
| 53 | ;
|
---|
| 54 | ; .PrepareBootLoaderStack
|
---|
[243] | 55 | ; Parameters:
|
---|
| 56 | ; ES: BDA and interrupt vector segment (zero)
|
---|
| 57 | ; Returns:
|
---|
| 58 | ; Never returns (loads operating system)
|
---|
| 59 | ;--------------------------------------------------------------------
|
---|
[392] | 60 | .PrepareBootLoaderStack:
|
---|
[243] | 61 | STORE_POST_STACK_POINTER
|
---|
| 62 | SWITCH_TO_BOOT_MENU_STACK
|
---|
| 63 | ; Fall to .InitializeDisplay
|
---|
| 64 |
|
---|
[392] | 65 |
|
---|
[243] | 66 | ;--------------------------------------------------------------------
|
---|
| 67 | ; .InitializeDisplay
|
---|
| 68 | ; Parameters:
|
---|
[392] | 69 | ; ES: BDA and interrupt vector segment (zero)
|
---|
[243] | 70 | ; Returns:
|
---|
| 71 | ; Never returns (loads operating system)
|
---|
| 72 | ;--------------------------------------------------------------------
|
---|
| 73 | .InitializeDisplay:
|
---|
| 74 | ; Change display mode if necessary
|
---|
| 75 | mov ax, [cs:ROMVARS.wDisplayMode] ; AH 00h = Set Video Mode
|
---|
| 76 | cmp al, DEFAULT_TEXT_MODE
|
---|
| 77 | je SHORT .InitializeDisplayLibrary
|
---|
| 78 | int BIOS_VIDEO_INTERRUPT_10h
|
---|
| 79 | .InitializeDisplayLibrary:
|
---|
[392] | 80 | call DetectPrint_InitializeDisplayContext
|
---|
| 81 | ; Fall to .InitializeBiosAndDetectDrives
|
---|
[243] | 82 |
|
---|
[392] | 83 |
|
---|
[243] | 84 | ;--------------------------------------------------------------------
|
---|
[392] | 85 | ; .InitializeBiosAndDetectDrives
|
---|
[243] | 86 | ; Parameters:
|
---|
[392] | 87 | ; ES: BDA and interrupt vector segment (zero)
|
---|
[243] | 88 | ; Returns:
|
---|
[392] | 89 | ; DS: RAMVARS segment
|
---|
[243] | 90 | ;--------------------------------------------------------------------
|
---|
[555] | 91 | .InitializeBiosAndDetectDrives:
|
---|
[413] | 92 | call Initialize_AndDetectDrives
|
---|
| 93 |
|
---|
| 94 | %ifdef MODULE_HOTKEYS
|
---|
[547] | 95 | ; Last hard drive might have scrolled Hotkey Bar out of screen.
|
---|
| 96 | ; We want to display it during wait.
|
---|
[599] | 97 | ;call HotkeyBar_UpdateDuringDriveDetection
|
---|
[547] | 98 |
|
---|
[413] | 99 | .WaitUntilTimeToCloseHotkeyBar:
|
---|
| 100 | call TimerTicks_ReadFromBdaToAX
|
---|
[524] | 101 | sub ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed]
|
---|
| 102 | cmp ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
|
---|
[413] | 103 | jb SHORT .WaitUntilTimeToCloseHotkeyBar
|
---|
[599] | 104 |
|
---|
| 105 | ; Restore system timer tick handler since hotkeys are no longer needed
|
---|
| 106 | cli
|
---|
| 107 | mov ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.fpPrevTimerHandler]
|
---|
[601] | 108 | mov [es:BIOS_SYSTEM_TIMER_TICK_INTERRUPT_1Ch*4], ax
|
---|
[599] | 109 | mov ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.fpPrevTimerHandler+2]
|
---|
[601] | 110 | mov [es:BIOS_SYSTEM_TIMER_TICK_INTERRUPT_1Ch*4+2], ax
|
---|
[599] | 111 | sti
|
---|
[413] | 112 | %endif
|
---|
[555] | 113 | ; Fall to .ResetAllDrives
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | ;--------------------------------------------------------------------
|
---|
| 117 | ; .ResetAllDrives
|
---|
| 118 | ; Parameters:
|
---|
| 119 | ; DS: RAMVARS segment
|
---|
| 120 | ; ES: BDA and interrupt vector segment (zero)
|
---|
| 121 | ; Returns:
|
---|
| 122 | ; Nothing
|
---|
| 123 | ;--------------------------------------------------------------------
|
---|
| 124 | .ResetAllDrives:
|
---|
| 125 | ; Reset all drives in the system, not just our drives.
|
---|
| 126 | xor ax, ax ; Disk Controller Reset
|
---|
| 127 | mov dl, 80h ; Reset all hard drives and floppy drives
|
---|
| 128 | int BIOS_DISK_INTERRUPT_13h
|
---|
[392] | 129 | ; Fall to SelectDriveToBootFrom
|
---|
[243] | 130 |
|
---|
[392] | 131 |
|
---|
[243] | 132 | ;--------------------------------------------------------------------
|
---|
[392] | 133 | ; SelectDriveToBootFrom
|
---|
[243] | 134 | ; Parameters:
|
---|
| 135 | ; DS: RAMVARS segment
|
---|
[392] | 136 | ; ES: BDA and interrupt vector segment (zero)
|
---|
[243] | 137 | ; Returns:
|
---|
| 138 | ; Never returns (loads operating system)
|
---|
| 139 | ;--------------------------------------------------------------------
|
---|
[492] | 140 | ; The following macro could be easily inlined below. Why a macro? Depending on the combination
|
---|
| 141 | ; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
|
---|
[505] | 142 | ; call to the boot menu.
|
---|
[492] | 143 | ;
|
---|
| 144 | %macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
|
---|
| 145 | push dx ; it's OK if this is left on the stack, if we are
|
---|
[505] | 146 | ; successful, the following call does not return
|
---|
[528] | 147 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[492] | 148 | pop dx
|
---|
| 149 | mov dl, dh
|
---|
[528] | 150 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[492] | 151 | %endmacro
|
---|
[505] | 152 |
|
---|
[528] | 153 |
|
---|
| 154 | SelectDriveToBootFrom: ; Function starts here
|
---|
[395] | 155 | %ifdef MODULE_HOTKEYS
|
---|
[528] | 156 | mov al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
|
---|
[492] | 157 | cmp al, ROM_BOOT_HOTKEY_SCANCODE
|
---|
[528] | 158 | je SHORT .RomBoot ; CF clear so ROM boot
|
---|
[392] | 159 | %ifdef MODULE_BOOT_MENU
|
---|
[492] | 160 | cmp al, BOOT_MENU_HOTKEY_SCANCODE
|
---|
[528] | 161 | je SHORT .BootMenu
|
---|
| 162 | %endif ; MODULE_BOOT_MENU
|
---|
| 163 |
|
---|
| 164 | .TryUsingHotKeysCode:
|
---|
[492] | 165 | call HotkeyBar_GetBootDriveNumbersToDX
|
---|
[528] | 166 | call DriveXlate_SetDriveToSwap ; Enable primary boot device translation
|
---|
| 167 | xchg dl, dh
|
---|
| 168 | call DriveXlate_SetDriveToSwap ; Enable secondary boot device translation
|
---|
| 169 | xchg dl, dh
|
---|
[529] | 170 | call DriveXlate_ToOrBack ; Translate now so boot device will appear as 00h or 80h to OS
|
---|
[492] | 171 | TRY_TO_BOOT_DL_AND_DH_DRIVES
|
---|
| 172 | ;; falls through to boot menu, if it is present. If not present, falls through to rom boot.
|
---|
[505] | 173 | %endif ; MODULE_HOTKEYS
|
---|
[392] | 174 |
|
---|
[528] | 175 |
|
---|
[492] | 176 | %ifdef MODULE_BOOT_MENU
|
---|
[505] | 177 | .BootMenu:
|
---|
[492] | 178 | call BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
|
---|
[528] | 179 | jnc SHORT .RomBoot ; CF clear so ROM boot
|
---|
[392] | 180 |
|
---|
[528] | 181 | call DriveXlate_Reset
|
---|
| 182 | %ifdef MODULE_HOTKEYS
|
---|
| 183 | jmp SHORT .TryUsingHotKeysCode ; Selected drive stored as hotkey
|
---|
| 184 | %else ; Boot menu without hotkeys, secondary boot drive is always 00h or 80h
|
---|
[492] | 185 | mov dh, dl ; Setup for secondary drive
|
---|
[505] | 186 | not dh ; Floppy goes to HD, or vice versa
|
---|
| 187 | and dh, 80h ; Go to first drive of the floppy or HD set
|
---|
[528] | 188 | call DriveXlate_SetDriveToSwap
|
---|
| 189 | call DriveXlate_ToOrBack
|
---|
| 190 | TRY_TO_BOOT_DL_AND_DH_DRIVES
|
---|
| 191 | jmp SHORT .BootMenu ; Show boot menu again
|
---|
| 192 | %endif ; MODULE_HOTKEYS
|
---|
[398] | 193 |
|
---|
[505] | 194 | %endif ; MODULE_BOOT_MENU
|
---|
[392] | 195 |
|
---|
[528] | 196 | ; No hotkeys and no boot menu means fixed "A then C" boot order
|
---|
[505] | 197 | %ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
|
---|
[529] | 198 | xor dl, dl ; Try to boot from Floppy Drive A
|
---|
[528] | 199 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[529] | 200 | mov dl, 80h ; Try to boot from Hard Drive C
|
---|
[528] | 201 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[386] | 202 | %endif
|
---|
[243] | 203 |
|
---|
[493] | 204 | .RomBoot:
|
---|
| 205 | %ifdef MODULE_DRIVEXLATE
|
---|
| 206 | call DriveXlate_Reset ; Clean up any drive mappings before Rom Boot
|
---|
| 207 | %endif
|
---|
[597] | 208 | stc
|
---|
| 209 | ;; fall through to Int19h_JumpToBootSectorInESBXOrRomBoot
|
---|
[392] | 210 |
|
---|
[243] | 211 | ;--------------------------------------------------------------------
|
---|
[597] | 212 | ; Int19h_JumpToBootSectorInESBXOrRomBoot
|
---|
[243] | 213 | ;
|
---|
| 214 | ; Switches back to the POST stack, clears the DS and ES registers,
|
---|
| 215 | ; and either jumps to the MBR (Master Boot Record) that was just read,
|
---|
[601] | 216 | ; or calls the ROM's boot routine on interrupt 18h.
|
---|
[243] | 217 | ;
|
---|
| 218 | ; Parameters:
|
---|
| 219 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
[597] | 220 | ; CF: Clear for Boot Sector Boot
|
---|
| 221 | ; Set for ROM Boot
|
---|
| 222 | ; ES:BX: (if CF clear) Ptr to boot sector (ES = zero)
|
---|
[243] | 223 | ;
|
---|
| 224 | ; Returns:
|
---|
| 225 | ; Never returns
|
---|
| 226 | ;--------------------------------------------------------------------
|
---|
[597] | 227 | Int19h_JumpToBootSectorInESBXOrRomBoot:
|
---|
| 228 | mov ax, es ; Clear AX. NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
|
---|
[243] | 229 | SWITCH_BACK_TO_POST_STACK
|
---|
| 230 |
|
---|
| 231 | ; clear segment registers before boot sector or rom call
|
---|
[597] | 232 | Int19h_JumpToBootSectorInESBXOrRomBootWithoutStackChange:
|
---|
| 233 | mov ax, es ; Clear AX and preserve CF
|
---|
[505] | 234 | mov ds, ax
|
---|
[243] | 235 | %ifdef USE_386
|
---|
| 236 | mov fs, ax
|
---|
| 237 | mov gs, ax
|
---|
| 238 | %endif
|
---|
[597] | 239 | jc SHORT .RomBoot
|
---|
[243] | 240 |
|
---|
| 241 | ; jump to boot sector
|
---|
[597] | 242 | push es ; sgment address for MBR
|
---|
[243] | 243 | push bx ; offset address for MBR
|
---|
| 244 | retf ; NOTE: DL is set to the drive number
|
---|
| 245 |
|
---|
| 246 | ; Boot by calling INT 18h (ROM Basic of ROM DOS)
|
---|
[596] | 247 | .RomBoot:
|
---|
[505] | 248 | int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
|
---|