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

Last change on this file since 571 was 567, checked in by krille_n_@…, 11 years ago

Changes:

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