wok view BootProg/stuff/boot32.asm @ rev 25486

debootstrap: update wget_url
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 04 08:52:47 2022 +0000 (18 months ago)
parents 2155b2665e26
children f40d97a52c42
line source
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; ;;
3 ;; "BootProg" Loader v 1.5 by Alexey Frunze (c) 2000-2015 ;;
4 ;; 2-clause BSD license. ;;
5 ;; ;;
6 ;; ;;
7 ;; How to Compile: ;;
8 ;; ~~~~~~~~~~~~~~~ ;;
9 ;; nasm boot32.asm -f bin -o boot32.bin ;;
10 ;; ;;
11 ;; ;;
12 ;; Features: ;;
13 ;; ~~~~~~~~~ ;;
14 ;; - FAT32 supported using BIOS int 13h function 42h (IOW, it will only ;;
15 ;; work with modern BIOSes supporting HDDs bigger than 8 GB) ;;
16 ;; ;;
17 ;; - Loads a 16-bit executable file in the MS-DOS .COM or .EXE format ;;
18 ;; from the root directory of a disk and transfers control to it ;;
19 ;; (the "ProgramName" variable holds the name of the file to be loaded) ;;
20 ;; Its maximum size can be up to 637KB without Extended BIOS Data area. ;;
21 ;; ;;
22 ;; - Prints an error if the file isn't found or couldn't be read ;;
23 ;; ("File not found" or "Read error") ;;
24 ;; and waits for a key to be pressed, then executes the Int 19h ;;
25 ;; instruction and lets the BIOS continue bootstrap. ;;
26 ;; ;;
27 ;; ;;
28 ;; Known Bugs: ;;
29 ;; ~~~~~~~~~~~ ;;
30 ;; - All bugs are fixed as far as I know. The boot sector has been tested ;;
31 ;; on my HDD and an 8GB USB stick. ;;
32 ;; ;;
33 ;; ;;
34 ;; Memory Layout: ;;
35 ;; ~~~~~~~~~~~~~~ ;;
36 ;; The diagram below shows the typical memory layout. The actual location ;;
37 ;; of the boot sector and its stack may be lower than A0000H if the BIOS ;;
38 ;; reserves memory for its Extended BIOS Data Area just below A0000H and ;;
39 ;; reports less than 640 KB of RAM via its Int 12H function. ;;
40 ;; ;;
41 ;; physical address ;;
42 ;; +------------------------+ 00000H ;;
43 ;; | Interrupt Vector Table | ;;
44 ;; +------------------------+ 00400H ;;
45 ;; | BIOS Data Area | ;;
46 ;; +------------------------+ 00500H ;;
47 ;; | PrtScr Status / Unused | ;;
48 ;; +------------------------+ 00600H ;;
49 ;; | Loaded Image | ;;
50 ;; +------------------------+ nnnnnH ;;
51 ;; | Available Memory | ;;
52 ;; +------------------------+ A0000H - 1KB ;;
53 ;; | Boot Sector | ;;
54 ;; +------------------------+ A0000H - 0.5KB ;;
55 ;; | 0.5KB Boot Stack | ;;
56 ;; +------------------------+ A0000H ;;
57 ;; | Video RAM | ;;
58 ;; ;;
59 ;; ;;
60 ;; Boot Image Startup (register values): ;;
61 ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;;
62 ;; ax = 0ffffh (both FCB in the PSP don't have a valid drive identifier), ;;
63 ;; bx = 0, dl = BIOS boot drive number (e.g. 0, 80H) ;;
64 ;; cs:ip = program entry point ;;
65 ;; ss:sp = program stack (don't confuse with boot sector's stack) ;;
66 ;; COM program defaults: cs = ds = es = ss = 50h, sp = 0, ip = 100h ;;
67 ;; EXE program defaults: ds = es = EXE data - 10h (fake MS-DOS psp), ;;
68 ;; cs:ip and ss:sp depends on EXE header ;;
69 ;; Magic numbers: ;;
70 ;; si = 16381 (prime number 2**14-3) ;;
71 ;; di = 32749 (prime number 2**15-19) ;;
72 ;; bp = 65521 (prime number 2**16-15) ;;
73 ;; The magic numbers let the program know whether it has been loaded by ;;
74 ;; this boot sector or by MS-DOS, which may be handy for universal, bare- ;;
75 ;; metal and MS-DOS programs. ;;
76 ;; The command line contains no arguments. ;;
77 ;; ;;
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 %define bx(label) bx+label-boot
81 %define si(label) si+label-boot
82 ExtraBootSector equ 1
83 ClusterMask equ 1 ; +9 bytes
84 NullEntryCheck equ 1 ; +5 bytes
85 CheckAttrib equ 1 ; +6 bytes
86 NonMirroredFATs equ 1 ; +18 bytes
87 ReadRetry equ 1 ; +7 bytes
88 LBA48bits equ 1 ; +15 bytes
89 CHSsupport equ 1 ; +27 bytes max 16MB, 32MB or 8GB
90 CHSupTo32MB equ 1 ; +6 bytes
91 CHSupTo8GB equ 1 ; +14 bytes
92 SectorOf512Bytes equ 0 ; -5 bytes
93 Always2FATs equ 0 ; -4 bytes
95 [BITS 16]
97 ImageLoadSeg equ 60h ; <=07Fh because of "push byte ImageLoadSeg" instructions
98 StackSize equ 512
100 [SECTION .text]
101 [ORG 0]
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 ;; Boot sector starts here ;;
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 boot:
108 DriveNumber equ boot+0
109 HiLBA equ boot+2
110 jmp short start ; MS-DOS/Windows checks for this jump
111 nop
112 bsOemName DB "BootProg" ; 0x03
114 ;;;;;;;;;;;;;;;;;;;;;;
115 ;; BPB1 starts here ;;
116 ;;;;;;;;;;;;;;;;;;;;;;
118 bpbBytesPerSector DW 0 ; 0x0B
119 bpbSectorsPerCluster DB 0 ; 0x0D
120 bpbReservedSectors DW 0 ; 0x0E
121 bpbNumberOfFATs DB 0 ; 0x10
122 bpbRootEntries DW 0 ; 0x11
123 bpbTotalSectors DW 0 ; 0x13
124 bpbMedia DB 0 ; 0x15
125 bpbSectorsPerFAT DW 0 ; 0x16
126 bpbSectorsPerTrack DW 0 ; 0x18
127 bpbHeadsPerCylinder DW 0 ; 0x1A
128 bpbHiddenSectors DD 0 ; 0x1C
129 bpbTotalSectorsBig DD 0 ; 0x20
131 ;;;;;;;;;;;;;;;;;;;;
132 ;; BPB1 ends here ;;
133 ;;;;;;;;;;;;;;;;;;;;
135 ;;;;;;;;;;;;;;;;;;;;;;
136 ;; BPB2 starts here ;;
137 ;;;;;;;;;;;;;;;;;;;;;;
139 bsSectorsPerFAT32 DD 0 ; 0x24
140 bsExtendedFlags DW 0 ; 0x28
141 bsFSVersion DW 0 ; 0x2A
142 bsRootDirectoryClusterNo DD 0 ; 0x2C
143 bsFSInfoSectorNo DW 0 ; 0x30
144 bsBackupBootSectorNo DW 0 ; 0x32
145 bsreserved times 12 DB 0 ; 0x34
146 bsDriveNumber DB 0 ; 0x40
147 bsreserved1 DB 0 ; 0x41
148 bsExtendedBootSignature DB 0 ; 0x42
149 bsVolumeSerialNumber DD 0 ; 0x43
150 bsVolumeLabel times 11 DB " " ; 0x47 "NO NAME "
151 bsFileSystemName times 8 DB " " ; 0x52 "FAT32 "
153 ;;;;;;;;;;;;;;;;;;;;
154 ;; BPB2 ends here ;;
155 ;;;;;;;;;;;;;;;;;;;;
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
158 ;; Boot sector code starts here ;;
159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 start:
162 cld
164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
165 ;; How much RAM is there? ;;
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 int 12h ; get conventional memory size (in KBs)
169 dec ax ; reserve 1K bytes for the code and the stack
170 mov cx, 106h
171 shl ax, cl ; and convert it to 16-byte paragraphs
173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 ;; Reserve memory for the boot sector and its stack ;;
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 mov es, ax ; cs:0 = ds:0 = ss:0 -> top - 512 - StackSize
178 %if ExtraBootSector == 0
179 mov ss, ax
180 mov sp, 512+StackSize ; bytes 0-511 are reserved for the boot code
181 %endif
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
184 ;; Copy ourselves to top of memory ;;
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 mov si, 7C00h
188 xor di, di
189 mov ds, di
190 push es
191 mov [si(DriveNumber)], dx ; store BIOS boot drive number
192 rep movsw
194 ;;;;;;;;;;;;;;;;;;;;;;
195 ;; Jump to the copy ;;
196 ;;;;;;;;;;;;;;;;;;;;;;
198 %if ExtraBootSector != 0
199 push word main
200 %else
201 push byte main
202 %endif
203 push es
204 pop ds
205 retf
207 %if ExtraBootSector != 0
208 %macro MovedCode 0
209 %endif
210 main:
211 xor ebx, ebx
212 %if ExtraBootSector != 0
213 add al, 32
214 mov es, ax
215 mov eax, [bx(bpbHiddenSectors)]
216 inc eax
217 %if LBA48bits != 0
218 mov [bx(HiLBA)], bx
219 %endif
220 call ReadSectorBoot
221 push ds
222 pop ss
223 mov sp, 512+StackSize ; bytes 0-511 are reserved for the boot code
224 %endif
226 %if ClusterMask != 0
227 and byte [bx(bsRootDirectoryClusterNo+3)], 0Fh ; mask cluster value
228 %endif
229 mov esi, [bx(bsRootDirectoryClusterNo)] ; esi=cluster # of root dir
231 push byte ImageLoadSeg
232 pop es
234 RootDirReadContinue:
235 call ReadClusterSector ; read one sector of the root dir
237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
238 ;; Look for the COM/EXE file to load and run ;;
239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
241 xor di, di ; es:di -> root entries array
243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
244 ;; Looks for a file/dir by its name ;;
245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246 ;; Input: DS:SI -> file name (11 chars) ;;
247 ;; ES:DI -> root directory array ;;
248 ;; BP = paragraphs in sector ;;
249 ;; Output: ESI = cluster number ;;
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 FindNameCycle:
253 %if NullEntryCheck != 0
254 cmp byte [es:di], bh
255 je ErrFind ; end of root directory (NULL entry found)
256 %endif
257 pusha
258 mov cl, NameLength
259 mov si, ProgramName ; ds:si -> program name
260 repe cmpsb
261 %if CheckAttrib != 0
262 VolumeLabel equ 8
263 SubDirectory equ 10h
264 jnz SkipFindName
265 test byte [es:di], VolumeLabel+SubDirectory
266 SkipFindName:
267 %endif
268 je FindNameFound
269 popa
270 add di, byte 32
271 dec bp
272 dec bp
273 jnz FindNameCycle ; next root entry
274 loop RootDirReadContinue ; next sector in cluster
275 cmp esi, 0FFFFFF6h ; carry=0 if last cluster, and carry=1 otherwise
276 jnc RootDirReadContinue ; continue to the next root dir cluster
277 ErrFind:
278 call Error ; end of root directory (dir end reached)
279 db "File not found."
280 FindNameFound:
281 push word [es:di+14h-11]
282 push word [es:di+1Ah-11]
283 pop esi ; esi = cluster no. cx = 0
285 dec dword [es:di+1Ch-11] ; load ((n - 1)/256)*16 +1 paragraphs
286 imul di, [es:di+1Ch+1-11], byte 16 ; file size in paragraphs (full pages)
288 ;;;;;;;;;;;;;;;;;;;;;;;;;;
289 ;; Load the entire file ;;
290 ;;;;;;;;;;;;;;;;;;;;;;;;;;
292 push es
293 FileReadContinue:
294 push di
295 call ReadClusterSector ; read one sector of the boot file
296 dec cx
297 mov di, es
298 add di, bp
299 mov es, di ; es:bx updated
300 pop di
302 sub di, bp
303 jae FileReadContinue
304 xor ax, ax
305 pop bp
307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
308 ;; Type detection, .COM or .EXE? ;;
309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
311 mov ds, bp ; bp=ds=seg the file is loaded to
313 add bp, [bx+08h] ; bp = image base
314 mov di, [bx+18h] ; di = reloc table pointer
316 cmp word [bx], 5A4Dh ; "MZ" signature?
317 je RelocateEXE ; yes, it's an EXE program
319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
320 ;; Setup and run a .COM program ;;
321 ;; Set CS=DS=ES=SS SP=0 IP=100h ;;
322 ;; AX=0ffffh BX=0 DX=drive and ;;
323 ;; cmdline=void ;;
324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
326 mov di, 100h ; ip
327 mov bp, ImageLoadSeg-10h ; "org 100h" stuff :)
328 mov ss, bp
329 xor sp, sp
330 push bp ; cs, ds and es
331 jmp short Run
332 %if ExtraBootSector != 0
333 %endm
334 %macro BootFileName 0
335 %endif
337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
338 ;; Relocate, setup and run a .EXE program ;;
339 ;; Set CS:IP, SS:SP, DS, ES and AX according ;;
340 ;; to wiki.osdev.org/MZ#Initial_Program_State ;;
341 ;; AX=0ffffh BX=0 DX=drive cmdline=void ;;
342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
344 ReloCycle:
345 add [di+2], bp ; item seg (abs)
346 les si, [di] ; si = item ofs, es = item seg
347 add [es:si], bp ; fixup
348 scasw ; di += 2
349 scasw ; point to next entry
351 RelocateEXE:
352 dec word [bx+06h] ; reloc items, 32768 max (128KB table)
353 jns ReloCycle
355 les si, [bx+0Eh]
356 add si, bp
357 mov ss, si ; ss for EXE
358 mov sp, es ; sp for EXE
360 lea si, [bp-10h] ; ds and es both point to the segment
361 push si ; containing the PSP structure
363 add bp, [bx+16h] ; cs for EXE
364 mov di, [bx+14h] ; ip for EXE
365 Run:
366 pop ds
367 push bp
368 push di
369 push ds
370 pop es
371 mov [80h], ax ; clear cmdline
372 dec ax ; both FCB in the PSP don't have a valid drive identifier
374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
375 ;; Set the magic numbers so the program knows that it ;;
376 ;; has been loaded by this bootsector and not by MS-DOS ;;
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378 mov si, 16381 ; prime number 2**14-3
379 mov di, 32749 ; prime number 2**15-19
380 mov bp, 65521 ; prime number 2**16-15
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383 ;; All done, transfer control to the program now ;;
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
385 retf
386 %if ExtraBootSector != 0
387 %endm
388 %endif
390 ;;;;;;;;;;;;;;;;;;;;;;;;;;
391 ;; Error Messaging Code ;;
392 ;;;;;;;;;;;;;;;;;;;;;;;;;;
394 Error:
395 pop si
396 puts:
397 mov ah, 0Eh
398 mov bl, 7
399 lodsb
400 int 10h
401 cmp al, '.'
402 jne puts
403 cbw
404 int 16h ; wait for a key...
405 int 19h ; bootstrap
407 Stop:
408 hlt
409 jmp short Stop
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412 ;; Reads a FAT32 sector ;;
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414 ;; Inout: ES:BX -> buffer ;;
415 ;; EAX = prev sector ;;
416 ;; CX = rem sectors in cluster ;;
417 ;; ESI = next cluster ;;
418 ;; Output: EAX = current sector ;;
419 ;; CX = rem sectors in cluster ;;
420 ;; ESI = next cluster ;;
421 ;; BP -> para / sector ;;
422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
424 ReadClusterSector:
425 %if SectorOf512Bytes != 0
426 mov bp, 32 ; bp = paragraphs per sector
427 %else
428 mov bp, [bx(bpbBytesPerSector)]
429 shr bp, 4 ; bp = paragraphs per sector
430 %endif
431 mov dx, 1 ; adjust LBA for next sector
432 inc cx
433 loop ReadSectorLBA
435 mul ebx ; edx:eax = 0
436 %if SectorOf512Bytes != 0
437 mov al, 128 ; ax=# of FAT32 entries per sector
438 %else
439 imul ax, bp, byte 4 ; ax=# of FAT32 entries per sector
440 %endif
441 lea edi, [esi-2] ; esi=cluster #
442 xchg eax, esi
443 div esi ; eax=FAT sector #, edx=entry # in sector
445 imul si, dx, byte 4 ; si=entry # in sector, clear C
446 %if NonMirroredFATs != 0
447 cwde
448 or dl, byte [bx(bsExtendedFlags)]
449 jns MirroredFATs ; Non-mirrored FATs ?
450 and dl, 0Fh
451 imul edx, dword [bx(bsSectorsPerFAT32)] ; we need to read the active one
452 add eax, edx
453 MirroredFATs:
454 cwde
455 %else
456 %if LBA48bits != 0
457 xor dx, dx
458 %endif
459 %endif
460 call ReadSectorLBAfromFAT ; read 1 FAT32 sector
462 %if ClusterMask != 0
463 and byte [es:si+3], 0Fh ; mask cluster value
464 %endif
465 mov esi, [es:si] ; esi=next cluster #
467 %if Always2FATs != 0
468 imul eax, dword [bx(bsSectorsPerFAT32)], 2
469 %else
470 movzx eax, byte [bx(bpbNumberOfFATs)]
471 mul dword [bx(bsSectorsPerFAT32)]
472 %endif
474 xchg eax, edi
475 movzx ecx, byte [bx(bpbSectorsPerCluster)] ; 8..128
476 mul ecx ; edx:eax=sector number in data area
477 add eax, edi
478 %if LBA48bits != 0
479 adc dx, bx
480 %endif
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
483 ;; Reads a sector form the start of FAT ;;
484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
486 ReadSectorLBAfromFAT:
487 add eax, [bx(bpbHiddenSectors)]
488 %if LBA48bits != 0
489 adc dx, bx
490 mov word [bx(HiLBA)], dx
491 %endif
492 mov dx, [bx(bpbReservedSectors)]
494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
495 ;; Reads a sector using BIOS Int 13h fn 42h ;;
496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
497 ;; Input: EAX = LBA ;;
498 ;; CX = sector count ;;
499 ;; ES:BX -> buffer address ;;
500 ;; Output: CF = 0 if no more sectors ;;
501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
503 ReadSectorLBA:
504 add eax, edx
505 %if LBA48bits != 0
506 adc word [bx(HiLBA)], bx
507 %endif
508 ReadSectorBoot:
509 mov dx, [bx(DriveNumber)] ; restore BIOS boot drive number
510 pusha
512 push bx
513 %if LBA48bits != 0
514 push word [bx(HiLBA)] ; 48-bit LBA
515 %else
516 push bx
517 %endif
518 push eax
519 push es
520 push bx
521 push byte 1 ; sector count word = 1
522 push byte 16 ; packet size byte = 16, reserved byte = 0
524 %if CHSsupport != 0
525 %if CHSupTo8GB != 0
526 push eax
527 pop cx ; save low LBA
528 pop ax ; get high LBA
529 cwd ; clear dx (assume LBA offset <1TB)
530 idiv word [bx(bpbSectorsPerTrack)] ; up to 8GB disks, avoid divide error
532 xchg ax, cx ; restore low LBA, save high LBA / SPT
533 %else
534 ; Busybox mkdosfs creates fat32 for floppies.
535 ; Floppies may support CHS only.
536 %if CHSupTo32MB != 0
537 xor dx, dx ; clear dx (LBA offset <32MB)
538 %else
539 cwd ; clear dx (LBA offset <16MB)
540 %endif
541 xor cx, cx ; high LBA / SPT = 0
542 %endif
543 idiv word [bx(bpbSectorsPerTrack)]
544 ; ax = LBA / SPT
545 ; dx = LBA % SPT = sector - 1
546 inc dx
548 xchg cx, dx ; restore high LBA / SPT, save sector no.
549 idiv word [bx(bpbHeadsPerCylinder)]
550 ; ax = (LBA / SPT) / HPC = cylinder
551 ; dx = (LBA / SPT) % HPC = head
553 xchg ch, al ; clear al
554 ; ch = LSB 0...7 of cylinder no.
555 %if CHSupTo8GB != 0 || CHSupTo32MB != 0
556 shr ax, 2
557 or cl, al
558 ; cl = MSB 8...9 of cylinder no. + sector no.
559 %endif
560 mov dh, dl
561 ; dh = head no.
562 mov dl, [bx(DriveNumber)] ; restore BIOS boot drive number
563 %endif
565 ReadSectorRetry:
566 mov si, sp
567 mov ah, 42h ; ah = 42h = extended read function no.
568 int 13h ; extended read sectors (DL, DS:SI)
569 jnc ReadSuccess ; CF = 0 if no error
571 %if CHSsupport != 0
572 mov ax, 201h ; al = sector count = 1
573 ; ah = 2 = read function no.
574 int 13h ; read sectors (AL, CX, DX, ES:BX)
576 jnc ReadSuccess ; CF = 0 if no error
577 %endif
578 %if ReadRetry != 0
579 %if CHSsupport != 0
580 cbw ; ah = 0 = reset function
581 %else
582 xor ax, ax ; ah = 0 = reset function
583 %endif
584 int 13h ; reset drive (DL)
586 dec bp ; up to 32 retries
587 jnz ReadSectorRetry
588 %endif
590 call Error
591 db "Read error."
593 ReadSuccess:
595 popa ; sp += 16
596 popa
597 ret
599 %if ExtraBootSector != 0
600 MovedCode
601 %endif
603 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
604 ;; Fill free space with zeroes ;;
605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
607 times (512-13-($-$$)) db 0
609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
610 ;; Name of the file to load and run ;;
611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
613 NameLength equ 11
614 ProgramName times NameLength db 0 ; name and extension
616 ;;;;;;;;;;;;;;;;;;;;;;;;;;
617 ;; End of the sector ID ;;
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;
620 dw 0AA55h ; BIOS checks for this ID
622 %if ExtraBootSector != 0
623 dd 61415252h ; "RRaA"
624 BootFileName
625 times (996-($-$$)) db 0
626 ; dd 41617272h ; "rrAa"
627 %endif