Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Writing a DOS device driver

449 views
Skip to first unread message

Rohit

unread,
Sep 25, 2006, 7:41:55 AM9/25/06
to
Hi!

Can someone please suggest me a good starting point for writing DOS
device drivers. I need to write an installable printer driver. I can
code in assembly and C.

Thanks

Alex Russell

unread,
Sep 25, 2006, 8:11:37 PM9/25/06
to
What do you mean by an "installable printer driver"?

Most DOS programs that supported multiple printers actually had to
support each printer with custom code.

Alex Russell

Sjouke Burry

unread,
Sep 25, 2006, 8:58:11 PM9/25/06
to
Installing graphics.com(DOS 6.22) gives interface
for:
PRINTER HPDEFAULT
PRINTER DESKJET,LASERJETII
PRINTER LASERJET
PRINTER PAINTJET
PRINTER QUIETJET
PRINTER QUIETJETPLUS
PRINTER RUGGEDWRITER
PRINTER RUGGEDWRITERWIDE
PRINTER THINKJET
PRINTER GRAPHICS,THERMAL5152,4201,4202(8"),5201-002(8"),5202,3812,4207,4208,5140
PRINTER COLOR8 ;; 5182 CMY Ribbon
PRINTER COLOR4 ;; 5182 RGB Ribbon
PRINTER GRAPHICSWIDE ;; 4202(13.5"), 5201-002(13.5")
PRINTER COLOR1 ;; 5182 with black ribbon

Alex Russell

unread,
Sep 26, 2006, 8:38:22 PM9/26/06
to

graphics.com is a TSR that allows you print graphics screens from dos
programs. It is not a print driver.

What exactly do you want to do?

Do do something like what graphics.com does you need:

information on writing TSR's
Detailed information on the graphics screen formats and how to read them
Detailed information on how to control each printer you want to support.

Alex

Rohit

unread,
Sep 27, 2006, 8:02:09 AM9/27/06
to
Thank you guys for your quick response. Here is what I needed to learn
:-

1. Installable means I can add DEVICE=[PATH]filename.sys or similar
line in config.sys file. The specified driver will be linked into DOS's
driver chain on bootup.
2. The driver will replace the default PRN device driver. We will just
re-write the centronics related logic ourselves again (this is an
exercise to create a simple driver).
3. My problem was finding the right literature on the above. As of now,
I have learnt about some books, but I would really appreciate if
someone could suggest me a website were I can download some ebook or
maybe some manual.

Again, thank you very much for responding.

Regards
Rohit Kulshreshtha

Alex Russell

unread,
Sep 27, 2006, 8:44:10 PM9/27/06
to

Heard this book is good.
"How to write dos device drivers"
"How to write dos device drivers in c"
Lai Robert S.

http://www.xs4all.nl/~skydiver/devicedriver.html
Complete character device driver in asm

http://www.engineering.usu.edu/ece/faculty/wheeler/Projects/Motion/isr_asm.htm
to control some sort of camera

http://www.infradead.org/devload/
loading device driver at run time

The freedos project likely has source code too.
http://www.freedos.org/

Alex Russell

pe...@nospam.demon.co.uk

unread,
Sep 28, 2006, 12:54:32 AM9/28/06
to
In article <uVESg.35348$bf5.19247@edtnps90>
alexande...@telus.net "Alex Russell" writes:

> Rohit wrote:
> > Thank you guys for your quick response. Here is what I needed to learn
> > :-
> >
> > 1. Installable means I can add DEVICE=[PATH]filename.sys or similar
> > line in config.sys file. The specified driver will be linked into DOS's
> > driver chain on bootup.
> > 2. The driver will replace the default PRN device driver. We will just
> > re-write the centronics related logic ourselves again (this is an
> > exercise to create a simple driver).
> > 3. My problem was finding the right literature on the above. As of now,
> > I have learnt about some books, but I would really appreciate if
> > someone could suggest me a website were I can download some ebook or
> > maybe some manual.
> >
> > Again, thank you very much for responding.
> >
> > Regards
> > Rohit Kulshreshtha
> >
>
> Heard this book is good.
> "How to write dos device drivers"
> "How to write dos device drivers in c"
> Lai Robert S.

One other book to consider:
"Advanced Assembly Language" Allen L. Wyatt
ISBN: 1-56529-037-2

Might be overkill if all you want is device driver info, but if
you're interested in interrupt handlers, TSRs, mouse/keyboard
handling, IOCTL etc. it would be good value for money.

> http://www.xs4all.nl/~skydiver/devicedriver.html
> Complete character device driver in asm
>
> http://www.engineering.usu.edu/ece/faculty/wheeler/Projects/Motion/isr_asm.htm
> to control some sort of camera
>
> http://www.infradead.org/devload/
> loading device driver at run time
>
> The freedos project likely has source code too.
> http://www.freedos.org/
>
> Alex Russell

That last one is the first place I would look.

Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."

Robert Riebisch

unread,
Sep 29, 2006, 4:22:27 AM9/29/06
to
Alex Russell schrieb:

> Heard this book is good.
> "How to write dos device drivers"
> "How to write dos device drivers in c"
> Lai Robert S.

It isn't really good, because it's full of errors. But there are no
alternatives. :-(

--
Robert Riebisch
Bitte NUR in der Newsgroup antworten!
Please reply to the Newsgroup ONLY!

R.Wieser

unread,
Oct 1, 2006, 4:38:27 PM10/1/06
to
Robert Riebisch <Robert....@arcor.de> schreef in berichtnieuws
451cd7c1$0$17400$9b4e...@newsspool2.arcor-online.net...

> Alex Russell schrieb:
>
> > Heard this book is good.
> > "How to write dos device drivers"
> > "How to write dos device drivers in c"
> > Lai Robert S.
>
> It isn't really good, because it's full of errors. But there are no
> alternatives. :-(

I second that. I've got the same book, ISBN 0201608375, second edition,
*6th* printing, march 2001, and its *still* full of errors.

And whats worse : I bought it (a couple of years ago) so I could learn a bit
more about block-device drivers . Alas, it stops early, leaving most of the
block-device -drivers commands un-described (which makes the stuff he *did*
explain quite worthless).

He did add a RAM-drive block-device example, but as beforementioned, it was
full of errors, some of the spelling-kind, but one even wrongly testing for
an out-of-bounds command-request.

In short : you can find the same information and examples on the 'net, and
with less errors. Don't waste your money on that book.

Regards,
Rudy Wieser

Rohit

unread,
Oct 17, 2006, 3:09:04 PM10/17/06
to
Thank you everyone for your replies. I have been able to implement the
required printer driver using your suggestions.

Regards,
Rohit Kulshreshtha

mcal...@ksu.edu

unread,
Oct 17, 2006, 3:19:01 PM10/17/06
to
>Thank you everyone for your replies. I have been able to implement the
>required printer driver using your suggestions.

Any chance you could post your code?
I can think of several device drivers I'd like to have, and
reading code would be one way to get started.

--Myron.
--
--Myron A. Calhoun.
Five boxes preserve our freedoms: soap, ballot, witness, jury, and cartridge
NRA Life Member and Rifle, Pistol, & Home Firearm Safety Certified Instructor
Certified Instructor for the Kansas Concealed-Carry Handgun license

Rohit

unread,
Oct 18, 2006, 11:05:32 AM10/18/06
to
Sure.
;-------------------------------------------

.model tiny
.586P
.code

; Maximum supported command
maxSupportedCommand equ 0Ch

Header:
dd -1 ; Link to next device driver
dw 8000h ; Simple charachter device
dw Strat ; Strategy routine entry point
dw Intr ; Interrupt routine entry point
db "PRN " ; Logical name for character device

RequestHeader dd ? ; Far pointer to request header
; which is passed to strat routine

Dispatch: ; Function Table from 0 - 0Ch
dw Init ; 0
dw MediaCheck ; 1
dw BuildBPB ; 2
dw IOCTL_Read ; 3
dw Read ; 4
dw NdRead ; 5
dw InpStat ; 6
dw InpFlush ; 7
dw Write ; 8
dw Write ; 9 - Write + Verify Routine
dw OutStat ; A
dw OutFlush ; B
dw IOCTL_Write ; C

; Strategy procedure called by MSDOS
; ES:BX contains the request header far pointer
Strat proc far

; Save the location of request header
mov word ptr cs:RequestHeader, bx
mov word ptr cs:[RequestHeader+2], es
retf

Strat endp

; Interrupt routine
Intr proc far

; Save all general purpose registers
pusha
push ds
push es
push fs

; Allow code segment variables to be accessed
push cs
pop ds

; Get the command code from request header
les di, RequestHeader
mov bl, es:[di+2]

; If command is not supported,
cmp bl, maxSupportedCommand
ja ErrorIntr

; Convert unsigned byte to word
xor bh, bh
shl bx, 1

; Branch to appropriate routine
call [Dispatch+bx]

; AX contains the appropriate return code
les di, [RequestHeader]
or ax, 0100h ; Set done bit
mov word ptr es:[di+3], ax


ExitIntr:
; Restore all general purpose registers
pop fs
pop es
pop ds
popa
retf

ErrorIntr:
mov word ptr es:[di+3], 8003h ; Unknown command code
jmp ExitIntr

Intr endp

; For block devices - Does nothing but sets 'done' flag
MediaCheck proc

xor ax, ax
ret

MediaCheck endp

; For block devices - Does nothing but sets 'done' flag
BuildBPB proc

xor ax, ax
ret

BuildBPB endp

; Our device attributes in header have disabled this function
IOCTL_Read proc

xor ax, ax
ret

IOCTL_Read endp

; Driver doesn't support reading. Return error...
Read proc

; return write fault error
mov ax, 800Bh

; Set number of bytes read to 0
les di, RequestHeader
mov word ptr es:[di+18], 0

ret

Read endp

; Driver doesn't support non-destructive reading. Return error...
NdRead proc

; return write fault error
mov ax, 800Bh

; Set number of bytes read to 0
les di, RequestHeader
mov word ptr es:[di+18], 0

ret


NdRead endp

; Input Buffer status
InpStat proc

; Set busy bit to 0 -> buffer contains datat\
xor ax, ax
ret

InpStat endp

InpFlush proc

xor ax, ax
ret

InpFlush endp

; Write data to the screen
Write proc

les di, RequestHeader

; Load source address in FS:SI
lfs si, es:[di+14]

; Load byte count
mov cx, es:[di+18]

; Display Character one-by-one
or cx, cx ; Prevent from executing 65536 times
jz ExitWrite

DispChar:

; Set attribute
; mov ah, 09h
; mov al, ' '
; mov bh, 0
; mov bl, 04 ; RED
; mov cx, 1
; int 10h

mov al, fs:[si]
mov ah, 0Eh
mov bh, 0
int 10h

mov al, fs:[si]
mov dx, 03F8h
out dx, al

inc si
loop DispChar

ExitWrite:
xor ax, ax
ret

Write endp

; Set output status to 0 -> not busy
OutStat proc

xor ax, ax
ret

OutStat endp

; Flush output
OutFlush proc

xor ax, ax
ret

OutFlush endp

; Won't be called
IOCTL_Write proc

xor ax, ax
ret

IOCTL_Write endp


; Init procedure is placed at end because it is called
; only once and can be successfully disposed by specifying
; the address of init as free memory above driver
Init proc

mov ah, 09h
mov dx, offset StartMessage
int 21h

les di, RequestHeader

; Set seg:offset of free memory
mov es:[di+14], offset Init
mov es:[di+16], cs

; Status
xor ax, ax
ret
Init endp

StartMessage db "Rohit's printer driver successfully loaded.", 10,
13, '$'

end
;------------- END OF CODE

Regards
Rohit Kulshreshta

Allan Adler

unread,
Dec 4, 2006, 11:24:00 AM12/4/06
to
pe...@nospam.demon.co.uk writes:

> One other book to consider:
> "Advanced Assembly Language" Allen L. Wyatt
> ISBN: 1-56529-037-2

I think his books are based on masm and tasm. Are they just as good
for nasm?
--
Ignorantly,
Allan Adler <a...@zurich.csail.mit.edu>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.

pe...@nospam.demon.co.uk

unread,
Dec 4, 2006, 1:38:04 PM12/4/06
to
In article <y93bqmj...@nestle.csail.mit.edu>
a...@nestle.csail.mit.edu "Allan Adler" writes:

> pe...@nospam.demon.co.uk writes:
>
> > One other book to consider:
> > "Advanced Assembly Language" Allen L. Wyatt
> > ISBN: 1-56529-037-2
>
> I think his books are based on masm and tasm. Are they just as good
> for nasm?

MASM 6. I would not think, however, that translating the
supplied files to NASM syntax would be too arduous; there might
even be a masm->nasm translator available somewhere that will do
90% of the work.

Allan Adler

unread,
Dec 4, 2006, 11:12:49 PM12/4/06
to
pe...@nospam.demon.co.uk writes:

> In article <y93bqmj...@nestle.csail.mit.edu>
> a...@nestle.csail.mit.edu "Allan Adler" writes:
> > I think his books are based on masm and tasm. Are they just as good
> > for nasm?
>
> MASM 6. I would not think, however, that translating the
> supplied files to NASM syntax would be too arduous; there might
> even be a masm->nasm translator available somewhere that will do
> 90% of the work.

I've been doing some googling without success to find a translator.
I think that, in principle, even I could write a translator for the
pure assembly code. But all assemblers have their own assembler macros
and those, according to the pages I looked at, might be harder to translate.

I've never written an assembler and I don't really know how hard it is.
Maybe translating between MASM6 and NASM in a way that takes into account
the macros and other conventions is about as difficult as writing
an assembler?

pe...@nospam.demon.co.uk

unread,
Dec 5, 2006, 1:31:19 PM12/5/06
to
In article <y937ix7...@nestle.csail.mit.edu>
a...@nestle.csail.mit.edu "Allan Adler" writes:

> pe...@nospam.demon.co.uk writes:
>
> > In article <y93bqmj...@nestle.csail.mit.edu>
> > a...@nestle.csail.mit.edu "Allan Adler" writes:
> > > I think his books are based on masm and tasm. Are they just as good
> > > for nasm?
> >
> > MASM 6. I would not think, however, that translating the
> > supplied files to NASM syntax would be too arduous; there might
> > even be a masm->nasm translator available somewhere that will do
> > 90% of the work.
>
> I've been doing some googling without success to find a translator.
> I think that, in principle, even I could write a translator for the
> pure assembly code. But all assemblers have their own assembler macros
> and those, according to the pages I looked at, might be harder to translate.

Hence the "90%" comment. You might also try a post to
comp.lang.asm.x86 -- there are some knowledgeable and helpful
contributors there for nasm (Frank Kotler is worth a special
mention on both counts).

> I've never written an assembler and I don't really know how hard it is.
> Maybe translating between MASM6 and NASM in a way that takes into account
> the macros and other conventions is about as difficult as writing
> an assembler?

If the device driver you are planning to write is huge/complex
this could be a problem. But a DOS device driver consists simply
of setting up the header, strategy and interrupt parts so if you
can avoid or minimise use of macros (the only ones I saw were
simple EQU or TEXTEQU) these should be straightforward to fix.

rug...@gmail.com

unread,
Jan 3, 2007, 4:45:28 PM1/3/07
to
pe...@nospam.demon.co.uk wrote:
> In article <y937ix7...@nestle.csail.mit.edu>
> a...@nestle.csail.mit.edu "Allan Adler" writes:
>
> > pe...@nospam.demon.co.uk writes:
> >
> > > In article <y93bqmj...@nestle.csail.mit.edu>
> > > a...@nestle.csail.mit.edu "Allan Adler" writes:
> > > > I think his books are based on masm and tasm. Are they just as good
> > > > for nasm?
> > >
> > > MASM 6. I would not think, however, that translating the
> > > supplied files to NASM syntax would be too arduous; there might
> > > even be a masm->nasm translator available somewhere that will do
> > > 90% of the work.
> >
> > I've been doing some googling without success to find a translator.
> > I think that, in principle, even I could write a translator for the
> > pure assembly code. But all assemblers have their own assembler macros
> > and those, according to the pages I looked at, might be harder to translate.
>
> Hence the "90%" comment. You might also try a post to
> comp.lang.asm.x86 -- there are some knowledgeable and helpful
> contributors there for nasm (Frank Kotler is worth a special
> mention on both counts).
>

I've not tried NOMYSO, but it may help (Perl script that converts
MASM/TASM to NASM):

http://www.devoresoftware.com/nomyso/

Also, FASM has some MASM-ish compatibility macros in its Win32 package.
Several forum members there are also familiar with MASM syntax (not me,
though), so you could ask there if you run into any major difficulties.

http://www.flatassembler.net

Take care! :-)

Steven Nichols

unread,
Jan 5, 2007, 4:27:39 PM1/5/07
to
Allan Adler <a...@nestle.csail.mit.edu> wrote:
> pe...@nospam.demon.co.uk writes:
>
>> One other book to consider:
>> "Advanced Assembly Language" Allen L. Wyatt
>> ISBN: 1-56529-037-2
>
> I think his books are based on masm and tasm. Are they just as good
> for nasm?

The assembler doesn't matter to the book. just convert from MASM to NASM.
There are a few differences, you will get some debugging practice.

Steve


0 new messages