source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Boot/BootSector.asm@ 129

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

Changes to the XTIDE Universal BIOS:

  • Size optimizations in various files.
File size: 3.4 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Reading and jumping to boot sector.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; BootSector_TryToLoadFromDriveDL
9; Parameters:
10; DL: Drive to boot from (translated, 00h or 80h)
11; DS: RAMVARS segment
12; Returns:
13; ES:BX: Ptr to boot sector (if successfull)
14; CF: Set if boot sector loaded succesfully
15; Cleared if failed to load boot sector
16; Corrupts registers:
17; AX, CX, DH, DI, (DL if failed to read boot sector)
18;--------------------------------------------------------------------
19ALIGN JUMP_ALIGN
20BootSector_TryToLoadFromDriveDL:
21 call BootPrint_TryToBootFromDL
22 call LoadFirstSectorFromDriveDL
23 jc SHORT .FailedToLoadFirstSector
24
25 test dl, dl
26 jns SHORT .AlwaysBootFromFloppyDriveForBooterGames
27 cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
28 jne SHORT .FirstHardDiskSectorNotBootable
29.AlwaysBootFromFloppyDriveForBooterGames:
30 mov bx, g_szFound
31 call BootPrint_BootSectorResultStringFromBX
32 stc
33 ret
34.FailedToLoadFirstSector:
35 call BootPrint_FailedToLoadFirstSector
36 clc
37 ret
38.FirstHardDiskSectorNotBootable:
39 mov bx, g_szNotFound
40 call BootPrint_BootSectorResultStringFromBX
41 clc
42 ret
43
44;--------------------------------------------------------------------
45; LoadFirstSectorFromDriveDL
46; Parameters:
47; DL: Drive to boot from (translated, 00h or 80h)
48; Returns:
49; AH: INT 13h error code
50; ES:BX: Ptr to boot sector (if successfull)
51; CF: Cleared if read successfull
52; Set if any error
53; Corrupts registers:
54; AL, CX, DH, DI
55;--------------------------------------------------------------------
56ALIGN JUMP_ALIGN
57LoadFirstSectorFromDriveDL:
58 LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
59 mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
60 mov di, BOOT_READ_RETRY_TIMES ; Initialize retry counter
61ALIGN JUMP_ALIGN
62.ReadRetryLoop:
63 call .ResetBootDriveFromDL
64 call .LoadFirstSectorFromDLtoESBX
65 jnc SHORT .Return
66 dec di ; Decrement retry counter
67 jnz SHORT .ReadRetryLoop ; Loop while retries left
68ALIGN JUMP_ALIGN
69.Return:
70 ret
71
72;--------------------------------------------------------------------
73; .ResetBootDriveFromDL
74; Parameters:
75; DL: Drive to boot from (translated, 00h or 80h)
76; Returns:
77; AH: INT 13h error code
78; CF: Cleared if read successfull
79; Set if any error
80; Corrupts registers:
81; AL
82;--------------------------------------------------------------------
83ALIGN JUMP_ALIGN
84.ResetBootDriveFromDL:
85 xor ax, ax ; AH=0h, Disk Controller Reset
86 test dl, dl ; Floppy drive?
87 jns SHORT .SkipAltReset
88 mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
89.SkipAltReset:
90 int INTV_DISK_FUNC
91 ret
92
93;--------------------------------------------------------------------
94; .LoadFirstSectorFromDLtoESBX
95; Parameters:
96; DL: Drive to boot from (translated, 00h or 80h)
97; ES:BX: Destination buffer for boot sector
98; Returns:
99; AH: INT 13h error code
100; ES:BX: Ptr to boot sector
101; CF: Cleared if read successfull
102; Set if any error
103; Corrupts registers:
104; AL, CX, DH
105;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
107.LoadFirstSectorFromDLtoESBX:
108 mov ax, 0201h ; Read 1 sector
109 mov cx, 1 ; Cylinder 0, Sector 1
110 xor dh, dh ; Head 0
111 int INTV_DISK_FUNC
112 ret
Note: See TracBrowser for help on using the repository browser.