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

Last change on this file since 391 was 386, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Boot menu is now an optional module (MODULE_BOOT_MENU).
File size: 3.9 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Reading and jumping to boot sector.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; BootSector_TryToLoadFromDriveDL
25; Parameters:
26; DL: Drive to boot from (translated, 00h or 80h)
27; DS: RAMVARS segment
28; Returns:
29; ES:BX: Ptr to boot sector (if successful)
30; CF: Set if boot sector loaded successfully
31; Cleared if failed to load boot sector
32; Corrupts registers:
33; AX, CX, DH, SI, DI, (DL if failed to read boot sector)
34;--------------------------------------------------------------------
35BootSector_TryToLoadFromDriveDL:
36 call DetectPrint_TryToBootFromDL
37 call LoadFirstSectorFromDriveDL
38 jc SHORT .FailedToLoadFirstSector
39
40 test dl, dl
41 jns SHORT .AlwaysBootFromFloppyDriveForBooterGames
42 cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
43 jne SHORT .FirstHardDiskSectorNotBootable
44.AlwaysBootFromFloppyDriveForBooterGames:
45 stc
46 ret
47.FailedToLoadFirstSector:
48 call DetectPrint_FailedToLoadFirstSector
49 clc
50 ret
51.FirstHardDiskSectorNotBootable:
52 mov si, g_szBootSectorNotFound
53 call DetectPrint_NullTerminatedStringFromCSSIandSetCF
54 clc
55 ret
56
57;--------------------------------------------------------------------
58; LoadFirstSectorFromDriveDL
59; Parameters:
60; DL: Drive to boot from (translated, 00h or 80h)
61; Returns:
62; AH: INT 13h error code
63; ES:BX: Ptr to boot sector (if successful)
64; CF: Cleared if read successful
65; Set if any error
66; Corrupts registers:
67; AL, CX, DH, DI
68;--------------------------------------------------------------------
69LoadFirstSectorFromDriveDL:
70 LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
71 mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
72 mov di, BOOT_READ_RETRY_TIMES ; Initialize retry counter
73
74.ReadRetryLoop:
75 call .ResetBootDriveFromDL
76 call .LoadFirstSectorFromDLtoESBX
77 jnc SHORT .Return
78 dec di ; Decrement retry counter
79 jnz SHORT .ReadRetryLoop ; Loop while retries left
80.Return:
81 ret
82
83;--------------------------------------------------------------------
84; .ResetBootDriveFromDL
85; Parameters:
86; DL: Drive to boot from (translated, 00h or 80h)
87; Returns:
88; AH: INT 13h error code
89; CF: Cleared if read successful
90; Set if any error
91; Corrupts registers:
92; AL
93;--------------------------------------------------------------------
94.ResetBootDriveFromDL:
95 xor ax, ax ; AH=0h, Disk Controller Reset
96 test dl, dl ; Floppy drive?
97 jns SHORT .SkipAltReset
98 mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
99.SkipAltReset:
100 int BIOS_DISK_INTERRUPT_13h
101 ret
102
103;--------------------------------------------------------------------
104; .LoadFirstSectorFromDLtoESBX
105; Parameters:
106; DL: Drive to boot from (translated, 00h or 80h)
107; ES:BX: Destination buffer for boot sector
108; Returns:
109; AH: INT 13h error code
110; ES:BX: Ptr to boot sector
111; CF: Cleared if read successful
112; Set if any error
113; Corrupts registers:
114; AL, CX, DH
115;--------------------------------------------------------------------
116.LoadFirstSectorFromDLtoESBX:
117 mov ax, 0201h ; Read 1 sector
118 mov cx, 1 ; Cylinder 0, Sector 1
119 xor dh, dh ; Head 0
120 int BIOS_DISK_INTERRUPT_13h
121 ret
Note: See TracBrowser for help on using the repository browser.