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

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

Changes to XTIDE Universal BIOS:

  • Cleaned some code concerning recent module changes.
  • Removed drive number translation flag from ROMVARS.
  • BOOTMENUINFO is now DRVDETECTINFO.
  • Makefile now builds tiny binary (XT build with minimal features).
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%ifdef MODULE_HOTKEYS
110    cmp     BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], ROM_BOOT_HOTKEY_SCANCODE
111    je      SHORT JumpToBootSector_or_RomBoot   ; CF clear so ROM boot
112%endif
113
114    ; Try to boot from Primary boot drive (00h by default)
115%ifdef MODULE_HOTKEYS
116    call    HotkeyBar_GetPrimaryBootDriveNumberToDL
117%else
118    mov     dl, [cs:ROMVARS.bBootDrv]
119    and     dl, 80h     ; Only 00h and 80h allowed when not using MODULE_HOTKEYS
120%endif
121    call    TryToBootFromPrimaryOrSecondaryBootDevice
122    jc      SHORT JumpToBootSector_or_RomBoot
123
124    ; Try to boot from Secondary boot device (80h by default)
125%ifdef MODULE_HOTKEYS
126    call    HotkeyBar_GetSecondaryBootDriveNumberToDL
127%else
128    mov     dl, [cs:ROMVARS.bBootDrv]
129    and     dl, 80h
130    xor     dl, 80h
131%endif
132    call    TryToBootFromPrimaryOrSecondaryBootDevice
133
134%ifdef MODULE_BOOT_MENU
135    ; Force Boot Menu hotkey to display boot menu
136    mov     BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], BOOT_MENU_HOTKEY_SCANCODE
137    jnc     SHORT SelectDriveToBootFrom
138%endif
139    ; Fall to JumpToBootSector_or_RomBoot
140
141
142;--------------------------------------------------------------------
143; JumpToBootSector_or_RomBoot
144;
145; Switches back to the POST stack, clears the DS and ES registers,
146; and either jumps to the MBR (Master Boot Record) that was just read,
147; or calls the ROM's boot routine on interrupt 18.
148;
149;   Parameters:
150;       DL:     Drive to boot from (translated, 00h or 80h)
151;       CF:     Set for Boot Sector Boot 
152;               Clear for ROM Boot
153;       ES:BX:  (if CF set) Ptr to boot sector
154;
155;   Returns:
156;       Never returns
157;--------------------------------------------------------------------
158JumpToBootSector_or_RomBoot:
159    mov     cx, es      ; Preserve MBR segment (can't push because of stack change)
160    mov     ax, 0       ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
161    SWITCH_BACK_TO_POST_STACK
162
163; clear segment registers before boot sector or rom call
164    mov     ds, ax     
165    mov     es, ax
166%ifdef USE_386
167    mov     fs, ax
168    mov     gs, ax
169%endif
170    jnc     SHORT .romboot
171
172; jump to boot sector
173    push    cx          ; sgment address for MBR
174    push    bx          ; offset address for MBR
175    retf                ; NOTE: DL is set to the drive number
176
177; Boot by calling INT 18h (ROM Basic of ROM DOS)
178.romboot:
179    int     BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns 
180
181
182;--------------------------------------------------------------------
183; TryToBootFromPrimaryOrSecondaryBootDevice
184;   Parameters
185;       DL:     Drive selected as boot device
186;       DS:     RAMVARS segment
187;       ES:     BDA and interrupt vector segment (zero)
188;   Returns:
189;       DL:     Drive to boot from (translated, 00h or 80h)
190;       CF:     Set for Boot Sector Boot
191;               Clear for ROM Boot
192;       ES:BX:  (if CF set) Ptr to boot sector
193;   Corrupts registers:
194;       AX, CX, DH, SI, DI, (DL if failed to read boot sector)
195;--------------------------------------------------------------------
196%ifndef MODULE_HOTKEYS
197TryToBootFromPrimaryOrSecondaryBootDevice   EQU     BootSector_TryToLoadFromDriveDL
198
199%else
200TryToBootFromPrimaryOrSecondaryBootDevice:
201    call    DriveXlate_SetDriveToSwap
202    call    DriveXlate_ToOrBack
203    jmp     BootSector_TryToLoadFromDriveDL
204%endif
Note: See TracBrowser for help on using the repository browser.