📄 boot.lst
字号:
442
443 ; readDisk: Reads a number of sectors into memory.
444 ;
445 ; Call with: DX:AX = 32-bit DOS sector number
446 ; DI = number of sectors to read
447 ; ES:BX = destination buffer
448 ; ES must be 64k aligned (1000h, 2000h etc).
449 ;
450 ; Returns: CF set on error
451 ; ES:BX points one byte after the last byte read.
452
453 015E readDisk proc
454 015E 56 push si
455 015F 52 read_next: push dx
456 0160 50 push ax
457
458 ;
459 ; translate sector number to BIOS parameters
460 ;
461
462 ;
463 ; abs = sector offset in track
464 ; + head * sectPerTrack offset in cylinder
465 ; + track * sectPerTrack * nHeads offset in platter
466 ;
467 ; t1 = abs / sectPerTrack (ax has t1)
468 ; sector = abs mod sectPerTrack (cx has sector)
469 ;
470 0161 F7 76 18 div word ptr sectPerTrack
471 0164 8B CA mov cx, dx
472
473 ;
474 ; t1 = head + track * nHeads
475 ;
476 ; track = t1 / nHeads (ax has track)
477 ; head = t1 mod nHeads (dl has head)
478 ;
479 0166 33 D2 xor dx, dx
480 0168 F7 76 1A div word ptr nHeads
481
482 ; the following manipulations are necessary in order to
483 ; properly place parameters into registers.
484 ; ch = cylinder number low 8 bits
485 ; cl = 7-6: cylinder high two bits
486 ; 5-0: sector
487 016B 8A F2 mov dh, dl ; save head into dh for bios
488 016D D0 CC ror ah, 1 ; move track high bits into
489 016F D0 CC ror ah, 1 ; bits 7-6 (assumes top = 0)
490 0171 86 C4 xchg al, ah ; swap for later
491 0173 8A 56 18 mov dl, byte ptr sectPerTrack
492 0176 2A D1 sub dl, cl
493 0178 FE C1 inc cl ; sector offset from 1
494 017A 0B C8 or cx, ax ; merge cylinder into sector
495 017C 8A C2 mov al, dl ; al has # of sectors left
Turbo Assembler Version 3.1 04/11/13 12:54:48 Page 10
boot.ASM
496
497 ; Calculate how many sectors can be transfered in this read
498 ; due to dma boundary conditions.
499 017E 52 push dx
500
501 017F 8B F7 mov si, di ; temp register save
502 ; this computes remaining bytes because of modulo 65536
503 ; nature of dma boundary condition
504 0181 8B C3 mov ax, bx ; get offset pointer
505 0183 F7 D8 neg ax ; and convert to bytes
506 0185 74 0B jz ax_min_1 ; started at seg:0, skip ahead
507
508 0187 33 D2 xor dx, dx ; convert to sectors
509 0189 F7 76 0B div word ptr bytesPerSector
510
511 018C 3B C7 cmp ax, di ; check remainder vs. asked
512 018E 72 02 jb ax_min_1 ; less, skip ahead
513 0190 8B F0 mov si, ax ; transfer only what we can
514
515 0192 5A ax_min_1: pop dx
516
517 ; Check that request sectors do not exceed track boundary
518 0193 8B 76 18 mov si, sectPerTrack
519 0196 46 inc si
520 0197 8B C1 mov ax, cx ; get the sector/cyl byte
521 0199 25 003F and ax, 03fh ; and mask out sector
522 019C 2B F0 sub si, ax ; si has how many we can read
523 019E 8B C7 mov ax, di
524 01A0 3B F7 cmp si, di ; see if asked <= available
525 01A2 7D 02 jge ax_min_2
526 01A4 8B C6 mov ax, si ; get what can be xfered
527
528 01A6 BE 0005 ax_min_2: mov si, RETRYCOUNT
529 01A9 B4 02 mov ah, 2
530 01AB 8A 56 24 mov dl, drive
531
532 01AE 50 retry: push ax
533 01AF CD 13 int 13h
534 01B1 58 pop ax
535 01B2 73 10 jnc read_ok
536 01B4 50 push ax
537 01B5 33 C0 xor ax, ax ; reset the drive
538 01B7 CD 13 int 13h
539 01B9 58 pop ax
540 01BA 4E dec si
541 01BB 75 F1 jnz retry
542 01BD F9 stc
543 01BE 58 pop ax
544 01BF 5A pop dx
545 01C0 5E pop si
546 01C1 C3 ret
547
548 01C2 EB 9B read_next_jmp: jmp short read_next
549 01C4 32 E4 read_ok: xor ah, ah
550 01C6 8B F0 mov si, ax ; AX = SI = number of sectors read
Turbo Assembler Version 3.1 04/11/13 12:54:48 Page 11
boot.ASM
551 01C8 F7 66 0B mul word ptr bytesPerSector ; AX = number of bytes read
552 01CB 03 D8 add bx, ax ; add number of bytes read to BX
553 01CD 73 07 jnc no_incr_es ; if overflow...
554
555 01CF 8C C0 mov ax, es
556 01D1 80 C4 10 add ah, 10h ; ...add 1000h to ES
557 01D4 8E C0 mov es, ax
558
559 01D6 58 no_incr_es: pop ax
560 01D7 5A pop dx ; DX:AX = last sector number
561
562 01D8 03 C6 add ax, si
563 01DA 83 D2 00 adc dx, 0 ; DX:AX = next sector to read
564 01DD 2B FE sub di, si ; if there is anything left to read,
565 01DF 7F E1 jg read_next_jmp ; continue
566
567 01E1 F8 clc
568 01E2 5E pop si
569 01E3 C3 ret
570 01E4 readDisk endp
571
572 01E4 42 6F 6F 74 20 65 72+ errmsg db "Boot error"
573 72 6F 72
574 =000A ERRMSGLEN equ $ - errmsg
575
576
577 01EE 49 50 4C 20 20 20 20+ filename db "IPL SYS"
578 20 53 59 53
579
580 org BASE+01feh
581 01FE AA55 sign dw 0aa55h
582
583 0200 TEXT ENDS
584 end
Turbo Assembler Version 3.1 04/11/13 12:54:48 Page 12
Symbol Table
Symbol Name Type Value
??DATE Text "04/11/13"
??FILENAME Text "boot "
??TIME Text "12:54:48"
??VERSION Number 030A
@CPU Text 0101H
@CURSEG Text TEXT
@FILENAME Text BOOT
@WORDSIZE Text 2
AX_MIN_1 Near TEXT:0192
AX_MIN_2 Near TEXT:01A6
BASE Number 0000
BOOT_ERROR Near TEXT:0140
BOOT_SUCCESS Near TEXT:0156
BYTESPERSECTOR Text [bp+0bh]
DATA_START Text [bp-12]
DRIVE Text [bp+24h]
ENTRY Near TEXT:0000
ERRMSG Byte TEXT:01E4
ERRMSGLEN Number 000A
EXTBOOT Text [bp+26h]
FATBUF Number 4000
FATERROR Near TEXT:011B
FAT_12 Near TEXT:00F1
FAT_16 Near TEXT:0106
FAT_EVEN Near TEXT:00FE
FAT_START Text [bp-4]
FFDONE Near TEXT:00C4
FILENAME Byte TEXT:01EE
FILESYS Text [bp+36h]
FINISHED Near TEXT:0118
FIRST_HALF Near TEXT:0110
LOADSEG Number 2000
LOAD_SEG Word TEXT:003E
MID Text [bp+15h]
NEXT_CHAR Near TEXT:0147
NEXT_CLUST Near TEXT:00E2
NEXT_CLUSTER Near TEXT:0125
NEXT_ENTRY Near TEXT:00A9
NEXT_TEST Near TEXT:0116
NFATS Text [bp+10h]
NHEADS Text [bp+1ah]
NHIDDEN Text [bp+1ch]
NO_INCR_ES Near TEXT:01D6
NROOTDIR Text [bp+11h]
NSECTORHUGE Text [bp+20h]
NSECTORS Text [bp+13h]
OEM Text [bp+3]
READDISK Near TEXT:015E
READ_NEXT Near TEXT:015F
READ_NEXT_JMP Near TEXT:01C2
READ_OK Near TEXT:01C4
REAL_START Near TEXT:0040
Turbo Assembler Version 3.1 04/11/13 12:54:48 Page 13
Symbol Table
RESSECTORS Text [bp+0eh]
RETRY Near TEXT:01AE
RETRYCOUNT Number 0005
ROOT_DIR_START Text [bp-8]
SECTPERCLUSTER Text [bp+0dh]
SECTPERFAT Text [bp+16h]
SECTPERTRACK Text [bp+18h]
SIGN Word TEXT:01FE
TEMPBUF Text [bp+3eh]
VOLID Text [bp+27h]
VOLLABEL Text [bp+2bh]
Macro Name
FINDFILE
GETDRIVEPARMS
GETFATCHAIN
LOADFILE
Groups & Segments Bit Size Align Combine Class
TEXT 16 0200 Word Public TEXT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -