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

Last change on this file since 536 was 529, checked in by krille_n_@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Fixed a bug in Int19h.asm (from r528)
File size: 7.3 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 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 mov [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed], ax
83%endif
84
85 call Initialize_AndDetectDrives
86
87%ifdef MODULE_HOTKEYS
88.WaitUntilTimeToCloseHotkeyBar:
89 call TimerTicks_ReadFromBdaToAX
90 sub ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed]
91 cmp ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
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;--------------------------------------------------------------------
105; The following macro could be easily inlined below. Why a macro? Depending on the combination
106; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
107; call to the boot menu.
108;
109%macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
110 push dx ; it's OK if this is left on the stack, if we are
111 ; successful, the following call does not return
112 call BootSector_TryToLoadFromDriveDL_AndBoot
113 pop dx
114 mov dl, dh
115 call BootSector_TryToLoadFromDriveDL_AndBoot
116%endmacro
117
118
119SelectDriveToBootFrom: ; Function starts here
120%ifdef MODULE_HOTKEYS
121 call HotkeyBar_UpdateDuringDriveDetection
122 mov al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
123 cmp al, ROM_BOOT_HOTKEY_SCANCODE
124 je SHORT .RomBoot ; CF clear so ROM boot
125%ifdef MODULE_BOOT_MENU
126 cmp al, BOOT_MENU_HOTKEY_SCANCODE
127 je SHORT .BootMenu
128%endif ; MODULE_BOOT_MENU
129
130.TryUsingHotKeysCode:
131 call HotkeyBar_GetBootDriveNumbersToDX
132 call DriveXlate_SetDriveToSwap ; Enable primary boot device translation
133 xchg dl, dh
134 call DriveXlate_SetDriveToSwap ; Enable secondary boot device translation
135 xchg dl, dh
136 call DriveXlate_ToOrBack ; Translate now so boot device will appear as 00h or 80h to OS
137 TRY_TO_BOOT_DL_AND_DH_DRIVES
138 ;; falls through to boot menu, if it is present. If not present, falls through to rom boot.
139%endif ; MODULE_HOTKEYS
140
141
142%ifdef MODULE_BOOT_MENU
143.BootMenu:
144 call BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
145 jnc SHORT .RomBoot ; CF clear so ROM boot
146
147 call DriveXlate_Reset
148%ifdef MODULE_HOTKEYS
149 jmp SHORT .TryUsingHotKeysCode ; Selected drive stored as hotkey
150%else ; Boot menu without hotkeys, secondary boot drive is always 00h or 80h
151 mov dh, dl ; Setup for secondary drive
152 not dh ; Floppy goes to HD, or vice versa
153 and dh, 80h ; Go to first drive of the floppy or HD set
154 call DriveXlate_SetDriveToSwap
155 call DriveXlate_ToOrBack
156 TRY_TO_BOOT_DL_AND_DH_DRIVES
157 jmp SHORT .BootMenu ; Show boot menu again
158%endif ; MODULE_HOTKEYS
159
160%endif ; MODULE_BOOT_MENU
161
162; No hotkeys and no boot menu means fixed "A then C" boot order
163%ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
164 xor dl, dl ; Try to boot from Floppy Drive A
165 call BootSector_TryToLoadFromDriveDL_AndBoot
166 mov dl, 80h ; Try to boot from Hard Drive C
167 call BootSector_TryToLoadFromDriveDL_AndBoot
168%endif
169
170.RomBoot:
171%ifdef MODULE_DRIVEXLATE
172 call DriveXlate_Reset ; Clean up any drive mappings before Rom Boot
173%endif
174 clc
175 ;; fall through to Int19_JumpToBootSectorOrRomBoot
176
177;--------------------------------------------------------------------
178; Int19_JumpToBootSectorOrRomBoot
179;
180; Switches back to the POST stack, clears the DS and ES registers,
181; and either jumps to the MBR (Master Boot Record) that was just read,
182; or calls the ROM's boot routine on interrupt 18.
183;
184; Parameters:
185; DL: Drive to boot from (translated, 00h or 80h)
186; CF: Set for Boot Sector Boot
187; Clear for ROM Boot
188; ES:BX: (if CF set) Ptr to boot sector
189;
190; Returns:
191; Never returns
192;--------------------------------------------------------------------
193Int19_JumpToBootSectorOrRomBoot:
194 mov cx, es ; Preserve MBR segment (can't push because of stack change)
195 mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
196 SWITCH_BACK_TO_POST_STACK
197
198; clear segment registers before boot sector or rom call
199 mov ds, ax
200 mov es, ax
201%ifdef USE_386
202 mov fs, ax
203 mov gs, ax
204%endif
205 jnc SHORT .romboot
206
207; jump to boot sector
208 push cx ; sgment address for MBR
209 push bx ; offset address for MBR
210 retf ; NOTE: DL is set to the drive number
211
212; Boot by calling INT 18h (ROM Basic of ROM DOS)
213.romboot:
214 int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
Note: See TracBrowser for help on using the repository browser.