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