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

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

Changes to XTIDE Universal BIOS:

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