wok view BootProg/stuff/boot16.asm @ rev 25457

Normazile https://sourceforge.net/projects web_sites
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Sep 23 08:28:09 2022 +0000 (19 months ago)
parents d4a851cd7f09
children 9a714ac859a3
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 boot16.asm -f bin -o boot16.bin ;;
10 ;; ;;
11 ;; ;;
12 ;; Features: ;;
13 ;; ~~~~~~~~~ ;;
14 ;; - FAT12 and FAT16 supported using BIOS int 13h function 42h or 02h. ;;
15 ;; ;;
16 ;; - Loads a 16-bit executable file in the MS-DOS .COM or .EXE format ;;
17 ;; from the root directory of a disk and transfers control to it ;;
18 ;; (the "ProgramName" variable holds the name of the file to be loaded) ;;
19 ;; Its maximum size can be up to 635KB without Extended BIOS Data area. ;;
20 ;; ;;
21 ;; - Prints an error if the file isn't found or couldn't be read ;;
22 ;; ("File not found" or "Read error") ;;
23 ;; and waits for a key to be pressed, then executes the Int 19h ;;
24 ;; instruction and lets the BIOS continue bootstrap. ;;
25 ;; ;;
26 ;; - cpu 8086 is supported ;;
27 ;; ;;
28 ;; ;;
29 ;; Known Bugs: ;;
30 ;; ~~~~~~~~~~~ ;;
31 ;; - All bugs are fixed as far as I know. The boot sector has been tested ;;
32 ;; on the following types of diskettes (FAT12): ;;
33 ;; - 360KB 5"25 ;;
34 ;; - 1.2MB 5"25 ;;
35 ;; - 1.44MB 3"5 ;;
36 ;; on my HDD (FAT16). ;;
37 ;; ;;
38 ;; ;;
39 ;; Memory Layout: ;;
40 ;; ~~~~~~~~~~~~~~ ;;
41 ;; The diagram below shows the typical memory layout. The actual location ;;
42 ;; of the boot sector and its stack may be lower than A0000H if the BIOS ;;
43 ;; reserves memory for its Extended BIOS Data Area just below A0000H and ;;
44 ;; reports less than 640 KB of RAM via its Int 12H function. ;;
45 ;; ;;
46 ;; physical address ;;
47 ;; +------------------------+ 00000H ;;
48 ;; | Interrupt Vector Table | ;;
49 ;; +------------------------+ 00400H ;;
50 ;; | BIOS Data Area | ;;
51 ;; +------------------------+ 00500H ;;
52 ;; | PrtScr Status / Unused | ;;
53 ;; +------------------------+ 00600H ;;
54 ;; | Loaded Image | ;;
55 ;; +------------------------+ nnnnnH ;;
56 ;; | Available Memory | ;;
57 ;; +------------------------+ A0000H - 512 - 3KB ;;
58 ;; | Boot Sector | ;;
59 ;; +------------------------+ A0000H - 3KB ;;
60 ;; | 3KB Boot Stack | ;;
61 ;; +------------------------+ A0000H ;;
62 ;; | Video RAM | ;;
63 ;; ;;
64 ;; ;;
65 ;; Boot Image Startup (register values): ;;
66 ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;;
67 ;; ax = 0ffffh (both FCB in the PSP don't have a valid drive identifier), ;;
68 ;; bx = 0, dl = BIOS boot drive number (e.g. 0, 80H) ;;
69 ;; cs:ip = program entry point ;;
70 ;; ss:sp = program stack (don't confuse with boot sector's stack) ;;
71 ;; COM program defaults: cs = ds = es = ss = 50h, sp = 0, ip = 100h ;;
72 ;; EXE program defaults: ds = es = EXE data - 10h (fake MS-DOS psp), ;;
73 ;; cs:ip and ss:sp depends on EXE header ;;
74 ;; Magic numbers: ;;
75 ;; si = 16381 (prime number 2**14-3) ;;
76 ;; di = 32749 (prime number 2**15-19) ;;
77 ;; bp = 65521 (prime number 2**16-15) ;;
78 ;; The magic numbers let the program know whether it has been loaded by ;;
79 ;; this boot sector or by MS-DOS, which may be handy for universal, bare- ;;
80 ;; metal and MS-DOS programs. ;;
81 ;; The command line contains no arguments. ;;
82 ;; ;;
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 %define bx(label) bx+label-boot
86 %define si(label) si+label-boot
87 NullEntryCheck equ 1 ; +3 bytes
88 ReadRetry equ 1 ; +9 bytes
89 LBAsupport equ 1 ; +16 bytes
90 Over2GB equ 1 ; +5 bytes
91 GeometryCheck equ 1 ; +18 bytes
93 [BITS 16]
94 [CPU 8086]
96 ImageLoadSeg equ 60h
97 StackSize equ 3072 ; Stack + cluster list
99 [SECTION .text]
100 [ORG 0]
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;; Boot sector starts here ;;
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 boot:
107 DriveNumber:
108 jmp short start ; MS-DOS/Windows checks for this jump
109 nop
110 bsOemName DB "BootProg" ; 0x03
112 ;;;;;;;;;;;;;;;;;;;;;
113 ;; BPB starts here ;;
114 ;;;;;;;;;;;;;;;;;;;;;
116 bpbBytesPerSector DW 0 ; 0x0B
117 bpbSectorsPerCluster DB 0 ; 0x0D
118 bpbReservedSectors DW 0 ; 0x0E
119 bpbNumberOfFATs DB 0 ; 0x10
120 bpbRootEntries DW 0 ; 0x11
121 bpbTotalSectors DW 0 ; 0x13
122 bpbMedia DB 0 ; 0x15
123 bpbSectorsPerFAT DW 0 ; 0x16
124 bpbSectorsPerTrack DW 0 ; 0x18
125 bpbHeadsPerCylinder DW 0 ; 0x1A
126 bpbHiddenSectors DD 0 ; 0x1C
127 bpbTotalSectorsBig DD 0 ; 0x20
129 ;;;;;;;;;;;;;;;;;;;
130 ;; BPB ends here ;;
131 ;;;;;;;;;;;;;;;;;;;
133 bsDriveNumber DB 0 ; 0x24
134 bsUnused DB 0 ; 0x25
135 bsExtBootSignature DB 0 ; 0x26
136 bsSerialNumber DD 0 ; 0x27
137 bsVolumeLabel DB "NO NAME " ; 0x2B
138 bsFileSystem DB "FAT12 " ; 0x36
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;; Boot sector code starts here ;;
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144 start:
145 cld
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
148 ;; How much RAM is there? ;;
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 int 12h ; get conventional memory size (in KBs)
152 mov cx, 106h
153 shl ax, cl ; and convert it to 16-byte paragraphs
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 ;; Reserve memory for the boot sector and its stack ;;
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 sub ax, (512+StackSize) /16 ; reserve bytes for the code and the stack
160 mov es, ax ; cs:0 = ds:0 = ss:0 -> top - 512 - StackSize
161 mov ss, ax
162 mov sp, 512+StackSize ; bytes 0-511 are reserved for the boot code
164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
165 ;; Copy ourselves to top of memory ;;
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 mov si, 7C00h
169 xor di, di
170 mov ds, di
171 push es
172 mov [si(DriveNumber)], dx ; store BIOS boot drive number
173 rep movsw ; move 512 bytes (+ 12)
175 ;;;;;;;;;;;;;;;;;;;;;;
176 ;; Jump to the copy ;;
177 ;;;;;;;;;;;;;;;;;;;;;;
179 mov cl, byte main
180 push cx
181 retf
183 main:
184 %if ImageLoadSeg != main-boot
185 %if ImageLoadSeg >= 100h
186 mov cx, ImageLoadSeg
187 %else
188 mov cl, ImageLoadSeg
189 %endif
190 %endif
191 push cx
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;
194 ;; Get drive parameters ;;
195 ;; Update heads count ;;
196 ;; for current BIOS ;;
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;
199 %if GeometryCheck != 0
200 mov ah, 8
201 int 13h ; may destroy SI,BP, and DS registers
202 %endif
203 ; update AX,BL,CX,DX,DI, and ES registers
204 push cs
205 pop ds
206 xor bx, bx
208 %if GeometryCheck != 0
209 and cx, byte 3Fh
210 cmp [bx(bpbSectorsPerTrack)], cx
211 jne BadParams ; verify updated and validity
212 mov al, dh
213 inc ax
214 mov [bpbHeadsPerCylinder], ax
215 BadParams:
216 %endif
218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219 ;; Load FAT (FAT12: 6KB max, FAT16: 128KB max) ;;
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 pop es ; ImageLoadSeg
223 push es
225 mul bx ; dx:ax = 0 = LBA (LBA are relative to FAT)
226 mov cx, word [bx(bpbSectorsPerFAT)]
228 call ReadCXSectors ; read fat and clear ax & cx; bp = SectorsPerFAT
230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231 ;; load the root directory in ;;
232 ;; its entirety (16KB max) ;;
233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
235 mov al, 32
237 mul word [bx(bpbRootEntries)]
238 div word [bx(bpbBytesPerSector)]
239 xchg ax, cx ; cx = root directory size in sectors, clear ax
241 mov al, [bpbNumberOfFATs]
242 mul bp ; [bx(bpbSectorsPerFAT)], set by ReadCXSectors
244 push es ; read root directory
245 call ReadCXSectors ; clear ax, cx & di; bp = first data sector
246 pop es
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 ;; Look for the COM/EXE file to load and run ;;
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 ; es:di -> root entries array
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
255 ;; Looks for the file/dir ProgramName ;;
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;; Input: ES:DI -> root directory array ;;
258 ;; Output: SI = cluster number ;;
259 ;; AX = file sector count ;;
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 FindNameCycle:
263 push di
264 mov cl, NameLength
265 mov si, ProgramName ; ds:si -> program name
266 repe cmpsb
267 pop di
268 je FindNameFound
269 %if NullEntryCheck != 0
270 scasb
271 je FindNameFailed ; end of root directory (NULL entry found)
272 add di, byte 31
273 %else
274 add di, byte 32
275 %endif
276 dec word [bx(bpbRootEntries)]
277 jnz FindNameCycle ; next root entry
279 FindNameFailed:
280 call Error
281 db "File not found."
283 FindNameFound:
284 push si
285 mov si, [es:di+1Ah] ; si = cluster no.
286 les ax, [es:di+1Ch] ; file size
287 mov dx, es
288 div word [bx(bpbBytesPerSector)]
289 cmp bx, dx ; sector aligned ?
290 adc ax, bx ; file last sector
291 pop di ; di = ClusterList
293 pop es ; ImageLoadSeg
294 push ax
296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
297 ;; build cluster list ;;
298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
299 ;; Input: ES:0 -> FAT ;;
300 ;; SI = first cluster ;;
301 ;; DI = cluster list :;
302 ;; CH = 0 ;;
303 ;; Output: SI = cluster list ;;
304 ;; CH = 0 ;;
305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
307 FAT12 equ 1
308 FAT16 equ 1
309 TINYFAT16 equ 1
310 push di ; up to 2 * 635K / BytesPerCluster = 2540 bytes
311 %if FAT12 == 1
312 mov cl, 12
313 %endif
314 ClusterLoop:
315 mov [di], si
316 add si, si ; si = cluster * 2
317 %if FAT16 == 1
318 mov ax, es ; ax = FAT segment = ImageLoadSeg
319 jnc First64k
320 mov ah, (1000h+ImageLoadSeg)>>8 ; adjust segment for 2nd part of FAT16
321 First64k:
322 %if FAT12 == 1
323 mov dx, 0FFF6h
324 %if TINYFAT16 == 1
325 test [bx(bsFileSystem+4)], cl ; FAT12 or FAT16 ? clear C
326 %else
327 cmp [bx(bpbSectorsPerFAT)], cx ; 1..12 = FAT12, 16..256 = FAT16
328 %endif
329 jne ReadClusterFat16
330 mov dh, 0Fh
331 %endif
332 %endif
333 %if FAT12 == 1
334 add si, [di]
335 shr si, 1 ; si = cluster * 3 / 2
336 %endif
337 %if FAT16 == 1
338 ReadClusterFat16:
339 push ds
340 mov ds, ax
341 lodsw ; ax = next cluster
342 pop ds
343 %else
344 es lodsw
345 %endif
346 %if FAT12 == 1
347 jnc ReadClusterEven
348 rol ax, cl
349 ReadClusterEven:
350 scasw ; di += 2
351 %if FAT16 == 1
352 and ah, dh ; mask cluster value
353 cmp ax, dx
354 %else
355 and ah, 0Fh ; mask cluster value
356 cmp ax, 0FF6h
357 %endif
358 %else
359 scasw ; di += 2
360 cmp ax, 0FFF6h
361 %endif
362 xchg ax, si
363 jc ClusterLoop
364 pop si
365 pop di ; file size in sectors
367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
368 ;; Load the entire file ;;
369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
370 ;; Input: ES:0 -> buffer ;;
371 ;; SI = cluster list ;;
372 ;; DI = file sectors ;;
373 ;; CH = 0 ;;
374 ;; BP = 1st data sec ;;
375 ;; Output: BP:0 -> buffer ;;
376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378 push es
380 ReadClusters:
381 lodsw
382 dec ax
383 dec ax
385 mov cl, [bx(bpbSectorsPerCluster)] ; 1..128
386 mul cx ; cx = sector count (ch = 0)
388 add ax, bp ; LBA for cluster data
389 adc dx, bx ; dx:ax = LBA
391 call ReadSector ; clear ax, restore dx
393 jne ReadClusters
395 pop bp ; ImageLoadSeg
397 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
398 ;; Type detection, .COM or .EXE? ;;
399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
401 mov ds, bp ; bp=ds=seg the file is loaded to
403 add bp, [bx+08h] ; bp = image base
404 mov di, [bx+18h] ; di = reloc table pointer
406 cmp word [bx], 5A4Dh ; "MZ" signature?
407 je RelocateEXE ; yes, it's an EXE program
409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410 ;; Setup and run a .COM program ;;
411 ;; Set CS=DS=ES=SS SP=0 IP=100h ;;
412 ;; AX=0ffffh BX=0 DX=drive and ;;
413 ;; cmdline=void ;;
414 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
416 mov di, 100h ; ip
417 mov bp, ImageLoadSeg-10h ; "org 100h" stuff :)
418 mov ss, bp
419 xor sp, sp
420 push bp ; cs, ds and es
421 jmp short Run
423 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
424 ;; Relocate, setup and run a .EXE program ;;
425 ;; Set CS:IP, SS:SP, DS, ES and AX according ;;
426 ;; to wiki.osdev.org/MZ#Initial_Program_State ;;
427 ;; AX=0ffffh BX=0 DX=drive cmdline=void ;;
428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
430 ReloCycle:
431 add [di+2], bp ; item seg (abs)
432 les si, [di] ; si = item ofs, es = item seg
433 add [es:si], bp ; fixup
434 scasw ; di += 2
435 scasw ; point to next entry
437 RelocateEXE:
438 dec word [bx+06h] ; reloc items, 32768 max (128KB table)
439 jns ReloCycle
440 ; PSP don't have a valid drive identifier
441 les si, [bx+0Eh]
442 add si, bp
443 mov ss, si ; ss for EXE
444 mov sp, es ; sp for EXE
446 lea si, [bp-10h] ; ds and es both point to the segment
447 push si ; containing the PSP structure
449 add bp, [bx+16h] ; cs for EXE
450 mov di, [bx+14h] ; ip for EXE
451 Run:
452 pop ds
453 push bp
454 push di
455 push ds
456 pop es
457 mov [80h], ax ; clear cmdline
458 dec ax ; both FCB in the PSP don't have a valid drive identifier
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 ;; Set the magic numbers so the program knows that it ;;
462 ;; has been loaded by this bootsector and not by MS-DOS ;;
463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
464 mov si, 16381 ; prime number 2**14-3
465 mov di, 32749 ; prime number 2**15-19
466 mov bp, 65521 ; prime number 2**16-15
468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
469 ;; All done, transfer control to the program now ;;
470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
471 retf
473 ReadCXSectors:
474 mov bp, cx
475 add bp, ax ; adjust LBA for cluster data
477 mov di, cx ; no file size limit
479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
480 ;; Reads sectors using BIOS Int 13h ;;
481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
482 ;; Input: DX:AX = LBA relative to FAT ;;
483 ;; BX = 0 ;;
484 ;; CX = sector count ;;
485 ;; DI = file sectors ;;
486 ;; ES:BX -> buffer address ;;
487 ;; Output: ES:BX -> next address ;;
488 ;; BX = 0 ;;
489 ;; CX or DI = 0 ;;
490 ;; DL = drive number ;;
491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
493 ReadSector:
494 add ax, [bx(bpbHiddenSectors)]
495 adc dx, [bx(bpbHiddenSectors)+2]
496 add ax, [bx(bpbReservedSectors)]
498 push si
499 ReadSectorNext:
500 adc dx, bx
501 push di
502 push cx
504 %if LBAsupport != 0
505 push bx
506 push bx
507 %endif
508 push dx ; 32-bit LBA: up to 2TB
509 push ax
510 push es
511 %if ReadRetry != 0 || LBAsupport != 0
512 mov di, 16 ; packet size byte = 16, reserved byte = 0
513 %endif
514 %if LBAsupport != 0
515 push bx
516 inc bx ; sector count word = 1
517 push bx
518 dec bx
519 push di
520 %endif
522 %if Over2GB != 0
523 xchg ax, cx ; save low LBA
524 xchg ax, dx ; get high LBA
525 cwd ; clear dx (LBA offset <1TB)
526 idiv word [bx(bpbSectorsPerTrack)] ; up to 8GB disks
528 xchg ax, cx ; restore low LBA, save high LBA / SPT
529 %else
530 xor cx, cx ; up to 2GB disks otherwise divide error interrupt !
531 %endif
532 idiv word [bx(bpbSectorsPerTrack)]
533 ; ax = LBA / SPT
534 ; dx = LBA % SPT = sector - 1
535 inc dx
537 xchg cx, dx ; restore high LBA / SPT, save sector no.
538 idiv word [bx(bpbHeadsPerCylinder)]
539 ; ax = (LBA / SPT) / HPC = cylinder
540 ; dx = (LBA / SPT) % HPC = head
541 mov ch, al
542 ; ch = LSB 0...7 of cylinder no.
543 mov al, 64
544 mul ah
545 or cl, al
546 ; cl = MSB 8...9 of cylinder no. + sector no.
547 mov dh, dl
548 ; dh = head no.
550 ReadSectorRetry:
551 mov dl, [bx(DriveNumber)]
552 ; dl = drive no.
553 mov si, sp
554 %if LBAsupport != 0
555 mov ah, 42h ; ah = 42h = extended read function no.
556 int 13h ; extended read sectors (DL, DS:SI)
557 jnc ReadSectorNextSegment
558 %endif
560 mov ax, 201h ; al = sector count = 1
561 ; ah = 2 = read function no.
562 int 13h ; read sectors (AL, CX, DX, ES:BX)
564 jnc ReadSectorNextSegment
565 %if ReadRetry != 0
566 cbw ; ah = 0 = reset function
567 int 13h ; reset drive (DL)
569 dec di
570 jnz ReadSectorRetry ; up to 15 extra attempt
571 %endif
573 call Error
574 db "Read error."
576 ReadSectorNextSegment:
578 %if LBAsupport != 0
579 pop ax ; al = 16
580 mul byte [bx(bpbBytesPerSector)+1] ; = (bpbBytesPerSector/256)*16
581 pop cx ; sector count = 1
582 pop bx
583 add [si+6], ax ; adjust segment for next sector
584 %else
585 mov al, 16
586 mul byte [bx(bpbBytesPerSector)+1] ; = (bpbBytesPerSector/256)*16
587 add [si], ax ; adjust segment for next sector
588 %endif
589 pop es ; es:0 updated
590 pop ax
591 pop dx
592 %if LBAsupport != 0
593 pop di
594 pop di
595 add ax, cx ; adjust LBA for next sector
596 %else
597 add ax, 1 ; adjust LBA for next sector
598 %endif
600 pop cx ; cluster sectors to read
601 pop di ; file sectors to read
602 dec di ; keep C
603 loopne ReadSectorNext ; until cluster sector count or file sector count
604 pop si
605 mov ax, bx ; clear ax
606 mov dx, [bx(DriveNumber)] ; pass the BIOS boot drive to Run or Error
608 ret
610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
611 ;; Fill free space with zeroes ;;
612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
614 times (512-13-20-($-$$)) db 0
616 ;;;;;;;;;;;;;;;;;;;;;;;;;;
617 ;; Error Messaging Code ;;
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;
620 Error:
621 pop si
623 PutStr:
624 mov ah, 0Eh
625 mov bl, 7
626 lodsb
627 int 10h
628 cmp al, "."
629 jne PutStr
631 cbw
632 int 16h ; wait for a key...
633 int 19h ; bootstrap
635 Stop:
636 hlt
637 jmp short Stop
639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
640 ;; Name of the file to load and run ;;
641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
643 ProgramName db "STARTUP BIN" ; name and extension each must be
644 times (510-($-$$)) db ' ' ; padded with spaces (11 bytes total)
645 NameLength equ $-ProgramName
647 ;;;;;;;;;;;;;;;;;;;;;;;;;;
648 ;; End of the sector ID ;;
649 ;;;;;;;;;;;;;;;;;;;;;;;;;;
651 ClusterList dw 0AA55h ; BIOS checks for this ID