Author Topic: DOS driver tutorial  (Read 4992 times)

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
DOS driver tutorial
« on: June 15, 2014, 02:38:29 AM »
I've to program for an embedded DOS system. Where can I find a DOS driver tutorial?

Gunther
Get your facts first, and then you can distort them.

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: DOS driver tutorial
« Reply #1 on: June 15, 2014, 03:45:38 AM »
If I recall correctly Ray Duncan’s Advanced MS-DOS Programming, and the MS-DOS Encyclopedia (Ray Duncan editor), both published by Microsoft, covered device drivers in detail and included example code.

Also Geoff Chappell’s book DOS Internals is a good possibility.

And the MS-DOS Programmer’s Reference, at least for versions 5 and 6, included a chapter but nothing in the way of code details or example code.


Well Microsoft, here’s another nice mess you’ve gotten us into.

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: DOS driver tutorial
« Reply #2 on: June 15, 2014, 04:56:12 AM »
maybe quicker...
i believe Ralf Brown had some information on drivers

i still remember some of that stuff - lol
i learned from Ray Duncan's book
one of the first things to decide is whether you are writing a character device or a block device
there is also a CLOCK$ device, a special case of a character device
a typical character device replaces system defined devices, like CON, PRN, NUL, etc
typical block devices are RAMDRIVES, and so on
any driver that doesn't fit one of the character device models is usually written as a block device

if you have specific questions, let me know - i may be able to help

are you writing a driver for a piece of hardware ?

FORTRANS

  • Member
  • ****
  • Posts: 946
Re: DOS driver tutorial
« Reply #3 on: June 15, 2014, 05:17:34 AM »
Hi,

   "Advanced Assembly Language", by Allen L. Wyatt, Sr. has a
chapter on device drivers.  Both character and block device
drivers were built.

HTH,

Steve N.

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: DOS driver tutorial
« Reply #4 on: June 15, 2014, 07:09:59 PM »
Thanks to all. I've Ray Duncan's books in my book shelf - probably in the basement. I don't know the books by Geoff Chappell and Allen L. Wyatt, Sr. Are they worth reading?

It seems that web tutorials don't exist.

Gunther
Get your facts first, and then you can distort them.

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: DOS driver tutorial
« Reply #5 on: June 15, 2014, 07:59:12 PM »
I don't know the books by Geoff Chappell and Allen L. Wyatt, Sr. Are they worth reading?

DOS Internals is well written and was a useful reference for me at the time, but I don't have any clear memory of device driver-related information in it. I would start with the Ray Duncan books.
Well Microsoft, here’s another nice mess you’ve gotten us into.

sinsi

  • Member
  • *****
  • Posts: 1007
Re: DOS driver tutorial
« Reply #6 on: June 15, 2014, 08:10:38 PM »
This is shareware (I think), but it's from 1994...
CHAPTER.009 is the one you want.
I can walk on water but stagger on beer.

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: DOS driver tutorial
« Reply #7 on: June 15, 2014, 09:14:36 PM »
if you have Ray Duncan's Advanced MS-DOS Programming book, you have everything you need   :t

FORTRANS

  • Member
  • ****
  • Posts: 946
Re: DOS driver tutorial
« Reply #8 on: June 15, 2014, 11:00:30 PM »
I don't know the books by Geoff Chappell and Allen L. Wyatt, Sr. Are they worth reading?


Hi Gunther,

   The book by Wyatt is somewhere between okay and good.
It is sort of a  "Advanced Assembly for Beginners" style of book.
Good explanations, and nicely commented code.  Some redundancy.
But not very deep if used as a reference.  Worthwhile, but not
mandatory in my opinion, if you have other sources to work with.

Regards,

Steve N.

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: DOS driver tutorial
« Reply #9 on: June 15, 2014, 11:32:06 PM »
Dave, Michael and Steve,

thank you for the fast answers. Special thanks to Sinsi for providing the material.  :t

Gunther
Get your facts first, and then you can distort them.

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: DOS driver tutorial
« Reply #10 on: June 16, 2014, 12:54:02 AM »
I've checked my basement and found: Advanced MS-DOS Programming. The Microsoft(R) Guide for Assembly Language and C Programmers. By Ray Duncan. Chapter 14 presents a skeleton example for a driver. I found furthermore Extending DOS. A Programmers Guide to Protected-Mode DOS. It has two working driver examples for an EMS and a XMS ram disk.

I think that'll be my starting point.

Gunther
Get your facts first, and then you can distort them.

nidud

  • Member
  • *****
  • Posts: 1411
    • https://github.com/nidud/asmc
Re: DOS driver tutorial
« Reply #11 on: June 16, 2014, 01:26:39 AM »
Here is the last device driver I wrote if that helps.
Code: [Select]
;
; build: jwasm -bin -Fo dzemm.sys dzemm.asm
;
.186
.model  tiny
.code
assume  ds:_TEXT

dd -1 ; pointer to next driver
dw 8000h ; device attributes
dw strategy ; device strategy entry point
dw interrupt ; device interrupt entry point
db 'EMMXXXX0' ; device name

strategy:
mov cs:drvseg,es
mov cs:drvoff,bx
retf

interrupt:
pusha
push ds
push es
lds bx,cs:drvptr
sub ax,ax
cmp cs:drvset,al
jne interrupt_end
inc cs:drvset
cmp [bx+3],al
je initdevice
    interrupt_end:
mov word ptr [bx+3],100h
pop es
pop ds
popa
retf

int_67: push bp
mov bp,ax
db 0B8h
vdd_67  dw 0
dw 0C4C4h
db 58h,02h
pop bp
iret

drvptr  label dword
drvoff  dw ?
drvseg  dw ?
drvset  db ?
vddname db 'dzemm.dll',0
vddinit db 'DZEmmInitVDD',0
vdddisp db 'DZEmmCallVDD',0

initdevice:
push ds
push bx
mov ax,cs
mov ds,ax
mov es,ax
mov si,offset vddname
mov di,offset vddinit
mov bx,offset vdddisp
dw 0C4C4h
db 58h,00h
jc initdevice_end
mov vdd_67,ax
mov vdd_in,ax
mov ah,41h ; steal memory from EMM ;-)
int 67h
test ah,ah
jnz @F
mov dx,bx
jmp initdevice_seg
      @@:
mov ax,5800h ; alloc one segment from dos
int 21h ; get alloc and UMB state
mov si,ax
mov ax,5802h
int 21h
mov ah,0
mov di,ax
mov ax,5801h ; set alloc and UMB strategy
mov bx,0082h ; last fit, try high then low memory
int 21h
mov ax,5803h ; add UMBs to DOS memory chain
mov bx,0001h
int 21h
xor bp,bp
mov ah,48h ; alloc segment
mov bx,1000h ; para
int 21h
jc @F
mov bp,ax
      @@:
mov ax,5801h ; reset alloc and UMB strategy
mov bx,si
int 21h
mov ax,5803h
mov bx,di
int 21h
mov dx,bp ; call dzemm.dll(dx)
    initdevice_seg:
mov bp,5E00h
db 0B8h
vdd_in  dw 0
dw 0C4C4h
db 58h,02h
test ax,ax
jz initdevice_end
mov dx,offset int_67
mov ax,2567h
int 21h
    initdevice_end:
pop bx
pop ds
mov word ptr [bx+0Eh],offset device_end
mov word ptr [bx+10h],cs
jmp interrupt_end

device_end:

end initdevice

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: DOS driver tutorial
« Reply #12 on: June 16, 2014, 04:23:07 AM »
Hi nidud,

Here is the last device driver I wrote if that helps.

thank you.  :t

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: DOS driver tutorial
« Reply #13 on: June 16, 2014, 04:32:55 AM »
suggestion, Gunther....

boot from a floppy to test your driver   :t
if it hangs, you can still boot the hard drive

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: DOS driver tutorial
« Reply #14 on: June 16, 2014, 06:04:26 AM »
Dave,

boot from a floppy to test your driver   :t
if it hangs, you can still boot the hard drive

that's my plan.

Gunther
Get your facts first, and then you can distort them.