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

Last change on this file since 592 was 592, checked in by krille_n_, 6 years ago

Changes:

  • The problem with NASM in the previous revision (r591) has been fixed.
  • The colors used by the boot menu and hotkey bar can now be customized by selecting one of a number of pre-defined color themes. Suggestions for additional themes are more than welcome!
  • Large builds are now 10 KB. Small builds are still 8 KB with the exception of the Tiny build which is now 4 KB. In other words, builds are now as small as possible to make it easier to combine them with other BIOSes.
  • Added code to the library to improve drive error handling. XTIDECFG can now handle "Drive Not Ready" errors.
  • Fixed a couple of potential bugs in AtaID.asm (AtaID_GetMaxPioModeToAXandMinCycleTimeToCX); 1) ATA1.bPioMode was treated as a WORD variable. 2) ATA2.bPIOSupp was assumed to be non-zero which would result in PIO mode 3 being returned if the assumption was wrong.
  • Made the same changes in the equivalent function used by BIOSDRVS (DisplayPioModeInformationUsingAtaInfoFromDSBX in AtaInfo.asm).
  • Fixed a bug from r587 in PDC20x30.asm in PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX.
  • Fixed a bug from r523 in XTIDECFG where Auto Configure would only set the IRQ on one IDE interface on AT-builds.
  • XTIDECFG will now restore the default settings for the "Serial port virtual device" when reselecting it in the list of device types. This makes it behave consistently for all device types.
  • The eAAM macro is now used regardless if USE_UNDOC_INTEL is defined or not because it is apparently supported on all processors including the NEC V20/V30 CPUs.
  • Renamed the EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define to EXCLUDE_FROM_XUB.
  • Added a define to exclude unused library code from BIOSDRVS (EXCLUDE_FROM_BIOSDRVS). This makes it a lot smaller than in previous revisions.
  • All unnecessary CLD-instructions are now under a new define 'CLD_NEEDED' which is only enabled for the BIOS. It is disabled for XTIDECFG and BIOSDRVS but can be enabled if needed by adding this define to the respective makefile. This change was made because these unnecessary instructions are wasteful and should never be needed. In fact, they only serve to hide bugs (in other peoples code) which I strongly believe should be avoided. I recommend people making their own BIOSes from source to not use this define as it's extremely unlikely to be needed.
  • Updated the copyright info in SerDrive and changed an URL to point to the new site.
  • Updated the copyright info and version number in BIOSDRVS.
  • Updated the copyright info in XTIDECFG.
  • Optimizations in general.
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%ifdef CLD_NEEDED
33    cld                                         ; String instructions to increment pointers
34%endif
35%ifdef MODULE_VERY_LATE_INIT
36    LOAD_BDA_SEGMENT_TO ds, ax                  ; Load BDA segment (zero) to DS
37    les     ax, [TEMPORARY_VECTOR_FOR_SYSTEM_INT13h*4]
38    mov     [BIOS_DISK_INTERRUPT_13h*4], ax
39    mov     [BIOS_DISK_INTERRUPT_13h*4+2], es
40    push    ds                                  ; BDA segment (zero)...
41    pop     es                                  ; ...to ES
42%else
43    LOAD_BDA_SEGMENT_TO es, ax                  ; Load BDA segment (zero) to ES
44%endif
45    ; Fall to .PrepareBootLoaderStack
46
47
48;--------------------------------------------------------------------
49; Drive detection and boot menu use lots of stack so it is
50; wise to relocate stack. Otherwise something important from
51; interrupt vectors are likely corrupted, likely our own DPTs if
52; they are located to 30:0h.
53;
54; .PrepareBootLoaderStack
55;   Parameters:
56;       ES:     BDA and interrupt vector segment (zero)
57;   Returns:
58;       Never returns (loads operating system)
59;--------------------------------------------------------------------
60.PrepareBootLoaderStack:
61    STORE_POST_STACK_POINTER
62    SWITCH_TO_BOOT_MENU_STACK
63    ; Fall to .InitializeDisplay
64
65
66;--------------------------------------------------------------------
67; .InitializeDisplay
68;   Parameters:
69;       ES:     BDA and interrupt vector segment (zero)
70;   Returns:
71;       Never returns (loads operating system)
72;--------------------------------------------------------------------
73.InitializeDisplay:
74    ; Change display mode if necessary
75    mov     ax, [cs:ROMVARS.wDisplayMode]   ; AH 00h = Set Video Mode
76    cmp     al, DEFAULT_TEXT_MODE
77    je      SHORT .InitializeDisplayLibrary
78    int     BIOS_VIDEO_INTERRUPT_10h
79.InitializeDisplayLibrary:
80    call    DetectPrint_InitializeDisplayContext
81    ; Fall to .InitializeBiosAndDetectDrives
82
83
84;--------------------------------------------------------------------
85; .InitializeBiosAndDetectDrives
86;   Parameters:
87;       ES:     BDA and interrupt vector segment (zero)
88;   Returns:
89;       DS:     RAMVARS segment
90;--------------------------------------------------------------------
91.InitializeBiosAndDetectDrives:
92%ifdef MODULE_HOTKEYS
93    call    TimerTicks_ReadFromBdaToAX
94    mov     [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed], ax
95%endif
96
97    call    Initialize_AndDetectDrives
98
99%ifdef MODULE_HOTKEYS
100    ; Last hard drive might have scrolled Hotkey Bar out of screen.
101    ; We want to display it during wait.
102    call    HotkeyBar_UpdateDuringDriveDetection
103
104.WaitUntilTimeToCloseHotkeyBar:
105    call    TimerTicks_ReadFromBdaToAX
106    sub     ax, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed]
107    cmp     ax, MIN_TIME_TO_DISPLAY_HOTKEY_BAR
108    jb      SHORT .WaitUntilTimeToCloseHotkeyBar
109%endif
110    ; Fall to .ResetAllDrives
111
112
113;--------------------------------------------------------------------
114; .ResetAllDrives
115;   Parameters:
116;       DS:     RAMVARS segment
117;       ES:     BDA and interrupt vector segment (zero)
118;   Returns:
119;       Nothing
120;--------------------------------------------------------------------
121.ResetAllDrives:
122    ; Reset all drives in the system, not just our drives.
123    xor     ax, ax      ; Disk Controller Reset
124    mov     dl, 80h     ; Reset all hard drives and floppy drives
125    int     BIOS_DISK_INTERRUPT_13h
126    ; Fall to SelectDriveToBootFrom
127
128
129;--------------------------------------------------------------------
130; SelectDriveToBootFrom
131;   Parameters:
132;       DS:     RAMVARS segment
133;       ES:     BDA and interrupt vector segment (zero)
134;   Returns:
135;       Never returns (loads operating system)
136;--------------------------------------------------------------------
137; The following macro could be easily inlined below.  Why a macro?  Depending on the combination
138; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
139; call to the boot menu.
140;
141%macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
142    push    dx                                  ; it's OK if this is left on the stack, if we are
143                                                ; successful, the following call does not return
144    call    BootSector_TryToLoadFromDriveDL_AndBoot
145    pop     dx
146    mov     dl, dh
147    call    BootSector_TryToLoadFromDriveDL_AndBoot
148%endmacro
149
150
151SelectDriveToBootFrom:      ; Function starts here
152%ifdef MODULE_HOTKEYS
153    call    HotkeyBar_UpdateDuringDriveDetection
154    mov     al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
155    cmp     al, ROM_BOOT_HOTKEY_SCANCODE
156    je      SHORT .RomBoot                      ; CF clear so ROM boot
157%ifdef MODULE_BOOT_MENU
158    cmp     al, BOOT_MENU_HOTKEY_SCANCODE
159    je      SHORT .BootMenu
160%endif ; MODULE_BOOT_MENU
161
162.TryUsingHotKeysCode:
163    call    HotkeyBar_GetBootDriveNumbersToDX
164    call    DriveXlate_SetDriveToSwap           ; Enable primary boot device translation
165    xchg    dl, dh
166    call    DriveXlate_SetDriveToSwap           ; Enable secondary boot device translation
167    xchg    dl, dh
168    call    DriveXlate_ToOrBack                 ; Translate now so boot device will appear as 00h or 80h to OS
169    TRY_TO_BOOT_DL_AND_DH_DRIVES
170    ;; falls through to boot menu, if it is present.  If not present, falls through to rom boot.
171%endif ; MODULE_HOTKEYS
172
173
174%ifdef MODULE_BOOT_MENU
175.BootMenu:
176    call    BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
177    jnc     SHORT .RomBoot                      ; CF clear so ROM boot
178
179    call    DriveXlate_Reset
180%ifdef MODULE_HOTKEYS
181    jmp     SHORT .TryUsingHotKeysCode          ; Selected drive stored as hotkey
182%else ; Boot menu without hotkeys, secondary boot drive is always 00h or 80h
183    mov     dh, dl                              ; Setup for secondary drive
184    not     dh                                  ; Floppy goes to HD, or vice versa
185    and     dh, 80h                             ; Go to first drive of the floppy or HD set
186    call    DriveXlate_SetDriveToSwap
187    call    DriveXlate_ToOrBack
188    TRY_TO_BOOT_DL_AND_DH_DRIVES
189    jmp     SHORT .BootMenu                     ; Show boot menu again
190%endif ; MODULE_HOTKEYS
191
192%endif ; MODULE_BOOT_MENU
193
194; No hotkeys and no boot menu means fixed "A then C" boot order
195%ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
196    xor     dl, dl                              ; Try to boot from Floppy Drive A
197    call    BootSector_TryToLoadFromDriveDL_AndBoot
198    mov     dl, 80h                             ; Try to boot from Hard Drive C
199    call    BootSector_TryToLoadFromDriveDL_AndBoot
200%endif
201
202.RomBoot:
203%ifdef MODULE_DRIVEXLATE
204    call    DriveXlate_Reset                    ; Clean up any drive mappings before Rom Boot
205%endif
206    clc
207    ;; fall through to Int19_JumpToBootSectorOrRomBoot
208
209;--------------------------------------------------------------------
210; Int19_JumpToBootSectorOrRomBoot
211;
212; Switches back to the POST stack, clears the DS and ES registers,
213; and either jumps to the MBR (Master Boot Record) that was just read,
214; or calls the ROM's boot routine on interrupt 18.
215;
216;   Parameters:
217;       DL:     Drive to boot from (translated, 00h or 80h)
218;       CF:     Set for Boot Sector Boot
219;               Clear for ROM Boot
220;       ES:BX:  (if CF set) Ptr to boot sector
221;
222;   Returns:
223;       Never returns
224;--------------------------------------------------------------------
225Int19_JumpToBootSectorOrRomBoot:
226    mov     cx, es      ; Preserve MBR segment (can't push because of stack change)
227    mov     ax, 0       ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
228    SWITCH_BACK_TO_POST_STACK
229
230; clear segment registers before boot sector or rom call
231    mov     ds, ax
232    mov     es, ax
233%ifdef USE_386
234    mov     fs, ax
235    mov     gs, ax
236%endif
237    jnc     SHORT .romboot
238
239; jump to boot sector
240    push    cx          ; sgment address for MBR
241    push    bx          ; offset address for MBR
242    retf                ; NOTE: DL is set to the drive number
243
244; Boot by calling INT 18h (ROM Basic of ROM DOS)
245.romboot:
246    int     BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns
Note: See TracBrowser for help on using the repository browser.