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

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

Changes to XTIDE Universal BIOS:

  • Hotkey Bar and drive translations are now in MODULE_HOTKEYS.
File size: 6.6 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-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
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                                         ; Allow timer interrupts
32    LOAD_BDA_SEGMENT_TO es, ax                  ; Load BDA segment (zero) to ES
33    ; Fall to .PrepareBootLoaderStack
34
35
36;--------------------------------------------------------------------
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
43;   Parameters:
44;       ES:     BDA and interrupt vector segment (zero)
45;   Returns:
46;       Never returns (loads operating system)
47;--------------------------------------------------------------------
48.PrepareBootLoaderStack:
49    STORE_POST_STACK_POINTER
50    SWITCH_TO_BOOT_MENU_STACK
51    ; Fall to .InitializeDisplay
52
53
54;--------------------------------------------------------------------
55; .InitializeDisplay
56;   Parameters:
57;       ES:     BDA and interrupt vector segment (zero)
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:
68    call    DetectPrint_InitializeDisplayContext
69    ; Fall to .InitializeBiosAndDetectDrives
70
71
72;--------------------------------------------------------------------
73; .InitializeBiosAndDetectDrives
74;   Parameters:
75;       ES:     BDA and interrupt vector segment (zero)
76;   Returns:
77;       DS:     RAMVARS segment
78;--------------------------------------------------------------------
79    call    Initialize_AndDetectDrives 
80    ; Fall to SelectDriveToBootFrom
81
82
83;--------------------------------------------------------------------
84; SelectDriveToBootFrom
85;   Parameters:
86;       DS:     RAMVARS segment
87;       ES:     BDA and interrupt vector segment (zero)
88;   Returns:
89;       Never returns (loads operating system)
90;--------------------------------------------------------------------
91SelectDriveToBootFrom:
92%ifdef MODULE_HOTKEYS
93    call    HotkeyBar_UpdateDuringDriveDetection
94
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
99
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%endif
107
108    ; Check if ROM boot (INT 18h) wanted
109    cmp     BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], ROM_BOOT_HOTKEY_SCANCODE
110    je      SHORT JumpToBootSector_or_RomBoot   ; CF clear so ROM boot
111
112    ; Try to boot from Primary boot drive (00h by default)
113%ifdef MODULE_HOTKEYS
114    call    HotkeyBar_GetPrimaryBootDriveNumberToDL
115%else
116    mov     dl, [cs:ROMVARS.bBootDrv]
117    and     dl, 80h     ; Only 00h and 80h allowed when not using MODULE_HOTKEYS
118%endif
119    call    TryToBootFromPrimaryOrSecondaryBootDevice
120    jc      SHORT JumpToBootSector_or_RomBoot
121
122    ; Try to boot from Secondary boot device (80h by default)
123%ifdef MODULE_HOTKEYS
124    call    HotkeyBar_GetSecondaryBootDriveNumberToDL
125%else
126    mov     dl, [cs:ROMVARS.bBootDrv]
127    and     dl, 80h
128    xor     dl, 80h
129%endif
130    call    TryToBootFromPrimaryOrSecondaryBootDevice
131
132%ifdef MODULE_BOOT_MENU
133    ; Force Boot Menu hotkey to display boot menu
134    mov     BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], BOOT_MENU_HOTKEY_SCANCODE
135    jnc     SHORT SelectDriveToBootFrom
136%endif
137    ; Fall to JumpToBootSector_or_RomBoot
138
139
140;--------------------------------------------------------------------
141; JumpToBootSector_or_RomBoot
142;
143; Switches back to the POST stack, clears the DS and ES registers,
144; and either jumps to the MBR (Master Boot Record) that was just read,
145; or calls the ROM's boot routine on interrupt 18.
146;
147;   Parameters:
148;       DL:     Drive to boot from (translated, 00h or 80h)
149;       CF:     Set for Boot Sector Boot 
150;               Clear for ROM Boot
151;       ES:BX:  (if CF set) Ptr to boot sector
152;
153;   Returns:
154;       Never returns
155;--------------------------------------------------------------------
156JumpToBootSector_or_RomBoot:
157    mov     cx, es      ; Preserve MBR segment (can't push because of stack change)
158    mov     ax, 0       ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
159    SWITCH_BACK_TO_POST_STACK
160
161; clear segment registers before boot sector or rom call
162    mov     ds, ax     
163    mov     es, ax
164%ifdef USE_386
165    mov     fs, ax
166    mov     gs, ax
167%endif
168    jnc     SHORT .romboot
169
170; jump to boot sector
171    push    cx          ; sgment address for MBR
172    push    bx          ; offset address for MBR
173    retf                ; NOTE: DL is set to the drive number
174
175; Boot by calling INT 18h (ROM Basic of ROM DOS)
176.romboot:
177    int     BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns 
178
179
180;--------------------------------------------------------------------
181; TryToBootFromPrimaryOrSecondaryBootDevice
182;   Parameters
183;       DL:     Drive selected as boot device
184;       DS:     RAMVARS segment
185;       ES:     BDA and interrupt vector segment (zero)
186;   Returns:
187;       DL:     Drive to boot from (translated, 00h or 80h)
188;       CF:     Set for Boot Sector Boot
189;               Clear for ROM Boot
190;       ES:BX:  (if CF set) Ptr to boot sector
191;   Corrupts registers:
192;       AX, CX, DH, SI, DI, (DL if failed to read boot sector)
193;--------------------------------------------------------------------
194%ifndef MODULE_HOTKEYS
195TryToBootFromPrimaryOrSecondaryBootDevice   EQU     BootSector_TryToLoadFromDriveDL
196
197%else
198TryToBootFromPrimaryOrSecondaryBootDevice:
199    call    DriveXlate_SetDriveToSwap
200    call    DriveXlate_ToOrBack
201    jmp     BootSector_TryToLoadFromDriveDL
202%endif
Note: See TracBrowser for help on using the repository browser.