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

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

Changes to XTIDE Universal BIOS:

  • Cleaned boot loader code some more.
File size: 3.3 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, 80h
26 jz 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, 80h ; Floppy drive?
87 eCMOVNZ ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
88 int INTV_DISK_FUNC
89 ret
90
91;--------------------------------------------------------------------
92; .LoadFirstSectorFromDLtoESBX
93; Parameters:
94; DL: Drive to boot from (translated, 00h or 80h)
95; ES:BX: Destination buffer for boot sector
96; Returns:
97; AH: INT 13h error code
98; ES:BX: Ptr to boot sector
99; CF: Cleared if read successfull
100; Set if any error
101; Corrupts registers:
102; AL, CX, DH
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105.LoadFirstSectorFromDLtoESBX:
106 mov ax, 0201h ; Read 1 sector
107 mov cx, 1 ; Cylinder 0, Sector 1
108 xor dh, dh ; Head 0
109 int INTV_DISK_FUNC
110 ret
Note: See TracBrowser for help on using the repository browser.