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