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

Last change on this file since 494 was 493, checked in by gregli@…, 12 years ago

Separated MODULE_8BIT_IDE into the basic part used by XTIDE rev 1 and rev 2 which is PIO based, and MODULE_8BIT_IDE_ADVANCED for JRIDE and XTCF support which requires memory mapping and/or DMA. This allows for creating an 8KB image with boot menu support (but no hotkeys) for the XTIDE rev 1. Cleaned up how we reset the drive translation information, ensuring it is properly set between boot attempt on a primary and secondary drive - as a result we clean it when needed, rather than trying to always keep it clean. Also fixed translation bugs in int13h.asm where I had previously missed converting some MODULE_HOTKEYS into MODULE_DRIVEXLATE.

File size: 7.6 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:
[414]31 sti ; Enable interrupts
32 cld ; String instructions to increment pointers
33 LOAD_BDA_SEGMENT_TO es, ax ; Load BDA segment (zero) to ES
[392]34 ; Fall to .PrepareBootLoaderStack
[243]35
[392]36
[243]37;--------------------------------------------------------------------
[392]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
[243]44; Parameters:
45; ES: BDA and interrupt vector segment (zero)
46; Returns:
47; Never returns (loads operating system)
48;--------------------------------------------------------------------
[392]49.PrepareBootLoaderStack:
[243]50 STORE_POST_STACK_POINTER
51 SWITCH_TO_BOOT_MENU_STACK
52 ; Fall to .InitializeDisplay
53
[392]54
[243]55;--------------------------------------------------------------------
56; .InitializeDisplay
57; Parameters:
[392]58; ES: BDA and interrupt vector segment (zero)
[243]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:
[392]69 call DetectPrint_InitializeDisplayContext
70 ; Fall to .InitializeBiosAndDetectDrives
[243]71
[392]72
[243]73;--------------------------------------------------------------------
[392]74; .InitializeBiosAndDetectDrives
[243]75; Parameters:
[392]76; ES: BDA and interrupt vector segment (zero)
[243]77; Returns:
[392]78; DS: RAMVARS segment
[243]79;--------------------------------------------------------------------
[413]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
[392]94 ; Fall to SelectDriveToBootFrom
[243]95
[392]96
[243]97;--------------------------------------------------------------------
[392]98; SelectDriveToBootFrom
[243]99; Parameters:
100; DS: RAMVARS segment
[392]101; ES: BDA and interrupt vector segment (zero)
[243]102; Returns:
103; Never returns (loads operating system)
104;--------------------------------------------------------------------
[392]105SelectDriveToBootFrom:
[492]106
107; The following macro could be easily inlined below. Why a macro? Depending on the combination
108; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
109; call to the boot menu.
110;
111%macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
112 push dx ; it's OK if this is left on the stack, if we are
113 ; are successful, the following call does not return
114 call TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
115 pop dx
116 mov dl, dh
117 call TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
118%endmacro
119
[395]120%ifdef MODULE_HOTKEYS
[492]121 call HotkeyBar_ScanHotkeysFromKeyBufferAndStoreToBootvars
122 cmp al, ROM_BOOT_HOTKEY_SCANCODE
[493]123 jz .RomBoot ; CF clear so ROM boot
[392]124%ifdef MODULE_BOOT_MENU
[492]125 cmp al, BOOT_MENU_HOTKEY_SCANCODE
126 jz .BootMenu
[392]127%endif
[492]128 call HotkeyBar_GetBootDriveNumbersToDX
129.TryUsingHotKeysCode:
130 TRY_TO_BOOT_DL_AND_DH_DRIVES
131 ;; falls through to boot menu, if it is present. If not present, falls through to rom boot.
132%endif
[392]133
[492]134%ifdef MODULE_BOOT_MENU
135.BootMenu:
136 call BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
[493]137 jnc .RomBoot ; CF clear so ROM boot
[392]138
[492]139 mov dh, dl ; Setup for secondary drive
140 not dh ; Floppy goes to HD, or vice veras
141 and dh, 080h ; Go to first drive of the floppy or HD set
[398]142
[395]143%ifdef MODULE_HOTKEYS
[492]144 jmp .TryUsingHotKeysCode
[395]145%else
[492]146 TRY_TO_BOOT_DL_AND_DH_DRIVES
147 jmp .BootMenu
[395]148%endif
[492]149%endif
[392]150
[492]151%ifndef MODULE_HOTKEYS
152%ifndef MODULE_BOOT_MENU
153 xor dl, dl ; Try to boot from Floppy Drive A
154 call TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
155 mov dl, 80h ; Try to boot from Hard Drive C
156 call TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
[386]157%endif
[492]158%endif
[243]159
[493]160.RomBoot:
161%ifdef MODULE_DRIVEXLATE
162 call DriveXlate_Reset ; Clean up any drive mappings before Rom Boot
163%endif
164 clc
165 ;; fall through to JumpToBootSector_or_RomBoot
[392]166
[243]167;--------------------------------------------------------------------
[392]168; JumpToBootSector_or_RomBoot
[243]169;
170; Switches back to the POST stack, clears the DS and ES registers,
171; and either jumps to the MBR (Master Boot Record) that was just read,
172; or calls the ROM's boot routine on interrupt 18.
173;
174; Parameters:
175; DL: Drive to boot from (translated, 00h or 80h)
176; CF: Set for Boot Sector Boot
[392]177; Clear for ROM Boot
[243]178; ES:BX: (if CF set) Ptr to boot sector
179;
180; Returns:
181; Never returns
182;--------------------------------------------------------------------
[392]183JumpToBootSector_or_RomBoot:
[243]184 mov cx, es ; Preserve MBR segment (can't push because of stack change)
185 mov ax, 0 ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
186 SWITCH_BACK_TO_POST_STACK
187
188; clear segment registers before boot sector or rom call
189 mov ds, ax
190 mov es, ax
191%ifdef USE_386
192 mov fs, ax
193 mov gs, ax
194%endif
195 jnc SHORT .romboot
196
197; jump to boot sector
198 push cx ; sgment address for MBR
199 push bx ; offset address for MBR
200 retf ; NOTE: DL is set to the drive number
201
202; Boot by calling INT 18h (ROM Basic of ROM DOS)
203.romboot:
[392]204 int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
205
206
207;--------------------------------------------------------------------
208; TryToBootFromPrimaryOrSecondaryBootDevice
209; Parameters
210; DL: Drive selected as boot device
211; DS: RAMVARS segment
212; ES: BDA and interrupt vector segment (zero)
213; Returns:
214; DL: Drive to boot from (translated, 00h or 80h)
215; CF: Set for Boot Sector Boot
216; Clear for ROM Boot
217; ES:BX: (if CF set) Ptr to boot sector
218; Corrupts registers:
219; AX, CX, DH, SI, DI, (DL if failed to read boot sector)
220;--------------------------------------------------------------------
[492]221%ifndef MODULE_DRIVEXLATE
222TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot EQU BootSector_TryToLoadFromDriveDL_AndBoot
[395]223
224%else
[492]225TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot:
[392]226 call DriveXlate_SetDriveToSwap
227 call DriveXlate_ToOrBack
[492]228 ; fall through to TryToBoot_FallThroughTo_BootSector_TryToLoadFromDriveDL_AndBoot
229
230TryToBoot_FallThroughTo_BootSector_TryToLoadFromDriveDL_AndBoot:
231; fall through to BootSector_TryToLoadFromDriveDL_AndBoot
[395]232%endif
[492]233
234
Note: See TracBrowser for help on using the repository browser.