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

Last change on this file since 66 was 61, checked in by Tomi Tilli, 14 years ago

Changes to XTIDE Universal BIOS:

  • AA55h signature no longer required when booting from floppy drives. This should make booter games work.
File size: 6.4 KB
RevLine 
[3]1; File name : Int19h.asm
2; Project name : IDE BIOS
3; Created date : 3.8.2007
[61]4; Last update : 28.11.2010
[3]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
[61]76
77 test dl, 80h
78 jz SHORT .AlwaysBootFromFloppyDriveForBooterGames
[3]79 cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
[61]80 jne SHORT .FirstHardDiskSectorNotBootable
81.AlwaysBootFromFloppyDriveForBooterGames:
[3]82 call BootPrint_BootSectorLoaded
83 stc
84 ret
85.FailedToLoadFirstSector:
86 call BootPrint_FailedToLoadFirstSector
87 clc
88 ret
[61]89.FirstHardDiskSectorNotBootable:
[3]90 call BootPrint_FirstSectorNotBootable
91 clc
92 ret
93
94;--------------------------------------------------------------------
95; Reads first sector (boot sector) from drive DL.
96;
97; Int19h_LoadFirstSectorFromDL
98; Parameters:
99; DL: Drive to boot from (translated, 00h or 80h)
100; Returns:
101; AH: INT 13h error code
102; ES:BX: Ptr to boot sector (if successfull)
103; CF: Cleared if read successfull
104; Set if any error
105; Corrupts registers:
106; AL, CX, DH, DI
107;--------------------------------------------------------------------
108ALIGN JUMP_ALIGN
109Int19h_LoadFirstSectorFromDL:
110 LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
111 mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
112 mov di, B_READ_RETRY_TIMES ; Retry counter
113ALIGN JUMP_ALIGN
114.ReadRetryLoop:
[28]115 call .ResetBootDriveFromDL
116 call .LoadFirstSectorFromDLtoESBX
[3]117 jnc SHORT .Return
118 dec di ; Decrement retry counter
119 jnz SHORT .ReadRetryLoop ; Loop while retries left
120 stc
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.