• How are sector iterations performed?
, CHS CylinderHeadSector,
. BIOS
08h on int 13h, ,
, .
CL 1 63.
DH 0 255, 255 .
CL 0 1023.
, 2 10- 6
7 CL!
CHS, - , C -
S - .
,
.
, S, , reset
(1) ,
H.
, H, , reset
(0) ,
C.
, C, , reset
(0). .
SectorCount , ,
.
; INPUT: DL=Drive
; CH=Cylinder
; DH=Head
; CL=Sector
; AX=SectorCount
; ES:BX=Buffer
; OUTPUT: CF=0 AH = 0
; CH,DH,CL = CHS of following sector
; CF=1 AH = Error status
; CH,DH,CL = CHS of problem sector
ReadDiskSectors:
push es
push di
push bp
mov bp,sp ;Local variables:
push ax ;[bp-2]=SectorCount
push cx ;[bp-4]=MaxSector
push dx ;[bp-6]=MaxHead
push bx ;[bp-8]=MaxCylinder
push es
mov ah,08h
int 13h ;ReturnDiskDriveParameters
pop es
jc NOK
mov bx,cx ;10-bit cylinder info -> BX
xchg bl,bh
shr bh,6
xchg [bp-8],bx ;Store MaxCylinder and get input BX back
movzx dx,dh ;8-bit head info -> DX
xchg [bp-6],dx ;Store MaxHead and get input DX back
and cx,003Fh ;6-bit sector info -> CX
xchg [bp-4],cx ;Store MaxSector and get input CX back
ReadNext:
mov di,5 ;Max 5 tries per sector
ReadAgain:
mov ax,0201h ;Read 1 sector
int 13h ;ReadDiskSectors
jnc OK
push ax ;Save error status byte in AH
mov ah,00h
int 13h ;ResetDiskSystem
pop ax
dec di
jnz ReadAgain
stc
jmp NOK
OK:
dec word ptr [bp-2] ;SectorCount
jz Ready
call NextCHS
mov ax,es ;Move buffer 512 bytes up
add ax,512/16
mov es,ax
jmp ReadNext
Ready:
call NextCHS ;Return useful CHS values to support reads
xor ah,ah ; -> CF=0 ... that are longer than memory
NOK:
mov sp,bp
pop bp
pop di
pop es
ret
NextCHS:
mov al,cl ;Calculate the 6-bit sector number
and al,00111111b
cmp al,[bp-4] ;MaxSector
jb NextSector
cmp dh,[bp-6] ;MaxHead
jb NextHead
mov ax,cx ;Calculate the 10-bit cylinder number
xchg al,ah
shr ah,6
cmp ax,[bp-8] ;MaxCylinder
jb NextCylinder
DiskWrap:
mov cx,1 ;Wraparound to very first sector on disk
mov dh,0
ret
NextCylinder:
inc ax
shl ah,6 ;Split 10-bit cylinder number over CL and CH
xchg al,ah
mov cx,ax
mov dh,0
inc cl
ret
NextHead:
inc dh
and cl,11000000b
NextSector:
inc cl
ret
, 512
, , .
, 512-
.
, 4-
DisketteParameterTable, ES: DI
BIOS ReturnDiskDriveParameters.
• ?
, .
BIOS CHS, ... , !
, , , . , @Jester, : " ?" , times 0xFFFF db 0x00
. 7C00h, SS: SP 0000h: 7C00h .
main:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 7C00h
sti
PRINT welcome
@Fifoernik, jmp halt yay db "kernel", CR, LF, NUL, !
kernel:
PRINT yay
jmp halt
yay db "kernel", CR, LF, NUL