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

BootProg/boot16.asm: too small fat16 support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Sep 17 08:17:46 2022 +0000 (19 months ago)
parents e3609bca2577
children 78727b04c002
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 = cx = 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
245 call ReadCXSectors ; read root directory; 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, 11
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 push di ; up to 2 * 635K / BytesPerCluster = 2540 bytes
310 %if FAT12 == 1
311 mov cl, 4
312 %endif
313 ClusterLoop:
314 mov [di], si
315 add si, si ; si = cluster * 2
316 %if FAT16 == 1
317 mov ax, es ; ax = FAT segment = ImageLoadSeg
318 jnc First64k
319 mov ah, (1000h+ImageLoadSeg)>>8 ; adjust segment for 2nd part of FAT16
320 First64k:
321 %if FAT12 == 1
322 mov dx, 0FFF8h
323 test [bx(bsFileSystem+4)], cl ; FAT12 or FAT16 ? clear C
324 jne ReadClusterFat16
325 mov dh, 0Fh
326 %endif
327 %endif
328 %if FAT12 == 1
329 add si, [di]
330 shr si, 1 ; si = cluster * 3 / 2
331 %endif
332 %if FAT16 == 1
333 ReadClusterFat16:
334 push ds
335 mov ds, ax
336 lodsw ; ax = next cluster
337 pop ds
338 %else
339 es lodsw
340 %endif
341 %if FAT12 == 1
342 jnc ReadClusterEven
343 shr ax, cl
344 ReadClusterEven:
345 %endif
346 scasw ; di += 2
347 %if FAT12 == 1 && FAT16 == 1
348 and ah, dh ; mask cluster value
349 cmp ax, dx
350 %else
351 %if FAT12 == 1
352 and ah, 0Fh ; mask cluster value
353 cmp ax, 0FF8h
354 %else
355 cmp ax, 0FFF8h
356 %endif
357 %endif
359 xchg ax, si
360 jc ClusterLoop
361 pop si
362 pop di ; file size in sectors
364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365 ;; Load the entire file ;;
366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
367 ;; Input: ES:0 -> buffer ;;
368 ;; SI = cluster list ;;
369 ;; DI = file sectors ;;
370 ;; CH = 0 ;;
371 ;; BP = 1st data sec ;;
372 ;; Output: BP:0 -> buffer ;;
373 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
375 push es
377 ReadClusters:
378 lodsw
379 dec ax
380 dec ax
382 mov cl, [bx(bpbSectorsPerCluster)]
383 mul cx ; cx = sector count (ch = 0)
385 add ax, bp ; LBA for cluster data
386 adc dx, bx ; dx:ax = LBA
388 call ReadSector ; clear ax & cx, restore dx
390 jne ReadClusters
392 pop bp ; ImageLoadSeg
394 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
395 ;; Type detection, .COM or .EXE? ;;
396 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
398 mov ds, bp ; bp=ds=seg the file is loaded to
400 add bp, [bx+08h] ; bp = image base
401 mov di, [bx+18h] ; di = reloc table pointer
403 cmp word [bx], 5A4Dh ; "MZ" signature?
404 je RelocateEXE ; yes, it's an EXE program
406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
407 ;; Setup and run a .COM program ;;
408 ;; Set CS=DS=ES=SS SP=0 IP=100h ;;
409 ;; AX=0ffffh BX=0 CX=0 DX=drive ;;
410 ;; and cmdline=void ;;
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
413 mov di, 100h ; ip
414 mov bp, ImageLoadSeg-10h ; "org 100h" stuff :)
415 mov ss, bp
416 xor sp, sp
417 push bp ; cs, ds and es
418 jmp short Run
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
421 ;; Relocate, setup and run a .EXE program ;;
422 ;; Set CS:IP, SS:SP, DS, ES and AX according ;;
423 ;; to wiki.osdev.org/MZ#Initial_Program_State ;;
424 ;; AX=0ffffh BX=0 CX=0 DX=drive cmdline=void ;;
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
427 ReloCycle:
428 add [di+2], bp ; item seg (abs)
429 les si, [di] ; si = item ofs, es = item seg
430 add [es:si], bp ; fixup
431 scasw ; di += 2
432 scasw ; point to next entry
434 RelocateEXE:
435 dec word [bx+06h] ; reloc items, 32768 max (128KB table)
436 jns ReloCycle
437 ; PSP don't have a valid drive identifier
438 les si, [bx+0Eh]
439 add si, bp
440 mov ss, si ; ss for EXE
441 mov sp, es ; sp for EXE
443 lea si, [bp-10h] ; ds and es both point to the segment
444 push si ; containing the PSP structure
446 add bp, [bx+16h] ; cs for EXE
447 mov di, [bx+14h] ; ip for EXE
448 Run:
449 pop ds
450 push bp
451 push di
452 push ds
453 pop es
454 mov [80h], ax ; clear cmdline
455 dec ax ; both FCB in the PSP don't have a valid drive identifier
457 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
458 ;; Set the magic numbers so the program knows that it ;;
459 ;; has been loaded by this bootsector and not by MS-DOS ;;
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 mov si, 16381 ; prime number 2**14-3
462 mov di, 32749 ; prime number 2**15-19
463 mov bp, 65521 ; prime number 2**16-15
465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
466 ;; All done, transfer control to the program now ;;
467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
468 retf
470 ReadCXSectors:
471 mov bp, cx
472 add bp, ax ; adjust LBA for cluster data
474 mov di, cx ; no file size limit
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
477 ;; Reads sectors using BIOS Int 13h ;;
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
479 ;; Input: DX:AX = LBA relative to FAT ;;
480 ;; BX = 0 ;;
481 ;; CX = sector count ;;
482 ;; DI = file sectors ;;
483 ;; ES:BX -> buffer address ;;
484 ;; Output: ES:BX -> next address ;;
485 ;; BX = 0 ;;
486 ;; CX or DI = 0 ;;
487 ;; DL = drive number ;;
488 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
490 ReadSector:
491 add ax, [bx(bpbHiddenSectors)]
492 adc dx, [bx(bpbHiddenSectors)+2]
493 add ax, [bx(bpbReservedSectors)]
495 push si
496 ReadSectorNext:
497 adc dx, bx
498 push di
499 push cx
501 %if LBAsupport != 0
502 push bx
503 push bx
504 %endif
505 push dx ; 32-bit LBA: up to 2TB
506 push ax
507 push es
508 %if ReadRetry != 0 || LBAsupport != 0
509 mov di, 16 ; packet size byte = 16, reserved byte = 0
510 %endif
511 %if LBAsupport != 0
512 push bx
513 inc bx ; sector count word = 1
514 push bx
515 dec bx
516 push di
517 %endif
519 %if Over2GB != 0
520 xchg ax, cx ; save low LBA
521 xchg ax, dx ; get high LBA
522 cwd ; clear dx (LBA offset <1TB)
523 idiv word [bx(bpbSectorsPerTrack)] ; up to 8GB disks
525 xchg ax, cx ; restore low LBA, save high LBA / SPT
526 %else
527 xor cx, cx ; up to 2GB disks otherwise divide error interrupt !
528 %endif
529 idiv word [bx(bpbSectorsPerTrack)]
530 ; ax = LBA / SPT
531 ; dx = LBA % SPT = sector - 1
532 inc dx
534 xchg cx, dx ; restore high LBA / SPT, save sector no.
535 idiv word [bx(bpbHeadsPerCylinder)]
536 ; ax = (LBA / SPT) / HPC = cylinder
537 ; dx = (LBA / SPT) % HPC = head
538 mov ch, al
539 ; ch = LSB 0...7 of cylinder no.
540 mov al, 64
541 mul ah
542 or cl, al
543 ; cl = MSB 8...9 of cylinder no. + sector no.
544 mov dh, dl
545 ; dh = head no.
547 ReadSectorRetry:
548 mov dl, [bx(DriveNumber)]
549 ; dl = drive no.
550 mov si, sp
551 %if LBAsupport != 0
552 mov ah, 42h ; ah = 42h = extended read function no.
553 int 13h ; extended read sectors (DL, DS:SI)
554 jnc ReadSectorNextSegment
555 %endif
557 mov ax, 201h ; al = sector count = 1
558 ; ah = 2 = read function no.
559 int 13h ; read sectors (AL, CX, DX, ES:BX)
561 jnc ReadSectorNextSegment
562 %if ReadRetry != 0
563 cbw ; ah = 0 = reset function
564 int 13h ; reset drive (DL)
566 dec di
567 jnz ReadSectorRetry ; extra attempt
568 %endif
570 call Error
571 db "Read error."
573 ReadSectorNextSegment:
575 %if LBAsupport != 0
576 pop ax ; al = 16
577 mul byte [bx(bpbBytesPerSector)+1] ; = (bpbBytesPerSector/256)*16
578 pop cx ; sector count = 1
579 pop bx
580 add [si+6], ax ; adjust segment for next sector
581 %else
582 mov al, 16
583 mul byte [bx(bpbBytesPerSector)+1] ; = (bpbBytesPerSector/256)*16
584 add [si], ax ; adjust segment for next sector
585 %endif
586 pop es ; es:0 updated
587 pop ax
588 pop dx
589 %if LBAsupport != 0
590 pop di
591 pop di
592 add ax, cx ; adjust LBA for next sector
593 %else
594 add ax, 1 ; adjust LBA for next sector
595 %endif
597 pop cx ; cluster sectors to read
598 pop di ; file sectors to read
599 dec di ; keep C
600 loopne ReadSectorNext ; until cluster sector count or file sector count is reached
601 pop si
602 mov ax, bx ; clear ax
603 mov dx, [bx(DriveNumber)] ; pass the BIOS boot drive to Run or Error
605 ret
607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
608 ;; Fill free space with zeroes ;;
609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
611 times (512-13-20-($-$$)) db 0
613 ;;;;;;;;;;;;;;;;;;;;;;;;;;
614 ;; Error Messaging Code ;;
615 ;;;;;;;;;;;;;;;;;;;;;;;;;;
617 Error:
618 pop si
620 PutStr:
621 mov ah, 0Eh
622 mov bl, 7
623 lodsb
624 int 10h
625 cmp al, "."
626 jne PutStr
628 cbw
629 int 16h ; wait for a key...
630 int 19h ; bootstrap
632 Stop:
633 hlt
634 jmp short Stop
636 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
637 ;; Name of the file to load and run ;;
638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
640 ProgramName db "STARTUP BIN" ; name and extension each must be
641 times (510-($-$$)) db ' ' ; padded with spaces (11 bytes total)
643 ;;;;;;;;;;;;;;;;;;;;;;;;;;
644 ;; End of the sector ID ;;
645 ;;;;;;;;;;;;;;;;;;;;;;;;;;
647 ClusterList dw 0AA55h ; BIOS checks for this ID