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

Last change on this file since 590 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
RevLine 
[243]1; Project name : XTIDE Universal BIOS
2; Description : Int 19h Handler (Boot Loader).
3
[376]4;
[505]5; XTIDE Universal BIOS and Associated Tools
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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.
[505]12;
[376]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
[505]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[505]18;
[376]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:
[553]31 sti ; Enable interrupts
32 cld ; String instructions to increment pointers
[567]33%ifdef MODULE_VERY_LATE_INIT
[561]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
[560]41 LOAD_BDA_SEGMENT_TO es, ax ; Load BDA segment (zero) to ES
[556]42%endif
[392]43 ; Fall to .PrepareBootLoaderStack
[243]44
[392]45
[243]46;--------------------------------------------------------------------
[392]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
[243]53; Parameters:
54; ES: BDA and interrupt vector segment (zero)
55; Returns:
56; Never returns (loads operating system)
57;--------------------------------------------------------------------
[392]58.PrepareBootLoaderStack:
[243]59 STORE_POST_STACK_POINTER
60 SWITCH_TO_BOOT_MENU_STACK
61 ; Fall to .InitializeDisplay
62
[392]63
[243]64;--------------------------------------------------------------------
65; .InitializeDisplay
66; Parameters:
[392]67; ES: BDA and interrupt vector segment (zero)
[243]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:
[392]78 call DetectPrint_InitializeDisplayContext
79 ; Fall to .InitializeBiosAndDetectDrives
[243]80
[392]81
[243]82;--------------------------------------------------------------------
[392]83; .InitializeBiosAndDetectDrives
[243]84; Parameters:
[392]85; ES: BDA and interrupt vector segment (zero)
[243]86; Returns:
[392]87; DS: RAMVARS segment
[243]88;--------------------------------------------------------------------
[555]89.InitializeBiosAndDetectDrives:
[413]90%ifdef MODULE_HOTKEYS
91 call TimerTicks_ReadFromBdaToAX
[524]92 mov [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed], ax
[413]93%endif
94
95 call Initialize_AndDetectDrives
96
97%ifdef MODULE_HOTKEYS
[547]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
[413]102.WaitUntilTimeToCloseHotkeyBar:
103 call TimerTicks_ReadFromBdaToAX
[524]104 sub ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed]
105 cmp ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
[413]106 jb SHORT .WaitUntilTimeToCloseHotkeyBar
107%endif
[555]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
[392]124 ; Fall to SelectDriveToBootFrom
[243]125
[392]126
[243]127;--------------------------------------------------------------------
[392]128; SelectDriveToBootFrom
[243]129; Parameters:
130; DS: RAMVARS segment
[392]131; ES: BDA and interrupt vector segment (zero)
[243]132; Returns:
133; Never returns (loads operating system)
134;--------------------------------------------------------------------
[492]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
[505]137; call to the boot menu.
[492]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
[505]141 ; successful, the following call does not return
[528]142 call BootSector_TryToLoadFromDriveDL_AndBoot
[492]143 pop dx
144 mov dl, dh
[528]145 call BootSector_TryToLoadFromDriveDL_AndBoot
[492]146%endmacro
[505]147
[528]148
149SelectDriveToBootFrom: ; Function starts here
[395]150%ifdef MODULE_HOTKEYS
[528]151 call HotkeyBar_UpdateDuringDriveDetection
152 mov al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
[492]153 cmp al, ROM_BOOT_HOTKEY_SCANCODE
[528]154 je SHORT .RomBoot ; CF clear so ROM boot
[392]155%ifdef MODULE_BOOT_MENU
[492]156 cmp al, BOOT_MENU_HOTKEY_SCANCODE
[528]157 je SHORT .BootMenu
158%endif ; MODULE_BOOT_MENU
159
160.TryUsingHotKeysCode:
[492]161 call HotkeyBar_GetBootDriveNumbersToDX
[528]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
[529]166 call DriveXlate_ToOrBack ; Translate now so boot device will appear as 00h or 80h to OS
[492]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.
[505]169%endif ; MODULE_HOTKEYS
[392]170
[528]171
[492]172%ifdef MODULE_BOOT_MENU
[505]173.BootMenu:
[492]174 call BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
[528]175 jnc SHORT .RomBoot ; CF clear so ROM boot
[392]176
[528]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
[492]181 mov dh, dl ; Setup for secondary drive
[505]182 not dh ; Floppy goes to HD, or vice versa
183 and dh, 80h ; Go to first drive of the floppy or HD set
[528]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
[398]189
[505]190%endif ; MODULE_BOOT_MENU
[392]191
[528]192; No hotkeys and no boot menu means fixed "A then C" boot order
[505]193%ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
[529]194 xor dl, dl ; Try to boot from Floppy Drive A
[528]195 call BootSector_TryToLoadFromDriveDL_AndBoot
[529]196 mov dl, 80h ; Try to boot from Hard Drive C
[528]197 call BootSector_TryToLoadFromDriveDL_AndBoot
[386]198%endif
[243]199
[493]200.RomBoot:
201%ifdef MODULE_DRIVEXLATE
202 call DriveXlate_Reset ; Clean up any drive mappings before Rom Boot
203%endif
[505]204 clc
[521]205 ;; fall through to Int19_JumpToBootSectorOrRomBoot
[392]206
[243]207;--------------------------------------------------------------------
[521]208; Int19_JumpToBootSectorOrRomBoot
[243]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)
[567]216; CF: Set for Boot Sector Boot
217; Clear for ROM Boot
218; ES:BX: (if CF set) Ptr to boot sector
[243]219;
220; Returns:
221; Never returns
222;--------------------------------------------------------------------
[521]223Int19_JumpToBootSectorOrRomBoot:
[243]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
[505]229 mov ds, ax
[243]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:
[505]244 int BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
Note: See TracBrowser for help on using the repository browser.