[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
|
---|
| 109 | cmp BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], ROM_BOOT_HOTKEY_SCANCODE
|
---|
| 110 | je SHORT JumpToBootSector_or_RomBoot ; CF clear so ROM boot
|
---|
| 111 |
|
---|
| 112 | ; Try to boot from Primary boot drive (00h by default)
|
---|
[395] | 113 | %ifdef MODULE_HOTKEYS
|
---|
[392] | 114 | call HotkeyBar_GetPrimaryBootDriveNumberToDL
|
---|
[395] | 115 | %else
|
---|
| 116 | mov dl, [cs:ROMVARS.bBootDrv]
|
---|
| 117 | and dl, 80h ; Only 00h and 80h allowed when not using MODULE_HOTKEYS
|
---|
| 118 | %endif
|
---|
[392] | 119 | call TryToBootFromPrimaryOrSecondaryBootDevice
|
---|
| 120 | jc SHORT JumpToBootSector_or_RomBoot
|
---|
| 121 |
|
---|
| 122 | ; Try to boot from Secondary boot device (80h by default)
|
---|
[395] | 123 | %ifdef MODULE_HOTKEYS
|
---|
[392] | 124 | call HotkeyBar_GetSecondaryBootDriveNumberToDL
|
---|
[395] | 125 | %else
|
---|
| 126 | mov dl, [cs:ROMVARS.bBootDrv]
|
---|
| 127 | and dl, 80h
|
---|
| 128 | xor dl, 80h
|
---|
| 129 | %endif
|
---|
[392] | 130 | call TryToBootFromPrimaryOrSecondaryBootDevice
|
---|
| 131 |
|
---|
[386] | 132 | %ifdef MODULE_BOOT_MENU
|
---|
[392] | 133 | ; Force Boot Menu hotkey to display boot menu
|
---|
| 134 | mov BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], BOOT_MENU_HOTKEY_SCANCODE
|
---|
| 135 | jnc SHORT SelectDriveToBootFrom
|
---|
[386] | 136 | %endif
|
---|
[392] | 137 | ; Fall to JumpToBootSector_or_RomBoot
|
---|
[243] | 138 |
|
---|
[392] | 139 |
|
---|
[243] | 140 | ;--------------------------------------------------------------------
|
---|
[392] | 141 | ; JumpToBootSector_or_RomBoot
|
---|
[243] | 142 | ;
|
---|
| 143 | ; Switches back to the POST stack, clears the DS and ES registers,
|
---|
| 144 | ; and either jumps to the MBR (Master Boot Record) that was just read,
|
---|
| 145 | ; or calls the ROM's boot routine on interrupt 18.
|
---|
| 146 | ;
|
---|
| 147 | ; Parameters:
|
---|
| 148 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 149 | ; CF: Set for Boot Sector Boot
|
---|
[392] | 150 | ; Clear for ROM Boot
|
---|
[243] | 151 | ; ES:BX: (if CF set) Ptr to boot sector
|
---|
| 152 | ;
|
---|
| 153 | ; Returns:
|
---|
| 154 | ; Never returns
|
---|
| 155 | ;--------------------------------------------------------------------
|
---|
[392] | 156 | JumpToBootSector_or_RomBoot:
|
---|
[243] | 157 | mov cx, es ; Preserve MBR segment (can't push because of stack change)
|
---|
| 158 | mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
|
---|
| 159 | SWITCH_BACK_TO_POST_STACK
|
---|
| 160 |
|
---|
| 161 | ; clear segment registers before boot sector or rom call
|
---|
| 162 | mov ds, ax
|
---|
| 163 | mov es, ax
|
---|
| 164 | %ifdef USE_386
|
---|
| 165 | mov fs, ax
|
---|
| 166 | mov gs, ax
|
---|
| 167 | %endif
|
---|
| 168 | jnc SHORT .romboot
|
---|
| 169 |
|
---|
| 170 | ; jump to boot sector
|
---|
| 171 | push cx ; sgment address for MBR
|
---|
| 172 | push bx ; offset address for MBR
|
---|
| 173 | retf ; NOTE: DL is set to the drive number
|
---|
| 174 |
|
---|
| 175 | ; Boot by calling INT 18h (ROM Basic of ROM DOS)
|
---|
| 176 | .romboot:
|
---|
[392] | 177 | int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | ;--------------------------------------------------------------------
|
---|
| 181 | ; TryToBootFromPrimaryOrSecondaryBootDevice
|
---|
| 182 | ; Parameters
|
---|
| 183 | ; DL: Drive selected as boot device
|
---|
| 184 | ; DS: RAMVARS segment
|
---|
| 185 | ; ES: BDA and interrupt vector segment (zero)
|
---|
| 186 | ; Returns:
|
---|
| 187 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 188 | ; CF: Set for Boot Sector Boot
|
---|
| 189 | ; Clear for ROM Boot
|
---|
| 190 | ; ES:BX: (if CF set) Ptr to boot sector
|
---|
| 191 | ; Corrupts registers:
|
---|
| 192 | ; AX, CX, DH, SI, DI, (DL if failed to read boot sector)
|
---|
| 193 | ;--------------------------------------------------------------------
|
---|
[395] | 194 | %ifndef MODULE_HOTKEYS
|
---|
| 195 | TryToBootFromPrimaryOrSecondaryBootDevice EQU BootSector_TryToLoadFromDriveDL
|
---|
| 196 |
|
---|
| 197 | %else
|
---|
[392] | 198 | TryToBootFromPrimaryOrSecondaryBootDevice:
|
---|
| 199 | call DriveXlate_SetDriveToSwap
|
---|
| 200 | call DriveXlate_ToOrBack
|
---|
| 201 | jmp BootSector_TryToLoadFromDriveDL
|
---|
[395] | 202 | %endif
|
---|