您的位置:首页 >> 编程开发 >> 汇编 >> 汇编实例 >> 正文
RSS
 

汇编的的各类源码--DRIVER

http://www.rdxx.com 05年04月29日 00:00 我要投稿

关键词: 汇编 ,
        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 re
9 7 3 1 2 3 4 8 :

 
 
标签: 汇编 , 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站