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

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 5.9 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; INT 19h handler that properly reboots the computer when
25; INT 19h is called.
26;
27; Int19h_ResetHandler
28;   Parameters:
29;       Nothing
30;   Returns:
31;       Never returns (reboots computer)
32;--------------------------------------------------------------------
33Int19h_ResetHandler:
34    mov     ax, BOOT_FLAG_WARM              ; Skip memory tests
35    jmp     Reboot_ComputerWithBootFlagInAX
36
37
38;--------------------------------------------------------------------
39; Int19h_BootLoaderHandler
40;   Parameters:
41;       Nothing
42;   Returns:
43;       Never returns (loads operating system)
44;--------------------------------------------------------------------
45ALIGN JUMP_ALIGN
46Int19h_BootLoaderHandler:
47    sti
48    ; Install INT 19h handler for proper reboot
49    LOAD_BDA_SEGMENT_TO es, ax
50    mov     al, BIOS_BOOT_LOADER_INTERRUPT_19h  ; INT 19h interrupt vector offset
51    mov     si, Int19h_ResetHandler             ; INT 19h handler to reboot the system
52    call    Interrupts_InstallHandlerToVectorInALFromCSSI
53    call    Initialize_AndDetectDrives          ; Installs new boot menu loader
54    ; Fall to .PrepareStackAndSelectDriveFromBootMenu
55
56;--------------------------------------------------------------------
57; .PrepareStackAndSelectDriveFromBootMenu
58;   Parameters:
59;       ES:     BDA and interrupt vector segment (zero)
60;   Returns:
61;       Never returns (loads operating system)
62;--------------------------------------------------------------------
63.PrepareStackAndSelectDriveFromBootMenu:
64    STORE_POST_STACK_POINTER
65    SWITCH_TO_BOOT_MENU_STACK
66    ; Fall to .InitializeDisplay
67
68;--------------------------------------------------------------------
69; .InitializeDisplay
70;   Parameters:
71;       Nothing
72;   Returns:
73;       Never returns (loads operating system)
74;--------------------------------------------------------------------
75.InitializeDisplay:
76    ; Change display mode if necessary
77    mov     ax, [cs:ROMVARS.wDisplayMode]   ; AH 00h = Set Video Mode
78    cmp     al, DEFAULT_TEXT_MODE
79    je      SHORT .InitializeDisplayLibrary
80    int     BIOS_VIDEO_INTERRUPT_10h
81.InitializeDisplayLibrary:
82    call    BootMenuPrint_InitializeDisplayContext
83    ; Fall to .SelectDriveToBootFrom
84
85;--------------------------------------------------------------------
86; .SelectDriveToBootFrom
87;   Parameters:
88;       Nothing
89;   Returns:
90;       Never returns (loads operating system)
91;--------------------------------------------------------------------
92.SelectDriveToBootFrom:
93    call    RamVars_GetSegmentToDS
94    cmp     WORD [cs:ROMVARS.wfDisplayBootMenu], BYTE 0
95    jne     SHORT ProcessBootMenuSelectionsUntilBootableDriveSelected   ; Display boot menu
96    ; Fall to BootFromDriveAthenTryDriveC
97
98;--------------------------------------------------------------------
99; BootFromDriveAthenTryDriveC
100;   Parameters:
101;       DS:     RAMVARS segment
102;   Returns:
103;       Never returns (loads operating system)
104;--------------------------------------------------------------------
105BootFromDriveAthenTryDriveC:
106    xor     dx, dx              ; DL = 00h = Floppy Drive A
107    call    BootSector_TryToLoadFromDriveDL
108    jc      SHORT Int19hMenu_JumpToBootSector_or_RomBoot
109    mov     dl, 80h             ; DL = 80h = First Hard Drive (usually C)
110    call    BootSector_TryToLoadFromDriveDL
111    jmp     SHORT Int19hMenu_JumpToBootSector_or_RomBoot    ; ROM Boot if error
112
113
114;--------------------------------------------------------------------
115; ProcessBootMenuSelectionsUntilBootableDriveSelected
116;   Parameters:
117;       DS:     RAMVARS segment
118;   Returns:
119;       Never returns
120;--------------------------------------------------------------------
121ProcessBootMenuSelectionsUntilBootableDriveSelected:
122    call    BootMenu_DisplayAndReturnSelectionInDX
123    call    DriveXlate_ToOrBack                                         ; Translate drive number
124    call    BootSector_TryToLoadFromDriveDL
125    jnc     SHORT ProcessBootMenuSelectionsUntilBootableDriveSelected   ; Boot failure, show menu again
126    ; Fall to Int19hMenu_JumpToBootSector_or_RomBoot
127    ; (CF is set or we wouldn't be here, see "jnc" immediately above)
128
129;--------------------------------------------------------------------
130; Int19hMenu_JumpToBootSector_or_RomBoot
131;
132; Switches back to the POST stack, clears the DS and ES registers,
133; and either jumps to the MBR (Master Boot Record) that was just read,
134; or calls the ROM's boot routine on interrupt 18.
135;
136;   Parameters:
137;       DL:     Drive to boot from (translated, 00h or 80h)
138;       CF:     Set for Boot Sector Boot 
139;               Clear for Rom Boot
140;       ES:BX:  (if CF set) Ptr to boot sector
141;
142;   Returns:
143;       Never returns
144;--------------------------------------------------------------------
145ALIGN JUMP_ALIGN
146Int19hMenu_JumpToBootSector_or_RomBoot:
147    mov     cx, es      ; Preserve MBR segment (can't push because of stack change)
148    mov     ax, 0       ; NOTE: can't use XOR (LOAD_BDA_SEGMENT_TO) as it impacts CF
149    SWITCH_BACK_TO_POST_STACK
150
151; clear segment registers before boot sector or rom call
152    mov     ds, ax     
153    mov     es, ax
154%ifdef USE_386
155    mov     fs, ax
156    mov     gs, ax
157%endif
158    jnc     SHORT .romboot
159
160; jump to boot sector
161    push    cx          ; sgment address for MBR
162    push    bx          ; offset address for MBR
163    retf                ; NOTE: DL is set to the drive number
164
165; Boot by calling INT 18h (ROM Basic of ROM DOS)
166.romboot:
167    int     BIOS_BOOT_FAILURE_INTERRUPT_18h ; Never returns     
Note: See TracBrowser for help on using the repository browser.