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

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

Changes to XTIDE Universal BIOS:

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