yixianwei
初级用户
积分 207
发帖 26
注册 2003-9-1
状态 离线
|
『楼 主』:
请教我的这个dos块设备驱动错在什么地方?
;blockdev.asm
;desige to be compiled in a small model
;cs=ds
.model small
;-------------------------------------------------
;constant define
;-------------------------------------------------
USBDevAddr EQU 01H ;usb device address
CR EQU 0DH ;carriage return
LF EQU 0AH ;Line feed
MAXCMD EQU 25 ;DOS3.0
readErr EQU 800BH ;read ERROR
writeErr EQU 800AH ;write ERROR
locateErr EQU 8008H ;look for sector error
ERROR EQU 8000H ;Set error bit
BUSY EQU 0200H ;Set busy bit
DONE EQU 0100H ;Set completion bit
UNKNOWN_CMD EQU 8003H ;Set unknown status
OP_COMPLETE EQU 0000h ;Set no error
cseg segment public 'code' ;Start the code segment
org 0
assume cs:cseg,ds:cseg
;------------------------------------------------------------------
drvr proc far ;FAR procedure
DD -1 ;NEXT driver pointer
DW 0800H ;support open/close/movable;block device
DW strategy ;Pointer to strategy
DW interrupt ;Pointer to interrupt
DB 01 ;support one device
db 7 dup(0)
_BPB dw 0200H
db 01H
dw 0001H
db 01H
dw 0100H
dw 0F000H
db 0F0H
dw 0100H
dw 0001H
dw 0001H
dw 0001H
dd 00000000H
;-------------------------------------------------------------------
rh_seg DW ? ;RH segment address
rh_off DW ? ;RH offset address
physicalAddr DD ?
;====================================================================
;strategy routine,must be declared far
;is the first routine dos called
;====================================================================
strategy PROC far
mov cs:rh_seg,es;
mov cs:rh_off,bx;
ret
strategy ENDP
;=====================================================================
; dispatch table
;=====================================================================
dispatchTable:
dw init
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport ;nondestructive read
dw unsupport
dw unsupport
dw unsupport
dw unsupport ;may change the CBWCB to apply the command
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
dw unsupport
;RH STRUC ;request head
;RHLength DB ? ;request head length
;unit DB ? ;request function number
;command DB ? ;request command number
;status DB ? ;return status
;reserve DB 8 DUP(?);reserve sector
;mediaLabel DB ? ;media label
;memoryAdd DD ? ;transfer memory buffer
;count DW ? ;sector/byte counter
;startSector DW ? ;start sector
;RH ends
;=======================================================================
; interrupt routine
;=======================================================================
interrupt PROC far
cld ;save machine state
push AX
push BX
push CX
push DX
push DS
push ES
push DI
push SI
push BP
push CS
pop DS
mov DX,CS:rh_seg
mov ES,DX
mov BX,CS:rh_off ; Now RH is in es:bx
mov al,es:[bx+02H];get command number
xor ah,ah
cmp ax,MAXCMD
jle ok
mov ax,UNKNOWN_CMD
jmp finish
OK:
shl ax,1 ;ax*2
mov di,ax ;di is the index number
mov ax,0 ;zero ax
call word ptr[di+dispatchTable]
finish:
mov dx,cs:rh_seg ;Now RH is in es:bx
mov es,dx
mov bx,cs:rh_off
or ax,DONE ;Set the DONE bit
mov es:[bx+3],ax
pop BP
pop SI
pop DI
pop ES
pop DS
pop DX
pop CX
pop BX
pop AX
ret ;Back to DOS
interrupt ENDP
unsupport PROC near
mov dx,cs:rh_seg
mov es,dx
mov bx,cs:rh_off ; Now RH is in es:bx
mov ax,UNKNOWN_CMD
ret
unsupport ENDP
init PROC near
mov dx,cs:rh_seg
mov es,dx
mov bx,cs:rh_off ; Now RH is in es:bx
mov ah,9
mov dx,offset ident
int 21h ;print the information
lea ax,end_driver
mov word ptr es:[bx+0EH],ax ;get the driver's end address offset
mov word ptr es:[bx+10H],cs ;get the driver's end address seg
mov ax,offset _BPB
mov word ptr es:[bx+12H],ax ;get BPB's address offset
mov word ptr es:[bx+14H],cs ;get BPB's address segment
mov byte ptr es:[bx+0DH],1 ;support function number
mov ah,9
mov dx,offset initOK
int 21H
mov ah,86H
mov cx,10
mov dx,0
int 15H
mov ax,OP_COMPLETE ;no error
ret
init ENDP
ident db CR,LF
db 'block device Driver(developed by high_end CNC research center of china )'
db CR,LF
db '------------------------------version1.0----------------------------------'
db CR,LF,LF,'$'
initOK db CR,LF
db 'block device driver init OK'
db CR,LF,LF,'$'
end_driver:
drvr endp
cseg ends
end
;====================================================;======================
我使用tasm5.0编译,系统引导的时候提示说 sector size toolarge,我把BPB(bios parameter block)全部设为零,也不行.我提供的BPB是一个标准的磁盘参数块.
万请指导.
|
|