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

Last change on this file since 461 was 428, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Motor spin up is now waited when resetting drive.
  • Optimized boot sector loading a bit.
File size: 3.6 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 .LoadFirstSectorFromDLtoESBX
76 jnc SHORT .Return
77 dec di ; Decrement retry counter (preserve CF)
78 jz SHORT .Return ; Loop while retries left
79
80 ; Reset drive and retry
81 xor ax, ax ; AH=0h, Disk Controller Reset
82 test dl, dl ; Floppy drive?
83 eCMOVS ah, RESET_HARD_DISK ; AH=Dh, Reset Hard Disk (Alternate reset)
84 int BIOS_DISK_INTERRUPT_13h
85 jmp SHORT .ReadRetryLoop
86
87
88;--------------------------------------------------------------------
89; .LoadFirstSectorFromDLtoESBX
90; Parameters:
91; DL: Drive to boot from (translated, 00h or 80h)
92; ES:BX: Destination buffer for boot sector
93; Returns:
94; AH: INT 13h error code
95; ES:BX: Ptr to boot sector
96; CF: Cleared if read successful
97; Set if any error
98; Corrupts registers:
99; AL, CX, DH
100;--------------------------------------------------------------------
101.LoadFirstSectorFromDLtoESBX:
102 mov ax, 0201h ; Read 1 sector
103 mov cx, 1 ; Cylinder 0, Sector 1
104 xor dh, dh ; Head 0
105 int BIOS_DISK_INTERRUPT_13h
106.Return:
107 ret
Note: See TracBrowser for help on using the repository browser.