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

Last change on this file since 302 was 294, checked in by krille_n_@…, 13 years ago

Commit 2/2 (BIOS):

  • Fixed a bug in AH1h_HStatus.asm.
  • Minor optimizations.
  • Fixed spelling and did some cleaning.
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 successful)
14; CF: Set if boot sector loaded successfully
15; Cleared if failed to load boot sector
16; Corrupts registers:
17; AX, CX, DH, SI, 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 stc
31 ret
32.FailedToLoadFirstSector:
33 call BootPrint_FailedToLoadFirstSector
34 clc
35 ret
36.FirstHardDiskSectorNotBootable:
37 mov si, g_szBootSectorNotFound
38 call BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
39 clc
40 ret
41
42;--------------------------------------------------------------------
43; LoadFirstSectorFromDriveDL
44; Parameters:
45; DL: Drive to boot from (translated, 00h or 80h)
46; Returns:
47; AH: INT 13h error code
48; ES:BX: Ptr to boot sector (if successful)
49; CF: Cleared if read successful
50; Set if any error
51; Corrupts registers:
52; AL, CX, DH, DI
53;--------------------------------------------------------------------
54ALIGN JUMP_ALIGN
55LoadFirstSectorFromDriveDL:
56 LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
57 mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
58 mov di, BOOT_READ_RETRY_TIMES ; Initialize retry counter
59ALIGN JUMP_ALIGN
60.ReadRetryLoop:
61 call .ResetBootDriveFromDL
62 call .LoadFirstSectorFromDLtoESBX
63 jnc SHORT .Return
64 dec di ; Decrement retry counter
65 jnz SHORT .ReadRetryLoop ; Loop while retries left
66.Return:
67 ret
68
69;--------------------------------------------------------------------
70; .ResetBootDriveFromDL
71; Parameters:
72; DL: Drive to boot from (translated, 00h or 80h)
73; Returns:
74; AH: INT 13h error code
75; CF: Cleared if read successful
76; Set if any error
77; Corrupts registers:
78; AL
79;--------------------------------------------------------------------
80ALIGN JUMP_ALIGN
81.ResetBootDriveFromDL:
82 xor ax, ax ; AH=0h, Disk Controller Reset
83 test dl, dl ; Floppy drive?
84 jns SHORT .SkipAltReset
85 mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
86.SkipAltReset:
87 int BIOS_DISK_INTERRUPT_13h
88 ret
89
90;--------------------------------------------------------------------
91; .LoadFirstSectorFromDLtoESBX
92; Parameters:
93; DL: Drive to boot from (translated, 00h or 80h)
94; ES:BX: Destination buffer for boot sector
95; Returns:
96; AH: INT 13h error code
97; ES:BX: Ptr to boot sector
98; CF: Cleared if read successful
99; Set if any error
100; Corrupts registers:
101; AL, CX, DH
102;--------------------------------------------------------------------
103ALIGN JUMP_ALIGN
104.LoadFirstSectorFromDLtoESBX:
105 mov ax, 0201h ; Read 1 sector
106 mov cx, 1 ; Cylinder 0, Sector 1
107 xor dh, dh ; Head 0
108 int BIOS_DISK_INTERRUPT_13h
109 ret
Note: See TracBrowser for help on using the repository browser.