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

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