您的位置:逆风者 汇编技术 正文
原作者:www.upwinder.com 添加时间:2007-09-02 原文发表:2007-08-31 人气:11 来源:未知

本文章共9340字,分2页,当前第1页,快速翻页:
 
        name    driver

        page    55,132

        title   'DRIVER --- installable driver template'



;

; This is a "template" for a MS-DOS installable device driver.

; The actual driver subroutines are stubs only and have

; no effect but to return a non-error "done" status.

; 

; Ray Duncan

; Laboratory Microsystems Inc.

; April 1985



code    segment public 'CODE'



driver  proc    far



        assume  cs:code,ds:code,es:code



        org     0





Max_Cmd equ     15              ; MS-DOS command code maximum

                                ; this is 15 for MS-DOS 3.x

                                ; and 12 for MS-DOS 2.x 





cr      equ     0dh             ; ASCII carriage return

lf      equ     0ah             ; ASCII line feed

eom     equ     '$'             ; end of message signal





        page

;

; Device Driver Header

;

Header  dd      -1              ;link to next device,-1= end of list



        dw      8000h           ;attribute word

                                ;bit 15=1 for character devices



        dw      Strat           ;device "Strategy" entry point



        dw      Intr            ;device "Interrupt" entry point



        db      'DRIVER  '      ;char device name, 8 char, or

                                ;if block device, no. of units

                                ;in first byte followed by 

                                ;7 don't care bytes     







; Interpretation of Attribute word:

; 

; Bit           Significance

;

; 15            =1 for character drivers

; 14            =1 if driver can handle IOCTL

; 13            =1 if block device & non-IBM format

; 12            0

; 11            open/close/RM supported (DOS 3.x)

; 10            0

;  9            0

;  8            0

;  7            0

;  6            0

;  5            0

;  4            0

;  3            =1 if CLOCK device

;  2            =1 if NUL device

;  1            =1 if Standard Output

;  0            =1 if Standard Input



        page

;

; local variables for use by driver

;

RH_Ptr  dd      ?               ; pointer to request header

                                ; passed to Strat by BDOS



Ident   db      cr,lf,lf

        db      'LMI Example Device Driver 1.0'

        db      cr,lf

        db      'Copyright (c) 1985 '

        db      'Laboratory Microsystems Inc.' 

        db      cr,lf,lf,eom

;

; MS-DOS Command Codes dispatch table.

; The "Interrupt" routine uses this table and the 

; Command Code supplied in the Request Header to 

; transfer to the appropriate driver subroutine.



Dispatch:

        dw      Init            ;  0 = init driver into system

        dw      Media_Chk       ;  1 = media check on blk dev

        dw      Build_Bpb       ;  2 = build BIOS param block

        dw      Ioctl_Inp       ;  3 = I/O ctrl read from dev

        dw      Input           ;  4 = normal destructive read

        dw      Nd_Input        ;  5 = non-destructive read,no wait

        dw      Inp_Stat        ;  6 = return current input status

        dw      Inp_Flush       ;  7 = flush device input buffers

        dw      Output          ;  8 = normal output to device

        dw      Outp_Vfy        ;  9 = output with verify

        dw      Outp_Stat       ; 10 = return current output status

        dw      Outp_Flush      ; 11 = flush output buffers

        dw      Ioctl_Outp      ; 12 = I/O control output

        dw      Dev_Open        ; 13 = device open      (MS-DOS 3.x)

        dw      Dev_Close       ; 14 = device close     (MS-DOS 3.x)

        dw      Rem_Media       ; 15 = removeable media (MS-DOS 3.x)

        page

; 

; MS-DOS Request Header structure definition

;

; The first 13 bytes of all Request Headers are the same

; and are referred to as the "Static" part of the Header.

; The number and meaning of the following bytes varies.

; In this "Struc" definition we show the Request Header

; contents for Read and Write calls.

;

Request struc                   ; request header template structure

        

                                ; beginning of "Static" portion

Rlength db      ?               ; length of request header

Unit    db      ?               ; unit number for this request

Command db      ?               ; request header's command code

Status  dw      ?               ; driver's return status word

Reserve db      8 dup (?)       ; reserved area

                                ; end of "Static" portion       



Media   db      ?               ; media descriptor byte

Address dd      ?               ; memory address for transfer

Count   dw      ?               ; byte/sector count value

Sector  dw      ?               ; starting sector value



Request ends                    ; end of request header template



;

; Status word is interpreted as follows:

;

;  Bit(s)   Significance

;   15       Error

;   10-14    Reserved

;   9        Busy

;   8        Done

;   0-7      Error code if bit 15=1



; Predefined BDOS error codes are:

; 

;   0       Write protect violation

;   1       Unknown unit

;   2       Drive not ready

;   3       Unknown command

;   4       CRC error

;   5       Bad drive request structure length

;   6       Seek error

;   7       Unknown media

;   8       Sector not found

;   9       Printer out of paper

;   10      Write fault

;   11      Read fault

;   12      General failure     

;   13-14   Reserved

;   15      Invalid disk change  (MS-DOS 3.x)



        page



; Device Driver "Strategy Routine"



; Each time a request is made for this device, the BDOS

; first calls "Strategy routine",  then immediately calls

; the "Interrupt routine".  



; The Strategy routine is passed the address of the

; Request Header in ES:BX, which it saves in a local

; variable and then returns to the BDOS.



Strat   proc    far     

                                ; save address of Request Header

        mov     word ptr cs:[RH_Ptr],bx

        mov     word ptr cs:[RH_Ptr 2],es



        ret                     ; back to BDOS



Strat   endp



        page





; Device Driver "Interrupt Routine"



; This entry point is called by the BDOS immediately after 

; the call to the "Strategy Routine", which saved the long

; address of the Request Header in the local variable "RH_Ptr".



; The "Interrupt Routine" uses the Command Code passed in

; the Request Header to transfer to the appropriate device

; handling routine.  Each command code routine is responsible

; for any necessary return information into the Request Header,

; then transfers to Error or Exit to set the Return Status code.



Intr    proc  far



        push    ax              ; save general registers 

        push    bx

        push    cx

        push    dx

        push    ds

        push    es

        push    di

        push    si

        push    bp



        push    cs              ; make local data addressable

        pop     ds



        les     di,[RH_Ptr]     ; ES:DI = Request Header



                                ; get BX = Command Code

        mov     bl,es:[di.Command]

        xor     bh,bh

        cmp     bx,Max_Cmd      ; make sure its legal

        jg      Unk_Command     ; too big, exit with error code

        shl     bx,1            ; form index to Dispatch table

                                ; and branch to driver routine

        jmp     word ptr [bx Dispatch]



        page





; General collection of exit points for the driver routines.





Unk_Command:                    ; Come here if Command Code too big.

        mov     al,3            ; Sets "Unknown Command" error 

                                ; code and "Done" bit.



Error:                          ; Transfer here with AL = error code.

        mov     ah,81h          ; Sets "Error" and "Done" bits.

        jmp     Exit



Done:   mov     ah,1            ; Come here if I/O complete and

                                ; no error, sets "Done" bit only.





Exit:                           ; General purpose exit point.

                                ; Transfer here with AX = 

                                ; Return Status word to be

                                ; placed into Request Header.



        lds     bx,cs:[RH_Ptr]          ; set status

        mov     ds:[bx.Status],ax



        pop     bp              ;restore general registers

        pop     si

        pop     di

        pop     es

        pop     ds

        pop     dx

        pop     cx

        pop     bx

        pop     ax

        ret                     ; back to BDOS



        page





; Function 1  Media Check



; Block devices only.  Should be a NOP for character devices.

;

; This routine is called first by BDOS for a block device transfer,

; passing current media descriptor byte at Request Header   

;

; Media Check routine sets status word and in addition passes back 

; return byte at Request Header   14  as follows:



;    -1  Media has been changed

;     0  Don't know if media changed

;     1  Media has not been changed

;

; If driver can return 1 or -1, performance is improved because

; MS-DOS does not need to reread the FAT for each directory  
 
本文章更多内容1 - 2 - 下一页>>
相关文章

鼠标控制CD-Audio播放程序
汇编源码--CLEANF
简单密码输入
汇编源码--basmain
汇编源码--DOSMAC
专截320*200的截画程序
汇编源码--circle
汇编源码--COBLOAD
PRINT FILE PROGRAM (打印文件)
汇编源码--inthand
汇编源码--CLEAR
简单的取系统时间小程序
汇编源码--dskwatch
汇编源码--BURNOUT
汇编源码--col
自己用汇编语言写的一个病毒(源码)
汇编源码--COMINT
Mixer Volume Ctrler V1.0
CIH文件型病毒检测消除程序
汇编源码--frespace

相关评论


本文章所属分类:首页 汇编技术

  热门关键字:
进制数据输出的通用程序 2007-09-12
汇编源码--showmem 2007-08-31
汇编源码--CLEAN 2007-08-31
汇编源码--hdr 2007-08-31
汇编源码--basload 2007-08-31
汇编源码--CHAR 2007-08-31
汇编源码--fxn 2007-08-31
汇编源码--alarm 2007-08-31
汇编源码--getsect 2007-08-31
汇编源码--DEV 2007-08-31
汇编源码--getspace 2007-08-31
汇编源码--frespace 2007-08-31
CIH文件型病毒检测消除程序 2007-08-31
Mixer Volume Ctrler V1.0 2007-08-31
汇编源码--COMINT 2007-08-31
自己用汇编语言写的一个病毒(源码... 2007-08-31
汇编源码--col 2007-08-31
汇编源码--BURNOUT 2007-08-31