DOS引导扇区代码详解

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

DOS引导扇区代码详解
Page ,132
TITLE BOOT SECTOR 1 OF TRACK 0 - BOOT LOADER
;/*
; * Microsoft Confidential
; * Copyright (C) Microsoft Corporation 1991
; * All Rights Reserved.
; */
; Rev 1.0 ChrisP, AaronR and others. 2.0 format boot
;
; Rev 3.0 MarkZ PC/AT enhancements
; 2.50 in label
; Rev 3.1 MarkZ 3.1 in label due to vagaries of SYSing to IBM drive Ds
; This resulted in the BPB being off by 1. So we now trust
; 2.0 and 3.1 boot sectors and disbelieve 3.0.
;
; Rev 3.2 LeeAc Modify layout of extended BPB for >32M support
; Move PHYDRV to 3rd byte from end of sector
; so that it won have to be moved again
; FORMAT and SYS count on PHYDRV being in a known location
;
; Rev. 3.3 D.C. L. Changed Sec 9 EOT field from 15 to 18. May 29, 1986.
;
; Rev 3.31 MarkT The COUNT value has a bogus check (JBE) to determine
; if weve loaded in all the sectors of IBMBIO. This will
; cause too big of a load if the sectors per track is high
; enough, causing either a stack overflow or the boot code
; to be overwritten.
;
; Rev 4.00 J. K. For DOS 4.00 Modified to handle the extended BPB, and
; 32 bit sector number calculation to enable the primary
; partition be started beyond 32 MB boundary.
;
;
; The ROM in the IBM PC starts the boot process by performing a hardware
; initialization and a verification of all external devices. If all goes
; well, it will then load from the boot drive the sector from track 0, head 0,
; sector 1. This sector is placed at physical address 07C00h. The initial
; registers are set up as follows: CS=DS=ES=SS=0. IP=7C00h, SP=0400H.
;
; The code in this sector is responsible for locating the MSDOS device drivers
; (IBMBIO) and for placing the directory sector with this information at
; physical address 00500h. After loading in this sector, it reads in the
; entirety of the BIOS at BIOSEG:0 and does a long jump to that point.
;
; If no BIOS/DOS pair is found an error message is displayed and the user is
; prompted to reinsert another disk. If there is a disk error during the
; process, a message is displayed and things are halted.
;
; At the beginning of the boot sector, there is a table which describes the
; MSDOS structure of the media. This is equivalent to the BPB with some
; additional information describing the physical layout of the driver (heads,
; tracks, sectors)
;
;============================================================================== ;REVISION HISTORY:
;AN000 - New for DOS Version 4.00 - J.K.
;AC000 - Changed for DOS Version 4.00 - J.K.
;AN00x - PTM number for DOS Version 4.00 - J.K.
;============================================================================== ;AN001; d52 Make the fixed positioned variable "CURHD" to be local. 7/6/87 J.K.
;AN002; d48 Change head settle at boot time. 7/7/87 J.K.
;AN003; P1820 New message SKL file 10/20/87 J.K.
;AN004; D304 New structrue of Boot record for OS2. 11/09/87 J.K.
;AN005; Changed version to 5.0 03/08/90 E.A.
;AN006; Changed to re
move MSLOAD in first cluster restriction 04/23/90 J.H.
;============================================================================== ORIGIN EQU 7C00H ; Origin of bootstrap LOADER
BIO_SEG EQU 70H ; Destingation segment of BIOS
BIO_OFFSET EQU 700H ; Offset of bios
SECTOR_SIZE EQU 512 ; Sector size in bytes
DIR_ENTRY_SIZE EQU 32 ; Size of directory entry in bytes
DIR_OFF EQU 500h
IBM_LOAD_SIZE EQU 3 ;J.K. Size of IBMLOAD module in sectors
ROM_DISKRD EQU 2
DSK_PARMS EQU 1EH*4 ;POINTER TO DRIVE PARAMETERS
; ========================================================================== include version.inc
include dirent.inc
; ========================================================================== SEGBIOS SEGMENT AT BIO_SEG
; Define the destination segment of the BIOS, including the
; initialization label
BIOS LABEL BYTE
SEGBIOS ENDS
; ========================================================================== CODE SEGMENT
ASSUME CS:CODE,DS:NOTHING,ES:NOTHING,SS:NOTHING
ORG ORIGIN
Public $START
$START:
; WARNING -- Don change this to a short jmp
jmp Main ; Jump to start of code
; ==========================================================================
; Start of BPB area of the boot record
IF IBMCOPYRIGHT
DB "IBM "
ELSE
DB "MSDOS"
ENDIF
; BUGBUG -- 7 Dec 1992 -- chuckst -- changed version back to 5.0 to
; avoid bug in PC-TOOLS DISKFIX
OsVersion DB "5.0" ; DOS version number
BytesPerSector DW SECTOR_SIZE ; Size of a physical sector
SecsPerClust DB 8 ; Sectors per allocation unit
ReservedSecs DW 1 ; Number of reserved sectors
NumFats DB 2 ; Number of fats
NumDirEntries DW 512 ; Number of direc entries
TotalSectors DW 4*17*305-1 ; Number of sectors - number of hidden
; sectors (0 when 32 bit sector number)
MediaByte DB 0F8H ; MediaByte byte
NumFatSecs DW 8 ; Number of fat sectors
SecPerTrack DW 17 ; Sectors per track
NumHeads DW 4 ; Number of drive heads
HiddenSecs DD 1 ; Number of hidden sectors
BigTotalSecs DD 0 ; 32 bit version of number of sectors
BootDrv DB 80h
CurrentHead DB 0h ; Current Head
ExtBootSig DB 41
SerialNum DD 0
VolumeLabel DB NO NAME
FatId DB FAT12
; Danger If not 32 bit sector number calculation,
; FORMAT should set the value of HiddenSecsHigh and
; BigTotalSectors to 0
PUBLIC uData
uData LABEL BYTE
;Equates to allow access to
;storage where Main is now
Sec9 EQU BYTE PTR uData+0 ;11 byte diskette parm. table
BiosLow EQU WORD PTR uData+11
BiosHigh EQU WORD PTR uData+13
CurTrk EQU WORD PTR uData+15
CurSec EQU BYTE PTR uData+17
DirLow EQU WORD PTR uData+18
DirHigh EQU WORD PTR uData+20
; ========================================================================= ; First thing is to reset the stack to a better and more known
; place. The ROM may change, but wed like to get the stack
; in the correct place.
MAIN:
cli ;Stop interrupts till stack ok
xor AX,AX
mov SS,AX ;Work in stack just below this routine
AS
SUME SS:CODE
mov SP,ORIGIN
push SS
pop ES
ASSUME ES:CODE
; We copy the disk parameter table into a local area. We scan
; the table above for non-zero parameters. Any we see get
; changed to their non-zero values. We copy the disk parameter
; table into a local area (overlayed into the code)
mov BX,DSK_PARMS
lds SI,DWORD PTR SS:[BX] ; get address of disk table
push DS ; save original vector for possible
push SI ; restore
push SS
push BX
mov DI,OFFSET Sec9
mov CX,11
cld
repz movsb
push ES
pop DS ; DS = ES = code = 0.
assume DS:CODE
; Set the head settle time to 15ms because we don have room
; to do a disk retry and then set sectors per from the value
; in the BPB
mov BYTE PTR [DI-2], 0fh ; Head settle time
mov CX, SecPerTrack
mov BYTE PTR [DI-7], cl ; End of Track
mov [BX+2],AX ; Place in new disk parameter
mov [BX],offset Sec9 ; table vector
; We may now turn interrupts back on. Before this, there is
; a small window when a reboot command may come in when the ; disk parameter table is garbage
sti ; Interrupts OK now
int 13h ; Reset the disk system just in case
jc CkErr ; any thing funny has happened.
; The system is now prepared for us to begin reading.
; First, determine logical sector numbers of the start of the
; directory and the start of the data area.
xor AX,AX
cmp TotalSectors,AX ; 32 bit calculation?
je Dir_Cont
mov CX,TotalSectors
mov WORD PTR BigTotalSecs,CX ; BigTotalSecs
Dir_Cont:
mov AL,NumFats ;Determine sector dir starts on
mul NumFatSecs ;DX;AX
add AX,WORD PTR HiddenSecs
adc DX,WORD PTR HiddenSecs[2]
add AX,ReservedSecs
adc DX,0
; DX:AX = NumFats * NumFatSecs + ReservedSecs + cSecHid mov [DirLow],AX
mov [DirHigh],DX
mov [BiosLow],AX
mov [BiosHigh],DX
; Take into account size of directory (only know number
; of directory entries)
mov AX,DIR_ENTRY_SIZE ; bytes per directory entry
mul NumDirEntries ; convert to bytes in directory
mov BX,BytesPerSector ; add in sector size
add AX,BX
dec AX ; decrement so that we round up
div BX ; convert to sector number
add [BiosLow],AX ; Start sector # of Data area
adc [BiosHigh],0
; We load in the first directory sector and examine it to
; make sure the the BIOS and DOS are the first two directory ; entries. If they are not found, the user is prompted to
; insert a new disk. The directory sector is loaded into 00500h mov BX,DIR_OFF ; sector to go in at 00500h
mov DX,[DirHigh]
mov AX,[DirLow] ; logical sector of directory
call DoDiv ; convert to sector, track, head
jc CkErr ; Overflow? BPB must be wrong!!
mov al, 1 ; disk read 1 sector
call DoCall ; do the disk read
jb CkErr ; if errors try to recover
; Now we scan for the presence of BIOS file.
mov DI,BX
mov CX,11
mov SI,OFFSET Bio ; point to "ibmbio com"
repz cmpsb ; see if the same
jnz CkErr ; if not there advise the user
; Found the BIOS. Check the second directory entry.
; SI will already point to "MSDOS SYS"
if first compare
; was successful
lea DI,[BX+20h]
;** mov SI,OFFSET Dos
mov CX,11
repz cmpsb
jz DoLoad
; There has been some recoverable error. Display a message ; and wait for a keystroke.
CkErr: mov SI,OFFSET SysMsg ; point to no system message ErrOut:
call Write ; and write on the screen
xor AX,AX ; wait for response
int 16h ; get character from keyboard
pop SI ; reset disk parameter table back to
pop DS ; rom
pop [SI]
pop [SI+2]
int 19h ; Continue in loop till good disk
Load_Failure:
pop ax ;adjust the stack
pop ax
pop ax
jmp short CkErr ;display message and reboot.
; We now begin to load the BIOS in.
; All we have to do is just read is multiply the BioStartClus
; by SecsPerClust to find the logical sector for the start
; of the BIOS file. When this value is added to the double
; word BiosHigh:BiosLow we get the absolute sector offset
; for the start of the file and then read the sectors
; contiguously IBM_LOAD_SIZE times. We here assume that
; IBMLOAD module is contiguous. Currently we estimate that
; IBMLOAD module will not be more than 3 sectors.
DoLoad:
mov AX,[BX].DIR_FIRST ; AX = BIOS starting cluster
dec AX ; Subtract first 2 reserved clusters
dec AX
mov BL,SecsPerClust ; BX = Sectors per cluster
xor BH,BH
mul BX ; DX:AX = first logical sector of bios
add AX,[BiosLow] ; Add absolute start sector
adc DX,[BiosHigh] ; DX:AX = Absolute bios sector offset
mov BX,BIO_OFFSET ;offset of ibmbio(IBMLOAD) to be loaded.
mov CX,IBM_LOAD_SIZE ;# of sectors to read.
Do_While:
push AX
push DX
push CX
call DoDiv ; DX:AX = sector number.
jc Load_Failure ; Adjust stack. Show error message
mov al, 1 ; Read 1 sector at a time.
; This is to handle a case of media
; when the first sector of IBMLOAD is the
; the last sector in a track.
call DoCall ; Read the sector.
pop CX
pop DX
pop AX
jc CkErr ; Read error?
add AX,1 ; Next sector number.
adc DX,0
add BX,BytesPerSector ; Adjust buffer address.
loop Do_While
; ========================================================================= ; Main read-in loop.
; ES:BX points to area to read.
; Count is the number of sectors remaining.
; BIOS$ is the next logical sector number to read
;
; CurrentHead is the head for this next disk request
; CurTrk is the track for this next request
; CurSec is the beginning sector number for this request
;
; AX is the number of sectors that we may read.
;
; ========================================================================= ;
; IBMINIT requires the following input conditions:
;
; DL = INT 13 drive number we booted from
; CH = media byte
; IBMBIO init routine should check if the boot record is the
; extended one by looking at the extended_boot_signature.
; If it is, then should us AX;BX for the starting data sector number.
;
========================================================================= DISKOK:
mov CH,MediaByte
mov DL,BootDrv
mov BX,[BiosLow] ; J.
K.I1.Get bios sector in bx
mov AX,[BiosHigh] ; J.K.I1.
jmp FAR PTR Bios ;CRANK UP THE DOS
WRITE:
lodsb ;GET NEXT CHARACTER
or AL,AL ;Clear the high bit
jz EndWr ;ERROR MESSAGE UP, JUMP TO BASIC
mov AH,14 ;WILL WRITE CHARACTER & ATTRIBUTE
mov BX,7 ;ATTRIBUTE
int 10h ;PRINT THE CHARACTER
jmp Write
; Convert a logical sector into Track/sector/head.
; DX;AX has the sector number. Because of not enough space, we
; are going to use Simple 32 bit division here.
; Carry set if DX;AX is too big to handle.
DODIV:
cmp DX,SecPerTrack ; To prevent overflow
jae DivOverFlow ; Compare high word with the divisor.
div SecPerTrack ; AX = Total tracks, DX = sector number
inc DL ; We assume SecPerTrack < 255 & DH=0
; curSec is 1-based.
mov CurSec, DL ; Save it
xor DX,DX
div NumHeads
mov CurrentHead,DL ;Also, NumHeads < 255.
mov CurTrk,AX
clc
ret
DivOverFlow:
stc
EndWR:
ret
; ========================================================================= ;
; Issue one read request. ES:BX have the transfer address,
; AL is the number of sectors.
;
; ========================================================================= DOCALL:
mov AH,ROM_DISKRD ;=2
mov DX,CurTrk
mov CL,6
shl DH,CL
or DH,CurSec
mov CX,DX
xchg CH,CL
mov DL, BootDrv
mov DH, CurrentHead
int 13h
ret
; ========================================================================= include boot.cl1
; ========================================================================= IF IBMCOPYRIGHT
Bio DB "IBMBIO COM"
Dos DB "IBMDOS COM"
ELSE
Bio DB "IO SYS"
Dos DB "MSDOS SYS"
ENDIF
; ========================================================================= Free EQU (SECTOR_SIZE - 4) - ($-$start)
if Free LT 0
%out FATAL PROBLEM:boot sector is too large
.ERR
endif
org origin + (SECTOR_SIZE - 2)
db 55h,0aah ; Boot sector signature
; ========================================================================= CODE ENDS
END
DOS引导扇区代码详解
如果从软盘起动,则Dos引导程序被ROM BIOS直接加载到内存,若从硬盘起动,则被硬
盘的主引导程序加载.不过都是被加载到内存的绝对地址0000:7C00H处.因此,Dos引导程
序的第⼀条指令的地址⼀定是0000:7C00H.
Dos引导程序所做的事情如下:
1>调整堆栈位置
2>修改并⽤修改后的磁盘参数表来复位磁盘系统
3>计算根⽬录表的⾸扇区的位置及IO.SYS的扇区位置
4>读⼊根⽬录表的⾸扇区
5>检查根⽬录表的开头两项是否为IO.SYS及MSDOS.SYS
6>将IO.SYS⽂件开头三个扇区读⼊内存0000:0700H处
7>跳到0000:0700H处执⾏IO.SYS,引导完毕
上述每⼀步若出错,则显⽰"Non system disk or disk error..."信息,等⽤户按任
⼀键后试图重新起动.
下⾯的Dos引导程序是从硬盘上得来的,显⽰MSDOS5.0,但Dos的ver命令报告的是6.22
版.FAT表⾃然是16位的.
说明:
(DX) 表⽰寄存器DX的值
逻辑
扇区号以0⾯0道1扇区作为逻辑0扇区,⽽不是以Dos引导扇区为逻辑0扇区,
当然,对软盘来说⼆者是相同的,对硬盘则不同
⾯号即磁头号
磁道号即柱⾯号(对硬盘)
物理扇区号由⾯号,磁道号,扇区号三者共同指定
偏移机器码符号指令说明
============================================================================ ==
0000 EB3C JMP 003E ;跳过数据区
;以下数据是⼚商OEM信息和磁盘BPB表
0000 90 4D 53 44 4F 53-35 2E 30 00 02 08 01 00 .MSDOS5.0.....
0010 02 00 02 00 00 F8 CC 00-3F 00 10 00 3F 00 00 00 ........?...?...
0020 F1 59 06 00 80 00 29 E3-0B 3F 26 53 4C 4D 20 20 .Y....)..?&SLM
0030 20 20 20 20 20 20 46 41-54 31 36 20 20 20 FAT16
----------------------------------------------------------------------------
--
003E FA CLI
003F 33C0 XOR AX,AX
0041 8ED0 MOV SS,AX
0041 8ED0 MOV SS,AX
0043 BC007C MOV SP,7C00 ; 初始化堆栈
0046 16 PUSH SS
0047 07 POP ES ;(ES)=0000H
0048 BB7800 MOV BX,0078 ;1EH 号中断向量的地址为0000:0078H
004B 36 SS: ;(SS)=0000H
004C C537 LDS SI,[BX] ;取1EH号中断向量的内容存⼊DS:SI
004E 1E PUSH DS ;该中断向量指向⼀个11字节的磁盘参
;数表
004F 56 PUSH SI ;取到后压⼊堆栈中保存
0050 16 PUSH SS
0051 53 PUSH BX ;保存地址0000:0078H
0052 BF3E7C MOV DI,7C3E ;7C3E-7C00=003EH,即偏移003EH,以下
;类推
0055 B90B00 MOV CX,000B ;磁盘参数表共11字节
0058 FC CLD
0059 F3 REPZ
005A A4 MOVSB ;将磁盘参数表复制到0000:7C3EH处
005B 06 PUSH ES
005C 1F POP DS ;(DS)=0000H
005D C645FE0F MOV BYTE PTR [DI-02],0F ;修改参数表中"磁头定位时间"
0061 8B0E187C MOV CX,[7C18] ;从BPB中取"每磁道扇区数"
0065 884DF9 MOV [DI-07],CL ;修改参数表中"每磁道扇区数"
0068 894702 MOV [BX+02],AX ;(AX)=0000H,修改1EH号中断向量
;(段址)
006B C7073E7C MOV WORD PTR [BX],7C3E ;修改1EH号中断向量(偏移),这
;样1EH号
006F FB STI ;中断向量的内容为0000:7C3EH,指向新的磁盘参
;数表
0070 CD13 INT 13 ;⽤新的磁盘参数表来复位磁盘
007
2 7279 JB 00ED ;出错则转出错处理
----------------------------------------------------------------------------
---
; 下⾯⼀段程序计算扇区位置
0074 33C0 XOR AX,AX
0076 3906137C CMP [7C13],AX ;偏移0013H处是Dos分区的总扇区数007A 7408 JZ 0084 ;为零表⽰⼤硬盘?
007C 8B0E137C MOV CX,[7C13] ;不为0则取出来放到偏移0020H处0080 890E207C MOV [7C20],CX ;这个值本程序未⽤,似乎为IO.SYS准备;的
0084 A0107C MOV AL,[7C10] ;取FAT表的个数
0087 F726167C MUL WORD PTR [7C16] ;乘以⼀个FAT表所占的扇区数008B 03061C7C ADD AX,[7C1C] ;加上Dos分区前的扇区数(隐藏扇数,低;位)
008F 13161E7C ADC DX,[7C1E] ; ⾼
;位)
0093 03060E7C ADD AX,[7C0E] ;加上Dos分区内的保留扇区数(低位) 0097 83D200 ADC DX,+00 ; (⾼位)
009A A3507C MOV [7C50],AX ;根⽬录表的⾸扇的逻辑扇区号(低位) 009D 8916527C MOV [7C52],DX ; (⾼位)
00A1 A3497C MOV [7C49],AX ;此处放IO.SYS的⾸扇的逻辑扇区号(低;位)
00A4 89164B7C MOV [7C4B],DX ; (⾼
;位)
00A8 B82000 MOV AX,0020 ;根⽬录表中每项占32字节
00AB F726117C MUL WORD PTR [7C11] ;乘以根⽬录表中的项数
00AF 8B1E0B7C MOV BX,[7C0B] ;取"每扇区的字节数"
00B3 03C3 ADD AX,BX ;这两条指令是为了取整
00B5 48 DEC AX
00B6 F7F3 DIV BX ;除以每扇字节数,得到根⽬录所占扇区
;数
00B8 0106497C ADD [7C49],AX ;得到根⽬录表后⾸扇的逻辑扇区号(低;位)
00BC 83164B7C00 ADC WORD PTR [7C4B],+00 ; (⾼
;位)
----------------------------------------------------------------------------
---
;下⾯⼀段程序在根⽬录表中找系统⽂件IO.SYS和MSDOS.SYS
00C1 BB0005 MOV BX,0500 ;内存缓冲区的偏移值
00C4 8B16527C MOV DX,[7C52] ;取根⽬录表的⾸扇的逻辑扇区号(⾼;位)
00C8 A1507C MOV AX,[7C50] ; (低
;位)
00CB E89200 CALL 0160
;将逻辑扇区号转换为物理扇区号
00CE 721D JB 00ED ;出错则转出错处理
00D0 B001 MOV AL,01
00D2 E8AC00 CALL 0181 ;读⼀个扇区到内存(根⽬录的⾸扇)
00D5 7216 JB 00ED ;出错处理
00D7 8BFB MOV DI,BX ;内存缓冲区的⾸址
00D9 B90B00 MOV CX,000B ;⽐较11个字节
00DC BEE67D MOV SI,7DE6 ;偏移01E6处是串"IO SYS",长11
;字节
00DF F3 REPZ
00E0 A6 CMPSB ;看第⼀项是否为IO.SYS
00E1 750A JNZ 00ED ;不是则出错
00E3 8D7F20 LEA DI,[BX+20] ;跳过32字节就指向第⼆项
00E6 B90B00 MOV CX,000B ;⽐较11个字节
00E9 F3 REPZ
00EA A6 CMPSB ;看第⼆项是否为MSDOS.SYS
00EB 7418 JZ 0105 ;是则两个⽂件都已找到,跳过出错处理
----------------------------------------------------------------------------
--
;下⾯⼀段进⾏出错处理
00ED BE9E7D MOV SI,7D9E ;偏移019EH处是串"Non system disk. ;.."
00F0 E85F00 CALL 0152 ;显⽰字符串
00F3 33C0 XOR AX,AX
00F5 CD16 INT 16 ;等待任⼀键按下
00F7 5E POP SI
00F8 1F POP DS ;得到1EH号中断向量的地址0000:0078H
00F9 8F04 POP [SI]
00FB 8F4402 POP [SI+02] ;恢复1EH号中断向量的内容
00FE CD19 INT 19 ;⾃举
0100 58 POP AX
0101 58 POP AX
0102 58 POP AX ;清理堆栈
0103 EBE8 JMP 00ED ;再次试图起动
----------------------------------------------------------------------------
--
;下⾯读⼊IO.SYS的头3个扇区到内存0000:0700H处
0105 8B471A MOV AX,[BX+1A] ;从根⽬录表第⼀项中取IO.SYS的⾸簇;号
0108 48 DEC AX
0109 48 DEC AX ;⾸簇号减⼆
010A 8A1E0D7C MOV BL,[7C0D] ;取每簇的扇区数
010E 32FF XOR BH,BH
0110 F7E3 MUL BX ;(⾸簇号 - 2)乘以每簇的扇区数
0112 0306497C ADD AX,[7C49] ;相加后得到IO.SYS的⾸扇的逻辑扇区;号
0116 13164B7C ADC DX,[7C4B]
011A BB0007 MOV BX,0700 ;内存缓冲区的偏移值
011D B90300 MOV CX,0003 ;循环计数初值,读3个扇区
0120 50 PUSH AX ;逻辑扇区号进栈(低位)
0121 52 PUSH
DX ; (⾼位)
0122 51 PUSH CX ;循环计数器进栈
0123 E83A00 CALL 0160 ;逻辑扇区号转换为物理扇区号
0126 72D8 JB 0100 ;出错处理
0128 B001 MOV AL,01
012A E85400 CALL 0181 ;读⼀个扇区到内存缓冲区
012D 59 POP CX ;循环计数出栈
012E 5A POP DX
012F 58 POP AX ;逻辑扇区号出栈
0130 72BB JB 00ED ;读盘出错处理
0132 050100 ADD AX,0001
0135 83D200 ADC DX,+00 ;下⼀个扇区
0138 031E0B7C ADD BX,[7C0B] ;缓冲区指针移动⼀个扇区的⼤⼩013C E2E2 LOOP 0120 ;循环读⼊三个扇区
013E 8A2E157C MOV CH,[7C15] ;取"磁盘介质描述",传给IO.SYS 0142 8A16247C MOV DL,[7C24] ;取"系统⽂件所在的驱动器号"
0146 8B1E497C MOV BX,[7C49] ;取IO.SYS的⾸扇的逻辑扇区号
014A A14B7C MOV AX,[7C4B]
014D EA00007000 JMP 0070:0000 ;执⾏IO.SYS,引导完毕
----------------------------------------------------------------------------
--
;显⽰字符串的⼦程序
0152 AC LODSB ;从串中取⼀个字符
0153 0AC0 OR AL,AL
0155 7429 JZ 0180 ;为0则已到串尾,返回(共⽤RET指令)
0157 B40E MOV AH,0E
0159 BB0700 MOV BX,0007
015C CD10 INT 10 ;显⽰该字符
015E EBF2 JMP 0152 ;循环显⽰下⼀个
----------------------------------------------------------------------------
;将逻辑扇区号转换为物理扇区号的⼦
;程序
0160 3B16187C CMP DX,[7C18] ;这两条指令是为了避免第⼆次除法时
;除数
0164 7319 JNB 017F ;为0
0166 F736187C DIV WORD PTR [7C18] ;逻辑扇取号除以每道扇区数,商(AX)= ;总磁
016A FEC2 INC DL ;道数,余数(DX)再加⼀即为扇区号,因
;为扇
016C 88164F7C MOV [7C4F],DL ;区号是从1开始的,⽽不是从0开始
0170 33D2 XOR DX,DX
0172 F7361A7C DIV WORD PTR [7C1A] ;总磁道数(AX)再除以⾯数,所得的0176 8816257C MOV [7C25],DL ;余数(DX)=⾯号(即磁头号)
017A A34D7C MOV [7C4D],AX ;商(AX)=磁道号
017D F8 CLC
017E C3 RET ;正常返回
017F F9 STC
0180 C3 RET ;异常返回
---------------------------
-------------------------------------------------
-
;读⼀个扇区的⼦程序
0181 B402 MOV AH,02 ;读功能调⽤
0183 8B164D7C MOV DX,[7C4D] ;需要的⼊⼝参数如下:
0187 B106 MOV CL,06 ;(DL)=驱动器号
0189 D2E6 SHL DH,CL ;(DH)=⾯号
018B 0A364F7C OR DH,[7C4F] ;(CH)=磁道号
018F 8BCA MOV CX,DX ;(CL)=扇区号(第6,7位为磁道号的⾼2
;位)
0191 86E9 XCHG CH,CL ;(AL)=要读的扇区数
0193 8A16247C MOV DL,[7C24] ;(ES:BX)=缓冲区⾸址
0197 8A36257C MOV DH,[7C25]
019B CD13 INT 13
019D C3 RET
----------------------------------------------------------------------------
---
0190 0D 0A ..
01A0 4E 6F 6E 2D 53 79 73 74-65 6D 20 64 69 73 6B 20 Non-System disk 01B0 6F 72 20 64 69 73 6B 20-65 72 72 6F 72 0D 0A 52 or disk error..R
01C0 65 70 6C 61 63 65 20 61-6E 64 20 70 72 65 73 73 eplace and press
01D0 20 61 6E 79 20 6B 65 79-20 77 68 65 6E 20 72 65 any key when re
01E0 61 64 79 0D 0A 00 49 4F-20 20 20 20 20 20 53 59 ady...IO SY
01F0 53 4D 53 44 4F 53 20 20-20 53 59 53 00 00 55 AA SMSDOS SYS..U.。

相关文档
最新文档