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

Last change on this file since 560 was 560, checked in by aitotat@…, 11 years ago

Changes to XTIDE Universal BIOS:

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