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

Last change on this file since 53 was 28, checked in by Tomi Tilli, 14 years ago
  • v1.1.1 broke booting from foreign drives, it is now fixed.
  • Improved error handling a bit.
  • Longer DRQ and IRQ timeouts to minimize write timouts with some (bad) CF cards.
  • Default boot menu drive should now be properly selected.
File size: 6.3 KB
Line 
1; File name : Int19h.asm
2; Project name : IDE BIOS
3; Created date : 3.8.2007
4; Last update : 1.8.2010
5; Author : Tomi Tilli
6; Description : Int 19h BIOS functions (Boot Strap Loader).
7
8; Section containing code
9SECTION .text
10
11B_READ_RETRY_TIMES EQU 3 ; Number of times to retry
12
13
14;--------------------------------------------------------------------
15; Int 19h software interrupt handler for late initialization.
16; Calls actual Int 19h after initialization is complete.
17;
18; Int19h_LateInitialization
19; Parameters:
20; Nothing
21; Returns:
22; Never returns
23;--------------------------------------------------------------------
24ALIGN JUMP_ALIGN
25Int19h_LateInitialization:
26 call Initialize_ShouldSkip ; Skip initialization?
27 jc SHORT .SkipInitialization
28 call Initialize_AndDetectDrives
29 int INTV_BOOTSTRAP ; Call actual boot loader
30.SkipInitialization:
31 call RamVars_Initialize ; RAMVARS must be initialized even for simple boot loader
32 ; Fall to Int19h_SimpleBootLoader
33
34;--------------------------------------------------------------------
35; Simple boot loader.
36; Boot sequence is fixed to 00h, 80h and INT 18h.
37;
38; Int19h_SimpleBootLoader
39; Parameters:
40; Nothing
41; Returns:
42; Never returns
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45Int19h_SimpleBootLoader:
46 sti ; Enable interrupts
47 call RamVars_GetSegmentToDS
48 xor dx, dx
49 call Int19h_TryToLoadBootSectorFromDL
50 jc SHORT Int19h_JumpToBootSector
51 mov dl, 80h
52 call Int19h_TryToLoadBootSectorFromDL
53 jc SHORT Int19h_JumpToBootSector
54 call Int19h_BootFailure ; Should never return
55 jmp SHORT Int19h_SimpleBootLoader
56
57;--------------------------------------------------------------------
58; Boots if boot sector is successfully read from the drive.
59;
60; Int19h_TryToLoadBootSectorFromDL
61; Parameters:
62; DL: Drive to boot from (translated, 00h or 80h)
63; DS: RAMVARS segment
64; Returns:
65; ES:BX: Ptr to boot sector (if successfull)
66; CF: Set if boot sector loaded succesfully
67; Cleared if failed to load boot sector
68; Corrupts registers:
69; AX, CX, DH, DI, (DL if failed to read boot sector)
70;--------------------------------------------------------------------
71ALIGN JUMP_ALIGN
72Int19h_TryToLoadBootSectorFromDL:
73 call BootPrint_TryToBootFromDL
74 call Int19h_LoadFirstSectorFromDL
75 jc SHORT .FailedToLoadFirstSector
76 cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
77 jne SHORT .FirstSectorNotBootable
78 call BootPrint_BootSectorLoaded
79 stc
80 ret
81.FailedToLoadFirstSector:
82 call BootPrint_FailedToLoadFirstSector
83 clc
84 ret
85.FirstSectorNotBootable:
86 call BootPrint_FirstSectorNotBootable
87 clc
88 ret
89
90;--------------------------------------------------------------------
91; Reads first sector (boot sector) from drive DL.
92;
93; Int19h_LoadFirstSectorFromDL
94; Parameters:
95; DL: Drive to boot from (translated, 00h or 80h)
96; Returns:
97; AH: INT 13h error code
98; ES:BX: Ptr to boot sector (if successfull)
99; CF: Cleared if read successfull
100; Set if any error
101; Corrupts registers:
102; AL, CX, DH, DI
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105Int19h_LoadFirstSectorFromDL:
106 LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
107 mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
108 mov di, B_READ_RETRY_TIMES ; Retry counter
109ALIGN JUMP_ALIGN
110.ReadRetryLoop:
111 call .ResetBootDriveFromDL
112 call .LoadFirstSectorFromDLtoESBX
113 jnc SHORT .Return
114 dec di ; Decrement retry counter
115 jnz SHORT .ReadRetryLoop ; Loop while retries left
116 stc
117ALIGN JUMP_ALIGN
118.Return:
119 ret
120
121;--------------------------------------------------------------------
122; .ResetBootDriveFromDL
123; Parameters:
124; DL: Drive to boot from (translated, 00h or 80h)
125; Returns:
126; AH: INT 13h error code
127; CF: Cleared if read successfull
128; Set if any error
129; Corrupts registers:
130; AL
131;--------------------------------------------------------------------
132ALIGN JUMP_ALIGN
133.ResetBootDriveFromDL:
134 xor ax, ax ; AH=0h, Disk Controller Reset
135 test dl, 80h ; Floppy drive?
136 jz SHORT .ResetDriveFromDL ; If so, jump to reset
137 mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
138.ResetDriveFromDL:
139 int INTV_DISK_FUNC
140 ret
141
142;--------------------------------------------------------------------
143; Reads first sector (boot sector) from drive DL to ES:BX.
144;
145; .LoadFirstSectorFromDLtoESBX
146; Parameters:
147; DL: Drive to boot from (translated, 00h or 80h)
148; ES:BX: Destination buffer for boot sector
149; Returns:
150; AH: INT 13h error code
151; ES:BX: Ptr to boot sector
152; CF: Cleared if read successfull
153; Set if any error
154; Corrupts registers:
155; AL, CX, DH
156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158.LoadFirstSectorFromDLtoESBX:
159 mov ax, 0201h ; Read 1 sector
160 mov cx, 1 ; Cylinder 0, Sector 1
161 xor dh, dh ; Head 0
162 int INTV_DISK_FUNC
163 ret
164
165
166;--------------------------------------------------------------------
167; Jumps to boot sector pointed by ES:BX.
168;
169; Int19h_JumpToBootSector
170; Parameters:
171; DL: Drive to boot from (translated, 00h or 80h)
172; ES:BX: Ptr to boot sector
173; Returns:
174; Never returns
175;--------------------------------------------------------------------
176ALIGN JUMP_ALIGN
177Int19h_JumpToBootSector:
178 push es ; Push boot sector segment
179 push bx ; Push boot sector offset
180 call Int19h_ClearSegmentsForBoot
181 xor dh, dh ; Device supported by INT 13h
182 retf
183
184;--------------------------------------------------------------------
185; Clears DS and ES registers to zero.
186;
187; Int19h_ClearSegmentsForBoot
188; Parameters:
189; Nothing
190; Returns:
191; DS=ES: Zero
192; Corrupts registers:
193; AX
194;--------------------------------------------------------------------
195ALIGN JUMP_ALIGN
196Int19h_ClearSegmentsForBoot:
197 xor ax, ax
198 mov ds, ax
199 mov es, ax
200 ret
201
202
203;--------------------------------------------------------------------
204; Calls INT 18h (ROM Basic or Boot Failure). Called after booting from
205; floppy drive or hard disk fails.
206;
207; Int19h_BootFailure
208; Parameters:
209; Nothing
210; Returns:
211; Should never return (but might)
212;--------------------------------------------------------------------
213ALIGN JUMP_ALIGN
214Int19h_BootFailure:
215 call Int19h_ClearSegmentsForBoot
216 int INTV_BOOT_FAILURE
217 ret
Note: See TracBrowser for help on using the repository browser.