1 | ; Project name : XTIDE Universal BIOS |
---|
2 | ; Description : Int 19h BIOS functions (Boot Strap Loader). |
---|
3 | |
---|
4 | ; Section containing code |
---|
5 | SECTION .text |
---|
6 | |
---|
7 | B_READ_RETRY_TIMES EQU 3 ; Number of times to retry |
---|
8 | |
---|
9 | |
---|
10 | ;-------------------------------------------------------------------- |
---|
11 | ; Boots if boot sector is successfully read from the drive. |
---|
12 | ; |
---|
13 | ; Int19h_TryToLoadBootSectorFromDL |
---|
14 | ; Parameters: |
---|
15 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
16 | ; DS: RAMVARS segment |
---|
17 | ; Returns: |
---|
18 | ; ES:BX: Ptr to boot sector (if successfull) |
---|
19 | ; CF: Set if boot sector loaded succesfully |
---|
20 | ; Cleared if failed to load boot sector |
---|
21 | ; Corrupts registers: |
---|
22 | ; AX, CX, DH, DI, (DL if failed to read boot sector) |
---|
23 | ;-------------------------------------------------------------------- |
---|
24 | ALIGN JUMP_ALIGN |
---|
25 | Int19h_TryToLoadBootSectorFromDL: |
---|
26 | call BootPrint_TryToBootFromDL |
---|
27 | call LoadFirstSectorFromDriveDL |
---|
28 | jc SHORT .FailedToLoadFirstSector |
---|
29 | |
---|
30 | test dl, 80h |
---|
31 | jz SHORT .AlwaysBootFromFloppyDriveForBooterGames |
---|
32 | cmp WORD [es:bx+510], 0AA55h ; Valid boot sector? |
---|
33 | jne SHORT .FirstHardDiskSectorNotBootable |
---|
34 | .AlwaysBootFromFloppyDriveForBooterGames: |
---|
35 | mov bx, g_szFound |
---|
36 | call BootPrint_BootSectorResultStringFromBX |
---|
37 | stc |
---|
38 | ret |
---|
39 | .FailedToLoadFirstSector: |
---|
40 | call BootPrint_FailedToLoadFirstSector |
---|
41 | clc |
---|
42 | ret |
---|
43 | .FirstHardDiskSectorNotBootable: |
---|
44 | mov bx, g_szNotFound |
---|
45 | call BootPrint_BootSectorResultStringFromBX |
---|
46 | clc |
---|
47 | ret |
---|
48 | |
---|
49 | ;-------------------------------------------------------------------- |
---|
50 | ; LoadFirstSectorFromDriveDL |
---|
51 | ; Parameters: |
---|
52 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
53 | ; Returns: |
---|
54 | ; AH: INT 13h error code |
---|
55 | ; ES:BX: Ptr to boot sector (if successfull) |
---|
56 | ; CF: Cleared if read successfull |
---|
57 | ; Set if any error |
---|
58 | ; Corrupts registers: |
---|
59 | ; AL, CX, DH, DI |
---|
60 | ;-------------------------------------------------------------------- |
---|
61 | ALIGN JUMP_ALIGN |
---|
62 | LoadFirstSectorFromDriveDL: |
---|
63 | LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to... |
---|
64 | mov bx, BOOTVARS.rgbBootSect ; ...boot sector location |
---|
65 | mov di, B_READ_RETRY_TIMES ; Initialize retry counter |
---|
66 | ALIGN JUMP_ALIGN |
---|
67 | .ReadRetryLoop: |
---|
68 | call .ResetBootDriveFromDL |
---|
69 | call .LoadFirstSectorFromDLtoESBX |
---|
70 | jnc SHORT .Return |
---|
71 | dec di ; Decrement retry counter |
---|
72 | jnz SHORT .ReadRetryLoop ; Loop while retries left |
---|
73 | ALIGN JUMP_ALIGN |
---|
74 | .Return: |
---|
75 | ret |
---|
76 | |
---|
77 | ;-------------------------------------------------------------------- |
---|
78 | ; .ResetBootDriveFromDL |
---|
79 | ; Parameters: |
---|
80 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
81 | ; Returns: |
---|
82 | ; AH: INT 13h error code |
---|
83 | ; CF: Cleared if read successfull |
---|
84 | ; Set if any error |
---|
85 | ; Corrupts registers: |
---|
86 | ; AL |
---|
87 | ;-------------------------------------------------------------------- |
---|
88 | ALIGN JUMP_ALIGN |
---|
89 | .ResetBootDriveFromDL: |
---|
90 | xor ax, ax ; AH=0h, Disk Controller Reset |
---|
91 | test dl, 80h ; Floppy drive? |
---|
92 | eCMOVNZ ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset) |
---|
93 | int INTV_DISK_FUNC |
---|
94 | ret |
---|
95 | |
---|
96 | ;-------------------------------------------------------------------- |
---|
97 | ; Reads first sector (boot sector) from drive DL to ES:BX. |
---|
98 | ; |
---|
99 | ; .LoadFirstSectorFromDLtoESBX |
---|
100 | ; Parameters: |
---|
101 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
102 | ; ES:BX: Destination buffer for boot sector |
---|
103 | ; Returns: |
---|
104 | ; AH: INT 13h error code |
---|
105 | ; ES:BX: Ptr to boot sector |
---|
106 | ; CF: Cleared if read successfull |
---|
107 | ; Set if any error |
---|
108 | ; Corrupts registers: |
---|
109 | ; AL, CX, DH |
---|
110 | ;-------------------------------------------------------------------- |
---|
111 | ALIGN JUMP_ALIGN |
---|
112 | .LoadFirstSectorFromDLtoESBX: |
---|
113 | mov ax, 0201h ; Read 1 sector |
---|
114 | mov cx, 1 ; Cylinder 0, Sector 1 |
---|
115 | xor dh, dh ; Head 0 |
---|
116 | int INTV_DISK_FUNC |
---|
117 | ret |
---|
118 | |
---|
119 | |
---|
120 | ;-------------------------------------------------------------------- |
---|
121 | ; Jumps to boot sector pointed by ES:BX. |
---|
122 | ; |
---|
123 | ; Int19h_JumpToBootSector |
---|
124 | ; Parameters: |
---|
125 | ; DL: Drive to boot from (translated, 00h or 80h) |
---|
126 | ; ES:BX: Ptr to boot sector |
---|
127 | ; Returns: |
---|
128 | ; Never returns |
---|
129 | ;-------------------------------------------------------------------- |
---|
130 | ALIGN JUMP_ALIGN |
---|
131 | Int19h_JumpToBootSector: |
---|
132 | push es ; Push boot sector segment |
---|
133 | push bx ; Push boot sector offset |
---|
134 | call Int19h_ClearSegmentsForBoot |
---|
135 | xor dh, dh ; Device supported by INT 13h |
---|
136 | retf |
---|
137 | |
---|
138 | ;-------------------------------------------------------------------- |
---|
139 | ; Clears DS and ES registers to zero. |
---|
140 | ; |
---|
141 | ; Int19h_ClearSegmentsForBoot |
---|
142 | ; Parameters: |
---|
143 | ; Nothing |
---|
144 | ; Returns: |
---|
145 | ; DS=ES: Zero |
---|
146 | ; Corrupts registers: |
---|
147 | ; AX |
---|
148 | ;-------------------------------------------------------------------- |
---|
149 | ALIGN JUMP_ALIGN |
---|
150 | Int19h_ClearSegmentsForBoot: |
---|
151 | xor ax, ax |
---|
152 | mov ds, ax |
---|
153 | mov es, ax |
---|
154 | ret |
---|