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

Last change on this file since 415 was 414, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • MEMPIOVARS no longer overflow when not building MODULE_EBIOS.
File size: 7.5 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-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
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 LOAD_BDA_SEGMENT_TO es, ax ; Load BDA segment (zero) to ES
34 ; Fall to .PrepareBootLoaderStack
35
36
37;--------------------------------------------------------------------
38; Drive detection and boot menu use lots of stack so it is
39; wise to relocate stack. Otherwise something important from
40; interrupt vectors are likely corrupted, likely our own DPTs if
41; they are located to 30:0h.
42;
43; .PrepareBootLoaderStack
44; Parameters:
45; ES: BDA and interrupt vector segment (zero)
46; Returns:
47; Never returns (loads operating system)
48;--------------------------------------------------------------------
49.PrepareBootLoaderStack:
50 STORE_POST_STACK_POINTER
51 SWITCH_TO_BOOT_MENU_STACK
52 ; Fall to .InitializeDisplay
53
54
55;--------------------------------------------------------------------
56; .InitializeDisplay
57; Parameters:
58; ES: BDA and interrupt vector segment (zero)
59; Returns:
60; Never returns (loads operating system)
61;--------------------------------------------------------------------
62.InitializeDisplay:
63 ; Change display mode if necessary
64 mov ax, [cs:ROMVARS.wDisplayMode] ; AH 00h = Set Video Mode
65 cmp al, DEFAULT_TEXT_MODE
66 je SHORT .InitializeDisplayLibrary
67 int BIOS_VIDEO_INTERRUPT_10h
68.InitializeDisplayLibrary:
69 call DetectPrint_InitializeDisplayContext
70 ; Fall to .InitializeBiosAndDetectDrives
71
72
73;--------------------------------------------------------------------
74; .InitializeBiosAndDetectDrives
75; Parameters:
76; ES: BDA and interrupt vector segment (zero)
77; Returns:
78; DS: RAMVARS segment
79;--------------------------------------------------------------------
80%ifdef MODULE_HOTKEYS
81 call TimerTicks_ReadFromBdaToAX
82 add ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
83 mov [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeToClose], ax
84%endif
85
86 call Initialize_AndDetectDrives
87
88%ifdef MODULE_HOTKEYS
89.WaitUntilTimeToCloseHotkeyBar:
90 call TimerTicks_ReadFromBdaToAX
91 cmp ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeToClose]
92 jb SHORT .WaitUntilTimeToCloseHotkeyBar
93%endif
94 ; Fall to SelectDriveToBootFrom
95
96
97;--------------------------------------------------------------------
98; SelectDriveToBootFrom
99; Parameters:
100; DS: RAMVARS segment
101; ES: BDA and interrupt vector segment (zero)
102; Returns:
103; Never returns (loads operating system)
104;--------------------------------------------------------------------
105SelectDriveToBootFrom:
106%ifdef MODULE_HOTKEYS
107 call HotkeyBar_UpdateDuringDriveDetection
108
109%ifdef MODULE_BOOT_MENU
110 mov di, BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode
111 cmp BYTE [es:di], BOOT_MENU_HOTKEY_SCANCODE
112 jne SHORT .DoNotDisplayBootMenu
113
114 ; Stop blinking the Boot Menu hotkey and display menu
115 mov BYTE [es:di], 0
116 call HotkeyBar_DrawToTopOfScreen
117 call BootMenu_DisplayAndStoreSelectionAsHotkey
118.DoNotDisplayBootMenu:
119%endif
120
121 ; Check if ROM boot (INT 18h) wanted
122 cmp BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], ROM_BOOT_HOTKEY_SCANCODE
123 je SHORT JumpToBootSector_or_RomBoot ; CF clear so ROM boot
124
125 ; Get Primary boot drive number to DL
126 call HotkeyBar_GetPrimaryBootDriveNumberToDL
127%else
128 call GetPrimaryBootDriveToDLwhenNotUsingModuleHotkeys
129%endif ; MODULE_HOTKEYS
130
131 ; Try to boot from Primary boot drive (00h by default)
132 call TryToBootFromPrimaryOrSecondaryBootDevice
133 jc SHORT JumpToBootSector_or_RomBoot
134
135 ; Try to boot from Secondary boot device (80h by default)
136%ifdef MODULE_HOTKEYS
137 call HotkeyBar_GetSecondaryBootDriveNumberToDL
138%else
139 call GetPrimaryBootDriveToDLwhenNotUsingModuleHotkeys
140 xor dl, 80h
141%endif
142 call TryToBootFromPrimaryOrSecondaryBootDevice
143
144%ifdef MODULE_BOOT_MENU
145 ; Force Boot Menu hotkey to display boot menu
146 mov BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], BOOT_MENU_HOTKEY_SCANCODE
147 jnc SHORT SelectDriveToBootFrom
148%endif
149 ; Fall to JumpToBootSector_or_RomBoot
150
151
152;--------------------------------------------------------------------
153; JumpToBootSector_or_RomBoot
154;
155; Switches back to the POST stack, clears the DS and ES registers,
156; and either jumps to the MBR (Master Boot Record) that was just read,
157; or calls the ROM's boot routine on interrupt 18.
158;
159; Parameters:
160; DL: Drive to boot from (translated, 00h or 80h)
161; CF: Set for Boot Sector Boot
162; Clear for ROM Boot
163; ES:BX: (if CF set) Ptr to boot sector
164;
165; Returns:
166; Never returns
167;--------------------------------------------------------------------
168JumpToBootSector_or_RomBoot:
169 mov cx, es ; Preserve MBR segment (can't push because of stack change)
170 mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
171 SWITCH_BACK_TO_POST_STACK
172
173; clear segment registers before boot sector or rom call
174 mov ds, ax
175 mov es, ax
176%ifdef USE_386
177 mov fs, ax
178 mov gs, ax
179%endif
180 jnc SHORT .romboot
181
182; jump to boot sector
183 push cx ; sgment address for MBR
184 push bx ; offset address for MBR
185 retf ; NOTE: DL is set to the drive number
186
187; Boot by calling INT 18h (ROM Basic of ROM DOS)
188.romboot:
189 int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
190
191
192;--------------------------------------------------------------------
193; TryToBootFromPrimaryOrSecondaryBootDevice
194; Parameters
195; DL: Drive selected as boot device
196; DS: RAMVARS segment
197; ES: BDA and interrupt vector segment (zero)
198; Returns:
199; DL: Drive to boot from (translated, 00h or 80h)
200; CF: Set for Boot Sector Boot
201; Clear for ROM Boot
202; ES:BX: (if CF set) Ptr to boot sector
203; Corrupts registers:
204; AX, CX, DH, SI, DI, (DL if failed to read boot sector)
205;--------------------------------------------------------------------
206%ifndef MODULE_HOTKEYS
207TryToBootFromPrimaryOrSecondaryBootDevice EQU BootSector_TryToLoadFromDriveDL
208
209%else
210TryToBootFromPrimaryOrSecondaryBootDevice:
211 call DriveXlate_SetDriveToSwap
212 call DriveXlate_ToOrBack
213 jmp BootSector_TryToLoadFromDriveDL
214%endif
215
216
217;--------------------------------------------------------------------
218; GetPrimaryBootDriveToDLwhenNotUsingModuleHotkeys
219; Parameters
220; Nothing
221; Returns:
222; DL: Drive to boot from (00h or 80h)
223; Corrupts registers:
224; Nothing
225;--------------------------------------------------------------------
226%ifndef MODULE_HOTKEYS
227GetPrimaryBootDriveToDLwhenNotUsingModuleHotkeys:
228 mov dl, [cs:ROMVARS.bBootDrv]
229 and dl, 80h ; Only 00h and 80h allowed when not using MODULE_HOTKEYS
230 ret
231%endif
Note: See TracBrowser for help on using the repository browser.