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

Last change on this file since 89 was 84, checked in by krille_n_@…, 14 years ago

Minor size optimizations in various files.

File size: 6.5 KB
RevLine 
[3]1; File name : Int19h.asm
2; Project name : IDE BIOS
3; Created date : 3.8.2007
[84]4; Last update : 14.1.2011
5; Author : Tomi Tilli,
6; : Krister Nordvall (optimizations)
[3]7; Description : Int 19h BIOS functions (Boot Strap Loader).
8
9; Section containing code
10SECTION .text
11
12B_READ_RETRY_TIMES EQU 3 ; Number of times to retry
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
[61]77
78 test dl, 80h
79 jz SHORT .AlwaysBootFromFloppyDriveForBooterGames
[3]80 cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
[61]81 jne SHORT .FirstHardDiskSectorNotBootable
82.AlwaysBootFromFloppyDriveForBooterGames:
[3]83 call BootPrint_BootSectorLoaded
84 stc
85 ret
86.FailedToLoadFirstSector:
87 call BootPrint_FailedToLoadFirstSector
88 clc
89 ret
[61]90.FirstHardDiskSectorNotBootable:
[3]91 call BootPrint_FirstSectorNotBootable
92 clc
93 ret
94
95;--------------------------------------------------------------------
96; Reads first sector (boot sector) from drive DL.
97;
98; Int19h_LoadFirstSectorFromDL
99; Parameters:
100; DL: Drive to boot from (translated, 00h or 80h)
101; Returns:
102; AH: INT 13h error code
103; ES:BX: Ptr to boot sector (if successfull)
104; CF: Cleared if read successfull
105; Set if any error
106; Corrupts registers:
107; AL, CX, DH, DI
108;--------------------------------------------------------------------
109ALIGN JUMP_ALIGN
110Int19h_LoadFirstSectorFromDL:
111 LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
112 mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
113 mov di, B_READ_RETRY_TIMES ; Retry counter
114ALIGN JUMP_ALIGN
115.ReadRetryLoop:
[28]116 call .ResetBootDriveFromDL
117 call .LoadFirstSectorFromDLtoESBX
[3]118 jnc SHORT .Return
119 dec di ; Decrement retry counter
120 jnz SHORT .ReadRetryLoop ; Loop while retries left
121ALIGN JUMP_ALIGN
122.Return:
123 ret
124
125;--------------------------------------------------------------------
[28]126; .ResetBootDriveFromDL
[3]127; Parameters:
128; DL: Drive to boot from (translated, 00h or 80h)
129; Returns:
130; AH: INT 13h error code
131; CF: Cleared if read successfull
132; Set if any error
133; Corrupts registers:
[28]134; AL
[3]135;--------------------------------------------------------------------
136ALIGN JUMP_ALIGN
[28]137.ResetBootDriveFromDL:
138 xor ax, ax ; AH=0h, Disk Controller Reset
139 test dl, 80h ; Floppy drive?
140 jz SHORT .ResetDriveFromDL ; If so, jump to reset
141 mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
142.ResetDriveFromDL:
[3]143 int INTV_DISK_FUNC
144 ret
145
146;--------------------------------------------------------------------
[28]147; Reads first sector (boot sector) from drive DL to ES:BX.
[3]148;
[28]149; .LoadFirstSectorFromDLtoESBX
[3]150; Parameters:
151; DL: Drive to boot from (translated, 00h or 80h)
[28]152; ES:BX: Destination buffer for boot sector
[3]153; Returns:
[28]154; AH: INT 13h error code
155; ES:BX: Ptr to boot sector
156; CF: Cleared if read successfull
157; Set if any error
[3]158; Corrupts registers:
[28]159; AL, CX, DH
[3]160;--------------------------------------------------------------------
161ALIGN JUMP_ALIGN
[28]162.LoadFirstSectorFromDLtoESBX:
163 mov ax, 0201h ; Read 1 sector
164 mov cx, 1 ; Cylinder 0, Sector 1
165 xor dh, dh ; Head 0
[3]166 int INTV_DISK_FUNC
167 ret
168
169
170;--------------------------------------------------------------------
171; Jumps to boot sector pointed by ES:BX.
172;
173; Int19h_JumpToBootSector
174; Parameters:
175; DL: Drive to boot from (translated, 00h or 80h)
176; ES:BX: Ptr to boot sector
177; Returns:
178; Never returns
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181Int19h_JumpToBootSector:
182 push es ; Push boot sector segment
183 push bx ; Push boot sector offset
184 call Int19h_ClearSegmentsForBoot
185 xor dh, dh ; Device supported by INT 13h
186 retf
187
188;--------------------------------------------------------------------
189; Clears DS and ES registers to zero.
190;
191; Int19h_ClearSegmentsForBoot
192; Parameters:
193; Nothing
194; Returns:
195; DS=ES: Zero
196; Corrupts registers:
197; AX
198;--------------------------------------------------------------------
199ALIGN JUMP_ALIGN
200Int19h_ClearSegmentsForBoot:
201 xor ax, ax
202 mov ds, ax
203 mov es, ax
204 ret
205
206
207;--------------------------------------------------------------------
208; Calls INT 18h (ROM Basic or Boot Failure). Called after booting from
209; floppy drive or hard disk fails.
210;
211; Int19h_BootFailure
212; Parameters:
213; Nothing
214; Returns:
215; Should never return (but might)
216;--------------------------------------------------------------------
217ALIGN JUMP_ALIGN
218Int19h_BootFailure:
219 call Int19h_ClearSegmentsForBoot
220 int INTV_BOOT_FAILURE
221 ret
Note: See TracBrowser for help on using the repository browser.