Page 1 of 1
.DOS device drivers
Posted: Fri Jul 28, 2006 1:25 pm
by ComputerPsi
Anybody here know a good tutorials of how to make dos device drivers in assembly? Or information about how standard dos device drivers work?
Posted: Fri Jul 28, 2006 2:29 pm
by Shark8
Not in assembly, but I did come across a Pascal set of documentation a LONG while back. If you can get your hands on it though, I'm pretty sure it's well enough documented that you could apply it to ASM.
Posted: Fri Jul 28, 2006 3:11 pm
by chase
Do you mean a TSR that it usable as an INT service?
Posted: Fri Jul 28, 2006 3:51 pm
by jgmorford
If you can find a copy of Advanced MS-DOS Programming: The Microsoft(R) Guide for Assembly Language and C Programmers (Ray Duncan), chapter 14 goes over dos drivers in detail. I found a text file version of it on a dos programming site a couple years back. Don't have a link though.
Posted: Fri Jul 28, 2006 4:19 pm
by ComputerPsi
chase: I mean devices that you can set in config.sys, for example:
"device mouse.dos"
Posted: Fri Jul 28, 2006 4:22 pm
by Legend
Well, then you mean exactly what chase meant.
Posted: Fri Jul 28, 2006 4:56 pm
by Dex
Theres not many examples, but what you do is set up a int, say int 40h
Here is a sound driver example
Code: Select all
Int_40h:
pushad
push es
push ds
;-----------------
call [CallTableSound]
jc Int_40hError
;-----------------
pop ds
pop es
popad
iret
Int_40hError:
pop ds
pop es
popad
mov eax,0xffffffff
iret
sound:
stc
ret
CallTable:
CallTable0 dd 0
CallTableSound dd Sound
The above examle works like this, if you want to use sound function from your program, you would call int 40h and then test eax for 0xffffffff and if there print "error no sound card load etc.
But lets say i have made a soundcard with lots of function, how do i link it ?.
Simple by having another function that all drives can call, that replace the address "Sound" with the start of my functions, a function like this
Code: Select all
Int_41h:
pushad
push es
push ds
;-----------------
mov edi,CallTable
shl ecx,2 ; ecx = number for driver eg: as sound is first it will have number 1
add edi,ecx ;ecx now = 4
movsd ; note esi = the drive function start address
;-----------------
pop ds
pop es
popad
iret
Now in the driver you would do this when loading it
Code: Select all
start:
mov ecx,1
mov esi,SoundDriverStart
int 41h
; more code here etc
SoundDriverStart:
cmp eax, 0
je soundOn
cmp eax,1
je soundOff
;and so on
Now to use the sound driver from program, you would do something like this
Code: Select all
int 40h
cmp eax,0xffffffff
je ToPrintError
mov eax,0 ;this will turn sound on
int 40h
;and more code here
That it i have kept it simple for this demo, but you would need a bit of error checking etc.
NOTE: There may be typo errors in the code and its based a 32bit pmode OS, as in a dos like OS.
PS: Here a good basic asm dos driver for AC97 sound card
http://www.programmersheaven.com/downlo ... nload.aspx
Posted: Fri Jul 28, 2006 5:38 pm
by ComputerPsi
I guess I need to give more details as this is going a little off subject. The main reason I want to do that is to figure out how some *.dos drivers work.
Posted: Fri Jul 28, 2006 7:02 pm
by chase
ComputerPsi wrote:I guess I need to give more details as this is going a little off subject. The main reason I want to do that is to figure out how some *.dos drivers work.
There really isn't much of a driver framework like I think your expecting. The basic idea is you create a TSR and you make up the rest, usually you take over an interrupt vector. You should be able to find example mouse drivers but lots of hardware didn't have a driver. Programs still did direct hardware access back then. Thats why having things like a sound blaster compatible sound card and vesa video card were so important.
Posted: Sat Jul 29, 2006 12:40 am
by jgmorford
Dos does actually does have a structured driver interface; it just seems widely ignored by most people since it's only required by the devices defined in IO.SYS, or if you want your driver to support the IOCTL-related int 0x21 sub-functions. I'd doubt it was ever used for anything other than storage devices, though. I've implemented a slightly modified form of it in my psuedo dos clone to implement my devices and vfs drivers.
It's not likely the .dos file you're interested in uses it.