[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:
|
---|
[414] | 31 | sti ; Enable interrupts
|
---|
| 32 | cld ; String instructions to increment pointers
|
---|
| 33 | LOAD_BDA_SEGMENT_TO es, ax ; Load BDA segment (zero) to ES
|
---|
[392] | 34 | ; Fall to .PrepareBootLoaderStack
|
---|
[243] | 35 |
|
---|
[392] | 36 |
|
---|
[243] | 37 | ;--------------------------------------------------------------------
|
---|
[392] | 38 | ; Drive detection and boot menu use lots of stack so it is
|
---|
| 39 | ; wise to relocate stack. Otherwise something important from
|
---|
| 40 | ; interrupt vectors are likely corrupted, likely our own DPTs if
|
---|
| 41 | ; they are located to 30:0h.
|
---|
| 42 | ;
|
---|
| 43 | ; .PrepareBootLoaderStack
|
---|
[243] | 44 | ; Parameters:
|
---|
| 45 | ; ES: BDA and interrupt vector segment (zero)
|
---|
| 46 | ; Returns:
|
---|
| 47 | ; Never returns (loads operating system)
|
---|
| 48 | ;--------------------------------------------------------------------
|
---|
[392] | 49 | .PrepareBootLoaderStack:
|
---|
[243] | 50 | STORE_POST_STACK_POINTER
|
---|
| 51 | SWITCH_TO_BOOT_MENU_STACK
|
---|
| 52 | ; Fall to .InitializeDisplay
|
---|
| 53 |
|
---|
[392] | 54 |
|
---|
[243] | 55 | ;--------------------------------------------------------------------
|
---|
| 56 | ; .InitializeDisplay
|
---|
| 57 | ; Parameters:
|
---|
[392] | 58 | ; ES: BDA and interrupt vector segment (zero)
|
---|
[243] | 59 | ; Returns:
|
---|
| 60 | ; Never returns (loads operating system)
|
---|
| 61 | ;--------------------------------------------------------------------
|
---|
| 62 | .InitializeDisplay:
|
---|
| 63 | ; Change display mode if necessary
|
---|
| 64 | mov ax, [cs:ROMVARS.wDisplayMode] ; AH 00h = Set Video Mode
|
---|
| 65 | cmp al, DEFAULT_TEXT_MODE
|
---|
| 66 | je SHORT .InitializeDisplayLibrary
|
---|
| 67 | int BIOS_VIDEO_INTERRUPT_10h
|
---|
| 68 | .InitializeDisplayLibrary:
|
---|
[392] | 69 | call DetectPrint_InitializeDisplayContext
|
---|
| 70 | ; Fall to .InitializeBiosAndDetectDrives
|
---|
[243] | 71 |
|
---|
[392] | 72 |
|
---|
[243] | 73 | ;--------------------------------------------------------------------
|
---|
[392] | 74 | ; .InitializeBiosAndDetectDrives
|
---|
[243] | 75 | ; Parameters:
|
---|
[392] | 76 | ; ES: BDA and interrupt vector segment (zero)
|
---|
[243] | 77 | ; Returns:
|
---|
[392] | 78 | ; DS: RAMVARS segment
|
---|
[243] | 79 | ;--------------------------------------------------------------------
|
---|
[413] | 80 | %ifdef MODULE_HOTKEYS
|
---|
| 81 | call TimerTicks_ReadFromBdaToAX
|
---|
[524] | 82 | mov [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed], ax
|
---|
[413] | 83 | %endif
|
---|
| 84 |
|
---|
| 85 | call Initialize_AndDetectDrives
|
---|
| 86 |
|
---|
| 87 | %ifdef MODULE_HOTKEYS
|
---|
[547] | 88 | ; Last hard drive might have scrolled Hotkey Bar out of screen.
|
---|
| 89 | ; We want to display it during wait.
|
---|
| 90 | call HotkeyBar_UpdateDuringDriveDetection
|
---|
| 91 |
|
---|
[413] | 92 | .WaitUntilTimeToCloseHotkeyBar:
|
---|
| 93 | call TimerTicks_ReadFromBdaToAX
|
---|
[524] | 94 | sub ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed]
|
---|
| 95 | cmp ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
|
---|
[413] | 96 | jb SHORT .WaitUntilTimeToCloseHotkeyBar
|
---|
| 97 | %endif
|
---|
[392] | 98 | ; Fall to SelectDriveToBootFrom
|
---|
[243] | 99 |
|
---|
[392] | 100 |
|
---|
[243] | 101 | ;--------------------------------------------------------------------
|
---|
[392] | 102 | ; SelectDriveToBootFrom
|
---|
[243] | 103 | ; Parameters:
|
---|
| 104 | ; DS: RAMVARS segment
|
---|
[392] | 105 | ; ES: BDA and interrupt vector segment (zero)
|
---|
[243] | 106 | ; Returns:
|
---|
| 107 | ; Never returns (loads operating system)
|
---|
| 108 | ;--------------------------------------------------------------------
|
---|
[492] | 109 | ; The following macro could be easily inlined below. Why a macro? Depending on the combination
|
---|
| 110 | ; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
|
---|
[505] | 111 | ; call to the boot menu.
|
---|
[492] | 112 | ;
|
---|
| 113 | %macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
|
---|
| 114 | push dx ; it's OK if this is left on the stack, if we are
|
---|
[505] | 115 | ; successful, the following call does not return
|
---|
[528] | 116 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[492] | 117 | pop dx
|
---|
| 118 | mov dl, dh
|
---|
[528] | 119 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[492] | 120 | %endmacro
|
---|
[505] | 121 |
|
---|
[528] | 122 |
|
---|
| 123 | SelectDriveToBootFrom: ; Function starts here
|
---|
[395] | 124 | %ifdef MODULE_HOTKEYS
|
---|
[528] | 125 | call HotkeyBar_UpdateDuringDriveDetection
|
---|
| 126 | mov al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
|
---|
[492] | 127 | cmp al, ROM_BOOT_HOTKEY_SCANCODE
|
---|
[528] | 128 | je SHORT .RomBoot ; CF clear so ROM boot
|
---|
[392] | 129 | %ifdef MODULE_BOOT_MENU
|
---|
[492] | 130 | cmp al, BOOT_MENU_HOTKEY_SCANCODE
|
---|
[528] | 131 | je SHORT .BootMenu
|
---|
| 132 | %endif ; MODULE_BOOT_MENU
|
---|
| 133 |
|
---|
| 134 | .TryUsingHotKeysCode:
|
---|
[492] | 135 | call HotkeyBar_GetBootDriveNumbersToDX
|
---|
[528] | 136 | call DriveXlate_SetDriveToSwap ; Enable primary boot device translation
|
---|
| 137 | xchg dl, dh
|
---|
| 138 | call DriveXlate_SetDriveToSwap ; Enable secondary boot device translation
|
---|
| 139 | xchg dl, dh
|
---|
[529] | 140 | call DriveXlate_ToOrBack ; Translate now so boot device will appear as 00h or 80h to OS
|
---|
[492] | 141 | TRY_TO_BOOT_DL_AND_DH_DRIVES
|
---|
| 142 | ;; falls through to boot menu, if it is present. If not present, falls through to rom boot.
|
---|
[505] | 143 | %endif ; MODULE_HOTKEYS
|
---|
[392] | 144 |
|
---|
[528] | 145 |
|
---|
[492] | 146 | %ifdef MODULE_BOOT_MENU
|
---|
[505] | 147 | .BootMenu:
|
---|
[492] | 148 | call BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
|
---|
[528] | 149 | jnc SHORT .RomBoot ; CF clear so ROM boot
|
---|
[392] | 150 |
|
---|
[528] | 151 | call DriveXlate_Reset
|
---|
| 152 | %ifdef MODULE_HOTKEYS
|
---|
| 153 | jmp SHORT .TryUsingHotKeysCode ; Selected drive stored as hotkey
|
---|
| 154 | %else ; Boot menu without hotkeys, secondary boot drive is always 00h or 80h
|
---|
[492] | 155 | mov dh, dl ; Setup for secondary drive
|
---|
[505] | 156 | not dh ; Floppy goes to HD, or vice versa
|
---|
| 157 | and dh, 80h ; Go to first drive of the floppy or HD set
|
---|
[528] | 158 | call DriveXlate_SetDriveToSwap
|
---|
| 159 | call DriveXlate_ToOrBack
|
---|
| 160 | TRY_TO_BOOT_DL_AND_DH_DRIVES
|
---|
| 161 | jmp SHORT .BootMenu ; Show boot menu again
|
---|
| 162 | %endif ; MODULE_HOTKEYS
|
---|
[398] | 163 |
|
---|
[505] | 164 | %endif ; MODULE_BOOT_MENU
|
---|
[392] | 165 |
|
---|
[528] | 166 | ; No hotkeys and no boot menu means fixed "A then C" boot order
|
---|
[505] | 167 | %ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
|
---|
[529] | 168 | xor dl, dl ; Try to boot from Floppy Drive A
|
---|
[528] | 169 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[529] | 170 | mov dl, 80h ; Try to boot from Hard Drive C
|
---|
[528] | 171 | call BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[386] | 172 | %endif
|
---|
[243] | 173 |
|
---|
[493] | 174 | .RomBoot:
|
---|
| 175 | %ifdef MODULE_DRIVEXLATE
|
---|
| 176 | call DriveXlate_Reset ; Clean up any drive mappings before Rom Boot
|
---|
| 177 | %endif
|
---|
[505] | 178 | clc
|
---|
[521] | 179 | ;; fall through to Int19_JumpToBootSectorOrRomBoot
|
---|
[392] | 180 |
|
---|
[243] | 181 | ;--------------------------------------------------------------------
|
---|
[521] | 182 | ; Int19_JumpToBootSectorOrRomBoot
|
---|
[243] | 183 | ;
|
---|
| 184 | ; Switches back to the POST stack, clears the DS and ES registers,
|
---|
| 185 | ; and either jumps to the MBR (Master Boot Record) that was just read,
|
---|
| 186 | ; or calls the ROM's boot routine on interrupt 18.
|
---|
| 187 | ;
|
---|
| 188 | ; Parameters:
|
---|
| 189 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
[505] | 190 | ; CF: Set for Boot Sector Boot
|
---|
[392] | 191 | ; Clear for ROM Boot
|
---|
[243] | 192 | ; ES:BX: (if CF set) Ptr to boot sector
|
---|
| 193 | ;
|
---|
| 194 | ; Returns:
|
---|
| 195 | ; Never returns
|
---|
| 196 | ;--------------------------------------------------------------------
|
---|
[521] | 197 | Int19_JumpToBootSectorOrRomBoot:
|
---|
[243] | 198 | mov cx, es ; Preserve MBR segment (can't push because of stack change)
|
---|
| 199 | mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
|
---|
| 200 | SWITCH_BACK_TO_POST_STACK
|
---|
| 201 |
|
---|
| 202 | ; clear segment registers before boot sector or rom call
|
---|
[505] | 203 | mov ds, ax
|
---|
[243] | 204 | mov es, ax
|
---|
| 205 | %ifdef USE_386
|
---|
| 206 | mov fs, ax
|
---|
| 207 | mov gs, ax
|
---|
| 208 | %endif
|
---|
| 209 | jnc SHORT .romboot
|
---|
| 210 |
|
---|
| 211 | ; jump to boot sector
|
---|
| 212 | push cx ; sgment address for MBR
|
---|
| 213 | push bx ; offset address for MBR
|
---|
| 214 | retf ; NOTE: DL is set to the drive number
|
---|
| 215 |
|
---|
| 216 | ; Boot by calling INT 18h (ROM Basic of ROM DOS)
|
---|
| 217 | .romboot:
|
---|
[505] | 218 | int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
|
---|