.DOS device drivers

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

.DOS device drivers

Post 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?
Anything is possible if you put your mind to it.
ComputerPsi
Shark8
Member
Member
Posts: 27
Joined: Wed Nov 02, 2005 12:00 am

Post 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.
User avatar
chase
Site Admin
Posts: 710
Joined: Wed Oct 20, 2004 10:46 pm
Libera.chat IRC: chase_osdev
Location: Texas
Discord: chase/matt.heimer
Contact:

Post by chase »

Do you mean a TSR that it usable as an INT service?
jgmorford
Posts: 6
Joined: Mon Jun 06, 2005 11:00 pm

Post 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.
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Post by ComputerPsi »

chase: I mean devices that you can set in config.sys, for example:
"device mouse.dos"
Anything is possible if you put your mind to it.
ComputerPsi
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Post by Legend »

Well, then you mean exactly what chase meant.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Post 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.
Anything is possible if you put your mind to it.
ComputerPsi
User avatar
chase
Site Admin
Posts: 710
Joined: Wed Oct 20, 2004 10:46 pm
Libera.chat IRC: chase_osdev
Location: Texas
Discord: chase/matt.heimer
Contact:

Post 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.
jgmorford
Posts: 6
Joined: Mon Jun 06, 2005 11:00 pm

Post 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.
Post Reply