Ñòóäåíòàì > Êóðñîâûå > Äðàéâåð æåñòêîãî äèñêà
Äðàéâåð æåñòêîãî äèñêàÑòðàíèöà: 5/6
Çàòåì ïåðåçàãðóçèòü ñèñòåìó äëÿ óñòàíîâêè äðàéâåðà.
Çàêëþ÷åíèå
Ñîçäàâ
äðàéâåð (êîòîðûé ðàáîòàåò â îïåðàöèîííîé ñèñòåìå MS DOS) äëÿ æ¸ñòêîãî
äèñêà, ÿ ðàçîáðàëñÿ êàê âçàèìîäåéñòâóþò ïåðñîíàëüíûé êîìïüþòåð è ïåðèôåðèéíîå
óñòðîéñòâî. Òàêæå ÿ íàó÷èëñÿ êàê çàìåíÿòü äðàéâåð ñòàíäàðòíîãî óñòðîéñòâà,
èñïîëüçóÿ ñèñòåìíûé êîíôèãóðàöèîííûé ôàéë CONFYG.SYS, ðàçîáðàëñÿ â
ñòàíäàðòíûõ ïðîöåäóðàõ è ôóíêöèÿõ, êîòîðûå èñïîëüçóþòñÿ ïðè íàïèñàíèè äðàéâåðà,
è ïîëó÷èë íàâûêè íàïèñàíèÿ äðàéâåðîâ óñòðîéñòâ.
Ñïèñîê
ëèòåðàòóðû
Äæîðäåéí Ð. “Ñïðàâî÷íèê ïðîãðàììèñòà ÏÊ òèïà
IBM PC, AT, XT, AT”
Ìîñêâà: 1991ã.
Ãðèíáåðã Ì. “Ìåòîäèêà ñîçäàíèÿ è îòëàäêè äðàéâåðà
ïåðèôåðèéíîãî
óñòðîéñòâà äëÿ ÎÑ MS DOS” Ñîôòïàíîðàìà:
1990ã.
“Ýëåêòðîííûé ñïðàâî÷íê
Tech Help”
Ëèñòèíã
ïðîãðàììû
; Âûçîâ : Ñêîïèpóéòå â êîpíåâîé êàòàëîã,
äîáàâüòå â ôàéë ;
; CONFIG.SYS êîìàíäó
DEVICE=myHDD.SYS è çàãpóçèòå;
; ñèñòåìó ;
; IDE
Controller PORT CONTENTS (write value)
;==========================================
; 1F0 Data Register (Áàçîâûé êîíòðîëëåð ââîäà-âûâîäà äëÿ
ïåðâîãî IDE)
; 1F1
Error register (write pre comp reg)
; 1F2
Sector count
; 1F3
Sector number
; 1F4
Cylinder low
; 1F5
Cylinder high
; 1F6 SDH register (Íîìåð óñòðîéñòâà è ãîëîâêè)
; 1F7
Status register (command register)
;
; 3F6
Alt. Status reg (Dig Output register)
; 3F7
Drive addr reg.
;
;
;COMMAND
CODE 1F2(SC) 1F3(SN) 1F4-5(CY) 1F6(SDH)
;===================================================
;Recalibrate
10 n n n d
;Read
Sec(s) 20 y y y y
;Write
Sec(s) 30 y y y y
;Verify
Sec(s) 40 y y y y
;Format track 50 n
n y y
;Seek
70 n n y y
;Diagnostic
90 n n n d
code segment
assume cs:code, ds:code, es:code, ss:code
org 0 ; Ýòà ñòðîêà ìîæåò îòñóòñòâîâàòü,
;òàê êàê íå íàäî ðåçåðâèðîâàòü ìåñòî äëÿ
PSP
;-- ÊÎÍÑÒÀÍÒÛ
--------------------------------------------------------------
cmd_fld equ 2 ; ïîëå êîìàíäû â çàïðîñå
status equ 3 ; ïîëå ñîñòîÿíèÿ â çàïðîñå
num_dev equ 13 ; ÷èñëî ïîääåpæèâàåìûõ óñòpîéñòâ
changed equ 14 ; íîñèòåëü ñìåíÿëñÿ ?
end_adr equ 14 ; êîíå÷íûé àäpåñ äpàéâåpà â çàïðîñå
num_rqst equ 18 ; íîìåp â çàïðîñå
bpb_adr equ 18 ; àäpåñ BPB íà íîñèòåëå
b_adr equ 14 ; àäpåñ áóôåpà â çàïðîñå
sector equ 20 ; íîìåp ñåêòîpà
num_cmd equ 16 ; ïîääåpæèâàþòñÿ ïîäôóíêöèè 0-16
dev_des equ 22 ; îáîçíà÷åíèå óñòpîéñòâà äëÿ äèñêà
;-- Çàãîëîâîê äpàéâåpà óñòpîéñòâà
------------------------------------------
dw -1, -1 ; ñâÿçü ñî ñëåäóþùèì
äpàéâåpîì
dw 0100100000000000b ; àòpèáóò äpàéâåpà
dw offset strat ; óêàçàòåëü íà ïîäïpîãpàììó
; ñòpàòåãèè
dw offset intr ; óêàçàòåëü íà
ïîäïpîãpàììó
;
ïpåpûâàíèÿ
db 1 ; óñòpîéñòâî
ïîääåpæèâàåòñÿ
db 7 dup (0) ; ýòè áàéòû îápàçóþò èìÿ
;-- Òàáëèöà ïåpåõîäîâ ê îòäåëüíûì ôóíêöèÿì
---------------------------------
fkt_tab dw offset init ; ôóíêöèÿ 0: èíèöèàëèçàöèÿ
dw offset med_test; ôóíêöèÿ 1: ïpîâåpêà íîñèòåëÿ
dw offset get_bpb ; ôóíêöèÿ 2: ñîçäàòü BPB
dw offset read ; ôóíêöèÿ 3: ïpÿìîå ÷òåíèå
dw offset read ; ôóíêöèÿ 4: ÷òåíèå
dw offset dummy ; ôóíêöèÿ 5: ÷èòàòü, îñòàòüñÿ â
áóôåpå
dw offset dummy ; ôóíêöèÿ 6: ñîñòîÿíèå ââîäà
dw offset dummy ; ôóíêöèÿ 7: î÷èñòèòü áóôåp
ââîäà
dw offset write ; ôóíêöèÿ 8: çàïèñü
dw offset write ; ôóíêöèÿ 9: çàïèñü ñ
âåpèôèêàöèåé
dw offset dummy ; ôóíêöèÿ 10: ñîñòîÿíèå
âûâîäà
dw offset dummy ; ôóíêöèÿ 11: î÷èñòèòü áóôåp
âûâîäà
dw offset write ; ôóíêöèÿ 12: ïpÿìàÿ çàïèñü
dw offset dummy ; ôóíêöèÿ 13: îòêpûòü (3.0 è
âûøå)
dw offset dummy ; ôóíêöèÿ 14: çàêpûòü
dw offset no_rem ; ôóíêöèÿ 15: ñìåíÿåìûé íîñèòåëü
?
dw offset write ; ôóíêöèÿ 16: âûâîäèòü, ïîêà íå
áóäåò çàíÿòî
request dw (?), (?) ; ýäåñü ïðîö. ñòðàòåãèè ñîõð. àäpåñ
áóôåðà çàïðîñà
bpb_ptr
dw offset bpb
mbr db 0bh dup(0)
bpb
db 200h-0bh dup(0) ;ñþäà ñ÷èòàåì bpb
cyl dw ?
head db ?
sect db ?
n dd ?
n63 dd 63
n255 dd 255
fsec dd ?
temp dd ?
;-- ÏÎÄÏÐÎÃÐÀÌÌÛ È ÔÓÍÊÖÈÈ ÄÐÀÉÂÅÐÀ
----------------------------------------
; DOS çàïèñûâàåò â es:bx àäðåñ çàãîëîâêà
çàïðîñà, è ìû äîëæíû âûòàùèòü åãî îòòóäà
strat proc far ; ïîäïpîãpàììà ñòpàòåãèè
mov cs:request, bx ; íà÷àëüíûé àäpåñ çàïðîñà
mov cs:request+2, es ; â ïåpåìåííîé REQUEST
ret ; âîçâpàò â âûçûâàþùóþ
ïîäïpîãpàììó
strat endp
;---------------------------------------------------------------------------
intr proc far ; ïîäïpîãpàììà ïpåpûâàíèÿ
push ax ; çàíåñòè påãèñòpû â ñòåê
push bx
push cx
push dx
push di
push si
push bp
push ds
push es
pushf ; çàíåñòè â ñòåê påãèñòp ôëàãîâ
push cs ; óñòàíîâèòü påãèñòp ñåãìåíòà äàííûõ
pop ds ; çäåñü êîä èäåíòè÷åí äàííûì
les di, dword ptr request ; çàíåñòè àäpåñ áëîêà
äàííûõ
; â ES:DI
mov bl, es:[di+cmd_fld] ; ïîëó÷èòü êîä êîìàíäû
cmp bl, num_cmd ; äîïóñòèì ëè êîä êîìàíäû ?
jle bc_ok ; ÄÀ
--> bc_ok
mov ax, 8003h ; êîä äëÿ "íåèçâåñòíîé
êîìàíäû"
jmp short intr_end ; âîçâpàò â âûçûâàþùóþ
ïîäïpîãpàììó
; ------ åñëè êîä êîìàíäû êîppåêòåí, òî âûïîëíèòü êîìàíäó
---------
bc_ok: shl bl, 1 ; âû÷èñëèòü óêàçàòåëü â òàáëèöå
ïåpåõîäîâ
xor bh, bh ; î÷èñòèòü BH
call [fkt_tab+bx] ; âûçîâ ôóíêöèè
les di, dword ptr request ; çàíåñòè àäpåñ áëîêà
äàííûõ
; â
ES:DI
; ------ âûïîëíåíèå ôóíêöèè çàâåpøåíî
-----------------------------
intr_end:push cs ; óñòàíîâèòü påãèñòp ñåãìåíòà
äàííûõ
pop ds ; çäåñü êîä èäåíòè÷åí äàííûì
les di, dword ptr request ; çàíåñòè àäpåñ áëîêà
äàííûõ
or ax, 0100h ; óñòàíîâèòü áèò
îêîí÷àíèÿ
mov es:[di+status], ax ; çàïîìíèòü âñå â ïîëå
ñîñòîÿíèÿ
popf ; âîññòàíîâèòü påãèñòp
ôëàãîâ
pop es ; âîññòàíîâèòü äpóãèå
påãèñòpû
pop ds
pop bp
pop si
pop di
pop dx
pop cx
pop bx
pop ax
ret ; âîçâpàò â âûçûâàþùóþ
ïîäïpîãpàììó
intr endp
init proc near ; ïîäïpîãpàììà èíèöèàëèçàöèè
mov dx, 3f6h
xor al, al
out dx, al ;Turn off IRQ 14
call waithd ; sit back and relax…
mov dx, 1f6h ;SDH register
mov al, 0a0h ;Drive descriptor
out dx, al
mov dx, 1f2h ;Sector count
mov al, 1
out dx, al
mov dx, 1f3h ;Sector number
mov al, 1
out dx, al
mov dx, 1f4h ;low cyl
mov al, 0
out dx, al
mov dx, 1f5h ;high cyl
mov al, 0
out dx, al ;New generation choose zero cyl.
mov dx, 1f6h ;1st head
mov al, 1
out dx, al
mov dx, 1f7h ;Status(Command) register
mov al, 20h ;Read Sector
out dx, al
gword: mov dx, 1f7h ; Wait for data
in al, dx
test al, 8 ; 8th bit=1 - óñòð-âî
çàíÿòî âûï-ì êîìàíäû
jz gword
mov cx, 256
mov si, offset mbr
mov dx, 1f0h ;Get data
gloop: in ax, dx
mov [si], ax
add si,2
loop gloop
call waithd ; sit back and relax…
mov dx, 3f6h ;Turn on IRQ14 and exit
mov al, 2
out dx, al
mov al, es:[di+dev_des] ; ïîëó÷èòü îáîçíà÷åíèå óñòpîéñòâà
add al, 'A' ; ïpåîápàçîâàòü â áóêâû
mov im_ger, al ; ñîõpàíèòü â ñîîáùåíèè îá
óñòàíîâêå
|