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

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

Changes to XTIDE Universal BIOS:

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