source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm@ 555

Last change on this file since 555 was 555, checked in by aitotat@…, 11 years ago

Changes to XTIDE Universal BIOS:

  • Short timeouts for drive detection work again.
  • All drives are now reset before booting (instead of XTIDE Universal BIOS controlled drives only).
  • Windows 98 now works without tricks (Floppy Drive accesses are redirected from INT 13h to 40h).
File size: 8.1 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Int 19h Handler (Boot Loader).
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int19h_BootLoaderHandler
25; Parameters:
26; Nothing
27; Returns:
28; Never returns (loads operating system)
29;--------------------------------------------------------------------
30Int19h_BootLoaderHandler:
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
35 ; Fall to .PrepareBootLoaderStack
36
37
38;--------------------------------------------------------------------
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
45; Parameters:
46; ES: BDA and interrupt vector segment (zero)
47; Returns:
48; Never returns (loads operating system)
49;--------------------------------------------------------------------
50.PrepareBootLoaderStack:
51 STORE_POST_STACK_POINTER
52 SWITCH_TO_BOOT_MENU_STACK
53 ; Fall to .InitializeDisplay
54
55
56;--------------------------------------------------------------------
57; .InitializeDisplay
58; Parameters:
59; ES: BDA and interrupt vector segment (zero)
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:
70 call DetectPrint_InitializeDisplayContext
71 ; Fall to .InitializeBiosAndDetectDrives
72
73
74;--------------------------------------------------------------------
75; .InitializeBiosAndDetectDrives
76; Parameters:
77; ES: BDA and interrupt vector segment (zero)
78; Returns:
79; DS: RAMVARS segment
80;--------------------------------------------------------------------
81.InitializeBiosAndDetectDrives:
82%ifdef MODULE_HOTKEYS
83 call TimerTicks_ReadFromBdaToAX
84 mov [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed], ax
85%endif
86
87 call Initialize_AndDetectDrives
88
89%ifdef MODULE_HOTKEYS
90 ; Last hard drive might have scrolled Hotkey Bar out of screen.
91 ; We want to display it during wait.
92 call HotkeyBar_UpdateDuringDriveDetection
93
94.WaitUntilTimeToCloseHotkeyBar:
95 call TimerTicks_ReadFromBdaToAX
96 sub ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed]
97 cmp ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
98 jb SHORT .WaitUntilTimeToCloseHotkeyBar
99%endif
100 ; Fall to .ResetAllDrives
101
102
103;--------------------------------------------------------------------
104; .ResetAllDrives
105; Parameters:
106; DS: RAMVARS segment
107; ES: BDA and interrupt vector segment (zero)
108; Returns:
109; Nothing
110;--------------------------------------------------------------------
111.ResetAllDrives:
112 ; Reset all drives in the system, not just our drives.
113 xor ax, ax ; Disk Controller Reset
114 mov dl, 80h ; Reset all hard drives and floppy drives
115 int BIOS_DISK_INTERRUPT_13h
116 ;call ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed ; Our drives only
117 ; Fall to SelectDriveToBootFrom
118
119
120;--------------------------------------------------------------------
121; SelectDriveToBootFrom
122; Parameters:
123; DS: RAMVARS segment
124; ES: BDA and interrupt vector segment (zero)
125; Returns:
126; Never returns (loads operating system)
127;--------------------------------------------------------------------
128; The following macro could be easily inlined below. Why a macro? Depending on the combination
129; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
130; call to the boot menu.
131;
132%macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
133 push dx ; it's OK if this is left on the stack, if we are
134 ; successful, the following call does not return
135 call BootSector_TryToLoadFromDriveDL_AndBoot
136 pop dx
137 mov dl, dh
138 call BootSector_TryToLoadFromDriveDL_AndBoot
139%endmacro
140
141
142SelectDriveToBootFrom: ; Function starts here
143%ifdef MODULE_HOTKEYS
144 call HotkeyBar_UpdateDuringDriveDetection
145 mov al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
146 cmp al, ROM_BOOT_HOTKEY_SCANCODE
147 je SHORT .RomBoot ; CF clear so ROM boot
148%ifdef MODULE_BOOT_MENU
149 cmp al, BOOT_MENU_HOTKEY_SCANCODE
150 je SHORT .BootMenu
151%endif ; MODULE_BOOT_MENU
152
153.TryUsingHotKeysCode:
154 call HotkeyBar_GetBootDriveNumbersToDX
155 call DriveXlate_SetDriveToSwap ; Enable primary boot device translation
156 xchg dl, dh
157 call DriveXlate_SetDriveToSwap ; Enable secondary boot device translation
158 xchg dl, dh
159 call DriveXlate_ToOrBack ; Translate now so boot device will appear as 00h or 80h to OS
160 TRY_TO_BOOT_DL_AND_DH_DRIVES
161 ;; falls through to boot menu, if it is present. If not present, falls through to rom boot.
162%endif ; MODULE_HOTKEYS
163
164
165%ifdef MODULE_BOOT_MENU
166.BootMenu:
167 call BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
168 jnc SHORT .RomBoot ; CF clear so ROM boot
169
170 call DriveXlate_Reset
171%ifdef MODULE_HOTKEYS
172 jmp SHORT .TryUsingHotKeysCode ; Selected drive stored as hotkey
173%else ; Boot menu without hotkeys, secondary boot drive is always 00h or 80h
174 mov dh, dl ; Setup for secondary drive
175 not dh ; Floppy goes to HD, or vice versa
176 and dh, 80h ; Go to first drive of the floppy or HD set
177 call DriveXlate_SetDriveToSwap
178 call DriveXlate_ToOrBack
179 TRY_TO_BOOT_DL_AND_DH_DRIVES
180 jmp SHORT .BootMenu ; Show boot menu again
181%endif ; MODULE_HOTKEYS
182
183%endif ; MODULE_BOOT_MENU
184
185; No hotkeys and no boot menu means fixed "A then C" boot order
186%ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
187 xor dl, dl ; Try to boot from Floppy Drive A
188 call BootSector_TryToLoadFromDriveDL_AndBoot
189 mov dl, 80h ; Try to boot from Hard Drive C
190 call BootSector_TryToLoadFromDriveDL_AndBoot
191%endif
192
193.RomBoot:
194%ifdef MODULE_DRIVEXLATE
195 call DriveXlate_Reset ; Clean up any drive mappings before Rom Boot
196%endif
197 clc
198 ;; fall through to Int19_JumpToBootSectorOrRomBoot
199
200;--------------------------------------------------------------------
201; Int19_JumpToBootSectorOrRomBoot
202;
203; Switches back to the POST stack, clears the DS and ES registers,
204; and either jumps to the MBR (Master Boot Record) that was just read,
205; or calls the ROM's boot routine on interrupt 18.
206;
207; Parameters:
208; DL: Drive to boot from (translated, 00h or 80h)
209; CF: Set for Boot Sector Boot
210; Clear for ROM Boot
211; ES:BX: (if CF set) Ptr to boot sector
212;
213; Returns:
214; Never returns
215;--------------------------------------------------------------------
216Int19_JumpToBootSectorOrRomBoot:
217 mov cx, es ; Preserve MBR segment (can't push because of stack change)
218 mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
219 SWITCH_BACK_TO_POST_STACK
220
221; clear segment registers before boot sector or rom call
222 mov ds, ax
223 mov es, ax
224%ifdef USE_386
225 mov fs, ax
226 mov gs, ax
227%endif
228 jnc SHORT .romboot
229
230; jump to boot sector
231 push cx ; sgment address for MBR
232 push bx ; offset address for MBR
233 retf ; NOTE: DL is set to the drive number
234
235; Boot by calling INT 18h (ROM Basic of ROM DOS)
236.romboot:
237 int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
Note: See TracBrowser for help on using the repository browser.