[243] | 1 | ; Project name : XTIDE Universal BIOS |
---|
| 2 | ; Description : Int 19h Handler (Boot Loader). |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. |
---|
| 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. |
---|
| 12 | ; |
---|
| 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 |
---|
| 16 | ; GNU General Public License for more details. |
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
| 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: |
---|
[392] | 31 | sti ; Allow timer interrupts |
---|
| 32 | LOAD_BDA_SEGMENT_TO es, ax ; Load BDA segment (zero) to ES |
---|
| 33 | ; Fall to .PrepareBootLoaderStack |
---|
[243] | 34 | |
---|
[392] | 35 | |
---|
[243] | 36 | ;-------------------------------------------------------------------- |
---|
[392] | 37 | ; Drive detection and boot menu use lots of stack so it is |
---|
| 38 | ; wise to relocate stack. Otherwise something important from |
---|
| 39 | ; interrupt vectors are likely corrupted, likely our own DPTs if |
---|
| 40 | ; they are located to 30:0h. |
---|
| 41 | ; |
---|
| 42 | ; .PrepareBootLoaderStack |
---|
[243] | 43 | ; Parameters: |
---|
| 44 | ; ES: BDA and interrupt vector segment (zero) |
---|
| 45 | ; Returns: |
---|
| 46 | ; Never returns (loads operating system) |
---|
| 47 | ;-------------------------------------------------------------------- |
---|
[392] | 48 | .PrepareBootLoaderStack: |
---|
[243] | 49 | STORE_POST_STACK_POINTER |
---|
| 50 | SWITCH_TO_BOOT_MENU_STACK |
---|
| 51 | ; Fall to .InitializeDisplay |
---|
| 52 | |
---|
[392] | 53 | |
---|
[243] | 54 | ;-------------------------------------------------------------------- |
---|
| 55 | ; .InitializeDisplay |
---|
| 56 | ; Parameters: |
---|
[392] | 57 | ; ES: BDA and interrupt vector segment (zero) |
---|
[243] | 58 | ; Returns: |
---|
| 59 | ; Never returns (loads operating system) |
---|
| 60 | ;-------------------------------------------------------------------- |
---|
| 61 | .InitializeDisplay: |
---|
| 62 | ; Change display mode if necessary |
---|
| 63 | mov ax, [cs:ROMVARS.wDisplayMode] ; AH 00h = Set Video Mode |
---|
| 64 | cmp al, DEFAULT_TEXT_MODE |
---|
| 65 | je SHORT .InitializeDisplayLibrary |
---|
| 66 | int BIOS_VIDEO_INTERRUPT_10h |
---|
| 67 | .InitializeDisplayLibrary: |
---|
[392] | 68 | call DetectPrint_InitializeDisplayContext |
---|
| 69 | ; Fall to .InitializeBiosAndDetectDrives |
---|
[243] | 70 | |
---|
[392] | 71 | |
---|
[243] | 72 | ;-------------------------------------------------------------------- |
---|
[392] | 73 | ; .InitializeBiosAndDetectDrives |
---|
[243] | 74 | ; Parameters: |
---|
[392] | 75 | ; ES: BDA and interrupt vector segment (zero) |
---|
[243] | 76 | ; Returns: |
---|
[392] | 77 | ; DS: RAMVARS segment |
---|
[243] | 78 | ;-------------------------------------------------------------------- |
---|
[392] | 79 | call Initialize_AndDetectDrives |
---|
| 80 | ; Fall to SelectDriveToBootFrom |
---|
[243] | 81 | |
---|
[392] | 82 | |
---|
[243] | 83 | ;-------------------------------------------------------------------- |
---|
[392] | 84 | ; SelectDriveToBootFrom |
---|
[243] | 85 | ; Parameters: |
---|
| 86 | ; DS: RAMVARS segment |
---|
[392] | 87 | ; ES: BDA and interrupt vector segment (zero) |
---|
[243] | 88 | ; Returns: |
---|
| 89 | ; Never returns (loads operating system) |
---|
| 90 | ;-------------------------------------------------------------------- |
---|
[392] | 91 | SelectDriveToBootFrom: |
---|
[395] | 92 | %ifdef MODULE_HOTKEYS |
---|
[392] | 93 | call HotkeyBar_UpdateDuringDriveDetection |
---|
[243] | 94 | |
---|
[392] | 95 | %ifdef MODULE_BOOT_MENU |
---|
| 96 | mov di, BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode |
---|
| 97 | cmp BYTE [es:di], BOOT_MENU_HOTKEY_SCANCODE |
---|
| 98 | jne SHORT .DoNotDisplayBootMenu |
---|
[243] | 99 | |
---|
[392] | 100 | ; Stop blinking the Boot Menu hotkey and display menu |
---|
| 101 | mov BYTE [es:di], 0 |
---|
| 102 | call HotkeyBar_DrawToTopOfScreen |
---|
| 103 | call BootMenu_DisplayAndStoreSelectionAsHotkey |
---|
| 104 | .DoNotDisplayBootMenu: |
---|
| 105 | %endif |
---|
[395] | 106 | %endif |
---|
[392] | 107 | |
---|
| 108 | ; Check if ROM boot (INT 18h) wanted |
---|
[397] | 109 | %ifdef MODULE_HOTKEYS |
---|
[392] | 110 | cmp BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], ROM_BOOT_HOTKEY_SCANCODE |
---|
| 111 | je SHORT JumpToBootSector_or_RomBoot ; CF clear so ROM boot |
---|
[397] | 112 | %endif |
---|
[392] | 113 | |
---|
| 114 | ; Try to boot from Primary boot drive (00h by default) |
---|
[395] | 115 | %ifdef MODULE_HOTKEYS |
---|
[392] | 116 | call HotkeyBar_GetPrimaryBootDriveNumberToDL |
---|
[395] | 117 | %else |
---|
| 118 | mov dl, [cs:ROMVARS.bBootDrv] |
---|
| 119 | and dl, 80h ; Only 00h and 80h allowed when not using MODULE_HOTKEYS |
---|
| 120 | %endif |
---|
[392] | 121 | call TryToBootFromPrimaryOrSecondaryBootDevice |
---|
| 122 | jc SHORT JumpToBootSector_or_RomBoot |
---|
| 123 | |
---|
| 124 | ; Try to boot from Secondary boot device (80h by default) |
---|
[395] | 125 | %ifdef MODULE_HOTKEYS |
---|
[392] | 126 | call HotkeyBar_GetSecondaryBootDriveNumberToDL |
---|
[395] | 127 | %else |
---|
| 128 | mov dl, [cs:ROMVARS.bBootDrv] |
---|
| 129 | and dl, 80h |
---|
| 130 | xor dl, 80h |
---|
| 131 | %endif |
---|
[392] | 132 | call TryToBootFromPrimaryOrSecondaryBootDevice |
---|
| 133 | |
---|
[386] | 134 | %ifdef MODULE_BOOT_MENU |
---|
[392] | 135 | ; Force Boot Menu hotkey to display boot menu |
---|
| 136 | mov BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], BOOT_MENU_HOTKEY_SCANCODE |
---|
| 137 | jnc SHORT SelectDriveToBootFrom |
---|
[386] | 138 | %endif |
---|
[392] | 139 | ; Fall to JumpToBootSector_or_RomBoot |
---|
[243] | 140 | |
---|
[392] | 141 | |
---|
[243] | 142 | ;-------------------------------------------------------------------- |
---|
[392] | 143 | ; JumpToBootSector_or_RomBoot |
---|
[243] | 144 | ; |
---|
| 145 | ; Switches back to the POST stack, clears the DS and ES registers, |
---|
| 146 | ; and either jumps to the MBR (Master Boot Record) that was just read, |
---|
| 147 | ; or calls the ROM's boot routine on interrupt 18. |
---|
| 148 | ; |
---|
| 149 | ; Parameters: |
---|
| 150 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
| 151 | ; CF: Set for Boot Sector Boot |
---|
[392] | 152 | ; Clear for ROM Boot |
---|
[243] | 153 | ; ES:BX: (if CF set) Ptr to boot sector |
---|
| 154 | ; |
---|
| 155 | ; Returns: |
---|
| 156 | ; Never returns |
---|
| 157 | ;-------------------------------------------------------------------- |
---|
[392] | 158 | JumpToBootSector_or_RomBoot: |
---|
[243] | 159 | mov cx, es ; Preserve MBR segment (can't push because of stack change) |
---|
| 160 | mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF |
---|
| 161 | SWITCH_BACK_TO_POST_STACK |
---|
| 162 | |
---|
| 163 | ; clear segment registers before boot sector or rom call |
---|
| 164 | mov ds, ax |
---|
| 165 | mov es, ax |
---|
| 166 | %ifdef USE_386 |
---|
| 167 | mov fs, ax |
---|
| 168 | mov gs, ax |
---|
| 169 | %endif |
---|
| 170 | jnc SHORT .romboot |
---|
| 171 | |
---|
| 172 | ; jump to boot sector |
---|
| 173 | push cx ; sgment address for MBR |
---|
| 174 | push bx ; offset address for MBR |
---|
| 175 | retf ; NOTE: DL is set to the drive number |
---|
| 176 | |
---|
| 177 | ; Boot by calling INT 18h (ROM Basic of ROM DOS) |
---|
| 178 | .romboot: |
---|
[392] | 179 | int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | ;-------------------------------------------------------------------- |
---|
| 183 | ; TryToBootFromPrimaryOrSecondaryBootDevice |
---|
| 184 | ; Parameters |
---|
| 185 | ; DL: Drive selected as boot device |
---|
| 186 | ; DS: RAMVARS segment |
---|
| 187 | ; ES: BDA and interrupt vector segment (zero) |
---|
| 188 | ; Returns: |
---|
| 189 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
| 190 | ; CF: Set for Boot Sector Boot |
---|
| 191 | ; Clear for ROM Boot |
---|
| 192 | ; ES:BX: (if CF set) Ptr to boot sector |
---|
| 193 | ; Corrupts registers: |
---|
| 194 | ; AX, CX, DH, SI, DI, (DL if failed to read boot sector) |
---|
| 195 | ;-------------------------------------------------------------------- |
---|
[395] | 196 | %ifndef MODULE_HOTKEYS |
---|
| 197 | TryToBootFromPrimaryOrSecondaryBootDevice EQU BootSector_TryToLoadFromDriveDL |
---|
| 198 | |
---|
| 199 | %else |
---|
[392] | 200 | TryToBootFromPrimaryOrSecondaryBootDevice: |
---|
| 201 | call DriveXlate_SetDriveToSwap |
---|
| 202 | call DriveXlate_ToOrBack |
---|
| 203 | jmp BootSector_TryToLoadFromDriveDL |
---|
[395] | 204 | %endif |
---|