為了能更好地讓大家了解裝置驅動程式,在這篇文章裡,我打算介紹乙個程式給大家,這個程式可以把dos下的裝置驅動程式乙個乙個地列出來,你可以清楚地看 到每個驅動程式的入口位址、裝置屬性、下乙個裝置的入口位址、strategy和interrupt的入口位址、以及裝置驅動程式的名稱,從程式中,你可 以清楚地體會到裝置驅動程式的單向鍊錶的鏈結方式,如果你願意,你還可以深入到任何乙個驅動程式中,看它的裝置頭的結構,看它的strategy和 interrupt的**,總之我希望在我們實際編寫驅動程式之前,你能對dos的裝置驅動程式有更深的了解。
我們說過,dos下的裝置驅動程式使用乙個單向鍊錶鏈結起來的,第乙個裝置是nul,那麼只要我們找到了這個nul的入口位址,理論上說,我們就可以找到 所有的裝置驅動程式,但是如何找到這個nul裝置驅動程式呢?dos能找的到,說明它一定儲存了這個位址,所有我們找到它儲存的地方就ok了。
得到這個位址我們不得不使用dos的一條沒有公開的呼叫,功能52h,我們在此僅就我們需要的部分做乙個說明,如果那位讀者需要這個功能的完整說明,可以和我聯絡。
int 21h 功能52h:
入口:ah=52h 出口:es:bx指向重要資料清單表
在dos呼叫返回的這個清單中偏移22h的地方存放著nul裝置的裝置頭,一共18個位元組,記住是裝置頭而不是裝置頭的存放位址,從這個裝置頭開始就可以完成我們的任務了。
這是我在部落格裡第一次發布組合語言的**,所以我得說一下我的環境,首先這段**是16位實模式的,用masm 6.11編譯連線的,是個.com的檔案格式,如果確實看著有困難,可以輕而易舉地在debug下進行跟蹤,因為程式太簡單所以基本上沒有注釋。我也不知 道該解釋什麼,好像沒有什麼需要解釋的。
下面給出程式清單:
code segment
assume cs:code, ds:code, es:code, ss:code
org 100h
main proc
jmp begin
ddh struc
ddh_nextoff dw ? ;next device driver after this
ddh_nextseg dw ?
ddh_attribute dw ? ;attribute of device
ddh_strategy dw ? ;address of strategy routine
ddh_interrupt dw ? ;address of interrupt routine
ddh_devname db 8 dup(?) ;8 bytes device driver name
ddh ends
msg1 db 0dh, 0ah, 0ah, 0ah, 'device driver entry : $'
msg2 db 0dh, 0ah, 0ah, 'next device driver : $'
msg3 db 0dh, 0ah, 'device attribute : $'
msg4 db 0dh, 0ah, 'device strategy offset : $'
msg5 db 0dh, 0ah, 'device interrupt offset : $'
msg6 db 0dh, 0ah, 'device driver name : $'
msg7 db 8 dup(?)
db '$'
begin:
mov ah, 52h
int 21h
add bx, 22h ;+34 bytes.pointer to ddh
next_ddh:
mov ax, es:[bx].ddh_nextoff
cmp ax, 0ffffh
jz finish
mov dx, offset msg1
mov ah, 09h
int 21h
mov ax, es
call disphex
mov dl, ':'
mov ah, 02h
int 21h
mov ax, bx
call disphex
mov dx, offset msg2
mov ah, 09h
int 21h
mov ax, es:[bx].ddh_nextseg
call disphex
mov dl, ':'
mov ah, 02h
int 21h
mov ax, es:[bx].ddh_nextoff
call disphex
mov dx, offset msg3
mov ah, 09h
int 21h
mov ax, es:[bx].ddh_attribute
call disphex
mov dx, offset msg4
mov ah, 09h
int 21h
mov ax, es:[bx].ddh_strategy
call disphex
mov dx, offset msg5
mov ah, 09h
int 21h
mov ax, es:[bx].ddh_interrupt
call disphex
mov dx, offset msg6
mov ah, 09h
int 21h
mov si, bx
add si, 10
mov di, offset msg7
mov cx, 8
push es
push ds
pop es
pop ds
rep movsb
push es
push ds
pop es
pop ds
mov dx, offset msg7
mov ah, 09h
int 21h
mov ax, es:[bx].ddh_nextseg
push ax
mov ax, es:[bx].ddh_nextoff
mov bx, ax
push bx
mov ah, 00h
int 16h
pop bx
pop es
jmp next_ddh
finish:
retmain endp
;************************************
;* display a hex digit
;* input: ax=digit output: none
;************************************
disphex proc
push bx
push es
mov cx, 4
xchg ah, al
mov bl, al
shr al, cl
shl bl, cl
or al, bl
mov bl, ah
shr ah, cl
shl bl, cl
or ah, bl
again:
push cx
push ax
and al, 0fh
cmp al, 9
ja disphex1
add al, 30h
jmp disphex2
disphex1:
add al, 37h
disphex2:
mov dl, al
mov ah, 02h
int 21h
pop ax
mov cl, 4
shr ax, cl
pop cx
loop again
mov dl, 'h'
mov ah, 02h
int 21h
pop es
pop bx
retdisphex endp
code ends
end main
linux裝置驅動程式 字元裝置驅動程式
先留個 有一起學習驅動程式的加qq295699450 字元裝置驅動 這篇比較惱火。載入成功,但是讀不出來資料,有知道怎麼回事的,留個言,一起討論下 資料結構 struct scull mem struct scull dev dev 整個驅動程式 如下 include include include...
Linux裝置驅動程式 字元裝置驅動程式
1.檢視主裝置號,次裝置號 進入 dev目錄執行ls l,第四,五列分別為主次裝置號,10,180,1,5,這些是主裝置號,而60,63這些就是次裝置號 130 shell android dev ls l crw rw r system radio 10,60 1969 12 31 21 00 a...
裝置驅動程式
首先要問,什麼是裝置驅動程式?又名裝置處理程式,是i o系統的高層與裝置控制器之間的通訊程式 起乙個翻譯的作用 這個東西能幹什麼?簡要來說就是啟動指定裝置,完成上層指定的i o工作 裝置驅動程式的特點 略,書上193頁有 裝置處理方式 為每一類裝置設定乙個程序,專門用於執行這類裝置的i o操作 一對...